Class: AgUi::EventBridge
- Inherits:
-
Object
- Object
- AgUi::EventBridge
- Defined in:
- lib/ag_ui/event_bridge.rb
Overview
The seam between brute's turn pipeline and the AG-UI SSE stream.
Brute middleware and terminal procs emit AG-UI events through the env; a bridge subscribes to that vocabulary on the agent's hooks and translates each one into the matching typed SSE emitter as it arrives — the browser sees deltas mid-turn, not after.
agent = Brute.agent.use(...).run(terminal)
AgUi::EventBridge.new(stream).subscribe(agent)
agent.start(messages)
Brute's own lifecycle events (:llm_start, :tool_end, the middleware and trace sets) are simply never subscribed to here, so only the AG-UI vocabulary reaches the wire.
Constant Summary collapse
- TRANSLATIONS =
{ text_message_start: :translate_text_start, text_message_content: :translate_text_content, text_message_end: :translate_text_end, tool_call_start: :translate_tool_call_start, tool_call_args: :translate_tool_call_args, tool_call_end: :translate_tool_call_end, tool_call_result: :translate_tool_call_result, state_snapshot: :translate_state_snapshot, state_delta: :translate_state_delta, messages_snapshot: :translate_messages_snapshot, activity_snapshot: :translate_activity_snapshot, reasoning_start: :translate_reasoning_start, reasoning_message_start: :translate_reasoning_message_start, reasoning_message_content: :translate_reasoning_message_content, reasoning_message_end: :translate_reasoning_message_end, reasoning_end: :translate_reasoning_end, step_started: :translate_step_started, step_finished: :translate_step_finished, custom: :translate_custom, raw: :translate_raw, }.freeze
Instance Method Summary collapse
-
#initialize(stream) ⇒ EventBridge
constructor
A new instance of EventBridge.
-
#subscribe(hooks) ⇒ Object
Registers the whole vocabulary above on a hooks registry — or on anything else answering
on, which a Brute pipeline builder does.
Constructor Details
#initialize(stream) ⇒ EventBridge
Returns a new instance of EventBridge.
45 46 47 |
# File 'lib/ag_ui/event_bridge.rb', line 45 def initialize(stream) @stream = stream end |
Instance Method Details
#subscribe(hooks) ⇒ Object
Registers the whole vocabulary above on a hooks registry — or on
anything else answering on, which a Brute pipeline builder does.
Answers what it was given, so it composes in one line.
Every subscriber takes (env, data, trace): brute hands the env first and appends the trace last, and a translation wants neither — the data is the whole of an AG-UI event.
56 57 58 59 60 61 |
# File 'lib/ag_ui/event_bridge.rb', line 56 def subscribe(hooks) TRANSLATIONS.each do |event, handler| hooks.on(event) { |_env, data, _trace| send(handler, data || {}) } end hooks end |