Class: Insika::Commands::UpdateAgent
- Inherits:
-
Object
- Object
- Insika::Commands::UpdateAgent
- Defined in:
- lib/insika/commands/update_agent.rb
Overview
Control command: edits an existing agent. Merges the patch over the current profile (only the sent fields change) + rebuild + put. Takes effect on the NEXT dispatch (the ProfileSource reads fresh). -> AgentProfile.
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(profile_source:, event_stream:) ⇒ UpdateAgent
constructor
A new instance of UpdateAgent.
Constructor Details
#initialize(profile_source:, event_stream:) ⇒ UpdateAgent
Returns a new instance of UpdateAgent.
11 12 13 14 |
# File 'lib/insika/commands/update_agent.rb', line 11 def initialize(profile_source:, event_stream:) @profile_source = profile_source @event_stream = event_stream end |
Instance Method Details
#call(command) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/insika/commands/update_agent.rb', line 16 def call(command) patch = AgentPayload.attrs(command.payload) id = AgentPayload.presence(patch[:id]) raise Insika::ValidationError, "id is required" if id.nil? existing = @profile_source.fetch(id) || (raise Insika::NotFoundError, "agent '#{id}' not found") # to_h of the current profile brings the correct symbols; patch overwrites only # what was sent. id never changes (rename = create+delete, out of scope). merged = existing.to_h.merge(patch).merge(id: id) profile = Insika::AgentProfile.build(**merged) # definition-time cycle + depth check (an update may ADD # subagents to an existing agent). Raises SubagentError before persisting. validate_subagent_graph!(profile) @profile_source.put(profile) @event_stream.emit(Insika::Event.new( type: :agent_updated, data: { agent_id: id }, meta: { at: Time.now.utc.iso8601 } )) @profile_source.fetch(id) end |