Module: Xeno::Hooks
- Defined in:
- lib/xeno/hooks.rb
Overview
Observe-only event handlers from agent/hooks/*.rb:
Xeno.hook "turn.completed" do |event|
Metrics.increment("agent.turns", tags: [event.session.channel])
end
Xeno.hook "*" do |event| ... end # every event
Handlers fire after the event row commits, typed handlers before the wildcard, with the Xeno::Event record as the argument. Return values are ignored and a raising handler is logged and skipped — a hook can never veto, inject context, or fail the turn. Delivery is at-least-once: replayed steps re-emit events, so key side effects on (turn_id, step) and stored content on (session_id, index).
Class Method Summary collapse
Class Method Details
.dispatch(event, definition: Xeno.definition) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/xeno/hooks.rb', line 20 def dispatch(event, definition: Xeno.definition) hooks = definition.respond_to?(:hooks) ? definition.hooks : {} return if hooks.empty? handlers = Array(hooks[event.event_type]) + Array(hooks["*"]) handlers.each do |handler| handler.call(event) rescue StandardError => e Rails.logger.warn( "xeno: hook for #{event.event_type} raised #{e.class}: #{e.} — hooks are observe-only, continuing" ) end end |