@agent-native/core 0.24.7 → 0.24.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/engine/anthropic-engine.d.ts.map +1 -1
- package/dist/agent/engine/anthropic-engine.js +7 -2
- package/dist/agent/engine/anthropic-engine.js.map +1 -1
- package/dist/agent/engine/translate-anthropic.d.ts +23 -1
- package/dist/agent/engine/translate-anthropic.d.ts.map +1 -1
- package/dist/agent/engine/translate-anthropic.js +43 -5
- package/dist/agent/engine/translate-anthropic.js.map +1 -1
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +28 -3
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-manager.d.ts +38 -6
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js +81 -12
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/agent/run-store.d.ts +33 -5
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +105 -13
- package/dist/agent/run-store.js.map +1 -1
- package/dist/agent/thread-data-builder.d.ts +27 -0
- package/dist/agent/thread-data-builder.d.ts.map +1 -1
- package/dist/agent/thread-data-builder.js +178 -8
- package/dist/agent/thread-data-builder.js.map +1 -1
- package/dist/agent/types.d.ts +8 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/client/PoweredByBadge.d.ts +1 -1
- package/dist/client/PoweredByBadge.js +2 -2
- package/dist/client/PoweredByBadge.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +20 -0
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/api-path.d.ts.map +1 -1
- package/dist/client/api-path.js +37 -2
- package/dist/client/api-path.js.map +1 -1
- package/dist/client/composer/TiptapComposer.d.ts +2 -0
- package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
- package/dist/client/composer/TiptapComposer.js +13 -1
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/deploy/build.d.ts.map +1 -1
- package/dist/deploy/build.js +31 -9
- package/dist/deploy/build.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +13 -3
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/ssr-handler.d.ts.map +1 -1
- package/dist/server/ssr-handler.js +24 -8
- package/dist/server/ssr-handler.js.map +1 -1
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/social-meta.d.ts +13 -0
- package/dist/shared/social-meta.d.ts.map +1 -0
- package/dist/shared/social-meta.js +26 -0
- package/dist/shared/social-meta.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-data-builder.js","sourceRoot":"","sources":["../../src/agent/thread-data-builder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,4BAA4B,GAK7B,MAAM,yCAAyC,CAAC;AAmBjD,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAE3C,SAAS,2BAA2B,CAAC,KAIpC;IACC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACzD,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;IACtC,IAAI,IAAI,KAAK,uBAAuB;QAAE,OAAO,KAAK,CAAC;IACnD,OAAO,CACL,KAAK,CAAC,WAAW,KAAK,IAAI;QAC1B,IAAI,KAAK,yBAAyB;QAClC,IAAI,KAAK,WAAW;QACpB,IAAI,KAAK,SAAS;QAClB,IAAI,KAAK,eAAe;QACxB,IAAI,KAAK,UAAU;QACnB,IAAI,KAAK,UAAU;QACnB,IAAI,KAAK,UAAU;QACnB,IAAI,KAAK,UAAU;QACnB,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AI,IAAI,EAAE,CAAC;QACzB,6FAA6F;QAC7F,MAAM,GAAG,GAAG,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC;QACpC,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM;YAAE,SAAS;QAClC,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;YAC1C,CAAC,CAAC,GAAG,CAAC,OAAO;iBACR,MAAM,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;iBACrC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;iBACvB,IAAI,CAAC,GAAG,CAAC;YACd,CAAC,CAAC,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ;gBAC/B,CAAC,CAAC,GAAG,CAAC,OAAO;gBACb,CAAC,CAAC,EAAE,CAAC;QACT,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;YACrB,IAAI,CAAC,KAAK;gBAAE,KAAK,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAClD,OAAO,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,aAAa,IAAI,KAAK,EAAE,OAAO,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type { AgentChatAttachment, RunEvent } from \"./types.js\";\nimport {\n normalizeCodeAgentTranscript,\n type CodeAgentTranscriptEvent as CoreCodeAgentTranscriptEvent,\n type NormalizedCodeAgentStatusEvent,\n type NormalizedCodeAgentToolEvent,\n type NormalizedCodeAgentTranscriptItem,\n} from \"../code-agents/transcript-normalizer.js\";\n\ninterface ContentPart {\n type: string;\n text?: string;\n toolCallId?: string;\n toolName?: string;\n argsText?: string;\n args?: Record<string, string>;\n result?: string;\n}\n\ninterface BuildAssistantMessageOptions {\n suppressInternalContinuation?: boolean;\n}\n\ntype AssistantMessage = NonNullable<ReturnType<typeof buildAssistantMessage>>;\ntype UserMessage = ReturnType<typeof buildUserMessage>;\n\nconst MAX_STORED_ATTACHMENT_CHARS = 60_000;\n\nfunction isInternalContinuationError(event: {\n error: string;\n errorCode?: string;\n recoverable?: boolean;\n}): boolean {\n const code = String(event.errorCode ?? \"\").toLowerCase();\n const msg = event.error.toLowerCase();\n if (code === \"builder_gateway_error\") return false;\n return (\n event.recoverable === true ||\n code === \"builder_gateway_timeout\" ||\n code === \"stale_run\" ||\n code === \"timeout\" ||\n code === \"timeout_error\" ||\n code === \"http_408\" ||\n code === \"http_429\" ||\n code === \"http_500\" ||\n code === \"http_502\" ||\n code === \"http_503\" ||\n code === \"http_504\" ||\n code === \"rate_limited\" ||\n code === \"too_many_concurrent_requests\" ||\n code === \"overloaded_error\" ||\n msg.includes(\"timeout\") ||\n msg.includes(\"gateway timeout\") ||\n msg.includes(\"inactivity timeout\") ||\n msg.includes(\"stream ended\") ||\n msg.includes(\"stream closed\") ||\n msg.includes(\"temporarily unavailable\") ||\n msg.includes(\"502\") ||\n msg.includes(\"503\") ||\n msg.includes(\"504\") ||\n msg.includes(\"529\")\n );\n}\n\n/**\n * Reconstruct an assistant-ui message from raw agent run events.\n * Mirrors the client-side processEvent logic so the server can persist\n * the assistant's response even if the frontend is disconnected.\n */\nexport function buildAssistantMessage(\n events: RunEvent[],\n runId?: string,\n options: BuildAssistantMessageOptions = {},\n): {\n id: string;\n createdAt: Date;\n role: \"assistant\";\n content: ContentPart[];\n status:\n | { type: \"complete\"; reason: \"stop\" }\n | { type: \"incomplete\"; reason: \"error\" };\n metadata: Record<string, unknown>;\n} | null {\n const content: ContentPart[] = [];\n let toolCallCounter = 0;\n let runError: {\n message: string;\n errorCode?: string;\n details?: string;\n recoverable?: boolean;\n } | null = null;\n let endedAtInternalContinuationBoundary = false;\n\n const appendText = (text: string) => {\n const last = content[content.length - 1];\n if (last && last.type === \"text\") {\n last.text = (last.text ?? \"\") + text;\n } else {\n content.push({ type: \"text\", text });\n }\n };\n\n for (const { event } of events) {\n if (event.type === \"clear\") {\n content.length = 0;\n toolCallCounter = 0;\n continue;\n }\n\n if (event.type === \"text\") {\n appendText(event.text ?? \"\");\n continue;\n }\n\n if (event.type === \"tool_start\") {\n const toolCallId = `tc_${++toolCallCounter}`;\n const args = (event.input ?? {}) as Record<string, string>;\n content.push({\n type: \"tool-call\",\n toolCallId,\n toolName: event.tool ?? \"unknown\",\n argsText: JSON.stringify(args),\n args,\n });\n continue;\n }\n\n if (event.type === \"tool_done\") {\n for (let i = content.length - 1; i >= 0; i--) {\n const part = content[i];\n if (\n part.type === \"tool-call\" &&\n part.toolName === event.tool &&\n part.result === undefined\n ) {\n part.result = event.result ?? \"\";\n break;\n }\n }\n continue;\n }\n\n if (event.type === \"loop_limit\") {\n // Older servers emitted this as a user-visible terminal event. Treat it\n // as an internal continuation boundary when rebuilding persisted turns.\n if (options.suppressInternalContinuation) {\n endedAtInternalContinuationBoundary = true;\n }\n continue;\n }\n\n if (event.type === \"auto_continue\") {\n if (options.suppressInternalContinuation) {\n endedAtInternalContinuationBoundary = true;\n }\n continue;\n }\n\n if (event.type === \"error\") {\n if (\n options.suppressInternalContinuation &&\n isInternalContinuationError(event)\n ) {\n endedAtInternalContinuationBoundary = true;\n continue;\n }\n if (event.errorCode === \"run_timeout\" && event.recoverable) {\n continue;\n }\n runError = {\n message: event.error,\n ...(event.errorCode ? { errorCode: event.errorCode } : {}),\n ...(event.details ? { details: event.details } : {}),\n ...(event.recoverable ? { recoverable: event.recoverable } : {}),\n };\n appendText(`${content.length > 0 ? \"\\n\\n\" : \"\"}Error: ${event.error}`);\n continue;\n }\n\n // done, missing_api_key — terminal signals, not content\n }\n\n if (content.length === 0 || endedAtInternalContinuationBoundary) return null;\n\n const metadata: Record<string, unknown> = {};\n if (runId) metadata.runId = runId;\n if (runError) {\n metadata.custom = {\n runError: {\n ...runError,\n ...(runId ? { runId } : {}),\n },\n };\n }\n\n return {\n id: `server-${runId ?? Date.now()}`,\n createdAt: new Date(),\n role: \"assistant\",\n content,\n status: runError\n ? { type: \"incomplete\" as const, reason: \"error\" as const }\n : { type: \"complete\" as const, reason: \"stop\" as const },\n metadata,\n };\n}\n\nfunction getStoredMessage(entry: any): any {\n return entry?.message ?? entry;\n}\n\nfunction getStoredParentId(entry: any): string | null | undefined {\n return typeof entry?.parentId === \"string\" || entry?.parentId === null\n ? entry.parentId\n : undefined;\n}\n\nfunction getStoredRunConfig(entry: any): any {\n return entry && typeof entry === \"object\" && \"runConfig\" in entry\n ? entry.runConfig\n : undefined;\n}\n\nfunction messageId(message: any): string | undefined {\n return typeof message?.id === \"string\" && message.id ? message.id : undefined;\n}\n\nfunction getMessageRunId(message: any): string | undefined {\n const meta = message?.metadata;\n const direct = meta?.runId;\n const custom = meta?.custom?.runId;\n const errorRun = meta?.custom?.runError?.runId ?? meta?.runError?.runId;\n if (typeof direct === \"string\") return direct;\n if (typeof custom === \"string\") return custom;\n if (typeof errorRun === \"string\") return errorRun;\n return undefined;\n}\n\nfunction messageContentIsEmpty(content: unknown): boolean {\n if (Array.isArray(content)) return content.length === 0;\n return content == null || content === \"\";\n}\n\nfunction messageText(content: unknown): string {\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n return content\n .filter(\n (part: any) => part?.type === \"text\" && typeof part.text === \"string\",\n )\n .map((part: any) => part.text)\n .join(\"\");\n}\n\nfunction isTerminalAssistantStatus(status: unknown): boolean {\n const type = (status as { type?: unknown } | undefined)?.type;\n return type === \"complete\" || type === \"incomplete\";\n}\n\nfunction normalizeAttachmentIdentity(attachments: unknown): unknown {\n if (!Array.isArray(attachments) || attachments.length === 0) return undefined;\n return attachments.map((att: any) => ({\n type: att?.type,\n name: att?.name,\n contentType: att?.contentType,\n }));\n}\n\nfunction messageIdentityKeys(message: any): string[] {\n const keys: string[] = [];\n if (typeof message?.id === \"string\" && message.id) {\n keys.push(`id:${message.id}`);\n }\n const runId = getMessageRunId(message);\n if (runId) keys.push(`run:${runId}`);\n\n // Normalize attachments through `normalizeAttachmentIdentity` so an\n // explicit empty `[]` (assistant-ui's default for messages with no\n // attachments) and an omitted/undefined `attachments` field hash to the\n // same fingerprint. Without this, every user message ended up duplicated\n // in `chat_threads`: one copy from `saveThreadData` (runtime export\n // includes `attachments: []`) and one from `persistSubmittedUserMessage`\n // → `buildUserMessage` (omits the field entirely). The merge couldn't\n // dedupe them because their fingerprints differed by exactly one\n // `[]` vs `undefined`. (Repro on slides prod: every user turn produced\n // a `client_user → assistant → server_user` triple instead of a\n // `user → assistant` pair.)\n try {\n keys.push(\n `fingerprint:${JSON.stringify({\n role: message?.role,\n content: message?.content,\n attachments: normalizeAttachmentIdentity(message?.attachments),\n })}`,\n );\n } catch {\n // Best effort. id/runId usually exist for persisted assistant-ui rows.\n }\n if (message?.role === \"user\") {\n try {\n keys.push(\n `user-fingerprint:${JSON.stringify({\n role: message.role,\n content: message.content,\n attachments: normalizeAttachmentIdentity(message.attachments),\n })}`,\n );\n } catch {\n // Same best-effort behavior as the full fingerprint.\n }\n }\n return keys;\n}\n\nfunction messagesMatch(a: any, b: any): boolean {\n const bKeys = new Set(messageIdentityKeys(b));\n return messageIdentityKeys(a).some((key) => bKeys.has(key));\n}\n\nfunction chooseMergedMessageEntry(existingEntry: any, incomingEntry: any): any {\n const existing = getStoredMessage(existingEntry);\n const incoming = getStoredMessage(incomingEntry);\n if (\n existing?.role === \"assistant\" &&\n incoming?.role === \"assistant\" &&\n isTerminalAssistantStatus(existing?.status) &&\n !isTerminalAssistantStatus(incoming?.status)\n ) {\n return existingEntry;\n }\n return incomingEntry;\n}\n\nfunction normalizeMessageEntry(\n entry: any,\n parentId: string | null,\n): { message: any; parentId: string | null; runConfig?: any } | null {\n const message = getStoredMessage(entry);\n if (!messageId(message)) return null;\n const runConfig = getStoredRunConfig(entry);\n return {\n message,\n parentId,\n ...(runConfig !== undefined ? { runConfig } : {}),\n };\n}\n\n/**\n * Convert legacy/partially merged thread data into assistant-ui's exported\n * repository shape and repair parent links so `threadRuntime.import()` cannot\n * fail with \"Parent message not found\".\n */\nexport function normalizeThreadRepository(repo: any): any {\n const normalized = repo && typeof repo === \"object\" ? { ...repo } : {};\n const sourceMessages = Array.isArray(repo?.messages) ? repo.messages : [];\n const messages: Array<{\n message: any;\n parentId: string | null;\n runConfig?: any;\n }> = [];\n const seenIds = new Set<string>();\n let previousId: string | null = null;\n\n for (const entry of sourceMessages) {\n const message = getStoredMessage(entry);\n const id = messageId(message);\n if (!id) continue;\n\n const requestedParentId = getStoredParentId(entry);\n const parentId =\n requestedParentId === null\n ? null\n : requestedParentId && seenIds.has(requestedParentId)\n ? requestedParentId\n : previousId;\n\n const normalizedEntry = normalizeMessageEntry(entry, parentId);\n if (!normalizedEntry) continue;\n\n messages.push(normalizedEntry);\n seenIds.add(id);\n previousId = id;\n }\n\n normalized.messages = messages;\n const headId = typeof repo?.headId === \"string\" ? repo.headId : undefined;\n normalized.headId =\n headId && seenIds.has(headId) ? headId : (previousId ?? null);\n return normalized;\n}\n\nexport interface CodeAgentThreadTranscriptEvent {\n id: string;\n runId: string;\n kind?: CoreCodeAgentTranscriptEvent[\"kind\"];\n type?: CoreCodeAgentTranscriptEvent[\"kind\"] | \"note\";\n message?: string;\n text?: string;\n createdAt: string;\n metadata?: Record<string, unknown>;\n artifactPath?: string;\n artifactUrl?: string;\n}\n\nexport interface BuildRepositoryFromCodeAgentTranscriptOptions {\n hideCredentialMessages?: boolean;\n}\n\nexport function buildRepositoryFromCodeAgentTranscript(\n events: readonly CodeAgentThreadTranscriptEvent[],\n options: BuildRepositoryFromCodeAgentTranscriptOptions = {},\n): any {\n const normalized = normalizeCodeAgentTranscript(\n events.map(toCoreCodeAgentTranscriptEvent),\n );\n const repo: {\n headId: string | null;\n messages: Array<{ message: any; parentId: string | null }>;\n } = {\n headId: null,\n messages: [],\n };\n\n let headId: string | null = null;\n let assistantTurn: {\n turnIndex: number;\n id: string;\n createdAt: string;\n updatedAt: string;\n runId?: string;\n content: ContentPart[];\n eventIds: string[];\n } | null = null;\n\n const flushAssistant = () => {\n if (!assistantTurn || assistantTurn.content.length === 0) {\n assistantTurn = null;\n return;\n }\n const message = {\n id: assistantTurn.id,\n createdAt: new Date(assistantTurn.createdAt),\n role: \"assistant\" as const,\n content: assistantTurn.content,\n status: { type: \"complete\" as const, reason: \"stop\" as const },\n metadata: {\n ...(assistantTurn.runId ? { runId: assistantTurn.runId } : {}),\n custom: {\n codeAgentTranscriptEventIds: assistantTurn.eventIds,\n },\n },\n };\n repo.messages.push({ message, parentId: headId });\n headId = message.id;\n repo.headId = headId;\n assistantTurn = null;\n };\n\n for (const item of normalized.items) {\n if (item.type === \"user\") {\n flushAssistant();\n const runId = item.events[0]?.runId;\n const userMessage = buildUserMessage({\n text: item.text,\n attachments: codeAgentAttachmentsFromEvents(item.events),\n runId: runId ? `${runId}-${item.id}` : item.id,\n createdAt: new Date(item.createdAt),\n });\n userMessage.id = `code-user-${item.id}`;\n const existingCustom =\n userMessage.metadata.custom &&\n typeof userMessage.metadata.custom === \"object\"\n ? (userMessage.metadata.custom as Record<string, unknown>)\n : {};\n userMessage.metadata = {\n ...userMessage.metadata,\n custom: {\n ...existingCustom,\n submittedRunId: runId,\n codeAgentTranscriptEventIds: item.eventIds,\n },\n };\n repo.messages.push({ message: userMessage, parentId: headId });\n headId = userMessage.id;\n repo.headId = headId;\n continue;\n }\n\n const content = contentPartForCodeAgentTranscriptItem(item, options);\n if (!content) continue;\n\n if (!assistantTurn || assistantTurn.turnIndex !== item.turnIndex) {\n flushAssistant();\n assistantTurn = {\n turnIndex: item.turnIndex,\n id: `code-assistant-${item.turnIndex}-${item.id}`,\n createdAt: item.createdAt,\n updatedAt: item.updatedAt,\n runId: item.events[0]?.runId,\n content: [],\n eventIds: [],\n };\n }\n assistantTurn.updatedAt = item.updatedAt;\n assistantTurn.eventIds.push(...item.eventIds);\n if (content.type === \"text\") {\n const last = assistantTurn.content.at(-1);\n if (last?.type === \"text\") {\n last.text = `${last.text}${last.text ? \"\\n\\n\" : \"\"}${content.text}`;\n } else {\n assistantTurn.content.push(content);\n }\n } else {\n assistantTurn.content.push(content);\n }\n }\n\n flushAssistant();\n return normalizeThreadRepository(repo);\n}\n\nfunction rewriteEntryParentId(\n entry: any,\n idRewrites: Map<string, string>,\n): any {\n const parentId = getStoredParentId(entry);\n if (!parentId) return entry;\n const rewritten = idRewrites.get(parentId);\n if (!rewritten) return entry;\n return { ...entry, parentId: rewritten };\n}\n\n/**\n * Merge an incoming client-side full-thread save over the current SQL copy.\n *\n * The browser exports and PUTs the whole assistant-ui repository. If a server\n * completion save lands first, an older browser export can otherwise replace\n * `thread_data` wholesale and delete the assistant message the server just\n * reconstructed from run events. Preserve server-only messages while still\n * accepting client-only messages and metadata.\n */\nexport interface MergeThreadDataOptions {\n preserveExistingQueuedMessages?: boolean;\n preserveExistingTopLevelKeys?: boolean;\n}\n\nexport function mergeThreadDataForClientSave(\n existingRepo: any,\n incomingRepo: any,\n options: MergeThreadDataOptions = {},\n) {\n const preserveExistingQueuedMessages =\n options.preserveExistingQueuedMessages ?? true;\n const preserveExistingTopLevelKeys =\n options.preserveExistingTopLevelKeys ?? true;\n const existingNormalized = normalizeThreadRepository(existingRepo);\n const incomingNormalized = normalizeThreadRepository(incomingRepo);\n const merged =\n incomingNormalized && typeof incomingNormalized === \"object\"\n ? { ...incomingNormalized }\n : {};\n if (\n preserveExistingTopLevelKeys &&\n existingNormalized &&\n typeof existingNormalized === \"object\"\n ) {\n for (const [key, value] of Object.entries(existingNormalized)) {\n if (key === \"messages\" || key === \"headId\") continue;\n if (key === \"queuedMessages\" && !preserveExistingQueuedMessages) {\n continue;\n }\n if (!(key in merged)) {\n merged[key] = value;\n }\n }\n } else if (\n preserveExistingQueuedMessages &&\n existingNormalized &&\n typeof existingNormalized === \"object\" &&\n existingNormalized.queuedMessages !== undefined &&\n merged.queuedMessages === undefined\n ) {\n merged.queuedMessages = existingNormalized.queuedMessages;\n }\n\n const existingMessages = Array.isArray(existingNormalized?.messages)\n ? existingNormalized.messages\n : null;\n const incomingMessages = Array.isArray(merged.messages)\n ? merged.messages\n : null;\n if (!existingMessages || !incomingMessages) return merged;\n\n const incomingKeySets = incomingMessages.map(\n (entry: any) => new Set(messageIdentityKeys(getStoredMessage(entry))),\n );\n const usedIncoming = new Set<number>();\n const nextMessages: any[] = [];\n const idRewrites = new Map<string, string>();\n\n for (const existingEntry of existingMessages) {\n const existingKeys = messageIdentityKeys(getStoredMessage(existingEntry));\n const incomingIndex = incomingKeySets.findIndex(\n (keys, index) =>\n !usedIncoming.has(index) && existingKeys.some((key) => keys.has(key)),\n );\n\n if (incomingIndex === -1) {\n nextMessages.push(existingEntry);\n continue;\n }\n\n usedIncoming.add(incomingIndex);\n const incomingEntry = incomingMessages[incomingIndex];\n const chosen = chooseMergedMessageEntry(existingEntry, incomingEntry);\n const existingId = messageId(getStoredMessage(existingEntry));\n const chosenId = messageId(getStoredMessage(chosen));\n if (existingId && chosenId && existingId !== chosenId) {\n idRewrites.set(existingId, chosenId);\n }\n nextMessages.push(chosen);\n }\n\n for (let index = 0; index < incomingMessages.length; index++) {\n if (!usedIncoming.has(index)) nextMessages.push(incomingMessages[index]);\n }\n\n merged.messages = nextMessages.map((entry) =>\n rewriteEntryParentId(entry, idRewrites),\n );\n return normalizeThreadRepository(merged);\n}\n\nfunction escapeAttachmentAttribute(value: string): string {\n return value.replace(/&/g, \"&\").replace(/\"/g, \""\");\n}\n\nfunction unwrapTextAttachmentEnvelope(text: string): string {\n const match = text.match(\n /^<attachment\\b[^>]*>\\n?([\\s\\S]*?)\\n?<\\/attachment>$/,\n );\n return match ? match[1] : text;\n}\n\nfunction truncateStoredAttachment(text: string): string {\n const unwrapped = unwrapTextAttachmentEnvelope(text);\n if (unwrapped.length <= MAX_STORED_ATTACHMENT_CHARS) return unwrapped;\n const omitted = unwrapped.length - MAX_STORED_ATTACHMENT_CHARS;\n return `${unwrapped.slice(0, MAX_STORED_ATTACHMENT_CHARS)}\\n\\n[Attachment truncated after ${MAX_STORED_ATTACHMENT_CHARS.toLocaleString()} characters; ${omitted.toLocaleString()} characters omitted from persisted chat history.]`;\n}\n\nfunction textAttachmentEnvelope(\n att: AgentChatAttachment,\n text: string,\n): string {\n const attrs = [\n `name=\"${escapeAttachmentAttribute(att.name || \"attachment\")}\"`,\n att.contentType\n ? `contentType=\"${escapeAttachmentAttribute(att.contentType)}\"`\n : null,\n att.type ? `type=\"${escapeAttachmentAttribute(att.type)}\"` : null,\n ].filter(Boolean);\n return `<attachment ${attrs.join(\" \")}>\\n${truncateStoredAttachment(text)}\\n</attachment>`;\n}\n\nfunction buildStoredAttachments(\n attachments: AgentChatAttachment[] | undefined,\n runId: string | undefined,\n): any[] {\n return (attachments ?? [])\n .map((att, index) => {\n const id = `server-${runId ?? Date.now()}-attachment-${index}`;\n if (att.type === \"image\" && att.data) {\n return {\n id,\n type: \"image\",\n name: att.name,\n contentType: att.contentType,\n status: { type: \"complete\" },\n content: [{ type: \"image\", image: att.data }],\n };\n }\n if (att.data) {\n return {\n id,\n type: \"file\",\n name: att.name,\n contentType: att.contentType,\n status: { type: \"complete\" },\n content: [\n {\n type: \"file\",\n data: att.data,\n mimeType: att.contentType,\n filename: att.name,\n },\n ],\n };\n }\n if (typeof att.text === \"string\" && att.text.length > 0) {\n return {\n id,\n type: \"file\",\n name: att.name,\n contentType: att.contentType,\n status: { type: \"complete\" },\n content: [\n { type: \"text\", text: textAttachmentEnvelope(att, att.text) },\n ],\n };\n }\n return null;\n })\n .filter(Boolean);\n}\n\nexport function buildUserMessage(opts: {\n text: string;\n attachments?: AgentChatAttachment[];\n runId?: string;\n createdAt?: Date;\n}): {\n id: string;\n createdAt: Date;\n role: \"user\";\n content: ContentPart[];\n attachments?: any[];\n metadata: Record<string, unknown>;\n} {\n const attachments = buildStoredAttachments(opts.attachments, opts.runId);\n return {\n id: `server-user-${opts.runId ?? Date.now()}`,\n createdAt: opts.createdAt ?? new Date(),\n role: \"user\",\n content: [{ type: \"text\", text: opts.text }],\n ...(attachments.length > 0 ? { attachments } : {}),\n metadata: {\n custom: {\n submittedRunId: opts.runId,\n },\n },\n };\n}\n\nfunction toCoreCodeAgentTranscriptEvent(\n event: CodeAgentThreadTranscriptEvent,\n): CoreCodeAgentTranscriptEvent {\n return {\n schemaVersion: 1,\n id: event.id,\n runId: event.runId,\n kind: (event.kind ??\n event.type ??\n \"status\") as CoreCodeAgentTranscriptEvent[\"kind\"],\n message: event.message ?? event.text ?? \"\",\n createdAt: event.createdAt,\n metadata: {\n ...(event.metadata ?? {}),\n ...(event.artifactPath ? { artifactPath: event.artifactPath } : {}),\n ...(event.artifactUrl ? { artifactUrl: event.artifactUrl } : {}),\n },\n };\n}\n\nfunction contentPartForCodeAgentTranscriptItem(\n item: NormalizedCodeAgentTranscriptItem,\n options: BuildRepositoryFromCodeAgentTranscriptOptions,\n): ContentPart | null {\n if (item.type === \"assistant\") {\n return item.text.trim() ? { type: \"text\", text: item.text } : null;\n }\n if (item.type === \"tool\") {\n return toolContentPartForCodeAgentTranscriptItem(item);\n }\n if (item.type === \"status\") {\n const text = statusTextForCodeAgentTranscriptItem(item, options);\n return text ? { type: \"text\", text } : null;\n }\n return null;\n}\n\nfunction toolContentPartForCodeAgentTranscriptItem(\n item: NormalizedCodeAgentToolEvent,\n): ContentPart {\n return {\n type: \"tool-call\",\n toolCallId: `code-tool-${item.id}`,\n toolName: item.tool ?? item.label ?? \"code-agent\",\n argsText: previewCodeAgentTranscriptValue(item.input) ?? \"\",\n args: recordArgsForCodeAgentTool(item.input),\n ...(item.result !== undefined\n ? { result: previewCodeAgentTranscriptValue(item.result) ?? \"\" }\n : {}),\n };\n}\n\nfunction statusTextForCodeAgentTranscriptItem(\n item: NormalizedCodeAgentStatusEvent,\n options: BuildRepositoryFromCodeAgentTranscriptOptions,\n): string | null {\n if (options.hideCredentialMessages && isCredentialCodeAgentText(item.text)) {\n return null;\n }\n if (item.statusKind === \"artifact\") {\n const event = item.events[0];\n const path =\n stringRecordValue(event?.metadata, \"artifactPath\") ??\n stringRecordValue(event?.metadata, \"path\");\n const url = stringRecordValue(event?.metadata, \"artifactUrl\");\n const target = url ?? path;\n return target\n ? `Artifact: ${item.text}\\n${target}`\n : `Artifact: ${item.text}`;\n }\n if (item.level === \"info\" && item.statusKind !== \"note\") return null;\n return item.text;\n}\n\nfunction codeAgentAttachmentsFromEvents(\n events: readonly CoreCodeAgentTranscriptEvent[],\n): AgentChatAttachment[] {\n for (const event of events) {\n const raw = event.metadata?.attachments;\n if (!Array.isArray(raw) || raw.length === 0) continue;\n const attachments: AgentChatAttachment[] = [];\n for (const item of raw) {\n if (!item || typeof item !== \"object\") continue;\n const record = item as Record<string, unknown>;\n const name = stringRecordValue(record, \"name\");\n if (!name) continue;\n const contentType = stringRecordValue(record, \"type\");\n const text = stringRecordValue(record, \"text\");\n const dataUrl = stringRecordValue(record, \"dataUrl\");\n attachments.push({\n type: dataUrl ? \"image\" : \"file\",\n name,\n ...(contentType ? { contentType } : {}),\n ...(text ? { text } : {}),\n ...(dataUrl ? { data: dataUrl } : {}),\n });\n }\n if (attachments.length > 0) return attachments;\n }\n return [];\n}\n\nfunction recordArgsForCodeAgentTool(value: unknown): Record<string, string> {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return {};\n const result: Record<string, string> = {};\n for (const [key, entry] of Object.entries(value)) {\n result[key] =\n typeof entry === \"string\"\n ? entry\n : (previewCodeAgentTranscriptValue(entry) ?? \"\");\n }\n return result;\n}\n\nfunction previewCodeAgentTranscriptValue(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n const text =\n typeof value === \"string\" ? value : (JSON.stringify(value, null, 2) ?? \"\");\n const trimmed = text.trim();\n if (!trimmed) return undefined;\n return trimmed.length > 4000 ? `${trimmed.slice(0, 4000)}\\n...` : trimmed;\n}\n\nfunction stringRecordValue(\n record: Record<string, unknown> | undefined,\n key: string,\n): string | undefined {\n const value = record?.[key];\n return typeof value === \"string\" && value.trim() ? value.trim() : undefined;\n}\n\nfunction isCredentialCodeAgentText(value: string): boolean {\n return /No LLM provider key was found|Missing credentials/i.test(value);\n}\n\nexport function upsertUserMessage(repo: any, userMsg: UserMessage): any {\n const nextRepo = normalizeThreadRepository(repo);\n\n const lastIndex = nextRepo.messages.length - 1;\n const lastEntry = lastIndex >= 0 ? nextRepo.messages[lastIndex] : undefined;\n const lastMsg = getStoredMessage(lastEntry);\n if (lastMsg?.role === \"user\" && messagesMatch(lastMsg, userMsg)) {\n return nextRepo;\n }\n\n const parentId =\n lastIndex >= 0 ? (messageId(getStoredMessage(lastEntry)) ?? null) : null;\n nextRepo.messages.push({ message: userMsg, parentId });\n nextRepo.headId = userMsg.id;\n return nextRepo;\n}\n\nfunction shouldReplaceLastAssistant(\n lastMessage: any,\n assistantMsg: AssistantMessage,\n): boolean {\n const lastContent = lastMessage?.content;\n if (messageContentIsEmpty(lastContent)) return true;\n\n const lastRunId = getMessageRunId(lastMessage);\n const nextRunId = getMessageRunId(assistantMsg);\n if (lastRunId && nextRunId && lastRunId === nextRunId) return true;\n if (lastRunId && nextRunId && lastRunId !== nextRunId) return false;\n\n const lastStatus = lastMessage?.status;\n if (lastStatus && !isTerminalAssistantStatus(lastStatus)) return true;\n\n try {\n if (JSON.stringify(lastContent) === JSON.stringify(assistantMsg.content)) {\n return true;\n }\n } catch {\n // Fall through to the text-prefix check.\n }\n\n const lastText = messageText(lastContent).trim();\n const nextText = messageText(assistantMsg.content).trim();\n if (isTerminalAssistantStatus(lastStatus)) return false;\n return Boolean(lastText && nextText && nextText.startsWith(lastText));\n}\n\n/**\n * Merge the server-reconstructed assistant message into persisted\n * assistant-ui thread data.\n *\n * The browser periodically saves thread data while a run is still streaming.\n * That can leave the last assistant message non-empty but partial/pending.\n * Completion must replace that same-run partial message instead of treating\n * any assistant content as proof that the frontend already saved the final\n * turn.\n */\nexport function upsertAssistantMessage(\n repo: any,\n assistantMsg: AssistantMessage,\n): any {\n const nextRepo = normalizeThreadRepository(repo);\n\n const lastIndex = nextRepo.messages.length - 1;\n const lastEntry = lastIndex >= 0 ? nextRepo.messages[lastIndex] : undefined;\n const lastMsg = getStoredMessage(lastEntry);\n const lastRole = lastMsg?.role;\n\n if (\n lastRole === \"assistant\" &&\n shouldReplaceLastAssistant(lastMsg, assistantMsg)\n ) {\n nextRepo.messages[lastIndex] = { ...lastEntry, message: assistantMsg };\n nextRepo.headId = assistantMsg.id;\n return nextRepo;\n }\n\n const parentId =\n nextRepo.messages.length > 0\n ? (messageId(\n getStoredMessage(nextRepo.messages[nextRepo.messages.length - 1]),\n ) ?? null)\n : null;\n nextRepo.messages.push({ message: assistantMsg, parentId });\n nextRepo.headId = assistantMsg.id;\n return nextRepo;\n}\n\nexport function normalizeThreadTitle(value: unknown): string {\n if (typeof value !== \"string\") return \"\";\n return value.replace(/\\s+/g, \" \").trim().slice(0, 160);\n}\n\n/**\n * Extract title and preview from a thread runtime export.\n * Isomorphic — works on both server and client.\n */\nexport function extractThreadMeta(repo: any): {\n title: string;\n preview: string;\n} {\n const titleOverride = normalizeThreadTitle(repo?._titleOverride);\n const msgs = repo?.messages;\n if (!Array.isArray(msgs) || msgs.length === 0)\n return { title: titleOverride, preview: \"\" };\n\n let title = \"\";\n let preview = \"\";\n for (const entry of msgs) {\n // Support both wrapped ({ message: { role, content } }) and flat ({ role, content }) formats\n const msg = entry?.message ?? entry;\n if (msg.role !== \"user\") continue;\n const textParts = Array.isArray(msg.content)\n ? msg.content\n .filter((p: any) => p.type === \"text\")\n .map((p: any) => p.text)\n .join(\" \")\n : typeof msg.content === \"string\"\n ? msg.content\n : \"\";\n if (textParts.trim()) {\n if (!title) title = textParts.trim().slice(0, 80);\n preview = textParts.trim().slice(0, 120);\n }\n }\n return { title: titleOverride || title, preview };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"thread-data-builder.js","sourceRoot":"","sources":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E,KAAK,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAClD,OAAO,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,aAAa,IAAI,KAAK,EAAE,OAAO,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import type { AgentChatAttachment, RunEvent } from \"./types.js\";\nimport {\n normalizeCodeAgentTranscript,\n type CodeAgentTranscriptEvent as CoreCodeAgentTranscriptEvent,\n type NormalizedCodeAgentStatusEvent,\n type NormalizedCodeAgentToolEvent,\n type NormalizedCodeAgentTranscriptItem,\n} from \"../code-agents/transcript-normalizer.js\";\n\ninterface ContentPart {\n type: string;\n text?: string;\n toolCallId?: string;\n toolName?: string;\n argsText?: string;\n args?: Record<string, string>;\n result?: string;\n}\n\ninterface BuildAssistantMessageOptions {\n suppressInternalContinuation?: boolean;\n /**\n * Logical-turn identity. When set it is stamped onto the message metadata so\n * continuation runs of the same turn can be folded onto a single durable\n * assistant message (see foldAssistantTurn) instead of each run dropping or\n * overwriting the others.\n */\n turnId?: string;\n}\n\ntype AssistantMessage = NonNullable<ReturnType<typeof buildAssistantMessage>>;\ntype UserMessage = ReturnType<typeof buildUserMessage>;\n\nconst MAX_STORED_ATTACHMENT_CHARS = 60_000;\n\nfunction isInternalContinuationError(event: {\n error: string;\n errorCode?: string;\n recoverable?: boolean;\n}): boolean {\n const code = String(event.errorCode ?? \"\").toLowerCase();\n const msg = event.error.toLowerCase();\n if (code === \"builder_gateway_error\") return false;\n return (\n event.recoverable === true ||\n code === \"builder_gateway_timeout\" ||\n code === \"stale_run\" ||\n code === \"timeout\" ||\n code === \"timeout_error\" ||\n code === \"http_408\" ||\n code === \"http_429\" ||\n code === \"http_500\" ||\n code === \"http_502\" ||\n code === \"http_503\" ||\n code === \"http_504\" ||\n code === \"rate_limited\" ||\n code === \"too_many_concurrent_requests\" ||\n code === \"overloaded_error\" ||\n msg.includes(\"timeout\") ||\n msg.includes(\"gateway timeout\") ||\n msg.includes(\"inactivity timeout\") ||\n msg.includes(\"stream ended\") ||\n msg.includes(\"stream closed\") ||\n msg.includes(\"temporarily unavailable\") ||\n msg.includes(\"502\") ||\n msg.includes(\"503\") ||\n msg.includes(\"504\") ||\n msg.includes(\"529\")\n );\n}\n\n/**\n * Reconstruct an assistant-ui message from raw agent run events.\n * Mirrors the client-side processEvent logic so the server can persist\n * the assistant's response even if the frontend is disconnected.\n */\nexport function buildAssistantMessage(\n events: RunEvent[],\n runId?: string,\n options: BuildAssistantMessageOptions = {},\n): {\n id: string;\n createdAt: Date;\n role: \"assistant\";\n content: ContentPart[];\n status:\n | { type: \"complete\"; reason: \"stop\" }\n | { type: \"incomplete\"; reason: \"error\" };\n metadata: Record<string, unknown>;\n} | null {\n const content: ContentPart[] = [];\n let toolCallCounter = 0;\n let runError: {\n message: string;\n errorCode?: string;\n details?: string;\n recoverable?: boolean;\n } | null = null;\n let endedAtInternalContinuationBoundary = false;\n\n const appendText = (text: string) => {\n const last = content[content.length - 1];\n if (last && last.type === \"text\") {\n last.text = (last.text ?? \"\") + text;\n } else {\n content.push({ type: \"text\", text });\n }\n };\n\n for (const { event } of events) {\n if (event.type === \"clear\") {\n content.length = 0;\n toolCallCounter = 0;\n continue;\n }\n\n if (event.type === \"text\") {\n appendText(event.text ?? \"\");\n continue;\n }\n\n if (event.type === \"tool_start\") {\n const toolCallId = `tc_${++toolCallCounter}`;\n const args = (event.input ?? {}) as Record<string, string>;\n content.push({\n type: \"tool-call\",\n toolCallId,\n toolName: event.tool ?? \"unknown\",\n argsText: JSON.stringify(args),\n args,\n });\n continue;\n }\n\n if (event.type === \"tool_done\") {\n for (let i = content.length - 1; i >= 0; i--) {\n const part = content[i];\n if (\n part.type === \"tool-call\" &&\n part.toolName === event.tool &&\n part.result === undefined\n ) {\n part.result = event.result ?? \"\";\n break;\n }\n }\n continue;\n }\n\n if (event.type === \"loop_limit\") {\n // Older servers emitted this as a user-visible terminal event. Treat it\n // as an internal continuation boundary when rebuilding persisted turns.\n if (options.suppressInternalContinuation) {\n endedAtInternalContinuationBoundary = true;\n }\n continue;\n }\n\n if (event.type === \"auto_continue\") {\n if (options.suppressInternalContinuation) {\n endedAtInternalContinuationBoundary = true;\n }\n continue;\n }\n\n if (event.type === \"error\") {\n if (\n options.suppressInternalContinuation &&\n isInternalContinuationError(event)\n ) {\n endedAtInternalContinuationBoundary = true;\n continue;\n }\n if (event.errorCode === \"run_timeout\" && event.recoverable) {\n continue;\n }\n runError = {\n message: event.error,\n ...(event.errorCode ? { errorCode: event.errorCode } : {}),\n ...(event.details ? { details: event.details } : {}),\n ...(event.recoverable ? { recoverable: event.recoverable } : {}),\n };\n appendText(`${content.length > 0 ? \"\\n\\n\" : \"\"}Error: ${event.error}`);\n continue;\n }\n\n // done, missing_api_key — terminal signals, not content\n }\n\n // Only a truly empty turn produces nothing to persist. A turn that ended at\n // an internal continuation boundary (soft-timeout auto_continue, a\n // recoverable gateway error, suppressed loop_limit) DID stream real content\n // — persist it as a partial so the continuation run can fold the next chunk\n // onto it (foldAssistantTurn) instead of the earlier text being dropped.\n if (content.length === 0) return null;\n\n const continued = endedAtInternalContinuationBoundary;\n\n const custom: Record<string, unknown> = {};\n if (options.turnId) custom.turnId = options.turnId;\n if (runId) custom.foldedRunIds = [runId];\n if (continued) custom.continued = true;\n if (runError) {\n custom.runError = {\n ...runError,\n ...(runId ? { runId } : {}),\n };\n }\n\n const metadata: Record<string, unknown> = {};\n if (runId) metadata.runId = runId;\n if (Object.keys(custom).length > 0) metadata.custom = custom;\n\n return {\n id: `server-${runId ?? Date.now()}`,\n createdAt: new Date(),\n role: \"assistant\",\n content,\n status: runError\n ? { type: \"incomplete\" as const, reason: \"error\" as const }\n : { type: \"complete\" as const, reason: \"stop\" as const },\n metadata,\n };\n}\n\nfunction getStoredMessage(entry: any): any {\n return entry?.message ?? entry;\n}\n\nfunction getStoredParentId(entry: any): string | null | undefined {\n return typeof entry?.parentId === \"string\" || entry?.parentId === null\n ? entry.parentId\n : undefined;\n}\n\nfunction getStoredRunConfig(entry: any): any {\n return entry && typeof entry === \"object\" && \"runConfig\" in entry\n ? entry.runConfig\n : undefined;\n}\n\nfunction messageId(message: any): string | undefined {\n return typeof message?.id === \"string\" && message.id ? message.id : undefined;\n}\n\nfunction getMessageRunId(message: any): string | undefined {\n const meta = message?.metadata;\n const direct = meta?.runId;\n const custom = meta?.custom?.runId;\n const errorRun = meta?.custom?.runError?.runId ?? meta?.runError?.runId;\n if (typeof direct === \"string\") return direct;\n if (typeof custom === \"string\") return custom;\n if (typeof errorRun === \"string\") return errorRun;\n return undefined;\n}\n\nfunction messageContentIsEmpty(content: unknown): boolean {\n if (Array.isArray(content)) return content.length === 0;\n return content == null || content === \"\";\n}\n\nfunction messageText(content: unknown): string {\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n return content\n .filter(\n (part: any) => part?.type === \"text\" && typeof part.text === \"string\",\n )\n .map((part: any) => part.text)\n .join(\"\");\n}\n\nfunction isTerminalAssistantStatus(status: unknown): boolean {\n const type = (status as { type?: unknown } | undefined)?.type;\n return type === \"complete\" || type === \"incomplete\";\n}\n\nfunction normalizeAttachmentIdentity(attachments: unknown): unknown {\n if (!Array.isArray(attachments) || attachments.length === 0) return undefined;\n return attachments.map((att: any) => ({\n type: att?.type,\n name: att?.name,\n contentType: att?.contentType,\n }));\n}\n\nfunction messageIdentityKeys(message: any): string[] {\n const keys: string[] = [];\n if (typeof message?.id === \"string\" && message.id) {\n keys.push(`id:${message.id}`);\n }\n const runId = getMessageRunId(message);\n if (runId) keys.push(`run:${runId}`);\n // A logical turn is ONE durable assistant message even though it may span\n // several continuation runs, so two messages sharing a turnId (e.g. the\n // client export and the server fold of the same answer) must dedupe to one.\n const turnId = turnIdOf(message);\n if (turnId) keys.push(`turn:${turnId}`);\n\n // Normalize attachments through `normalizeAttachmentIdentity` so an\n // explicit empty `[]` (assistant-ui's default for messages with no\n // attachments) and an omitted/undefined `attachments` field hash to the\n // same fingerprint. Without this, every user message ended up duplicated\n // in `chat_threads`: one copy from `saveThreadData` (runtime export\n // includes `attachments: []`) and one from `persistSubmittedUserMessage`\n // → `buildUserMessage` (omits the field entirely). The merge couldn't\n // dedupe them because their fingerprints differed by exactly one\n // `[]` vs `undefined`. (Repro on slides prod: every user turn produced\n // a `client_user → assistant → server_user` triple instead of a\n // `user → assistant` pair.)\n try {\n keys.push(\n `fingerprint:${JSON.stringify({\n role: message?.role,\n content: message?.content,\n attachments: normalizeAttachmentIdentity(message?.attachments),\n })}`,\n );\n } catch {\n // Best effort. id/runId usually exist for persisted assistant-ui rows.\n }\n if (message?.role === \"user\") {\n try {\n keys.push(\n `user-fingerprint:${JSON.stringify({\n role: message.role,\n content: message.content,\n attachments: normalizeAttachmentIdentity(message.attachments),\n })}`,\n );\n } catch {\n // Same best-effort behavior as the full fingerprint.\n }\n }\n return keys;\n}\n\nfunction messagesMatch(a: any, b: any): boolean {\n const bKeys = new Set(messageIdentityKeys(b));\n return messageIdentityKeys(a).some((key) => bKeys.has(key));\n}\n\nfunction chooseMergedMessageEntry(existingEntry: any, incomingEntry: any): any {\n const existing = getStoredMessage(existingEntry);\n const incoming = getStoredMessage(incomingEntry);\n // Same logical turn (client export vs server fold of one accumulating\n // answer): never shrink — keep whichever side accumulated more content, so a\n // stale/lossy export can't overwrite the richer folded turn. Ties prefer the\n // terminal copy.\n const existingTurn = turnIdOf(existing);\n const incomingTurn = turnIdOf(incoming);\n if (\n existing?.role === \"assistant\" &&\n incoming?.role === \"assistant\" &&\n existingTurn &&\n existingTurn === incomingTurn\n ) {\n const existingWeight = assistantContentWeight(existing.content);\n const incomingWeight = assistantContentWeight(incoming.content);\n if (existingWeight > incomingWeight) return existingEntry;\n if (incomingWeight > existingWeight) return incomingEntry;\n return isTerminalAssistantStatus(existing?.status) &&\n !isTerminalAssistantStatus(incoming?.status)\n ? existingEntry\n : incomingEntry;\n }\n if (\n existing?.role === \"assistant\" &&\n incoming?.role === \"assistant\" &&\n isTerminalAssistantStatus(existing?.status) &&\n !isTerminalAssistantStatus(incoming?.status)\n ) {\n return existingEntry;\n }\n return incomingEntry;\n}\n\nfunction normalizeMessageEntry(\n entry: any,\n parentId: string | null,\n): { message: any; parentId: string | null; runConfig?: any } | null {\n const message = getStoredMessage(entry);\n if (!messageId(message)) return null;\n const runConfig = getStoredRunConfig(entry);\n return {\n message,\n parentId,\n ...(runConfig !== undefined ? { runConfig } : {}),\n };\n}\n\n/**\n * Convert legacy/partially merged thread data into assistant-ui's exported\n * repository shape and repair parent links so `threadRuntime.import()` cannot\n * fail with \"Parent message not found\".\n */\nexport function normalizeThreadRepository(repo: any): any {\n const normalized = repo && typeof repo === \"object\" ? { ...repo } : {};\n const sourceMessages = Array.isArray(repo?.messages) ? repo.messages : [];\n const messages: Array<{\n message: any;\n parentId: string | null;\n runConfig?: any;\n }> = [];\n const seenIds = new Set<string>();\n let previousId: string | null = null;\n\n for (const entry of sourceMessages) {\n const message = getStoredMessage(entry);\n const id = messageId(message);\n if (!id) continue;\n\n const requestedParentId = getStoredParentId(entry);\n const parentId =\n requestedParentId === null\n ? null\n : requestedParentId && seenIds.has(requestedParentId)\n ? requestedParentId\n : previousId;\n\n const normalizedEntry = normalizeMessageEntry(entry, parentId);\n if (!normalizedEntry) continue;\n\n messages.push(normalizedEntry);\n seenIds.add(id);\n previousId = id;\n }\n\n normalized.messages = messages;\n const headId = typeof repo?.headId === \"string\" ? repo.headId : undefined;\n normalized.headId =\n headId && seenIds.has(headId) ? headId : (previousId ?? null);\n return normalized;\n}\n\nexport interface CodeAgentThreadTranscriptEvent {\n id: string;\n runId: string;\n kind?: CoreCodeAgentTranscriptEvent[\"kind\"];\n type?: CoreCodeAgentTranscriptEvent[\"kind\"] | \"note\";\n message?: string;\n text?: string;\n createdAt: string;\n metadata?: Record<string, unknown>;\n artifactPath?: string;\n artifactUrl?: string;\n}\n\nexport interface BuildRepositoryFromCodeAgentTranscriptOptions {\n hideCredentialMessages?: boolean;\n}\n\nexport function buildRepositoryFromCodeAgentTranscript(\n events: readonly CodeAgentThreadTranscriptEvent[],\n options: BuildRepositoryFromCodeAgentTranscriptOptions = {},\n): any {\n const normalized = normalizeCodeAgentTranscript(\n events.map(toCoreCodeAgentTranscriptEvent),\n );\n const repo: {\n headId: string | null;\n messages: Array<{ message: any; parentId: string | null }>;\n } = {\n headId: null,\n messages: [],\n };\n\n let headId: string | null = null;\n let assistantTurn: {\n turnIndex: number;\n id: string;\n createdAt: string;\n updatedAt: string;\n runId?: string;\n content: ContentPart[];\n eventIds: string[];\n } | null = null;\n\n const flushAssistant = () => {\n if (!assistantTurn || assistantTurn.content.length === 0) {\n assistantTurn = null;\n return;\n }\n const message = {\n id: assistantTurn.id,\n createdAt: new Date(assistantTurn.createdAt),\n role: \"assistant\" as const,\n content: assistantTurn.content,\n status: { type: \"complete\" as const, reason: \"stop\" as const },\n metadata: {\n ...(assistantTurn.runId ? { runId: assistantTurn.runId } : {}),\n custom: {\n codeAgentTranscriptEventIds: assistantTurn.eventIds,\n },\n },\n };\n repo.messages.push({ message, parentId: headId });\n headId = message.id;\n repo.headId = headId;\n assistantTurn = null;\n };\n\n for (const item of normalized.items) {\n if (item.type === \"user\") {\n flushAssistant();\n const runId = item.events[0]?.runId;\n const userMessage = buildUserMessage({\n text: item.text,\n attachments: codeAgentAttachmentsFromEvents(item.events),\n runId: runId ? `${runId}-${item.id}` : item.id,\n createdAt: new Date(item.createdAt),\n });\n userMessage.id = `code-user-${item.id}`;\n const existingCustom =\n userMessage.metadata.custom &&\n typeof userMessage.metadata.custom === \"object\"\n ? (userMessage.metadata.custom as Record<string, unknown>)\n : {};\n userMessage.metadata = {\n ...userMessage.metadata,\n custom: {\n ...existingCustom,\n submittedRunId: runId,\n codeAgentTranscriptEventIds: item.eventIds,\n },\n };\n repo.messages.push({ message: userMessage, parentId: headId });\n headId = userMessage.id;\n repo.headId = headId;\n continue;\n }\n\n const content = contentPartForCodeAgentTranscriptItem(item, options);\n if (!content) continue;\n\n if (!assistantTurn || assistantTurn.turnIndex !== item.turnIndex) {\n flushAssistant();\n assistantTurn = {\n turnIndex: item.turnIndex,\n id: `code-assistant-${item.turnIndex}-${item.id}`,\n createdAt: item.createdAt,\n updatedAt: item.updatedAt,\n runId: item.events[0]?.runId,\n content: [],\n eventIds: [],\n };\n }\n assistantTurn.updatedAt = item.updatedAt;\n assistantTurn.eventIds.push(...item.eventIds);\n if (content.type === \"text\") {\n const last = assistantTurn.content.at(-1);\n if (last?.type === \"text\") {\n last.text = `${last.text}${last.text ? \"\\n\\n\" : \"\"}${content.text}`;\n } else {\n assistantTurn.content.push(content);\n }\n } else {\n assistantTurn.content.push(content);\n }\n }\n\n flushAssistant();\n return normalizeThreadRepository(repo);\n}\n\nfunction rewriteEntryParentId(\n entry: any,\n idRewrites: Map<string, string>,\n): any {\n const parentId = getStoredParentId(entry);\n if (!parentId) return entry;\n const rewritten = idRewrites.get(parentId);\n if (!rewritten) return entry;\n return { ...entry, parentId: rewritten };\n}\n\n/**\n * Merge an incoming client-side full-thread save over the current SQL copy.\n *\n * The browser exports and PUTs the whole assistant-ui repository. If a server\n * completion save lands first, an older browser export can otherwise replace\n * `thread_data` wholesale and delete the assistant message the server just\n * reconstructed from run events. Preserve server-only messages while still\n * accepting client-only messages and metadata.\n */\nexport interface MergeThreadDataOptions {\n preserveExistingQueuedMessages?: boolean;\n preserveExistingTopLevelKeys?: boolean;\n}\n\nexport function mergeThreadDataForClientSave(\n existingRepo: any,\n incomingRepo: any,\n options: MergeThreadDataOptions = {},\n) {\n const preserveExistingQueuedMessages =\n options.preserveExistingQueuedMessages ?? true;\n const preserveExistingTopLevelKeys =\n options.preserveExistingTopLevelKeys ?? true;\n const existingNormalized = normalizeThreadRepository(existingRepo);\n const incomingNormalized = normalizeThreadRepository(incomingRepo);\n const merged =\n incomingNormalized && typeof incomingNormalized === \"object\"\n ? { ...incomingNormalized }\n : {};\n if (\n preserveExistingTopLevelKeys &&\n existingNormalized &&\n typeof existingNormalized === \"object\"\n ) {\n for (const [key, value] of Object.entries(existingNormalized)) {\n if (key === \"messages\" || key === \"headId\") continue;\n if (key === \"queuedMessages\" && !preserveExistingQueuedMessages) {\n continue;\n }\n if (!(key in merged)) {\n merged[key] = value;\n }\n }\n } else if (\n preserveExistingQueuedMessages &&\n existingNormalized &&\n typeof existingNormalized === \"object\" &&\n existingNormalized.queuedMessages !== undefined &&\n merged.queuedMessages === undefined\n ) {\n merged.queuedMessages = existingNormalized.queuedMessages;\n }\n\n const existingMessages = Array.isArray(existingNormalized?.messages)\n ? existingNormalized.messages\n : null;\n const incomingMessages = Array.isArray(merged.messages)\n ? merged.messages\n : null;\n if (!existingMessages || !incomingMessages) return merged;\n\n const incomingKeySets = incomingMessages.map(\n (entry: any) => new Set(messageIdentityKeys(getStoredMessage(entry))),\n );\n const usedIncoming = new Set<number>();\n const nextMessages: any[] = [];\n const idRewrites = new Map<string, string>();\n\n for (const existingEntry of existingMessages) {\n const existingKeys = messageIdentityKeys(getStoredMessage(existingEntry));\n const incomingIndex = incomingKeySets.findIndex(\n (keys, index) =>\n !usedIncoming.has(index) && existingKeys.some((key) => keys.has(key)),\n );\n\n if (incomingIndex === -1) {\n nextMessages.push(existingEntry);\n continue;\n }\n\n usedIncoming.add(incomingIndex);\n const incomingEntry = incomingMessages[incomingIndex];\n const chosen = chooseMergedMessageEntry(existingEntry, incomingEntry);\n const existingId = messageId(getStoredMessage(existingEntry));\n const chosenId = messageId(getStoredMessage(chosen));\n if (existingId && chosenId && existingId !== chosenId) {\n idRewrites.set(existingId, chosenId);\n }\n nextMessages.push(chosen);\n }\n\n for (let index = 0; index < incomingMessages.length; index++) {\n if (!usedIncoming.has(index)) nextMessages.push(incomingMessages[index]);\n }\n\n merged.messages = nextMessages.map((entry) =>\n rewriteEntryParentId(entry, idRewrites),\n );\n return normalizeThreadRepository(merged);\n}\n\nfunction escapeAttachmentAttribute(value: string): string {\n return value.replace(/&/g, \"&\").replace(/\"/g, \""\");\n}\n\nfunction unwrapTextAttachmentEnvelope(text: string): string {\n const match = text.match(\n /^<attachment\\b[^>]*>\\n?([\\s\\S]*?)\\n?<\\/attachment>$/,\n );\n return match ? match[1] : text;\n}\n\nfunction truncateStoredAttachment(text: string): string {\n const unwrapped = unwrapTextAttachmentEnvelope(text);\n if (unwrapped.length <= MAX_STORED_ATTACHMENT_CHARS) return unwrapped;\n const omitted = unwrapped.length - MAX_STORED_ATTACHMENT_CHARS;\n return `${unwrapped.slice(0, MAX_STORED_ATTACHMENT_CHARS)}\\n\\n[Attachment truncated after ${MAX_STORED_ATTACHMENT_CHARS.toLocaleString()} characters; ${omitted.toLocaleString()} characters omitted from persisted chat history.]`;\n}\n\nfunction textAttachmentEnvelope(\n att: AgentChatAttachment,\n text: string,\n): string {\n const attrs = [\n `name=\"${escapeAttachmentAttribute(att.name || \"attachment\")}\"`,\n att.contentType\n ? `contentType=\"${escapeAttachmentAttribute(att.contentType)}\"`\n : null,\n att.type ? `type=\"${escapeAttachmentAttribute(att.type)}\"` : null,\n ].filter(Boolean);\n return `<attachment ${attrs.join(\" \")}>\\n${truncateStoredAttachment(text)}\\n</attachment>`;\n}\n\nfunction buildStoredAttachments(\n attachments: AgentChatAttachment[] | undefined,\n runId: string | undefined,\n): any[] {\n return (attachments ?? [])\n .map((att, index) => {\n const id = `server-${runId ?? Date.now()}-attachment-${index}`;\n if (att.type === \"image\" && att.data) {\n return {\n id,\n type: \"image\",\n name: att.name,\n contentType: att.contentType,\n status: { type: \"complete\" },\n content: [{ type: \"image\", image: att.data }],\n };\n }\n if (att.data) {\n return {\n id,\n type: \"file\",\n name: att.name,\n contentType: att.contentType,\n status: { type: \"complete\" },\n content: [\n {\n type: \"file\",\n data: att.data,\n mimeType: att.contentType,\n filename: att.name,\n },\n ],\n };\n }\n if (typeof att.text === \"string\" && att.text.length > 0) {\n return {\n id,\n type: \"file\",\n name: att.name,\n contentType: att.contentType,\n status: { type: \"complete\" },\n content: [\n { type: \"text\", text: textAttachmentEnvelope(att, att.text) },\n ],\n };\n }\n return null;\n })\n .filter(Boolean);\n}\n\nexport function buildUserMessage(opts: {\n text: string;\n attachments?: AgentChatAttachment[];\n runId?: string;\n createdAt?: Date;\n}): {\n id: string;\n createdAt: Date;\n role: \"user\";\n content: ContentPart[];\n attachments?: any[];\n metadata: Record<string, unknown>;\n} {\n const attachments = buildStoredAttachments(opts.attachments, opts.runId);\n return {\n id: `server-user-${opts.runId ?? Date.now()}`,\n createdAt: opts.createdAt ?? new Date(),\n role: \"user\",\n content: [{ type: \"text\", text: opts.text }],\n ...(attachments.length > 0 ? { attachments } : {}),\n metadata: {\n custom: {\n submittedRunId: opts.runId,\n },\n },\n };\n}\n\nfunction toCoreCodeAgentTranscriptEvent(\n event: CodeAgentThreadTranscriptEvent,\n): CoreCodeAgentTranscriptEvent {\n return {\n schemaVersion: 1,\n id: event.id,\n runId: event.runId,\n kind: (event.kind ??\n event.type ??\n \"status\") as CoreCodeAgentTranscriptEvent[\"kind\"],\n message: event.message ?? event.text ?? \"\",\n createdAt: event.createdAt,\n metadata: {\n ...(event.metadata ?? {}),\n ...(event.artifactPath ? { artifactPath: event.artifactPath } : {}),\n ...(event.artifactUrl ? { artifactUrl: event.artifactUrl } : {}),\n },\n };\n}\n\nfunction contentPartForCodeAgentTranscriptItem(\n item: NormalizedCodeAgentTranscriptItem,\n options: BuildRepositoryFromCodeAgentTranscriptOptions,\n): ContentPart | null {\n if (item.type === \"assistant\") {\n return item.text.trim() ? { type: \"text\", text: item.text } : null;\n }\n if (item.type === \"tool\") {\n return toolContentPartForCodeAgentTranscriptItem(item);\n }\n if (item.type === \"status\") {\n const text = statusTextForCodeAgentTranscriptItem(item, options);\n return text ? { type: \"text\", text } : null;\n }\n return null;\n}\n\nfunction toolContentPartForCodeAgentTranscriptItem(\n item: NormalizedCodeAgentToolEvent,\n): ContentPart {\n return {\n type: \"tool-call\",\n toolCallId: `code-tool-${item.id}`,\n toolName: item.tool ?? item.label ?? \"code-agent\",\n argsText: previewCodeAgentTranscriptValue(item.input) ?? \"\",\n args: recordArgsForCodeAgentTool(item.input),\n ...(item.result !== undefined\n ? { result: previewCodeAgentTranscriptValue(item.result) ?? \"\" }\n : {}),\n };\n}\n\nfunction statusTextForCodeAgentTranscriptItem(\n item: NormalizedCodeAgentStatusEvent,\n options: BuildRepositoryFromCodeAgentTranscriptOptions,\n): string | null {\n if (options.hideCredentialMessages && isCredentialCodeAgentText(item.text)) {\n return null;\n }\n if (item.statusKind === \"artifact\") {\n const event = item.events[0];\n const path =\n stringRecordValue(event?.metadata, \"artifactPath\") ??\n stringRecordValue(event?.metadata, \"path\");\n const url = stringRecordValue(event?.metadata, \"artifactUrl\");\n const target = url ?? path;\n return target\n ? `Artifact: ${item.text}\\n${target}`\n : `Artifact: ${item.text}`;\n }\n if (item.level === \"info\" && item.statusKind !== \"note\") return null;\n return item.text;\n}\n\nfunction codeAgentAttachmentsFromEvents(\n events: readonly CoreCodeAgentTranscriptEvent[],\n): AgentChatAttachment[] {\n for (const event of events) {\n const raw = event.metadata?.attachments;\n if (!Array.isArray(raw) || raw.length === 0) continue;\n const attachments: AgentChatAttachment[] = [];\n for (const item of raw) {\n if (!item || typeof item !== \"object\") continue;\n const record = item as Record<string, unknown>;\n const name = stringRecordValue(record, \"name\");\n if (!name) continue;\n const contentType = stringRecordValue(record, \"type\");\n const text = stringRecordValue(record, \"text\");\n const dataUrl = stringRecordValue(record, \"dataUrl\");\n attachments.push({\n type: dataUrl ? \"image\" : \"file\",\n name,\n ...(contentType ? { contentType } : {}),\n ...(text ? { text } : {}),\n ...(dataUrl ? { data: dataUrl } : {}),\n });\n }\n if (attachments.length > 0) return attachments;\n }\n return [];\n}\n\nfunction recordArgsForCodeAgentTool(value: unknown): Record<string, string> {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return {};\n const result: Record<string, string> = {};\n for (const [key, entry] of Object.entries(value)) {\n result[key] =\n typeof entry === \"string\"\n ? entry\n : (previewCodeAgentTranscriptValue(entry) ?? \"\");\n }\n return result;\n}\n\nfunction previewCodeAgentTranscriptValue(value: unknown): string | undefined {\n if (value === undefined || value === null) return undefined;\n const text =\n typeof value === \"string\" ? value : (JSON.stringify(value, null, 2) ?? \"\");\n const trimmed = text.trim();\n if (!trimmed) return undefined;\n return trimmed.length > 4000 ? `${trimmed.slice(0, 4000)}\\n...` : trimmed;\n}\n\nfunction stringRecordValue(\n record: Record<string, unknown> | undefined,\n key: string,\n): string | undefined {\n const value = record?.[key];\n return typeof value === \"string\" && value.trim() ? value.trim() : undefined;\n}\n\nfunction isCredentialCodeAgentText(value: string): boolean {\n return /No LLM provider key was found|Missing credentials/i.test(value);\n}\n\nexport function upsertUserMessage(repo: any, userMsg: UserMessage): any {\n const nextRepo = normalizeThreadRepository(repo);\n\n const lastIndex = nextRepo.messages.length - 1;\n const lastEntry = lastIndex >= 0 ? nextRepo.messages[lastIndex] : undefined;\n const lastMsg = getStoredMessage(lastEntry);\n if (lastMsg?.role === \"user\" && messagesMatch(lastMsg, userMsg)) {\n return nextRepo;\n }\n\n const parentId =\n lastIndex >= 0 ? (messageId(getStoredMessage(lastEntry)) ?? null) : null;\n nextRepo.messages.push({ message: userMsg, parentId });\n nextRepo.headId = userMsg.id;\n return nextRepo;\n}\n\nfunction shouldReplaceLastAssistant(\n lastMessage: any,\n assistantMsg: AssistantMessage,\n): boolean {\n const lastContent = lastMessage?.content;\n if (messageContentIsEmpty(lastContent)) return true;\n\n const lastRunId = getMessageRunId(lastMessage);\n const nextRunId = getMessageRunId(assistantMsg);\n if (lastRunId && nextRunId && lastRunId === nextRunId) return true;\n if (lastRunId && nextRunId && lastRunId !== nextRunId) return false;\n\n const lastStatus = lastMessage?.status;\n if (lastStatus && !isTerminalAssistantStatus(lastStatus)) return true;\n\n try {\n if (JSON.stringify(lastContent) === JSON.stringify(assistantMsg.content)) {\n return true;\n }\n } catch {\n // Fall through to the text-prefix check.\n }\n\n const lastText = messageText(lastContent).trim();\n const nextText = messageText(assistantMsg.content).trim();\n if (isTerminalAssistantStatus(lastStatus)) return false;\n return Boolean(lastText && nextText && nextText.startsWith(lastText));\n}\n\n/**\n * Merge the server-reconstructed assistant message into persisted\n * assistant-ui thread data.\n *\n * The browser periodically saves thread data while a run is still streaming.\n * That can leave the last assistant message non-empty but partial/pending.\n * Completion must replace that same-run partial message instead of treating\n * any assistant content as proof that the frontend already saved the final\n * turn.\n */\nexport function upsertAssistantMessage(\n repo: any,\n assistantMsg: AssistantMessage,\n): any {\n const nextRepo = normalizeThreadRepository(repo);\n\n const lastIndex = nextRepo.messages.length - 1;\n const lastEntry = lastIndex >= 0 ? nextRepo.messages[lastIndex] : undefined;\n const lastMsg = getStoredMessage(lastEntry);\n const lastRole = lastMsg?.role;\n\n if (\n lastRole === \"assistant\" &&\n shouldReplaceLastAssistant(lastMsg, assistantMsg)\n ) {\n nextRepo.messages[lastIndex] = { ...lastEntry, message: assistantMsg };\n nextRepo.headId = assistantMsg.id;\n return nextRepo;\n }\n\n const parentId =\n nextRepo.messages.length > 0\n ? (messageId(\n getStoredMessage(nextRepo.messages[nextRepo.messages.length - 1]),\n ) ?? null)\n : null;\n nextRepo.messages.push({ message: assistantMsg, parentId });\n nextRepo.headId = assistantMsg.id;\n return nextRepo;\n}\n\nfunction turnIdOf(message: any): string | undefined {\n const t = message?.metadata?.custom?.turnId;\n return typeof t === \"string\" && t ? t : undefined;\n}\n\nfunction foldedRunIdsOf(message: any): string[] {\n const ids = message?.metadata?.custom?.foldedRunIds;\n return Array.isArray(ids)\n ? ids.filter((x: unknown): x is string => typeof x === \"string\")\n : [];\n}\n\n/** Rough size of an assistant message's content, used only to pick the larger\n * of two representations of the same chunk so a fold can never shrink. */\nfunction assistantContentWeight(content: unknown): number {\n if (!Array.isArray(content)) return 0;\n let weight = 0;\n for (const part of content) {\n if (part?.type === \"text\" && typeof part.text === \"string\") {\n weight += part.text.length;\n } else {\n weight += 1;\n }\n }\n return weight;\n}\n\n/** Concatenate continuation content onto the accumulated turn, merging a\n * trailing+leading text run so the resumed answer reads as one flowing\n * message rather than two stacked fragments. */\nfunction appendFoldedContent(existing: any[], incoming: any[]): any[] {\n const merged = existing.map((p) => ({ ...p }));\n for (const part of incoming) {\n const last = merged[merged.length - 1];\n if (\n part?.type === \"text\" &&\n typeof part.text === \"string\" &&\n last?.type === \"text\" &&\n typeof last.text === \"string\"\n ) {\n last.text = `${last.text}${part.text}`;\n } else {\n merged.push({ ...part });\n }\n }\n return merged;\n}\n\n/**\n * Fold a continuation run's assistant message onto the single durable message\n * for its logical turn (identified by `turnId`), so a turn that spans several\n * continuation runs accumulates into ONE message that only ever grows. This is\n * the server-side analog of an append-only rollout: the durable transcript is\n * a monotonic fold over every run in the turn, never a per-run snapshot that\n * drops the earlier chunks.\n *\n * Idempotent and never-shrinking, so it is safe to run alongside the client's\n * full-thread export (which may write the same turn from the other side):\n * - First chunk of a turn → appended as a fresh message.\n * - A run whose content is already represented (already folded, or the client\n * saved it) → kept as-is, choosing whichever copy has more content.\n * - A new chunk → appended onto the accumulated turn.\n * Falls back to per-run upsert when no `turnId` is available (turn == run).\n */\nexport function foldAssistantTurn(\n repo: any,\n assistantMsg: AssistantMessage,\n options: { turnId?: string; runId?: string },\n): any {\n const turnId = options.turnId;\n const runId = options.runId;\n if (!turnId) return upsertAssistantMessage(repo, assistantMsg);\n\n const nextRepo = normalizeThreadRepository(repo);\n const lastIndex = nextRepo.messages.length - 1;\n const lastEntry = lastIndex >= 0 ? nextRepo.messages[lastIndex] : undefined;\n const lastMsg = getStoredMessage(lastEntry);\n\n const sameTurn =\n lastMsg?.role === \"assistant\" &&\n (turnIdOf(lastMsg) === turnId ||\n // A message the client wrote for one of this turn's runs before it\n // carried a turnId stamp.\n (!!runId && getMessageRunId(lastMsg) === runId));\n\n if (!sameTurn) {\n // First chunk of this turn (or the previous assistant belongs to an\n // earlier turn) — append as a fresh message; buildAssistantMessage already\n // stamped turnId + foldedRunIds onto it.\n return upsertAssistantMessage(repo, assistantMsg);\n }\n\n const existingContent = Array.isArray(lastMsg.content) ? lastMsg.content : [];\n const incomingContent = Array.isArray(assistantMsg.content)\n ? assistantMsg.content\n : [];\n const existingFolded = foldedRunIdsOf(lastMsg);\n const runAlreadyFolded =\n !!runId &&\n (existingFolded.includes(runId) || getMessageRunId(lastMsg) === runId);\n\n // If this run's chunk is already represented in the turn (the client saved\n // it, or we already folded it), do not re-append — keep the larger copy so\n // the turn never shrinks. Otherwise fold this chunk onto the accumulated turn.\n const mergedContent = runAlreadyFolded\n ? assistantContentWeight(incomingContent) >\n assistantContentWeight(existingContent)\n ? incomingContent\n : existingContent\n : appendFoldedContent(existingContent, incomingContent);\n\n const mergedFolded = Array.from(\n new Set([...existingFolded, ...(runId ? [runId] : [])]),\n );\n\n const existingCustom =\n lastMsg.metadata?.custom && typeof lastMsg.metadata.custom === \"object\"\n ? (lastMsg.metadata.custom as Record<string, unknown>)\n : {};\n const incomingCustom =\n assistantMsg.metadata?.custom &&\n typeof assistantMsg.metadata.custom === \"object\"\n ? (assistantMsg.metadata.custom as Record<string, unknown>)\n : {};\n\n const mergedCustom: Record<string, unknown> = {\n ...existingCustom,\n ...incomingCustom,\n turnId,\n foldedRunIds: mergedFolded,\n };\n // Only the freshest chunk decides whether the turn is still continuing.\n if (incomingCustom.continued !== true) delete mergedCustom.continued;\n\n const mergedMessage = {\n ...lastMsg,\n content: mergedContent,\n // The freshest chunk's status wins: a clean done supersedes a prior\n // partial; a real error supersedes a partial.\n status: assistantMsg.status ?? lastMsg.status,\n metadata: {\n ...lastMsg.metadata,\n runId: runId ?? lastMsg.metadata?.runId,\n custom: mergedCustom,\n },\n };\n\n nextRepo.messages[lastIndex] = { ...lastEntry, message: mergedMessage };\n nextRepo.headId = mergedMessage.id ?? nextRepo.headId;\n return nextRepo;\n}\n\nexport function normalizeThreadTitle(value: unknown): string {\n if (typeof value !== \"string\") return \"\";\n return value.replace(/\\s+/g, \" \").trim().slice(0, 160);\n}\n\n/**\n * Extract title and preview from a thread runtime export.\n * Isomorphic — works on both server and client.\n */\nexport function extractThreadMeta(repo: any): {\n title: string;\n preview: string;\n} {\n const titleOverride = normalizeThreadTitle(repo?._titleOverride);\n const msgs = repo?.messages;\n if (!Array.isArray(msgs) || msgs.length === 0)\n return { title: titleOverride, preview: \"\" };\n\n let title = \"\";\n let preview = \"\";\n for (const entry of msgs) {\n // Support both wrapped ({ message: { role, content } }) and flat ({ role, content }) formats\n const msg = entry?.message ?? entry;\n if (msg.role !== \"user\") continue;\n const textParts = Array.isArray(msg.content)\n ? msg.content\n .filter((p: any) => p.type === \"text\")\n .map((p: any) => p.text)\n .join(\" \")\n : typeof msg.content === \"string\"\n ? msg.content\n : \"\";\n if (textParts.trim()) {\n if (!title) title = textParts.trim().slice(0, 80);\n preview = textParts.trim().slice(0, 120);\n }\n }\n return { title: titleOverride || title, preview };\n}\n"]}
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -97,6 +97,14 @@ export interface AgentChatRequest {
|
|
|
97
97
|
attachments?: AgentChatAttachment[];
|
|
98
98
|
/** Internal retry/continuation requests should not create visible user turns. */
|
|
99
99
|
internalContinuation?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Stable identity for the logical assistant turn this request belongs to.
|
|
102
|
+
* The client sends the SAME turnId for the initial POST and every
|
|
103
|
+
* auto-continuation re-POST of one turn, so the server can fold each
|
|
104
|
+
* continuation run's output onto a single durable assistant message instead
|
|
105
|
+
* of dropping the earlier chunks. Defaults to the run id when absent.
|
|
106
|
+
*/
|
|
107
|
+
turnId?: string;
|
|
100
108
|
/** Execution mode for this turn. Plan mode is read-only and proposes before acting. */
|
|
101
109
|
mode?: "act" | "plan";
|
|
102
110
|
/** Per-request model override (ephemeral, from the composer model picker). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ag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,0EAA0E;IAC1E,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GACD;IAAE,IAAI,EAAE,iBAAiB,CAAA;CAAE,GAC3B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9C;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EACF,aAAa,GACb,YAAY,GACZ,aAAa,GACb,cAAc,GACd,iBAAiB,GACjB,qBAAqB,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GACD;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtB,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,cAAc,CAAC;CACvB;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC"}
|
package/dist/agent/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport type { AgentMcpAppPayload } from \"../mcp-client/app-result.js\";\n\nexport interface ActionTool {\n description: string;\n parameters?: {\n type: \"object\";\n properties: Record<\n string,\n {\n type: string;\n description?: string;\n enum?: string[];\n }\n >;\n required?: string[];\n };\n}\n\n/** @deprecated Use `ActionTool` instead */\nexport type ScriptTool = ActionTool;\n\nexport interface AgentMessage {\n role: \"user\" | \"assistant\";\n content: string;\n}\n\nexport type AgentChatStructuredContentPart =\n | { type: \"text\"; text: string }\n | {\n type: \"tool-call\";\n id?: string;\n toolCallId?: string;\n name?: string;\n toolName?: string;\n input?: unknown;\n args?: unknown;\n }\n | {\n type: \"tool-result\";\n toolCallId: string;\n /** Persisted for replay; omitted in older rows is backfilled server-side. */\n toolName?: string;\n toolInput?: string;\n content: string;\n isError?: boolean;\n };\n\nexport interface AgentChatStructuredMessage {\n role: \"user\" | \"assistant\";\n content: AgentChatStructuredContentPart[];\n}\n\nexport interface AgentChatReference {\n type: \"file\" | \"skill\" | \"mention\" | \"agent\" | \"custom-agent\";\n path: string;\n name: string;\n source: string;\n refType?: string;\n refId?: string;\n}\n\nexport interface MentionProviderItem {\n id: string;\n label: string;\n description?: string;\n icon?: string;\n refType: string;\n refId?: string;\n refPath?: string;\n}\n\nexport interface MentionProvider {\n label: string;\n icon?: string;\n search: (\n query: string,\n /** The H3 event for the current request — use to make internal API calls */\n event?: any,\n ) => MentionProviderItem[] | Promise<MentionProviderItem[]>;\n}\n\nexport interface AgentChatAttachment {\n type: string;\n name: string;\n data?: string;\n contentType?: string;\n text?: string;\n}\n\nexport interface AgentChatScope {\n type: string;\n id: string;\n label?: string;\n}\n\nexport interface AgentChatRequest {\n message: string;\n /**\n * User-visible text to persist in chat history. `message` may be normalized\n * for the model (for example mention markup or internal continuation text).\n */\n displayMessage?: string;\n history?: AgentMessage[];\n /**\n * Provider-neutral transcript used for run recovery. Unlike `history`,\n * this preserves assistant tool calls and matching tool results so\n * continuation turns do not re-run completed read-only tools.\n */\n structuredHistory?: AgentChatStructuredMessage[];\n references?: AgentChatReference[];\n threadId?: string;\n attachments?: AgentChatAttachment[];\n /** Internal retry/continuation requests should not create visible user turns. */\n internalContinuation?: boolean;\n /** Execution mode for this turn. Plan mode is read-only and proposes before acting. */\n mode?: \"act\" | \"plan\";\n /** Per-request model override (ephemeral, from the composer model picker). */\n model?: string;\n /** Per-request engine override (sent alongside model for cross-provider switches). */\n engine?: string;\n /** Per-request reasoning effort override (ephemeral, from the composer picker). */\n effort?: ReasoningEffort;\n /** Usage-tracking label for this call (e.g. \"chat\", \"summarize\"). Default: \"chat\". */\n usageLabel?: string;\n /** Stable browser tab id so screen/url context and navigation commands are tab-scoped. */\n browserTabId?: string;\n /** Resource scope for this chat thread, e.g. the deck currently bound to the tab. */\n scope?: AgentChatScope | null;\n}\n\nexport type AgentChatEvent =\n | { type: \"text\"; text: string }\n | { type: \"activity\"; label: string; tool?: string }\n | { type: \"tool_start\"; tool: string; input: Record<string, string> }\n | {\n type: \"tool_done\";\n tool: string;\n result: string;\n mcpApp?: AgentMcpAppPayload;\n }\n | {\n type: \"agent_call\";\n agent: string;\n status: \"start\" | \"done\" | \"error\";\n }\n | { type: \"agent_call_text\"; agent: string; text: string }\n | {\n type: \"agent_task\";\n taskId: string;\n threadId: string;\n description: string;\n status: \"running\" | \"completed\" | \"errored\";\n }\n | {\n type: \"agent_task_update\";\n taskId: string;\n preview: string;\n currentStep?: string;\n }\n | {\n type: \"agent_task_complete\";\n taskId: string;\n summary: string;\n }\n | { type: \"done\" }\n | {\n type: \"error\";\n error: string;\n /**\n * Optional machine-readable error code. Builder gateway uses codes\n * like \"credits-limit-monthly\" / \"unauthorized\" / \"gateway_not_enabled\"\n * so the chat UI can render a structured CTA (e.g. upgrade button).\n */\n errorCode?: string;\n /** Optional link paired with errorCode — e.g. Builder billing page. */\n upgradeUrl?: string;\n /** Optional details for expandable UI/debugging. */\n details?: string;\n /** True when the user can reasonably continue/retry from partial work. */\n recoverable?: boolean;\n }\n | { type: \"missing_api_key\" }\n | { type: \"loop_limit\"; maxIterations?: number }\n | {\n type: \"auto_continue\";\n reason:\n | \"run_timeout\"\n | \"loop_limit\"\n | \"no_progress\"\n | \"stream_ended\"\n | \"gateway_timeout\"\n | \"network_interrupted\";\n maxIterations?: number;\n }\n | { type: \"clear\" };\n\nexport interface RunEvent {\n seq: number;\n event: AgentChatEvent;\n}\n\nexport type RunStatus = \"running\" | \"completed\" | \"errored\" | \"aborted\";\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReasoningEffort } from \"../shared/reasoning-effort.js\";\nimport type { AgentMcpAppPayload } from \"../mcp-client/app-result.js\";\n\nexport interface ActionTool {\n description: string;\n parameters?: {\n type: \"object\";\n properties: Record<\n string,\n {\n type: string;\n description?: string;\n enum?: string[];\n }\n >;\n required?: string[];\n };\n}\n\n/** @deprecated Use `ActionTool` instead */\nexport type ScriptTool = ActionTool;\n\nexport interface AgentMessage {\n role: \"user\" | \"assistant\";\n content: string;\n}\n\nexport type AgentChatStructuredContentPart =\n | { type: \"text\"; text: string }\n | {\n type: \"tool-call\";\n id?: string;\n toolCallId?: string;\n name?: string;\n toolName?: string;\n input?: unknown;\n args?: unknown;\n }\n | {\n type: \"tool-result\";\n toolCallId: string;\n /** Persisted for replay; omitted in older rows is backfilled server-side. */\n toolName?: string;\n toolInput?: string;\n content: string;\n isError?: boolean;\n };\n\nexport interface AgentChatStructuredMessage {\n role: \"user\" | \"assistant\";\n content: AgentChatStructuredContentPart[];\n}\n\nexport interface AgentChatReference {\n type: \"file\" | \"skill\" | \"mention\" | \"agent\" | \"custom-agent\";\n path: string;\n name: string;\n source: string;\n refType?: string;\n refId?: string;\n}\n\nexport interface MentionProviderItem {\n id: string;\n label: string;\n description?: string;\n icon?: string;\n refType: string;\n refId?: string;\n refPath?: string;\n}\n\nexport interface MentionProvider {\n label: string;\n icon?: string;\n search: (\n query: string,\n /** The H3 event for the current request — use to make internal API calls */\n event?: any,\n ) => MentionProviderItem[] | Promise<MentionProviderItem[]>;\n}\n\nexport interface AgentChatAttachment {\n type: string;\n name: string;\n data?: string;\n contentType?: string;\n text?: string;\n}\n\nexport interface AgentChatScope {\n type: string;\n id: string;\n label?: string;\n}\n\nexport interface AgentChatRequest {\n message: string;\n /**\n * User-visible text to persist in chat history. `message` may be normalized\n * for the model (for example mention markup or internal continuation text).\n */\n displayMessage?: string;\n history?: AgentMessage[];\n /**\n * Provider-neutral transcript used for run recovery. Unlike `history`,\n * this preserves assistant tool calls and matching tool results so\n * continuation turns do not re-run completed read-only tools.\n */\n structuredHistory?: AgentChatStructuredMessage[];\n references?: AgentChatReference[];\n threadId?: string;\n attachments?: AgentChatAttachment[];\n /** Internal retry/continuation requests should not create visible user turns. */\n internalContinuation?: boolean;\n /**\n * Stable identity for the logical assistant turn this request belongs to.\n * The client sends the SAME turnId for the initial POST and every\n * auto-continuation re-POST of one turn, so the server can fold each\n * continuation run's output onto a single durable assistant message instead\n * of dropping the earlier chunks. Defaults to the run id when absent.\n */\n turnId?: string;\n /** Execution mode for this turn. Plan mode is read-only and proposes before acting. */\n mode?: \"act\" | \"plan\";\n /** Per-request model override (ephemeral, from the composer model picker). */\n model?: string;\n /** Per-request engine override (sent alongside model for cross-provider switches). */\n engine?: string;\n /** Per-request reasoning effort override (ephemeral, from the composer picker). */\n effort?: ReasoningEffort;\n /** Usage-tracking label for this call (e.g. \"chat\", \"summarize\"). Default: \"chat\". */\n usageLabel?: string;\n /** Stable browser tab id so screen/url context and navigation commands are tab-scoped. */\n browserTabId?: string;\n /** Resource scope for this chat thread, e.g. the deck currently bound to the tab. */\n scope?: AgentChatScope | null;\n}\n\nexport type AgentChatEvent =\n | { type: \"text\"; text: string }\n | { type: \"activity\"; label: string; tool?: string }\n | { type: \"tool_start\"; tool: string; input: Record<string, string> }\n | {\n type: \"tool_done\";\n tool: string;\n result: string;\n mcpApp?: AgentMcpAppPayload;\n }\n | {\n type: \"agent_call\";\n agent: string;\n status: \"start\" | \"done\" | \"error\";\n }\n | { type: \"agent_call_text\"; agent: string; text: string }\n | {\n type: \"agent_task\";\n taskId: string;\n threadId: string;\n description: string;\n status: \"running\" | \"completed\" | \"errored\";\n }\n | {\n type: \"agent_task_update\";\n taskId: string;\n preview: string;\n currentStep?: string;\n }\n | {\n type: \"agent_task_complete\";\n taskId: string;\n summary: string;\n }\n | { type: \"done\" }\n | {\n type: \"error\";\n error: string;\n /**\n * Optional machine-readable error code. Builder gateway uses codes\n * like \"credits-limit-monthly\" / \"unauthorized\" / \"gateway_not_enabled\"\n * so the chat UI can render a structured CTA (e.g. upgrade button).\n */\n errorCode?: string;\n /** Optional link paired with errorCode — e.g. Builder billing page. */\n upgradeUrl?: string;\n /** Optional details for expandable UI/debugging. */\n details?: string;\n /** True when the user can reasonably continue/retry from partial work. */\n recoverable?: boolean;\n }\n | { type: \"missing_api_key\" }\n | { type: \"loop_limit\"; maxIterations?: number }\n | {\n type: \"auto_continue\";\n reason:\n | \"run_timeout\"\n | \"loop_limit\"\n | \"no_progress\"\n | \"stream_ended\"\n | \"gateway_timeout\"\n | \"network_interrupted\";\n maxIterations?: number;\n }\n | { type: \"clear\" };\n\nexport interface RunEvent {\n seq: number;\n event: AgentChatEvent;\n}\n\nexport type RunStatus = \"running\" | \"completed\" | \"errored\" | \"aborted\";\n"]}
|
|
@@ -15,7 +15,7 @@ export interface OpenSourceBadgeProps {
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function PoweredByBadge({ position, }: PoweredByBadgeProps): import("react/jsx-runtime").JSX.Element;
|
|
17
17
|
/**
|
|
18
|
-
* Small GitHub badge: "
|
|
18
|
+
* Small GitHub badge: "100% free and open source"
|
|
19
19
|
*
|
|
20
20
|
* Intended to pair with PoweredByBadge on public pages.
|
|
21
21
|
*/
|
|
@@ -113,7 +113,7 @@ export function PoweredByBadge({ position = "bottom-right", }) {
|
|
|
113
113
|
` }), _jsxs("a", { href: "https://agent-native.com", target: "_blank", rel: "noopener noreferrer", className: "an-powered-badge", style: containerStyle(position), "aria-label": "Built with Agent Native", children: [_jsx("span", { children: "Built with" }), _jsx("img", { src: logoOnLight, alt: "Agent Native", className: "an-powered-logo an-powered-logo-light" }), _jsx("img", { src: logoOnDark, alt: "Agent Native", className: "an-powered-logo an-powered-logo-dark" })] })] }));
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
|
-
* Small GitHub badge: "
|
|
116
|
+
* Small GitHub badge: "100% free and open source"
|
|
117
117
|
*
|
|
118
118
|
* Intended to pair with PoweredByBadge on public pages.
|
|
119
119
|
*/
|
|
@@ -168,6 +168,6 @@ export function OpenSourceBadge({ position = "bottom-left", }) {
|
|
|
168
168
|
.light .an-open-source-badge:hover {
|
|
169
169
|
color: rgba(70, 70, 70, 1) !important;
|
|
170
170
|
}
|
|
171
|
-
` }), _jsxs("a", { href: "https://github.com/BuilderIO/agent-native", target: "_blank", rel: "noopener noreferrer", className: "an-open-source-badge", style: containerStyle(position), children: [_jsx(IconBrandGithub, { "aria-hidden": "true", stroke: 1.8 }), _jsx("span", { children: "
|
|
171
|
+
` }), _jsxs("a", { href: "https://github.com/BuilderIO/agent-native", target: "_blank", rel: "noopener noreferrer", className: "an-open-source-badge", style: containerStyle(position), children: [_jsx(IconBrandGithub, { "aria-hidden": "true", stroke: 1.8 }), _jsx("span", { children: "100% free and open source" })] })] }));
|
|
172
172
|
}
|
|
173
173
|
//# sourceMappingURL=PoweredByBadge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PoweredByBadge.js","sourceRoot":"","sources":["../../src/client/PoweredByBadge.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAUxC,MAAM,cAAc,GAAG,CACrB,QAAwC,EACzB,EAAE,CAAC,CAAC;IACnB,QAAQ,EAAE,OAAO;IACjB,MAAM,EAAE,EAAE;IACV,GAAG,CAAC,QAAQ,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAC/D,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,QAAQ;IACpB,GAAG,EAAE,CAAC;IACN,OAAO,EAAE,UAAU;IACnB,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,EAAE;IACZ,UAAU,EACR,mEAAmE;IACrE,UAAU,EAAE,GAAG;IACf,UAAU,EAAE,CAAC;IACb,KAAK,EAAE,wBAAwB;IAC/B,UAAU,EAAE,qBAAqB;IACjC,cAAc,EAAE,WAAW;IAC3B,oBAAoB,EAAE,WAAW;IACjC,MAAM,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;;;;;;;;;iBAYT,SAAS;;;;;;;;;;;OAWnB,GAAS,EACV,aACE,IAAI,EAAC,2CAA2C,EAChD,MAAM,EAAC,QAAQ,EACf,GAAG,EAAC,qBAAqB,EACzB,SAAS,EAAC,sBAAsB,EAChC,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,aAE/B,KAAC,eAAe,mBAAa,MAAM,EAAC,MAAM,EAAE,GAAG,GAAI,EACnD,uDAAsC,IACpC,IACH,CACJ,CAAC;AACJ,CAAC","sourcesContent":["import type { CSSProperties } from \"react\";\nimport { IconBrandGithub } from \"@tabler/icons-react\";\nimport { appPath } from \"./api-path.js\";\n\nexport interface PoweredByBadgeProps {\n position?: \"bottom-right\" | \"bottom-left\";\n}\n\nexport interface OpenSourceBadgeProps {\n position?: \"bottom-left\" | \"bottom-right\";\n}\n\nconst containerStyle = (\n position: \"bottom-right\" | \"bottom-left\",\n): CSSProperties => ({\n position: \"fixed\",\n bottom: 16,\n ...(position === \"bottom-right\" ? { right: 16 } : { left: 16 }),\n zIndex: 50,\n display: \"flex\",\n alignItems: \"center\",\n gap: 6,\n padding: \"6px 12px\",\n borderRadius: 8,\n fontSize: 12,\n fontFamily:\n '-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif',\n fontWeight: 500,\n lineHeight: 1,\n color: \"rgba(95, 95, 95, 0.95)\",\n background: \"rgba(0, 0, 0, 0.05)\",\n backdropFilter: \"blur(8px)\",\n WebkitBackdropFilter: \"blur(8px)\",\n border: \"1px solid rgba(0, 0, 0, 0.06)\",\n textDecoration: \"none\",\n transition: \"opacity 0.2s, color 0.2s\",\n opacity: 0.82,\n});\n\nconst darkQuery = \"(prefers-color-scheme: dark)\";\n\n/**\n * Small branding badge: \"Built with [Agent Native logo]\"\n *\n * - Fixed position in the corner\n * - Subtle, semi-transparent\n * - Links to https://agent-native.com\n * - Respects prefers-color-scheme\n * - Can be hidden via HIDE_BRANDING=true env var (for white-label)\n */\nexport function PoweredByBadge({\n position = \"bottom-right\",\n}: PoweredByBadgeProps) {\n // Allow hiding via env var\n const hidden =\n (import.meta.env as Record<string, string | undefined>)\n ?.VITE_HIDE_BRANDING === \"true\";\n\n if (hidden) return null;\n\n const logoOnLight = appPath(\"/agent-native-logo-light.svg\");\n const logoOnDark = appPath(\"/agent-native-logo-dark.svg\");\n\n return (\n <>\n <style>{`\n .an-powered-logo {\n display: block;\n height: 14px;\n width: auto;\n flex: none;\n }\n .an-powered-logo-dark {\n display: none;\n }\n @media (max-width: 640px) {\n .an-powered-badge {\n position: static !important;\n margin: 0.75rem auto 0 !important;\n width: max-content;\n max-width: calc(100vw - 2rem);\n }\n }\n .dark .an-powered-badge {\n background: rgba(255, 255, 255, 0.06) !important;\n border-color: rgba(255, 255, 255, 0.08) !important;\n color: rgba(215, 215, 215, 0.94) !important;\n }\n .dark .an-powered-logo-light {\n display: none;\n }\n .dark .an-powered-logo-dark {\n display: block;\n }\n @media ${darkQuery} {\n .an-powered-badge {\n background: rgba(255, 255, 255, 0.06) !important;\n border-color: rgba(255, 255, 255, 0.08) !important;\n color: rgba(215, 215, 215, 0.94) !important;\n }\n .an-powered-logo-light {\n display: none;\n }\n .an-powered-logo-dark {\n display: block;\n }\n }\n .light .an-powered-badge {\n background: rgba(0, 0, 0, 0.05) !important;\n border-color: rgba(0, 0, 0, 0.06) !important;\n color: rgba(95, 95, 95, 0.95) !important;\n }\n .light .an-powered-logo-light {\n display: block;\n }\n .light .an-powered-logo-dark {\n display: none;\n }\n .an-powered-badge:hover {\n opacity: 1 !important;\n color: rgba(70, 70, 70, 1) !important;\n }\n @media ${darkQuery} {\n .an-powered-badge:hover {\n color: rgba(238, 238, 238, 1) !important;\n }\n }\n .dark .an-powered-badge:hover {\n color: rgba(238, 238, 238, 1) !important;\n }\n .light .an-powered-badge:hover {\n color: rgba(70, 70, 70, 1) !important;\n }\n `}</style>\n <a\n href=\"https://agent-native.com\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"an-powered-badge\"\n style={containerStyle(position)}\n aria-label=\"Built with Agent Native\"\n >\n <span>Built with</span>\n <img\n src={logoOnLight}\n alt=\"Agent Native\"\n className=\"an-powered-logo an-powered-logo-light\"\n />\n <img\n src={logoOnDark}\n alt=\"Agent Native\"\n className=\"an-powered-logo an-powered-logo-dark\"\n />\n </a>\n </>\n );\n}\n\n/**\n * Small GitHub badge: \"100% free and open source\"\n *\n * Intended to pair with PoweredByBadge on public pages.\n */\nexport function OpenSourceBadge({\n position = \"bottom-left\",\n}: OpenSourceBadgeProps) {\n const hidden =\n (import.meta.env as Record<string, string | undefined>)\n ?.VITE_HIDE_BRANDING === \"true\";\n\n if (hidden) return null;\n\n return (\n <>\n <style>{`\n .an-open-source-badge svg {\n width: 15px;\n height: 15px;\n flex: none;\n }\n .an-open-source-badge {\n background: transparent !important;\n border-color: transparent !important;\n backdrop-filter: none !important;\n -webkit-backdrop-filter: none !important;\n }\n @media (max-width: 640px) {\n .an-open-source-badge {\n position: static !important;\n margin: 1rem auto 0 !important;\n width: max-content;\n max-width: calc(100vw - 2rem);\n }\n }\n .dark .an-open-source-badge {\n color: rgba(215, 215, 215, 0.94) !important;\n }\n @media ${darkQuery} {\n .an-open-source-badge {\n color: rgba(215, 215, 215, 0.94) !important;\n }\n }\n .light .an-open-source-badge {\n color: rgba(95, 95, 95, 0.95) !important;\n }\n .an-open-source-badge:hover {\n opacity: 1 !important;\n color: rgba(70, 70, 70, 1) !important;\n }\n @media ${darkQuery} {\n .an-open-source-badge:hover {\n color: rgba(238, 238, 238, 1) !important;\n }\n }\n .dark .an-open-source-badge:hover {\n color: rgba(238, 238, 238, 1) !important;\n }\n .light .an-open-source-badge:hover {\n color: rgba(70, 70, 70, 1) !important;\n }\n `}</style>\n <a\n href=\"https://github.com/BuilderIO/agent-native\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"an-open-source-badge\"\n style={containerStyle(position)}\n >\n <IconBrandGithub aria-hidden=\"true\" stroke={1.8} />\n <span>100% free and open source</span>\n </a>\n </>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-chat-adapter.d.ts","sourceRoot":"","sources":["../../src/client/agent-chat-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAsB,MAAM,qBAAqB,CAAC;AAgBhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAKrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,MAAM,oBAAoB;AAC9B;;;;GAIG;AACD,KAAK;AACP,0EAA0E;GACxE,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-chat-adapter.d.ts","sourceRoot":"","sources":["../../src/client/agent-chat-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAsB,MAAM,qBAAqB,CAAC;AAgBhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAKrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,MAAM,oBAAoB;AAC9B;;;;GAIG;AACD,KAAK;AACP,0EAA0E;GACxE,WAAW,CAAC;AAw0BhB;;;;GAIG;AACH;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAC3C,SAAS,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IAC5C,SAAS,CAAC,EAAE;QAAE,OAAO,EAAE,eAAe,GAAG,SAAS,CAAA;KAAE,CAAC;IACrD,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IACxD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE;QAAE,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,CAAA;KAAE,CAAC;IAC3D,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,GAAG,gBAAgB,CAk/BnB"}
|
|
@@ -414,6 +414,17 @@ function combineContinuationHistory(fragments) {
|
|
|
414
414
|
return truncateForContinuation(fragments.filter(Boolean).join("\n\n"), 40_000).trim();
|
|
415
415
|
}
|
|
416
416
|
function visibleTransientContinuationContent(content) {
|
|
417
|
+
// NOTE: this intentionally keeps ONLY completed tool calls, dropping
|
|
418
|
+
// already-streamed text, on a transient continuation. Preserving the text
|
|
419
|
+
// here is desirable (it's the live "paragraphs disappear" flicker) BUT it
|
|
420
|
+
// breaks visibleContentForContinuation's part-count prefix slicing: the
|
|
421
|
+
// resumed run's text concatenates into the preserved trailing text part, so
|
|
422
|
+
// the "new chunk" reads as empty and the empty-continuation cap gives up
|
|
423
|
+
// prematurely on text-heavy multi-continuation turns. The durable fix
|
|
424
|
+
// (server-side foldAssistantTurn) already preserves the text in thread_data,
|
|
425
|
+
// so no data is lost — only the live render flickers. Fixing the flicker
|
|
426
|
+
// safely requires reworking the prefix/new-chunk detection to diff by text
|
|
427
|
+
// length rather than part count; see the agent-run reliability follow-up.
|
|
417
428
|
return content.filter((part) => part.type === "tool-call" && part.result !== undefined);
|
|
418
429
|
}
|
|
419
430
|
function hasContinuationProgress(content) {
|
|
@@ -499,6 +510,13 @@ function retryDelay(attempt, abortSignal) {
|
|
|
499
510
|
const ms = Math.max(0, base + (Math.random() * 2 - 1) * jitter);
|
|
500
511
|
return delay(ms, abortSignal);
|
|
501
512
|
}
|
|
513
|
+
function generateTurnId() {
|
|
514
|
+
if (typeof crypto !== "undefined" &&
|
|
515
|
+
typeof crypto.randomUUID === "function") {
|
|
516
|
+
return `turn-${crypto.randomUUID()}`;
|
|
517
|
+
}
|
|
518
|
+
return `turn-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
|
|
519
|
+
}
|
|
502
520
|
function isRetryableStartupError(message) {
|
|
503
521
|
const msg = message.toLowerCase();
|
|
504
522
|
if (msg.includes("cannot find any route matching") &&
|
|
@@ -724,6 +742,7 @@ export function createAgentChatAdapter(options) {
|
|
|
724
742
|
}
|
|
725
743
|
const content = [];
|
|
726
744
|
const toolCallCounter = { value: 0 };
|
|
745
|
+
const turnId = generateTurnId();
|
|
727
746
|
let runId = null;
|
|
728
747
|
let lastSeq = -1;
|
|
729
748
|
let currentMessageText = normalizeMentions(recoveryMessageText.trim() || userMessageText);
|
|
@@ -1085,6 +1104,7 @@ export function createAgentChatAdapter(options) {
|
|
|
1085
1104
|
displayMessage: userMessageText,
|
|
1086
1105
|
history: currentHistory,
|
|
1087
1106
|
structuredHistory: currentStructuredHistory,
|
|
1107
|
+
turnId,
|
|
1088
1108
|
...(threadId ? { threadId } : {}),
|
|
1089
1109
|
...(internalContinuationRequest
|
|
1090
1110
|
? { internalContinuation: true }
|