/** * The wire contract between an agent runtime and whatever renders its answer. * * Every runtime emits these four events, in this shape, as newline-delimited * JSON. That is what lets one interface drive any runtime: the browser never * learns which one is running, and swapping runtimes changes no client code. * * Adding a field to an event is safe. Renaming or removing one is not, because * a browser holding an older bundle is still reading the stream. */ /** One tool call, as a reader sees it while they wait. */ export type TraceStep = { /** Stable for the life of the call, so an update replaces rather than appends. */ id: string; /** The tool's real name. Diagnostic; the interface shows `label`. */ tool: string; /** What to show a reader, in plain words. */ label: string; /** A coarse group, so an interface can say "Searched 3 things". */ kind: "searched" | "looked-up" | "read" | "ran"; status: "running" | "completed" | "failed" | "rejected"; /** * Set when this step read something that is NOT the corpus. * * A reader weighs an answer by where it came from, and prose alone cannot * carry that: the model writes the answer, and the model is the thing being * checked. This field is written by the tool that did the reading, so an * interface can mark the claim as outside the rules data without trusting a * sentence the model chose to write. */ source?: { /** What to call the site, e.g. "Riftbound FAQ". */ name: string; /** The exact page that was read. */ url: string; /** False for a community site. Show the difference. */ official: boolean; }; }; /** A tool call started, or its status changed. */ export type StepEvent = { type: "step"; step: TraceStep; }; /** * The answer so far. * * `text` is the WHOLE answer up to this point, not the newest fragment. A * consumer assigns it rather than appending. That costs a little bandwidth and * removes a class of bug: a dropped or reordered fragment cannot corrupt the * text, because the next event carries the whole thing again. */ export type TextEvent = { type: "text"; text: string; }; /** The turn ended. This is the only event that carries usage. */ export type DoneEvent = { type: "done"; text: string; /** Which layer produced this answer. "agent" when the model wrote it. */ source: string; /** * Whether the turn reached a real ending. * * False means the text is real but cut short: show it to the reader who * waited for it, and never write it to a cache other readers will hit. */ complete: boolean; usage?: Record | null; model?: string | null; latencyMs?: number; }; /** The turn failed. Any text already sent stays on screen. */ export type ErrorEvent = { type: "error"; error: string; }; export type AgentEvent = StepEvent | TextEvent | DoneEvent | ErrorEvent; /** Encode one event as an NDJSON line, newline included. */ export declare function encodeEvent(event: AgentEvent): string; /** * Read an NDJSON stream into events. * * A chunk boundary can land anywhere, including inside a JSON object, so the * tail of a chunk is held until its newline arrives. A line that does not parse * is skipped rather than throwing: one corrupt line must not end a turn that is * still producing a good answer. */ export declare function decodeEvents(body: ReadableStream): AsyncGenerator; /** Turn a tool name and its input into something a reader can follow. */ export declare function deriveLabel(toolName: string, input?: Record): { label: string; kind: TraceStep["kind"]; }; //# sourceMappingURL=events.d.ts.map