ai-sdk-relay-protocol
v0.2.0
Published
Wire protocol for an agent-session relay: provider-agnostic AgentEvent stream, session channel (client ⇄ relay ⇄ runner), replay cursors, and permission flow, all as Zod schemas.
Maintainers
Readme
ai-sdk-relay-protocol
The wire protocol for an agent-session relay: one Durable Object per session, many client sockets, exactly one runner driving the agent, and optionally one tool host serving local tools. Zod schemas are canonical; types are inferred so runtime validation and compile-time types never drift.
What it defines:
AgentEvent: the provider-agnostic output stream a runner emits (turn, text, reasoning, tool, artifact, error). Runners map harness stream parts (@ai-sdk/harness-*) onto these; provider-specific shapes never reach the relay or clients.- Session channel: the frame unions for each connection,
ClientToSession,RunnerToSession,SessionToClient(sequenced updates, replay cursors, live text chunks, permission lifecycle),SessionToRunner, and the tool-host pairHostToSession/SessionToHost. - Permission lifecycle: requests, decisions, and a sequenced resolution for every request (answered, replayed, withdrawn, superseded, or unavailable).
- Turn receipts and archives:
TurnReceiptrecords a prompt's acceptance and progress;SessionArchiveis a session's total state as one portable document, for moves and forks. toModelMessagesandarchiveEvents:toModelMessagesrehydrates a replay log into AI SDKModelMessages, so the log is the canonical conversation state and a session can resume or hand off on any provider.archiveEventsextracts the events from an exported archive, sotoModelMessages(archiveEvents(archive))rebuilds a moved session's conversation.decode/encode: malformed or oversized frames become typed errors, never exceptions orany.
The reference relay is ai-sdk-relay; the tool-host client is
ai-sdk-relay-host. The reference product is
dispatch, where this protocol was
extracted from.
