Class: AgentClientProtocol::Contrib::SessionAccumulator
- Inherits:
-
Object
- Object
- AgentClientProtocol::Contrib::SessionAccumulator
- Defined in:
- lib/agent_client_protocol/contrib/session_accumulator.rb
Defined Under Namespace
Classes: SessionSnapshot
Instance Method Summary collapse
- #apply(notification) ⇒ Object
-
#initialize ⇒ SessionAccumulator
constructor
A new instance of SessionAccumulator.
- #reset ⇒ Object
- #snapshot ⇒ Object
- #subscribe(&block) ⇒ Object
Constructor Details
#initialize ⇒ SessionAccumulator
Returns a new instance of SessionAccumulator.
24 25 26 27 |
# File 'lib/agent_client_protocol/contrib/session_accumulator.rb', line 24 def initialize reset @subscribers = [] end |
Instance Method Details
#apply(notification) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/agent_client_protocol/contrib/session_accumulator.rb', line 41 def apply(notification) notif = normalize(notification) session_id = notif[:session_id] update = notif[:update] # Reset on session change if @session_id && @session_id != session_id reset end @session_id = session_id apply_update(update) snap = snapshot @subscribers.each { |cb| cb.call(snap, notification) } snap end |
#reset ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/agent_client_protocol/contrib/session_accumulator.rb', line 29 def reset @session_id = nil @tool_calls = {} @plan_entries = [] @current_mode_id = nil @available_commands = [] @user_messages = [] @agent_messages = [] @agent_thoughts = [] @config_options = [] end |
#snapshot ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/agent_client_protocol/contrib/session_accumulator.rb', line 59 def snapshot SessionSnapshot.new( session_id: @session_id, tool_calls: @tool_calls.dup, plan_entries: @plan_entries.dup, current_mode_id: @current_mode_id, available_commands: @available_commands.dup, user_messages: @user_messages.dup, agent_messages: @agent_messages.dup, agent_thoughts: @agent_thoughts.dup, config_options: @config_options.dup ).freeze end |
#subscribe(&block) ⇒ Object
73 74 75 |
# File 'lib/agent_client_protocol/contrib/session_accumulator.rb', line 73 def subscribe(&block) @subscribers << block end |