Event Bridges
Bridge internal Namzu runtime events to SSE and A2A wire formats, and convert messages, runs, and agent metadata into protocol-friendly shapes.
Namzu's runtime emits internal domain events and messages, but published apps often need wire-friendly shapes. The bridge helpers are the translation layer between those internal runtime types and external protocols such as SSE and A2A.
1. Why the Bridge Layer Exists
The SDK exports both:
- internal domain types under
types/ - wire-facing contracts under
contracts/
The bridge helpers keep those worlds explicit instead of forcing your app to manually rewrite every event and message shape.
2. SSE Mapping With mapRunToStreamEvent()
mapRunToStreamEvent(event, runId) turns selected RunEvent values into SSE-friendly wire events:
Typical mapped wire events include:
run.startediteration.startedmessage.deltatool.executingtool.completedreview.requestedcheckpoint.created
3. Important SSE Limitation
Not every RunEvent maps to an SSE event, and the final completion does not come from the mapper.
Key rule:
- use
mapRunToStreamEvent()for incremental wire events - use the final
AgentRunfromdrainQuery()or generator completion for the terminal result
This matters because run_completed and run_failed are not emitted as mapped SSE payloads today.
4. A2A Message Conversion
The message bridge helpers translate between Namzu messages and A2A messages:
Practical behavior:
userstaysuserassistant,system, andtoolbecome A2A roleagent- tool calls are encoded as
dataparts with Namzu-specific MIME types
5. Convert a Run Into an A2A Task
runToA2ATask() turns a wire-contract Run plus optional message history into an A2A task object:
This is useful when:
- a Namzu run should be exposed to an A2A client
- your app already stores or serves
Runcontract payloads - you need task history and final artifacts in A2A-compatible form
6. Convert Inbound A2A Messages Into Namzu Run Inputs
a2aMessageToCreateRun() is the inbound half of the bridge:
This helper extracts text input and preserves selected runtime config values from the inbound A2A metadata envelope.
7. Build an A2A Agent Card
buildAgentCard() creates the capability card an A2A client can consume:
The helper converts tool names and optional skills into A2A skills entries and sets the supported interface URL automatically from the supplied config.
8. Map Live Runtime Events to A2A Stream Events
mapRunToA2AEvent() maps selected RunEvent values into TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads:
Important runtime choices baked into the mapper:
run_startedmaps to task staterunningrun_completedmaps to final task statecompletedrun_failedmaps to final task statefailedtool_review_requested,plan_ready, andrun_pausedmap toinput-required- many internal events intentionally map to
null
That makes the A2A stream cleaner than the full internal event bus.
9. State Helpers
The A2A helpers also export two small but useful state functions:
runStatusToA2AState()isTerminalState()
Use them when your app needs to reason about status transitions without rebuilding the mapping table yourself.
10. Choosing the Right Bridge
| If you need... | Use |
|---|---|
| Browser- or app-friendly incremental run events | mapRunToStreamEvent() |
| A2A task lifecycle streaming | mapRunToA2AEvent() |
| A2A task snapshots from stored runs | runToA2ATask() |
| A2A agent discovery metadata | buildAgentCard() |
| Inbound A2A message parsing | a2aMessageToCreateRun() and a2aMessageToInput() |
11. Common Mistakes
| Mistake | Why it hurts |
|---|---|
expecting every internal RunEvent to map to SSE or A2A | the bridge intentionally drops some internal-only events |
| treating mapped SSE output as the final run result channel | final completion still comes from the returned AgentRun or stored Run |
| manually rewriting message role conversions | the bridge already encodes Namzu-to-A2A role semantics consistently |