Class: Legion::Extensions::Agentic::Integration::GlobalWorkspace::Helpers::Broadcast

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb

Constant Summary

Constants included from Constants

Constants::BROADCAST_TTL, Constants::COMPETITION_THRESHOLD, Constants::DOMINANCE_MARGIN, Constants::MAX_BROADCAST_HISTORY, Constants::MAX_COALITION_SIZE, Constants::MAX_COMPETITORS, Constants::MAX_SUBSCRIBERS, Constants::MAX_URGENCY, Constants::SALIENCE_DECAY, Constants::SALIENCE_LABELS, Constants::URGENCY_BOOST, Constants::UTILIZATION_ALPHA, Constants::WORKSPACE_STATE_LABELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, source:, domain:, salience:, coalition: []) ⇒ Broadcast

Returns a new instance of Broadcast.



15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 15

def initialize(content:, source:, domain:, salience:, coalition: [])
  @content      = content
  @source       = source
  @domain       = domain
  @salience     = salience.to_f.clamp(0.0, 1.0)
  @coalition    = Array(coalition).first(MAX_COALITION_SIZE)
  @broadcast_at = Time.now.utc
  @received_by  = []
end

Instance Attribute Details

#broadcast_atObject (readonly)

Returns the value of attribute broadcast_at.



12
13
14
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 12

def broadcast_at
  @broadcast_at
end

#coalitionObject (readonly)

Returns the value of attribute coalition.



12
13
14
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 12

def coalition
  @coalition
end

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 12

def content
  @content
end

#domainObject (readonly)

Returns the value of attribute domain.



12
13
14
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 12

def domain
  @domain
end

#received_byObject (readonly)

Returns the value of attribute received_by.



12
13
14
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 12

def received_by
  @received_by
end

#salienceObject (readonly)

Returns the value of attribute salience.



12
13
14
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 12

def salience
  @salience
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 12

def source
  @source
end

Instance Method Details

#acknowledge(subscriber_id) ⇒ Object



25
26
27
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 25

def acknowledge(subscriber_id)
  @received_by << subscriber_id unless @received_by.include?(subscriber_id)
end

#ageObject



33
34
35
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 33

def age
  Time.now.utc - @broadcast_at
end

#expired?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 29

def expired?
  (Time.now.utc - @broadcast_at) > BROADCAST_TTL
end

#labelObject



37
38
39
40
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 37

def label
  SALIENCE_LABELS.each { |range, lbl| return lbl if range.cover?(@salience) }
  :subliminal
end

#to_hObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb', line 42

def to_h
  {
    content:      @content,
    source:       @source,
    domain:       @domain,
    salience:     @salience.round(4),
    label:        label,
    coalition:    @coalition,
    broadcast_at: @broadcast_at,
    age:          age.round(2),
    received_by:  @received_by.dup,
    expired:      expired?
  }
end