@assistant-ui/react-ag-ui 0.0.59 → 0.0.61

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.
Files changed (45) hide show
  1. package/dist/agUiExtras.d.ts +2 -5
  2. package/dist/agUiExtras.d.ts.map +1 -1
  3. package/dist/hooks.d.ts +9 -12
  4. package/dist/hooks.d.ts.map +1 -1
  5. package/dist/index.d.ts +7 -5
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/runtime/AgUiThreadRuntimeCore.d.ts +153 -146
  8. package/dist/runtime/AgUiThreadRuntimeCore.d.ts.map +1 -1
  9. package/dist/runtime/AgUiThreadRuntimeCore.js +146 -26
  10. package/dist/runtime/AgUiThreadRuntimeCore.js.map +1 -1
  11. package/dist/runtime/adapter/conversions.d.ts +54 -56
  12. package/dist/runtime/adapter/conversions.d.ts.map +1 -1
  13. package/dist/runtime/adapter/conversions.js +164 -23
  14. package/dist/runtime/adapter/conversions.js.map +1 -1
  15. package/dist/runtime/adapter/run-aggregator.d.ts +98 -98
  16. package/dist/runtime/adapter/run-aggregator.d.ts.map +1 -1
  17. package/dist/runtime/adapter/run-aggregator.js +35 -2
  18. package/dist/runtime/adapter/run-aggregator.js.map +1 -1
  19. package/dist/runtime/adapter/subscriber.d.ts +109 -111
  20. package/dist/runtime/adapter/subscriber.d.ts.map +1 -1
  21. package/dist/runtime/adapter/tool-approval.d.ts +7 -9
  22. package/dist/runtime/adapter/tool-approval.d.ts.map +1 -1
  23. package/dist/runtime/event-parser.d.ts +5 -8
  24. package/dist/runtime/event-parser.d.ts.map +1 -1
  25. package/dist/runtime/interrupt-internals.d.ts +4 -7
  26. package/dist/runtime/interrupt-internals.d.ts.map +1 -1
  27. package/dist/runtime/logger.d.ts +4 -7
  28. package/dist/runtime/logger.d.ts.map +1 -1
  29. package/dist/runtime/mcp-tool-result.d.ts +7 -10
  30. package/dist/runtime/mcp-tool-result.d.ts.map +1 -1
  31. package/dist/runtime/types.d.ts +248 -250
  32. package/dist/runtime/types.d.ts.map +1 -1
  33. package/dist/useAgUiRuntime.d.ts +15 -18
  34. package/dist/useAgUiRuntime.d.ts.map +1 -1
  35. package/dist/useAgUiRuntime.js +9 -2
  36. package/dist/useAgUiRuntime.js.map +1 -1
  37. package/package.json +12 -11
  38. package/src/runtime/AgUiThreadRuntimeCore.ts +246 -30
  39. package/src/runtime/adapter/conversions.content.test.ts +56 -0
  40. package/src/runtime/adapter/conversions.ts +278 -36
  41. package/src/runtime/adapter/run-aggregator.ts +53 -2
  42. package/src/useAgUiRuntime.history.test.tsx +93 -2
  43. package/src/useAgUiRuntime.thread-switch.test.tsx +84 -4
  44. package/src/useAgUiRuntime.ts +12 -3
  45. package/src/useAgUiRuntime.voice.test.tsx +402 -0
