Class: Insika::Commands::MemoryForgetFact
- Inherits:
-
Object
- Object
- Insika::Commands::MemoryForgetFact
- Defined in:
- lib/insika/commands/memory_forget_fact.rb
Overview
Control command: forgets (removes) a fact from the
agent's memory. Idempotent: forgetting something that doesn't exist is not an error
(existed: false). Scoped by tenant. -> { existed: bool }.
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(memory_store:, event_stream:) ⇒ MemoryForgetFact
constructor
A new instance of MemoryForgetFact.
Constructor Details
#initialize(memory_store:, event_stream:) ⇒ MemoryForgetFact
Returns a new instance of MemoryForgetFact.
11 12 13 14 |
# File 'lib/insika/commands/memory_forget_fact.rb', line 11 def initialize(memory_store:, event_stream:) @memory_store = memory_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 |
# File 'lib/insika/commands/memory_forget_fact.rb', line 16 def call(command) p = AgentPayload.symbolize(command.payload) key = AgentPayload.presence(p[:key]) raise Insika::ValidationError, "key is required" if key.nil? tenant = AgentPayload.presence(p[:tenant]) || command.[:tenant] existed = @memory_store.forget_fact(tenant: tenant, key: key) @event_stream.emit(Insika::Event.new( type: :memory_fact_forgotten, data: { tenant: tenant, key: key, existed: existed }, meta: { at: Time.now.utc.iso8601 } )) { existed: existed } end |