@assistant-ui/react-langgraph 0.6.2 → 0.6.5
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/appendLangChainChunk.js +4 -4
- package/dist/appendLangChainChunk.js.map +1 -1
- package/dist/convertLangChainMessages.d.ts.map +1 -1
- package/dist/convertLangChainMessages.js +36 -26
- package/dist/convertLangChainMessages.js.map +1 -1
- package/dist/types.d.ts +14 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +4 -4
- package/src/appendLangChainChunk.ts +4 -4
- package/src/convertLangChainMessages.ts +55 -30
- package/src/types.ts +19 -2
|
@@ -37,13 +37,13 @@ var appendLangChainChunk = (prev, curr) => {
|
|
|
37
37
|
}
|
|
38
38
|
const newToolCalls = [...prev.tool_calls ?? []];
|
|
39
39
|
for (const chunk of curr.tool_call_chunks ?? []) {
|
|
40
|
-
const existing = newToolCalls[chunk.index - 1] ?? {
|
|
41
|
-
const
|
|
40
|
+
const existing = newToolCalls[chunk.index - 1] ?? { partial_json: "" };
|
|
41
|
+
const partialJson = existing.partial_json + chunk.args;
|
|
42
42
|
newToolCalls[chunk.index - 1] = {
|
|
43
43
|
...chunk,
|
|
44
44
|
...existing,
|
|
45
|
-
|
|
46
|
-
args: parsePartialJsonObject(
|
|
45
|
+
partial_json: partialJson,
|
|
46
|
+
args: parsePartialJsonObject(partialJson) ?? ("args" in existing ? existing.args : {})
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/appendLangChainChunk.ts"],"sourcesContent":["import {\n LangChainMessage,\n LangChainMessageChunk,\n MessageContentText,\n} from \"./types\";\nimport { parsePartialJsonObject } from \"assistant-stream/utils\";\n\nexport const appendLangChainChunk = (\n prev: LangChainMessage | undefined,\n curr: LangChainMessage | LangChainMessageChunk,\n): LangChainMessage => {\n if (curr.type !== \"AIMessageChunk\") {\n return curr;\n }\n\n if (!prev || prev.type !== \"ai\") {\n return {\n ...curr,\n type: curr.type.replace(\"MessageChunk\", \"\").toLowerCase(),\n } as LangChainMessage;\n }\n\n const newContent =\n typeof prev.content === \"string\"\n ? [{ type: \"text\" as const, text: prev.content }]\n : [...prev.content];\n\n if (typeof curr?.content === \"string\") {\n const lastIndex = newContent.length - 1;\n if (newContent[lastIndex]?.type === \"text\") {\n (newContent[lastIndex] as MessageContentText).text =\n (newContent[lastIndex] as MessageContentText).text + curr.content;\n } else {\n newContent.push({ type: \"text\", text: curr.content });\n }\n } else if (Array.isArray(curr.content)) {\n const lastIndex = newContent.length - 1;\n for (const item of curr.content) {\n if (!(\"type\" in item)) {\n continue;\n }\n\n if (item.type === \"text\") {\n if (newContent[lastIndex]?.type === \"text\") {\n (newContent[lastIndex] as MessageContentText).text =\n (newContent[lastIndex] as MessageContentText).text + item.text;\n } else {\n newContent.push({ type: \"text\", text: item.text });\n }\n } else if (item.type === \"image_url\") {\n newContent.push(item);\n }\n }\n }\n\n const newToolCalls = [...(prev.tool_calls ?? [])];\n for (const chunk of curr.tool_call_chunks ?? []) {\n const existing = newToolCalls[chunk.index - 1] ?? {
|
|
1
|
+
{"version":3,"sources":["../src/appendLangChainChunk.ts"],"sourcesContent":["import {\n LangChainMessage,\n LangChainMessageChunk,\n MessageContentText,\n} from \"./types\";\nimport { parsePartialJsonObject } from \"assistant-stream/utils\";\n\nexport const appendLangChainChunk = (\n prev: LangChainMessage | undefined,\n curr: LangChainMessage | LangChainMessageChunk,\n): LangChainMessage => {\n if (curr.type !== \"AIMessageChunk\") {\n return curr;\n }\n\n if (!prev || prev.type !== \"ai\") {\n return {\n ...curr,\n type: curr.type.replace(\"MessageChunk\", \"\").toLowerCase(),\n } as LangChainMessage;\n }\n\n const newContent =\n typeof prev.content === \"string\"\n ? [{ type: \"text\" as const, text: prev.content }]\n : [...prev.content];\n\n if (typeof curr?.content === \"string\") {\n const lastIndex = newContent.length - 1;\n if (newContent[lastIndex]?.type === \"text\") {\n (newContent[lastIndex] as MessageContentText).text =\n (newContent[lastIndex] as MessageContentText).text + curr.content;\n } else {\n newContent.push({ type: \"text\", text: curr.content });\n }\n } else if (Array.isArray(curr.content)) {\n const lastIndex = newContent.length - 1;\n for (const item of curr.content) {\n if (!(\"type\" in item)) {\n continue;\n }\n\n if (item.type === \"text\") {\n if (newContent[lastIndex]?.type === \"text\") {\n (newContent[lastIndex] as MessageContentText).text =\n (newContent[lastIndex] as MessageContentText).text + item.text;\n } else {\n newContent.push({ type: \"text\", text: item.text });\n }\n } else if (item.type === \"image_url\") {\n newContent.push(item);\n }\n }\n }\n\n const newToolCalls = [...(prev.tool_calls ?? [])];\n for (const chunk of curr.tool_call_chunks ?? []) {\n const existing = newToolCalls[chunk.index - 1] ?? { partial_json: \"\" };\n const partialJson = existing.partial_json + chunk.args;\n newToolCalls[chunk.index - 1] = {\n ...chunk,\n ...existing,\n partial_json: partialJson,\n args:\n parsePartialJsonObject(partialJson) ??\n (\"args\" in existing ? existing.args : {}),\n };\n }\n\n return {\n ...prev,\n content: newContent,\n tool_calls: newToolCalls,\n };\n};\n"],"mappings":";AAKA,SAAS,8BAA8B;AAEhC,IAAM,uBAAuB,CAClC,MACA,SACqB;AACrB,MAAI,KAAK,SAAS,kBAAkB;AAClC,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,QAAQ,KAAK,SAAS,MAAM;AAC/B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,MAAM,KAAK,KAAK,QAAQ,gBAAgB,EAAE,EAAE,YAAY;AAAA,IAC1D;AAAA,EACF;AAEA,QAAM,aACJ,OAAO,KAAK,YAAY,WACpB,CAAC,EAAE,MAAM,QAAiB,MAAM,KAAK,QAAQ,CAAC,IAC9C,CAAC,GAAG,KAAK,OAAO;AAEtB,MAAI,OAAO,MAAM,YAAY,UAAU;AACrC,UAAM,YAAY,WAAW,SAAS;AACtC,QAAI,WAAW,SAAS,GAAG,SAAS,QAAQ;AAC1C,M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AEA,OAAO,
|
|
1
|
+
{"version":3,"file":"convertLangChainMessages.d.ts","sourceRoot":"","sources":["../src/convertLangChainMessages.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAyD3C,eAAO,MAAM,wBAAwB,EAAE,2BAA2B,CAAC,QAAQ,CACzE,gBAAgB,CA+CjB,CAAC"}
|
|
@@ -1,34 +1,44 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/convertLangChainMessages.ts
|
|
4
|
+
import { parsePartialJsonObject } from "assistant-stream/utils";
|
|
4
5
|
var contentToParts = (content) => {
|
|
5
6
|
if (typeof content === "string")
|
|
6
7
|
return [{ type: "text", text: content }];
|
|
7
|
-
return content.map(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
8
|
+
return content.map(
|
|
9
|
+
(part) => {
|
|
10
|
+
const type = part.type;
|
|
11
|
+
switch (type) {
|
|
12
|
+
case "text":
|
|
13
|
+
return { type: "text", text: part.text };
|
|
14
|
+
case "text_delta":
|
|
15
|
+
return { type: "text", text: part.text };
|
|
16
|
+
case "image_url":
|
|
17
|
+
if (typeof part.image_url === "string") {
|
|
18
|
+
return { type: "image", image: part.image_url };
|
|
19
|
+
} else {
|
|
20
|
+
return {
|
|
21
|
+
type: "image",
|
|
22
|
+
image: part.image_url.url
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
case "thinking":
|
|
26
|
+
return { type: "reasoning", text: part.thinking };
|
|
27
|
+
case "reasoning":
|
|
28
|
+
return part.summary.map((s) => s.text).map((text) => ({
|
|
29
|
+
type: "reasoning",
|
|
30
|
+
text
|
|
31
|
+
}));
|
|
32
|
+
case "tool_use":
|
|
33
|
+
return null;
|
|
34
|
+
case "input_json_delta":
|
|
35
|
+
return null;
|
|
36
|
+
default:
|
|
37
|
+
const _exhaustiveCheck = type;
|
|
38
|
+
throw new Error(`Unknown message part type: ${_exhaustiveCheck}`);
|
|
39
|
+
}
|
|
30
40
|
}
|
|
31
|
-
|
|
41
|
+
).flat().filter((a) => a !== null);
|
|
32
42
|
};
|
|
33
43
|
var convertLangChainMessages = (message) => {
|
|
34
44
|
switch (message.type) {
|
|
@@ -55,8 +65,8 @@ var convertLangChainMessages = (message) => {
|
|
|
55
65
|
type: "tool-call",
|
|
56
66
|
toolCallId: chunk.id,
|
|
57
67
|
toolName: chunk.name,
|
|
58
|
-
args: chunk.args,
|
|
59
|
-
argsText:
|
|
68
|
+
args: chunk.partial_json ? parsePartialJsonObject(chunk.partial_json) ?? {} : chunk.args,
|
|
69
|
+
argsText: chunk.partial_json ? chunk.partial_json : JSON.stringify(chunk.args)
|
|
60
70
|
})
|
|
61
71
|
) ?? []
|
|
62
72
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/convertLangChainMessages.ts"],"sourcesContent":["\"use client\";\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/convertLangChainMessages.ts"],"sourcesContent":["\"use client\";\n\nimport {\n ThreadAssistantMessage,\n useExternalMessageConverter,\n} from \"@assistant-ui/react\";\nimport { LangChainMessage } from \"./types\";\nimport { ToolCallMessagePart } from \"@assistant-ui/react\";\nimport { ThreadUserMessage } from \"@assistant-ui/react\";\nimport { parsePartialJsonObject } from \"assistant-stream/utils\";\n\nconst contentToParts = (content: LangChainMessage[\"content\"]) => {\n if (typeof content === \"string\")\n return [{ type: \"text\" as const, text: content }];\n return content\n .map(\n (\n part,\n ):\n | (ThreadUserMessage | ThreadAssistantMessage)[\"content\"][number]\n | (ThreadUserMessage | ThreadAssistantMessage)[\"content\"][number][]\n | null => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n case \"text_delta\":\n return { type: \"text\", text: part.text };\n case \"image_url\":\n if (typeof part.image_url === \"string\") {\n return { type: \"image\", image: part.image_url };\n } else {\n return {\n type: \"image\",\n image: part.image_url.url,\n };\n }\n case \"thinking\":\n return { type: \"reasoning\", text: part.thinking };\n\n case \"reasoning\":\n return part.summary\n .map((s) => s.text)\n .map((text) => ({\n type: \"reasoning\",\n text,\n }));\n\n case \"tool_use\":\n return null;\n case \"input_json_delta\":\n return null;\n\n default:\n const _exhaustiveCheck: never = type;\n throw new Error(`Unknown message part type: ${_exhaustiveCheck}`);\n }\n },\n )\n .flat()\n .filter((a) => a !== null);\n};\n\nexport const convertLangChainMessages: useExternalMessageConverter.Callback<\n LangChainMessage\n> = (message) => {\n switch (message.type) {\n case \"system\":\n return {\n role: \"system\",\n id: message.id,\n content: [{ type: \"text\", text: message.content }],\n };\n case \"human\":\n return {\n role: \"user\",\n id: message.id,\n content: contentToParts(message.content),\n };\n case \"ai\":\n return {\n role: \"assistant\",\n id: message.id,\n content: [\n ...contentToParts(message.content),\n ...(message.tool_calls?.map(\n (chunk): ToolCallMessagePart => ({\n type: \"tool-call\",\n toolCallId: chunk.id,\n toolName: chunk.name,\n args: chunk.partial_json\n ? (parsePartialJsonObject(chunk.partial_json) ?? {})\n : chunk.args,\n argsText: chunk.partial_json\n ? chunk.partial_json\n : JSON.stringify(chunk.args),\n }),\n ) ?? []),\n ],\n ...(message.status && { status: message.status }),\n };\n case \"tool\":\n return {\n role: \"tool\",\n toolName: message.name,\n toolCallId: message.tool_call_id,\n result: message.content,\n artifact: message.artifact,\n isError: message.status === \"error\",\n };\n }\n};\n"],"mappings":";;;AASA,SAAS,8BAA8B;AAEvC,IAAM,iBAAiB,CAAC,YAAyC;AAC/D,MAAI,OAAO,YAAY;AACrB,WAAO,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;AACH,aAAO;AAAA,QACL,MAAM;AAAA,QACN,IAAI,QAAQ;AAAA,QACZ,SAAS;AAAA,UACP,GAAG,eAAe,QAAQ,OAAO;AAAA,UACjC,GAAI,QAAQ,YAAY;AAAA,YACtB,CAAC,WAAgC;AAAA,cAC/B,MAAM;AAAA,cACN,YAAY,MAAM;AAAA,cAClB,UAAU,MAAM;AAAA,cAChB,MAAM,MAAM,eACP,uBAAuB,MAAM,YAAY,KAAK,CAAC,IAChD,MAAM;AAAA,cACV,UAAU,MAAM,eACZ,MAAM,eACN,KAAK,UAAU,MAAM,IAAI;AAAA,YAC/B;AAAA,UACF,KAAK,CAAC;AAAA,QACR;AAAA,QACA,GAAI,QAAQ,UAAU,EAAE,QAAQ,QAAQ,OAAO;AAAA,MACjD;AAAA,IACF,KAAK;AACH,aAAO;AAAA,QACL,MAAM;AAAA,QACN,UAAU,QAAQ;AAAA,QAClB,YAAY,QAAQ;AAAA,QACpB,QAAQ,QAAQ;AAAA,QAChB,UAAU,QAAQ;AAAA,QAClB,SAAS,QAAQ,WAAW;AAAA,MAC9B;AAAA,EACJ;AACF;","names":[]}
|
package/dist/types.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export type LangChainToolCallChunk = {
|
|
|
9
9
|
export type LangChainToolCall = {
|
|
10
10
|
id: string;
|
|
11
11
|
name: string;
|
|
12
|
-
argsText: string;
|
|
13
12
|
args: ReadonlyJSONObject;
|
|
13
|
+
partial_json?: string;
|
|
14
14
|
};
|
|
15
15
|
export type MessageContentText = {
|
|
16
16
|
type: "text" | "text_delta";
|
|
@@ -22,6 +22,18 @@ export type MessageContentImageUrl = {
|
|
|
22
22
|
url: string;
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
+
export type MessageContentThinking = {
|
|
26
|
+
type: "thinking";
|
|
27
|
+
thinking: string;
|
|
28
|
+
};
|
|
29
|
+
export type MessageContentReasoningSummaryText = {
|
|
30
|
+
type: "summary_text";
|
|
31
|
+
text: string;
|
|
32
|
+
};
|
|
33
|
+
export type MessageContentReasoning = {
|
|
34
|
+
type: "reasoning";
|
|
35
|
+
summary: MessageContentReasoningSummaryText[];
|
|
36
|
+
};
|
|
25
37
|
type MessageContentToolUse = {
|
|
26
38
|
type: "tool_use" | "input_json_delta";
|
|
27
39
|
};
|
|
@@ -37,7 +49,7 @@ export declare enum LangGraphKnownEventTypes {
|
|
|
37
49
|
type CustomEventType = string;
|
|
38
50
|
export type EventType = LangGraphKnownEventTypes | CustomEventType;
|
|
39
51
|
type UserMessageContentComplex = MessageContentText | MessageContentImageUrl;
|
|
40
|
-
type AssistantMessageContentComplex = MessageContentText | MessageContentImageUrl | MessageContentToolUse;
|
|
52
|
+
type AssistantMessageContentComplex = MessageContentText | MessageContentImageUrl | MessageContentToolUse | MessageContentReasoning | MessageContentThinking;
|
|
41
53
|
type UserMessageContent = string | UserMessageContentComplex[];
|
|
42
54
|
type AssistantMessageContent = string | AssistantMessageContentComplex[];
|
|
43
55
|
export type LangChainMessage = {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,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S,CAAC;IAC9C,gBAAgB,CAAC,EAAE,sBAAsB,EAAE,GAAG,SAAS,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EACD,wBAAwB,CAAC,eAAe,GACxC,wBAAwB,CAAC,gBAAgB,CAAC;IAC9C,IAAI,EAAE,gBAAgB,EAAE,CAAC;CAC1B,CAAC;AAEF,KAAK,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEtD,MAAM,MAAM,0BAA0B,GAAG;IACvC,KAAK,EAAE,wBAAwB,CAAC,QAAQ,CAAC;IACzC,IAAI,EAAE,CAAC,qBAAqB,EAAE,sBAAsB,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,CACpC,QAAQ,EAAE,OAAO,KACd,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1B,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1E,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAC5E,MAAM,MAAM,qBAAqB,GAAG,CAClC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,KACV,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import { MessageStatus } from \"@assistant-ui/react\";\nimport { ReadonlyJSONObject } from \"assistant-stream/utils\";\n\nexport type LangChainToolCallChunk = {\n index: number;\n id: string;\n name: string;\n args: string;\n};\n\nexport type LangChainToolCall = {\n id: string;\n name: string;\n
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import { MessageStatus } from \"@assistant-ui/react\";\nimport { ReadonlyJSONObject } from \"assistant-stream/utils\";\n\nexport type LangChainToolCallChunk = {\n index: number;\n id: string;\n name: string;\n args: string;\n};\n\nexport type LangChainToolCall = {\n id: string;\n name: string;\n args: ReadonlyJSONObject;\n partial_json?: string;\n};\n\nexport type MessageContentText = {\n type: \"text\" | \"text_delta\";\n text: string;\n};\n\nexport type MessageContentImageUrl = {\n type: \"image_url\";\n image_url: string | { url: string };\n};\n\nexport type MessageContentThinking = {\n type: \"thinking\";\n thinking: string;\n};\n\nexport type MessageContentReasoningSummaryText = {\n type: \"summary_text\";\n text: string;\n};\n\nexport type MessageContentReasoning = {\n type: \"reasoning\";\n summary: MessageContentReasoningSummaryText[];\n};\n\ntype MessageContentToolUse = {\n type: \"tool_use\" | \"input_json_delta\";\n};\n\nexport enum LangGraphKnownEventTypes {\n Messages = \"messages\",\n MessagesPartial = \"messages/partial\",\n MessagesComplete = \"messages/complete\",\n Metadata = \"metadata\",\n Updates = \"updates\",\n Info = \"info\",\n Error = \"error\",\n}\n\ntype CustomEventType = string;\n\nexport type EventType = LangGraphKnownEventTypes | CustomEventType;\n\ntype UserMessageContentComplex = MessageContentText | MessageContentImageUrl;\ntype AssistantMessageContentComplex =\n | MessageContentText\n | MessageContentImageUrl\n | MessageContentToolUse\n | MessageContentReasoning\n | MessageContentThinking;\n\ntype UserMessageContent = string | UserMessageContentComplex[];\ntype AssistantMessageContent = string | AssistantMessageContentComplex[];\n\nexport type LangChainMessage =\n | {\n id?: string;\n type: \"system\";\n content: string;\n }\n | {\n id?: string;\n type: \"human\";\n content: UserMessageContent;\n }\n | {\n id?: string;\n type: \"tool\";\n content: string;\n tool_call_id: string;\n name: string;\n artifact?: any;\n status: \"success\" | \"error\";\n }\n | {\n id?: string;\n type: \"ai\";\n content: AssistantMessageContent;\n tool_call_chunks?: LangChainToolCallChunk[];\n tool_calls?: LangChainToolCall[];\n status?: MessageStatus;\n };\n\nexport type LangChainMessageChunk = {\n id?: string | undefined;\n type: \"AIMessageChunk\";\n content?: AssistantMessageContent | undefined;\n tool_call_chunks?: LangChainToolCallChunk[] | undefined;\n};\n\nexport type LangChainEvent = {\n event:\n | LangGraphKnownEventTypes.MessagesPartial\n | LangGraphKnownEventTypes.MessagesComplete;\n data: LangChainMessage[];\n};\n\ntype LangGraphTupleMetadata = Record<string, unknown>;\n\nexport type LangChainMessageTupleEvent = {\n event: LangGraphKnownEventTypes.Messages;\n data: [LangChainMessageChunk, LangGraphTupleMetadata];\n};\n\nexport type OnMetadataEventCallback = (\n metadata: unknown,\n) => void | Promise<void>;\nexport type OnInfoEventCallback = (info: unknown) => void | Promise<void>;\nexport type OnErrorEventCallback = (error: unknown) => void | Promise<void>;\nexport type OnCustomEventCallback = (\n type: string,\n data: unknown,\n) => void | Promise<void>;\n"],"mappings":";AA8CO,IAAK,2BAAL,kBAAKA,8BAAL;AACL,EAAAA,0BAAA,cAAW;AACX,EAAAA,0BAAA,qBAAkB;AAClB,EAAAA,0BAAA,sBAAmB;AACnB,EAAAA,0BAAA,cAAW;AACX,EAAAA,0BAAA,aAAU;AACV,EAAAA,0BAAA,UAAO;AACP,EAAAA,0BAAA,WAAQ;AAPE,SAAAA;AAAA,GAAA;","names":["LangGraphKnownEventTypes"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react-langgraph",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
],
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"assistant-stream": "^0.2.
|
|
21
|
+
"assistant-stream": "^0.2.25",
|
|
22
22
|
"uuid": "^11.1.0",
|
|
23
23
|
"zod": "^4.0.17"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@assistant-ui/react": "^0.11.
|
|
26
|
+
"@assistant-ui/react": "^0.11.6",
|
|
27
27
|
"@types/react": "*",
|
|
28
28
|
"react": "^18 || ^19 || ^19.0.0-rc"
|
|
29
29
|
},
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"react": "19.1.1",
|
|
45
45
|
"tsx": "^4.20.4",
|
|
46
46
|
"vitest": "^3.2.4",
|
|
47
|
-
"@assistant-ui/react": "0.11.
|
|
47
|
+
"@assistant-ui/react": "0.11.6",
|
|
48
48
|
"@assistant-ui/x-buildutils": "0.0.1"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
@@ -55,14 +55,14 @@ export const appendLangChainChunk = (
|
|
|
55
55
|
|
|
56
56
|
const newToolCalls = [...(prev.tool_calls ?? [])];
|
|
57
57
|
for (const chunk of curr.tool_call_chunks ?? []) {
|
|
58
|
-
const existing = newToolCalls[chunk.index - 1] ?? {
|
|
59
|
-
const
|
|
58
|
+
const existing = newToolCalls[chunk.index - 1] ?? { partial_json: "" };
|
|
59
|
+
const partialJson = existing.partial_json + chunk.args;
|
|
60
60
|
newToolCalls[chunk.index - 1] = {
|
|
61
61
|
...chunk,
|
|
62
62
|
...existing,
|
|
63
|
-
|
|
63
|
+
partial_json: partialJson,
|
|
64
64
|
args:
|
|
65
|
-
parsePartialJsonObject(
|
|
65
|
+
parsePartialJsonObject(partialJson) ??
|
|
66
66
|
("args" in existing ? existing.args : {}),
|
|
67
67
|
};
|
|
68
68
|
}
|
|
@@ -1,40 +1,63 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ThreadAssistantMessage,
|
|
5
|
+
useExternalMessageConverter,
|
|
6
|
+
} from "@assistant-ui/react";
|
|
4
7
|
import { LangChainMessage } from "./types";
|
|
5
8
|
import { ToolCallMessagePart } from "@assistant-ui/react";
|
|
6
9
|
import { ThreadUserMessage } from "@assistant-ui/react";
|
|
10
|
+
import { parsePartialJsonObject } from "assistant-stream/utils";
|
|
7
11
|
|
|
8
12
|
const contentToParts = (content: LangChainMessage["content"]) => {
|
|
9
13
|
if (typeof content === "string")
|
|
10
14
|
return [{ type: "text" as const, text: content }];
|
|
11
15
|
return content
|
|
12
|
-
.map(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
.map(
|
|
17
|
+
(
|
|
18
|
+
part,
|
|
19
|
+
):
|
|
20
|
+
| (ThreadUserMessage | ThreadAssistantMessage)["content"][number]
|
|
21
|
+
| (ThreadUserMessage | ThreadAssistantMessage)["content"][number][]
|
|
22
|
+
| null => {
|
|
23
|
+
const type = part.type;
|
|
24
|
+
switch (type) {
|
|
25
|
+
case "text":
|
|
26
|
+
return { type: "text", text: part.text };
|
|
27
|
+
case "text_delta":
|
|
28
|
+
return { type: "text", text: part.text };
|
|
29
|
+
case "image_url":
|
|
30
|
+
if (typeof part.image_url === "string") {
|
|
31
|
+
return { type: "image", image: part.image_url };
|
|
32
|
+
} else {
|
|
33
|
+
return {
|
|
34
|
+
type: "image",
|
|
35
|
+
image: part.image_url.url,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
case "thinking":
|
|
39
|
+
return { type: "reasoning", text: part.thinking };
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
case "reasoning":
|
|
42
|
+
return part.summary
|
|
43
|
+
.map((s) => s.text)
|
|
44
|
+
.map((text) => ({
|
|
45
|
+
type: "reasoning",
|
|
46
|
+
text,
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
case "tool_use":
|
|
50
|
+
return null;
|
|
51
|
+
case "input_json_delta":
|
|
52
|
+
return null;
|
|
53
|
+
|
|
54
|
+
default:
|
|
55
|
+
const _exhaustiveCheck: never = type;
|
|
56
|
+
throw new Error(`Unknown message part type: ${_exhaustiveCheck}`);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
.flat()
|
|
38
61
|
.filter((a) => a !== null);
|
|
39
62
|
};
|
|
40
63
|
|
|
@@ -65,10 +88,12 @@ export const convertLangChainMessages: useExternalMessageConverter.Callback<
|
|
|
65
88
|
type: "tool-call",
|
|
66
89
|
toolCallId: chunk.id,
|
|
67
90
|
toolName: chunk.name,
|
|
68
|
-
args: chunk.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
91
|
+
args: chunk.partial_json
|
|
92
|
+
? (parsePartialJsonObject(chunk.partial_json) ?? {})
|
|
93
|
+
: chunk.args,
|
|
94
|
+
argsText: chunk.partial_json
|
|
95
|
+
? chunk.partial_json
|
|
96
|
+
: JSON.stringify(chunk.args),
|
|
72
97
|
}),
|
|
73
98
|
) ?? []),
|
|
74
99
|
],
|
package/src/types.ts
CHANGED
|
@@ -11,8 +11,8 @@ export type LangChainToolCallChunk = {
|
|
|
11
11
|
export type LangChainToolCall = {
|
|
12
12
|
id: string;
|
|
13
13
|
name: string;
|
|
14
|
-
argsText: string;
|
|
15
14
|
args: ReadonlyJSONObject;
|
|
15
|
+
partial_json?: string;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export type MessageContentText = {
|
|
@@ -25,6 +25,21 @@ export type MessageContentImageUrl = {
|
|
|
25
25
|
image_url: string | { url: string };
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
+
export type MessageContentThinking = {
|
|
29
|
+
type: "thinking";
|
|
30
|
+
thinking: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type MessageContentReasoningSummaryText = {
|
|
34
|
+
type: "summary_text";
|
|
35
|
+
text: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type MessageContentReasoning = {
|
|
39
|
+
type: "reasoning";
|
|
40
|
+
summary: MessageContentReasoningSummaryText[];
|
|
41
|
+
};
|
|
42
|
+
|
|
28
43
|
type MessageContentToolUse = {
|
|
29
44
|
type: "tool_use" | "input_json_delta";
|
|
30
45
|
};
|
|
@@ -47,7 +62,9 @@ type UserMessageContentComplex = MessageContentText | MessageContentImageUrl;
|
|
|
47
62
|
type AssistantMessageContentComplex =
|
|
48
63
|
| MessageContentText
|
|
49
64
|
| MessageContentImageUrl
|
|
50
|
-
| MessageContentToolUse
|
|
65
|
+
| MessageContentToolUse
|
|
66
|
+
| MessageContentReasoning
|
|
67
|
+
| MessageContentThinking;
|
|
51
68
|
|
|
52
69
|
type UserMessageContent = string | UserMessageContentComplex[];
|
|
53
70
|
type AssistantMessageContent = string | AssistantMessageContentComplex[];
|