/** * The crtrd broker `error` control frame — `{ code, message, id? }`. `id` is a * correlation token echoed only from the request that failed (a read-op / * `dequeue`); absent on uncorrelated errors. There is NO `retryable` field. */ export interface BrokerErrorFrame { type: 'error'; code: string; message: string; /** Correlation token, echoed from the failed request; absent on uncorrelated errors. */ id?: string; } /** * The `welcome` frame's history/state snapshot, narrowed to what a relay consumer * replays: the message history and the streaming flag. `M` is the message shape * (pi's `AgentMessage` in a pi consumer; `unknown` by default). */ export interface BrokerWelcomeSnapshot { messages: M[]; state?: { isStreaming?: boolean; }; } /** * The crtrd broker `welcome` control frame — the history/resume catch-up snapshot * delivered on (re)attach. */ export interface BrokerWelcomeFrame { type: 'welcome'; snapshot?: BrokerWelcomeSnapshot; } /** * The broker-control frames a relay consumer reads: `welcome` (catch-up snapshot) * and `error`. The broker interleaves others (display_*, control_changed, ack, …) * under non-colliding `type` discriminants; a relay mapper drops those through its * `default` arm untyped, so they are not enumerated here. */ export type BrokerControlFrame = BrokerWelcomeFrame | BrokerErrorFrame; /** * What the crtrd broker attach delivers to a relay consumer: the live engine * event stream (`E` — pi's `AgentSessionEvent`, relayed verbatim) unioned with the * broker's own control frames. Discriminants never collide: an `AgentSessionEvent` * owns no `welcome` / `error` `type`. */ export type BrokerAttachFrame = E | BrokerControlFrame;