Class: Insika::Commands::DeleteAgentFile
- Inherits:
-
Object
- Object
- Insika::Commands::DeleteAgentFile
- Defined in:
- lib/insika/commands/delete_agent_file.rb
Overview
Control command: removes a prompt file from an agent's workspace. Nonexistent -> NotFoundError. -> { agent_id, file }.
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(profile_source:, agent_file_store:, event_stream:) ⇒ DeleteAgentFile
constructor
A new instance of DeleteAgentFile.
Constructor Details
#initialize(profile_source:, agent_file_store:, event_stream:) ⇒ DeleteAgentFile
Returns a new instance of DeleteAgentFile.
10 11 12 13 14 |
# File 'lib/insika/commands/delete_agent_file.rb', line 10 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/insika/commands/delete_agent_file.rb', line 16 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? unless @agent_files.delete(agent_id, file) raise Insika::NotFoundError, "file '#{file}' not found for agent '#{agent_id}'" end unregister_prompt_file(agent_id, file) @event_stream.emit(Insika::Event.new( type: :agent_file_deleted, data: { agent_id: agent_id, file: file }, meta: { at: Time.now.utc.iso8601 } )) { agent_id: agent_id, file: file } end |