Class: Insika::Commands::WriteAgentFile
- Inherits:
-
Object
- Object
- Insika::Commands::WriteAgentFile
- Defined in:
- lib/insika/commands/write_agent_file.rb
Overview
Control command: writes an agent's prompt file to the
workspace (AgentFileStore). This is what gives each BIA its own identity — the
Prompt provider reads these files via profile.prompt_files. Takes effect
on the next dispatch (hot). -> { agent_id, file, updated_at }.
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(profile_source:, agent_file_store:, event_stream:) ⇒ WriteAgentFile
constructor
A new instance of WriteAgentFile.
Constructor Details
#initialize(profile_source:, agent_file_store:, event_stream:) ⇒ WriteAgentFile
Returns a new instance of WriteAgentFile.
12 13 14 15 16 |
# File 'lib/insika/commands/write_agent_file.rb', line 12 def initialize(profile_source:, agent_file_store:, event_stream:) @profile_source = profile_source @agent_files = agent_file_store @event_stream = event_stream end |
Instance Method Details
#call(command) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/insika/commands/write_agent_file.rb', line 18 def call(command) p = AgentPayload.symbolize(command.payload) agent_id = AgentPayload.presence(p[:agent_id]) file = AgentPayload.presence(p[:file]) raise Insika::ValidationError, "agent_id is required" if agent_id.nil? raise Insika::ValidationError, "file is required" if file.nil? profile = @profile_source.fetch(agent_id) || (raise Insika::NotFoundError, "agent '#{agent_id}' not found") # `.to_s` used to be unconditional here, which is how a JSON body carrying an # OBJECT for `content` became a prompt file holding Ruby's #inspect of it. The # store refuses that now; keep the coercion for scalars (a form always sends a # String, and nil means "clear the file"). content = Insika::AgentFileStore.text!(p[:content], agent_id, file).to_s entry = @agent_files.write(agent_id, file, content, create_only: !!p[:create_only]) # Writing a prompt registers it in prompt_files — otherwise the Prompt provider # would never load it. It's the Command's job, not the dispatcher's. register_prompt_file(profile, file) emit(:agent_file_written, agent_id, file) { agent_id: agent_id, file: file, updated_at: entry["updated_at"] } end |