@dudousxd/nestjs-agent-core 0.40.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/ag-ui/index.cjs +46 -10
- package/dist/ag-ui/index.cjs.map +1 -1
- package/dist/ag-ui/index.d.cts +9 -3
- package/dist/ag-ui/index.d.ts +9 -3
- package/dist/ag-ui/index.js +46 -10
- package/dist/ag-ui/index.js.map +1 -1
- package/dist/{catalog-CrzetM3_.d.cts → catalog-BKS3Yxo6.d.cts} +2 -0
- package/dist/{catalog-CrzetM3_.d.ts → catalog-BKS3Yxo6.d.ts} +2 -0
- package/dist/genui/builtins.cjs.map +1 -1
- package/dist/genui/builtins.d.cts +1 -1
- package/dist/genui/builtins.d.ts +1 -1
- package/dist/genui/builtins.js.map +1 -1
- package/dist/genui/index.cjs +660 -68
- package/dist/genui/index.cjs.map +1 -1
- package/dist/genui/index.d.cts +5 -5
- package/dist/genui/index.d.ts +5 -5
- package/dist/genui/index.js +654 -68
- package/dist/genui/index.js.map +1 -1
- package/dist/guardrails/index.cjs +3 -1
- package/dist/guardrails/index.cjs.map +1 -1
- package/dist/guardrails/index.d.cts +5 -4
- package/dist/guardrails/index.d.ts +5 -4
- package/dist/guardrails/index.js +3 -1
- package/dist/guardrails/index.js.map +1 -1
- package/dist/index.cjs +1161 -421
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +118 -13
- package/dist/index.d.ts +118 -13
- package/dist/index.js +1153 -421
- package/dist/index.js.map +1 -1
- package/dist/{processors-B7nfbU6E.d.cts → processors-BXM-MNga.d.cts} +1 -1
- package/dist/{processors-BR3nICcp.d.ts → processors-ByDr5POu.d.ts} +1 -1
- package/dist/{stream-events-DAmes2Of.d.ts → stream-events-BGKLD6RX.d.ts} +73 -4
- package/dist/{stream-events-M0jc7lSW.d.cts → stream-events-CF-6-Y6L.d.cts} +73 -4
- package/package.json +1 -1
package/dist/ag-ui/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ag-ui/interrupt-id.ts","../../src/ag-ui/types.ts","../../src/ag-ui/encoder.ts","../../src/genui/catalog.ts","../../src/genui/capabilities.ts","../../src/ag-ui/input.ts","../../src/spi/token-stream-sink.ts","../../src/stream-events.ts","../../src/ag-ui/stream.ts","../../src/ag-ui/proposal-decision.ts"],"sourcesContent":["/**\n * An interrupt's id carries everything a resuming request needs, so the producer keeps NOTHING\n * between the run that stopped to ask and the run that answers — the statelessness AG-UI lets a\n * producer have, and what lets any replica serve the resume.\n *\n * It names the library run the human is answering (`parked` — a delegated sub-agent parks its OWN\n * run), the run whose stream carries the work (`stream`), the tool call, and how many of that\n * stream's frames the interrupted AG-UI run already delivered (`position`), which is where the\n * resuming run picks the stream up.\n *\n * It is an address, not a credential: the resume route checks the caller owns the run exactly as\n * the native approve/answer routes do.\n */\nexport interface InterruptAddress {\n kind: 'approval' | 'elicitation';\n /** The run to settle the call on. */\n parked: string;\n /** The run whose buffered stream the resume re-attaches to. */\n stream: string;\n toolCallId: string;\n /** Frames of `stream` already delivered when the run was reported interrupted. */\n position: number;\n}\n\nconst PREFIX = 'agora_';\n\nexport function encodeInterruptId(address: InterruptAddress): string {\n const compact = [\n address.kind === 'approval' ? 'a' : 'e',\n address.parked,\n address.stream,\n address.toolCallId,\n address.position,\n ];\n return PREFIX + Buffer.from(JSON.stringify(compact), 'utf8').toString('base64url');\n}\n\n/** The address an id names, or `null` for an id this producer did not mint. */\nexport function decodeInterruptId(id: unknown): InterruptAddress | null {\n if (typeof id !== 'string' || !id.startsWith(PREFIX)) return null;\n try {\n const parsed: unknown = JSON.parse(\n Buffer.from(id.slice(PREFIX.length), 'base64url').toString('utf8'),\n );\n if (!Array.isArray(parsed) || parsed.length !== 5) return null;\n const [kind, parked, stream, toolCallId, position] = parsed as unknown[];\n if (\n (kind !== 'a' && kind !== 'e') ||\n typeof parked !== 'string' ||\n typeof stream !== 'string' ||\n typeof toolCallId !== 'string' ||\n typeof position !== 'number' ||\n !Number.isSafeInteger(position) ||\n position < 0\n ) {\n return null;\n }\n return {\n kind: kind === 'a' ? 'approval' : 'elicitation',\n parked,\n stream,\n toolCallId,\n position,\n };\n } catch {\n return null;\n }\n}\n","import type { AgentStreamEvent } from '../stream-events.js';\n\n/**\n * The slice of AG-UI 1.0 (https://docs.ag-ui.com/spec/1.0) this producer writes and reads. Typed by\n * hand rather than imported: the agent package takes no dependency on an AG-UI SDK, and the wire\n * shape is pinned by the protocol's own JSON Schema, which the tests validate every emitted event\n * against (`src/ag-ui/fixtures/schema-1.0.json`).\n *\n * Optional members are OMITTED when there is nothing to say, never `null` — the protocol's\n * \"absent means absent\" rule.\n */\n\n/** The protocol version this producer declares on `RUN_STARTED`. */\nexport const AG_UI_PROTOCOL_VERSION = '1.0';\n\nexport type AgUiMetadata = Record<string, unknown>;\n\n/** One provider-and-model's token usage, in the protocol's single accounting. */\nexport interface AgUiTokenUsage {\n provider?: string;\n model?: string;\n /** Every prompt token, cached or not. */\n inputTokens?: number;\n /** Every generated token, reasoning included. */\n outputTokens?: number;\n totalTokens?: number;\n /** Part of `outputTokens`. */\n reasoningTokens?: number;\n /** Cache reads — part of `inputTokens`. */\n cachedInputTokens?: number;\n /** Cache writes — part of `inputTokens`, disjoint from the reads. */\n cacheWriteInputTokens?: number;\n}\n\n/** What an interrupted run is waiting for; a resume entry answers it by `id`. */\nexport interface AgUiInterrupt {\n id: string;\n /** Open string. This producer writes `tool_approval` and `input_required`. */\n reason: string;\n message?: string;\n toolCallId?: string;\n responseSchema?: Record<string, unknown>;\n expiresAt?: string;\n metadata?: AgUiMetadata;\n}\n\nexport type AgUiRunOutcome =\n | { type: 'success'; pendingToolCallIds?: string[] }\n | { type: 'interrupt'; interrupts: AgUiInterrupt[] }\n | { type: 'cancelled' };\n\ninterface Base {\n metadata?: AgUiMetadata;\n}\n\nexport type AgUiEvent =\n | (Base & { type: 'RUN_STARTED'; threadId: string; runId: string; protocolVersion?: string })\n | (Base & {\n type: 'RUN_FINISHED';\n threadId: string;\n runId: string;\n outcome?: AgUiRunOutcome;\n usage?: AgUiTokenUsage[];\n })\n | (Base & { type: 'RUN_ERROR'; message: string; code?: string; usage?: AgUiTokenUsage[] })\n | (Base & { type: 'STEP_STARTED'; stepName: string })\n | (Base & { type: 'STEP_FINISHED'; stepName: string })\n | (Base & { type: 'TEXT_MESSAGE_START'; messageId: string; role: 'assistant' })\n | (Base & { type: 'TEXT_MESSAGE_CONTENT'; messageId: string; delta: string })\n | (Base & { type: 'TEXT_MESSAGE_END'; messageId: string })\n | (Base & { type: 'REASONING_START'; messageId: string })\n | (Base & { type: 'REASONING_MESSAGE_START'; messageId: string; role: 'reasoning' })\n | (Base & { type: 'REASONING_MESSAGE_CONTENT'; messageId: string; delta: string })\n | (Base & { type: 'REASONING_MESSAGE_END'; messageId: string })\n | (Base & { type: 'REASONING_END'; messageId: string })\n | (Base & {\n type: 'TOOL_CALL_START';\n toolCallId: string;\n toolCallName: string;\n parentMessageId?: string;\n })\n | (Base & { type: 'TOOL_CALL_ARGS'; toolCallId: string; delta: string })\n | (Base & { type: 'TOOL_CALL_END'; toolCallId: string })\n | (Base & {\n type: 'TOOL_CALL_RESULT';\n messageId: string;\n toolCallId: string;\n content: string;\n role: 'tool';\n })\n | (Base & { type: 'CUSTOM'; name: string; value: unknown });\n\n/** Where a media part's bytes are. Closed set: an unknown `type` is malformed input. */\nexport type AgUiPartSource =\n | { type: 'data'; value: string; mimeType: string }\n | { type: 'url'; value: string; mimeType?: string }\n | { type: 'file'; value: string; provider?: string; mimeType?: string };\n\nexport type AgUiContentPart =\n | { type: 'text'; text: string; id?: string; metadata?: unknown }\n | {\n type: 'image' | 'audio' | 'video' | 'document';\n source: AgUiPartSource;\n id?: string;\n metadata?: unknown;\n };\n\nexport interface AgUiMessage {\n id: string;\n role: string;\n content?: string | AgUiContentPart[];\n [key: string]: unknown;\n}\n\nexport interface AgUiResumeEntry {\n interruptId: string;\n status: 'resolved' | 'cancelled';\n payload?: unknown;\n metadata?: AgUiMetadata;\n}\n\nexport interface AgUiContext {\n description: string;\n value: string;\n}\n\n/** `RunAgentInput`: the one message that travels from the application to the agent. */\nexport interface AgUiRunInput {\n threadId: string;\n runId: string;\n protocolVersion?: string;\n parentRunId?: string;\n state?: unknown;\n messages: AgUiMessage[];\n tools?: unknown[];\n context?: AgUiContext[];\n forwardedProps?: unknown;\n resume?: AgUiResumeEntry[];\n}\n\n/**\n * The names of the `CUSTOM` events this producer writes for what AG-UI does not model. Prefixed, as\n * the protocol asks of invented names; a consumer that does not know one ignores it.\n */\nexport const AG_UI_CUSTOM = {\n /** `{ runId, threadId }` — the library's own ids for the run behind this stream (cancel, re-attach). */\n run: 'agora.run',\n /** A generative-UI component (`AgentUiComponent`); a repeat `id` replaces. */\n ui: 'agora.ui',\n title: 'agora.title',\n queue: 'agora.queue',\n /** The approval request as the native protocol carries it, for a consumer that renders it live. */\n approvalRequested: 'agora.approval-requested',\n approvalSettled: 'agora.approval-settled',\n /** The whole question set of an elicitation (`ElicitationRequest`). */\n elicitation: 'agora.elicitation',\n /** `{ usage, costUsd, reasoningMs }` of one model step. */\n stepUsage: 'agora.step-usage',\n /** `{ message }` — input material this producer could not use and dropped. */\n warning: 'agora.warning',\n} as const;\n\n/**\n * What the encoder reads: one frame of a run's stream, in the shared vocabulary\n * ({@link AgentStreamEvent}) — plus the terminal failure, which the NestJS sink throws and the\n * Adonis sink writes as a frame, and three optional facts a sink may know about a parked call:\n * - `runId` — the run that is PARKED, when it is not the one whose stream this is (a delegated\n * sub-agent forwards its frames into its ancestor's stream). Absent → the stream's own run.\n * - `toolName`, `input` — the call being approved. Absent → read off the call's announcement.\n *\n * Framework-free on purpose: both servers project their own sink onto this and share one encoder.\n */\nexport type AgUiSourceFrame =\n | Exclude<\n AgentStreamEvent,\n { kind: 'approval-requested' } | { kind: 'elicitation' } | { kind: 'ui' }\n >\n | (Extract<AgentStreamEvent, { kind: 'approval-requested' }> & {\n runId?: string;\n toolName?: string;\n input?: unknown;\n })\n | (Extract<AgentStreamEvent, { kind: 'elicitation' }> & { runId?: string })\n /** A component with no `id` is numbered by its position in the stream (`ui:<n>`). */\n | (Omit<Extract<AgentStreamEvent, { kind: 'ui' }>, 'id' | 'props'> & {\n id?: string;\n props: unknown;\n })\n /** The run failed: the AG-UI run ends with `RUN_ERROR`, and nothing follows it. */\n | { kind: 'error'; code: string; message: string };\n","import type { ElicitationRequest } from '../elicitation.js';\nimport type { MessageUsage } from '../types.js';\nimport { encodeInterruptId } from './interrupt-id.js';\nimport {\n AG_UI_CUSTOM,\n AG_UI_PROTOCOL_VERSION,\n type AgUiEvent,\n type AgUiInterrupt,\n type AgUiSourceFrame,\n type AgUiTokenUsage,\n} from './types.js';\n\nexport interface AgUiEncoderOptions {\n /** The ids the consumer sent on `RunAgentInput`: every boundary event echoes them. */\n threadId: string;\n runId: string;\n /** The library run whose stream is being projected (it mints interrupt ids and the `agora.run` event). */\n streamRunId: string;\n /** The library's thread id, when it differs from what the consumer calls the thread. */\n streamThreadId?: string;\n /**\n * Frames of the library run's stream that an earlier AG-UI run already delivered (a resume). They\n * are fed to the encoder like any other — it has to know what they opened — but produce no events.\n */\n skip?: number;\n /**\n * Tool calls a resuming request just answered. The run has not necessarily said so yet — a parked\n * run takes a moment to wake — so without this the encoder would read them as still waiting and\n * report the interrupt again before the answer had any effect.\n */\n answered?: readonly string[];\n /** Model id for the usage entry when the step frames carry none. */\n model?: string;\n}\n\ninterface OpenCall {\n name: string;\n /** The arguments it was announced with, for an approval frame that does not repeat them. */\n input?: unknown;\n /** `TOOL_CALL_START` was written in THIS run (a resumed run meets results of calls it never saw open). */\n started: boolean;\n ended: boolean;\n sawDelta: boolean;\n answered: boolean;\n}\n\ninterface Pending {\n interrupt: Omit<AgUiInterrupt, 'id'>;\n kind: 'approval' | 'elicitation';\n parked: string;\n toolCallId: string;\n}\n\nconst APPROVAL_SCHEMA = {\n type: 'object',\n properties: {\n approved: { type: 'boolean' },\n reason: { type: 'string' },\n remember: { type: 'boolean' },\n },\n required: ['approved'],\n};\n\n/** The answer an elicitation expects: `{ answers: { <questionId>: string[] } }`. */\nfunction elicitationSchema(request: ElicitationRequest): Record<string, unknown> {\n const properties: Record<string, unknown> = {};\n for (const question of request.questions) {\n const options = question.options?.map((option) => option.value);\n properties[question.id] = {\n type: 'array',\n title: question.prompt,\n ...(question.description !== undefined ? { description: question.description } : {}),\n items:\n options !== undefined && options.length > 0 && question.allowFreeText !== true\n ? { type: 'string', enum: options }\n : { type: 'string' },\n ...(question.multiple === true ? {} : { maxItems: 1 }),\n ...(question.defaults !== undefined ? { default: question.defaults } : {}),\n };\n }\n return {\n type: 'object',\n properties: { answers: { type: 'object', properties } },\n required: ['answers'],\n };\n}\n\nfunction text(value: unknown): string {\n if (typeof value === 'string') return value;\n const json = JSON.stringify(value);\n return json === undefined ? '' : json;\n}\n\n/**\n * Projects one library run's stream ({@link AgUiSourceFrame}s, in buffer order) onto AG-UI 1.0 events.\n *\n * A pure state machine: the same frames always give the same events, which is what lets a resuming\n * request — served by any replica — replay the run's buffer, skip what the interrupted AG-UI run\n * already delivered, and continue. It writes nothing itself; {@link agUiEvents} drives it and\n * decides when the run has stopped to ask.\n *\n * What maps where:\n * - `text` → `TEXT_MESSAGE_*` (one message per stretch of text);\n * - `reasoning` → a reasoning span with one reasoning message;\n * - `step-start`/`step-finish` → `STEP_STARTED`/`STEP_FINISHED`, the step's usage folded into the\n * run's `usage`;\n * - `tool-input-*` → `TOOL_CALL_START`/`ARGS`/`END`; `tool-output*` → `TOOL_CALL_RESULT`;\n * - an approval or a question set the run parks on → an `Interrupt` on the closing `RUN_FINISHED`;\n * - `cancelled` → the cancelled outcome; an error frame → `RUN_ERROR`;\n * - generative UI, title, queue and the native approval/elicitation frames → `CUSTOM` events named\n * in {@link AG_UI_CUSTOM}, for what AG-UI has no event for.\n *\n * Not mapped: sub-agent attribution (`subagentRunId`) — a delegated agent's frames are projected\n * flat, as the protocol allows of a producer that does not attribute.\n */\nexport class AgUiEncoder {\n private position = 0;\n private started = false;\n private closed = false;\n private cancelled = false;\n private crossed = false;\n private messageSeq = 0;\n private stepSeq = 0;\n private openText: string | undefined;\n private openReasoning: string | undefined;\n /** The last text message of the current step: a tool call attaches to it. */\n private stepMessage: string | undefined;\n private readonly openSteps: string[] = [];\n private readonly calls = new Map<string, OpenCall>();\n private readonly pending = new Map<string, Pending>();\n private readonly usage = new Map<string, AgUiTokenUsage>();\n\n constructor(private readonly options: AgUiEncoderOptions) {}\n\n /** How many frames of the library stream this encoder has consumed. */\n get consumed(): number {\n return this.position;\n }\n\n /** The run is waiting on at least one approval or question set nobody has settled yet. */\n get waiting(): boolean {\n return this.pending.size > 0;\n }\n\n /**\n * Is anything still in flight that is NOT waiting on a person — a tool call announced and neither\n * answered nor parked? While there is, more frames are coming without anyone's help.\n */\n get busy(): boolean {\n for (const [id, call] of this.calls) {\n if (!call.answered && !this.pending.has(id)) return true;\n }\n return false;\n }\n\n /** `RUN_STARTED`, and the library's own ids for the run. Call once, before the first frame. */\n start(): AgUiEvent[] {\n if (this.started) return [];\n this.started = true;\n return [\n {\n type: 'RUN_STARTED',\n threadId: this.options.threadId,\n runId: this.options.runId,\n protocolVersion: AG_UI_PROTOCOL_VERSION,\n },\n {\n type: 'CUSTOM',\n name: AG_UI_CUSTOM.run,\n value: {\n runId: this.options.streamRunId,\n threadId: this.options.streamThreadId ?? this.options.threadId,\n },\n },\n ];\n }\n\n /** The AG-UI events the next frame of the library stream stands for (possibly none). */\n encode(frame: AgUiSourceFrame): AgUiEvent[] {\n const position = this.position;\n this.position += 1;\n if (this.closed) return [];\n const skip = this.options.skip ?? 0;\n if (!this.crossed && position >= skip) this.crossBoundary();\n const events = this.project(frame, position);\n // A frame an earlier AG-UI run already delivered still moves the state (what is open, what is\n // pending; NOT what was spent — usage is per run) but writes nothing. The last of them is the\n // boundary: crossed at once, not when the next frame happens to arrive, because a run that was\n // just answered may take a moment to write one.\n if (position < skip) {\n if (this.position >= skip) this.crossBoundary();\n return [];\n }\n return events;\n }\n\n /**\n * The replayed frames are behind us: from here on events are written. The AG-UI run that delivered\n * them closed everything it had open before it finished, so this run starts with nothing open, and\n * what the resuming request answered is no longer waiting.\n */\n private crossBoundary(): void {\n this.crossed = true;\n this.openText = undefined;\n this.openReasoning = undefined;\n this.stepMessage = undefined;\n this.openSteps.length = 0;\n for (const call of this.calls.values()) {\n call.started = false;\n call.ended = true;\n }\n for (const id of this.options.answered ?? []) this.pending.delete(id);\n }\n\n private get replaying(): boolean {\n return this.position <= (this.options.skip ?? 0);\n }\n\n private project(event: AgUiSourceFrame, position: number): AgUiEvent[] {\n switch (event.kind) {\n case 'error': {\n this.closed = true;\n const usage = this.usageEntries();\n return [\n {\n type: 'RUN_ERROR',\n message: event.message,\n code: event.code,\n ...(usage.length > 0 ? { usage } : {}),\n },\n ];\n }\n case 'ui':\n return [\n this.custom(AG_UI_CUSTOM.ui, {\n id: event.id ?? `ui:${position}`,\n component: event.component,\n props: event.props,\n ...(event.version !== undefined ? { version: event.version } : {}),\n ...(event.toolCallId !== undefined ? { toolCallId: event.toolCallId } : {}),\n }),\n ];\n case 'approval-requested': {\n const call = this.calls.get(event.id);\n const parked = event.runId ?? this.options.streamRunId;\n const toolName = event.toolName ?? call?.name ?? '';\n const input = event.input ?? call?.input ?? null;\n this.pending.set(event.id, {\n kind: 'approval',\n parked,\n toolCallId: event.id,\n interrupt: {\n reason: 'tool_approval',\n message: event.reason ?? (toolName.length > 0 ? `Approve ${toolName}?` : 'Approve?'),\n toolCallId: event.id,\n responseSchema: APPROVAL_SCHEMA,\n ...(event.expiresAt !== undefined ? { expiresAt: event.expiresAt } : {}),\n metadata: {\n 'agora.toolName': toolName,\n 'agora.input': input,\n 'agora.approver': event.approver,\n },\n },\n });\n return [\n this.custom(AG_UI_CUSTOM.approvalRequested, {\n id: event.id,\n runId: parked,\n toolName,\n input,\n approver: event.approver,\n ...(event.expiresAt !== undefined ? { expiresAt: event.expiresAt } : {}),\n ...(event.reason !== undefined ? { reason: event.reason } : {}),\n }),\n ];\n }\n case 'elicitation': {\n const parked = event.runId ?? this.options.streamRunId;\n this.pending.set(event.id, {\n kind: 'elicitation',\n parked,\n toolCallId: event.id,\n interrupt: {\n reason: 'input_required',\n message:\n event.request.preamble ?? event.request.questions[0]?.prompt ?? 'Input required',\n // An intake's question set belongs to no tool call the stream announced.\n ...(this.calls.has(event.id) ? { toolCallId: event.id } : {}),\n responseSchema: elicitationSchema(event.request),\n metadata: { 'agora.request': event.request },\n },\n });\n return [this.custom(AG_UI_CUSTOM.elicitation, { runId: parked, request: event.request })];\n }\n case 'text':\n return event.text.length > 0 ? this.textDelta(event.text) : [];\n case 'reasoning':\n return event.text.length > 0 ? this.reasoningDelta(event.text) : [];\n case 'step-start': {\n this.stepSeq += 1;\n const stepName = `step-${this.stepSeq}`;\n this.openSteps.push(stepName);\n this.stepMessage = undefined;\n return [...this.closeStreams(), { type: 'STEP_STARTED', stepName }];\n }\n case 'step-finish': {\n const out = this.closeStreams();\n if (!this.replaying) this.addUsage(event.usage, event.model);\n const stepName = this.openSteps.pop();\n if (stepName !== undefined) out.push({ type: 'STEP_FINISHED', stepName });\n if (event.usage !== undefined || event.costUsd !== undefined) {\n out.push(\n this.custom(AG_UI_CUSTOM.stepUsage, {\n ...(event.usage !== undefined ? { usage: event.usage } : {}),\n ...(event.costUsd !== undefined ? { costUsd: event.costUsd } : {}),\n ...(event.reasoningMs !== undefined ? { reasoningMs: event.reasoningMs } : {}),\n }),\n );\n }\n return out;\n }\n case 'tool-input-start': {\n if (this.calls.has(event.id)) return [];\n const out = this.closeStreams();\n this.calls.set(event.id, {\n name: event.name,\n started: true,\n ended: false,\n sawDelta: false,\n answered: false,\n });\n out.push(this.callStart(event.id, event.name));\n return out;\n }\n case 'tool-input-delta': {\n const call = this.calls.get(event.id);\n if (call === undefined || call.ended || event.delta.length === 0) return [];\n call.sawDelta = true;\n return [{ type: 'TOOL_CALL_ARGS', toolCallId: event.id, delta: event.delta }];\n }\n case 'tool-input-available': {\n const known = this.calls.get(event.id);\n if (known?.ended === true) return [];\n const out = this.closeStreams();\n const call = known ?? {\n name: event.name,\n started: false,\n ended: false,\n sawDelta: false,\n answered: false,\n };\n if (!call.started) {\n call.started = true;\n out.push(this.callStart(event.id, event.name));\n }\n if (!call.sawDelta) {\n out.push({\n type: 'TOOL_CALL_ARGS',\n toolCallId: event.id,\n delta: text(event.input ?? {}),\n });\n }\n call.ended = true;\n call.input = event.input;\n this.calls.set(event.id, call);\n out.push({ type: 'TOOL_CALL_END', toolCallId: event.id });\n return out;\n }\n case 'tool-output':\n return this.result(event.id, text(event.output));\n case 'tool-output-error':\n return this.result(event.id, event.error, { 'agora.outcome': 'error' });\n case 'tool-output-denied':\n return this.result(event.id, event.reason ?? 'denied', { 'agora.outcome': 'denied' });\n case 'approval-settled':\n this.pending.delete(event.id);\n return [this.custom(AG_UI_CUSTOM.approvalSettled, event)];\n case 'title':\n return [this.custom(AG_UI_CUSTOM.title, { title: event.title })];\n case 'queue':\n return [\n this.custom(AG_UI_CUSTOM.queue, {\n queue: event.queue,\n ...(event.started !== undefined ? { started: event.started } : {}),\n }),\n ];\n case 'cancelled':\n this.cancelled = true;\n return [];\n default:\n // A kind newer than this encoder: tolerated, as every reader of the stream must.\n return [];\n }\n }\n\n /**\n * The events that end the AG-UI run: whatever is still open is closed first, then `RUN_FINISHED`\n * with how it ended — interrupted when the run is waiting on someone, cancelled when it was\n * stopped, success otherwise. Nothing after a `RUN_ERROR`. `ended` says the library run's stream\n * itself ended, rather than this reader having stopped following it.\n */\n finish(ended = false): AgUiEvent[] {\n if (this.closed) return [];\n this.closed = true;\n if (!this.crossed) this.crossBoundary();\n // A library run that ended is waiting on no one, whatever it asked along the way.\n if (ended) this.pending.clear();\n const out = this.start();\n out.push(...this.closeStreams());\n for (const [id, call] of this.calls) {\n if (call.started && !call.ended) {\n call.ended = true;\n out.push({ type: 'TOOL_CALL_END', toolCallId: id });\n }\n }\n while (this.openSteps.length > 0) {\n out.push({ type: 'STEP_FINISHED', stepName: this.openSteps.pop() as string });\n }\n const usage = this.usageEntries();\n const interrupts = this.cancelled ? [] : this.interrupts();\n out.push({\n type: 'RUN_FINISHED',\n threadId: this.options.threadId,\n runId: this.options.runId,\n ...(this.cancelled\n ? { outcome: { type: 'cancelled' as const } }\n : interrupts.length > 0\n ? { outcome: { type: 'interrupt' as const, interrupts } }\n : {}),\n ...(usage.length > 0 ? { usage } : {}),\n });\n return out;\n }\n\n private interrupts(): AgUiInterrupt[] {\n return [...this.pending.values()].map((entry) => ({\n id: encodeInterruptId({\n kind: entry.kind,\n parked: entry.parked,\n stream: this.options.streamRunId,\n toolCallId: entry.toolCallId,\n position: this.position,\n }),\n ...entry.interrupt,\n }));\n }\n\n private custom(name: string, value: unknown): AgUiEvent {\n return { type: 'CUSTOM', name, value };\n }\n\n private nextMessageId(): string {\n this.messageSeq += 1;\n return `${this.options.runId}:m${this.messageSeq}`;\n }\n\n private textDelta(delta: string): AgUiEvent[] {\n const out: AgUiEvent[] = [];\n if (this.openReasoning !== undefined) out.push(...this.closeReasoning());\n if (this.openText === undefined) {\n this.openText = this.nextMessageId();\n this.stepMessage = this.openText;\n out.push({ type: 'TEXT_MESSAGE_START', messageId: this.openText, role: 'assistant' });\n }\n out.push({ type: 'TEXT_MESSAGE_CONTENT', messageId: this.openText, delta });\n return out;\n }\n\n private reasoningDelta(delta: string): AgUiEvent[] {\n const out: AgUiEvent[] = [];\n if (this.openText !== undefined) out.push(...this.closeText());\n if (this.openReasoning === undefined) {\n this.openReasoning = this.nextMessageId();\n out.push(\n { type: 'REASONING_START', messageId: this.openReasoning },\n { type: 'REASONING_MESSAGE_START', messageId: this.openReasoning, role: 'reasoning' },\n );\n }\n out.push({ type: 'REASONING_MESSAGE_CONTENT', messageId: this.openReasoning, delta });\n return out;\n }\n\n private closeText(): AgUiEvent[] {\n if (this.openText === undefined) return [];\n const messageId = this.openText;\n this.openText = undefined;\n return [{ type: 'TEXT_MESSAGE_END', messageId }];\n }\n\n private closeReasoning(): AgUiEvent[] {\n if (this.openReasoning === undefined) return [];\n const messageId = this.openReasoning;\n this.openReasoning = undefined;\n return [\n { type: 'REASONING_MESSAGE_END', messageId },\n { type: 'REASONING_END', messageId },\n ];\n }\n\n private closeStreams(): AgUiEvent[] {\n return [...this.closeReasoning(), ...this.closeText()];\n }\n\n private callStart(id: string, name: string): AgUiEvent {\n return {\n type: 'TOOL_CALL_START',\n toolCallId: id,\n toolCallName: name,\n ...(this.stepMessage !== undefined ? { parentMessageId: this.stepMessage } : {}),\n };\n }\n\n private result(id: string, content: string, metadata?: Record<string, unknown>): AgUiEvent[] {\n const call = this.calls.get(id);\n if (call !== undefined) call.answered = true;\n else {\n this.calls.set(id, {\n name: '',\n started: false,\n ended: true,\n sawDelta: false,\n answered: true,\n });\n }\n this.pending.delete(id);\n return [\n ...this.closeStreams(),\n {\n type: 'TOOL_CALL_RESULT',\n messageId: `${this.options.runId}:tool:${id}`,\n toolCallId: id,\n content,\n role: 'tool',\n ...(metadata !== undefined ? { metadata } : {}),\n },\n ];\n }\n\n private addUsage(usage: MessageUsage | undefined, model: unknown): void {\n if (usage === undefined) return;\n const name = typeof model === 'string' && model.length > 0 ? model : this.options.model;\n const key = name ?? '';\n const entry = this.usage.get(key) ?? (name !== undefined ? { model: name } : {});\n // The library's accounting is already the protocol's: input and output are totals, cache and\n // reasoning counts are parts of them. A count the provider did not report stays absent.\n entry.inputTokens = (entry.inputTokens ?? 0) + usage.inputTokens;\n entry.outputTokens = (entry.outputTokens ?? 0) + usage.outputTokens;\n entry.totalTokens = entry.inputTokens + entry.outputTokens;\n if (usage.cacheReadTokens !== undefined) {\n entry.cachedInputTokens = (entry.cachedInputTokens ?? 0) + usage.cacheReadTokens;\n }\n if (usage.cacheWriteTokens !== undefined) {\n entry.cacheWriteInputTokens = (entry.cacheWriteInputTokens ?? 0) + usage.cacheWriteTokens;\n }\n if (usage.reasoningTokens !== undefined) {\n entry.reasoningTokens = (entry.reasoningTokens ?? 0) + usage.reasoningTokens;\n }\n this.usage.set(key, entry);\n }\n\n private usageEntries(): AgUiTokenUsage[] {\n return [...this.usage.values()];\n }\n}\n","import {\n type GenuiValidation,\n type JsonSchema,\n type JsonSchemaValidator,\n type PropsSchema,\n builtinJsonSchemaValidator,\n toJsonSchema,\n validateProps,\n validatePropsSync,\n} from './schema.js';\n\n/**\n * One component a server may push into a conversation. Data only — how it LOOKS is each app's own\n * renderer, looked up by {@link name}. The same definition serves the model (description + props\n * schema), the server (validation), text-only channels ({@link fallbackText}) and the client\n * (validation before rendering).\n */\nexport interface ComponentDefinition<P = Record<string, unknown>> {\n /** Registry key, e.g. `DataTable`. What a `ui` frame's `component` names. */\n name: string;\n /** Human label: \"Data table\". */\n title: string;\n /** Shown to the model: what the component is for and when to use it. */\n description: string;\n /** The props schema: a Standard Schema (Zod, Valibot, ArkType) or a JSON Schema object. */\n props: PropsSchema;\n /**\n * The component takes nested elements (a layout: `Stack`, `Card`). Only meaningful in tree mode,\n * where a node's `children` are validated against the catalog too.\n */\n children?: boolean;\n /**\n * Plain text / Slack mrkdwn rendering of these props, for a channel that cannot draw the\n * component. Absent → {@link componentToText} prints the props as JSON.\n */\n fallbackText?: (props: P) => string;\n /**\n * Pushed by the server (e.g. an approval card), never offered to the model. Excluded from\n * {@link catalogToModelText} and from the tool factories.\n */\n internal?: boolean;\n /**\n * Schema version of {@link props}. Stamped on every `ui` frame the component is pushed with, so a\n * client can keep rendering messages persisted under an older shape.\n */\n version?: number;\n}\n\n/** Component names: an identifier a registry key, a tool name and a snake_case slug can all be derived from. */\nexport const COMPONENT_NAME = /^[A-Za-z][A-Za-z0-9]{0,63}$/;\n\n/** Declare a component. Validates the name and returns the definition unchanged (typed). */\nexport function defineComponent<P = Record<string, unknown>>(\n definition: ComponentDefinition<P>,\n): ComponentDefinition<P> {\n if (!COMPONENT_NAME.test(definition.name)) {\n throw new Error(\n `genui: component name \"${definition.name}\" must be letters and digits, starting with a letter (e.g. DataTable)`,\n );\n }\n if (\n definition.version !== undefined &&\n (!Number.isSafeInteger(definition.version) || definition.version <= 0)\n )\n throw new RangeError('genui: component version must be a positive safe integer');\n if (definition.fallbackText !== undefined && typeof definition.fallbackText !== 'function')\n throw new TypeError('genui: fallbackText must be a function');\n return definition;\n}\n\nexport interface CatalogOptions {\n /** How JSON Schema props are checked. Default: {@link builtinJsonSchemaValidator}; pass `ajvValidator(new Ajv())` for full JSON Schema. */\n jsonSchemaValidator?: JsonSchemaValidator;\n}\n\n/** An immutable set of component definitions, looked up by name. */\nexport interface Catalog {\n readonly components: readonly ComponentDefinition<any>[];\n readonly validator: JsonSchemaValidator;\n get(name: string): ComponentDefinition<any> | undefined;\n has(name: string): boolean;\n /** The components a model may be offered (every non-`internal` one). */\n modelComponents(): ComponentDefinition<any>[];\n /** Validate `props` for `component`. An unknown component is a validation failure, not a throw. */\n validate(component: string, props: unknown): Promise<GenuiValidation<Record<string, unknown>>>;\n /**\n * {@link validate} without waiting — `undefined` only when the component's Standard Schema\n * validates asynchronously. An unknown component is a failure, as in `validate`.\n */\n validateSync(\n component: string,\n props: unknown,\n ): GenuiValidation<Record<string, unknown>> | undefined;\n /** The component's props as JSON Schema, when it can be derived (see {@link toJsonSchema}). */\n jsonSchemaFor(component: string): JsonSchema | undefined;\n /** A new catalog with these components added (a later definition replaces an earlier one of the same name). */\n extend(components: readonly ComponentDefinition<any>[]): Catalog;\n}\n\n/**\n * Collect component definitions into a {@link Catalog}. Names must be unique; to override a\n * definition (e.g. a builtin), use {@link Catalog.extend}.\n */\nexport function defineCatalog(\n components: readonly ComponentDefinition<any>[],\n options: CatalogOptions = {},\n): Catalog {\n const byName = new Map<string, ComponentDefinition<any>>();\n for (const component of components) {\n defineComponent(component);\n if (byName.has(component.name)) {\n throw new Error(`genui: component \"${component.name}\" is defined twice in one catalog`);\n }\n byName.set(component.name, component);\n }\n return buildCatalog(byName, options.jsonSchemaValidator ?? builtinJsonSchemaValidator);\n}\n\nfunction buildCatalog(\n byName: Map<string, ComponentDefinition<any>>,\n validator: JsonSchemaValidator,\n): Catalog {\n const list = Object.freeze([...byName.values()]);\n return {\n components: list,\n validator,\n get: (name) => byName.get(name),\n has: (name) => byName.has(name),\n modelComponents: () => list.filter((component) => component.internal !== true),\n async validate(component, props) {\n const definition = byName.get(component);\n if (definition === undefined) {\n return {\n ok: false,\n issues: [{ path: [], message: `unknown component \"${component}\"` }],\n };\n }\n const result = await validateProps(definition.props, props, validator);\n return result as GenuiValidation<Record<string, unknown>>;\n },\n validateSync(component, props) {\n const definition = byName.get(component);\n if (definition === undefined) {\n return {\n ok: false,\n issues: [{ path: [], message: `unknown component \"${component}\"` }],\n };\n }\n return validatePropsSync(definition.props, props, validator) as\n | GenuiValidation<Record<string, unknown>>\n | undefined;\n },\n jsonSchemaFor(component) {\n const definition = byName.get(component);\n return definition === undefined ? undefined : toJsonSchema(definition.props);\n },\n extend(more) {\n const next = new Map(byName);\n for (const component of more) {\n defineComponent(component);\n next.set(component.name, component);\n }\n return buildCatalog(next, validator);\n },\n };\n}\n\n/** `DataTable` → `data_table`, `KPICards` → `kpi_cards`. */\nexport function toSnakeCase(name: string): string {\n return name\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')\n .replace(/[^a-zA-Z0-9]+/g, '_')\n .toLowerCase();\n}\n\n/** The per-component tool name: `ui__show_data_table` with the default prefix. */\nexport function toolNameFor(component: string, prefix = 'ui__show_'): string {\n return `${prefix}${toSnakeCase(component)}`;\n}\n","import { COMPONENT_NAME, type Catalog, defineCatalog } from './catalog.js';\nimport { formatIssues } from './schema.js';\nimport { componentToText, treeToText } from './text.js';\nimport { GENUI_TREE_COMPONENT, type GenuiElement, validateTree } from './tree.js';\n\n/** Renderer support only. Component definitions and authorization remain server-owned. */\nexport interface UiCapabilities {\n components: Array<{ name: string; version: number }>;\n}\n\nexport function validateUiCapabilities(value: unknown): UiCapabilities {\n if (\n !record(value) ||\n Object.keys(value).some((key) => key !== 'components') ||\n !Array.isArray(value.components)\n )\n throw new TypeError('Invalid UI capabilities');\n const seen = new Set<string>();\n const components = value.components.map((component: unknown) => {\n if (\n !record(component) ||\n Object.keys(component).some((key) => key !== 'name' && key !== 'version') ||\n typeof component.name !== 'string' ||\n !COMPONENT_NAME.test(component.name) ||\n !Number.isSafeInteger(component.version) ||\n Number(component.version) <= 0 ||\n seen.has(component.name)\n )\n throw new TypeError('Invalid UI component capability');\n seen.add(component.name);\n return { name: component.name, version: Number(component.version) };\n });\n return { components };\n}\n\nfunction record(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function negotiateCatalog(catalog: Catalog, capabilities?: UiCapabilities): Catalog {\n if (capabilities === undefined) return catalog;\n const supported = validateUiCapabilities(capabilities).components;\n return defineCatalog(\n catalog.components.filter((component) =>\n supported.some(\n (entry) => entry.name === component.name && entry.version === (component.version ?? 1),\n ),\n ),\n { jsonSchemaValidator: catalog.validator },\n );\n}\n\nexport type PreparedUiEmission =\n | {\n kind: 'ui';\n component: string;\n props: Record<string, unknown>;\n version: number;\n fallbackText: string;\n componentVersions?: Record<string, number>;\n }\n | { kind: 'text'; text: string };\n\n/** Validate against current trusted definitions before drawing or generating complete text. */\nexport async function prepareUiEmission(\n catalog: Catalog,\n capabilities: UiCapabilities | undefined,\n component: string,\n props: Record<string, unknown>,\n version?: number,\n): Promise<PreparedUiEmission> {\n const drawable = negotiateCatalog(catalog, capabilities);\n if (component === GENUI_TREE_COMPONENT) {\n if (version !== undefined && version !== 1) throw new Error('Invalid UI tree version');\n const validated = await validateTree(catalog, props.root);\n if (!validated.ok) throw new Error(`Invalid UI tree: ${formatIssues(validated.issues)}`);\n const supported = (node: GenuiElement): boolean =>\n drawable.has(node.type) && (node.children ?? []).every(supported);\n const versions = new Map<string, number>();\n const collectVersions = (node: GenuiElement): void => {\n versions.set(node.type, catalog.get(node.type)?.version ?? 1);\n for (const child of node.children ?? []) collectVersions(child);\n };\n collectVersions(validated.value);\n return supported(validated.value)\n ? {\n kind: 'ui',\n component,\n props: { root: validated.value },\n version: 1,\n fallbackText: treeToText(catalog, validated.value),\n componentVersions: Object.fromEntries(versions),\n }\n : { kind: 'text', text: treeToText(catalog, validated.value) };\n }\n const definition = catalog.get(component);\n if (definition === undefined) throw new Error(`Unknown UI component \"${component}\"`);\n const currentVersion = definition.version ?? 1;\n if (version !== undefined && version !== currentVersion)\n throw new Error(`Invalid UI component version for \"${component}\"`);\n const validated = await catalog.validate(component, props);\n if (!validated.ok) throw new Error(`Invalid UI props: ${formatIssues(validated.issues)}`);\n return drawable.has(component)\n ? {\n kind: 'ui',\n component,\n props: validated.value,\n version: currentVersion,\n fallbackText: componentToText(catalog, component, validated.value),\n }\n : { kind: 'text', text: componentToText(catalog, component, validated.value) };\n}\n","import { type UiCapabilities, validateUiCapabilities } from '../genui/capabilities.js';\nimport { type InterruptAddress, decodeInterruptId } from './interrupt-id.js';\nimport type {\n AgUiContentPart,\n AgUiContext,\n AgUiMessage,\n AgUiResumeEntry,\n AgUiRunInput,\n} from './types.js';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Read a request body as a `RunAgentInput`, or say why it is not one.\n *\n * Only what this producer acts on is checked, and a KNOWN member with a value the schema rejects is\n * malformed (the run never starts). A member it does not recognise is not an error — the protocol's\n * asymmetry: a newer consumer's input must not bounce off an older producer.\n */\nexport function parseRunInput(body: unknown): AgUiRunInput | string {\n if (!isRecord(body)) return 'the body must be a RunAgentInput object';\n if (typeof body.threadId !== 'string' || body.threadId.length === 0) {\n return 'threadId must be a non-empty string';\n }\n if (body.threadId.length > 255) return 'threadId must be at most 255 characters';\n if (typeof body.runId !== 'string' || body.runId.length === 0) {\n return 'runId must be a non-empty string';\n }\n if (!Array.isArray(body.messages)) return 'messages must be an array';\n for (const message of body.messages) {\n if (!isRecord(message) || typeof message.role !== 'string') {\n return 'each message must be an object with a role';\n }\n }\n if (body.resume !== undefined) {\n if (!Array.isArray(body.resume)) return 'resume must be an array';\n for (const entry of body.resume) {\n if (\n !isRecord(entry) ||\n typeof entry.interruptId !== 'string' ||\n (entry.status !== 'resolved' && entry.status !== 'cancelled')\n ) {\n return \"each resume entry needs an interruptId and a status of 'resolved' or 'cancelled'\";\n }\n }\n }\n if (body.context !== undefined && !Array.isArray(body.context)) {\n return 'context must be an array';\n }\n if (isRecord(body.forwardedProps) && Object.hasOwn(body.forwardedProps, 'uiCapabilities')) {\n try {\n validateUiCapabilities(body.forwardedProps.uiCapabilities);\n } catch {\n return 'forwardedProps.uiCapabilities must be valid UI capabilities';\n }\n }\n return body as unknown as AgUiRunInput;\n}\n\n/** A media part carried inline, ready to be staged as an attachment. */\nexport interface InlineMedia {\n kind: 'image' | 'audio' | 'video' | 'document';\n contentType: string;\n data: Buffer;\n filename: string;\n}\n\nexport interface UserTurn {\n /** The text of the message the run answers. */\n text: string;\n media: InlineMedia[];\n /** Why a part was not used, one sentence each — reported, never fatal. */\n dropped: string[];\n}\n\nconst EXTENSIONS: Record<string, string> = {\n 'image/png': 'png',\n 'image/jpeg': 'jpg',\n 'image/gif': 'gif',\n 'image/webp': 'webp',\n 'application/pdf': 'pdf',\n 'text/plain': 'txt',\n};\n\nfunction filenameOf(part: AgUiContentPart, index: number, contentType: string): string {\n const metadata = (part as { metadata?: unknown }).metadata;\n if (isRecord(metadata)) {\n for (const key of ['filename', 'name', 'title']) {\n const value = metadata[key];\n if (typeof value === 'string' && value.trim().length > 0) return value.trim().slice(0, 200);\n }\n }\n const extension = EXTENSIONS[contentType];\n return `${part.type}-${index + 1}${extension !== undefined ? `.${extension}` : ''}`;\n}\n\n/**\n * The turn a run answers: the LAST user message of the input. The library keeps each thread's\n * history itself, so the earlier messages the consumer restates are not read back in — what the\n * agent resumes from is what it stored.\n *\n * Multimodal parts: text parts are the message's text; a media part carried inline (`data`) becomes\n * an attachment. A part by `url` or by provider `file` handle is dropped and said so — this producer\n * hands the model only bytes it staged itself, never an address a caller supplied.\n */\nexport function readUserTurn(messages: readonly AgUiMessage[]): UserTurn | null {\n let last: AgUiMessage | undefined;\n for (let index = messages.length - 1; index >= 0; index -= 1) {\n if (messages[index]?.role === 'user') {\n last = messages[index];\n break;\n }\n }\n if (last === undefined) return null;\n if (typeof last.content === 'string') return { text: last.content, media: [], dropped: [] };\n if (!Array.isArray(last.content)) return { text: '', media: [], dropped: [] };\n\n const texts: string[] = [];\n const media: InlineMedia[] = [];\n const dropped: string[] = [];\n last.content.forEach((part, index) => {\n if (!isRecord(part)) return;\n if (part.type === 'text') {\n if (typeof part.text === 'string') texts.push(part.text);\n return;\n }\n if (\n part.type !== 'image' &&\n part.type !== 'audio' &&\n part.type !== 'video' &&\n part.type !== 'document'\n ) {\n return;\n }\n const source = part.source;\n if (!isRecord(source) || source.type !== 'data') {\n const how = isRecord(source) && typeof source.type === 'string' ? source.type : 'unknown';\n dropped.push(\n `The ${part.type} part ${index + 1} was not used: only inline data is accepted, not a ${how} source.`,\n );\n return;\n }\n if (typeof source.value !== 'string' || typeof source.mimeType !== 'string') {\n dropped.push(\n `The ${part.type} part ${index + 1} was not used: its inline data is malformed.`,\n );\n return;\n }\n const data = Buffer.from(source.value, 'base64');\n if (data.length === 0) {\n dropped.push(`The ${part.type} part ${index + 1} was not used: it carries no bytes.`);\n return;\n }\n const contentType = source.mimeType.toLowerCase();\n media.push({\n kind: part.type,\n contentType,\n data,\n filename: filenameOf(part as AgUiContentPart, index, contentType),\n });\n });\n return { text: texts.join('\\n'), media, dropped };\n}\n\n/** `context` entries as the library's page context carries them, or `undefined` for none. */\nexport function readContext(\n context: readonly AgUiContext[] | undefined,\n): AgUiContext[] | undefined {\n if (context === undefined) return undefined;\n const entries = context.filter(\n (entry) =>\n isRecord(entry) && typeof entry.description === 'string' && typeof entry.value === 'string',\n );\n return entries.length > 0 ? entries : undefined;\n}\n\n/**\n * What the library reads from `forwardedProps` — the consumer's channel for what AG-UI does not\n * model: which agent, which model, which persona, and the page context the tools see.\n */\nexport interface ForwardedOptions {\n uiCapabilities?: UiCapabilities;\n agent?: string;\n model?: string;\n persona?: string;\n pageContext?: Record<string, unknown>;\n}\n\nexport function readForwardedProps(forwarded: unknown): ForwardedOptions {\n if (!isRecord(forwarded)) return {};\n const pick = (key: string): string | undefined => {\n const value = forwarded[key];\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n };\n const agent = pick('agent');\n const model = pick('model');\n const persona = pick('persona');\n return {\n ...(Object.hasOwn(forwarded, 'uiCapabilities')\n ? { uiCapabilities: validateUiCapabilities(forwarded.uiCapabilities) }\n : {}),\n ...(agent !== undefined ? { agent } : {}),\n ...(model !== undefined ? { model } : {}),\n ...(persona !== undefined ? { persona } : {}),\n ...(isRecord(forwarded.pageContext) ? { pageContext: forwarded.pageContext } : {}),\n };\n}\n\n/** One resume entry this producer can act on. */\nexport interface ResumeDecision {\n address: InterruptAddress;\n entry: AgUiResumeEntry;\n}\n\nexport interface ResumePlan {\n decisions: ResumeDecision[];\n /** Entries naming an interrupt this producer did not raise: skipped with a warning, never fatal. */\n unrecognised: string[];\n}\n\n/**\n * Sort a resume list into what it answers. Every recognised entry must continue the SAME library\n * run from the SAME point — they are the interrupts of one `RUN_FINISHED` — and a list that does not\n * is malformed (a string says why).\n */\nexport function planResume(resume: readonly AgUiResumeEntry[]): ResumePlan | string {\n const decisions: ResumeDecision[] = [];\n const unrecognised: string[] = [];\n for (const entry of resume) {\n const address = decodeInterruptId(entry.interruptId);\n if (address === null) {\n unrecognised.push(entry.interruptId);\n continue;\n }\n decisions.push({ address, entry });\n }\n const first = decisions[0];\n if (first === undefined) return { decisions, unrecognised };\n for (const { address } of decisions) {\n if (address.stream !== first.address.stream || address.position !== first.address.position) {\n return 'the resume entries answer interrupts of different runs';\n }\n }\n const seen = new Set<string>();\n for (const { address } of decisions) {\n if (seen.has(address.toolCallId)) return 'an interrupt is answered twice';\n seen.add(address.toolCallId);\n }\n return { decisions, unrecognised };\n}\n\n/** `{ approved, reason?, remember? }` out of an approval's resume payload. A bare boolean is accepted. */\nexport function readApprovalPayload(payload: unknown): {\n approved: boolean;\n reason?: string;\n remember?: boolean;\n} | null {\n if (typeof payload === 'boolean') return { approved: payload };\n if (!isRecord(payload) || typeof payload.approved !== 'boolean') return null;\n return {\n approved: payload.approved,\n ...(typeof payload.reason === 'string' ? { reason: payload.reason } : {}),\n ...(typeof payload.remember === 'boolean' ? { remember: payload.remember } : {}),\n };\n}\n\n/** `questionId → string[]` out of an elicitation's resume payload (`{ answers }` or the map itself). */\nexport function readAnswersPayload(payload: unknown): Record<string, string[]> | null {\n const source = isRecord(payload) && isRecord(payload.answers) ? payload.answers : payload;\n if (!isRecord(source)) return null;\n const answers: Record<string, string[]> = {};\n for (const [key, value] of Object.entries(source)) {\n if (typeof value === 'string') answers[key] = [value];\n else if (Array.isArray(value) && value.every((item) => typeof item === 'string')) {\n answers[key] = value as string[];\n } else return null;\n }\n return answers;\n}\n","/**\n * The \"data plane\": live token transport, decoupled from the durable control plane.\n *\n * The model turn writes deltas to a `SinkWriter` keyed by runId; the HTTP layer\n * `subscribe`s by runId and pipes the chunks to the browser as SSE. A late subscriber\n * (reconnect/resume) replays buffered chunks first, then follows live — which is what\n * makes streaming survive a dropped connection or a pod restart.\n */\nexport interface SinkWriter {\n write(chunk: Uint8Array): void | Promise<void>;\n /** Mark the run's stream finished (no more chunks). */\n end(): void | Promise<void>;\n /**\n * Terminate the run's stream with an error instead of a normal end. Subscribers replay any\n * buffered chunks first, then throw an {@link AgentStreamError} carrying this `code`/`message`\n * — so the transport can surface a typed failure frame instead of leaking it as assistant text.\n */\n fail(error: StreamError): void | Promise<void>;\n /**\n * OPTIONAL: write out anything this writer is still holding back, without ending the stream. Only\n * a sink that gathers frames before writing them (the SQL sink coalesces text) has anything to do\n * here; a delegated run's child writer calls it where it would have ended the stream, so nothing\n * of the delegate's is still held back when its parent — possibly on another replica — writes next.\n */\n flush?(): void | Promise<void>;\n}\n\n/** A machine-readable stream failure. `code` is a stable slug; `message` is human-facing. */\nexport interface StreamError {\n code: string;\n message: string;\n}\n\n/**\n * Thrown out of {@link TokenStreamSink.subscribe} when a run ended via {@link SinkWriter.fail}.\n * Carries the structured {@link StreamError} so the HTTP layer can emit an `event: error` frame.\n */\nexport class AgentStreamError extends Error {\n readonly code: string;\n constructor(error: StreamError) {\n super(error.message);\n this.name = 'AgentStreamError';\n this.code = error.code;\n }\n}\n\nexport interface TokenStreamSink {\n /** Open (or reopen) the writer for a run. */\n open(runId: string): SinkWriter | Promise<SinkWriter>;\n /**\n * Replay buffered chunks for the run, then yield live ones until `end()`. Throws\n * {@link AgentStreamError} if the run was terminated with {@link SinkWriter.fail}.\n */\n subscribe(runId: string): AsyncIterable<Uint8Array>;\n /** Drop any buffer/resources for the run. */\n close(runId: string): void | Promise<void>;\n}\n","/**\n * The structured live-stream vocabulary carried over the {@link SinkWriter} byte channel.\n *\n * The model turn (via the AI-SDK adapter) and the agent loop write these events as NDJSON — one\n * `JSON.stringify(event)\\n` per {@link SinkWriter.write}. The HTTP layer forwards each line as an\n * SSE `data:` frame, and the client transport maps them back to the AI SDK UI-message chunk\n * protocol so the browser renders text, reasoning, and tool cards (input + output) LIVE — the same\n * rich rendering a raw `streamText().toUIMessageStream()` would give, but reconstructed on the\n * client so the sink stays a format-agnostic byte buffer (durable buffering/replay is untouched).\n *\n * Keeping this vocabulary neutral (not AI-SDK `UIMessageChunk`) means core never depends on `ai`:\n * the adapter owns model-parts → event, the transport owns event → UI-chunk.\n *\n * The vocabulary is also a CONTRACT for runners that are not this library's loop: anything that\n * writes these frames (one JSON object per SSE `data:` line) gets the React transport, transcript\n * model and hooks for free. Two rules keep it evolvable:\n * - every frame is a JSON object with a string `kind`; a reader MUST tolerate kinds it does not\n * know (the React transport forwards them as `data-<kind>` parts rather than dropping them);\n * - fields are only ever added, and new fields are optional.\n */\nimport type { ElicitationRequest } from './elicitation.js';\nimport type { ChatQueueState } from './spi/chat-queue.js';\nimport type { ToolConfirmation } from './tool-presentation.js';\nimport type { MessageUsage } from './types.js';\n\n/**\n * A component the server pushed into the conversation: generative UI that is NOT a tool call's\n * rendering. It is addressed by `component` (a key in the client's own component registry), never\n * by a tool name, so a runner can emit one from anywhere — a tool body, a post-processing step, a\n * sandboxed agent that renders through its own protocol.\n *\n * `id` is the component's identity within the message: a second frame with the same `id` REPLACES\n * the first (streaming props into a chart, flipping a card from \"loading\" to \"ready\"), it never\n * adds a second component.\n */\nexport interface AgentUiComponent {\n id: string;\n /** Registry key the client resolves to its own renderer, e.g. `data-table`. */\n component: string;\n props: Record<string, unknown>;\n /** Schema version of `props`, so a client can keep rendering components persisted by an older server. */\n version?: number;\n /** Validated readable fallback retained for clients without this renderer. */\n fallbackText?: string;\n /** Trusted schema versions for every component in a persisted tree. */\n componentVersions?: Record<string, number>;\n /**\n * The tool call that pushed the component (`ctx.emitUi`), when one did. Lets a client place it\n * with that call — a reloaded message puts it right after the call's tool part, where the live\n * stream showed it. Absent for a component pushed outside a tool.\n */\n toolCallId?: string;\n}\n\n/**\n * Who has to settle an action tool call, and until when. Metadata only: the call itself is still\n * settled through the tool-call approve/reject routes, by its `toolCallId`.\n */\nexport interface AgentApprovalRequest {\n target?: { kind: 'proposal'; proposalId: string };\n /** Resolved confirmation from the action preflight; overrides presentation templates. */\n confirmation?: ToolConfirmation;\n /** The tool call awaiting the decision — the `id` of a call already announced on this stream. */\n id: string;\n /**\n * Who may decide. Open vocabulary the host defines — `'requester'` (the person chatting),\n * `'admin'`, a role name, a team. A client uses it to say \"waiting on an admin\" instead of\n * offering buttons the viewer cannot use.\n */\n approver: string;\n /** ISO-8601 instant after which the request lapses. Absent → it never expires. */\n expiresAt?: string;\n /** Why this call needs a person, in words for that person. */\n reason?: string;\n}\n\n/**\n * How an approval settled — the other half of {@link AgentApprovalRequest}, under the same `id`.\n * Metadata again: the call's own outcome still arrives as `tool-output` (approved and ran),\n * `tool-output-error` (approved and failed) or `tool-output-denied` (rejected or expired).\n */\nexport interface AgentApprovalSettlement {\n id: string;\n status: 'approved' | 'rejected' | 'expired';\n /** Repeated from the request, for a call approved without one being streamed (a remembered approval). */\n approver?: string;\n /** Opaque ref of who decided. Absent on an expiry. */\n decidedBy?: string;\n /** The surface the decision came through: `'web'`, `'slack'`, `'remembered'`, … */\n decidedVia?: string;\n /** The approval also covers later calls of this tool in this thread. */\n remember?: boolean;\n /** What the person said when declining. */\n reason?: string;\n}\n\nexport type AgentStreamEvent =\n | { kind: 'step-start' }\n /**\n * Closes the step opened by the matching `step-start`. Carries the model call's token usage and\n * `costUsd` (an estimate from the bound pricing store, or `null` when unpriced/unbound — never a\n * fabricated `0`) so a live client can render running cost without waiting for a thread re-fetch.\n */\n | {\n kind: 'step-finish';\n usage?: MessageUsage;\n costUsd?: number | null;\n /**\n * How long the model spent thinking in this step, in ms — the same number persisted as\n * `StoredMessage.reasoningMs`, so a live thread and a reloaded one read the same duration.\n * Absent when the step had no reasoning.\n */\n reasoningMs?: number;\n /**\n * The model the step ran on: the one the provider reported, else the configured `modelId`.\n * What a per-model usage report keys on (the AG-UI producer's `RUN_FINISHED.usage`). Absent\n * when neither is known; a reader that does not know the field ignores it.\n */\n model?: string;\n }\n | { kind: 'text'; text: string }\n | { kind: 'reasoning'; text: string }\n /**\n * `toolKind` collapses `ToolKind`'s `'agent'` into `'read'` — delegation tools auto-execute like a read tool.\n *\n * `parentId` nests this call under another call on the same stream: the inner calls a code-mode\n * `execute` makes, the tools a delegated sub-agent runs. The parent must be announced first. A\n * call's parent is fixed by its first frame that names one; later frames may omit it.\n */\n | {\n kind: 'tool-input-start';\n id: string;\n name: string;\n toolKind: 'read' | 'action';\n parentId?: string;\n }\n | { kind: 'tool-input-delta'; id: string; delta: string }\n | {\n kind: 'tool-input-available';\n id: string;\n name: string;\n input: unknown;\n toolKind: 'read' | 'action';\n /** Same as on `tool-input-start`, for a runner that announces a call without streaming its input. */\n parentId?: string;\n }\n | { kind: 'tool-output'; id: string; output: unknown }\n | { kind: 'tool-output-error'; id: string; error: string }\n /**\n * A person was asked to approve an action tool and declined it. Its own frame, NOT\n * `tool-output-error`: a refusal is a decision with a known outcome — nothing ran — while a\n * failure is an outcome nobody chose and whose effects are unknown. Rendering them the same way\n * tells an operator their own \"no\" was a malfunction. Maps onto the SDK's `output-denied` tool\n * part state, which a client reads without knowing any tool's name.\n */\n | { kind: 'tool-output-denied'; id: string; reason?: string }\n /**\n * The run has put a question set to the user and is parked until someone answers it (or skips).\n * Written by the LOOP for both elicitation surfaces — the configured intake and the model's `ask`\n * tool — so a client renders one form either way rather than learning to recognise a tool name.\n * The matching `tool-output` frame, under the same `id`, carries the settled answers.\n */\n | { kind: 'elicitation'; id: string; request: ElicitationRequest }\n /**\n * An action tool call (already announced by `tool-input-start`/`tool-input-available` under the\n * same `id`) is parked on a person. Optional: a client still treats an `action` call stuck at\n * its input as pending — this frame adds WHO has to decide and UNTIL WHEN, and moves the call\n * into the AI SDK's native `approval-requested` state.\n */\n | ({ kind: 'approval-requested' } & AgentApprovalRequest)\n /**\n * A parked action call was decided (or lapsed). Optional, like `approval-requested`: it adds WHO\n * decided, THROUGH WHAT and whether the approval is REMEMBERED; the outcome itself rides the\n * call's own output frame. See {@link AgentApprovalSettlement}.\n */\n | ({ kind: 'approval-settled' } & AgentApprovalSettlement)\n /**\n * Server-pushed generative UI, positioned in the message where it arrives. Not tied to a tool\n * call. See {@link AgentUiComponent}.\n */\n | ({ kind: 'ui' } & AgentUiComponent)\n /**\n * The thread's title was set or changed while this run streamed (typically derived from the\n * first exchange). Thread-level, not message content: a client updates its header/sidebar and\n * does not render it in the transcript.\n */\n | { kind: 'title'; title: string }\n /**\n * Host-defined facts about the message being streamed (the model that answered, how long it took,\n * the error it ended with), merged into the client message's `metadata`. The persisted\n * counterpart is `StoredMessage.metadata`, so a reload reads the same values. The library's own\n * loop never writes it; a runner that is not this library's loop uses it for what its store keeps\n * per message.\n */\n | { kind: 'message-metadata'; metadata: Record<string, unknown> }\n /**\n * Someone stopped this run. The stream's LAST frame, written by the runner that settled the\n * cancel, immediately before a normal `end()` — never a `fail()`, because a cancel is not an\n * error and a client that retries on a failed stream must not retry this.\n *\n * A run that simply ends wrote everything it had; one that ends after this frame did not, and the\n * difference is the whole point: without it a reader cannot tell a truncated answer from a\n * complete one. Consumers that predate the frame ignore it and see the `end()` they always saw.\n */\n | { kind: 'cancelled' }\n /**\n * The thread's message queue changed — a snapshot of the whole queue, never a delta, so a client\n * that missed one frame is corrected by the next. Written into the stream of the run that is\n * holding the thread: when someone queues, edits, reorders or removes a waiting message, and, just\n * before this run's own terminal frame, with what happens next — `started` names the queued\n * message that became the next turn and that turn's run id (attach to it with\n * `GET <base>/chat/:runId/stream`), `queue.paused` says why nothing starts.\n */\n | { kind: 'queue'; queue: ChatQueueState; started?: { messageId: string; runId: string } };\n\nconst encoder = new TextEncoder();\n\n/** Encode one event as an NDJSON line (`{...}\\n`) for {@link SinkWriter.write}. */\nexport function encodeStreamEvent(event: AgentStreamEvent): Uint8Array {\n return encoder.encode(`${JSON.stringify(event)}\\n`);\n}\n\n/**\n * Read one NDJSON line back, or `null` when the line is not a stream event at all.\n *\n * `null` covers a genuinely opaque chunk, not just malformed JSON: the sink is a byte channel, so a\n * model provider is free to write anything into it and some write bare text. A caller that has to\n * CLASSIFY a chunk — the output gate, which may only forward what it can prove is not the answer —\n * treats an unreadable frame as unclassifiable rather than guessing.\n */\nexport function decodeStreamEvent(line: string): AgentStreamEvent | null {\n try {\n const parsed: unknown = JSON.parse(line);\n if (\n typeof parsed === 'object' &&\n parsed !== null &&\n typeof (parsed as AgentStreamEvent).kind === 'string'\n ) {\n return parsed as AgentStreamEvent;\n }\n } catch {\n /* not a stream event — the caller decides what an opaque chunk means */\n }\n return null;\n}\n\n/**\n * The `code` of a failed run's `event: error` frame — what a client branches on, and translates.\n * `quota_exceeded`, `output_rejected` and `structured_output_invalid` are outcomes the library words\n * itself (their `message` is safe to show as it is); the rest are crashes, whose `message` is a\n * generic sentence in production. Open-ended on purpose: a host's own runner may send other codes.\n */\nexport type AgentStreamErrorCode =\n | 'quota_exceeded'\n | 'output_rejected'\n | 'structured_output_invalid'\n /** The durable runtime refused a checkpoint position: the run's journal and its code disagree. */\n | 'replay_diverged'\n /** A model call ended without producing anything. */\n | 'model_no_output'\n | 'run_failed';\n","import { AgentStreamError } from '../spi/token-stream-sink.js';\nimport { decodeStreamEvent } from '../stream-events.js';\nimport { AgUiEncoder, type AgUiEncoderOptions } from './encoder.js';\nimport type { AgUiEvent, AgUiSourceFrame } from './types.js';\n\nexport interface AgUiStreamOptions extends AgUiEncoderOptions {\n /**\n * How long the library stream may stay silent, while the run waits on a person AND has other work\n * announced, before the AG-UI run is reported interrupted. Default 750 ms.\n *\n * Only that mixed case needs a clock. A run whose every open tool call is waiting on someone is\n * reported at once; a run waiting on no one is never cut short.\n */\n quietMs?: number;\n /** Events to write right after `RUN_STARTED` (warnings about input that was dropped). */\n preamble?: AgUiEvent[];\n}\n\nconst DEFAULT_QUIET_MS = 750;\nconst GRACE_MS = 50;\n\ntype Next = IteratorResult<AgUiSourceFrame> | 'quiet';\n\n/**\n * One AG-UI run over a library run's stream.\n *\n * AG-UI has no mid-run channel from the consumer: a run that needs an approval or an answer does not\n * wait with the connection open — it ENDS, saying what it waits for, and a later run carries the\n * answers. The library run underneath does wait (parked, durably when the runner is durable). So this\n * stops reading when the run is waiting on someone and nothing else is moving, closes the AG-UI run\n * with the interrupt outcome, and leaves the library run parked for the resume to pick up.\n */\nexport async function* agUiEvents(\n frames: AsyncIterable<AgUiSourceFrame>,\n options: AgUiStreamOptions,\n): AsyncGenerator<AgUiEvent> {\n const encoder = new AgUiEncoder(options);\n const quietMs = options.quietMs ?? DEFAULT_QUIET_MS;\n yield* encoder.start();\n yield* options.preamble ?? [];\n const iterator = frames[Symbol.asyncIterator]();\n let upcoming: Promise<IteratorResult<AgUiSourceFrame>> | undefined;\n let ended = false;\n try {\n for (;;) {\n upcoming ??= iterator.next();\n // Frames buffered before this reader attached are replayed without a pause between them, so\n // \"is it waiting?\" is only asked of a stream that has caught up with what it already holds.\n const caughtUp = encoder.consumed >= (options.skip ?? 0);\n let next: Next;\n if (caughtUp && encoder.waiting) {\n // Nothing else in flight: only a frame already on its way (a sink that reads in batches)\n // can still arrive, so a short grace is enough. Otherwise wait out the quiet window.\n next = await raceQuiet(upcoming, encoder.busy ? quietMs : Math.min(quietMs, GRACE_MS));\n } else {\n next = await upcoming;\n }\n if (next === 'quiet') break;\n upcoming = undefined;\n if (next.done === true) {\n ended = true;\n break;\n }\n yield* encoder.encode(next.value);\n }\n } finally {\n // Stop following the library stream; the run it carries is left exactly as it is.\n void iterator.return?.();\n }\n yield* encoder.finish(ended);\n}\n\nfunction raceQuiet(upcoming: Promise<IteratorResult<AgUiSourceFrame>>, ms: number): Promise<Next> {\n return new Promise<Next>((resolve, reject) => {\n const timer = setTimeout(() => resolve('quiet'), ms);\n upcoming.then(\n (result) => {\n clearTimeout(timer);\n resolve(result);\n },\n (error: unknown) => {\n clearTimeout(timer);\n reject(error);\n },\n );\n });\n}\n\n/** One AG-UI event as an SSE frame: a single `data:` line, LF-terminated, as the binding pins. */\nexport function agUiSse(event: AgUiEvent): string {\n return `data: ${JSON.stringify(event)}\\n\\n`;\n}\n\n/**\n * A byte sink's stream (NDJSON {@link AgentStreamEvent}s, one per line, as the NestJS sinks carry\n * it) as the frames the encoder reads. A line that is not a stream event is bare model text — the\n * sink is a byte channel and a provider may write raw text into it. A run that failed ends the\n * sink with an {@link AgentStreamError}, which becomes the terminal `error` frame; anything else\n * thrown is rethrown, for the caller to report.\n */\nexport async function* agUiFramesFromNdjson(\n chunks: AsyncIterable<Uint8Array>,\n): AsyncGenerator<AgUiSourceFrame> {\n const decoder = new TextDecoder();\n let buffer = '';\n // Bare text has no line end of its own, so the event written after it shares its line.\n const read = (line: string): AgUiSourceFrame[] => {\n const event = decodeStreamEvent(line) as AgUiSourceFrame | null;\n if (event !== null) return [event];\n const at = line.indexOf('{\"kind\":');\n const tail = at > 0 ? (decodeStreamEvent(line.slice(at)) as AgUiSourceFrame | null) : null;\n if (tail !== null) return [{ kind: 'text', text: line.slice(0, at) }, tail];\n return [{ kind: 'text', text: line }];\n };\n try {\n for await (const chunk of chunks) {\n buffer += decoder.decode(chunk, { stream: true });\n let newline = buffer.indexOf('\\n');\n while (newline !== -1) {\n const line = buffer.slice(0, newline);\n buffer = buffer.slice(newline + 1);\n if (line.length > 0) yield* read(line);\n newline = buffer.indexOf('\\n');\n }\n }\n buffer += decoder.decode();\n if (buffer.length > 0) yield* read(buffer);\n } catch (error) {\n if (error instanceof AgentStreamError) {\n yield { kind: 'error', code: error.code, message: error.message };\n return;\n }\n throw error;\n }\n}\n","import { AG_UI_PROTOCOL_VERSION, type AgUiEvent } from './types.js';\n\n/** A decision-only protocol invocation: no model run, stream holder or tool execution is created. */\nexport function actionProposalDecisionEvents(input: {\n threadId: string;\n runId: string;\n text: string;\n proposalDecision: unknown;\n}): AgUiEvent[] {\n const messageId = `${input.runId}:proposal-decision`;\n return [\n {\n type: 'RUN_STARTED',\n threadId: input.threadId,\n runId: input.runId,\n protocolVersion: AG_UI_PROTOCOL_VERSION,\n },\n {\n type: 'CUSTOM',\n name: 'aviary.action-proposal-decision',\n value: { threadId: input.threadId, proposalDecision: input.proposalDecision },\n },\n { type: 'TEXT_MESSAGE_START', messageId, role: 'assistant' },\n { type: 'TEXT_MESSAGE_CONTENT', messageId, delta: input.text },\n { type: 'TEXT_MESSAGE_END', messageId },\n { type: 'RUN_FINISHED', threadId: input.threadId, runId: input.runId },\n ];\n}\n"],"mappings":";;;;AAwBA,IAAMA,SAAS;AAER,SAASC,kBAAkBC,SAAyB;AACzD,QAAMC,UAAU;IACdD,QAAQE,SAAS,aAAa,MAAM;IACpCF,QAAQG;IACRH,QAAQI;IACRJ,QAAQK;IACRL,QAAQM;;AAEV,SAAOR,SAASS,OAA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MAAMS;MAAiB;IAC9E;IACA;MAAEN,MAAM;MAAsBF;MAAWS,MAAM;IAAY;IAC3D;MAAEP,MAAM;MAAwBF;MAAWU,OAAOX,MAAMY;IAAK;IAC7D;MAAET,MAAM;MAAoBF;IAAU;IACtC;MAAEE,MAAM;MAAgBC,UAAUJ,MAAMI;MAAUF,OAAOF,MAAME;IAAM;;AAEzE;AAxBgBH;","names":["PREFIX","encodeInterruptId","address","compact","kind","parked","stream","toolCallId","position","Buffer","from","JSON","stringify","toString","decodeInterruptId","id","startsWith","parsed","parse","slice","length","Array","isArray","Number","isSafeInteger","AG_UI_PROTOCOL_VERSION","AG_UI_CUSTOM","run","ui","title","queue","approvalRequested","approvalSettled","elicitation","stepUsage","warning","APPROVAL_SCHEMA","type","properties","approved","reason","remember","required","elicitationSchema","request","question","questions","options","map","option","value","id","title","prompt","description","undefined","items","length","allowFreeText","enum","multiple","maxItems","defaults","default","answers","text","json","JSON","stringify","AgUiEncoder","position","started","closed","cancelled","crossed","messageSeq","stepSeq","openText","openReasoning","stepMessage","openSteps","calls","Map","pending","usage","consumed","waiting","size","busy","call","answered","has","start","threadId","runId","protocolVersion","AG_UI_PROTOCOL_VERSION","name","AG_UI_CUSTOM","run","streamRunId","streamThreadId","encode","frame","skip","crossBoundary","events","project","values","ended","delete","replaying","event","kind","usageEntries","message","code","custom","ui","component","props","version","toolCallId","get","parked","toolName","input","set","interrupt","responseSchema","expiresAt","metadata","approver","approvalRequested","preamble","elicitation","textDelta","reasoningDelta","stepName","push","closeStreams","out","addUsage","model","pop","costUsd","stepUsage","reasoningMs","sawDelta","callStart","delta","known","result","output","error","approvalSettled","queue","finish","clear","interrupts","outcome","entry","encodeInterruptId","stream","nextMessageId","closeReasoning","messageId","role","closeText","toolCallName","parentMessageId","content","key","inputTokens","outputTokens","totalTokens","cacheReadTokens","cachedInputTokens","cacheWriteTokens","cacheWriteInputTokens","reasoningTokens","COMPONENT_NAME","validateUiCapabilities","value","record","Object","keys","some","key","Array","isArray","components","TypeError","seen","Set","map","component","name","COMPONENT_NAME","test","Number","isSafeInteger","version","has","add","isRecord","value","Array","isArray","parseRunInput","body","threadId","length","runId","messages","message","role","resume","undefined","entry","interruptId","status","context","forwardedProps","Object","hasOwn","validateUiCapabilities","uiCapabilities","EXTENSIONS","filenameOf","part","index","contentType","metadata","key","trim","slice","extension","type","readUserTurn","last","content","text","media","dropped","texts","forEach","push","source","how","mimeType","data","Buffer","from","toLowerCase","kind","filename","join","readContext","entries","filter","description","readForwardedProps","forwarded","pick","agent","model","persona","pageContext","planResume","decisions","unrecognised","address","decodeInterruptId","first","stream","position","seen","Set","has","toolCallId","add","readApprovalPayload","payload","approved","reason","remember","readAnswersPayload","answers","every","item","AgentStreamError","Error","code","error","message","name","encoder","TextEncoder","decodeStreamEvent","line","parsed","JSON","parse","kind","DEFAULT_QUIET_MS","GRACE_MS","agUiEvents","frames","options","encoder","AgUiEncoder","quietMs","start","preamble","iterator","Symbol","asyncIterator","upcoming","ended","next","caughtUp","consumed","skip","waiting","raceQuiet","busy","Math","min","undefined","done","encode","value","return","finish","ms","Promise","resolve","reject","timer","setTimeout","then","result","clearTimeout","error","agUiSse","event","JSON","stringify","agUiFramesFromNdjson","chunks","decoder","TextDecoder","buffer","read","line","decodeStreamEvent","at","indexOf","tail","slice","kind","text","chunk","decode","stream","newline","length","AgentStreamError","code","message","actionProposalDecisionEvents","input","messageId","runId","type","threadId","protocolVersion","AG_UI_PROTOCOL_VERSION","name","value","proposalDecision","role","delta","text"]}
|
|
1
|
+
{"version":3,"sources":["../../src/ag-ui/interrupt-id.ts","../../src/ag-ui/types.ts","../../src/ag-ui/encoder.ts","../../src/genui/catalog.ts","../../src/genui/capabilities.ts","../../src/ag-ui/input.ts","../../src/spi/token-stream-sink.ts","../../src/stream-events.ts","../../src/ag-ui/stream.ts","../../src/ag-ui/proposal-decision.ts"],"sourcesContent":["/**\n * An interrupt's id carries everything a resuming request needs, so the producer keeps NOTHING\n * between the run that stopped to ask and the run that answers — the statelessness AG-UI lets a\n * producer have, and what lets any replica serve the resume.\n *\n * It names the library run the human is answering (`parked` — a delegated sub-agent parks its OWN\n * run), the run whose stream carries the work (`stream`), the tool call, and how many of that\n * stream's frames the interrupted AG-UI run already delivered (`position`), which is where the\n * resuming run picks the stream up.\n *\n * It is an address, not a credential: the resume route checks the caller owns the run exactly as\n * the native approve/answer routes do.\n */\nexport interface InterruptAddress {\n /** `proposal` — an independent proposal's approval, decided through the proposal service. */\n kind: 'approval' | 'elicitation' | 'proposal';\n /** The run to settle the call on. */\n parked: string;\n /** The run whose buffered stream the resume re-attaches to. */\n stream: string;\n toolCallId: string;\n /** Frames of `stream` already delivered when the run was reported interrupted. */\n position: number;\n /** `proposal` only: the proposal and the library thread it belongs to. */\n proposalId?: string;\n threadId?: string;\n}\n\nconst KIND_CODES = { approval: 'a', elicitation: 'e', proposal: 'p' } as const;\n\nconst PREFIX = 'agora_';\n\nexport function encodeInterruptId(address: InterruptAddress): string {\n const compact: unknown[] = [\n KIND_CODES[address.kind],\n address.parked,\n address.stream,\n address.toolCallId,\n address.position,\n ];\n if (address.kind === 'proposal') compact.push(address.proposalId, address.threadId);\n return PREFIX + Buffer.from(JSON.stringify(compact), 'utf8').toString('base64url');\n}\n\n/** The address an id names, or `null` for an id this producer did not mint. */\nexport function decodeInterruptId(id: unknown): InterruptAddress | null {\n if (typeof id !== 'string' || !id.startsWith(PREFIX)) return null;\n try {\n const parsed: unknown = JSON.parse(\n Buffer.from(id.slice(PREFIX.length), 'base64url').toString('utf8'),\n );\n if (!Array.isArray(parsed)) return null;\n const [kind, parked, stream, toolCallId, position, proposalId, threadId] = parsed as unknown[];\n if (\n parsed.length !== (kind === 'p' ? 7 : 5) ||\n (kind === 'p' && (typeof proposalId !== 'string' || typeof threadId !== 'string')) ||\n (kind !== 'a' && kind !== 'e' && kind !== 'p') ||\n typeof parked !== 'string' ||\n typeof stream !== 'string' ||\n typeof toolCallId !== 'string' ||\n typeof position !== 'number' ||\n !Number.isSafeInteger(position) ||\n position < 0\n ) {\n return null;\n }\n return {\n kind: kind === 'a' ? 'approval' : kind === 'e' ? 'elicitation' : 'proposal',\n parked,\n stream,\n toolCallId,\n position,\n ...(kind === 'p' ? { proposalId: proposalId as string, threadId: threadId as string } : {}),\n };\n } catch {\n return null;\n }\n}\n","import type { AgentStreamEvent } from '../stream-events.js';\n\n/**\n * The slice of AG-UI 1.0 (https://docs.ag-ui.com/spec/1.0) this producer writes and reads. Typed by\n * hand rather than imported: the agent package takes no dependency on an AG-UI SDK, and the wire\n * shape is pinned by the protocol's own JSON Schema, which the tests validate every emitted event\n * against (`src/ag-ui/fixtures/schema-1.0.json`).\n *\n * Optional members are OMITTED when there is nothing to say, never `null` — the protocol's\n * \"absent means absent\" rule.\n */\n\n/** The protocol version this producer declares on `RUN_STARTED`. */\nexport const AG_UI_PROTOCOL_VERSION = '1.0';\n\nexport type AgUiMetadata = Record<string, unknown>;\n\n/** One provider-and-model's token usage, in the protocol's single accounting. */\nexport interface AgUiTokenUsage {\n provider?: string;\n model?: string;\n /** Every prompt token, cached or not. */\n inputTokens?: number;\n /** Every generated token, reasoning included. */\n outputTokens?: number;\n totalTokens?: number;\n /** Part of `outputTokens`. */\n reasoningTokens?: number;\n /** Cache reads — part of `inputTokens`. */\n cachedInputTokens?: number;\n /** Cache writes — part of `inputTokens`, disjoint from the reads. */\n cacheWriteInputTokens?: number;\n}\n\n/** What an interrupted run is waiting for; a resume entry answers it by `id`. */\nexport interface AgUiInterrupt {\n id: string;\n /** Open string. This producer writes `tool_approval` and `input_required`. */\n reason: string;\n message?: string;\n toolCallId?: string;\n responseSchema?: Record<string, unknown>;\n expiresAt?: string;\n metadata?: AgUiMetadata;\n}\n\nexport type AgUiRunOutcome =\n | { type: 'success'; pendingToolCallIds?: string[] }\n | { type: 'interrupt'; interrupts: AgUiInterrupt[] }\n | { type: 'cancelled' };\n\ninterface Base {\n metadata?: AgUiMetadata;\n}\n\nexport type AgUiEvent =\n | (Base & { type: 'RUN_STARTED'; threadId: string; runId: string; protocolVersion?: string })\n | (Base & {\n type: 'RUN_FINISHED';\n threadId: string;\n runId: string;\n outcome?: AgUiRunOutcome;\n usage?: AgUiTokenUsage[];\n })\n | (Base & { type: 'RUN_ERROR'; message: string; code?: string; usage?: AgUiTokenUsage[] })\n | (Base & { type: 'STEP_STARTED'; stepName: string })\n | (Base & { type: 'STEP_FINISHED'; stepName: string })\n | (Base & { type: 'TEXT_MESSAGE_START'; messageId: string; role: 'assistant' })\n | (Base & { type: 'TEXT_MESSAGE_CONTENT'; messageId: string; delta: string })\n | (Base & { type: 'TEXT_MESSAGE_END'; messageId: string })\n | (Base & { type: 'REASONING_START'; messageId: string })\n | (Base & { type: 'REASONING_MESSAGE_START'; messageId: string; role: 'reasoning' })\n | (Base & { type: 'REASONING_MESSAGE_CONTENT'; messageId: string; delta: string })\n | (Base & { type: 'REASONING_MESSAGE_END'; messageId: string })\n | (Base & { type: 'REASONING_END'; messageId: string })\n | (Base & {\n type: 'TOOL_CALL_START';\n toolCallId: string;\n toolCallName: string;\n parentMessageId?: string;\n })\n | (Base & { type: 'TOOL_CALL_ARGS'; toolCallId: string; delta: string })\n | (Base & { type: 'TOOL_CALL_END'; toolCallId: string })\n | (Base & {\n type: 'TOOL_CALL_RESULT';\n messageId: string;\n toolCallId: string;\n content: string;\n role: 'tool';\n })\n | (Base & { type: 'CUSTOM'; name: string; value: unknown });\n\n/** Where a media part's bytes are. Closed set: an unknown `type` is malformed input. */\nexport type AgUiPartSource =\n | { type: 'data'; value: string; mimeType: string }\n | { type: 'url'; value: string; mimeType?: string }\n | { type: 'file'; value: string; provider?: string; mimeType?: string };\n\nexport type AgUiContentPart =\n | { type: 'text'; text: string; id?: string; metadata?: unknown }\n | {\n type: 'image' | 'audio' | 'video' | 'document';\n source: AgUiPartSource;\n id?: string;\n metadata?: unknown;\n };\n\nexport interface AgUiMessage {\n id: string;\n role: string;\n content?: string | AgUiContentPart[];\n [key: string]: unknown;\n}\n\nexport interface AgUiResumeEntry {\n interruptId: string;\n status: 'resolved' | 'cancelled';\n payload?: unknown;\n metadata?: AgUiMetadata;\n}\n\nexport interface AgUiContext {\n description: string;\n value: string;\n}\n\n/** `RunAgentInput`: the one message that travels from the application to the agent. */\nexport interface AgUiRunInput {\n threadId: string;\n runId: string;\n protocolVersion?: string;\n parentRunId?: string;\n state?: unknown;\n messages: AgUiMessage[];\n tools?: unknown[];\n context?: AgUiContext[];\n forwardedProps?: unknown;\n resume?: AgUiResumeEntry[];\n}\n\n/**\n * The names of the `CUSTOM` events this producer writes for what AG-UI does not model. Prefixed, as\n * the protocol asks of invented names; a consumer that does not know one ignores it.\n */\nexport const AG_UI_CUSTOM = {\n /** `{ runId, threadId }` — the library's own ids for the run behind this stream (cancel, re-attach). */\n run: 'agora.run',\n /** A generative-UI component (`AgentUiComponent`); a repeat `id` replaces. */\n ui: 'agora.ui',\n title: 'agora.title',\n queue: 'agora.queue',\n /** The approval request as the native protocol carries it, for a consumer that renders it live. */\n approvalRequested: 'agora.approval-requested',\n approvalSettled: 'agora.approval-settled',\n /** The whole question set of an elicitation (`ElicitationRequest`). */\n elicitation: 'agora.elicitation',\n /** `{ usage, costUsd, reasoningMs }` of one model step. */\n stepUsage: 'agora.step-usage',\n /** A proposal decided by a text message or an interrupt resume, with no model run behind it. */\n actionProposalDecision: 'agora.action-proposal-decision',\n /** `{ message }` — input material this producer could not use and dropped. */\n warning: 'agora.warning',\n} as const;\n\n/**\n * What the encoder reads: one frame of a run's stream, in the shared vocabulary\n * ({@link AgentStreamEvent}) — plus the terminal failure, which the NestJS sink throws and the\n * Adonis sink writes as a frame, and three optional facts a sink may know about a parked call:\n * - `runId` — the run that is PARKED, when it is not the one whose stream this is (a delegated\n * sub-agent forwards its frames into its ancestor's stream). Absent → the stream's own run.\n * - `toolName`, `input` — the call being approved. Absent → read off the call's announcement.\n *\n * Framework-free on purpose: both servers project their own sink onto this and share one encoder.\n */\nexport type AgUiSourceFrame =\n | Exclude<\n AgentStreamEvent,\n { kind: 'approval-requested' } | { kind: 'elicitation' } | { kind: 'ui' }\n >\n | (Extract<AgentStreamEvent, { kind: 'approval-requested' }> & {\n runId?: string;\n toolName?: string;\n input?: unknown;\n })\n | (Extract<AgentStreamEvent, { kind: 'elicitation' }> & { runId?: string })\n /** A component with no `id` is numbered by its position in the stream (`ui:<n>`). */\n | (Omit<Extract<AgentStreamEvent, { kind: 'ui' }>, 'id' | 'props'> & {\n id?: string;\n props: unknown;\n })\n /** The run failed: the AG-UI run ends with `RUN_ERROR`, and nothing follows it. */\n | { kind: 'error'; code: string; message: string };\n","import type { ElicitationRequest } from '../elicitation.js';\nimport type { MessageUsage } from '../types.js';\nimport { encodeInterruptId } from './interrupt-id.js';\nimport {\n AG_UI_CUSTOM,\n AG_UI_PROTOCOL_VERSION,\n type AgUiEvent,\n type AgUiInterrupt,\n type AgUiSourceFrame,\n type AgUiTokenUsage,\n} from './types.js';\n\nexport interface AgUiEncoderOptions {\n /** The ids the consumer sent on `RunAgentInput`: every boundary event echoes them. */\n threadId: string;\n runId: string;\n /** The library run whose stream is being projected (it mints interrupt ids and the `agora.run` event). */\n streamRunId: string;\n /** The library's thread id, when it differs from what the consumer calls the thread. */\n streamThreadId?: string;\n /**\n * Frames of the library run's stream that an earlier AG-UI run already delivered (a resume). They\n * are fed to the encoder like any other — it has to know what they opened — but produce no events.\n */\n skip?: number;\n /**\n * Tool calls a resuming request just answered. The run has not necessarily said so yet — a parked\n * run takes a moment to wake — so without this the encoder would read them as still waiting and\n * report the interrupt again before the answer had any effect.\n */\n answered?: readonly string[];\n /** Model id for the usage entry when the step frames carry none. */\n model?: string;\n}\n\ninterface OpenCall {\n name: string;\n /** The arguments it was announced with, for an approval frame that does not repeat them. */\n input?: unknown;\n /** `TOOL_CALL_START` was written in THIS run (a resumed run meets results of calls it never saw open). */\n started: boolean;\n ended: boolean;\n sawDelta: boolean;\n answered: boolean;\n}\n\ninterface Pending {\n interrupt: Omit<AgUiInterrupt, 'id'>;\n kind: 'approval' | 'elicitation' | 'proposal';\n parked: string;\n toolCallId: string;\n /** `proposal` only: the independent proposal the approval decides. */\n proposalId?: string;\n}\n\nconst APPROVAL_SCHEMA = {\n type: 'object',\n properties: {\n approved: { type: 'boolean' },\n reason: { type: 'string' },\n remember: { type: 'boolean' },\n },\n required: ['approved'],\n};\n\n/** The answer an elicitation expects: `{ answers: { <questionId>: string[] } }`. */\nfunction elicitationSchema(request: ElicitationRequest): Record<string, unknown> {\n const properties: Record<string, unknown> = {};\n for (const question of request.questions) {\n const options = question.options?.map((option) => option.value);\n properties[question.id] = {\n type: 'array',\n title: question.prompt,\n ...(question.description !== undefined ? { description: question.description } : {}),\n items:\n options !== undefined && options.length > 0 && question.allowFreeText !== true\n ? { type: 'string', enum: options }\n : { type: 'string' },\n ...(question.multiple === true ? {} : { maxItems: 1 }),\n ...(question.defaults !== undefined ? { default: question.defaults } : {}),\n };\n }\n return {\n type: 'object',\n properties: { answers: { type: 'object', properties } },\n required: ['answers'],\n };\n}\n\nfunction text(value: unknown): string {\n if (typeof value === 'string') return value;\n const json = JSON.stringify(value);\n return json === undefined ? '' : json;\n}\n\n/**\n * Projects one library run's stream ({@link AgUiSourceFrame}s, in buffer order) onto AG-UI 1.0 events.\n *\n * A pure state machine: the same frames always give the same events, which is what lets a resuming\n * request — served by any replica — replay the run's buffer, skip what the interrupted AG-UI run\n * already delivered, and continue. It writes nothing itself; {@link agUiEvents} drives it and\n * decides when the run has stopped to ask.\n *\n * What maps where:\n * - `text` → `TEXT_MESSAGE_*` (one message per stretch of text);\n * - `reasoning` → a reasoning span with one reasoning message;\n * - `step-start`/`step-finish` → `STEP_STARTED`/`STEP_FINISHED`, the step's usage folded into the\n * run's `usage`;\n * - `tool-input-*` → `TOOL_CALL_START`/`ARGS`/`END`; `tool-output*` → `TOOL_CALL_RESULT`;\n * - an approval or a question set the run parks on → an `Interrupt` on the closing `RUN_FINISHED`;\n * - `cancelled` → the cancelled outcome; an error frame → `RUN_ERROR`;\n * - generative UI, title, queue and the native approval/elicitation frames → `CUSTOM` events named\n * in {@link AG_UI_CUSTOM}, for what AG-UI has no event for.\n *\n * Not mapped: sub-agent attribution (`subagentRunId`) — a delegated agent's frames are projected\n * flat, as the protocol allows of a producer that does not attribute.\n */\nexport class AgUiEncoder {\n private position = 0;\n private started = false;\n private closed = false;\n private cancelled = false;\n private crossed = false;\n private messageSeq = 0;\n private stepSeq = 0;\n private openText: string | undefined;\n private openReasoning: string | undefined;\n /** The last text message of the current step: a tool call attaches to it. */\n private stepMessage: string | undefined;\n private readonly openSteps: string[] = [];\n private readonly calls = new Map<string, OpenCall>();\n private readonly pending = new Map<string, Pending>();\n private readonly usage = new Map<string, AgUiTokenUsage>();\n\n constructor(private readonly options: AgUiEncoderOptions) {}\n\n /** How many frames of the library stream this encoder has consumed. */\n get consumed(): number {\n return this.position;\n }\n\n /** The run is waiting on at least one approval or question set nobody has settled yet. */\n get waiting(): boolean {\n return this.pending.size > 0;\n }\n\n /**\n * Is anything still in flight that is NOT waiting on a person — a tool call announced and neither\n * answered nor parked? While there is, more frames are coming without anyone's help.\n */\n get busy(): boolean {\n for (const [id, call] of this.calls) {\n if (!call.answered && !this.pending.has(id)) return true;\n }\n return false;\n }\n\n /** `RUN_STARTED`, and the library's own ids for the run. Call once, before the first frame. */\n start(): AgUiEvent[] {\n if (this.started) return [];\n this.started = true;\n return [\n {\n type: 'RUN_STARTED',\n threadId: this.options.threadId,\n runId: this.options.runId,\n protocolVersion: AG_UI_PROTOCOL_VERSION,\n },\n {\n type: 'CUSTOM',\n name: AG_UI_CUSTOM.run,\n value: {\n runId: this.options.streamRunId,\n threadId: this.options.streamThreadId ?? this.options.threadId,\n },\n },\n ];\n }\n\n /** The AG-UI events the next frame of the library stream stands for (possibly none). */\n encode(frame: AgUiSourceFrame): AgUiEvent[] {\n const position = this.position;\n this.position += 1;\n if (this.closed) return [];\n const skip = this.options.skip ?? 0;\n if (!this.crossed && position >= skip) this.crossBoundary();\n const events = this.project(frame, position);\n // A frame an earlier AG-UI run already delivered still moves the state (what is open, what is\n // pending; NOT what was spent — usage is per run) but writes nothing. The last of them is the\n // boundary: crossed at once, not when the next frame happens to arrive, because a run that was\n // just answered may take a moment to write one.\n if (position < skip) {\n if (this.position >= skip) this.crossBoundary();\n return [];\n }\n return events;\n }\n\n /**\n * The replayed frames are behind us: from here on events are written. The AG-UI run that delivered\n * them closed everything it had open before it finished, so this run starts with nothing open, and\n * what the resuming request answered is no longer waiting.\n */\n private crossBoundary(): void {\n this.crossed = true;\n this.openText = undefined;\n this.openReasoning = undefined;\n this.stepMessage = undefined;\n this.openSteps.length = 0;\n for (const call of this.calls.values()) {\n call.started = false;\n call.ended = true;\n }\n for (const id of this.options.answered ?? []) this.pending.delete(id);\n }\n\n private get replaying(): boolean {\n return this.position <= (this.options.skip ?? 0);\n }\n\n private project(event: AgUiSourceFrame, position: number): AgUiEvent[] {\n switch (event.kind) {\n case 'error': {\n this.closed = true;\n const usage = this.usageEntries();\n return [\n {\n type: 'RUN_ERROR',\n message: event.message,\n code: event.code,\n ...(usage.length > 0 ? { usage } : {}),\n },\n ];\n }\n case 'ui':\n return [\n this.custom(AG_UI_CUSTOM.ui, {\n id: event.id ?? `ui:${position}`,\n component: event.component,\n props: event.props,\n ...(event.version !== undefined ? { version: event.version } : {}),\n // What a client that cannot draw the component shows instead.\n ...(event.fallbackText !== undefined ? { fallbackText: event.fallbackText } : {}),\n ...(event.componentVersions !== undefined\n ? { componentVersions: event.componentVersions }\n : {}),\n ...(event.toolCallId !== undefined ? { toolCallId: event.toolCallId } : {}),\n }),\n ];\n case 'approval-requested': {\n const call = this.calls.get(event.id);\n const parked = event.runId ?? this.options.streamRunId;\n const toolName = event.toolName ?? call?.name ?? '';\n const input = event.input ?? call?.input ?? null;\n // An independent proposal: decided through the proposal service, not by signalling the run.\n const proposal = event.target?.kind === 'proposal' ? event.target : undefined;\n this.pending.set(event.id, {\n kind: proposal !== undefined ? 'proposal' : 'approval',\n parked,\n toolCallId: event.id,\n ...(proposal !== undefined ? { proposalId: proposal.proposalId } : {}),\n interrupt: {\n reason: 'tool_approval',\n message: event.reason ?? (toolName.length > 0 ? `Approve ${toolName}?` : 'Approve?'),\n toolCallId: event.id,\n responseSchema: APPROVAL_SCHEMA,\n ...(event.expiresAt !== undefined ? { expiresAt: event.expiresAt } : {}),\n metadata: {\n 'agora.toolName': toolName,\n 'agora.input': input,\n 'agora.approver': event.approver,\n ...(event.target !== undefined ? { 'agora.target': event.target } : {}),\n },\n },\n });\n return [\n this.custom(AG_UI_CUSTOM.approvalRequested, {\n id: event.id,\n runId: parked,\n toolName,\n input,\n approver: event.approver,\n ...(event.target !== undefined ? { target: event.target } : {}),\n ...(event.confirmation !== undefined ? { confirmation: event.confirmation } : {}),\n ...(event.expiresAt !== undefined ? { expiresAt: event.expiresAt } : {}),\n ...(event.reason !== undefined ? { reason: event.reason } : {}),\n }),\n ];\n }\n case 'elicitation': {\n const parked = event.runId ?? this.options.streamRunId;\n this.pending.set(event.id, {\n kind: 'elicitation',\n parked,\n toolCallId: event.id,\n interrupt: {\n reason: 'input_required',\n message:\n event.request.preamble ?? event.request.questions[0]?.prompt ?? 'Input required',\n // An intake's question set belongs to no tool call the stream announced.\n ...(this.calls.has(event.id) ? { toolCallId: event.id } : {}),\n responseSchema: elicitationSchema(event.request),\n metadata: { 'agora.request': event.request },\n },\n });\n return [this.custom(AG_UI_CUSTOM.elicitation, { runId: parked, request: event.request })];\n }\n case 'text':\n return event.text.length > 0 ? this.textDelta(event.text) : [];\n case 'reasoning':\n return event.text.length > 0 ? this.reasoningDelta(event.text) : [];\n case 'step-start': {\n this.stepSeq += 1;\n const stepName = `step-${this.stepSeq}`;\n this.openSteps.push(stepName);\n this.stepMessage = undefined;\n return [...this.closeStreams(), { type: 'STEP_STARTED', stepName }];\n }\n case 'step-finish': {\n const out = this.closeStreams();\n if (!this.replaying) this.addUsage(event.usage, event.model);\n const stepName = this.openSteps.pop();\n if (stepName !== undefined) out.push({ type: 'STEP_FINISHED', stepName });\n if (event.usage !== undefined || event.costUsd !== undefined) {\n out.push(\n this.custom(AG_UI_CUSTOM.stepUsage, {\n ...(event.usage !== undefined ? { usage: event.usage } : {}),\n ...(event.costUsd !== undefined ? { costUsd: event.costUsd } : {}),\n ...(event.reasoningMs !== undefined ? { reasoningMs: event.reasoningMs } : {}),\n }),\n );\n }\n return out;\n }\n case 'tool-input-start': {\n if (this.calls.has(event.id)) return [];\n const out = this.closeStreams();\n this.calls.set(event.id, {\n name: event.name,\n started: true,\n ended: false,\n sawDelta: false,\n answered: false,\n });\n out.push(this.callStart(event.id, event.name));\n return out;\n }\n case 'tool-input-delta': {\n const call = this.calls.get(event.id);\n if (call === undefined || call.ended || event.delta.length === 0) return [];\n call.sawDelta = true;\n return [{ type: 'TOOL_CALL_ARGS', toolCallId: event.id, delta: event.delta }];\n }\n case 'tool-input-available': {\n const known = this.calls.get(event.id);\n if (known?.ended === true) return [];\n const out = this.closeStreams();\n const call = known ?? {\n name: event.name,\n started: false,\n ended: false,\n sawDelta: false,\n answered: false,\n };\n if (!call.started) {\n call.started = true;\n out.push(this.callStart(event.id, event.name));\n }\n if (!call.sawDelta) {\n out.push({\n type: 'TOOL_CALL_ARGS',\n toolCallId: event.id,\n delta: text(event.input ?? {}),\n });\n }\n call.ended = true;\n call.input = event.input;\n this.calls.set(event.id, call);\n out.push({ type: 'TOOL_CALL_END', toolCallId: event.id });\n return out;\n }\n case 'tool-output':\n return this.result(event.id, text(event.output));\n case 'tool-output-error':\n return this.result(event.id, event.error, { 'agora.outcome': 'error' });\n case 'tool-output-denied':\n return this.result(event.id, event.reason ?? 'denied', { 'agora.outcome': 'denied' });\n case 'approval-settled':\n this.pending.delete(event.id);\n return [this.custom(AG_UI_CUSTOM.approvalSettled, event)];\n case 'title':\n return [this.custom(AG_UI_CUSTOM.title, { title: event.title })];\n case 'queue':\n return [\n this.custom(AG_UI_CUSTOM.queue, {\n queue: event.queue,\n ...(event.started !== undefined ? { started: event.started } : {}),\n }),\n ];\n case 'cancelled':\n this.cancelled = true;\n return [];\n default:\n // A kind newer than this encoder: tolerated, as every reader of the stream must.\n return [];\n }\n }\n\n /**\n * The events that end the AG-UI run: whatever is still open is closed first, then `RUN_FINISHED`\n * with how it ended — interrupted when the run is waiting on someone, cancelled when it was\n * stopped, success otherwise. Nothing after a `RUN_ERROR`. `ended` says the library run's stream\n * itself ended, rather than this reader having stopped following it.\n */\n finish(ended = false): AgUiEvent[] {\n if (this.closed) return [];\n this.closed = true;\n if (!this.crossed) this.crossBoundary();\n // A library run that ended is waiting on no one, whatever it asked along the way.\n if (ended) this.pending.clear();\n const out = this.start();\n out.push(...this.closeStreams());\n for (const [id, call] of this.calls) {\n if (call.started && !call.ended) {\n call.ended = true;\n out.push({ type: 'TOOL_CALL_END', toolCallId: id });\n }\n }\n while (this.openSteps.length > 0) {\n out.push({ type: 'STEP_FINISHED', stepName: this.openSteps.pop() as string });\n }\n const usage = this.usageEntries();\n const interrupts = this.cancelled ? [] : this.interrupts();\n out.push({\n type: 'RUN_FINISHED',\n threadId: this.options.threadId,\n runId: this.options.runId,\n ...(this.cancelled\n ? { outcome: { type: 'cancelled' as const } }\n : interrupts.length > 0\n ? { outcome: { type: 'interrupt' as const, interrupts } }\n : {}),\n ...(usage.length > 0 ? { usage } : {}),\n });\n return out;\n }\n\n private interrupts(): AgUiInterrupt[] {\n return [...this.pending.values()].map((entry) => ({\n id: encodeInterruptId({\n kind: entry.kind,\n parked: entry.parked,\n stream: this.options.streamRunId,\n toolCallId: entry.toolCallId,\n position: this.position,\n ...(entry.proposalId !== undefined\n ? {\n proposalId: entry.proposalId,\n threadId: this.options.streamThreadId ?? this.options.threadId,\n }\n : {}),\n }),\n ...entry.interrupt,\n }));\n }\n\n private custom(name: string, value: unknown): AgUiEvent {\n return { type: 'CUSTOM', name, value };\n }\n\n private nextMessageId(): string {\n this.messageSeq += 1;\n return `${this.options.runId}:m${this.messageSeq}`;\n }\n\n private textDelta(delta: string): AgUiEvent[] {\n const out: AgUiEvent[] = [];\n if (this.openReasoning !== undefined) out.push(...this.closeReasoning());\n if (this.openText === undefined) {\n this.openText = this.nextMessageId();\n this.stepMessage = this.openText;\n out.push({ type: 'TEXT_MESSAGE_START', messageId: this.openText, role: 'assistant' });\n }\n out.push({ type: 'TEXT_MESSAGE_CONTENT', messageId: this.openText, delta });\n return out;\n }\n\n private reasoningDelta(delta: string): AgUiEvent[] {\n const out: AgUiEvent[] = [];\n if (this.openText !== undefined) out.push(...this.closeText());\n if (this.openReasoning === undefined) {\n this.openReasoning = this.nextMessageId();\n out.push(\n { type: 'REASONING_START', messageId: this.openReasoning },\n { type: 'REASONING_MESSAGE_START', messageId: this.openReasoning, role: 'reasoning' },\n );\n }\n out.push({ type: 'REASONING_MESSAGE_CONTENT', messageId: this.openReasoning, delta });\n return out;\n }\n\n private closeText(): AgUiEvent[] {\n if (this.openText === undefined) return [];\n const messageId = this.openText;\n this.openText = undefined;\n return [{ type: 'TEXT_MESSAGE_END', messageId }];\n }\n\n private closeReasoning(): AgUiEvent[] {\n if (this.openReasoning === undefined) return [];\n const messageId = this.openReasoning;\n this.openReasoning = undefined;\n return [\n { type: 'REASONING_MESSAGE_END', messageId },\n { type: 'REASONING_END', messageId },\n ];\n }\n\n private closeStreams(): AgUiEvent[] {\n return [...this.closeReasoning(), ...this.closeText()];\n }\n\n private callStart(id: string, name: string): AgUiEvent {\n return {\n type: 'TOOL_CALL_START',\n toolCallId: id,\n toolCallName: name,\n ...(this.stepMessage !== undefined ? { parentMessageId: this.stepMessage } : {}),\n };\n }\n\n private result(id: string, content: string, metadata?: Record<string, unknown>): AgUiEvent[] {\n const call = this.calls.get(id);\n if (call !== undefined) call.answered = true;\n else {\n this.calls.set(id, {\n name: '',\n started: false,\n ended: true,\n sawDelta: false,\n answered: true,\n });\n }\n this.pending.delete(id);\n return [\n ...this.closeStreams(),\n {\n type: 'TOOL_CALL_RESULT',\n messageId: `${this.options.runId}:tool:${id}`,\n toolCallId: id,\n content,\n role: 'tool',\n ...(metadata !== undefined ? { metadata } : {}),\n },\n ];\n }\n\n private addUsage(usage: MessageUsage | undefined, model: unknown): void {\n if (usage === undefined) return;\n const name = typeof model === 'string' && model.length > 0 ? model : this.options.model;\n const key = name ?? '';\n const entry = this.usage.get(key) ?? (name !== undefined ? { model: name } : {});\n // The library's accounting is already the protocol's: input and output are totals, cache and\n // reasoning counts are parts of them. A count the provider did not report stays absent.\n entry.inputTokens = (entry.inputTokens ?? 0) + usage.inputTokens;\n entry.outputTokens = (entry.outputTokens ?? 0) + usage.outputTokens;\n entry.totalTokens = entry.inputTokens + entry.outputTokens;\n if (usage.cacheReadTokens !== undefined) {\n entry.cachedInputTokens = (entry.cachedInputTokens ?? 0) + usage.cacheReadTokens;\n }\n if (usage.cacheWriteTokens !== undefined) {\n entry.cacheWriteInputTokens = (entry.cacheWriteInputTokens ?? 0) + usage.cacheWriteTokens;\n }\n if (usage.reasoningTokens !== undefined) {\n entry.reasoningTokens = (entry.reasoningTokens ?? 0) + usage.reasoningTokens;\n }\n this.usage.set(key, entry);\n }\n\n private usageEntries(): AgUiTokenUsage[] {\n return [...this.usage.values()];\n }\n}\n","import {\n type GenuiValidation,\n type JsonSchema,\n type JsonSchemaValidator,\n type PropsSchema,\n builtinJsonSchemaValidator,\n toJsonSchema,\n validateProps,\n validatePropsSync,\n} from './schema.js';\n\n/**\n * One component a server may push into a conversation. Data only — how it LOOKS is each app's own\n * renderer, looked up by {@link name}. The same definition serves the model (description + props\n * schema), the server (validation), text-only channels ({@link fallbackText}) and the client\n * (validation before rendering).\n */\nexport interface ComponentDefinition<P = Record<string, unknown>> {\n /** Registry key, e.g. `DataTable`. What a `ui` frame's `component` names. */\n name: string;\n /** Human label: \"Data table\". */\n title: string;\n /** Shown to the model: what the component is for and when to use it. */\n description: string;\n /** The props schema: a Standard Schema (Zod, Valibot, ArkType) or a JSON Schema object. */\n props: PropsSchema;\n /** Portable normalized props schema. Required when input transformations are not idempotent. */\n outputProps?: PropsSchema;\n /**\n * The component takes nested elements (a layout: `Stack`, `Card`). Only meaningful in tree mode,\n * where a node's `children` are validated against the catalog too.\n */\n children?: boolean;\n /**\n * Plain text / Slack mrkdwn rendering of these props, for a channel that cannot draw the\n * component. Absent → {@link componentToText} prints the props as JSON.\n */\n fallbackText?: (props: P) => string;\n /**\n * Pushed by the server (e.g. an approval card), never offered to the model. Excluded from\n * {@link catalogToModelText} and from the tool factories.\n */\n internal?: boolean;\n /**\n * Schema version of {@link props}. Stamped on every `ui` frame the component is pushed with, so a\n * client can keep rendering messages persisted under an older shape.\n */\n version?: number;\n}\n\n/** Component names: an identifier a registry key, a tool name and a snake_case slug can all be derived from. */\nexport const COMPONENT_NAME = /^[A-Za-z][A-Za-z0-9]{0,63}$/;\n\n/** Declare a component. Validates the name and returns the definition unchanged (typed). */\nexport function defineComponent<P = Record<string, unknown>>(\n definition: ComponentDefinition<P>,\n): ComponentDefinition<P> {\n if (!COMPONENT_NAME.test(definition.name)) {\n throw new Error(\n `genui: component name \"${definition.name}\" must be letters and digits, starting with a letter (e.g. DataTable)`,\n );\n }\n if (\n definition.version !== undefined &&\n (!Number.isSafeInteger(definition.version) || definition.version <= 0)\n )\n throw new RangeError('genui: component version must be a positive safe integer');\n if (definition.fallbackText !== undefined && typeof definition.fallbackText !== 'function')\n throw new TypeError('genui: fallbackText must be a function');\n return definition;\n}\n\nexport interface CatalogOptions {\n /** How JSON Schema props are checked. Default: {@link builtinJsonSchemaValidator}; pass `ajvValidator(new Ajv())` for full JSON Schema. */\n jsonSchemaValidator?: JsonSchemaValidator;\n}\n\n/** An immutable set of component definitions, looked up by name. */\nexport interface Catalog {\n readonly components: readonly ComponentDefinition<any>[];\n readonly validator: JsonSchemaValidator;\n get(name: string): ComponentDefinition<any> | undefined;\n has(name: string): boolean;\n /** The components a model may be offered (every non-`internal` one). */\n modelComponents(): ComponentDefinition<any>[];\n /** Validate `props` for `component`. An unknown component is a validation failure, not a throw. */\n validate(component: string, props: unknown): Promise<GenuiValidation<Record<string, unknown>>>;\n /**\n * {@link validate} without waiting — `undefined` only when the component's Standard Schema\n * validates asynchronously. An unknown component is a failure, as in `validate`.\n */\n validateSync(\n component: string,\n props: unknown,\n ): GenuiValidation<Record<string, unknown>> | undefined;\n /** The component's props as JSON Schema, when it can be derived (see {@link toJsonSchema}). */\n jsonSchemaFor(component: string): JsonSchema | undefined;\n /** A new catalog with these components added (a later definition replaces an earlier one of the same name). */\n extend(components: readonly ComponentDefinition<any>[]): Catalog;\n}\n\n/**\n * Collect component definitions into a {@link Catalog}. Names must be unique; to override a\n * definition (e.g. a builtin), use {@link Catalog.extend}.\n */\nexport function defineCatalog(\n components: readonly ComponentDefinition<any>[],\n options: CatalogOptions = {},\n): Catalog {\n const byName = new Map<string, ComponentDefinition<any>>();\n for (const component of components) {\n defineComponent(component);\n if (byName.has(component.name)) {\n throw new Error(`genui: component \"${component.name}\" is defined twice in one catalog`);\n }\n byName.set(component.name, component);\n }\n return buildCatalog(byName, options.jsonSchemaValidator ?? builtinJsonSchemaValidator);\n}\n\nfunction buildCatalog(\n byName: Map<string, ComponentDefinition<any>>,\n validator: JsonSchemaValidator,\n): Catalog {\n const list = Object.freeze([...byName.values()]);\n return {\n components: list,\n validator,\n get: (name) => byName.get(name),\n has: (name) => byName.has(name),\n modelComponents: () => list.filter((component) => component.internal !== true),\n async validate(component, props) {\n const definition = byName.get(component);\n if (definition === undefined) {\n return {\n ok: false,\n issues: [{ path: [], message: `unknown component \"${component}\"` }],\n };\n }\n const result = await validateProps(\n definition.outputProps ?? definition.props,\n props,\n validator,\n );\n return result as GenuiValidation<Record<string, unknown>>;\n },\n validateSync(component, props) {\n const definition = byName.get(component);\n if (definition === undefined) {\n return {\n ok: false,\n issues: [{ path: [], message: `unknown component \"${component}\"` }],\n };\n }\n return validatePropsSync(definition.outputProps ?? definition.props, props, validator) as\n | GenuiValidation<Record<string, unknown>>\n | undefined;\n },\n jsonSchemaFor(component) {\n const definition = byName.get(component);\n return definition === undefined\n ? undefined\n : toJsonSchema(definition.outputProps ?? definition.props);\n },\n extend(more) {\n const next = new Map(byName);\n for (const component of more) {\n defineComponent(component);\n next.set(component.name, component);\n }\n return buildCatalog(next, validator);\n },\n };\n}\n\n/** `DataTable` → `data_table`, `KPICards` → `kpi_cards`. */\nexport function toSnakeCase(name: string): string {\n return name\n .replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')\n .replace(/[^a-zA-Z0-9]+/g, '_')\n .toLowerCase();\n}\n\n/** The per-component tool name: `ui__show_data_table` with the default prefix. */\nexport function toolNameFor(component: string, prefix = 'ui__show_'): string {\n return `${prefix}${toSnakeCase(component)}`;\n}\n","import { COMPONENT_NAME, type Catalog, defineCatalog } from './catalog.js';\nimport { formatIssues } from './schema.js';\nimport { componentToText, treeToText } from './text.js';\nimport { GENUI_TREE_COMPONENT, type GenuiElement, validateTree } from './tree.js';\n\n/** Renderer support only. Component definitions and authorization remain server-owned. */\nexport interface UiCapabilities {\n components: Array<{ name: string; version: number }>;\n}\n\nexport function validateUiCapabilities(value: unknown): UiCapabilities {\n if (\n !record(value) ||\n Object.keys(value).some((key) => key !== 'components') ||\n !Array.isArray(value.components)\n )\n throw new TypeError('Invalid UI capabilities');\n const seen = new Set<string>();\n const components = value.components.map((component: unknown) => {\n if (\n !record(component) ||\n Object.keys(component).some((key) => key !== 'name' && key !== 'version') ||\n typeof component.name !== 'string' ||\n !COMPONENT_NAME.test(component.name) ||\n !Number.isSafeInteger(component.version) ||\n Number(component.version) <= 0 ||\n seen.has(component.name)\n )\n throw new TypeError('Invalid UI component capability');\n seen.add(component.name);\n return { name: component.name, version: Number(component.version) };\n });\n return { components };\n}\n\nfunction record(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function negotiateCatalog(catalog: Catalog, capabilities?: UiCapabilities): Catalog {\n if (capabilities === undefined) return catalog;\n const supported = validateUiCapabilities(capabilities).components;\n return defineCatalog(\n catalog.components.filter((component) =>\n supported.some(\n (entry) => entry.name === component.name && entry.version === (component.version ?? 1),\n ),\n ),\n { jsonSchemaValidator: catalog.validator },\n );\n}\n\nexport type PreparedUiEmission =\n | {\n kind: 'ui';\n component: string;\n props: Record<string, unknown>;\n version: number;\n fallbackText: string;\n componentVersions?: Record<string, number>;\n }\n | { kind: 'text'; text: string };\n\n/** Validate against current trusted definitions before drawing or generating complete text. */\nexport async function prepareUiEmission(\n catalog: Catalog,\n capabilities: UiCapabilities | undefined,\n component: string,\n props: Record<string, unknown>,\n version?: number,\n): Promise<PreparedUiEmission> {\n const drawable = negotiateCatalog(catalog, capabilities);\n if (component === GENUI_TREE_COMPONENT) {\n if (version !== undefined && version !== 1) throw new Error('Invalid UI tree version');\n const validated = await validateTree(catalog, props.root);\n if (!validated.ok) throw new Error(`Invalid UI tree: ${formatIssues(validated.issues)}`);\n const supported = (node: GenuiElement): boolean =>\n drawable.has(node.type) && (node.children ?? []).every(supported);\n const versions = new Map<string, number>();\n const collectVersions = (node: GenuiElement): void => {\n versions.set(node.type, catalog.get(node.type)?.version ?? 1);\n for (const child of node.children ?? []) collectVersions(child);\n };\n collectVersions(validated.value);\n return supported(validated.value)\n ? {\n kind: 'ui',\n component,\n props: { root: validated.value },\n version: 1,\n fallbackText: treeToText(catalog, validated.value),\n componentVersions: Object.fromEntries(versions),\n }\n : { kind: 'text', text: treeToText(catalog, validated.value) };\n }\n const definition = catalog.get(component);\n if (definition === undefined) throw new Error(`Unknown UI component \"${component}\"`);\n const currentVersion = definition.version ?? 1;\n if (version !== undefined && version !== currentVersion)\n throw new Error(`Invalid UI component version for \"${component}\"`);\n const validated = await catalog.validate(component, props);\n if (!validated.ok) throw new Error(`Invalid UI props: ${formatIssues(validated.issues)}`);\n return drawable.has(component)\n ? {\n kind: 'ui',\n component,\n props: validated.value,\n version: currentVersion,\n fallbackText: componentToText(catalog, component, validated.value),\n }\n : { kind: 'text', text: componentToText(catalog, component, validated.value) };\n}\n","import { type UiCapabilities, validateUiCapabilities } from '../genui/capabilities.js';\nimport { type InterruptAddress, decodeInterruptId } from './interrupt-id.js';\nimport type {\n AgUiContentPart,\n AgUiContext,\n AgUiMessage,\n AgUiResumeEntry,\n AgUiRunInput,\n} from './types.js';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Read a request body as a `RunAgentInput`, or say why it is not one.\n *\n * Only what this producer acts on is checked, and a KNOWN member with a value the schema rejects is\n * malformed (the run never starts). A member it does not recognise is not an error — the protocol's\n * asymmetry: a newer consumer's input must not bounce off an older producer.\n */\nexport function parseRunInput(body: unknown): AgUiRunInput | string {\n if (!isRecord(body)) return 'the body must be a RunAgentInput object';\n if (typeof body.threadId !== 'string' || body.threadId.length === 0) {\n return 'threadId must be a non-empty string';\n }\n if (body.threadId.length > 255) return 'threadId must be at most 255 characters';\n if (typeof body.runId !== 'string' || body.runId.length === 0) {\n return 'runId must be a non-empty string';\n }\n if (!Array.isArray(body.messages)) return 'messages must be an array';\n for (const message of body.messages) {\n if (!isRecord(message) || typeof message.role !== 'string') {\n return 'each message must be an object with a role';\n }\n }\n if (body.resume !== undefined) {\n if (!Array.isArray(body.resume)) return 'resume must be an array';\n for (const entry of body.resume) {\n if (\n !isRecord(entry) ||\n typeof entry.interruptId !== 'string' ||\n (entry.status !== 'resolved' && entry.status !== 'cancelled')\n ) {\n return \"each resume entry needs an interruptId and a status of 'resolved' or 'cancelled'\";\n }\n }\n }\n if (body.context !== undefined && !Array.isArray(body.context)) {\n return 'context must be an array';\n }\n if (isRecord(body.forwardedProps) && Object.hasOwn(body.forwardedProps, 'uiCapabilities')) {\n try {\n validateUiCapabilities(body.forwardedProps.uiCapabilities);\n } catch {\n return 'forwardedProps.uiCapabilities must be valid UI capabilities';\n }\n }\n return body as unknown as AgUiRunInput;\n}\n\n/** A media part carried inline, ready to be staged as an attachment. */\nexport interface InlineMedia {\n kind: 'image' | 'audio' | 'video' | 'document';\n contentType: string;\n data: Buffer;\n filename: string;\n}\n\nexport interface UserTurn {\n /** The text of the message the run answers. */\n text: string;\n media: InlineMedia[];\n /** Why a part was not used, one sentence each — reported, never fatal. */\n dropped: string[];\n}\n\nconst EXTENSIONS: Record<string, string> = {\n 'image/png': 'png',\n 'image/jpeg': 'jpg',\n 'image/gif': 'gif',\n 'image/webp': 'webp',\n 'application/pdf': 'pdf',\n 'text/plain': 'txt',\n};\n\nfunction filenameOf(part: AgUiContentPart, index: number, contentType: string): string {\n const metadata = (part as { metadata?: unknown }).metadata;\n if (isRecord(metadata)) {\n for (const key of ['filename', 'name', 'title']) {\n const value = metadata[key];\n if (typeof value === 'string' && value.trim().length > 0) return value.trim().slice(0, 200);\n }\n }\n const extension = EXTENSIONS[contentType];\n return `${part.type}-${index + 1}${extension !== undefined ? `.${extension}` : ''}`;\n}\n\n/**\n * The turn a run answers: the LAST user message of the input. The library keeps each thread's\n * history itself, so the earlier messages the consumer restates are not read back in — what the\n * agent resumes from is what it stored.\n *\n * Multimodal parts: text parts are the message's text; a media part carried inline (`data`) becomes\n * an attachment. A part by `url` or by provider `file` handle is dropped and said so — this producer\n * hands the model only bytes it staged itself, never an address a caller supplied.\n */\nexport function readUserTurn(messages: readonly AgUiMessage[]): UserTurn | null {\n let last: AgUiMessage | undefined;\n for (let index = messages.length - 1; index >= 0; index -= 1) {\n if (messages[index]?.role === 'user') {\n last = messages[index];\n break;\n }\n }\n if (last === undefined) return null;\n if (typeof last.content === 'string') return { text: last.content, media: [], dropped: [] };\n if (!Array.isArray(last.content)) return { text: '', media: [], dropped: [] };\n\n const texts: string[] = [];\n const media: InlineMedia[] = [];\n const dropped: string[] = [];\n last.content.forEach((part, index) => {\n if (!isRecord(part)) return;\n if (part.type === 'text') {\n if (typeof part.text === 'string') texts.push(part.text);\n return;\n }\n if (\n part.type !== 'image' &&\n part.type !== 'audio' &&\n part.type !== 'video' &&\n part.type !== 'document'\n ) {\n return;\n }\n const source = part.source;\n if (!isRecord(source) || source.type !== 'data') {\n const how = isRecord(source) && typeof source.type === 'string' ? source.type : 'unknown';\n dropped.push(\n `The ${part.type} part ${index + 1} was not used: only inline data is accepted, not a ${how} source.`,\n );\n return;\n }\n if (typeof source.value !== 'string' || typeof source.mimeType !== 'string') {\n dropped.push(\n `The ${part.type} part ${index + 1} was not used: its inline data is malformed.`,\n );\n return;\n }\n const data = Buffer.from(source.value, 'base64');\n if (data.length === 0) {\n dropped.push(`The ${part.type} part ${index + 1} was not used: it carries no bytes.`);\n return;\n }\n const contentType = source.mimeType.toLowerCase();\n media.push({\n kind: part.type,\n contentType,\n data,\n filename: filenameOf(part as AgUiContentPart, index, contentType),\n });\n });\n return { text: texts.join('\\n'), media, dropped };\n}\n\n/** `context` entries as the library's page context carries them, or `undefined` for none. */\nexport function readContext(\n context: readonly AgUiContext[] | undefined,\n): AgUiContext[] | undefined {\n if (context === undefined) return undefined;\n const entries = context.filter(\n (entry) =>\n isRecord(entry) && typeof entry.description === 'string' && typeof entry.value === 'string',\n );\n return entries.length > 0 ? entries : undefined;\n}\n\n/**\n * What the library reads from `forwardedProps` — the consumer's channel for what AG-UI does not\n * model: which agent, which model, which persona, and the page context the tools see.\n */\nexport interface ForwardedOptions {\n uiCapabilities?: UiCapabilities;\n agent?: string;\n model?: string;\n persona?: string;\n pageContext?: Record<string, unknown>;\n}\n\nexport function readForwardedProps(forwarded: unknown): ForwardedOptions {\n if (!isRecord(forwarded)) return {};\n const pick = (key: string): string | undefined => {\n const value = forwarded[key];\n return typeof value === 'string' && value.length > 0 ? value : undefined;\n };\n const agent = pick('agent');\n const model = pick('model');\n const persona = pick('persona');\n return {\n ...(Object.hasOwn(forwarded, 'uiCapabilities')\n ? { uiCapabilities: validateUiCapabilities(forwarded.uiCapabilities) }\n : {}),\n ...(agent !== undefined ? { agent } : {}),\n ...(model !== undefined ? { model } : {}),\n ...(persona !== undefined ? { persona } : {}),\n ...(isRecord(forwarded.pageContext) ? { pageContext: forwarded.pageContext } : {}),\n };\n}\n\n/** One resume entry this producer can act on. */\nexport interface ResumeDecision {\n address: InterruptAddress;\n entry: AgUiResumeEntry;\n}\n\nexport interface ResumePlan {\n decisions: ResumeDecision[];\n /** Entries naming an interrupt this producer did not raise: skipped with a warning, never fatal. */\n unrecognised: string[];\n}\n\n/**\n * Sort a resume list into what it answers. Every recognised entry must continue the SAME library\n * run from the SAME point — they are the interrupts of one `RUN_FINISHED` — and a list that does not\n * is malformed (a string says why).\n */\nexport function planResume(resume: readonly AgUiResumeEntry[]): ResumePlan | string {\n const decisions: ResumeDecision[] = [];\n const unrecognised: string[] = [];\n for (const entry of resume) {\n const address = decodeInterruptId(entry.interruptId);\n if (address === null) {\n unrecognised.push(entry.interruptId);\n continue;\n }\n decisions.push({ address, entry });\n }\n const first = decisions[0];\n if (first === undefined) return { decisions, unrecognised };\n for (const { address } of decisions) {\n if (address.stream !== first.address.stream || address.position !== first.address.position) {\n return 'the resume entries answer interrupts of different runs';\n }\n }\n const seen = new Set<string>();\n for (const { address } of decisions) {\n if (seen.has(address.toolCallId)) return 'an interrupt is answered twice';\n seen.add(address.toolCallId);\n }\n return { decisions, unrecognised };\n}\n\n/** `{ approved, reason?, remember? }` out of an approval's resume payload. A bare boolean is accepted. */\nexport function readApprovalPayload(payload: unknown): {\n approved: boolean;\n reason?: string;\n remember?: boolean;\n} | null {\n if (typeof payload === 'boolean') return { approved: payload };\n if (!isRecord(payload) || typeof payload.approved !== 'boolean') return null;\n return {\n approved: payload.approved,\n ...(typeof payload.reason === 'string' ? { reason: payload.reason } : {}),\n ...(typeof payload.remember === 'boolean' ? { remember: payload.remember } : {}),\n };\n}\n\n/** `questionId → string[]` out of an elicitation's resume payload (`{ answers }` or the map itself). */\nexport function readAnswersPayload(payload: unknown): Record<string, string[]> | null {\n const source = isRecord(payload) && isRecord(payload.answers) ? payload.answers : payload;\n if (!isRecord(source)) return null;\n const answers: Record<string, string[]> = {};\n for (const [key, value] of Object.entries(source)) {\n if (typeof value === 'string') answers[key] = [value];\n else if (Array.isArray(value) && value.every((item) => typeof item === 'string')) {\n answers[key] = value as string[];\n } else return null;\n }\n return answers;\n}\n","/**\n * The \"data plane\": live token transport, decoupled from the durable control plane.\n *\n * The model turn writes deltas to a `SinkWriter` keyed by runId; the HTTP layer\n * `subscribe`s by runId and pipes the chunks to the browser as SSE. A late subscriber\n * (reconnect/resume) replays buffered chunks first, then follows live — which is what\n * makes streaming survive a dropped connection or a pod restart.\n */\nexport interface SinkWriter {\n write(chunk: Uint8Array): void | Promise<void>;\n /** Mark the run's stream finished (no more chunks). */\n end(): void | Promise<void>;\n /**\n * Terminate the run's stream with an error instead of a normal end. Subscribers replay any\n * buffered chunks first, then throw an {@link AgentStreamError} carrying this `code`/`message`\n * — so the transport can surface a typed failure frame instead of leaking it as assistant text.\n */\n fail(error: StreamError): void | Promise<void>;\n /**\n * OPTIONAL: write out anything this writer is still holding back, without ending the stream. Only\n * a sink that gathers frames before writing them (the SQL sink coalesces text) has anything to do\n * here; a delegated run's child writer calls it where it would have ended the stream, so nothing\n * of the delegate's is still held back when its parent — possibly on another replica — writes next.\n */\n flush?(): void | Promise<void>;\n}\n\n/** A machine-readable stream failure. `code` is a stable slug; `message` is human-facing. */\nexport interface StreamError {\n code: string;\n message: string;\n}\n\n/**\n * Thrown out of {@link TokenStreamSink.subscribe} when a run ended via {@link SinkWriter.fail}.\n * Carries the structured {@link StreamError} so the HTTP layer can emit an `event: error` frame.\n */\nexport class AgentStreamError extends Error {\n readonly code: string;\n constructor(error: StreamError) {\n super(error.message);\n this.name = 'AgentStreamError';\n this.code = error.code;\n }\n}\n\nexport interface TokenStreamSink {\n /** Open (or reopen) the writer for a run. */\n open(runId: string): SinkWriter | Promise<SinkWriter>;\n /**\n * Replay buffered chunks for the run, then yield live ones until `end()`. Throws\n * {@link AgentStreamError} if the run was terminated with {@link SinkWriter.fail}.\n */\n subscribe(runId: string): AsyncIterable<Uint8Array>;\n /** Drop any buffer/resources for the run. */\n close(runId: string): void | Promise<void>;\n}\n","/**\n * The structured live-stream vocabulary carried over the {@link SinkWriter} byte channel.\n *\n * The model turn (via the AI-SDK adapter) and the agent loop write these events as NDJSON — one\n * `JSON.stringify(event)\\n` per {@link SinkWriter.write}. The HTTP layer forwards each line as an\n * SSE `data:` frame, and the client transport maps them back to the AI SDK UI-message chunk\n * protocol so the browser renders text, reasoning, and tool cards (input + output) LIVE — the same\n * rich rendering a raw `streamText().toUIMessageStream()` would give, but reconstructed on the\n * client so the sink stays a format-agnostic byte buffer (durable buffering/replay is untouched).\n *\n * Keeping this vocabulary neutral (not AI-SDK `UIMessageChunk`) means core never depends on `ai`:\n * the adapter owns model-parts → event, the transport owns event → UI-chunk.\n *\n * The vocabulary is also a CONTRACT for runners that are not this library's loop: anything that\n * writes these frames (one JSON object per SSE `data:` line) gets the React transport, transcript\n * model and hooks for free. Two rules keep it evolvable:\n * - every frame is a JSON object with a string `kind`; a reader MUST tolerate kinds it does not\n * know (the React transport forwards them as `data-<kind>` parts rather than dropping them);\n * - fields are only ever added, and new fields are optional.\n */\nimport type { ElicitationRequest } from './elicitation.js';\nimport type { ChatQueueState } from './spi/chat-queue.js';\nimport type { ToolConfirmation } from './tool-presentation.js';\nimport type { MessageUsage } from './types.js';\n\n/**\n * A component the server pushed into the conversation: generative UI that is NOT a tool call's\n * rendering. It is addressed by `component` (a key in the client's own component registry), never\n * by a tool name, so a runner can emit one from anywhere — a tool body, a post-processing step, a\n * sandboxed agent that renders through its own protocol.\n *\n * `id` is the component's identity within the message: a second frame with the same `id` REPLACES\n * the first (streaming props into a chart, flipping a card from \"loading\" to \"ready\"), it never\n * adds a second component.\n */\nexport interface AgentUiComponent {\n id: string;\n /** Registry key the client resolves to its own renderer, e.g. `data-table`. */\n component: string;\n props: Record<string, unknown>;\n /** Schema version of `props`, so a client can keep rendering components persisted by an older server. */\n version?: number;\n /** Validated readable fallback retained for clients without this renderer. */\n fallbackText?: string;\n /** Trusted schema versions for every component in a persisted tree. */\n componentVersions?: Record<string, number>;\n /**\n * The tool call that pushed the component (`ctx.emitUi`), when one did. Lets a client place it\n * with that call — a reloaded message puts it right after the call's tool part, where the live\n * stream showed it. Absent for a component pushed outside a tool.\n */\n toolCallId?: string;\n}\n\n/**\n * Who has to settle an action tool call, and until when. Metadata only: the call itself is still\n * settled through the tool-call approve/reject routes, by its `toolCallId`.\n */\nexport interface AgentApprovalRequest {\n target?: { kind: 'proposal'; proposalId: string };\n /** Resolved confirmation from the action preflight; overrides presentation templates. */\n confirmation?: ToolConfirmation;\n /** The tool call awaiting the decision — the `id` of a call already announced on this stream. */\n id: string;\n /**\n * Who may decide. Open vocabulary the host defines — `'requester'` (the person chatting),\n * `'admin'`, a role name, a team. A client uses it to say \"waiting on an admin\" instead of\n * offering buttons the viewer cannot use.\n */\n approver: string;\n /** ISO-8601 instant after which the request lapses. Absent → it never expires. */\n expiresAt?: string;\n /** Why this call needs a person, in words for that person. */\n reason?: string;\n}\n\n/**\n * How an approval settled — the other half of {@link AgentApprovalRequest}, under the same `id`.\n * Metadata again: the call's own outcome still arrives as `tool-output` (approved and ran),\n * `tool-output-error` (approved and failed) or `tool-output-denied` (rejected or expired).\n */\nexport interface AgentApprovalSettlement {\n id: string;\n status: 'approved' | 'rejected' | 'expired';\n /** Repeated from the request, for a call approved without one being streamed (a remembered approval). */\n approver?: string;\n /** Opaque ref of who decided. Absent on an expiry. */\n decidedBy?: string;\n /** The surface the decision came through: `'web'`, `'slack'`, `'remembered'`, … */\n decidedVia?: string;\n /** The approval also covers later calls of this tool in this thread. */\n remember?: boolean;\n /** What the person said when declining. */\n reason?: string;\n}\n\nexport type AgentStreamEvent =\n | { kind: 'step-start' }\n /**\n * Closes the step opened by the matching `step-start`. Carries the model call's token usage and\n * `costUsd` (an estimate from the bound pricing store, or `null` when unpriced/unbound — never a\n * fabricated `0`) so a live client can render running cost without waiting for a thread re-fetch.\n */\n | {\n kind: 'step-finish';\n usage?: MessageUsage;\n costUsd?: number | null;\n /**\n * How long the model spent thinking in this step, in ms — the same number persisted as\n * `StoredMessage.reasoningMs`, so a live thread and a reloaded one read the same duration.\n * Absent when the step had no reasoning.\n */\n reasoningMs?: number;\n /**\n * The model the step ran on: the one the provider reported, else the configured `modelId`.\n * What a per-model usage report keys on (the AG-UI producer's `RUN_FINISHED.usage`). Absent\n * when neither is known; a reader that does not know the field ignores it.\n */\n model?: string;\n }\n | { kind: 'text'; text: string }\n | { kind: 'reasoning'; text: string }\n /**\n * `toolKind` collapses `ToolKind`'s `'agent'` into `'read'` — delegation tools auto-execute like a read tool.\n *\n * `parentId` nests this call under another call on the same stream: the inner calls a code-mode\n * `execute` makes, the tools a delegated sub-agent runs. The parent must be announced first. A\n * call's parent is fixed by its first frame that names one; later frames may omit it.\n */\n | {\n kind: 'tool-input-start';\n id: string;\n name: string;\n toolKind: 'read' | 'action';\n parentId?: string;\n }\n | { kind: 'tool-input-delta'; id: string; delta: string }\n | {\n kind: 'tool-input-available';\n id: string;\n name: string;\n input: unknown;\n toolKind: 'read' | 'action';\n /** Same as on `tool-input-start`, for a runner that announces a call without streaming its input. */\n parentId?: string;\n }\n | { kind: 'tool-output'; id: string; output: unknown }\n | { kind: 'tool-output-error'; id: string; error: string }\n /**\n * A person was asked to approve an action tool and declined it. Its own frame, NOT\n * `tool-output-error`: a refusal is a decision with a known outcome — nothing ran — while a\n * failure is an outcome nobody chose and whose effects are unknown. Rendering them the same way\n * tells an operator their own \"no\" was a malfunction. Maps onto the SDK's `output-denied` tool\n * part state, which a client reads without knowing any tool's name.\n */\n | { kind: 'tool-output-denied'; id: string; reason?: string }\n /**\n * The run has put a question set to the user and is parked until someone answers it (or skips).\n * Written by the LOOP for both elicitation surfaces — the configured intake and the model's `ask`\n * tool — so a client renders one form either way rather than learning to recognise a tool name.\n * The matching `tool-output` frame, under the same `id`, carries the settled answers.\n */\n | { kind: 'elicitation'; id: string; request: ElicitationRequest }\n /**\n * An action tool call (already announced by `tool-input-start`/`tool-input-available` under the\n * same `id`) is parked on a person. Optional: a client still treats an `action` call stuck at\n * its input as pending — this frame adds WHO has to decide and UNTIL WHEN, and moves the call\n * into the AI SDK's native `approval-requested` state.\n */\n | ({ kind: 'approval-requested' } & AgentApprovalRequest)\n /**\n * A parked action call was decided (or lapsed). Optional, like `approval-requested`: it adds WHO\n * decided, THROUGH WHAT and whether the approval is REMEMBERED; the outcome itself rides the\n * call's own output frame. See {@link AgentApprovalSettlement}.\n */\n | ({ kind: 'approval-settled' } & AgentApprovalSettlement)\n /**\n * Server-pushed generative UI, positioned in the message where it arrives. Not tied to a tool\n * call. See {@link AgentUiComponent}.\n */\n | ({ kind: 'ui' } & AgentUiComponent)\n /**\n * The thread's title was set or changed while this run streamed (typically derived from the\n * first exchange). Thread-level, not message content: a client updates its header/sidebar and\n * does not render it in the transcript.\n */\n | { kind: 'title'; title: string }\n /**\n * Host-defined facts about the message being streamed (the model that answered, how long it took,\n * the error it ended with), merged into the client message's `metadata`. The persisted\n * counterpart is `StoredMessage.metadata`, so a reload reads the same values. The library's own\n * loop never writes it; a runner that is not this library's loop uses it for what its store keeps\n * per message.\n */\n | { kind: 'message-metadata'; metadata: Record<string, unknown> }\n /**\n * Someone stopped this run. The stream's LAST frame, written by the runner that settled the\n * cancel, immediately before a normal `end()` — never a `fail()`, because a cancel is not an\n * error and a client that retries on a failed stream must not retry this.\n *\n * A run that simply ends wrote everything it had; one that ends after this frame did not, and the\n * difference is the whole point: without it a reader cannot tell a truncated answer from a\n * complete one. Consumers that predate the frame ignore it and see the `end()` they always saw.\n */\n | { kind: 'cancelled' }\n /**\n * The thread's message queue changed — a snapshot of the whole queue, never a delta, so a client\n * that missed one frame is corrected by the next. Written into the stream of the run that is\n * holding the thread: when someone queues, edits, reorders or removes a waiting message, and, just\n * before this run's own terminal frame, with what happens next — `started` names the queued\n * message that became the next turn and that turn's run id (attach to it with\n * `GET <base>/chat/:runId/stream`), `queue.paused` says why nothing starts.\n */\n | { kind: 'queue'; queue: ChatQueueState; started?: { messageId: string; runId: string } };\n\nconst encoder = new TextEncoder();\n\n/** Encode one event as an NDJSON line (`{...}\\n`) for {@link SinkWriter.write}. */\nexport function encodeStreamEvent(event: AgentStreamEvent): Uint8Array {\n return encoder.encode(`${JSON.stringify(event)}\\n`);\n}\n\n/**\n * Read one NDJSON line back, or `null` when the line is not a stream event at all.\n *\n * `null` covers a genuinely opaque chunk, not just malformed JSON: the sink is a byte channel, so a\n * model provider is free to write anything into it and some write bare text. A caller that has to\n * CLASSIFY a chunk — the output gate, which may only forward what it can prove is not the answer —\n * treats an unreadable frame as unclassifiable rather than guessing.\n */\nexport function decodeStreamEvent(line: string): AgentStreamEvent | null {\n try {\n const parsed: unknown = JSON.parse(line);\n if (\n typeof parsed === 'object' &&\n parsed !== null &&\n typeof (parsed as AgentStreamEvent).kind === 'string'\n ) {\n return parsed as AgentStreamEvent;\n }\n } catch {\n /* not a stream event — the caller decides what an opaque chunk means */\n }\n return null;\n}\n\n/**\n * The `code` of a failed run's `event: error` frame — what a client branches on, and translates.\n * `quota_exceeded`, `output_rejected` and `structured_output_invalid` are outcomes the library words\n * itself (their `message` is safe to show as it is); the rest are crashes, whose `message` is a\n * generic sentence in production. Open-ended on purpose: a host's own runner may send other codes.\n */\nexport type AgentStreamErrorCode =\n | 'quota_exceeded'\n | 'output_rejected'\n | 'structured_output_invalid'\n /** The durable runtime refused a checkpoint position: the run's journal and its code disagree. */\n | 'replay_diverged'\n /** A model call ended without producing anything. */\n | 'model_no_output'\n | 'run_failed';\n","import { AgentStreamError } from '../spi/token-stream-sink.js';\nimport { decodeStreamEvent } from '../stream-events.js';\nimport { AgUiEncoder, type AgUiEncoderOptions } from './encoder.js';\nimport type { AgUiEvent, AgUiSourceFrame } from './types.js';\n\nexport interface AgUiStreamOptions extends AgUiEncoderOptions {\n /**\n * How long the library stream may stay silent, while the run waits on a person AND has other work\n * announced, before the AG-UI run is reported interrupted. Default 750 ms.\n *\n * Only that mixed case needs a clock. A run whose every open tool call is waiting on someone is\n * reported at once; a run waiting on no one is never cut short.\n */\n quietMs?: number;\n /** Events to write right after `RUN_STARTED` (warnings about input that was dropped). */\n preamble?: AgUiEvent[];\n}\n\nconst DEFAULT_QUIET_MS = 750;\nconst GRACE_MS = 50;\n\ntype Next = IteratorResult<AgUiSourceFrame> | 'quiet';\n\n/**\n * One AG-UI run over a library run's stream.\n *\n * AG-UI has no mid-run channel from the consumer: a run that needs an approval or an answer does not\n * wait with the connection open — it ENDS, saying what it waits for, and a later run carries the\n * answers. The library run underneath does wait (parked, durably when the runner is durable). So this\n * stops reading when the run is waiting on someone and nothing else is moving, closes the AG-UI run\n * with the interrupt outcome, and leaves the library run parked for the resume to pick up.\n */\nexport async function* agUiEvents(\n frames: AsyncIterable<AgUiSourceFrame>,\n options: AgUiStreamOptions,\n): AsyncGenerator<AgUiEvent> {\n const encoder = new AgUiEncoder(options);\n const quietMs = options.quietMs ?? DEFAULT_QUIET_MS;\n yield* encoder.start();\n yield* options.preamble ?? [];\n const iterator = frames[Symbol.asyncIterator]();\n let upcoming: Promise<IteratorResult<AgUiSourceFrame>> | undefined;\n let ended = false;\n try {\n for (;;) {\n upcoming ??= iterator.next();\n // Frames buffered before this reader attached are replayed without a pause between them, so\n // \"is it waiting?\" is only asked of a stream that has caught up with what it already holds.\n const caughtUp = encoder.consumed >= (options.skip ?? 0);\n let next: Next;\n if (caughtUp && encoder.waiting) {\n // Nothing else in flight: only a frame already on its way (a sink that reads in batches)\n // can still arrive, so a short grace is enough. Otherwise wait out the quiet window.\n next = await raceQuiet(upcoming, encoder.busy ? quietMs : Math.min(quietMs, GRACE_MS));\n } else {\n next = await upcoming;\n }\n if (next === 'quiet') break;\n upcoming = undefined;\n if (next.done === true) {\n ended = true;\n break;\n }\n yield* encoder.encode(next.value);\n }\n } finally {\n // Stop following the library stream; the run it carries is left exactly as it is.\n void iterator.return?.();\n }\n yield* encoder.finish(ended);\n}\n\nfunction raceQuiet(upcoming: Promise<IteratorResult<AgUiSourceFrame>>, ms: number): Promise<Next> {\n return new Promise<Next>((resolve, reject) => {\n const timer = setTimeout(() => resolve('quiet'), ms);\n upcoming.then(\n (result) => {\n clearTimeout(timer);\n resolve(result);\n },\n (error: unknown) => {\n clearTimeout(timer);\n reject(error);\n },\n );\n });\n}\n\n/** One AG-UI event as an SSE frame: a single `data:` line, LF-terminated, as the binding pins. */\nexport function agUiSse(event: AgUiEvent): string {\n return `data: ${JSON.stringify(event)}\\n\\n`;\n}\n\n/**\n * A byte sink's stream (NDJSON {@link AgentStreamEvent}s, one per line, as the NestJS sinks carry\n * it) as the frames the encoder reads. A line that is not a stream event is bare model text — the\n * sink is a byte channel and a provider may write raw text into it. A run that failed ends the\n * sink with an {@link AgentStreamError}, which becomes the terminal `error` frame; anything else\n * thrown is rethrown, for the caller to report.\n */\nexport async function* agUiFramesFromNdjson(\n chunks: AsyncIterable<Uint8Array>,\n): AsyncGenerator<AgUiSourceFrame> {\n const decoder = new TextDecoder();\n let buffer = '';\n // Bare text has no line end of its own, so the event written after it shares its line.\n const read = (line: string): AgUiSourceFrame[] => {\n const event = decodeStreamEvent(line) as AgUiSourceFrame | null;\n if (event !== null) return [event];\n const at = line.indexOf('{\"kind\":');\n const tail = at > 0 ? (decodeStreamEvent(line.slice(at)) as AgUiSourceFrame | null) : null;\n if (tail !== null) return [{ kind: 'text', text: line.slice(0, at) }, tail];\n return [{ kind: 'text', text: line }];\n };\n try {\n for await (const chunk of chunks) {\n buffer += decoder.decode(chunk, { stream: true });\n let newline = buffer.indexOf('\\n');\n while (newline !== -1) {\n const line = buffer.slice(0, newline);\n buffer = buffer.slice(newline + 1);\n if (line.length > 0) yield* read(line);\n newline = buffer.indexOf('\\n');\n }\n }\n buffer += decoder.decode();\n if (buffer.length > 0) yield* read(buffer);\n } catch (error) {\n if (error instanceof AgentStreamError) {\n yield { kind: 'error', code: error.code, message: error.message };\n return;\n }\n throw error;\n }\n}\n","import { AG_UI_CUSTOM, AG_UI_PROTOCOL_VERSION, type AgUiEvent } from './types.js';\n\n/** A decision-only protocol invocation: no model run, stream holder or tool execution is created. */\nexport function actionProposalDecisionEvents(input: {\n threadId: string;\n runId: string;\n text: string;\n proposalDecision: unknown;\n}): AgUiEvent[] {\n const messageId = `${input.runId}:proposal-decision`;\n return [\n {\n type: 'RUN_STARTED',\n threadId: input.threadId,\n runId: input.runId,\n protocolVersion: AG_UI_PROTOCOL_VERSION,\n },\n {\n type: 'CUSTOM',\n name: AG_UI_CUSTOM.actionProposalDecision,\n value: { threadId: input.threadId, proposalDecision: input.proposalDecision },\n },\n { type: 'TEXT_MESSAGE_START', messageId, role: 'assistant' },\n { type: 'TEXT_MESSAGE_CONTENT', messageId, delta: input.text },\n { type: 'TEXT_MESSAGE_END', messageId },\n { type: 'RUN_FINISHED', threadId: input.threadId, runId: input.runId },\n ];\n}\n"],"mappings":";;;;AA4BA,IAAMA,aAAa;EAAEC,UAAU;EAAKC,aAAa;EAAKC,UAAU;AAAI;AAEpE,IAAMC,SAAS;AAER,SAASC,kBAAkBC,SAAyB;AACzD,QAAMC,UAAqB;IACzBP,WAAWM,QAAQE,IAAI;IACvBF,QAAQG;IACRH,QAAQI;IACRJ,QAAQK;IACRL,QAAQM;;AAEV,MAAIN,QAAQE,SAAS,WAAYD,SAAQM,KAAKP,QAAQQ,YAAYR,QAAQS,QAAQ;AAClF,SAAOX,SAASY,OAAOC,KAAKC,KAAKC,UAAUZ,OAAAA,GAAU,MAAA,EAAQa,SAAS,WAAA;AACxE;AAVgBf;AAaT,SAASgB,kBAAkBC,IAAW;AAC3C,MAAI,OAAOA,OAAO,YAAY,CAACA,GAAGC,WAAWnB,MAAAA,EAAS,QAAO;AAC7D,MAAI;AACF,UAAMoB,SAAkBN,KAAKO,MAC3BT,OAAOC,KAAKK,GAAGI,MAAMtB,OAAOuB,MAAM,GAAG,WAAA,EAAaP,SAAS,MAAA,CAAA;AAE7D,QAAI,CAACQ,MAAMC,QAAQL,MAAAA,EAAS,QAAO;A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AAA;AACjCW,kBAAUb,OAAOK,QAAQ,IAAA;MAC3B;IACF;AACAL,cAAUF,QAAQa,OAAM;AACxB,QAAIX,OAAOc,SAAS,EAAG,QAAOb,KAAKD,MAAAA;EACrC,SAAST,OAAO;AACd,QAAIA,iBAAiBwB,kBAAkB;AACrC,YAAM;QAAEP,MAAM;QAASQ,MAAMzB,MAAMyB;QAAMC,SAAS1B,MAAM0B;MAAQ;AAChE;IACF;AACA,UAAM1B;EACR;AACF;AAlCuBK;;;ACjGhB,SAASsB,6BAA6BC,OAK5C;AACC,QAAMC,YAAY,GAAGD,MAAME,KAAK;AAChC,SAAO;IACL;MACEC,MAAM;MACNC,UAAUJ,MAAMI;MAChBF,OAAOF,MAAME;MACbG,iBAAiBC;IACnB;IACA;MACEH,MAAM;MACNI,MAAMC,aAAaC;MACnBC,OAAO;QAAEN,UAAUJ,MAAMI;QAAUO,kBAAkBX,MAAMW;MAAiB;IAC9E;IACA;MAAER,MAAM;MAAsBF;MAAWW,MAAM;IAAY;IAC3D;MAAET,MAAM;MAAwBF;MAAWY,OAAOb,MAAMc;IAAK;IAC7D;MAAEX,MAAM;MAAoBF;IAAU;IACtC;MAAEE,MAAM;MAAgBC,UAAUJ,MAAMI;MAAUF,OAAOF,MAAME;IAAM;;AAEzE;AAxBgBH;","names":["KIND_CODES","approval","elicitation","proposal","PREFIX","encodeInterruptId","address","compact","kind","parked","stream","toolCallId","position","push","proposalId","threadId","Buffer","from","JSON","stringify","toString","decodeInterruptId","id","startsWith","parsed","parse","slice","length","Array","isArray","Number","isSafeInteger","AG_UI_PROTOCOL_VERSION","AG_UI_CUSTOM","run","ui","title","queue","approvalRequested","approvalSettled","elicitation","stepUsage","actionProposalDecision","warning","APPROVAL_SCHEMA","type","properties","approved","reason","remember","required","elicitationSchema","request","question","questions","options","map","option","value","id","title","prompt","description","undefined","items","length","allowFreeText","enum","multiple","maxItems","defaults","default","answers","text","json","JSON","stringify","AgUiEncoder","position","started","closed","cancelled","crossed","messageSeq","stepSeq","openText","openReasoning","stepMessage","openSteps","calls","Map","pending","usage","consumed","waiting","size","busy","call","answered","has","start","threadId","runId","protocolVersion","AG_UI_PROTOCOL_VERSION","name","AG_UI_CUSTOM","run","streamRunId","streamThreadId","encode","frame","skip","crossBoundary","events","project","values","ended","delete","replaying","event","kind","usageEntries","message","code","custom","ui","component","props","version","fallbackText","componentVersions","toolCallId","get","parked","toolName","input","proposal","target","set","proposalId","interrupt","responseSchema","expiresAt","metadata","approver","approvalRequested","confirmation","preamble","elicitation","textDelta","reasoningDelta","stepName","push","closeStreams","out","addUsage","model","pop","costUsd","stepUsage","reasoningMs","sawDelta","callStart","delta","known","result","output","error","approvalSettled","queue","finish","clear","interrupts","outcome","entry","encodeInterruptId","stream","nextMessageId","closeReasoning","messageId","role","closeText","toolCallName","parentMessageId","content","key","inputTokens","outputTokens","totalTokens","cacheReadTokens","cachedInputTokens","cacheWriteTokens","cacheWriteInputTokens","reasoningTokens","COMPONENT_NAME","validateUiCapabilities","value","record","Object","keys","some","key","Array","isArray","components","TypeError","seen","Set","map","component","name","COMPONENT_NAME","test","Number","isSafeInteger","version","has","add","isRecord","value","Array","isArray","parseRunInput","body","threadId","length","runId","messages","message","role","resume","undefined","entry","interruptId","status","context","forwardedProps","Object","hasOwn","validateUiCapabilities","uiCapabilities","EXTENSIONS","filenameOf","part","index","contentType","metadata","key","trim","slice","extension","type","readUserTurn","last","content","text","media","dropped","texts","forEach","push","source","how","mimeType","data","Buffer","from","toLowerCase","kind","filename","join","readContext","entries","filter","description","readForwardedProps","forwarded","pick","agent","model","persona","pageContext","planResume","decisions","unrecognised","address","decodeInterruptId","first","stream","position","seen","Set","has","toolCallId","add","readApprovalPayload","payload","approved","reason","remember","readAnswersPayload","answers","every","item","AgentStreamError","Error","code","error","message","name","encoder","TextEncoder","decodeStreamEvent","line","parsed","JSON","parse","kind","DEFAULT_QUIET_MS","GRACE_MS","agUiEvents","frames","options","encoder","AgUiEncoder","quietMs","start","preamble","iterator","Symbol","asyncIterator","upcoming","ended","next","caughtUp","consumed","skip","waiting","raceQuiet","busy","Math","min","undefined","done","encode","value","return","finish","ms","Promise","resolve","reject","timer","setTimeout","then","result","clearTimeout","error","agUiSse","event","JSON","stringify","agUiFramesFromNdjson","chunks","decoder","TextDecoder","buffer","read","line","decodeStreamEvent","at","indexOf","tail","slice","kind","text","chunk","decode","stream","newline","length","AgentStreamError","code","message","actionProposalDecisionEvents","input","messageId","runId","type","threadId","protocolVersion","AG_UI_PROTOCOL_VERSION","name","AG_UI_CUSTOM","actionProposalDecision","value","proposalDecision","role","delta","text"]}
|
|
@@ -85,6 +85,8 @@ interface ComponentDefinition<P = Record<string, unknown>> {
|
|
|
85
85
|
description: string;
|
|
86
86
|
/** The props schema: a Standard Schema (Zod, Valibot, ArkType) or a JSON Schema object. */
|
|
87
87
|
props: PropsSchema;
|
|
88
|
+
/** Portable normalized props schema. Required when input transformations are not idempotent. */
|
|
89
|
+
outputProps?: PropsSchema;
|
|
88
90
|
/**
|
|
89
91
|
* The component takes nested elements (a layout: `Stack`, `Card`). Only meaningful in tree mode,
|
|
90
92
|
* where a node's `children` are validated against the catalog too.
|
|
@@ -85,6 +85,8 @@ interface ComponentDefinition<P = Record<string, unknown>> {
|
|
|
85
85
|
description: string;
|
|
86
86
|
/** The props schema: a Standard Schema (Zod, Valibot, ArkType) or a JSON Schema object. */
|
|
87
87
|
props: PropsSchema;
|
|
88
|
+
/** Portable normalized props schema. Required when input transformations are not idempotent. */
|
|
89
|
+
outputProps?: PropsSchema;
|
|
88
90
|
/**
|
|
89
91
|
* The component takes nested elements (a layout: `Stack`, `Card`). Only meaningful in tree mode,
|
|
90
92
|
* where a node's `children` are validated against the catalog too.
|