@assistant-ui/react-langchain 0.0.32 → 0.0.34
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/LICENSE +1 -1
- package/dist/attachSubagentTranscripts.d.ts +13 -14
- package/dist/attachSubagentTranscripts.d.ts.map +1 -1
- package/dist/convertMessages.d.ts +6 -9
- package/dist/convertMessages.d.ts.map +1 -1
- package/dist/convertMessages.js +57 -15
- package/dist/convertMessages.js.map +1 -1
- package/dist/converter.d.ts +128 -128
- package/dist/converter.d.ts.map +1 -1
- package/dist/converter.js +2 -1
- package/dist/converter.js.map +1 -1
- package/dist/findForkCheckpointInHistory.d.ts +15 -16
- package/dist/findForkCheckpointInHistory.d.ts.map +1 -1
- package/dist/hooks.d.ts +5 -7
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.d.ts +7 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/resolveForkCheckpoint.d.ts +4 -5
- package/dist/resolveForkCheckpoint.d.ts.map +1 -1
- package/dist/runtimeExtras.d.ts +1 -3
- package/dist/runtimeExtras.d.ts.map +1 -1
- package/dist/sdkIdentity.d.ts +1 -3
- package/dist/sdkIdentity.d.ts.map +1 -1
- package/dist/sdkIdentity.js +1 -1
- package/dist/streamingTiming.d.ts +2 -4
- package/dist/streamingTiming.d.ts.map +1 -1
- package/dist/subagentMessagesProjection.d.ts +17 -0
- package/dist/subagentMessagesProjection.d.ts.map +1 -0
- package/dist/subagentMessagesProjection.js +40 -0
- package/dist/subagentMessagesProjection.js.map +1 -0
- package/dist/types.d.ts +100 -103
- package/dist/types.d.ts.map +1 -1
- package/dist/uiMessages.d.ts +18 -6
- package/dist/uiMessages.d.ts.map +1 -1
- package/dist/uiMessages.js +33 -1
- package/dist/uiMessages.js.map +1 -1
- package/dist/useStreamRuntime.d.ts +7 -10
- package/dist/useStreamRuntime.d.ts.map +1 -1
- package/dist/useStreamRuntime.js +100 -26
- package/dist/useStreamRuntime.js.map +1 -1
- package/dist/useSubagentTranscripts.d.ts +3 -5
- package/dist/useSubagentTranscripts.d.ts.map +1 -1
- package/dist/useSubagentTranscripts.js +5 -3
- package/dist/useSubagentTranscripts.js.map +1 -1
- package/package.json +16 -9
- package/src/convertMessages.test.ts +153 -0
- package/src/convertMessages.ts +54 -8
- package/src/converter.ts +6 -0
- package/src/subagentMessagesProjection.test.ts +175 -0
- package/src/subagentMessagesProjection.ts +50 -0
- package/src/tests/settleOutsideAct.ts +15 -0
- package/src/uiMessages.test.ts +106 -0
- package/src/uiMessages.ts +43 -0
- package/src/useStreamRuntime.test.tsx +147 -7
- package/src/useStreamRuntime.ts +197 -45
- package/src/useStreamRuntime.voice.test.tsx +713 -0
- package/src/useSubagentTranscripts.fast-refresh.test.tsx +152 -0
- package/src/useSubagentTranscripts.test.tsx +2 -0
- package/src/useSubagentTranscripts.ts +5 -7
package/dist/converter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.js","names":["_exhaustiveCheck"],"sources":["../src/converter.ts"],"sourcesContent":["import type {\n AppendMessage,\n DataMessagePart,\n ThreadAssistantMessage,\n ThreadUserMessage,\n} from \"@assistant-ui/core\";\nimport {\n parseDataUrl,\n resolveFilePartSource,\n} from \"@assistant-ui/core/internal\";\nimport type { StreamingTimingAccessors } from \"@assistant-ui/core/react\";\n\n/** Known content block types from @langchain/core messages. */\nexport type LangChainContentBlock =\n | { type: \"text\"; text: string }\n | { type: \"text_delta\"; text: string }\n | { type: \"image_url\"; image_url: string | { url?: string } }\n | { type: \"thinking\"; thinking: string }\n | {\n type: \"reasoning\";\n summary?: Array<{ type: \"summary_text\"; text?: string }>;\n reasoning?: string;\n }\n | {\n type: \"file\";\n data: string;\n mime_type: string;\n source_type?: \"base64\";\n metadata?: { filename?: string };\n }\n | {\n type: \"file\";\n url: string;\n mime_type?: string;\n source_type: \"url\";\n metadata?: { filename?: string };\n }\n | {\n type: \"file\";\n id: string;\n mime_type?: string;\n source_type: \"id\";\n metadata?: { filename?: string };\n }\n | {\n type: \"audio\";\n data: string;\n mime_type: string;\n source_type: \"base64\";\n }\n | { type: \"tool_use\" | \"input_json_delta\" };\n\ntype ConvertedContentPart =\n | ThreadUserMessage[\"content\"][number]\n | ThreadAssistantMessage[\"content\"][number];\n\nexport const convertLangChainContentBlock = (\n part: LangChainContentBlock,\n): ConvertedContentPart | null | undefined => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"text_delta\":\n return {\n type: \"text\" as const,\n text: typeof part.text === \"string\" ? part.text : \"\",\n };\n case \"image_url\": {\n const image =\n typeof part.image_url === \"string\"\n ? part.image_url\n : part.image_url?.url;\n if (!image) return null;\n return { type: \"image\" as const, image };\n }\n case \"file\":\n return {\n type: \"file\" as const,\n filename: part.metadata?.filename ?? \"file\",\n data:\n part.source_type === \"url\"\n ? part.url\n : part.source_type === \"id\"\n ? part.id\n : part.data,\n mimeType: part.mime_type ?? \"application/octet-stream\",\n ...((part.source_type === \"url\" || part.source_type === \"id\") && {\n sourceType: part.source_type,\n }),\n };\n case \"audio\": {\n const mimeType = part.mime_type ?? \"application/octet-stream\";\n const subtype = mimeType.startsWith(\"audio/\")\n ? mimeType.slice(\"audio/\".length)\n : undefined;\n return {\n type: \"file\" as const,\n filename: subtype ? `audio.${subtype}` : \"audio\",\n data: part.data,\n mimeType,\n };\n }\n case \"thinking\":\n return hasVisibleText(part.thinking)\n ? { type: \"reasoning\" as const, text: part.thinking }\n : null;\n case \"reasoning\": {\n const text = getReasoningText(part);\n return text ? { type: \"reasoning\" as const, text } : null;\n }\n case \"tool_use\":\n case \"input_json_delta\":\n return null;\n default:\n return undefined;\n }\n};\n\nconst hasVisibleText = (text: unknown): boolean =>\n typeof text === \"string\" && text.trim() !== \"\";\n\n/**\n * Audio output arrives outside the content array: providers leave `content`\n * empty and put the spoken text in `additional_kwargs.audio.transcript`. The\n * audio bytes stay behind because no provider reports their media type, and a\n * streamed response carries raw PCM rather than a playable file.\n */\nexport const withAudioTranscript = <T extends { type: string; text?: unknown }>(\n parts: readonly T[],\n additionalKwargs: Record<string, unknown> | undefined,\n): readonly (T | { type: \"text\"; text: string })[] => {\n const audio = additionalKwargs?.audio as { transcript?: unknown } | undefined;\n const transcript = audio?.transcript;\n if (typeof transcript !== \"string\" || !hasVisibleText(transcript))\n return parts;\n if (parts.some((part) => part.type === \"text\" && hasVisibleText(part.text)))\n return parts;\n return [\n ...parts.filter((part) => part.type !== \"text\"),\n { type: \"text\" as const, text: transcript },\n ];\n};\n\nexport const getCustomMetadata = (\n additionalKwargs: Record<string, unknown> | undefined,\n): Record<string, unknown> =>\n (additionalKwargs?.metadata as Record<string, unknown>) ?? {};\n\nexport const uiMessageToDataPart = <\n TUIMessage extends { name: string; props: Record<string, unknown> },\n>(\n ui: TUIMessage,\n): DataMessagePart => ({\n type: \"data\",\n name: ui.name,\n data: ui.props,\n});\n\n/**\n * Audio media types that reach a provider's audio input through the LangChain\n * `audio` block. langchain-core derives OpenAI's `input_audio.format` by\n * splitting `mime_type` on `/`, and that format is a wav-or-mp3 enum, so\n * `audio/mpeg` passes the converter and is rejected at the provider.\n */\nconst audioBlockMimeTypes = new Map<string, \"audio/mp3\" | \"audio/wav\">([\n [\"audio/mp3\", \"audio/mp3\"],\n [\"audio/mpeg\", \"audio/mp3\"],\n [\"audio/wav\", \"audio/wav\"],\n [\"audio/wave\", \"audio/wav\"],\n [\"audio/x-wav\", \"audio/wav\"],\n]);\n\nexport const getMessageContent = (msg: AppendMessage) => {\n const allContent = [\n ...msg.content,\n ...(msg.attachments?.flatMap((a) => a.content) ?? []),\n ];\n\n const hasNonText = allContent.some(\n (part) =>\n part.type === \"file\" || part.type === \"image\" || part.type === \"audio\",\n );\n const hasText = allContent.some((part) => part.type === \"text\");\n if (hasNonText && !hasText) {\n allContent.unshift({ type: \"text\", text: \" \" });\n }\n\n const content = allContent.flatMap((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\" as const, text: part.text };\n case \"image\":\n return { type: \"image_url\" as const, image_url: { url: part.image } };\n case \"file\": {\n const metadata = { filename: part.filename ?? \"file\" };\n if (part.sourceType === \"id\") {\n return {\n type: \"file\" as const,\n id: part.data,\n mime_type: part.mimeType,\n filename: metadata.filename,\n metadata,\n source_type: \"id\" as const,\n };\n }\n const source = resolveFilePartSource(part);\n if (source.kind === \"url\") {\n return {\n type: \"file\" as const,\n url: source.url,\n mime_type: part.mimeType,\n filename: metadata.filename,\n metadata,\n source_type: \"url\" as const,\n };\n }\n const audioMimeType = audioBlockMimeTypes.get(\n source.mimeType.toLowerCase(),\n );\n if (audioMimeType) {\n return {\n type: \"audio\" as const,\n data: source.data,\n mime_type: audioMimeType,\n source_type: \"base64\" as const,\n };\n }\n return {\n type: \"file\" as const,\n data: source.data,\n mime_type: source.mimeType,\n filename: metadata.filename,\n metadata,\n source_type: \"base64\" as const,\n };\n }\n case \"audio\": {\n const parsed = parseDataUrl(part.audio.data);\n return {\n type: \"audio\" as const,\n data: parsed?.data ?? part.audio.data,\n mime_type: `audio/${part.audio.format}`,\n source_type: \"base64\" as const,\n };\n }\n case \"data\":\n return [];\n case \"tool-call\":\n throw new Error(\"Tool call appends are not supported.\");\n default: {\n const _exhaustiveCheck: \"reasoning\" | \"source\" | \"generative-ui\" = type;\n throw new Error(\n `Unsupported append message part type: ${_exhaustiveCheck}`,\n );\n }\n }\n });\n\n if (content.length === 1 && content[0]?.type === \"text\") {\n return content[0].text ?? \"\";\n }\n return content;\n};\n\nconst getReasoningText = (part: {\n readonly summary?: ReadonlyArray<{ readonly text?: string }>;\n readonly reasoning?: string;\n}): string => {\n const summary = part.summary?.map((s) => s?.text ?? \"\").join(\"\\n\\n\\n\") ?? \"\";\n if (hasVisibleText(summary)) return summary;\n const reasoning = part.reasoning ?? \"\";\n return hasVisibleText(reasoning) ? reasoning : \"\";\n};\n\nexport const createLangChainStreamingTimingAccessors = <\n TMessage extends {\n id?: string | undefined;\n content?: unknown;\n tool_calls?: readonly unknown[] | undefined;\n },\n>(\n getType: (message: TMessage) => string,\n): StreamingTimingAccessors<TMessage> => {\n const findAiMessage = (\n messages: readonly TMessage[],\n messageId: string,\n ): TMessage | undefined =>\n messages.find(\n (message) => getType(message) === \"ai\" && message.id === messageId,\n );\n\n const getTextLength = (\n messages: readonly TMessage[],\n messageId: string,\n ): number => {\n const message = findAiMessage(messages, messageId);\n if (!message) return 0;\n const content = message.content;\n if (typeof content === \"string\") return content.length;\n if (!Array.isArray(content)) return 0;\n let len = 0;\n for (const part of content as readonly LangChainContentBlock[]) {\n if (typeof part !== \"object\" || part === null) continue;\n switch (part.type) {\n case \"text\":\n case \"text_delta\":\n if (typeof part.text === \"string\") len += part.text.length;\n break;\n case \"thinking\":\n if (hasVisibleText(part.thinking)) len += part.thinking.length;\n break;\n case \"reasoning\":\n len += getReasoningText(part).length;\n break;\n }\n }\n return len;\n };\n\n const getToolCallCount = (\n messages: readonly TMessage[],\n messageId: string,\n ): number => findAiMessage(messages, messageId)?.tool_calls?.length ?? 0;\n\n const getAssistantMessageId = (\n messages: readonly TMessage[],\n ): string | undefined => {\n for (let i = messages.length - 1; i >= 0; i--) {\n const message = messages[i];\n if (message && getType(message) === \"ai\" && message.id) return message.id;\n }\n return undefined;\n };\n\n return {\n getAssistantMessageId,\n getTextLength,\n getToolCallCount,\n };\n};\n\n/**\n * Resolve the assistant message a `UIMessage` belongs to: the parent id comes\n * from `metadata.message_id` (Python SDK) or `metadata.id` (JS SDK).\n */\nexport const getUIMessageParentId = (ui: {\n metadata?: { message_id?: string; id?: string } | undefined;\n}): string | undefined => ui.metadata?.message_id ?? ui.metadata?.id;\n\n/**\n * Group the graph's accumulated `UIMessage`s by the assistant message they\n * belong to. Non-array state and entries without a parent link are dropped.\n */\nexport const groupUIMessagesByParent = <\n T extends {\n metadata?: { message_id?: string; id?: string } | undefined;\n },\n>(\n value: unknown,\n): Map<string, T[]> => {\n const map = new Map<string, T[]>();\n if (!Array.isArray(value)) return map;\n for (const ui of value as T[]) {\n const parentId = getUIMessageParentId(ui);\n if (!parentId) continue;\n const existing = map.get(parentId);\n if (existing) {\n existing.push(ui);\n } else {\n map.set(parentId, [ui]);\n }\n }\n return map;\n};\n"],"mappings":";;AAwDA,MAAa,gCACX,SAC4C;CAE5C,QADa,KAAK,MAClB;EACE,KAAK;EACL,KAAK,cACH,OAAO;GACL,MAAM;GACN,MAAM,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO;EACpD;EACF,KAAK,aAAa;GAChB,MAAM,QACJ,OAAO,KAAK,cAAc,WACtB,KAAK,YACL,KAAK,WAAW;GACtB,IAAI,CAAC,OAAO,OAAO;GACnB,OAAO;IAAE,MAAM;IAAkB;GAAM;EACzC;EACA,KAAK,QACH,OAAO;GACL,MAAM;GACN,UAAU,KAAK,UAAU,YAAY;GACrC,MACE,KAAK,gBAAgB,QACjB,KAAK,MACL,KAAK,gBAAgB,OACnB,KAAK,KACL,KAAK;GACb,UAAU,KAAK,aAAa;GAC5B,IAAK,KAAK,gBAAgB,SAAS,KAAK,gBAAgB,SAAS,EAC/D,YAAY,KAAK,YACnB;EACF;EACF,KAAK,SAAS;GACZ,MAAM,WAAW,KAAK,aAAa;GACnC,MAAM,UAAU,SAAS,WAAW,QAAQ,IACxC,SAAS,MAAM,CAAe,IAC9B,KAAA;GACJ,OAAO;IACL,MAAM;IACN,UAAU,UAAU,SAAS,YAAY;IACzC,MAAM,KAAK;IACX;GACF;EACF;EACA,KAAK,YACH,OAAO,eAAe,KAAK,QAAQ,IAC/B;GAAE,MAAM;GAAsB,MAAM,KAAK;EAAS,IAClD;EACN,KAAK,aAAa;GAChB,MAAM,OAAO,iBAAiB,IAAI;GAClC,OAAO,OAAO;IAAE,MAAM;IAAsB;GAAK,IAAI;EACvD;EACA,KAAK;EACL,KAAK,oBACH,OAAO;EACT,SACE;CACJ;AACF;AAEA,MAAM,kBAAkB,SACtB,OAAO,SAAS,YAAY,KAAK,KAAK,MAAM;;;;;;;AAQ9C,MAAa,uBACX,OACA,qBACoD;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AAI,UAAU,CAAC,EAAE,CAAC;CAE1B;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"converter.js","names":["_exhaustiveCheck"],"sources":["../src/converter.ts"],"sourcesContent":["import type {\n AppendMessage,\n DataMessagePart,\n MessageModality,\n ThreadAssistantMessage,\n ThreadUserMessage,\n} from \"@assistant-ui/core\";\nimport {\n parseDataUrl,\n resolveFilePartSource,\n} from \"@assistant-ui/core/internal\";\nimport type { StreamingTimingAccessors } from \"@assistant-ui/core/react\";\n\n/** Known content block types from @langchain/core messages. */\nexport type LangChainContentBlock =\n | { type: \"text\"; text: string }\n | { type: \"text_delta\"; text: string }\n | { type: \"image_url\"; image_url: string | { url?: string } }\n | { type: \"thinking\"; thinking: string }\n | {\n type: \"reasoning\";\n summary?: Array<{ type: \"summary_text\"; text?: string }>;\n reasoning?: string;\n }\n | {\n type: \"file\";\n data: string;\n mime_type: string;\n source_type?: \"base64\";\n metadata?: { filename?: string };\n }\n | {\n type: \"file\";\n url: string;\n mime_type?: string;\n source_type: \"url\";\n metadata?: { filename?: string };\n }\n | {\n type: \"file\";\n id: string;\n mime_type?: string;\n source_type: \"id\";\n metadata?: { filename?: string };\n }\n | {\n type: \"audio\";\n data: string;\n mime_type: string;\n source_type: \"base64\";\n }\n | { type: \"tool_use\" | \"input_json_delta\" };\n\ntype ConvertedContentPart =\n | ThreadUserMessage[\"content\"][number]\n | ThreadAssistantMessage[\"content\"][number];\n\nexport const convertLangChainContentBlock = (\n part: LangChainContentBlock,\n): ConvertedContentPart | null | undefined => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"text_delta\":\n return {\n type: \"text\" as const,\n text: typeof part.text === \"string\" ? part.text : \"\",\n };\n case \"image_url\": {\n const image =\n typeof part.image_url === \"string\"\n ? part.image_url\n : part.image_url?.url;\n if (!image) return null;\n return { type: \"image\" as const, image };\n }\n case \"file\":\n return {\n type: \"file\" as const,\n filename: part.metadata?.filename ?? \"file\",\n data:\n part.source_type === \"url\"\n ? part.url\n : part.source_type === \"id\"\n ? part.id\n : part.data,\n mimeType: part.mime_type ?? \"application/octet-stream\",\n ...((part.source_type === \"url\" || part.source_type === \"id\") && {\n sourceType: part.source_type,\n }),\n };\n case \"audio\": {\n const mimeType = part.mime_type ?? \"application/octet-stream\";\n const subtype = mimeType.startsWith(\"audio/\")\n ? mimeType.slice(\"audio/\".length)\n : undefined;\n return {\n type: \"file\" as const,\n filename: subtype ? `audio.${subtype}` : \"audio\",\n data: part.data,\n mimeType,\n };\n }\n case \"thinking\":\n return hasVisibleText(part.thinking)\n ? { type: \"reasoning\" as const, text: part.thinking }\n : null;\n case \"reasoning\": {\n const text = getReasoningText(part);\n return text ? { type: \"reasoning\" as const, text } : null;\n }\n case \"tool_use\":\n case \"input_json_delta\":\n return null;\n default:\n return undefined;\n }\n};\n\nconst hasVisibleText = (text: unknown): boolean =>\n typeof text === \"string\" && text.trim() !== \"\";\n\n/**\n * Audio output arrives outside the content array: providers leave `content`\n * empty and put the spoken text in `additional_kwargs.audio.transcript`. The\n * audio bytes stay behind because no provider reports their media type, and a\n * streamed response carries raw PCM rather than a playable file.\n */\nexport const withAudioTranscript = <T extends { type: string; text?: unknown }>(\n parts: readonly T[],\n additionalKwargs: Record<string, unknown> | undefined,\n): readonly (T | { type: \"text\"; text: string })[] => {\n const audio = additionalKwargs?.audio as { transcript?: unknown } | undefined;\n const transcript = audio?.transcript;\n if (typeof transcript !== \"string\" || !hasVisibleText(transcript))\n return parts;\n if (parts.some((part) => part.type === \"text\" && hasVisibleText(part.text)))\n return parts;\n return [\n ...parts.filter((part) => part.type !== \"text\"),\n { type: \"text\" as const, text: transcript },\n ];\n};\n\nexport const getCustomMetadata = (\n additionalKwargs: Record<string, unknown> | undefined,\n): Record<string, unknown> =>\n (additionalKwargs?.metadata as Record<string, unknown>) ?? {};\n\nexport const getMessageModality = (\n additionalKwargs: Record<string, unknown> | undefined,\n): MessageModality | undefined =>\n additionalKwargs?.modality === \"voice\" ? \"voice\" : undefined;\n\nexport const uiMessageToDataPart = <\n TUIMessage extends { name: string; props: Record<string, unknown> },\n>(\n ui: TUIMessage,\n): DataMessagePart => ({\n type: \"data\",\n name: ui.name,\n data: ui.props,\n});\n\n/**\n * Audio media types that reach a provider's audio input through the LangChain\n * `audio` block. langchain-core derives OpenAI's `input_audio.format` by\n * splitting `mime_type` on `/`, and that format is a wav-or-mp3 enum, so\n * `audio/mpeg` passes the converter and is rejected at the provider.\n */\nconst audioBlockMimeTypes = new Map<string, \"audio/mp3\" | \"audio/wav\">([\n [\"audio/mp3\", \"audio/mp3\"],\n [\"audio/mpeg\", \"audio/mp3\"],\n [\"audio/wav\", \"audio/wav\"],\n [\"audio/wave\", \"audio/wav\"],\n [\"audio/x-wav\", \"audio/wav\"],\n]);\n\nexport const getMessageContent = (msg: AppendMessage) => {\n const allContent = [\n ...msg.content,\n ...(msg.attachments?.flatMap((a) => a.content) ?? []),\n ];\n\n const hasNonText = allContent.some(\n (part) =>\n part.type === \"file\" || part.type === \"image\" || part.type === \"audio\",\n );\n const hasText = allContent.some((part) => part.type === \"text\");\n if (hasNonText && !hasText) {\n allContent.unshift({ type: \"text\", text: \" \" });\n }\n\n const content = allContent.flatMap((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\" as const, text: part.text };\n case \"image\":\n return { type: \"image_url\" as const, image_url: { url: part.image } };\n case \"file\": {\n const metadata = { filename: part.filename ?? \"file\" };\n if (part.sourceType === \"id\") {\n return {\n type: \"file\" as const,\n id: part.data,\n mime_type: part.mimeType,\n filename: metadata.filename,\n metadata,\n source_type: \"id\" as const,\n };\n }\n const source = resolveFilePartSource(part);\n if (source.kind === \"url\") {\n return {\n type: \"file\" as const,\n url: source.url,\n mime_type: part.mimeType,\n filename: metadata.filename,\n metadata,\n source_type: \"url\" as const,\n };\n }\n const audioMimeType = audioBlockMimeTypes.get(\n source.mimeType.toLowerCase(),\n );\n if (audioMimeType) {\n return {\n type: \"audio\" as const,\n data: source.data,\n mime_type: audioMimeType,\n source_type: \"base64\" as const,\n };\n }\n return {\n type: \"file\" as const,\n data: source.data,\n mime_type: source.mimeType,\n filename: metadata.filename,\n metadata,\n source_type: \"base64\" as const,\n };\n }\n case \"audio\": {\n const parsed = parseDataUrl(part.audio.data);\n return {\n type: \"audio\" as const,\n data: parsed?.data ?? part.audio.data,\n mime_type: `audio/${part.audio.format}`,\n source_type: \"base64\" as const,\n };\n }\n case \"data\":\n return [];\n case \"tool-call\":\n throw new Error(\"Tool call appends are not supported.\");\n default: {\n const _exhaustiveCheck: \"reasoning\" | \"source\" | \"generative-ui\" = type;\n throw new Error(\n `Unsupported append message part type: ${_exhaustiveCheck}`,\n );\n }\n }\n });\n\n if (content.length === 1 && content[0]?.type === \"text\") {\n return content[0].text ?? \"\";\n }\n return content;\n};\n\nconst getReasoningText = (part: {\n readonly summary?: ReadonlyArray<{ readonly text?: string }>;\n readonly reasoning?: string;\n}): string => {\n const summary = part.summary?.map((s) => s?.text ?? \"\").join(\"\\n\\n\\n\") ?? \"\";\n if (hasVisibleText(summary)) return summary;\n const reasoning = part.reasoning ?? \"\";\n return hasVisibleText(reasoning) ? reasoning : \"\";\n};\n\nexport const createLangChainStreamingTimingAccessors = <\n TMessage extends {\n id?: string | undefined;\n content?: unknown;\n tool_calls?: readonly unknown[] | undefined;\n },\n>(\n getType: (message: TMessage) => string,\n): StreamingTimingAccessors<TMessage> => {\n const findAiMessage = (\n messages: readonly TMessage[],\n messageId: string,\n ): TMessage | undefined =>\n messages.find(\n (message) => getType(message) === \"ai\" && message.id === messageId,\n );\n\n const getTextLength = (\n messages: readonly TMessage[],\n messageId: string,\n ): number => {\n const message = findAiMessage(messages, messageId);\n if (!message) return 0;\n const content = message.content;\n if (typeof content === \"string\") return content.length;\n if (!Array.isArray(content)) return 0;\n let len = 0;\n for (const part of content as readonly LangChainContentBlock[]) {\n if (typeof part !== \"object\" || part === null) continue;\n switch (part.type) {\n case \"text\":\n case \"text_delta\":\n if (typeof part.text === \"string\") len += part.text.length;\n break;\n case \"thinking\":\n if (hasVisibleText(part.thinking)) len += part.thinking.length;\n break;\n case \"reasoning\":\n len += getReasoningText(part).length;\n break;\n }\n }\n return len;\n };\n\n const getToolCallCount = (\n messages: readonly TMessage[],\n messageId: string,\n ): number => findAiMessage(messages, messageId)?.tool_calls?.length ?? 0;\n\n const getAssistantMessageId = (\n messages: readonly TMessage[],\n ): string | undefined => {\n for (let i = messages.length - 1; i >= 0; i--) {\n const message = messages[i];\n if (message && getType(message) === \"ai\" && message.id) return message.id;\n }\n return undefined;\n };\n\n return {\n getAssistantMessageId,\n getTextLength,\n getToolCallCount,\n };\n};\n\n/**\n * Resolve the assistant message a `UIMessage` belongs to: the parent id comes\n * from `metadata.message_id` (Python SDK) or `metadata.id` (JS SDK).\n */\nexport const getUIMessageParentId = (ui: {\n metadata?: { message_id?: string; id?: string } | undefined;\n}): string | undefined => ui.metadata?.message_id ?? ui.metadata?.id;\n\n/**\n * Group the graph's accumulated `UIMessage`s by the assistant message they\n * belong to. Non-array state and entries without a parent link are dropped.\n */\nexport const groupUIMessagesByParent = <\n T extends {\n metadata?: { message_id?: string; id?: string } | undefined;\n },\n>(\n value: unknown,\n): Map<string, T[]> => {\n const map = new Map<string, T[]>();\n if (!Array.isArray(value)) return map;\n for (const ui of value as T[]) {\n const parentId = getUIMessageParentId(ui);\n if (!parentId) continue;\n const existing = map.get(parentId);\n if (existing) {\n existing.push(ui);\n } else {\n map.set(parentId, [ui]);\n }\n }\n return map;\n};\n"],"mappings":";;AAyDA,MAAa,gCACX,SAC4C;CAE5C,QADa,KAAK,MAClB;EACE,KAAK;EACL,KAAK,cACH,OAAO;GACL,MAAM;GACN,MAAM,OAAO,KAAK,SAAS,WAAW,KAAK,OAAO;EACpD;EACF,KAAK,aAAa;GAChB,MAAM,QACJ,OAAO,KAAK,cAAc,WACtB,KAAK,YACL,KAAK,WAAW;GACtB,IAAI,CAAC,OAAO,OAAO;GACnB,OAAO;IAAE,MAAM;IAAkB;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IACE,KAAK;IACL,KAAK;KACH,IAAI,OAAO,KAAK,SAAS,UAAU,OAAO,KAAK,KAAK;KACpD;IACF,KAAK;KACH,IAAI,eAAe,KAAK,QAAQ,GAAG,OAAO,KAAK,SAAS;KACxD;IACF,KAAK,aACH,OAAO,iBAAiB,IAAI,CAAC,CAAC;GAElC;EACF;EACA,OAAO;CACT;CAEA,MAAM,oBACJ,UACA,cACW,cAAc,UAAU,SAAS,CAAC,EAAE,YAAY,UAAU;CAEvE,MAAM,yBACJ,aACuB;EACvB,KAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;GAC7C,MAAM,UAAU,SAAS;GACzB,IAAI,WAAW,QAAQ,OAAO,MAAM,QAAQ,QAAQ,IAAI,OAAO,QAAQ;EACzE;CAEF;CAEA,OAAO;EACL;EACA;EACA;CACF;AACF;;;;;AAMA,MAAa,wBAAwB,OAEX,GAAG,UAAU,cAAc,GAAG,UAAU;;;;;AAMlE,MAAa,2BAKX,UACqB;CACrB,MAAM,sBAAM,IAAI,IAAiB;CACjC,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAClC,KAAK,MAAM,MAAM,OAAc;EAC7B,MAAM,WAAW,qBAAqB,EAAE;EACxC,IAAI,CAAC,UAAU;EACf,MAAM,WAAW,IAAI,IAAI,QAAQ;EACjC,IAAI,UACF,SAAS,KAAK,EAAE;OAEhB,IAAI,IAAI,UAAU,CAAC,EAAE,CAAC;CAE1B;CACA,OAAO;AACT"}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { LangChainBaseMessage } from "./types.js";
|
|
2
|
-
//#region src/findForkCheckpointInHistory.d.ts
|
|
1
|
+
import type { LangChainBaseMessage } from "./types.js";
|
|
3
2
|
type ForkCheckpointHistoryState = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
values?: Record<string, unknown> | undefined;
|
|
4
|
+
checkpoint?: {
|
|
5
|
+
checkpoint_id?: string | null | undefined;
|
|
6
|
+
} | undefined;
|
|
8
7
|
};
|
|
9
8
|
type ForkHistoryCursor = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
configurable: {
|
|
10
|
+
checkpoint_id: string;
|
|
11
|
+
};
|
|
13
12
|
};
|
|
14
13
|
export type ForkCheckpointClient = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
threads: {
|
|
15
|
+
getHistory: (threadId: string, options?: {
|
|
16
|
+
limit?: number;
|
|
17
|
+
before?: ForkHistoryCursor;
|
|
18
|
+
}) => Promise<readonly ForkCheckpointHistoryState[]>;
|
|
19
|
+
};
|
|
21
20
|
};
|
|
22
21
|
export declare const findForkCheckpointInHistory: (client: ForkCheckpointClient, threadId: string, messagesUpToParent: readonly LangChainBaseMessage[], messagesKey: string, pageSize?: number) => Promise<string | null>;
|
|
23
|
-
|
|
22
|
+
export {};
|
|
24
23
|
//# sourceMappingURL=findForkCheckpointInHistory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findForkCheckpointInHistory.d.ts","
|
|
1
|
+
{"version":3,"file":"findForkCheckpointInHistory.d.ts","sourceRoot":"","sources":["../src/findForkCheckpointInHistory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAgB;AAEpD,KAAK,0BAA0B,GAAG;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC7C,UAAU,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC;CACxE,CAAC;AAEF,KAAK,iBAAiB,GAAG;IAAE,YAAY,EAAE;QAAE,aAAa,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE;QACP,UAAU,EAAE,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,iBAAiB,CAAA;SAAE,KACrD,OAAO,CAAC,SAAS,0BAA0B,EAAE,CAAC,CAAC;KACrD,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,2BAA2B,GACtC,QAAQ,oBAAoB,EAC5B,UAAU,MAAM,EAChB,oBAAoB,SAAS,oBAAoB,EAAE,EACnD,aAAa,MAAM,EACnB,iBAAc,KACb,OAAO,CAAC,MAAM,GAAG,IAAI,CA2CvB,CAAC"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/hooks.d.ts
|
|
1
|
+
import type { AssembledToolCall, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot } from "@langchain/react";
|
|
2
|
+
import type { LangChainBaseMessage } from "./types.js";
|
|
4
3
|
/**
|
|
5
4
|
* Read the current LangGraph interrupt state from the runtime extras.
|
|
6
5
|
*/
|
|
7
6
|
export declare const useLangChainInterruptState: () => {
|
|
8
|
-
|
|
7
|
+
value?: unknown;
|
|
9
8
|
} | undefined;
|
|
10
9
|
/**
|
|
11
10
|
* Read every interrupt pending at the current checkpoint, each with `id`
|
|
@@ -13,8 +12,8 @@ export declare const useLangChainInterruptState: () => {
|
|
|
13
12
|
* (keyed by interrupt id) to resolve several at once.
|
|
14
13
|
*/
|
|
15
14
|
export declare const useLangChainInterrupts: () => readonly {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
id?: string;
|
|
16
|
+
value?: unknown;
|
|
18
17
|
}[];
|
|
19
18
|
/** Read the last run/hydration error from the runtime extras. */
|
|
20
19
|
export declare const useLangChainError: () => unknown;
|
|
@@ -82,5 +81,4 @@ export declare const useLangChainSendCommand: () => (command: Record<string, unk
|
|
|
82
81
|
*/
|
|
83
82
|
export declare function useLangChainState<T>(key: string): T | undefined;
|
|
84
83
|
export declare function useLangChainState<T>(key: string, defaultValue: T): T;
|
|
85
|
-
//#endregion
|
|
86
84
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAgB;AAYpD;;GAEG;AACH,eAAO,MAAM,0BAA0B;;aACa,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;;;GAIhC,CAAC;AAEJ,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,eACkB,CAAC;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,8DAC6C,CAAC;AAEhF,oEAAoE;AACpE,eAAO,MAAM,qBAAqB,sDAC2C,CAAC;AAE9E,+CAA+C;AAC/C,eAAO,MAAM,qBAAqB,sDAC2C,CAAC;AAE9E;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,wDACkB,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,SAG3B,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EAClD,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kBAEpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,SAEtB,UAAU,OAAO,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kBAE7D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,SAG/B,eAAe,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kBAEpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,SAGzB,UAAU,SAAS,oBAAoB,EAAE,EACzC,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kBAKpC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,SAE1B,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kBACzC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;AACjE,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export { type LangChainBaseMessage, type LangChainContentBlock, type LangChainToolCall, type RemoveUIMessage, type SubagentDiscoverySnapshot, type SubgraphDiscoverySnapshot, type UIMessage, type UseStreamRuntimeOptions, convertLangChainBaseMessage, useLangChainError, useLangChainInterruptState, useLangChainInterrupts, useLangChainRespond, useLangChainRespondAll, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainStream, useLangChainStreamingTiming, useLangChainSubagents, useLangChainSubgraphs, useLangChainSubmit, useLangChainToolCalls, useStreamRuntime };
|
|
1
|
+
export { useStreamRuntime } from "./useStreamRuntime.js";
|
|
2
|
+
export { useLangChainError, useLangChainInterrupts, useLangChainInterruptState, useLangChainRespond, useLangChainRespondAll, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainStream, useLangChainSubagents, useLangChainSubgraphs, useLangChainSubmit, useLangChainToolCalls, } from "./hooks.js";
|
|
3
|
+
export { convertLangChainBaseMessage } from "./convertMessages.js";
|
|
4
|
+
export { useLangChainStreamingTiming } from "./streamingTiming.js";
|
|
5
|
+
export type { SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, } from "@langchain/react";
|
|
6
|
+
export type { LangChainBaseMessage, LangChainContentBlock, LangChainToolCall, RemoveUIMessage, UIMessage, UseStreamRuntimeOptions, } from "./types.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,8BAA2B;AAEtD,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,GACtB,mBAAgB;AAEjB,OAAO,EAAE,2BAA2B,EAAE,6BAA0B;AAChE,OAAO,EAAE,2BAA2B,EAAE,6BAA0B;AAEhE,YAAY,EACV,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,uBAAuB,GACxB,mBAAgB"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { LangChainBaseMessage } from "./types.js";
|
|
2
|
-
import { ForkCheckpointClient } from "./findForkCheckpointInHistory.js";
|
|
3
|
-
//#region src/resolveForkCheckpoint.d.ts
|
|
1
|
+
import type { LangChainBaseMessage } from "./types.js";
|
|
2
|
+
import { type ForkCheckpointClient } from "./findForkCheckpointInHistory.js";
|
|
4
3
|
type MessageMetadataSnapshot = ReadonlyMap<string, {
|
|
5
|
-
|
|
4
|
+
readonly parentCheckpointId: string | undefined;
|
|
6
5
|
}> | undefined;
|
|
7
6
|
/**
|
|
8
7
|
* Hydration seeds every message with the head's parent checkpoint, so only the
|
|
@@ -11,5 +10,5 @@ type MessageMetadataSnapshot = ReadonlyMap<string, {
|
|
|
11
10
|
* message and forks from the thread's initial (empty-message) checkpoint.
|
|
12
11
|
*/
|
|
13
12
|
export declare const resolveForkCheckpoint: (client: ForkCheckpointClient, threadId: string, messages: readonly LangChainBaseMessage[], parentId: string | null, sourceId: string | null | undefined, metadata: MessageMetadataSnapshot, messagesKey: string) => Promise<string | null>;
|
|
14
|
-
|
|
13
|
+
export {};
|
|
15
14
|
//# sourceMappingURL=resolveForkCheckpoint.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveForkCheckpoint.d.ts","
|
|
1
|
+
{"version":3,"file":"resolveForkCheckpoint.d.ts","sourceRoot":"","sources":["../src/resolveForkCheckpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAgB;AACpD,OAAO,EAEL,KAAK,oBAAoB,EAC1B,yCAAsC;AAEvC,KAAK,uBAAuB,GACxB,WAAW,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC,GACxE,SAAS,CAAC;AAEd;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAChC,QAAQ,oBAAoB,EAC5B,UAAU,MAAM,EAChB,UAAU,SAAS,oBAAoB,EAAE,EACzC,UAAU,MAAM,GAAG,IAAI,EACvB,UAAU,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,UAAU,uBAAuB,EACjC,aAAa,MAAM,KAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAwBvB,CAAC"}
|
package/dist/runtimeExtras.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { LangChainRuntimeExtras } from "./types.js";
|
|
2
|
-
//#region src/runtimeExtras.d.ts
|
|
1
|
+
import type { LangChainRuntimeExtras } from "./types.js";
|
|
3
2
|
export declare const langChainExtras: import("@assistant-ui/core/react").RuntimeExtras<LangChainRuntimeExtras>;
|
|
4
|
-
//#endregion
|
|
5
3
|
//# sourceMappingURL=runtimeExtras.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeExtras.d.ts","
|
|
1
|
+
{"version":3,"file":"runtimeExtras.d.ts","sourceRoot":"","sources":["../src/runtimeExtras.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,mBAAgB;AAEtD,eAAO,MAAM,eAAe,0EACqC,CAAC"}
|
package/dist/sdkIdentity.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkIdentity.d.ts","
|
|
1
|
+
{"version":3,"file":"sdkIdentity.d.ts","sourceRoot":"","sources":["../src/sdkIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,eAAO,MAAM,aAAa,EAAE,WAM3B,CAAC"}
|
package/dist/sdkIdentity.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/streamingTiming.d.ts
|
|
1
|
+
import type { MessageTiming } from "@assistant-ui/core";
|
|
2
|
+
import type { LangChainBaseMessage } from "./types.js";
|
|
4
3
|
export declare const langChainStreamingTimingAccessors: import("@assistant-ui/core").StreamingTimingAccessors<LangChainBaseMessage>;
|
|
5
4
|
/**
|
|
6
5
|
* Tracks per-message streaming timing for LangChain messages. Delegates to
|
|
@@ -9,5 +8,4 @@ export declare const langChainStreamingTimingAccessors: import("@assistant-ui/co
|
|
|
9
8
|
* blocks including text/thinking/reasoning, `tool_calls`).
|
|
10
9
|
*/
|
|
11
10
|
export declare const useLangChainStreamingTiming: (messages: readonly LangChainBaseMessage[], isRunning: boolean) => Record<string, MessageTiming>;
|
|
12
|
-
//#endregion
|
|
13
11
|
//# sourceMappingURL=streamingTiming.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamingTiming.d.ts","
|
|
1
|
+
{"version":3,"file":"streamingTiming.d.ts","sourceRoot":"","sources":["../src/streamingTiming.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAIxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAgB;AAEpD,eAAO,MAAM,iCAAiC,6EACiC,CAAC;AAEhF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GACtC,UAAU,SAAS,oBAAoB,EAAE,EACzC,WAAW,OAAO,KACjB,MAAM,CAAC,MAAM,EAAE,aAAa,CAC6C,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BaseMessage } from "@langchain/core/messages";
|
|
2
|
+
import { type ProjectionSpec } from "@langchain/langgraph-sdk/stream";
|
|
3
|
+
type MessagesProjection = ProjectionSpec<BaseMessage[]>;
|
|
4
|
+
/**
|
|
5
|
+
* The SDK's messages projection subscribes at the protocol's default depth
|
|
6
|
+
* of 1 and applies every delivered event, so a nested subagent's `values`
|
|
7
|
+
* snapshots rebuild its parent's store from the child's state while the child
|
|
8
|
+
* runs. The projection exposes no depth option, so this spec opens it against
|
|
9
|
+
* a thread whose subscription is pinned to depth 0: the namespace the SDK
|
|
10
|
+
* sets stays and only events at exactly that namespace are delivered, the
|
|
11
|
+
* rule the SDK's root projection already applies. The client unions every
|
|
12
|
+
* subscription's depth into the server filter, so a depth 0 subscription
|
|
13
|
+
* narrows nothing for other consumers.
|
|
14
|
+
*/
|
|
15
|
+
export declare const subagentMessagesProjection: (namespace: readonly string[]) => MessagesProjection;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=subagentMessagesProjection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagentMessagesProjection.d.ts","sourceRoot":"","sources":["../src/subagentMessagesProjection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,iCAAiC,CAAC;AAEzC,KAAK,kBAAkB,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC;AAgBxD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,GACrC,WAAW,SAAS,MAAM,EAAE,KAC3B,kBAcF,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { messagesProjection } from "@langchain/langgraph-sdk/stream";
|
|
2
|
+
//#region src/subagentMessagesProjection.ts
|
|
3
|
+
const exactDepthThread = (thread) => new Proxy(thread, { get(target, property) {
|
|
4
|
+
if (property === "subscribe") return (...[params]) => target.subscribe({
|
|
5
|
+
...params,
|
|
6
|
+
depth: 0
|
|
7
|
+
});
|
|
8
|
+
const value = Reflect.get(target, property, target);
|
|
9
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
10
|
+
} });
|
|
11
|
+
/**
|
|
12
|
+
* The SDK's messages projection subscribes at the protocol's default depth
|
|
13
|
+
* of 1 and applies every delivered event, so a nested subagent's `values`
|
|
14
|
+
* snapshots rebuild its parent's store from the child's state while the child
|
|
15
|
+
* runs. The projection exposes no depth option, so this spec opens it against
|
|
16
|
+
* a thread whose subscription is pinned to depth 0: the namespace the SDK
|
|
17
|
+
* sets stays and only events at exactly that namespace are delivered, the
|
|
18
|
+
* rule the SDK's root projection already applies. The client unions every
|
|
19
|
+
* subscription's depth into the server filter, so a depth 0 subscription
|
|
20
|
+
* narrows nothing for other consumers.
|
|
21
|
+
*/
|
|
22
|
+
const subagentMessagesProjection = (namespace) => {
|
|
23
|
+
const projection = messagesProjection(namespace);
|
|
24
|
+
return {
|
|
25
|
+
key: `exact|${projection.key}`,
|
|
26
|
+
namespace: projection.namespace,
|
|
27
|
+
initial: projection.initial,
|
|
28
|
+
open({ thread, store, rootBus }) {
|
|
29
|
+
return projection.open({
|
|
30
|
+
thread: exactDepthThread(thread),
|
|
31
|
+
store,
|
|
32
|
+
rootBus
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
export { subagentMessagesProjection };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=subagentMessagesProjection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagentMessagesProjection.js","names":[],"sources":["../src/subagentMessagesProjection.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport {\n messagesProjection,\n type ProjectionSpec,\n} from \"@langchain/langgraph-sdk/stream\";\n\ntype MessagesProjection = ProjectionSpec<BaseMessage[]>;\n\ntype ProjectionThread = Parameters<MessagesProjection[\"open\"]>[0][\"thread\"];\n\nconst exactDepthThread = (thread: ProjectionThread): ProjectionThread =>\n new Proxy(thread, {\n get(target, property) {\n if (property === \"subscribe\") {\n return (...[params]: Parameters<ProjectionThread[\"subscribe\"]>) =>\n target.subscribe({ ...params, depth: 0 });\n }\n const value = Reflect.get(target, property, target);\n return typeof value === \"function\" ? value.bind(target) : value;\n },\n });\n\n/**\n * The SDK's messages projection subscribes at the protocol's default depth\n * of 1 and applies every delivered event, so a nested subagent's `values`\n * snapshots rebuild its parent's store from the child's state while the child\n * runs. The projection exposes no depth option, so this spec opens it against\n * a thread whose subscription is pinned to depth 0: the namespace the SDK\n * sets stays and only events at exactly that namespace are delivered, the\n * rule the SDK's root projection already applies. The client unions every\n * subscription's depth into the server filter, so a depth 0 subscription\n * narrows nothing for other consumers.\n */\nexport const subagentMessagesProjection = (\n namespace: readonly string[],\n): MessagesProjection => {\n const projection = messagesProjection(namespace);\n return {\n key: `exact|${projection.key}`,\n namespace: projection.namespace,\n initial: projection.initial,\n open({ thread, store, rootBus }) {\n return projection.open({\n thread: exactDepthThread(thread),\n store,\n rootBus,\n });\n },\n };\n};\n"],"mappings":";;AAUA,MAAM,oBAAoB,WACxB,IAAI,MAAM,QAAQ,EAChB,IAAI,QAAQ,UAAU;CACpB,IAAI,aAAa,aACf,QAAQ,GAAG,CAAC,YACV,OAAO,UAAU;EAAE,GAAG;EAAQ,OAAO;CAAE,CAAC;CAE5C,MAAM,QAAQ,QAAQ,IAAI,QAAQ,UAAU,MAAM;CAClD,OAAO,OAAO,UAAU,aAAa,MAAM,KAAK,MAAM,IAAI;AAC5D,EACF,CAAC;;;;;;;;;;;;AAaH,MAAa,8BACX,cACuB;CACvB,MAAM,aAAa,mBAAmB,SAAS;CAC/C,OAAO;EACL,KAAK,SAAS,WAAW;EACzB,WAAW,WAAW;EACtB,SAAS,WAAW;EACpB,KAAK,EAAE,QAAQ,OAAO,WAAW;GAC/B,OAAO,WAAW,KAAK;IACrB,QAAQ,iBAAiB,MAAM;IAC/B;IACA;GACF,CAAC;EACH;CACF;AACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
//#region src/types.d.ts
|
|
1
|
+
import type { AttachmentAdapter, DictationAdapter, ExternalStoreSharedOptions, FeedbackAdapter, MessageStatus, RealtimeVoiceAdapter, RemoteThreadListAdapter, SpeechSynthesisAdapter } from "@assistant-ui/core";
|
|
2
|
+
import type { AssistantCloud } from "assistant-cloud";
|
|
3
|
+
import type { UseStreamOptions, AssembledToolCall, AnyStream, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot } from "@langchain/react";
|
|
4
|
+
export type { LangChainContentBlock } from "./converter.js";
|
|
6
5
|
export type LangChainToolCall = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
args: Record<string, unknown>;
|
|
10
9
|
};
|
|
11
10
|
/**
|
|
12
11
|
* A generative UI component the graph accumulates in its state. Read from
|
|
@@ -16,27 +15,27 @@ export type LangChainToolCall = {
|
|
|
16
15
|
* Python SDK and in `metadata.id` by the JS SDK; the runtime reads either.
|
|
17
16
|
*/
|
|
18
17
|
export type UIMessage<TName extends string = string, TProps extends Record<string, unknown> = Record<string, unknown>> = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
type: "ui";
|
|
19
|
+
id: string;
|
|
20
|
+
name: TName;
|
|
21
|
+
props: TProps;
|
|
22
|
+
metadata?: {
|
|
23
|
+
merge?: boolean;
|
|
24
|
+
run_id?: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
tags?: string[];
|
|
27
|
+
message_id?: string;
|
|
28
|
+
id?: string;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
};
|
|
32
31
|
};
|
|
33
32
|
/**
|
|
34
33
|
* Emitted on the live `custom` channel by the graph's `remove_ui_message`
|
|
35
34
|
* helper to drop a pushed `UIMessage` by id.
|
|
36
35
|
*/
|
|
37
36
|
export type RemoveUIMessage = {
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
type: "remove-ui";
|
|
38
|
+
id: string;
|
|
40
39
|
};
|
|
41
40
|
/**
|
|
42
41
|
* Minimal duck-typed interface for BaseMessage class instances returned by
|
|
@@ -46,89 +45,87 @@ export type RemoveUIMessage = {
|
|
|
46
45
|
* `@langchain/core`'s `MessageContent` union.
|
|
47
46
|
*/
|
|
48
47
|
export type LangChainBaseMessage = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
_getType: () => string;
|
|
49
|
+
content: unknown;
|
|
50
|
+
id?: string | undefined;
|
|
51
|
+
name?: string | undefined;
|
|
52
|
+
additional_kwargs?: Record<string, unknown> | undefined;
|
|
53
|
+
/** Present on AIMessage */
|
|
54
|
+
tool_calls?: readonly LangChainToolCall[] | undefined;
|
|
55
|
+
/** Present on ToolMessage */
|
|
56
|
+
tool_call_id?: string | undefined;
|
|
57
|
+
/** Completion status (AIMessage) or outcome status (ToolMessage) */
|
|
58
|
+
status?: MessageStatus | "success" | "error" | undefined;
|
|
59
|
+
/** Present on ToolMessage */
|
|
60
|
+
artifact?: unknown;
|
|
62
61
|
};
|
|
63
62
|
export type LangChainRuntimeExtras = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
interrupt: {
|
|
64
|
+
value?: unknown;
|
|
65
|
+
} | undefined;
|
|
66
|
+
interrupts: readonly {
|
|
67
|
+
id?: string;
|
|
68
|
+
value?: unknown;
|
|
69
|
+
}[];
|
|
70
|
+
toolCalls: readonly AssembledToolCall[];
|
|
71
|
+
subagents: ReadonlyMap<string, SubagentDiscoverySnapshot>;
|
|
72
|
+
subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;
|
|
73
|
+
stream: AnyStream;
|
|
74
|
+
error: unknown;
|
|
75
|
+
submit: (values: Record<string, unknown> | null | undefined, options?: Record<string, unknown>) => Promise<void>;
|
|
76
|
+
respond: (response: unknown, options?: Record<string, unknown>) => Promise<void>;
|
|
77
|
+
respondAll: (responsesById: Record<string, unknown>, options?: Record<string, unknown>) => Promise<void>;
|
|
78
|
+
values: Record<string, unknown>;
|
|
79
|
+
messagesKey: string;
|
|
81
80
|
};
|
|
82
81
|
export type LangChainRuntimeExtraOptions = ExternalStoreSharedOptions & {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Called whenever the active thread's canonical (remote) ID changes, so the
|
|
84
|
+
* value can be treated as a managed/controlled variable (e.g. synced to a URL
|
|
85
|
+
* query param). Only the settled remote ID is emitted: while a freshly created
|
|
86
|
+
* thread is still optimistic the value is `undefined`, and the real ID is
|
|
87
|
+
* emitted once the thread is initialized; the transient local ID is never
|
|
88
|
+
* surfaced.
|
|
89
|
+
*/
|
|
90
|
+
onThreadIdChange?: ((threadId: string | undefined) => void) | undefined;
|
|
91
|
+
cloud?: AssistantCloud | undefined;
|
|
92
|
+
adapters?: {
|
|
93
|
+
attachments?: AttachmentAdapter | undefined;
|
|
94
|
+
speech?: SpeechSynthesisAdapter | undefined;
|
|
95
|
+
dictation?: DictationAdapter | undefined;
|
|
96
|
+
voice?: RealtimeVoiceAdapter | undefined;
|
|
97
|
+
feedback?: FeedbackAdapter | undefined;
|
|
98
|
+
} | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* When the user sends a new message while previous tool calls are
|
|
101
|
+
* still pending, automatically submit `tool` messages that cancel
|
|
102
|
+
* them so the agent's tool-call accounting stays consistent.
|
|
103
|
+
* Defaults to `true`.
|
|
104
|
+
*/
|
|
105
|
+
autoCancelPendingToolCalls?: boolean | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Routes the Cancel button's click to `useStream().stop()`. On by
|
|
108
|
+
* default. Pass `false` to disable the Cancel button.
|
|
109
|
+
*/
|
|
110
|
+
unstable_allowCancellation?: boolean | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Custom `RemoteThreadListAdapter`. When provided, replaces the
|
|
113
|
+
* cloud-backed thread list adapter.
|
|
114
|
+
*/
|
|
115
|
+
unstable_threadListAdapter?: RemoteThreadListAdapter | undefined;
|
|
116
|
+
/** Custom thread-creation hook, forwarded to the cloud adapter. */
|
|
117
|
+
create?: (() => Promise<{
|
|
118
|
+
externalId: string | undefined;
|
|
119
|
+
}>) | undefined;
|
|
120
|
+
/** Custom thread-deletion hook, forwarded to the cloud adapter. */
|
|
121
|
+
delete?: ((threadId: string) => Promise<void>) | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* State key the graph accumulates generative `UIMessage`s under. Each UI
|
|
124
|
+
* is attached to the assistant message identified by its `metadata.message_id`
|
|
125
|
+
* (Python SDK) or `metadata.id` (JS SDK) and emitted as a `data` part.
|
|
126
|
+
* Defaults to `"ui"`.
|
|
127
|
+
*/
|
|
128
|
+
uiStateKey?: string | undefined;
|
|
130
129
|
};
|
|
131
|
-
export type UseStreamRuntimeOptions = UseStreamOptions extends
|
|
132
|
-
//#endregion
|
|
133
|
-
export type { LangChainContentBlock };
|
|
130
|
+
export type UseStreamRuntimeOptions = UseStreamOptions extends infer O ? O extends UseStreamOptions ? O & LangChainRuntimeExtraOptions : never : never;
|
|
134
131
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB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