@@ -1 +1 @@
1
- {"version":3,"file":"conversions.js","names":[],"sources":["../../../src/runtime/adapter/conversions.ts"],"sourcesContent":["\"use client\";\n\nimport type { InputContent, RunAgentParameters } from \"@ag-ui/client\";\nimport { generateId } from \"@assistant-ui/core\";\nimport type {\n ThreadMessageLike as CoreThreadMessageLike,\n PartProviderMetadata,\n ThreadMessage,\n ToolCallMessagePartMcpMetadata,\n ToolModelContentPart,\n} from \"@assistant-ui/core\";\nimport {\n getAutoStatus,\n parseDataUrl,\n resolveFilePartSource,\n} from \"@assistant-ui/core/internal\";\nimport { type Tool, toToolsJSONSchema } from \"assistant-stream\";\nimport type { ReadonlyJSONObject } from \"assistant-stream/utils\";\nimport {\n AG_UI_METADATA_NAMESPACE,\n A2UI_SURFACE_ACTIVITY_TYPE,\n type AgUiCustomMetadata,\n type AgUiOpaqueReasoning,\n} from \"./run-aggregator\";\nimport {\n applyA2uiOperations,\n convertSurfaceToUISpec,\n type A2uiState,\n type A2uiSurfaceState,\n} from \"@assistant-ui/react-generative-ui/a2ui\";\nimport type { AgUiInterrupt } from \"../types\";\nimport { projectAgUiToolApprovals } from \"./tool-approval\";\nimport {\n parseMcpToolCallResult,\n readMcpAppResourceUri,\n} from \"../mcp-tool-result\";\n\nexport type { InputContent };\n\ntype AttachmentLike = {\n name?: string | undefined;\n contentType?: string | undefined;\n content?: readonly unknown[] | undefined;\n};\n\ntype ThreadMessageLike = {\n id?: string;\n role: string;\n content: unknown;\n metadata?: unknown;\n name?: string;\n toolCallId?: string;\n error?: string;\n attachments?: readonly AttachmentLike[];\n};\n\ntype NormalizedThreadMessageLike = ThreadMessageLike & { id: string };\n\ntype AgUiToolCall = {\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n};\n\nexport type AgUiMessage =\n | {\n id: string;\n role: \"user\";\n content: string | InputContent[];\n name?: string;\n }\n | {\n id: string;\n role: \"assistant\";\n content: string;\n name?: string;\n toolCalls?: AgUiToolCall[];\n }\n | {\n id: string;\n role: \"system\" | \"developer\";\n content: string;\n name?: string;\n }\n | {\n id: string;\n role: \"reasoning\";\n content: string;\n encryptedValue?: string;\n }\n | {\n id: string;\n role: \"tool\";\n content: string;\n toolCallId: string;\n error?: string;\n };\n\ntype ToolCallPart = {\n type: \"tool-call\";\n toolCallId?: string;\n toolName: string;\n argsText?: string;\n args?: ReadonlyJSONObject;\n result?: unknown;\n isError?: boolean;\n modelContent?: readonly ToolModelContentPart[];\n unstable_toolMessageId?: string;\n mcp?: ToolCallMessagePartMcpMetadata;\n messages?: readonly ThreadMessage[];\n approval?: CoreToolCallPartApproval;\n};\n\ntype CoreToolCallPartApproval = NonNullable<\n Extract<\n Exclude<CoreThreadMessageLike[\"content\"], string>[number],\n { type: \"tool-call\" }\n >[\"approval\"]\n>;\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst getString = (record: Record<string, unknown>, key: string) => {\n const value = record[key];\n return typeof value === \"string\" ? value : undefined;\n};\n\nconst getToolCallId = (record: Record<string, unknown>) =>\n getString(record, \"toolCallId\") ?? getString(record, \"tool_call_id\");\n\nconst readAgUiNamespace = (providerMetadata: unknown) => {\n if (!isObject(providerMetadata)) return undefined;\n const namespaced = providerMetadata[AG_UI_METADATA_NAMESPACE];\n return isObject(namespaced) ? namespaced : undefined;\n};\n\nconst readAgUiReasoningMeta = (providerMetadata: unknown) => {\n const namespaced = readAgUiNamespace(providerMetadata);\n if (!namespaced) return {};\n return {\n encryptedValue: getString(namespaced, \"encryptedValue\"),\n reasoningId: getString(namespaced, \"reasoningId\"),\n };\n};\n\n// AG-UI carries per-item extras in `metadata`; anything else on the item is\n// stripped by its schema. The part's own `filename` wins over a key of the\n// same name in the bag.\nconst buildInputMetadata = (\n part: Record<string, unknown>,\n filename?: string | undefined,\n) => {\n const metadata = {\n ...readAgUiNamespace(part.providerMetadata),\n ...(filename !== undefined && { filename }),\n };\n return Object.keys(metadata).length > 0 ? metadata : undefined;\n};\n\n// The inverse: `filename` lands on the part's own field, everything else the\n// item carried goes back into the namespace it came from, so a snapshot echo\n// resends what the host attached.\nconst readInputMetadata = (\n metadata: unknown,\n): {\n filename?: string | undefined;\n providerMetadata?: PartProviderMetadata | undefined;\n} => {\n if (!isObject(metadata)) return {};\n const { filename: _filename, ...rest } = metadata;\n return {\n filename: getString(metadata, \"filename\"),\n ...(Object.keys(rest).length > 0 && {\n providerMetadata: {\n [AG_UI_METADATA_NAMESPACE]: rest as PartProviderMetadata[string],\n },\n }),\n };\n};\n\nfunction parseJSONText(value: string): unknown {\n if (!value) return value;\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nfunction normalizeToolCall(part: ToolCallPart): {\n id: string;\n call: AgUiToolCall;\n} {\n const id = part.toolCallId ?? generateId();\n const argsText =\n typeof part.argsText === \"string\"\n ? part.argsText\n : JSON.stringify(part.args ?? {});\n\n return {\n id,\n call: {\n id,\n type: \"function\",\n function: {\n name: part.toolName ?? \"tool\",\n arguments: argsText,\n },\n },\n };\n}\n\nfunction extractText(content: unknown): string {\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n\n return content\n .filter(\n (part): part is { type: \"text\"; text: string } =>\n part?.type === \"text\" && typeof part?.text === \"string\",\n )\n .map((part) => part.text)\n .join(\"\\n\");\n}\n\ntype InputContentSource =\n | { type: \"data\"; value: string; mimeType: string }\n | { type: \"url\"; value: string; mimeType?: string };\n\ntype MediaInputType = \"image\" | \"audio\" | \"video\" | \"document\";\n\nfunction mediaTypeForMime(mimeType: string | undefined): MediaInputType {\n if (mimeType?.startsWith(\"image/\")) return \"image\";\n if (mimeType?.startsWith(\"audio/\")) return \"audio\";\n if (mimeType?.startsWith(\"video/\")) return \"video\";\n return \"document\";\n}\n\n// Build an AG-UI multimodal source from a data URL, raw base64 payload, or an\n// http(s) URL. A `url` source may omit the mime type; a `data` source always\n// resolves one (falling back to application/octet-stream). An explicit\n// `sourceType: \"url\"` on the part forces the url leg for non-http references.\nfunction buildInputSource(\n value: string,\n declaredMimeType: string | undefined,\n sourceType?: string,\n): InputContentSource {\n const source = resolveFilePartSource({\n data: value,\n mimeType: declaredMimeType ?? \"application/octet-stream\",\n sourceType,\n });\n if (source.kind === \"url\") {\n return declaredMimeType !== undefined\n ? { type: \"url\", value: source.url, mimeType: declaredMimeType }\n : { type: \"url\", value: source.url };\n }\n return {\n type: \"data\",\n value: source.data,\n mimeType: source.mimeType,\n };\n}\n\nfunction toInputContent(\n part: unknown,\n fallbackMimeType: string | undefined,\n): InputContent | null {\n if (!isObject(part)) return null;\n const type = getString(part, \"type\");\n\n if (type === \"text\") {\n const text = getString(part, \"text\");\n if (text === undefined) return null;\n return { type: \"text\", text };\n }\n\n if (type === \"image\") {\n const image = getString(part, \"image\");\n if (image === undefined) return null;\n const metadata = buildInputMetadata(part, getString(part, \"filename\"));\n return {\n type: \"image\",\n source: buildInputSource(image, fallbackMimeType),\n ...(metadata && { metadata }),\n };\n }\n\n if (type === \"file\") {\n const data = getString(part, \"data\");\n if (data === undefined) return null;\n const declaredMimeType = getString(part, \"mimeType\") || fallbackMimeType;\n const filename = getString(part, \"filename\");\n const source = buildInputSource(\n data,\n declaredMimeType,\n getString(part, \"sourceType\"),\n );\n const metadata = buildInputMetadata(part, filename);\n switch (mediaTypeForMime(source.mimeType)) {\n case \"image\":\n return { type: \"image\", source, ...(metadata && { metadata }) };\n case \"audio\":\n return { type: \"audio\", source, ...(metadata && { metadata }) };\n case \"video\":\n return { type: \"video\", source, ...(metadata && { metadata }) };\n default:\n return { type: \"document\", source, ...(metadata && { metadata }) };\n }\n }\n\n if (type === \"audio\") {\n const audio = part.audio;\n if (!isObject(audio)) return null;\n const data = getString(audio, \"data\");\n const format = getString(audio, \"format\");\n if (data === undefined || format === undefined) return null;\n return {\n type: \"audio\",\n source: buildInputSource(\n parseDataUrl(data)?.data ?? data,\n `audio/${format}`,\n ),\n };\n }\n\n return null;\n}\n\ntype SnapshotAttachment = NonNullable<\n CoreThreadMessageLike[\"attachments\"]\n>[number];\n\nconst mediaInputTypes = new Set([\"image\", \"audio\", \"video\", \"document\"]);\n\n// Inverse of buildInputSource.\nfunction inputSourceToString(\n value: unknown,\n): { value: string; mimeType?: string; isUrl?: boolean } | null {\n if (!isObject(value)) return null;\n const sourceValue = getString(value, \"value\");\n if (sourceValue === undefined) return null;\n const mimeType = getString(value, \"mimeType\");\n const type = getString(value, \"type\");\n if (type === \"url\") {\n return {\n value: sourceValue,\n isUrl: true,\n ...(mimeType !== undefined && { mimeType }),\n };\n }\n if (type === \"data\") {\n const resolvedMimeType = mimeType ?? \"application/octet-stream\";\n return {\n value: `data:${resolvedMimeType};base64,${sourceValue}`,\n mimeType: resolvedMimeType,\n };\n }\n return null;\n}\n\n// Mirrors @ag-ui/client's BackwardCompatibility_0_0_47 middleware.\nfunction upgradeBinaryInputPart(\n part: Record<string, unknown>,\n): Record<string, unknown> | null {\n const mimeType = getString(part, \"mimeType\");\n if (mimeType === undefined) return null;\n const data = getString(part, \"data\");\n const url = getString(part, \"url\");\n const source = data\n ? { type: \"data\", value: data, mimeType }\n : url\n ? { type: \"url\", value: url, mimeType }\n : null;\n if (!source) return null;\n const filename = getString(part, \"filename\");\n return {\n type: mediaTypeForMime(mimeType),\n source,\n ...(filename && { metadata: { filename } }),\n };\n}\n\nfunction toSnapshotAttachments(content: unknown): SnapshotAttachment[] {\n if (!Array.isArray(content)) return [];\n\n const attachments: SnapshotAttachment[] = [];\n for (const rawPart of content) {\n if (!isObject(rawPart)) continue;\n const part =\n getString(rawPart, \"type\") === \"binary\"\n ? upgradeBinaryInputPart(rawPart)\n : rawPart;\n if (!part) continue;\n const type = getString(part, \"type\");\n if (type === undefined || !mediaInputTypes.has(type)) continue;\n const source = inputSourceToString(part.source);\n if (!source) continue;\n\n const { filename, providerMetadata } = readInputMetadata(part.metadata);\n const id = attachments.length.toString();\n\n if (type === \"image\") {\n attachments.push({\n id,\n type: \"image\",\n name: filename ?? \"image\",\n ...(source.mimeType !== undefined && { contentType: source.mimeType }),\n status: { type: \"complete\" },\n content: [\n {\n type: \"image\",\n image: source.value,\n ...(filename !== undefined && { filename }),\n ...(providerMetadata && { providerMetadata }),\n },\n ],\n });\n continue;\n }\n\n const mimeType = source.mimeType ?? \"application/octet-stream\";\n attachments.push({\n id,\n type: type === \"document\" ? \"document\" : \"file\",\n name: filename ?? \"file\",\n contentType: mimeType,\n status: { type: \"complete\" },\n content: [\n {\n type: \"file\",\n data: source.value,\n mimeType,\n ...(source.isUrl && { sourceType: \"url\" as const }),\n ...(filename !== undefined && { filename }),\n ...(providerMetadata && { providerMetadata }),\n },\n ],\n });\n }\n return attachments;\n}\n\nfunction buildUserContent(message: ThreadMessageLike): string | InputContent[] {\n const contentParts = Array.isArray(message.content) ? message.content : [];\n\n const attachments = message.attachments ?? [];\n\n const converted: InputContent[] = [];\n\n // Promote string-form content to a leading text part so it survives when\n // non-text attachments are present (fromAgUiMessages emits string content).\n if (typeof message.content === \"string\" && message.content.length > 0) {\n converted.push({ type: \"text\", text: message.content });\n }\n\n for (const part of contentParts) {\n const input = toInputContent(part, undefined);\n if (input) converted.push(input);\n }\n for (const attachment of attachments) {\n if (!isObject(attachment)) continue;\n const attachmentContent = attachment.content;\n if (!Array.isArray(attachmentContent)) continue;\n const fallbackMime = getString(attachment, \"contentType\");\n for (const part of attachmentContent) {\n const input = toInputContent(part, fallbackMime);\n if (input) converted.push(input);\n }\n }\n\n const hasNonText = converted.some((part) => part.type !== \"text\");\n if (hasNonText) return converted;\n\n // All-text path: collapse to plain string. Join text parts collected from\n // both content and attachments so attachment-sourced text is not dropped.\n if (converted.length === 0) return extractText(message.content);\n return converted\n .filter(\n (part): part is { type: \"text\"; text: string } => part.type === \"text\",\n )\n .map((part) => part.text)\n .join(\"\\n\");\n}\n\nfunction toToolCallPart(value: unknown): ToolCallPart | null {\n if (!isObject(value)) return null;\n const rawFunction = isObject(value.function) ? value.function : null;\n const toolCallId = getString(value, \"toolCallId\") ?? getString(value, \"id\");\n const toolName =\n getString(value, \"toolName\") ??\n getString(value, \"name\") ??\n (rawFunction ? getString(rawFunction, \"name\") : undefined) ??\n \"tool\";\n const argsText =\n getString(value, \"argsText\") ??\n getString(value, \"arguments\") ??\n (rawFunction ? getString(rawFunction, \"arguments\") : undefined);\n\n const parsedArgs =\n typeof argsText === \"string\" ? parseJSONText(argsText) : undefined;\n const args =\n isObject(parsedArgs) && !Array.isArray(parsedArgs)\n ? (parsedArgs as ReadonlyJSONObject)\n : isObject(value.args) && !Array.isArray(value.args)\n ? (value.args as ReadonlyJSONObject)\n : undefined;\n\n const part: ToolCallPart = {\n type: \"tool-call\",\n ...(toolCallId !== undefined ? { toolCallId } : {}),\n toolName,\n argsText: argsText ?? JSON.stringify(args ?? {}),\n ...(args !== undefined ? { args } : {}),\n };\n\n if (value.type === \"tool-call\") {\n const result = value.result;\n const isError = value.isError;\n if (result !== undefined) part.result = result;\n if (typeof isError === \"boolean\") part.isError = isError;\n }\n\n return part;\n}\n\nfunction extractAssistantToolCalls(\n message: Record<string, unknown>,\n): ToolCallPart[] {\n const parts: ToolCallPart[] = [];\n const seenToolCallIds = new Set<string>();\n const pushPart = (part: ToolCallPart | null) => {\n if (!part) return;\n const id = part.toolCallId ?? generateId();\n if (seenToolCallIds.has(id)) return;\n seenToolCallIds.add(id);\n parts.push({\n ...part,\n toolCallId: id,\n });\n };\n\n const content = message.content;\n if (Array.isArray(content)) {\n for (const part of content) {\n if (isObject(part) && part.type === \"tool-call\") {\n pushPart(toToolCallPart(part));\n }\n }\n }\n\n const toolCalls = Array.isArray(message.toolCalls)\n ? message.toolCalls\n : Array.isArray(message.tool_calls)\n ? message.tool_calls\n : [];\n for (const call of toolCalls) {\n pushPart(toToolCallPart(call));\n }\n\n return parts;\n}\n\nfunction validateInterrupts(value: unknown): AgUiInterrupt[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const valid = value.filter(\n (entry): entry is AgUiInterrupt =>\n isObject(entry) &&\n typeof entry.id === \"string\" &&\n typeof entry.reason === \"string\",\n );\n return valid.length > 0 ? valid : undefined;\n}\n\nfunction readPersistedInterrupts(\n metadata: unknown,\n): AgUiInterrupt[] | undefined {\n if (!isObject(metadata)) return undefined;\n const custom = metadata.custom;\n if (!isObject(custom)) return undefined;\n const namespaced = custom[AG_UI_METADATA_NAMESPACE];\n if (!isObject(namespaced)) return undefined;\n return validateInterrupts(namespaced.interrupts);\n}\n\nfunction readOpaqueReasoning(metadata: unknown): AgUiOpaqueReasoning[] {\n if (!isObject(metadata)) return [];\n const custom = metadata.custom;\n if (!isObject(custom)) return [];\n const namespaced = custom[AG_UI_METADATA_NAMESPACE];\n if (!isObject(namespaced)) return [];\n const entries = namespaced.opaqueReasoning;\n if (!Array.isArray(entries)) return [];\n return entries.flatMap((entry) => {\n if (!isObject(entry)) return [];\n const id = getString(entry, \"id\");\n const encryptedValue = getString(entry, \"encryptedValue\");\n if (!id?.trim() || !encryptedValue?.trim()) return [];\n return [\n { id, encryptedValue, ...(entry.after === true ? { after: true } : {}) },\n ];\n });\n}\n\nfunction withOpaqueReasoning(\n message: CoreThreadMessageLike,\n opaqueReasoning: AgUiOpaqueReasoning[],\n): CoreThreadMessageLike {\n const metadata = isObject(message.metadata) ? message.metadata : {};\n const custom = isObject(metadata.custom) ? metadata.custom : {};\n const namespaced = isObject(custom[AG_UI_METADATA_NAMESPACE])\n ? (custom[AG_UI_METADATA_NAMESPACE] as Record<string, unknown>)\n : {};\n return {\n ...message,\n metadata: {\n ...metadata,\n custom: {\n ...custom,\n [AG_UI_METADATA_NAMESPACE]: { ...namespaced, opaqueReasoning },\n },\n },\n } as CoreThreadMessageLike;\n}\n\nfunction toAssistantSnapshotMessage(\n rawMessage: Record<string, unknown>,\n): CoreThreadMessageLike {\n const text = extractText(rawMessage.content);\n const interrupts = readPersistedInterrupts(rawMessage.metadata);\n const restoredToolCalls = extractAssistantToolCalls(rawMessage);\n const approvals = projectAgUiToolApprovals(\n interrupts,\n new Set(\n restoredToolCalls\n .map((part) => part.toolCallId)\n .filter((id): id is string => !!id),\n ),\n );\n const toolCallParts = restoredToolCalls.map((part) => {\n const approval = part.toolCallId\n ? approvals.get(part.toolCallId)\n : undefined;\n return approval ? { ...part, approval } : part;\n });\n const assistantContent = [\n ...(text.length > 0 ? [{ type: \"text\" as const, text }] : []),\n ...toolCallParts,\n ];\n const messageName = getString(rawMessage, \"name\");\n return {\n id: getString(rawMessage, \"id\") ?? generateId(),\n role: \"assistant\",\n content: assistantContent.length > 0 ? assistantContent : \"\",\n ...(messageName !== undefined ? { name: messageName } : {}),\n ...(interrupts\n ? {\n metadata: {\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n interrupts,\n } satisfies AgUiCustomMetadata,\n },\n },\n }\n : {}),\n };\n}\n\nfunction toUserOrSystemSnapshotMessage(\n role: \"user\" | \"system\" | \"developer\",\n rawMessage: Record<string, unknown>,\n): CoreThreadMessageLike {\n const messageName = getString(rawMessage, \"name\");\n const attachments =\n role === \"user\" ? toSnapshotAttachments(rawMessage.content) : [];\n return {\n id: getString(rawMessage, \"id\") ?? generateId(),\n // The internal message model has no developer role; it rides as a system\n // message with its wire role kept in metadata so the export restores it.\n role: role === \"developer\" ? \"system\" : role,\n content: extractText(rawMessage.content),\n ...(messageName !== undefined ? { name: messageName } : {}),\n ...(attachments.length > 0 ? { attachments } : {}),\n ...(role === \"developer\"\n ? {\n metadata: {\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n role: \"developer\",\n } satisfies AgUiCustomMetadata,\n },\n },\n }\n : {}),\n };\n}\n\n// Rebuilds the a2ui:<surfaceId> \"present\" tool-call parts for one owning\n// assistant message from a bucket of rebuilt surface state, mirroring the\n// live RunAggregator.synthesizeA2uiToolCalls shape. Non-a2ui parts (text,\n// other tool calls) are preserved; existing a2ui parts are replaced wholesale\n// so create/update/delete within the bucket all converge on the rebuilt set.\nfunction attachA2uiSurfaces(\n message: CoreThreadMessageLike,\n state: A2uiState,\n): CoreThreadMessageLike {\n const a2uiParts: ToolCallPart[] = [];\n for (const [surfaceId, surface] of state) {\n const { spec } = convertSurfaceToUISpec(surface);\n if (!spec) continue;\n a2uiParts.push({\n type: \"tool-call\",\n toolCallId: `a2ui:${surfaceId}`,\n toolName: \"present\",\n args: spec as unknown as ReadonlyJSONObject,\n argsText: JSON.stringify(spec),\n result: {},\n });\n }\n\n const content = Array.isArray(message.content) ? message.content : [];\n const preserved = content.filter(\n (part) =>\n !(\n isObject(part) &&\n part.type === \"tool-call\" &&\n typeof part.toolCallId === \"string\" &&\n part.toolCallId.startsWith(\"a2ui:\")\n ),\n );\n return { ...message, content: [...preserved, ...a2uiParts] };\n}\n\nexport type FromAgUiMessagesOptions = {\n /**\n * Whether to convert `reasoning` messages into visible reasoning parts.\n * Matches the `showThinking` option of `useAgUiRuntime`. Defaults to `true`.\n */\n showThinking?: boolean;\n};\n\nexport function fromAgUiMessages(\n messages: readonly unknown[],\n options?: FromAgUiMessagesOptions,\n): CoreThreadMessageLike[] {\n const showThinking = options?.showThinking ?? true;\n const converted: CoreThreadMessageLike[] = [];\n const a2uiBuckets = new Map<string, A2uiState>();\n const a2uiBucketOwnerIndices = new Map<string, number>();\n // A zero-data-retention run carries its payload in encryptedValue with no\n // readable content, so the record has no part to become and rides on the\n // neighbouring message instead of being dropped. The anchor is the index the\n // next pushed message will occupy, which is where it sat on the wire.\n const opaqueReasoning: (AgUiOpaqueReasoning & { anchor: number })[] = [];\n\n for (const rawMessage of messages) {\n if (!isObject(rawMessage)) continue;\n const role = getString(rawMessage, \"role\");\n if (!role) continue;\n\n if (role === \"tool\") {\n const toolCallId = getToolCallId(rawMessage) ?? `tool-${generateId()}`;\n const toolMessageId = getString(rawMessage, \"id\");\n const modelContent = extractText(rawMessage.content);\n const mcpResult = parseMcpToolCallResult(rawMessage, modelContent);\n const mcpModelContent = mcpResult\n ? [{ type: \"text\" as const, text: modelContent }]\n : undefined;\n const result =\n mcpResult ??\n (rawMessage.result !== undefined\n ? rawMessage.result\n : typeof rawMessage.content === \"string\"\n ? parseJSONText(rawMessage.content)\n : rawMessage.content);\n const isError =\n typeof rawMessage.error === \"string\" ||\n rawMessage.isError === true ||\n rawMessage.status === \"error\"\n ? true\n : rawMessage.isError === false\n ? false\n : undefined;\n const mcpAppUri = readMcpAppResourceUri(mcpResult?._meta);\n const mcpApp =\n mcpAppUri !== undefined ? { resourceUri: mcpAppUri } : undefined;\n\n let updated = false;\n for (\n let messageIndex = converted.length - 1;\n messageIndex >= 0 && !updated;\n messageIndex--\n ) {\n const message = converted[messageIndex];\n if (\n !message ||\n message.role !== \"assistant\" ||\n !Array.isArray(message.content)\n )\n continue;\n\n for (\n let partIndex = message.content.length - 1;\n partIndex >= 0;\n partIndex--\n ) {\n const part = message.content[partIndex];\n if (!isObject(part) || part.type !== \"tool-call\") continue;\n if (getString(part, \"toolCallId\") !== toolCallId) continue;\n\n const updatedPart: ToolCallPart = {\n ...(part as ToolCallPart),\n result,\n ...(mcpModelContent ? { modelContent: mcpModelContent } : {}),\n ...(isError !== undefined ? { isError } : {}),\n ...(toolMessageId !== undefined\n ? { unstable_toolMessageId: toolMessageId }\n : {}),\n ...(mcpApp ? { mcp: { app: mcpApp } } : {}),\n };\n const updatedContent = message.content.map((contentPart, index) =>\n index === partIndex ? updatedPart : contentPart,\n );\n converted[messageIndex] = { ...message, content: updatedContent };\n updated = true;\n break;\n }\n }\n\n if (updated) {\n continue;\n }\n\n const id = toolMessageId ?? toolCallId;\n const toolName =\n getString(rawMessage, \"name\") ??\n getString(rawMessage, \"toolName\") ??\n \"tool\";\n converted.push({\n id: `${id}:assistant`,\n role: \"assistant\",\n content: [\n {\n type: \"tool-call\",\n toolCallId,\n toolName,\n args: {},\n argsText: \"{}\",\n result,\n ...(mcpModelContent ? { modelContent: mcpModelContent } : {}),\n ...(isError !== undefined ? { isError } : {}),\n ...(toolMessageId !== undefined\n ? { unstable_toolMessageId: toolMessageId }\n : {}),\n ...(mcpApp ? { mcp: { app: mcpApp } } : {}),\n },\n ],\n });\n continue;\n }\n\n if (role === \"activity\") {\n // Only a2ui-surface activity messages have an assistant-part equivalent\n // to rehydrate; other activity types still have no surface to repaint.\n const activityType = getString(rawMessage, \"activityType\");\n if (activityType !== A2UI_SURFACE_ACTIVITY_TYPE) continue;\n const activityContent = isObject(rawMessage.content)\n ? (rawMessage.content as Record<string, unknown>)\n : null;\n const operations = activityContent?.[\"a2ui_operations\"];\n if (!Array.isArray(operations)) continue;\n\n let ownerIndex = -1;\n for (let i = converted.length - 1; i >= 0; i--) {\n const candidate = converted[i];\n if (candidate && candidate.role === \"assistant\") {\n ownerIndex = i;\n break;\n }\n }\n if (ownerIndex === -1) continue;\n\n const owner = converted[ownerIndex]!;\n const bucketKey = getString(rawMessage, \"id\") ?? \"a2ui:anonymous\";\n const { state } = applyA2uiOperations(new Map(), operations);\n a2uiBuckets.delete(bucketKey);\n a2uiBucketOwnerIndices.delete(bucketKey);\n a2uiBuckets.set(bucketKey, state);\n a2uiBucketOwnerIndices.set(bucketKey, ownerIndex);\n\n const ownerState = new Map<string, A2uiSurfaceState>();\n for (const [candidateBucketKey, candidateState] of a2uiBuckets) {\n if (a2uiBucketOwnerIndices.get(candidateBucketKey) !== ownerIndex)\n continue;\n for (const [surfaceId, surface] of candidateState) {\n ownerState.set(surfaceId, surface);\n }\n }\n converted[ownerIndex] = attachA2uiSurfaces(owner, ownerState);\n continue;\n }\n\n if (role === \"assistant\") {\n converted.push(toAssistantSnapshotMessage(rawMessage));\n continue;\n }\n\n if (role === \"reasoning\") {\n const text = extractText(rawMessage.content);\n const encryptedValue = getString(rawMessage, \"encryptedValue\");\n if (text.trim().length === 0) {\n // showThinking hides reasoning; this record is never rendered anyway,\n // and dropping it would deny the provider the payload it needs to\n // accept the next run.\n const opaqueId = getString(rawMessage, \"id\");\n if (opaqueId?.trim() && encryptedValue?.trim()) {\n opaqueReasoning.push({\n id: opaqueId,\n encryptedValue,\n anchor: converted.length,\n });\n }\n continue;\n }\n // Gate visible reasoning on showThinking so a cold reload matches the\n // live run: the aggregator never stores reasoning parts when it is off.\n // A signature on a hidden record is still transport state, so it is kept\n // opaque rather than discarded with the text.\n if (!showThinking) {\n const hiddenId = getString(rawMessage, \"id\");\n if (hiddenId?.trim() && encryptedValue?.trim()) {\n opaqueReasoning.push({\n id: hiddenId,\n encryptedValue,\n anchor: converted.length,\n });\n }\n continue;\n }\n converted.push({\n id: getString(rawMessage, \"id\") ?? generateId(),\n role: \"assistant\",\n content: [\n {\n type: \"reasoning\",\n text,\n ...(encryptedValue !== undefined\n ? {\n providerMetadata: {\n [AG_UI_METADATA_NAMESPACE]: { encryptedValue },\n },\n }\n : {}),\n },\n ],\n });\n continue;\n }\n\n if (role === \"user\" || role === \"system\" || role === \"developer\") {\n converted.push(toUserOrSystemSnapshotMessage(role, rawMessage));\n }\n }\n\n for (const { anchor, ...entry } of opaqueReasoning) {\n // Nothing followed it on the wire, so it trails the last message instead.\n const trailing = anchor >= converted.length;\n const index = trailing ? converted.length - 1 : anchor;\n const target = converted[index];\n if (!target) continue;\n converted[index] = withOpaqueReasoning(target, [\n ...readOpaqueReasoning(target.metadata),\n ...(trailing ? [{ ...entry, after: true }] : [entry]),\n ]);\n }\n\n for (let i = 0; i < converted.length; i++) {\n const message = converted[i]!;\n if (message.role !== \"assistant\") continue;\n\n const hasInterrupt =\n readPersistedInterrupts(message.metadata) !== undefined;\n const hasPendingToolCall =\n Array.isArray(message.content) &&\n message.content.some(\n (part) =>\n isObject(part) &&\n part.type === \"tool-call\" &&\n part.result === undefined,\n );\n\n if (hasInterrupt || hasPendingToolCall) {\n converted[i] = {\n ...message,\n status: getAutoStatus(\n false,\n false,\n hasInterrupt,\n hasPendingToolCall,\n undefined,\n ),\n };\n }\n }\n\n return converted;\n}\n\nfunction convertAssistantMessage(\n message: NormalizedThreadMessageLike,\n converted: AgUiMessage[],\n): void {\n const content = extractText(message.content);\n const contentArray = Array.isArray(message.content) ? message.content : [];\n\n const toolCallParts = contentArray.filter(\n (part): part is ToolCallPart =>\n part?.type === \"tool-call\" &&\n !(\n typeof part.toolCallId === \"string\" &&\n part.toolCallId.startsWith(\"a2ui:\")\n ),\n );\n\n const toolCalls = toolCallParts.map((part) => ({\n ...normalizeToolCall(part),\n part,\n }));\n\n // An AG-UI assistant record has no reasoning field, so reasoning leaves as\n // the standalone record it arrived as, ahead of the assistant it belongs to.\n const shellIsDropped = content.length === 0 && toolCalls.length === 0;\n let reasoningIndex = 0;\n for (const part of contentArray) {\n if (!isObject(part) || part.type !== \"reasoning\") continue;\n const text = getString(part, \"text\") ?? \"\";\n if (text.trim().length === 0) continue;\n const { encryptedValue, reasoningId } = readAgUiReasoningMeta(\n part.providerMetadata,\n );\n converted.push({\n // The wire id is what a signature was issued against, so it wins over a\n // synthesized one whenever the run carried it.\n id: reasoningId?.trim()\n ? reasoningId\n : shellIsDropped && reasoningIndex === 0\n ? message.id\n : `${message.id}:reasoning-${reasoningIndex}`,\n role: \"reasoning\",\n content: text,\n ...(encryptedValue !== undefined ? { encryptedValue } : {}),\n });\n reasoningIndex++;\n }\n\n // Drop assistant messages with no text or tool calls (e.g. an imported\n // reasoning-only entry) so they are not re-sent as a blank assistant turn.\n if (shellIsDropped) {\n return;\n }\n\n // A subagent's tool calls live on nested assistant messages. Before\n // subagent attribution they flattened to root and went out with this\n // assistant record as their antecedent, so the resume payload restores\n // exactly that shape: the calls join this record's toolCalls and their\n // results follow as tool records — never a tool record without its call.\n // The nested assistant content itself is backend-owned state and is not\n // re-sent.\n const nestedToolCalls: {\n id: string;\n call: AgUiToolCall;\n part: ToolCallPart;\n }[] = [];\n for (const { part } of toolCalls) {\n collectNestedToolCalls(part, nestedToolCalls);\n }\n\n converted.push({\n id: message.id,\n role: \"assistant\",\n content,\n ...(message.name ? { name: message.name } : {}),\n ...(toolCalls.length + nestedToolCalls.length > 0\n ? {\n toolCalls: [...toolCalls, ...nestedToolCalls].map(\n (entry) => entry.call,\n ),\n }\n : {}),\n });\n\n for (const { id: toolCallId, part } of toolCalls) {\n emitToolResult(toolCallId, part, converted);\n }\n for (const { id: toolCallId, part } of nestedToolCalls) {\n // A result recorded while the call's approval gate is still open must not\n // reach the backend as if the gate had been decided.\n const gateOpen =\n part.approval != null &&\n part.approval.approved === undefined &&\n part.approval.resolution === undefined;\n if (gateOpen) continue;\n emitToolResult(toolCallId, part, converted);\n }\n}\n\nfunction collectNestedToolCalls(\n part: ToolCallPart,\n out: { id: string; call: AgUiToolCall; part: ToolCallPart }[],\n): void {\n for (const nested of part.messages ?? []) {\n if (!isObject(nested) || nested.role !== \"assistant\") continue;\n const nestedContent = Array.isArray(nested.content) ? nested.content : [];\n for (const nestedPart of nestedContent) {\n if (!isObject(nestedPart) || nestedPart.type !== \"tool-call\") continue;\n const nestedToolCall = nestedPart as ToolCallPart;\n if (\n typeof nestedToolCall.toolCallId !== \"string\" ||\n nestedToolCall.toolCallId.startsWith(\"a2ui:\")\n ) {\n continue;\n }\n out.push({ ...normalizeToolCall(nestedToolCall), part: nestedToolCall });\n collectNestedToolCalls(nestedToolCall, out);\n }\n }\n}\n\nfunction emitToolResult(\n toolCallId: string,\n part: ToolCallPart,\n converted: AgUiMessage[],\n): void {\n if (part.result === undefined) return;\n\n const resultContent =\n part.modelContent !== undefined\n ? extractText(part.modelContent)\n : typeof part.result === \"string\"\n ? part.result\n : JSON.stringify(part.result);\n\n converted.push({\n id: part.unstable_toolMessageId ?? `${toolCallId}:tool`,\n role: \"tool\",\n content: resultContent,\n toolCallId,\n ...(part.isError ? { error: resultContent } : {}),\n });\n}\n\nfunction convertToolMessage(\n message: NormalizedThreadMessageLike,\n converted: AgUiMessage[],\n): void {\n const content = extractText(message.content);\n const toolCallId = message.toolCallId ?? generateId();\n\n converted.push({\n id: message.id,\n role: \"tool\",\n content,\n toolCallId,\n ...(typeof message.error === \"string\" ? { error: message.error } : {}),\n });\n}\n\nexport function toAgUiMessages(\n messages: readonly ThreadMessageLike[],\n): AgUiMessage[] {\n const converted: AgUiMessage[] = [];\n\n for (const rawMessage of messages) {\n const message: NormalizedThreadMessageLike = {\n ...rawMessage,\n id: rawMessage.id ?? generateId(),\n };\n const opaqueReasoning = readOpaqueReasoning(message.metadata);\n const toOpaqueRecord = (entry: AgUiOpaqueReasoning): AgUiMessage => ({\n id: entry.id,\n role: \"reasoning\",\n content: \"\",\n encryptedValue: entry.encryptedValue,\n });\n for (const entry of opaqueReasoning) {\n if (entry.after !== true) converted.push(toOpaqueRecord(entry));\n }\n const flushTrailingOpaqueReasoning = () => {\n for (const entry of opaqueReasoning) {\n if (entry.after === true) converted.push(toOpaqueRecord(entry));\n }\n };\n\n if (message.role === \"assistant\") {\n convertAssistantMessage(message, converted);\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n if (message.role === \"tool\") {\n convertToolMessage(message, converted);\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n if (message.role === \"user\") {\n converted.push({\n id: message.id,\n role: \"user\",\n content: buildUserContent(message),\n ...(message.name ? { name: message.name } : {}),\n });\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n if (message.role === \"system\" || message.role === \"developer\") {\n const custom = isObject(message.metadata)\n ? message.metadata.custom\n : undefined;\n const namespaced = isObject(custom)\n ? custom[AG_UI_METADATA_NAMESPACE]\n : undefined;\n const wireRole =\n message.role === \"system\" &&\n isObject(namespaced) &&\n namespaced.role === \"developer\"\n ? (\"developer\" as const)\n : message.role;\n converted.push({\n id: message.id,\n role: wireRole,\n content: extractText(message.content),\n ...(message.name ? { name: message.name } : {}),\n });\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n if (message.role === \"reasoning\") {\n converted.push({\n id: message.id,\n role: \"reasoning\",\n content: extractText(message.content),\n });\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n flushTrailingOpaqueReasoning();\n }\n\n return converted;\n}\n\ntype AgUiTool = NonNullable<RunAgentParameters[\"tools\"]>[number];\n\nexport function toAgUiTools(\n tools: Record<string, Tool> | undefined,\n): AgUiTool[] {\n if (!tools) return [];\n\n const toolsSchema = toToolsJSONSchema(tools);\n return Object.entries(toolsSchema).map(([name, tool]) => ({\n name,\n description: tool.description ?? \"\",\n parameters: tool.parameters,\n }));\n}\n"],"mappings":";;;;;;;;;AAwHA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU;AAEzC,MAAM,aAAa,QAAiC,QAAgB;CAClE,MAAM,QAAQ,OAAO;CACrB,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C;AAEA,MAAM,iBAAiB,WACrB,UAAU,QAAQ,YAAY,KAAK,UAAU,QAAQ,cAAc;AAErE,MAAM,qBAAqB,qBAA8B;CACvD,IAAI,CAAC,SAAS,gBAAgB,GAAG,OAAO,KAAA;CACxC,MAAM,aAAa,iBAAiB;CACpC,OAAO,SAAS,UAAU,IAAI,aAAa,KAAA;AAC7C;AAEA,MAAM,yBAAyB,qBAA8B;CAC3D,MAAM,aAAa,kBAAkB,gBAAgB;CACrD,IAAI,CAAC,YAAY,OAAO,CAAC;CACzB,OAAO;EACL,gBAAgB,UAAU,YAAY,gBAAgB;EACtD,aAAa,UAAU,YAAY,aAAa;CAClD;AACF;AAKA,MAAM,sBACJ,MACA,aACG;CACH,MAAM,WAAW;EACf,GAAG,kBAAkB,KAAK,gBAAgB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GACD,6BAA6B;GAC7B;EACF;EAEA,IAAI,QAAQ,SAAS,aAAa;GAChC,UAAU,KAAK;IACb,IAAI,QAAQ;IACZ,MAAM;IACN,SAAS,YAAY,QAAQ,OAAO;GACtC,CAAC;GACD,6BAA6B;GAC7B;EACF;EAEA,6BAA6B;CAC/B;CAEA,OAAO;AACT;AAIA,SAAgB,YACd,OACY;CACZ,IAAI,CAAC,OAAO,OAAO,CAAC;CAEpB,MAAM,cAAc,kBAAkB,KAAK;CAC3C,OAAO,OAAO,QAAQ,WAAW,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW;EACxD;EACA,aAAa,KAAK,eAAe;EACjC,YAAY,KAAK;CACnB,EAAE;AACJ"}
1
+ {"version":3,"file":"conversions.js","names":[],"sources":["../../../src/runtime/adapter/conversions.ts"],"sourcesContent":["\"use client\";\n\nimport type { InputContent, RunAgentParameters } from \"@ag-ui/client\";\nimport { generateId } from \"@assistant-ui/core\";\nimport type {\n ThreadMessageLike as CoreThreadMessageLike,\n PartProviderMetadata,\n ReasoningMessagePart,\n ThreadMessage,\n ToolCallMessagePartMcpMetadata,\n ToolModelContentPart,\n} from \"@assistant-ui/core\";\nimport {\n getAutoStatus,\n parseDataUrl,\n resolveFilePartSource,\n} from \"@assistant-ui/core/internal\";\nimport { type Tool, toToolsJSONSchema } from \"assistant-stream\";\nimport type { ReadonlyJSONObject } from \"assistant-stream/utils\";\nimport {\n AG_UI_METADATA_NAMESPACE,\n A2UI_SURFACE_ACTIVITY_TYPE,\n MCP_APPS_ACTIVITY_TYPE,\n type AgUiCustomMetadata,\n type AgUiOpaqueReasoning,\n} from \"./run-aggregator\";\nimport {\n applyA2uiOperations,\n convertSurfaceToUISpec,\n surfaceToOperations,\n type A2uiState,\n type A2uiSurfaceState,\n} from \"@assistant-ui/react-generative-ui/a2ui\";\nimport type { AgUiInterrupt } from \"../types\";\nimport { projectAgUiToolApprovals } from \"./tool-approval\";\nimport {\n parseMcpToolCallResult,\n readMcpAppResourceUri,\n} from \"../mcp-tool-result\";\n\nexport type { InputContent };\n\ntype AttachmentLike = {\n name?: string | undefined;\n contentType?: string | undefined;\n content?: readonly unknown[] | undefined;\n};\n\ntype ThreadMessageLike = {\n id?: string | undefined;\n role: string;\n content: unknown;\n metadata?: unknown;\n name?: string | undefined;\n toolCallId?: string | undefined;\n error?: string | undefined;\n attachments?: readonly AttachmentLike[] | undefined;\n};\n\ntype NormalizedThreadMessageLike = ThreadMessageLike & { id: string };\n\ntype AgUiToolCall = {\n id: string;\n type: \"function\";\n function: { name: string; arguments: string };\n};\n\nexport type AgUiMessage =\n | {\n id: string;\n role: \"user\";\n content: string | InputContent[];\n name?: string;\n }\n | {\n id: string;\n role: \"assistant\";\n content: string;\n name?: string;\n toolCalls?: AgUiToolCall[];\n }\n | {\n id: string;\n role: \"system\" | \"developer\";\n content: string;\n name?: string;\n }\n | {\n id: string;\n role: \"reasoning\";\n content: string;\n encryptedValue?: string;\n }\n | {\n id: string;\n role: \"tool\";\n content: string;\n toolCallId: string;\n error?: string;\n };\n\ntype ToolCallPart = {\n type: \"tool-call\";\n toolCallId?: string;\n toolName: string;\n argsText?: string;\n args?: ReadonlyJSONObject;\n result?: unknown;\n artifact?: unknown;\n isError?: boolean;\n modelContent?: readonly ToolModelContentPart[];\n unstable_toolMessageId?: string;\n mcp?: ToolCallMessagePartMcpMetadata;\n messages?: readonly ThreadMessage[];\n approval?: CoreToolCallPartApproval;\n};\n\ntype CoreToolCallPartApproval = NonNullable<\n Extract<\n Exclude<CoreThreadMessageLike[\"content\"], string>[number],\n { type: \"tool-call\" }\n >[\"approval\"]\n>;\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst getString = (record: Record<string, unknown>, key: string) => {\n const value = record[key];\n return typeof value === \"string\" ? value : undefined;\n};\n\nconst getToolCallId = (record: Record<string, unknown>) =>\n getString(record, \"toolCallId\") ?? getString(record, \"tool_call_id\");\n\nconst readAgUiNamespace = (providerMetadata: unknown) => {\n if (!isObject(providerMetadata)) return undefined;\n const namespaced = providerMetadata[AG_UI_METADATA_NAMESPACE];\n return isObject(namespaced) ? namespaced : undefined;\n};\n\nconst readAgUiReasoningMeta = (providerMetadata: unknown) => {\n const namespaced = readAgUiNamespace(providerMetadata);\n if (!namespaced) return {};\n return {\n encryptedValue: getString(namespaced, \"encryptedValue\"),\n reasoningId: getString(namespaced, \"reasoningId\"),\n };\n};\n\n// AG-UI carries per-item extras in `metadata`; anything else on the item is\n// stripped by its schema. The part's own `filename` wins over a key of the\n// same name in the bag.\nconst buildInputMetadata = (\n part: Record<string, unknown>,\n filename?: string | undefined,\n) => {\n const metadata = {\n ...readAgUiNamespace(part.providerMetadata),\n ...(filename !== undefined && { filename }),\n };\n return Object.keys(metadata).length > 0 ? metadata : undefined;\n};\n\n// The inverse: `filename` lands on the part's own field, everything else the\n// item carried goes back into the namespace it came from, so a snapshot echo\n// resends what the host attached.\nconst readInputMetadata = (\n metadata: unknown,\n): {\n filename?: string | undefined;\n providerMetadata?: PartProviderMetadata | undefined;\n} => {\n if (!isObject(metadata)) return {};\n const { filename: _filename, ...rest } = metadata;\n return {\n filename: getString(metadata, \"filename\"),\n ...(Object.keys(rest).length > 0 && {\n providerMetadata: {\n [AG_UI_METADATA_NAMESPACE]: rest as PartProviderMetadata[string],\n },\n }),\n };\n};\n\nfunction parseJSONText(value: string): unknown {\n if (!value) return value;\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n}\n\nfunction normalizeToolCall(part: ToolCallPart): {\n id: string;\n call: AgUiToolCall;\n} {\n const id = part.toolCallId ?? generateId();\n const argsText =\n typeof part.argsText === \"string\"\n ? part.argsText\n : JSON.stringify(part.args ?? {});\n\n return {\n id,\n call: {\n id,\n type: \"function\",\n function: {\n name: part.toolName ?? \"tool\",\n arguments: argsText,\n },\n },\n };\n}\n\nfunction extractText(content: unknown): string {\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n\n return content\n .filter(\n (part): part is { type: \"text\"; text: string } =>\n part?.type === \"text\" && typeof part?.text === \"string\",\n )\n .map((part) => part.text)\n .join(\"\\n\");\n}\n\ntype InputContentSource =\n | { type: \"data\"; value: string; mimeType: string }\n | { type: \"url\"; value: string; mimeType?: string };\n\ntype MediaInputType = \"image\" | \"audio\" | \"video\" | \"document\";\n\nfunction mediaTypeForMime(mimeType: string | undefined): MediaInputType {\n if (mimeType?.startsWith(\"image/\")) return \"image\";\n if (mimeType?.startsWith(\"audio/\")) return \"audio\";\n if (mimeType?.startsWith(\"video/\")) return \"video\";\n return \"document\";\n}\n\n// Build an AG-UI multimodal source from a data URL, raw base64 payload, or an\n// http(s) URL. A `url` source may omit the mime type; a `data` source always\n// resolves one (falling back to application/octet-stream). An explicit\n// `sourceType: \"url\"` on the part forces the url leg for non-http references,\n// and a data URL that is not base64 takes it too, since a `data` source\n// carries base64 bytes.\nfunction buildInputSource(\n value: string,\n declaredMimeType: string | undefined,\n sourceType?: string,\n): InputContentSource {\n const source = resolveFilePartSource({\n data: value,\n mimeType: declaredMimeType ?? \"application/octet-stream\",\n sourceType:\n /^data:/i.test(value) && !parseDataUrl(value) ? \"url\" : sourceType,\n });\n if (source.kind === \"url\") {\n return declaredMimeType !== undefined\n ? { type: \"url\", value: source.url, mimeType: declaredMimeType }\n : { type: \"url\", value: source.url };\n }\n return {\n type: \"data\",\n value: source.data,\n mimeType: source.mimeType,\n };\n}\n\nfunction toInputContent(\n part: unknown,\n fallbackMimeType: string | undefined,\n): InputContent | null {\n if (!isObject(part)) return null;\n const type = getString(part, \"type\");\n\n if (type === \"text\") {\n const text = getString(part, \"text\");\n if (text === undefined) return null;\n return { type: \"text\", text };\n }\n\n if (type === \"image\") {\n const image = getString(part, \"image\");\n if (image === undefined) return null;\n const metadata = buildInputMetadata(part, getString(part, \"filename\"));\n return {\n type: \"image\",\n source: buildInputSource(image, fallbackMimeType),\n ...(metadata && { metadata }),\n };\n }\n\n if (type === \"file\") {\n const data = getString(part, \"data\");\n if (data === undefined) return null;\n const declaredMimeType = getString(part, \"mimeType\") || fallbackMimeType;\n const filename = getString(part, \"filename\");\n const source = buildInputSource(\n data,\n declaredMimeType,\n getString(part, \"sourceType\"),\n );\n const metadata = buildInputMetadata(part, filename);\n switch (mediaTypeForMime(source.mimeType)) {\n case \"image\":\n return { type: \"image\", source, ...(metadata && { metadata }) };\n case \"audio\":\n return { type: \"audio\", source, ...(metadata && { metadata }) };\n case \"video\":\n return { type: \"video\", source, ...(metadata && { metadata }) };\n default:\n return { type: \"document\", source, ...(metadata && { metadata }) };\n }\n }\n\n if (type === \"audio\") {\n const audio = part.audio;\n if (!isObject(audio)) return null;\n const data = getString(audio, \"data\");\n const format = getString(audio, \"format\");\n if (data === undefined || format === undefined) return null;\n return {\n type: \"audio\",\n source: buildInputSource(\n parseDataUrl(data)?.data ?? data,\n `audio/${format}`,\n ),\n };\n }\n\n return null;\n}\n\ntype SnapshotAttachment = NonNullable<\n CoreThreadMessageLike[\"attachments\"]\n>[number];\n\nconst mediaInputTypes = new Set([\"image\", \"audio\", \"video\", \"document\"]);\n\n// Inverse of buildInputSource.\nfunction inputSourceToString(\n value: unknown,\n): { value: string; mimeType?: string; isUrl?: boolean } | null {\n if (!isObject(value)) return null;\n const sourceValue = getString(value, \"value\");\n if (sourceValue === undefined) return null;\n const mimeType = getString(value, \"mimeType\");\n const type = getString(value, \"type\");\n if (type === \"url\") {\n return {\n value: sourceValue,\n isUrl: true,\n ...(mimeType !== undefined && { mimeType }),\n };\n }\n if (type === \"data\") {\n const resolvedMimeType = mimeType ?? \"application/octet-stream\";\n return {\n value: `data:${resolvedMimeType};base64,${sourceValue}`,\n mimeType: resolvedMimeType,\n };\n }\n return null;\n}\n\n// Mirrors @ag-ui/client's BackwardCompatibility_0_0_47 middleware.\nfunction upgradeBinaryInputPart(\n part: Record<string, unknown>,\n): Record<string, unknown> | null {\n const mimeType = getString(part, \"mimeType\");\n if (mimeType === undefined) return null;\n const data = getString(part, \"data\");\n const url = getString(part, \"url\");\n const source = data\n ? { type: \"data\", value: data, mimeType }\n : url\n ? { type: \"url\", value: url, mimeType }\n : null;\n if (!source) return null;\n const filename = getString(part, \"filename\");\n return {\n type: mediaTypeForMime(mimeType),\n source,\n ...(filename && { metadata: { filename } }),\n };\n}\n\nfunction toSnapshotAttachments(content: unknown): SnapshotAttachment[] {\n if (!Array.isArray(content)) return [];\n\n const attachments: SnapshotAttachment[] = [];\n for (const rawPart of content) {\n if (!isObject(rawPart)) continue;\n const part =\n getString(rawPart, \"type\") === \"binary\"\n ? upgradeBinaryInputPart(rawPart)\n : rawPart;\n if (!part) continue;\n const type = getString(part, \"type\");\n if (type === undefined || !mediaInputTypes.has(type)) continue;\n const source = inputSourceToString(part.source);\n if (!source) continue;\n\n const { filename, providerMetadata } = readInputMetadata(part.metadata);\n const id = attachments.length.toString();\n\n if (type === \"image\") {\n attachments.push({\n id,\n type: \"image\",\n name: filename ?? \"image\",\n ...(source.mimeType !== undefined && { contentType: source.mimeType }),\n status: { type: \"complete\" },\n content: [\n {\n type: \"image\",\n image: source.value,\n ...(filename !== undefined && { filename }),\n ...(providerMetadata && { providerMetadata }),\n },\n ],\n });\n continue;\n }\n\n const mimeType = source.mimeType ?? \"application/octet-stream\";\n attachments.push({\n id,\n type: type === \"document\" ? \"document\" : \"file\",\n name: filename ?? \"file\",\n contentType: mimeType,\n status: { type: \"complete\" },\n content: [\n {\n type: \"file\",\n data: source.value,\n mimeType,\n ...(source.isUrl && { sourceType: \"url\" as const }),\n ...(filename !== undefined && { filename }),\n ...(providerMetadata && { providerMetadata }),\n },\n ],\n });\n }\n return attachments;\n}\n\nfunction buildUserContent(message: ThreadMessageLike): string | InputContent[] {\n const contentParts = Array.isArray(message.content) ? message.content : [];\n\n const attachments = message.attachments ?? [];\n\n const converted: InputContent[] = [];\n\n // Promote string-form content to a leading text part so it survives when\n // non-text attachments are present (fromAgUiMessages emits string content).\n if (typeof message.content === \"string\" && message.content.length > 0) {\n converted.push({ type: \"text\", text: message.content });\n }\n\n for (const part of contentParts) {\n const input = toInputContent(part, undefined);\n if (input) converted.push(input);\n }\n for (const attachment of attachments) {\n if (!isObject(attachment)) continue;\n const attachmentContent = attachment.content;\n if (!Array.isArray(attachmentContent)) continue;\n const fallbackMime = getString(attachment, \"contentType\");\n for (const part of attachmentContent) {\n const input = toInputContent(part, fallbackMime);\n if (input) converted.push(input);\n }\n }\n\n const hasNonText = converted.some((part) => part.type !== \"text\");\n if (hasNonText) return converted;\n\n // All-text path: collapse to plain string. Join text parts collected from\n // both content and attachments so attachment-sourced text is not dropped.\n if (converted.length === 0) return extractText(message.content);\n return converted\n .filter(\n (part): part is { type: \"text\"; text: string } => part.type === \"text\",\n )\n .map((part) => part.text)\n .join(\"\\n\");\n}\n\nfunction toToolCallPart(value: unknown): ToolCallPart | null {\n if (!isObject(value)) return null;\n const rawFunction = isObject(value.function) ? value.function : null;\n const toolCallId = getString(value, \"toolCallId\") ?? getString(value, \"id\");\n const toolName =\n getString(value, \"toolName\") ??\n getString(value, \"name\") ??\n (rawFunction ? getString(rawFunction, \"name\") : undefined) ??\n \"tool\";\n const argsText =\n getString(value, \"argsText\") ??\n getString(value, \"arguments\") ??\n (rawFunction ? getString(rawFunction, \"arguments\") : undefined);\n\n const parsedArgs =\n typeof argsText === \"string\" ? parseJSONText(argsText) : undefined;\n const args =\n isObject(parsedArgs) && !Array.isArray(parsedArgs)\n ? (parsedArgs as ReadonlyJSONObject)\n : isObject(value.args) && !Array.isArray(value.args)\n ? (value.args as ReadonlyJSONObject)\n : undefined;\n\n const part: ToolCallPart = {\n type: \"tool-call\",\n ...(toolCallId !== undefined ? { toolCallId } : {}),\n toolName,\n argsText: argsText ?? JSON.stringify(args ?? {}),\n ...(args !== undefined ? { args } : {}),\n };\n\n if (value.type === \"tool-call\") {\n const result = value.result;\n const isError = value.isError;\n if (result !== undefined) part.result = result;\n if (typeof isError === \"boolean\") part.isError = isError;\n }\n\n return part;\n}\n\nfunction extractAssistantToolCalls(\n message: Record<string, unknown>,\n): ToolCallPart[] {\n const parts: ToolCallPart[] = [];\n const seenToolCallIds = new Set<string>();\n const pushPart = (part: ToolCallPart | null) => {\n if (!part) return;\n const id = part.toolCallId ?? generateId();\n if (seenToolCallIds.has(id)) return;\n seenToolCallIds.add(id);\n parts.push({\n ...part,\n toolCallId: id,\n });\n };\n\n const content = message.content;\n if (Array.isArray(content)) {\n for (const part of content) {\n if (isObject(part) && part.type === \"tool-call\") {\n pushPart(toToolCallPart(part));\n }\n }\n }\n\n const toolCalls = Array.isArray(message.toolCalls)\n ? message.toolCalls\n : Array.isArray(message.tool_calls)\n ? message.tool_calls\n : [];\n for (const call of toolCalls) {\n pushPart(toToolCallPart(call));\n }\n\n return parts;\n}\n\nfunction validateInterrupts(value: unknown): AgUiInterrupt[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const valid = value.filter(\n (entry): entry is AgUiInterrupt =>\n isObject(entry) &&\n typeof entry.id === \"string\" &&\n typeof entry.reason === \"string\",\n );\n return valid.length > 0 ? valid : undefined;\n}\n\nfunction readPersistedInterrupts(\n metadata: unknown,\n): AgUiInterrupt[] | undefined {\n if (!isObject(metadata)) return undefined;\n const custom = metadata.custom;\n if (!isObject(custom)) return undefined;\n const namespaced = custom[AG_UI_METADATA_NAMESPACE];\n if (!isObject(namespaced)) return undefined;\n return validateInterrupts(namespaced.interrupts);\n}\n\nfunction readOpaqueReasoning(metadata: unknown): AgUiOpaqueReasoning[] {\n if (!isObject(metadata)) return [];\n const custom = metadata.custom;\n if (!isObject(custom)) return [];\n const namespaced = custom[AG_UI_METADATA_NAMESPACE];\n if (!isObject(namespaced)) return [];\n const entries = namespaced.opaqueReasoning;\n if (!Array.isArray(entries)) return [];\n return entries.flatMap((entry) => {\n if (!isObject(entry)) return [];\n const id = getString(entry, \"id\");\n const encryptedValue = getString(entry, \"encryptedValue\");\n if (!id?.trim() || !encryptedValue?.trim()) return [];\n return [\n { id, encryptedValue, ...(entry.after === true ? { after: true } : {}) },\n ];\n });\n}\n\nfunction withOpaqueReasoning(\n message: CoreThreadMessageLike,\n opaqueReasoning: AgUiOpaqueReasoning[],\n): CoreThreadMessageLike {\n const metadata = isObject(message.metadata) ? message.metadata : {};\n const custom = isObject(metadata.custom) ? metadata.custom : {};\n const namespaced = isObject(custom[AG_UI_METADATA_NAMESPACE])\n ? (custom[AG_UI_METADATA_NAMESPACE] as Record<string, unknown>)\n : {};\n return {\n ...message,\n metadata: {\n ...metadata,\n custom: {\n ...custom,\n [AG_UI_METADATA_NAMESPACE]: { ...namespaced, opaqueReasoning },\n },\n },\n } as CoreThreadMessageLike;\n}\n\nfunction toAssistantSnapshotMessage(\n rawMessage: Record<string, unknown>,\n): CoreThreadMessageLike {\n const text = extractText(rawMessage.content);\n const interrupts = readPersistedInterrupts(rawMessage.metadata);\n const restoredToolCalls = extractAssistantToolCalls(rawMessage);\n const approvals = projectAgUiToolApprovals(\n interrupts,\n new Set(\n restoredToolCalls\n .map((part) => part.toolCallId)\n .filter((id): id is string => !!id),\n ),\n );\n const toolCallParts = restoredToolCalls.map((part) => {\n const approval = part.toolCallId\n ? approvals.get(part.toolCallId)\n : undefined;\n return approval ? { ...part, approval } : part;\n });\n const assistantContent = [\n ...(text.length > 0 ? [{ type: \"text\" as const, text }] : []),\n ...toolCallParts,\n ];\n const messageName = getString(rawMessage, \"name\");\n return {\n id: getString(rawMessage, \"id\") ?? generateId(),\n role: \"assistant\",\n content: assistantContent.length > 0 ? assistantContent : \"\",\n ...(messageName !== undefined ? { name: messageName } : {}),\n ...(interrupts\n ? {\n metadata: {\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n interrupts,\n } satisfies AgUiCustomMetadata,\n },\n },\n }\n : {}),\n };\n}\n\nfunction toUserOrSystemSnapshotMessage(\n role: \"user\" | \"system\" | \"developer\",\n rawMessage: Record<string, unknown>,\n): CoreThreadMessageLike {\n const messageName = getString(rawMessage, \"name\");\n const attachments =\n role === \"user\" ? toSnapshotAttachments(rawMessage.content) : [];\n return {\n id: getString(rawMessage, \"id\") ?? generateId(),\n // The internal message model has no developer role; it rides as a system\n // message with its wire role kept in metadata so the export restores it.\n role: role === \"developer\" ? \"system\" : role,\n content: extractText(rawMessage.content),\n ...(messageName !== undefined ? { name: messageName } : {}),\n ...(attachments.length > 0 ? { attachments } : {}),\n ...(role === \"developer\"\n ? {\n metadata: {\n custom: {\n [AG_UI_METADATA_NAMESPACE]: {\n role: \"developer\",\n } satisfies AgUiCustomMetadata,\n },\n },\n }\n : {}),\n };\n}\n\n// Rebuilds the a2ui:<surfaceId> \"present\" tool-call parts for one owning\n// assistant message from a bucket of rebuilt surface state, mirroring the\n// live RunAggregator.synthesizeA2uiToolCalls shape. Non-a2ui parts (text,\n// other tool calls) are preserved; existing a2ui parts are replaced wholesale\n// so create/update/delete within the bucket all converge on the rebuilt set.\nfunction attachA2uiSurfaces(\n message: CoreThreadMessageLike,\n state: A2uiState,\n): CoreThreadMessageLike {\n const a2uiParts: ToolCallPart[] = [];\n for (const [surfaceId, surface] of state) {\n const { spec } = convertSurfaceToUISpec(surface);\n if (!spec) continue;\n a2uiParts.push({\n type: \"tool-call\",\n toolCallId: `a2ui:${surfaceId}`,\n toolName: \"present\",\n args: spec as unknown as ReadonlyJSONObject,\n argsText: JSON.stringify(spec),\n result: {},\n artifact: { a2ui: surfaceToOperations(surface) },\n });\n }\n\n const content = Array.isArray(message.content) ? message.content : [];\n const preserved = content.filter(\n (part) =>\n !(\n isObject(part) &&\n part.type === \"tool-call\" &&\n typeof part.toolCallId === \"string\" &&\n part.toolCallId.startsWith(\"a2ui:\")\n ),\n );\n return { ...message, content: [...preserved, ...a2uiParts] };\n}\n\n// A tool call that arrives without a `parentMessageId` has no record to join, so\n// the client opens one keyed by the call id. An assistant record whose own id is\n// a call it carries is that container: an id the client invented for the call\n// rather than a boundary an agent drew. The prose of the turn lands in records\n// of its own on either side of it, and nothing on the wire binds them to the\n// run that produced them.\nfunction isSyntheticToolCallContainer(message: CoreThreadMessageLike): boolean {\n if (message.role !== \"assistant\" || !Array.isArray(message.content))\n return false;\n let carriesOwnId = false;\n for (const part of message.content) {\n if (!isObject(part)) continue;\n // The container is opened empty, so text on the record means an agent\n // addressed it and the id is one it chose.\n if (part.type === \"text\") return false;\n if (\n part.type === \"tool-call\" &&\n getString(part, \"toolCallId\") === message.id\n ) {\n carriesOwnId = true;\n }\n }\n return carriesOwnId;\n}\n\nfunction carriesPart(message: CoreThreadMessageLike, type: string): boolean {\n return (\n Array.isArray(message.content) &&\n message.content.some((part) => isObject(part) && part.type === type)\n );\n}\n\nfunction carriesText(message: CoreThreadMessageLike): boolean {\n return carriesPart(message, \"text\");\n}\n\n// A container joins the assistant record ahead of it when that record holds\n// prose or calls of the turn. A released reasoning record holds neither: its\n// part leaves the export under the record's own id, so a message merged under\n// that id would put two records with one id on the wire.\nfunction opensTurn(message: CoreThreadMessageLike): boolean {\n return (\n message.role === \"assistant\" &&\n (carriesText(message) || carriesPart(message, \"tool-call\"))\n );\n}\n\n// The parts of the answer fold onto the container ahead of them. A record\n// carrying a tool call an agent addressed is a boundary of its own and keeps\n// its message.\nfunction answersToolCallContainer(message: CoreThreadMessageLike): boolean {\n if (message.role !== \"assistant\" || !Array.isArray(message.content))\n return false;\n if (message.content.length === 0) return false;\n return !message.content.some(\n (part) => isObject(part) && part.type === \"tool-call\",\n );\n}\n\nfunction readCustomMetadata(metadata: unknown): Record<string, unknown> {\n if (!isObject(metadata) || !isObject(metadata.custom)) return {};\n return metadata.custom;\n}\n\nfunction readNamespacedMetadata(metadata: unknown): Record<string, unknown> {\n const namespaced = readCustomMetadata(metadata)[AG_UI_METADATA_NAMESPACE];\n return isObject(namespaced) ? namespaced : {};\n}\n\nfunction foldTurnRecords(\n previous: CoreThreadMessageLike,\n message: CoreThreadMessageLike,\n): CoreThreadMessageLike {\n const interrupts = [\n ...(readPersistedInterrupts(previous.metadata) ?? []),\n ...(readPersistedInterrupts(message.metadata) ?? []),\n ];\n // An entry that rode a record behind the turn's calls sat ahead of content\n // that now follows them, so it is replayed after the merged record and its\n // tool results rather than ahead of a message that no longer starts there.\n // One that rode the container opening the turn sat ahead of every call and\n // stays ahead of the record.\n const trailsCalls = carriesPart(previous, \"tool-call\");\n const opaqueReasoning = [\n ...readOpaqueReasoning(previous.metadata),\n ...readOpaqueReasoning(message.metadata).map((entry) =>\n trailsCalls ? { ...entry, after: true } : entry,\n ),\n ];\n const namespaced = {\n ...readNamespacedMetadata(previous.metadata),\n ...readNamespacedMetadata(message.metadata),\n ...(interrupts.length > 0 ? { interrupts } : {}),\n ...(opaqueReasoning.length > 0 ? { opaqueReasoning } : {}),\n } satisfies AgUiCustomMetadata & Record<string, unknown>;\n const custom = {\n ...readCustomMetadata(previous.metadata),\n ...readCustomMetadata(message.metadata),\n ...(Object.keys(namespaced).length > 0\n ? { [AG_UI_METADATA_NAMESPACE]: namespaced }\n : {}),\n };\n const metadata = {\n ...(isObject(previous.metadata) ? previous.metadata : {}),\n ...(isObject(message.metadata) ? message.metadata : {}),\n ...(Object.keys(custom).length > 0 ? { custom } : {}),\n };\n return {\n ...previous,\n ...message,\n // A container's id names a call rather than the turn, so the record the\n // agent addressed its prose to wins: that is the id the next run has to\n // carry for the agent to recognize the message it wrote.\n id: carriesText(message) ? message.id : previous.id,\n content: [\n ...(Array.isArray(previous.content) ? previous.content : []),\n ...(Array.isArray(message.content) ? message.content : []),\n ],\n ...(Object.keys(metadata).length > 0 ? { metadata } : {}),\n } as CoreThreadMessageLike;\n}\n\nexport type FromAgUiMessagesOptions = {\n /**\n * Whether to convert `reasoning` messages into visible reasoning parts.\n * Matches the `showThinking` option of `useAgUiRuntime`. Defaults to `true`.\n */\n showThinking?: boolean;\n};\n\nexport function fromAgUiMessages(\n messages: readonly unknown[],\n options?: FromAgUiMessagesOptions,\n): CoreThreadMessageLike[] {\n const showThinking = options?.showThinking ?? true;\n const converted: CoreThreadMessageLike[] = [];\n const a2uiBuckets = new Map<string, A2uiState>();\n const a2uiBucketOwnerIndices = new Map<string, number>();\n const activityParts = new Map<\n string,\n { ownerIndex: number; part: { type: \"data\"; name: string; data: unknown } }\n >();\n // A zero-data-retention run carries its payload in encryptedValue with no\n // readable content, so the record has no part to become and rides on the\n // neighbouring message instead of being dropped. The anchor is the index the\n // next pushed message will occupy, which is where it sat on the wire.\n const opaqueReasoning: (AgUiOpaqueReasoning & { anchor: number })[] = [];\n // A reasoning record belongs to the assistant record that follows it, which is\n // the binding the export writes and the one the reference integrations read\n // back. Holding it until that assistant arrives rebuilds the pair as the\n // single message the live run produced.\n const pendingReasoning: {\n id: string | undefined;\n part: ReasoningMessagePart;\n }[] = [];\n\n const flushPendingReasoning = () => {\n for (const { id, part } of pendingReasoning) {\n converted.push({\n id: id ?? generateId(),\n role: \"assistant\",\n content: [part],\n });\n }\n pendingReasoning.length = 0;\n };\n\n const withPendingReasoning = (\n message: CoreThreadMessageLike,\n ): CoreThreadMessageLike => {\n if (pendingReasoning.length === 0) return message;\n const parts = pendingReasoning.map(({ part }) => part);\n pendingReasoning.length = 0;\n return {\n ...message,\n content: [\n ...parts,\n ...(Array.isArray(message.content) ? message.content : []),\n ],\n };\n };\n\n for (const rawMessage of messages) {\n if (!isObject(rawMessage)) continue;\n const role = getString(rawMessage, \"role\");\n if (!role) continue;\n\n if (role === \"tool\") {\n flushPendingReasoning();\n const toolCallId = getToolCallId(rawMessage) ?? `tool-${generateId()}`;\n const toolMessageId = getString(rawMessage, \"id\");\n const modelContent = extractText(rawMessage.content);\n const mcpResult = parseMcpToolCallResult(rawMessage, modelContent);\n const mcpModelContent = mcpResult\n ? [{ type: \"text\" as const, text: modelContent }]\n : undefined;\n const result =\n mcpResult ??\n (rawMessage.result !== undefined\n ? rawMessage.result\n : typeof rawMessage.content === \"string\"\n ? parseJSONText(rawMessage.content)\n : rawMessage.content);\n const isError =\n typeof rawMessage.error === \"string\" ||\n rawMessage.isError === true ||\n rawMessage.status === \"error\"\n ? true\n : rawMessage.isError === false\n ? false\n : undefined;\n const mcpAppUri = readMcpAppResourceUri(mcpResult?._meta);\n const mcpApp =\n mcpAppUri !== undefined ? { resourceUri: mcpAppUri } : undefined;\n\n let updated = false;\n for (\n let messageIndex = converted.length - 1;\n messageIndex >= 0 && !updated;\n messageIndex--\n ) {\n const message = converted[messageIndex];\n if (\n !message ||\n message.role !== \"assistant\" ||\n !Array.isArray(message.content)\n )\n continue;\n\n for (\n let partIndex = message.content.length - 1;\n partIndex >= 0;\n partIndex--\n ) {\n const part = message.content[partIndex];\n if (!isObject(part) || part.type !== \"tool-call\") continue;\n if (getString(part, \"toolCallId\") !== toolCallId) continue;\n\n const updatedPart: ToolCallPart = {\n ...(part as ToolCallPart),\n result,\n ...(mcpModelContent ? { modelContent: mcpModelContent } : {}),\n ...(isError !== undefined ? { isError } : {}),\n ...(toolMessageId !== undefined\n ? { unstable_toolMessageId: toolMessageId }\n : {}),\n ...(mcpApp ? { mcp: { app: mcpApp } } : {}),\n };\n const updatedContent = message.content.map((contentPart, index) =>\n index === partIndex ? updatedPart : contentPart,\n );\n converted[messageIndex] = { ...message, content: updatedContent };\n updated = true;\n break;\n }\n }\n\n if (updated) {\n continue;\n }\n\n const id = toolMessageId ?? toolCallId;\n const toolName =\n getString(rawMessage, \"name\") ??\n getString(rawMessage, \"toolName\") ??\n \"tool\";\n converted.push({\n id: `${id}:assistant`,\n role: \"assistant\",\n content: [\n {\n type: \"tool-call\",\n toolCallId,\n toolName,\n args: {},\n argsText: \"{}\",\n result,\n ...(mcpModelContent ? { modelContent: mcpModelContent } : {}),\n ...(isError !== undefined ? { isError } : {}),\n ...(toolMessageId !== undefined\n ? { unstable_toolMessageId: toolMessageId }\n : {}),\n ...(mcpApp ? { mcp: { app: mcpApp } } : {}),\n },\n ],\n });\n continue;\n }\n\n if (role === \"activity\") {\n const activityType = getString(rawMessage, \"activityType\");\n if (activityType === undefined || activityType === MCP_APPS_ACTIVITY_TYPE)\n continue;\n\n // A surface belongs to the turn that painted it, and held reasoning is a\n // nearer antecedent than the previous turn's assistant record, so it is\n // released here rather than folded past this record.\n flushPendingReasoning();\n\n let ownerIndex = -1;\n for (let i = converted.length - 1; i >= 0; i--) {\n const candidate = converted[i];\n if (candidate && candidate.role === \"assistant\") {\n ownerIndex = i;\n break;\n }\n }\n if (ownerIndex === -1) continue;\n\n const owner = converted[ownerIndex]!;\n if (activityType !== A2UI_SURFACE_ACTIVITY_TYPE) {\n const bucketKey =\n getString(rawMessage, \"id\") ?? `agui-activity:${activityType}`;\n const part = {\n type: \"data\" as const,\n name: `agui-activity/${activityType}`,\n data: rawMessage.content,\n };\n const existing = activityParts.get(bucketKey);\n const existingOwner = existing && converted[existing.ownerIndex];\n const existingIndex =\n existingOwner && Array.isArray(existingOwner.content)\n ? existingOwner.content.indexOf(existing.part)\n : -1;\n if (existing && existingOwner && existingIndex !== -1) {\n const content = [...(existingOwner.content as unknown[])];\n content[existingIndex] = part;\n converted[existing.ownerIndex] = {\n ...existingOwner,\n content: content as typeof existingOwner.content,\n };\n activityParts.set(bucketKey, {\n ownerIndex: existing.ownerIndex,\n part,\n });\n continue;\n }\n\n const content = Array.isArray(owner.content) ? owner.content : [];\n activityParts.set(bucketKey, { ownerIndex, part });\n converted[ownerIndex] = {\n ...owner,\n content: [...content, part],\n };\n continue;\n }\n\n const activityContent = isObject(rawMessage.content)\n ? (rawMessage.content as Record<string, unknown>)\n : null;\n const operations = activityContent?.[\"a2ui_operations\"];\n if (!Array.isArray(operations)) continue;\n const bucketKey = getString(rawMessage, \"id\") ?? \"a2ui:anonymous\";\n const { state } = applyA2uiOperations(new Map(), operations);\n a2uiBuckets.delete(bucketKey);\n a2uiBucketOwnerIndices.delete(bucketKey);\n a2uiBuckets.set(bucketKey, state);\n a2uiBucketOwnerIndices.set(bucketKey, ownerIndex);\n\n const ownerState = new Map<string, A2uiSurfaceState>();\n for (const [candidateBucketKey, candidateState] of a2uiBuckets) {\n if (a2uiBucketOwnerIndices.get(candidateBucketKey) !== ownerIndex)\n continue;\n for (const [surfaceId, surface] of candidateState) {\n ownerState.set(surfaceId, surface);\n }\n }\n converted[ownerIndex] = attachA2uiSurfaces(owner, ownerState);\n continue;\n }\n\n if (role === \"assistant\") {\n converted.push(\n withPendingReasoning(toAssistantSnapshotMessage(rawMessage)),\n );\n continue;\n }\n\n if (role === \"reasoning\") {\n const text = extractText(rawMessage.content);\n const encryptedValue = getString(rawMessage, \"encryptedValue\");\n if (text.trim().length === 0) {\n // showThinking hides reasoning; this record is never rendered anyway,\n // and dropping it would deny the provider the payload it needs to\n // accept the next run.\n const opaqueId = getString(rawMessage, \"id\");\n if (opaqueId?.trim() && encryptedValue?.trim()) {\n // The anchor counts materialized messages, so anything still held\n // takes its own slot rather than folding past this record.\n flushPendingReasoning();\n opaqueReasoning.push({\n id: opaqueId,\n encryptedValue,\n anchor: converted.length,\n });\n }\n continue;\n }\n // Gate visible reasoning on showThinking so a cold reload matches the\n // live run: the aggregator never stores reasoning parts when it is off.\n // A signature on a hidden record is still transport state, so it is kept\n // opaque rather than discarded with the text.\n if (!showThinking) {\n const hiddenId = getString(rawMessage, \"id\");\n if (hiddenId?.trim() && encryptedValue?.trim()) {\n opaqueReasoning.push({\n id: hiddenId,\n encryptedValue,\n anchor: converted.length,\n });\n }\n continue;\n }\n const rawReasoningId = getString(rawMessage, \"id\");\n // A blank id still wins over a synthesized one on export, which would put\n // an unaddressable record on the wire.\n const reasoningId = rawReasoningId?.trim() ? rawReasoningId : undefined;\n // The fold costs the record its own message id, so it rides the part\n // instead: the export re-emits each block under the id it arrived with.\n const meta = {\n ...(reasoningId !== undefined ? { reasoningId } : {}),\n ...(encryptedValue !== undefined ? { encryptedValue } : {}),\n };\n pendingReasoning.push({\n id: reasoningId,\n part: {\n type: \"reasoning\",\n text,\n ...(Object.keys(meta).length > 0\n ? { providerMetadata: { [AG_UI_METADATA_NAMESPACE]: meta } }\n : {}),\n },\n });\n continue;\n }\n\n if (role === \"user\" || role === \"system\" || role === \"developer\") {\n flushPendingReasoning();\n converted.push(toUserOrSystemSnapshotMessage(role, rawMessage));\n }\n }\n\n flushPendingReasoning();\n\n for (const { anchor, ...entry } of opaqueReasoning) {\n // Nothing followed it on the wire, so it trails the last message instead.\n const trailing = anchor >= converted.length;\n const index = trailing ? converted.length - 1 : anchor;\n const target = converted[index];\n if (!target) continue;\n converted[index] = withOpaqueReasoning(target, [\n ...readOpaqueReasoning(target.metadata),\n ...(trailing ? [{ ...entry, after: true }] : [entry]),\n ]);\n }\n\n // A turn that called a tool without addressing a record sits on the wire as\n // a container beside the records around it, which the live run renders as\n // one message: the container joins the assistant record ahead of it, and\n // what follows a container joins it until the turn carries text, where a\n // further text record opens a message of its own as it does live.\n const folded: CoreThreadMessageLike[] = [];\n for (const message of converted) {\n const previous = folded[folded.length - 1];\n if (\n previous !== undefined &&\n (isSyntheticToolCallContainer(message)\n ? opensTurn(previous)\n : isSyntheticToolCallContainer(previous) &&\n answersToolCallContainer(message))\n ) {\n folded[folded.length - 1] = foldTurnRecords(previous, message);\n continue;\n }\n folded.push(message);\n }\n\n for (let i = 0; i < folded.length; i++) {\n const message = folded[i]!;\n if (message.role !== \"assistant\") continue;\n\n const hasInterrupt =\n readPersistedInterrupts(message.metadata) !== undefined;\n const hasPendingToolCall =\n Array.isArray(message.content) &&\n message.content.some(\n (part) =>\n isObject(part) &&\n part.type === \"tool-call\" &&\n part.result === undefined,\n );\n\n if (hasInterrupt || hasPendingToolCall) {\n folded[i] = {\n ...message,\n status: getAutoStatus(\n false,\n false,\n hasInterrupt,\n hasPendingToolCall,\n undefined,\n ),\n };\n }\n }\n\n return folded;\n}\n\nfunction convertAssistantMessage(\n message: NormalizedThreadMessageLike,\n converted: AgUiMessage[],\n): void {\n const content = extractText(message.content);\n const contentArray = Array.isArray(message.content) ? message.content : [];\n\n const toolCallParts = contentArray.filter(\n (part): part is ToolCallPart =>\n part?.type === \"tool-call\" &&\n !(\n typeof part.toolCallId === \"string\" &&\n part.toolCallId.startsWith(\"a2ui:\")\n ),\n );\n\n const toolCalls = toolCallParts.map((part) => ({\n ...normalizeToolCall(part),\n part,\n }));\n\n // An AG-UI assistant record has no reasoning field, so reasoning leaves as\n // the standalone record it arrived as, ahead of the assistant it belongs to.\n const shellIsDropped = content.length === 0 && toolCalls.length === 0;\n let reasoningIndex = 0;\n for (const part of contentArray) {\n if (!isObject(part) || part.type !== \"reasoning\") continue;\n const text = getString(part, \"text\") ?? \"\";\n if (text.trim().length === 0) continue;\n const { encryptedValue, reasoningId } = readAgUiReasoningMeta(\n part.providerMetadata,\n );\n converted.push({\n // The wire id is what a signature was issued against, so it wins over a\n // synthesized one whenever the run carried it.\n id: reasoningId?.trim()\n ? reasoningId\n : shellIsDropped && reasoningIndex === 0\n ? message.id\n : `${message.id}:reasoning-${reasoningIndex}`,\n role: \"reasoning\",\n content: text,\n ...(encryptedValue !== undefined ? { encryptedValue } : {}),\n });\n reasoningIndex++;\n }\n\n // Drop assistant messages with no text or tool calls (e.g. an imported\n // reasoning-only entry) so they are not re-sent as a blank assistant turn.\n if (shellIsDropped) {\n return;\n }\n\n // A subagent's tool calls live on nested assistant messages. Before\n // subagent attribution they flattened to root and went out with this\n // assistant record as their antecedent, so the resume payload restores\n // exactly that shape: the calls join this record's toolCalls and their\n // results follow as tool records — never a tool record without its call.\n // The nested assistant content itself is backend-owned state and is not\n // re-sent.\n const nestedToolCalls: {\n id: string;\n call: AgUiToolCall;\n part: ToolCallPart;\n }[] = [];\n for (const { part } of toolCalls) {\n collectNestedToolCalls(part, nestedToolCalls);\n }\n\n converted.push({\n id: message.id,\n role: \"assistant\",\n content,\n ...(message.name ? { name: message.name } : {}),\n ...(toolCalls.length + nestedToolCalls.length > 0\n ? {\n toolCalls: [...toolCalls, ...nestedToolCalls].map(\n (entry) => entry.call,\n ),\n }\n : {}),\n });\n\n for (const { id: toolCallId, part } of toolCalls) {\n emitToolResult(toolCallId, part, converted);\n }\n for (const { id: toolCallId, part } of nestedToolCalls) {\n // A result recorded while the call's approval gate is still open must not\n // reach the backend as if the gate had been decided.\n const gateOpen =\n part.approval != null &&\n part.approval.approved === undefined &&\n part.approval.resolution === undefined;\n if (gateOpen) continue;\n emitToolResult(toolCallId, part, converted);\n }\n}\n\nfunction collectNestedToolCalls(\n part: ToolCallPart,\n out: { id: string; call: AgUiToolCall; part: ToolCallPart }[],\n): void {\n for (const nested of part.messages ?? []) {\n if (!isObject(nested) || nested.role !== \"assistant\") continue;\n const nestedContent = Array.isArray(nested.content) ? nested.content : [];\n for (const nestedPart of nestedContent) {\n if (!isObject(nestedPart) || nestedPart.type !== \"tool-call\") continue;\n const nestedToolCall = nestedPart as ToolCallPart;\n if (\n typeof nestedToolCall.toolCallId !== \"string\" ||\n nestedToolCall.toolCallId.startsWith(\"a2ui:\")\n ) {\n continue;\n }\n out.push({ ...normalizeToolCall(nestedToolCall), part: nestedToolCall });\n collectNestedToolCalls(nestedToolCall, out);\n }\n }\n}\n\nfunction emitToolResult(\n toolCallId: string,\n part: ToolCallPart,\n converted: AgUiMessage[],\n): void {\n if (part.result === undefined) return;\n\n const resultContent =\n part.modelContent !== undefined\n ? extractText(part.modelContent)\n : typeof part.result === \"string\"\n ? part.result\n : JSON.stringify(part.result);\n\n converted.push({\n id: part.unstable_toolMessageId ?? `${toolCallId}:tool`,\n role: \"tool\",\n content: resultContent,\n toolCallId,\n ...(part.isError ? { error: resultContent } : {}),\n });\n}\n\nfunction convertToolMessage(\n message: NormalizedThreadMessageLike,\n converted: AgUiMessage[],\n): void {\n const content = extractText(message.content);\n const toolCallId = message.toolCallId ?? generateId();\n\n converted.push({\n id: message.id,\n role: \"tool\",\n content,\n toolCallId,\n ...(typeof message.error === \"string\" ? { error: message.error } : {}),\n });\n}\n\nexport function toAgUiMessages(\n messages: readonly ThreadMessageLike[],\n): AgUiMessage[] {\n const converted: AgUiMessage[] = [];\n\n for (const rawMessage of messages) {\n const message: NormalizedThreadMessageLike = {\n ...rawMessage,\n id: rawMessage.id ?? generateId(),\n };\n const opaqueReasoning = readOpaqueReasoning(message.metadata);\n const toOpaqueRecord = (entry: AgUiOpaqueReasoning): AgUiMessage => ({\n id: entry.id,\n role: \"reasoning\",\n content: \"\",\n encryptedValue: entry.encryptedValue,\n });\n for (const entry of opaqueReasoning) {\n if (entry.after !== true) converted.push(toOpaqueRecord(entry));\n }\n const flushTrailingOpaqueReasoning = () => {\n for (const entry of opaqueReasoning) {\n if (entry.after === true) converted.push(toOpaqueRecord(entry));\n }\n };\n\n if (message.role === \"assistant\") {\n convertAssistantMessage(message, converted);\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n if (message.role === \"tool\") {\n convertToolMessage(message, converted);\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n if (message.role === \"user\") {\n converted.push({\n id: message.id,\n role: \"user\",\n content: buildUserContent(message),\n ...(message.name ? { name: message.name } : {}),\n });\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n if (message.role === \"system\" || message.role === \"developer\") {\n const custom = isObject(message.metadata)\n ? message.metadata.custom\n : undefined;\n const namespaced = isObject(custom)\n ? custom[AG_UI_METADATA_NAMESPACE]\n : undefined;\n const wireRole =\n message.role === \"system\" &&\n isObject(namespaced) &&\n namespaced.role === \"developer\"\n ? (\"developer\" as const)\n : message.role;\n converted.push({\n id: message.id,\n role: wireRole,\n content: extractText(message.content),\n ...(message.name ? { name: message.name } : {}),\n });\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n if (message.role === \"reasoning\") {\n converted.push({\n id: message.id,\n role: \"reasoning\",\n content: extractText(message.content),\n });\n flushTrailingOpaqueReasoning();\n continue;\n }\n\n flushTrailingOpaqueReasoning();\n }\n\n return converted;\n}\n\ntype AgUiTool = NonNullable<RunAgentParameters[\"tools\"]>[number];\n\nexport function toAgUiTools(\n tools: Record<string, Tool> | undefined,\n): AgUiTool[] {\n if (!tools) return [];\n\n const toolsSchema = toToolsJSONSchema(tools);\n return Object.entries(toolsSchema).map(([name, tool]) => ({\n name,\n description: tool.description ?? \"\",\n parameters: tool.parameters,\n }));\n}\n"],"mappings":";;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SAAS,YAAY,QAAQ,OAAO;IACpC,GAAI,QAAQ,OAAO,EAAE,MAAM,QAAQ,KAAK,IAAI,CAAC;GAC/C,CAAC;GACD,6BAA6B;GAC7B;EACF;EAEA,IAAI,QAAQ,SAAS,aAAa;GAChC,UAAU,KAAK;IACb,IAAI,QAAQ;IACZ,MAAM;IACN,SAAS,YAAY,QAAQ,OAAO;GACtC,CAAC;GACD,6BAA6B;GAC7B;EACF;EAEA,6BAA6B;CAC/B;CAEA,OAAO;AACT;AAIA,SAAgB,YACd,OACY;CACZ,IAAI,CAAC,OAAO,OAAO,CAAC;CAEpB,MAAM,cAAc,kBAAkB,KAAK;CAC3C,OAAO,OAAO,QAAQ,WAAW,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW;EACxD;EACA,aAAa,KAAK,eAAe;EACjC,YAAY,KAAK;CACnB,EAAE;AACJ"}
@@ -1,30 +1,29 @@
1
- import { Logger } from "../logger.js";
2
- import { AgUiEvent, AgUiInterrupt } from "../types.js";
3
- import { ChatModelRunResult } from "@assistant-ui/core";
4
- //#region src/runtime/adapter/run-aggregator.d.ts
5
- declare const AG_UI_METADATA_NAMESPACE = "agui";
6
- type AgUiOpaqueReasoning = {
7
- id: string;
8
- encryptedValue: string;
9
- after?: boolean;
1
+ import { type ChatModelRunResult } from "@assistant-ui/core";
2
+ import type { AgUiEvent, AgUiInterrupt } from "../types.js";
3
+ import type { Logger } from "../logger.js";
4
+ export declare const AG_UI_METADATA_NAMESPACE = "agui";
5
+ export type AgUiOpaqueReasoning = {
6
+ id: string;
7
+ encryptedValue: string;
8
+ after?: boolean;
10
9
  };
11
- type AgUiCustomMetadata = {
12
- /** Wire role restored on export for messages the internal model cannot
13
- * represent (a developer record rides as a system message). */
14
- role?: "developer";
15
- interrupts?: AgUiInterrupt[];
16
- opaqueReasoning?: AgUiOpaqueReasoning[];
10
+ export type AgUiCustomMetadata = {
11
+ /** Wire role restored on export for messages the internal model cannot
12
+ * represent (a developer record rides as a system message). */
13
+ role?: "developer";
14
+ interrupts?: AgUiInterrupt[];
15
+ opaqueReasoning?: AgUiOpaqueReasoning[];
17
16
  };
18
17
  type Emit = (update: ChatModelRunResult) => void;
19
- declare const MCP_APPS_ACTIVITY_TYPE = "mcp-apps";
20
- declare const A2UI_SURFACE_ACTIVITY_TYPE = "a2ui-surface";
21
- declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
22
- type RunAggregatorOptions = {
23
- showThinking: boolean;
24
- logger: Logger;
25
- emit: Emit;
26
- onServerMessageId?: (messageId: string) => void;
27
- onTextMessageStart?: (messageId: string) => void;
18
+ export declare const MCP_APPS_ACTIVITY_TYPE = "mcp-apps";
19
+ export declare const A2UI_SURFACE_ACTIVITY_TYPE = "a2ui-surface";
20
+ export declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
21
+ export type RunAggregatorOptions = {
22
+ showThinking: boolean;
23
+ logger: Logger;
24
+ emit: Emit;
25
+ onServerMessageId?: (messageId: string) => void;
26
+ onTextMessageStart?: (messageId: string) => void;
28
27
  };
29
28
  /**
30
29
  * Collects AG-UI events into assistant-ui run snapshots that can be yielded from a ChatModelAdapter.
@@ -36,79 +35,80 @@ type RunAggregatorOptions = {
36
35
  * `system:*`, and `MultiAgentHandoff` are forwarded the same way, so apps only
37
36
  * need data renderers for names they own.
38
37
  */
39
- declare class RunAggregator {
40
- private readonly emitUpdate;
41
- private readonly showThinking;
42
- private readonly logger;
43
- private readonly onServerMessageId;
44
- private readonly onTextMessageStart;
45
- private status;
46
- private interrupts;
47
- private readonly textParts;
48
- private readonly activeTextMessageIdByScope;
49
- private readonly reasoningParts;
50
- private readonly reasoningSignatures;
51
- private readonly reasoningSignatureIds;
52
- private readonly hiddenSignatures;
53
- private readonly hiddenSignatureAnchors;
54
- private readonly hiddenBlockAnchors;
55
- private hiddenAnonymousAnchor;
56
- private readonly hiddenReasoningIds;
57
- private hiddenActiveReasoning;
58
- private hasEmittedOpaqueReasoning;
59
- private readonly loggedDroppedOpaqueIds;
60
- private readonly reasoningMessageIds;
61
- private readonly anonymousReasoningKeys;
62
- private readonly activeReasoningKeyByScope;
63
- private readonly subagentRuns;
64
- private nestingMemo;
65
- private reasoningPartCounter;
66
- private readonly toolCalls;
67
- private readonly a2uiBuckets;
68
- private readonly a2uiToolCallIds;
69
- private readonly lastResolvedToolCallIdByScope;
70
- private readonly partOrder;
71
- private textPartCounter;
72
- private serverMessageIdReported;
73
- private reportedServerMessageId;
74
- private lastTextMessageId;
75
- private streamStartTime;
76
- private firstTokenTime;
77
- private totalChunks;
78
- constructor(options: RunAggregatorOptions);
79
- hasToolCall(toolCallId: string): boolean;
80
- handle(event: AgUiEvent): void;
81
- private handleA2uiActivitySnapshot;
82
- private synthesizeA2uiToolCalls;
83
- private reportServerMessageId;
84
- private clearTextParts;
85
- private resetMessageParts;
86
- private closeOpenSubagentRuns;
87
- private scopeOf;
88
- private partKey;
89
- private beginDistinctTextMessage;
90
- private generateTextKey;
91
- private startTextMessage;
92
- private resolveTextMessageId;
93
- private ensureTextPart;
94
- private appendText;
95
- private startToolCall;
96
- private insertToolPart;
97
- private appendToolArgs;
98
- private finishToolCall;
99
- private nesting;
100
- private subagentsByParentToolCallId;
101
- private reachableSubagentRunIds;
102
- private materializeSubagentMessage;
103
- private buildParts;
104
- private emit;
105
- private recordFirstToken;
106
- private getTiming;
107
- private handleReasoningStart;
108
- private handleReasoningContent;
109
- private handleReasoningEnd;
38
+ export declare class RunAggregator {
39
+ private readonly emitUpdate;
40
+ private readonly showThinking;
41
+ private readonly logger;
42
+ private readonly onServerMessageId;
43
+ private readonly onTextMessageStart;
44
+ private status;
45
+ private interrupts;
46
+ private readonly textParts;
47
+ private readonly activeTextMessageIdByScope;
48
+ private readonly reasoningParts;
49
+ private readonly reasoningSignatures;
50
+ private readonly reasoningSignatureIds;
51
+ private readonly hiddenSignatures;
52
+ private readonly hiddenSignatureAnchors;
53
+ private readonly hiddenBlockAnchors;
54
+ private hiddenAnonymousAnchor;
55
+ private readonly hiddenReasoningIds;
56
+ private hiddenActiveReasoning;
57
+ private hasEmittedOpaqueReasoning;
58
+ private readonly loggedDroppedOpaqueIds;
59
+ private readonly reasoningMessageIds;
60
+ private readonly anonymousReasoningKeys;
61
+ private readonly activeReasoningKeyByScope;
62
+ private readonly subagentRuns;
63
+ private nestingMemo;
64
+ private reasoningPartCounter;
65
+ private readonly toolCalls;
66
+ private readonly a2uiBuckets;
67
+ private readonly a2uiToolCallIds;
68
+ private readonly activityParts;
69
+ private readonly lastResolvedToolCallIdByScope;
70
+ private readonly partOrder;
71
+ private textPartCounter;
72
+ private serverMessageIdReported;
73
+ private reportedServerMessageId;
74
+ private lastTextMessageId;
75
+ private streamStartTime;
76
+ private firstTokenTime;
77
+ private totalChunks;
78
+ constructor(options: RunAggregatorOptions);
79
+ hasToolCall(toolCallId: string): boolean;
80
+ handle(event: AgUiEvent): void;
81
+ private handleA2uiActivitySnapshot;
82
+ private handleActivitySnapshot;
83
+ private synthesizeA2uiToolCalls;
84
+ private reportServerMessageId;
85
+ private clearTextParts;
86
+ private resetMessageParts;
87
+ private closeOpenSubagentRuns;
88
+ private scopeOf;
89
+ private partKey;
90
+ private beginDistinctTextMessage;
91
+ private generateTextKey;
92
+ private startTextMessage;
93
+ private resolveTextMessageId;
94
+ private ensureTextPart;
95
+ private appendText;
96
+ private startToolCall;
97
+ private insertToolPart;
98
+ private appendToolArgs;
99
+ private finishToolCall;
100
+ private nesting;
101
+ private subagentsByParentToolCallId;
102
+ private reachableSubagentRunIds;
103
+ private materializeSubagentMessage;
104
+ private buildParts;
105
+ private emit;
106
+ private recordFirstToken;
107
+ private getTiming;
108
+ private handleReasoningStart;
109
+ private handleReasoningContent;
110
+ private handleReasoningEnd;
110
111
  }
111
- declare function tryParseJSON(value: string): unknown;
112
- //#endregion
113
- export { A2UI_SURFACE_ACTIVITY_TYPE, AG_UI_METADATA_NAMESPACE, AgUiCustomMetadata, AgUiOpaqueReasoning, MCP_APPS_ACTIVITY_TYPE, RunAggregator, RunAggregatorOptions, isPlainObject, tryParseJSON };
112
+ export declare function tryParseJSON(value: string): unknown;
113
+ export {};
114
114
  //# sourceMappingURL=run-aggregator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run-aggregator.d.ts","names":[],"sources":["../../../src/runtime/adapter/run-aggregator.ts"],"mappings":";;;;cAuBa;KA8CD;EACV;EACA;EACA;;KAGU;;;EAGV;EACA,aAAa;EACb,kBAAkB;;KAGf,QAAQ,QAAQ;cA6FR;cAEA;cAEA,gBACX,mBACC,SAAS;KAGA;EACV;EACA,QAAQ;EACR,MAAM;EACN,qBAAqB;EACrB,sBAAsB;;;;;;;;;;;;cAaX;mBACM;mBACA;mBACA;mBACA;mBACA;UAIT;UACA;mBACS;mBACA;mBACA;mBACA;mBACA;mBAKA;mBACA;mBACA;UACT;mBACS;UACT;UACA;mBACS;mBACA;mBACA;mBACA;mBACA;UAIT;UAMA;mBACS;mBACA;mBACA;mBACA;mBACA;UACT;UACA;UACA;UACA;UAEA;UACA;UACA;EAEI,YAAA,SAAS;EAQrB,YAAY;EAIZ,OAAO,OAAO;UAoWN;UAmBA;UAiDA;UAWA;UAIA;UA8BA;UAMA;UAOA;UAIA;UAaA;UAKA;UAOA;UAiBA;UAiBA;UAMA;UAwCA;UA4BA;UA0BA;UAyDA;UAcA;UAgBA;UAwBA;UAyCA;UA4HA;UAmHA;UASA;UAgCA;UA+CA;UA0BA;;iBAUM,aAAa"}
1
+ {"version":3,"file":"run-aggregator.d.ts","sourceRoot":"","sources":["../../../src/runtime/adapter/run-aggregator.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,kBAAkB,EAOxB,MAAM,oBAAoB,CAAC;AAU5B,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,oBAAiB;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,qBAAkB;AAExC,eAAO,MAAM,wBAAwB,SAAS,CAAC;AA8C/C,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE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