Class: Insika::Commands::WriteDataTool

Inherits:
Object
  • Object
show all
Defined in:
lib/insika/commands/write_data_tool.rb

Overview

Writes (upserts) a DATA-defined tool into the ToolStore and RELOADS the overlay + catalog — takes effect without a restart. Rejects a name that collides with a code tool (R3). Validating the definition (format, method/url, types, placeholders) is the ToolStore/ToolDefinition's job. Secrets (headers) reconcile in the store; the event carries only the name (0 leakage). -> { name, definition }.

Instance Method Summary collapse

Constructor Details

#initialize(tool_store:, registry:, tool_catalog:, event_stream:) ⇒ WriteDataTool

Returns a new instance of WriteDataTool.



13
14
15
16
17
18
# File 'lib/insika/commands/write_data_tool.rb', line 13

def initialize(tool_store:, registry:, tool_catalog:, event_stream:)
  @tool_store = tool_store
  @registry = registry
  @tool_catalog = tool_catalog
  @event_stream = event_stream
end

Instance Method Details

#call(command) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/insika/commands/write_data_tool.rb', line 20

def call(command)
  p = AgentPayload.symbolize(command.payload)
  name = AgentPayload.presence(p[:name])
  raise Insika::ValidationError, "name is required" if name.nil?
  raise Insika::ValidationError, "'#{name}' is already a code tool" if @registry.code_tool?(name)

  masked = @tool_store.write(p, create_only: !!p[:create_only])
  @registry.reload
  @tool_catalog.reload
  emit(name)
  { name: name, definition: masked }
end