@assistant-ui/react-langchain 0.0.7 → 0.0.8
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/convertMessages.d.ts +8 -4
- package/dist/convertMessages.d.ts.map +1 -1
- package/dist/convertMessages.js +94 -106
- package/dist/convertMessages.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.js +3 -3
- package/dist/types.d.ts +36 -36
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -2
- package/dist/useStreamRuntime.d.ts +44 -43
- package/dist/useStreamRuntime.d.ts.map +1 -1
- package/dist/useStreamRuntime.js +213 -255
- package/dist/useStreamRuntime.js.map +1 -1
- package/package.json +11 -11
- package/src/useStreamRuntime.ts +6 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { LangChainBaseMessage } from "./types.js";
|
|
2
|
+
import { useExternalMessageConverter } from "@assistant-ui/core/react";
|
|
3
|
+
|
|
4
|
+
//#region src/convertMessages.d.ts
|
|
5
|
+
declare const getMessageType: (message: LangChainBaseMessage) => string;
|
|
6
|
+
declare const convertLangChainBaseMessage: useExternalMessageConverter.Callback<LangChainBaseMessage>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { convertLangChainBaseMessage, getMessageType };
|
|
5
9
|
//# sourceMappingURL=convertMessages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessages.d.ts","
|
|
1
|
+
{"version":3,"file":"convertMessages.d.ts","names":[],"sources":["../src/convertMessages.ts"],"mappings":";;;;cAMa,cAAA,GAAkB,OAA6B,EAApB,oBAAoB;AAAA,cAuD/C,2BAAA,EAA6B,2BAAA,CAA4B,QAAQ,CAC5E,oBAAA"}
|
package/dist/convertMessages.js
CHANGED
|
@@ -1,115 +1,103 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
throw new Error("Cannot determine message type");
|
|
2
|
+
//#region src/convertMessages.ts
|
|
3
|
+
const getMessageType = (message) => {
|
|
4
|
+
if (typeof message._getType === "function") return message._getType();
|
|
5
|
+
if ("type" in message) return message.type;
|
|
6
|
+
throw new Error("Cannot determine message type");
|
|
8
7
|
};
|
|
9
8
|
const contentToParts = (content) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
9
|
+
if (typeof content === "string") return [{
|
|
10
|
+
type: "text",
|
|
11
|
+
text: content
|
|
12
|
+
}];
|
|
13
|
+
return content.map((part) => {
|
|
14
|
+
switch (part.type) {
|
|
15
|
+
case "text":
|
|
16
|
+
case "text_delta": return {
|
|
17
|
+
type: "text",
|
|
18
|
+
text: part.text
|
|
19
|
+
};
|
|
20
|
+
case "image_url":
|
|
21
|
+
if (typeof part.image_url === "string") return {
|
|
22
|
+
type: "image",
|
|
23
|
+
image: part.image_url
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
type: "image",
|
|
27
|
+
image: part.image_url.url
|
|
28
|
+
};
|
|
29
|
+
case "thinking": return {
|
|
30
|
+
type: "reasoning",
|
|
31
|
+
text: part.thinking
|
|
32
|
+
};
|
|
33
|
+
case "reasoning": return {
|
|
34
|
+
type: "reasoning",
|
|
35
|
+
text: part.summary.map((s) => s.text).join("\n\n\n")
|
|
36
|
+
};
|
|
37
|
+
case "tool_use":
|
|
38
|
+
case "input_json_delta": return null;
|
|
39
|
+
default: return null;
|
|
40
|
+
}
|
|
41
|
+
}).filter((p) => p !== null);
|
|
40
42
|
};
|
|
41
43
|
const getCustomMetadata = (additionalKwargs) => additionalKwargs?.metadata ?? {};
|
|
42
44
|
const getStringContent = (content) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const parts = content;
|
|
46
|
-
return parts
|
|
47
|
-
.filter((c) => c.type === "text")
|
|
48
|
-
.map((c) => c.text)
|
|
49
|
-
.join("");
|
|
45
|
+
if (typeof content === "string") return content;
|
|
46
|
+
return content.filter((c) => c.type === "text").map((c) => c.text).join("");
|
|
50
47
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
role: "system",
|
|
103
|
-
id: message.id,
|
|
104
|
-
content: [
|
|
105
|
-
{
|
|
106
|
-
type: "text",
|
|
107
|
-
text: typeof message.content === "string"
|
|
108
|
-
? message.content
|
|
109
|
-
: JSON.stringify(message.content),
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
};
|
|
113
|
-
}
|
|
48
|
+
const convertLangChainBaseMessage = (message) => {
|
|
49
|
+
switch (getMessageType(message)) {
|
|
50
|
+
case "system": return {
|
|
51
|
+
role: "system",
|
|
52
|
+
id: message.id,
|
|
53
|
+
content: [{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: getStringContent(message.content)
|
|
56
|
+
}],
|
|
57
|
+
metadata: { custom: getCustomMetadata(message.additional_kwargs) }
|
|
58
|
+
};
|
|
59
|
+
case "human": return {
|
|
60
|
+
role: "user",
|
|
61
|
+
id: message.id,
|
|
62
|
+
content: contentToParts(message.content),
|
|
63
|
+
metadata: { custom: getCustomMetadata(message.additional_kwargs) }
|
|
64
|
+
};
|
|
65
|
+
case "ai": {
|
|
66
|
+
const toolCallParts = message.tool_calls?.map((tc) => ({
|
|
67
|
+
type: "tool-call",
|
|
68
|
+
toolCallId: tc.id,
|
|
69
|
+
toolName: tc.name,
|
|
70
|
+
args: tc.args,
|
|
71
|
+
argsText: JSON.stringify(tc.args)
|
|
72
|
+
})) ?? [];
|
|
73
|
+
const assistantStatus = typeof message.status === "object" ? message.status : void 0;
|
|
74
|
+
return {
|
|
75
|
+
role: "assistant",
|
|
76
|
+
id: message.id,
|
|
77
|
+
content: [...contentToParts(message.content), ...toolCallParts],
|
|
78
|
+
metadata: { custom: getCustomMetadata(message.additional_kwargs) },
|
|
79
|
+
...assistantStatus && { status: assistantStatus }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
case "tool": return {
|
|
83
|
+
role: "tool",
|
|
84
|
+
toolName: message.name ?? "",
|
|
85
|
+
toolCallId: message.tool_call_id ?? "",
|
|
86
|
+
result: message.content,
|
|
87
|
+
artifact: message.artifact,
|
|
88
|
+
isError: message.status === "error"
|
|
89
|
+
};
|
|
90
|
+
default: return {
|
|
91
|
+
role: "system",
|
|
92
|
+
id: message.id,
|
|
93
|
+
content: [{
|
|
94
|
+
type: "text",
|
|
95
|
+
text: typeof message.content === "string" ? message.content : JSON.stringify(message.content)
|
|
96
|
+
}]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
114
99
|
};
|
|
100
|
+
//#endregion
|
|
101
|
+
export { convertLangChainBaseMessage, getMessageType };
|
|
102
|
+
|
|
115
103
|
//# sourceMappingURL=convertMessages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessages.js","
|
|
1
|
+
{"version":3,"file":"convertMessages.js","names":["parts"],"sources":["../src/convertMessages.ts"],"sourcesContent":["\"use client\";\n\nimport type { useExternalMessageConverter } from \"@assistant-ui/core/react\";\nimport type { ReadonlyJSONObject } from \"assistant-stream/utils\";\nimport type { LangChainBaseMessage, LangChainContentBlock } from \"./types\";\n\nexport const getMessageType = (message: LangChainBaseMessage): string => {\n if (typeof message._getType === \"function\") return message._getType();\n if (\"type\" in message)\n return (message as Record<string, unknown>).type as string;\n throw new Error(\"Cannot determine message type\");\n};\n\nconst contentToParts = (content: unknown) => {\n if (typeof content === \"string\")\n return [{ type: \"text\" as const, text: content }];\n\n const parts = content as readonly LangChainContentBlock[];\n return parts\n .map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"text_delta\":\n return { type: \"text\" as const, text: part.text };\n case \"image_url\":\n if (typeof part.image_url === \"string\") {\n return { type: \"image\" as const, image: part.image_url };\n }\n return { type: \"image\" as const, image: part.image_url.url };\n case \"thinking\":\n return { type: \"reasoning\" as const, text: part.thinking };\n case \"reasoning\":\n return {\n type: \"reasoning\" as const,\n text: part.summary.map((s) => s.text).join(\"\\n\\n\\n\"),\n };\n case \"tool_use\":\n case \"input_json_delta\":\n return null;\n default:\n return null;\n }\n })\n .filter((p) => p !== null);\n};\n\nconst getCustomMetadata = (\n additionalKwargs: Record<string, unknown> | undefined,\n): Record<string, unknown> =>\n (additionalKwargs?.metadata as Record<string, unknown>) ?? {};\n\nconst getStringContent = (content: unknown): string => {\n if (typeof content === \"string\") return content;\n const parts = content as readonly LangChainContentBlock[];\n return parts\n .filter((c): c is { type: \"text\"; text: string } => c.type === \"text\")\n .map((c) => c.text)\n .join(\"\");\n};\n\nexport const convertLangChainBaseMessage: useExternalMessageConverter.Callback<\n LangChainBaseMessage\n> = (message) => {\n const type = getMessageType(message);\n\n switch (type) {\n case \"system\":\n return {\n role: \"system\",\n id: message.id,\n content: [{ type: \"text\", text: getStringContent(message.content) }],\n metadata: {\n custom: getCustomMetadata(message.additional_kwargs),\n },\n };\n\n case \"human\":\n return {\n role: \"user\",\n id: message.id,\n content: contentToParts(message.content),\n metadata: {\n custom: getCustomMetadata(message.additional_kwargs),\n },\n };\n\n case \"ai\": {\n const toolCallParts =\n message.tool_calls?.map((tc) => ({\n type: \"tool-call\" as const,\n toolCallId: tc.id,\n toolName: tc.name,\n args: tc.args as ReadonlyJSONObject,\n argsText: JSON.stringify(tc.args),\n })) ?? [];\n\n const assistantStatus =\n typeof message.status === \"object\" ? message.status : undefined;\n\n return {\n role: \"assistant\",\n id: message.id,\n content: [...contentToParts(message.content), ...toolCallParts],\n metadata: {\n custom: getCustomMetadata(message.additional_kwargs),\n },\n ...(assistantStatus && { status: assistantStatus }),\n };\n }\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 default:\n return {\n role: \"system\",\n id: message.id,\n content: [\n {\n type: \"text\",\n text:\n typeof message.content === \"string\"\n ? message.content\n : JSON.stringify(message.content),\n },\n ],\n };\n }\n};\n"],"mappings":";;AAMA,MAAa,kBAAkB,YAA0C;CACvE,IAAI,OAAO,QAAQ,aAAa,YAAY,OAAO,QAAQ,SAAS;CACpE,IAAI,UAAU,SACZ,OAAQ,QAAoC;CAC9C,MAAM,IAAI,MAAM,+BAA+B;AACjD;AAEA,MAAM,kBAAkB,YAAqB;CAC3C,IAAI,OAAO,YAAY,U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gBACJ,QAAQ,YAAY,KAAK,QAAQ;IAC/B,MAAM;IACN,YAAY,GAAG;IACf,UAAU,GAAG;IACb,MAAM,GAAG;IACT,UAAU,KAAK,UAAU,GAAG,IAAI;GAClC,EAAE,KAAK,CAAC;GAEV,MAAM,kBACJ,OAAO,QAAQ,WAAW,WAAW,QAAQ,SAAS,KAAA;GAExD,OAAO;IACL,MAAM;IACN,IAAI,QAAQ;IACZ,SAAS,CAAC,GAAG,eAAe,QAAQ,OAAO,GAAG,GAAG,aAAa;IAC9D,UAAU,EACR,QAAQ,kBAAkB,QAAQ,iBAAiB,EACrD;IACA,GAAI,mBAAmB,EAAE,QAAQ,gBAAgB;GACnD;EACF;EAEA,KAAK,QACH,OAAO;GACL,MAAM;GACN,UAAU,QAAQ,QAAQ;GAC1B,YAAY,QAAQ,gBAAgB;GACpC,QAAQ,QAAQ;GAChB,UAAU,QAAQ;GAClB,SAAS,QAAQ,WAAW;EAC9B;EAEF,SACE,OAAO;GACL,MAAM;GACN,IAAI,QAAQ;GACZ,SAAS,CACP;IACE,MAAM;IACN,MACE,OAAO,QAAQ,YAAY,WACvB,QAAQ,UACR,KAAK,UAAU,QAAQ,OAAO;GACtC,CACF;EACF;CACJ;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { LangChainBaseMessage, LangChainContentBlock, LangChainToolCall } from "./types.js";
|
|
2
|
+
import { convertLangChainBaseMessage } from "./convertMessages.js";
|
|
3
|
+
import { UseStreamRuntimeOptions, useLangChainInterruptState, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainSubmit, useStreamRuntime } from "./useStreamRuntime.js";
|
|
4
|
+
export { type LangChainBaseMessage, type LangChainContentBlock, type LangChainToolCall, type UseStreamRuntimeOptions, convertLangChainBaseMessage, useLangChainInterruptState, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainSubmit, useStreamRuntime };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { convertLangChainBaseMessage } from "./convertMessages.js";
|
|
2
|
+
import { useLangChainInterruptState, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainSubmit, useStreamRuntime } from "./useStreamRuntime.js";
|
|
3
|
+
export { convertLangChainBaseMessage, useLangChainInterruptState, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainSubmit, useStreamRuntime };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MessageStatus } from "@assistant-ui/core";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
2
4
|
/** Known content block types from @langchain/core messages. */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
type LangChainContentBlock = {
|
|
6
|
+
type: "text";
|
|
7
|
+
text: string;
|
|
6
8
|
} | {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
type: "text_delta";
|
|
10
|
+
text: string;
|
|
9
11
|
} | {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
type: "image_url";
|
|
13
|
+
image_url: string | {
|
|
14
|
+
url: string;
|
|
15
|
+
};
|
|
14
16
|
} | {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
type: "thinking";
|
|
18
|
+
thinking: string;
|
|
17
19
|
} | {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
type: "reasoning";
|
|
21
|
+
summary: Array<{
|
|
22
|
+
type: "summary_text";
|
|
23
|
+
text: string;
|
|
24
|
+
}>;
|
|
23
25
|
} | {
|
|
24
|
-
|
|
26
|
+
type: "tool_use" | "input_json_delta";
|
|
25
27
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
type LangChainToolCall = {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
args: Record<string, unknown>;
|
|
30
32
|
};
|
|
31
33
|
/**
|
|
32
34
|
* Minimal duck-typed interface for BaseMessage class instances returned by
|
|
@@ -35,19 +37,17 @@ export type LangChainToolCall = {
|
|
|
35
37
|
* Uses `unknown` for `content` to remain compatible with
|
|
36
38
|
* `@langchain/core`'s `MessageContent` union.
|
|
37
39
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/** Completion status (AIMessage) or outcome status (ToolMessage) */
|
|
49
|
-
status?: MessageStatus | "success" | "error" | undefined;
|
|
50
|
-
/** Present on ToolMessage */
|
|
51
|
-
artifact?: unknown;
|
|
40
|
+
type LangChainBaseMessage = {
|
|
41
|
+
_getType: () => string;
|
|
42
|
+
content: unknown;
|
|
43
|
+
id?: string | undefined;
|
|
44
|
+
name?: string | undefined;
|
|
45
|
+
additional_kwargs?: Record<string, unknown> | undefined; /** Present on AIMessage */
|
|
46
|
+
tool_calls?: readonly LangChainToolCall[] | undefined; /** Present on ToolMessage */
|
|
47
|
+
tool_call_id?: string | undefined; /** Completion status (AIMessage) or outcome status (ToolMessage) */
|
|
48
|
+
status?: MessageStatus | "success" | "error" | undefined; /** Present on ToolMessage */
|
|
49
|
+
artifact?: unknown;
|
|
52
50
|
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { LangChainBaseMessage, LangChainContentBlock, LangChainToolCall };
|
|
53
53
|
//# 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","names":[],"sources":["../src/types.ts"],"mappings":";;;;KAGY,qBAAA;EACN,IAAA;EAAc,IAAA;AAAA;EACd,IAAA;EAAoB,IAAA;AAAA;EACpB,IAAA;EAAmB,SAAA;IAAsB,GAAA;EAAA;AAAA;EACzC,IAAA;EAAkB,QAAA;AAAA;EAElB,IAAA;EACA,OAAA,EAAS,KAAK;IAAG,IAAA;IAAsB,IAAA;EAAA;AAAA;EAEvC,IAAA;AAAA;AAAA,KAEM,iBAAA;EACV,EAAA;EACA,IAAA;EACA,IAAA,EAAM,MAAM;AAAA;;;;AAAA;AAUd;;;KAAY,oBAAA;EACV,QAAA;EACA,OAAA;EACA,EAAA;EACA,IAAA;EACA,iBAAA,GAAoB,MAAA,+BAHpB;EAKA,UAAA,YAAsB,iBAAA,gBAHtB;EAKA,YAAA,uBAJoB;EAMpB,MAAA,GAAS,aAAA,oCAJa;EAMtB,QAAA;AAAA"}
|
package/dist/types.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { LangChainBaseMessage } from "./types.js";
|
|
2
|
+
import { UseStreamOptions } from "@langchain/react";
|
|
3
|
+
import { AttachmentAdapter, FeedbackAdapter, RemoteThreadListAdapter, SpeechSynthesisAdapter } from "@assistant-ui/core";
|
|
4
|
+
import { AssistantCloud } from "assistant-cloud";
|
|
5
|
+
|
|
6
|
+
//#region src/useStreamRuntime.d.ts
|
|
5
7
|
type LangChainRuntimeExtraOptions = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/** Custom thread-deletion hook, forwarded to the cloud adapter. */
|
|
34
|
-
delete?: ((threadId: string) => Promise<void>) | undefined;
|
|
8
|
+
cloud?: AssistantCloud | undefined;
|
|
9
|
+
adapters?: {
|
|
10
|
+
attachments?: AttachmentAdapter | undefined;
|
|
11
|
+
speech?: SpeechSynthesisAdapter | undefined;
|
|
12
|
+
feedback?: FeedbackAdapter | undefined;
|
|
13
|
+
} | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* When the user sends a new message while previous tool calls are
|
|
16
|
+
* still pending, automatically submit `tool` messages that cancel
|
|
17
|
+
* them so the agent's tool-call accounting stays consistent.
|
|
18
|
+
* Defaults to `true`.
|
|
19
|
+
*/
|
|
20
|
+
autoCancelPendingToolCalls?: boolean | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Routes the Cancel button's click to `useStream().stop()`. On by
|
|
23
|
+
* default. Pass `false` to disable the Cancel button.
|
|
24
|
+
*/
|
|
25
|
+
unstable_allowCancellation?: boolean | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Custom `RemoteThreadListAdapter`. When provided, replaces the
|
|
28
|
+
* cloud-backed thread list adapter.
|
|
29
|
+
*/
|
|
30
|
+
unstable_threadListAdapter?: RemoteThreadListAdapter | undefined; /** Custom thread-creation hook, forwarded to the cloud adapter. */
|
|
31
|
+
create?: (() => Promise<{
|
|
32
|
+
externalId: string | undefined;
|
|
33
|
+
}>) | undefined; /** Custom thread-deletion hook, forwarded to the cloud adapter. */
|
|
34
|
+
delete?: ((threadId: string) => Promise<void>) | undefined;
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
type UseStreamRuntimeOptions = UseStreamOptions extends infer O ? O extends UseStreamOptions ? O & LangChainRuntimeExtraOptions : never : never;
|
|
37
37
|
/**
|
|
38
38
|
* Creates an assistant-ui runtime backed by LangChain's `useStream` hook.
|
|
39
39
|
* Accepts the same options as `useStream` from `@langchain/react`, plus
|
|
@@ -58,25 +58,25 @@ export type UseStreamRuntimeOptions = UseStreamOptions extends infer O ? O exten
|
|
|
58
58
|
* }
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
declare const useStreamRuntime: (rawOptions: UseStreamRuntimeOptions) => import("@assistant-ui/core").AssistantRuntime;
|
|
62
62
|
/**
|
|
63
63
|
* Read the current LangGraph interrupt state from the runtime extras.
|
|
64
64
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
declare const useLangChainInterruptState: () => {
|
|
66
|
+
value?: unknown;
|
|
67
67
|
} | undefined;
|
|
68
68
|
/**
|
|
69
69
|
* Returns a function to submit raw state updates to the LangGraph agent,
|
|
70
70
|
* bypassing the normal message flow. Useful for sending interrupt resume
|
|
71
71
|
* commands.
|
|
72
72
|
*/
|
|
73
|
-
|
|
73
|
+
declare const useLangChainSubmit: () => (values: Record<string, unknown> | null | undefined, options?: Record<string, unknown>) => Promise<void>;
|
|
74
74
|
/**
|
|
75
75
|
* Submit a list of LangChain-shaped messages on the current thread.
|
|
76
76
|
* Parity helper for migrating from `useLangGraphSend`. Routes to
|
|
77
77
|
* `useStream().submit({ [messagesKey]: messages }, options)`.
|
|
78
78
|
*/
|
|
79
|
-
|
|
79
|
+
declare const useLangChainSend: () => (messages: readonly LangChainBaseMessage[], options?: Record<string, unknown>) => Promise<void>;
|
|
80
80
|
/**
|
|
81
81
|
* Submit a `useStream` command (e.g. interrupt resume). Parity helper
|
|
82
82
|
* for migrating from `useLangGraphSendCommand`. Note that v1's command
|
|
@@ -84,7 +84,7 @@ export declare const useLangChainSend: () => (messages: readonly LangChainBaseMe
|
|
|
84
84
|
* `{ resume: string }` form — to carry a payload, use the input or
|
|
85
85
|
* `stream.respond` instead.
|
|
86
86
|
*/
|
|
87
|
-
|
|
87
|
+
declare const useLangChainSendCommand: () => (command: Record<string, unknown>) => Promise<void>;
|
|
88
88
|
/**
|
|
89
89
|
* Read a custom LangGraph state key from the current thread. Mirrors
|
|
90
90
|
* `useStream().values[key]` from `@langchain/react` and updates when the
|
|
@@ -96,7 +96,8 @@ export declare const useLangChainSendCommand: () => (command: Record<string, unk
|
|
|
96
96
|
* const files = useLangChainState<Record<string, string>>("files", {});
|
|
97
97
|
* ```
|
|
98
98
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
declare function useLangChainState<T>(key: string): T | undefined;
|
|
100
|
+
declare function useLangChainState<T>(key: string, defaultValue: T): T;
|
|
101
|
+
//#endregion
|
|
102
|
+
export { UseStreamRuntimeOptions, useLangChainInterruptState, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainSubmit, useStreamRuntime };
|
|
102
103
|
//# sourceMappingURL=useStreamRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStreamRuntime.d.ts","
|
|
1
|
+
{"version":3,"file":"useStreamRuntime.d.ts","names":[],"sources":["../src/useStreamRuntime.ts"],"mappings":";;;;;;KAkDK,4BAAA;EACH,KAAA,GAAQ,cAAA;EACR,QAAA;IAEM,WAAA,GAAc,iBAAA;IACd,MAAA,GAAS,sBAAA;IACT,QAAA,GAAW,eAAA;EAAA;EADF;;;;;;EAUf,0BAAA;EAdA;;;;EAmBA,0BAAA;EAfM;;;;EAoBN,0BAAA,GAA6B,uBAAA,cAL7B;EAOA,MAAA,UAAgB,OAAA;IAAU,UAAA;EAAA,iBAAV;EAEhB,MAAA,KAAW,QAAA,aAAqB,OAAA;AAAA;AAAA,KAsBtB,uBAAA,GAA0B,gBAAA,mBAClC,CAAA,SAAU,gBAAA,GACR,CAAA,GAAI,4BAAA;;;AAxB+B;AAsBzC;;;;;;;;;;;;;;;;AAEsC;AA4OtC;;;;cAAa,gBAAA,GAAoB,UAAA,EAAY,uBAAuB,kCAAA,gBAAA;;;;cAgCvD,0BAAA;EAMZ,KAAA;AAAA;;;;AAOD;;cAAa,kBAAA,SAGT,MAAA,EAAQ,MAAA,sCACR,OAAA,GAAU,MAAA,sBAAuB,OAAA;;;;;;cAaxB,gBAAA,SAGT,QAAA,WAAmB,oBAAA,IACnB,OAAA,GAAU,MAAA,sBAAuB,OAAA;;;;;;AAjBA;AAarC;cAoBa,uBAAA,SAEH,OAAA,EAAS,MAAA,sBAAuB,OAAA;;;;;;;;;;;;iBAc1B,iBAAA,GAAA,CAAqB,GAAA,WAAc,CAAC;AAAA,iBACpC,iBAAA,GAAA,CAAqB,GAAA,UAAa,YAAA,EAAc,CAAA,GAAI,CAAC"}
|
package/dist/useStreamRuntime.js
CHANGED
|
@@ -1,280 +1,238 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { convertLangChainBaseMessage, getMessageType } from "./convertMessages.js";
|
|
2
3
|
import { useMemo, useRef, useState } from "react";
|
|
3
|
-
import { useCloudThreadListAdapter,
|
|
4
|
+
import { useCloudThreadListAdapter, useExternalMessageConverter, useExternalStoreRuntime, useRemoteThreadListRuntime, useToolInvocations } from "@assistant-ui/core/react";
|
|
4
5
|
import { useAui, useAuiState } from "@assistant-ui/store";
|
|
5
6
|
import { useStream } from "@langchain/react";
|
|
6
|
-
|
|
7
|
+
//#region src/useStreamRuntime.ts
|
|
7
8
|
const symbolLangChainRuntimeExtras = Symbol("langchain-runtime-extras");
|
|
8
9
|
const asLangChainRuntimeExtras = (extras) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
!(symbolLangChainRuntimeExtras in extras))
|
|
12
|
-
throw new Error("This method can only be called when you are using useStreamRuntime");
|
|
13
|
-
return extras;
|
|
10
|
+
if (typeof extras !== "object" || extras == null || !(symbolLangChainRuntimeExtras in extras)) throw new Error("This method can only be called when you are using useStreamRuntime");
|
|
11
|
+
return extras;
|
|
14
12
|
};
|
|
15
13
|
const getPendingToolCalls = (messages) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
else if (type === "tool" && m.tool_call_id) {
|
|
24
|
-
pending.delete(m.tool_call_id);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return [...pending.values()];
|
|
14
|
+
const pending = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const m of messages) {
|
|
16
|
+
const type = getMessageType(m);
|
|
17
|
+
if (type === "ai") for (const tc of m.tool_calls ?? []) pending.set(tc.id, tc);
|
|
18
|
+
else if (type === "tool" && m.tool_call_id) pending.delete(m.tool_call_id);
|
|
19
|
+
}
|
|
20
|
+
return [...pending.values()];
|
|
28
21
|
};
|
|
29
22
|
const getMessageContent = (msg) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
if (content.length === 1 && content[0]?.type === "text") {
|
|
63
|
-
return content[0].text ?? "";
|
|
64
|
-
}
|
|
65
|
-
return content;
|
|
23
|
+
const allContent = [...msg.content, ...msg.attachments?.flatMap((a) => a.content) ?? []];
|
|
24
|
+
const hasNonText = allContent.some((part) => part.type === "file" || part.type === "image");
|
|
25
|
+
const hasText = allContent.some((part) => part.type === "text");
|
|
26
|
+
if (hasNonText && !hasText) allContent.unshift({
|
|
27
|
+
type: "text",
|
|
28
|
+
text: " "
|
|
29
|
+
});
|
|
30
|
+
const content = allContent.map((part) => {
|
|
31
|
+
const type = part.type;
|
|
32
|
+
switch (type) {
|
|
33
|
+
case "text": return {
|
|
34
|
+
type: "text",
|
|
35
|
+
text: part.text
|
|
36
|
+
};
|
|
37
|
+
case "image": return {
|
|
38
|
+
type: "image_url",
|
|
39
|
+
image_url: { url: part.image }
|
|
40
|
+
};
|
|
41
|
+
case "file": return {
|
|
42
|
+
type: "file",
|
|
43
|
+
data: part.data,
|
|
44
|
+
mime_type: part.mimeType,
|
|
45
|
+
metadata: { filename: part.filename ?? "file" },
|
|
46
|
+
source_type: "base64"
|
|
47
|
+
};
|
|
48
|
+
case "tool-call": throw new Error("Tool call appends are not supported.");
|
|
49
|
+
default: throw new Error(`Unsupported append message part type: ${type}`);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
if (content.length === 1 && content[0]?.type === "text") return content[0].text ?? "";
|
|
53
|
+
return content;
|
|
66
54
|
};
|
|
67
55
|
const useStreamThreadRuntime = (options) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
status: "error",
|
|
152
|
-
}))
|
|
153
|
-
: [];
|
|
154
|
-
await stream.submit({
|
|
155
|
-
[messagesKey]: [...cancellations, { type: "human", content }],
|
|
156
|
-
});
|
|
157
|
-
},
|
|
158
|
-
onAddToolResult: async ({ toolCallId, toolName, result, isError, artifact, }) => {
|
|
159
|
-
await stream.submit({
|
|
160
|
-
[messagesKey]: [
|
|
161
|
-
{
|
|
162
|
-
type: "tool",
|
|
163
|
-
name: toolName,
|
|
164
|
-
tool_call_id: toolCallId,
|
|
165
|
-
content: JSON.stringify(result),
|
|
166
|
-
...(artifact !== undefined && { artifact }),
|
|
167
|
-
status: isError ? "error" : "success",
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
onCancel: unstable_allowCancellation !== false
|
|
173
|
-
? async () => {
|
|
174
|
-
await stream.stop();
|
|
175
|
-
await toolInvocations.abort();
|
|
176
|
-
}
|
|
177
|
-
: undefined,
|
|
178
|
-
});
|
|
179
|
-
return runtime;
|
|
56
|
+
const { adapters, autoCancelPendingToolCalls, unstable_allowCancellation } = options;
|
|
57
|
+
const messagesKey = options.messagesKey ?? "messages";
|
|
58
|
+
options.threadId = useAuiState((s) => s.threadListItem.externalId);
|
|
59
|
+
const stream = useStream(options);
|
|
60
|
+
const [toolStatuses, setToolStatuses] = useState({});
|
|
61
|
+
const hasExecutingTools = Object.values(toolStatuses).some((s) => s?.type === "executing");
|
|
62
|
+
const effectiveIsRunning = stream.isLoading || hasExecutingTools;
|
|
63
|
+
const threadMessages = useExternalMessageConverter({
|
|
64
|
+
callback: convertLangChainBaseMessage,
|
|
65
|
+
messages: stream.messages,
|
|
66
|
+
isRunning: effectiveIsRunning
|
|
67
|
+
});
|
|
68
|
+
const [runtimeRef] = useState(() => ({ get current() {
|
|
69
|
+
return runtime;
|
|
70
|
+
} }));
|
|
71
|
+
const streamRef = useRef(stream);
|
|
72
|
+
streamRef.current = stream;
|
|
73
|
+
const toolInvocations = useToolInvocations({
|
|
74
|
+
state: {
|
|
75
|
+
messages: threadMessages,
|
|
76
|
+
isRunning: effectiveIsRunning
|
|
77
|
+
},
|
|
78
|
+
getTools: () => runtimeRef.current.thread.getModelContext().tools,
|
|
79
|
+
onResult: (command) => {
|
|
80
|
+
if (command.type === "add-tool-result") streamRef.current.submit({ [messagesKey]: [{
|
|
81
|
+
type: "tool",
|
|
82
|
+
name: command.toolName,
|
|
83
|
+
tool_call_id: command.toolCallId,
|
|
84
|
+
content: JSON.stringify(command.result),
|
|
85
|
+
status: command.isError ? "error" : "success"
|
|
86
|
+
}] }, {});
|
|
87
|
+
},
|
|
88
|
+
setToolStatuses
|
|
89
|
+
});
|
|
90
|
+
const runtime = useExternalStoreRuntime({
|
|
91
|
+
isRunning: effectiveIsRunning,
|
|
92
|
+
messages: threadMessages,
|
|
93
|
+
adapters,
|
|
94
|
+
extras: useMemo(() => ({
|
|
95
|
+
[symbolLangChainRuntimeExtras]: true,
|
|
96
|
+
interrupt: stream.interrupt,
|
|
97
|
+
interrupts: stream.interrupts,
|
|
98
|
+
submit: stream.submit,
|
|
99
|
+
values: stream.values,
|
|
100
|
+
messagesKey
|
|
101
|
+
}), [
|
|
102
|
+
stream.interrupt,
|
|
103
|
+
stream.interrupts,
|
|
104
|
+
stream.submit,
|
|
105
|
+
stream.values,
|
|
106
|
+
messagesKey
|
|
107
|
+
]),
|
|
108
|
+
onNew: async (msg) => {
|
|
109
|
+
await toolInvocations.abort();
|
|
110
|
+
const content = getMessageContent(msg);
|
|
111
|
+
const cancellations = autoCancelPendingToolCalls !== false ? getPendingToolCalls(streamRef.current.messages).map((t) => ({
|
|
112
|
+
type: "tool",
|
|
113
|
+
name: t.name,
|
|
114
|
+
tool_call_id: t.id,
|
|
115
|
+
content: JSON.stringify({ cancelled: true }),
|
|
116
|
+
status: "error"
|
|
117
|
+
})) : [];
|
|
118
|
+
await stream.submit({ [messagesKey]: [...cancellations, {
|
|
119
|
+
type: "human",
|
|
120
|
+
content
|
|
121
|
+
}] });
|
|
122
|
+
},
|
|
123
|
+
onAddToolResult: async ({ toolCallId, toolName, result, isError, artifact }) => {
|
|
124
|
+
await stream.submit({ [messagesKey]: [{
|
|
125
|
+
type: "tool",
|
|
126
|
+
name: toolName,
|
|
127
|
+
tool_call_id: toolCallId,
|
|
128
|
+
content: JSON.stringify(result),
|
|
129
|
+
...artifact !== void 0 && { artifact },
|
|
130
|
+
status: isError ? "error" : "success"
|
|
131
|
+
}] });
|
|
132
|
+
},
|
|
133
|
+
onCancel: unstable_allowCancellation !== false ? async () => {
|
|
134
|
+
await stream.stop();
|
|
135
|
+
await toolInvocations.abort();
|
|
136
|
+
} : void 0
|
|
137
|
+
});
|
|
138
|
+
return runtime;
|
|
180
139
|
};
|
|
181
140
|
/**
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
allowNesting: true,
|
|
222
|
-
});
|
|
141
|
+
* Creates an assistant-ui runtime backed by LangChain's `useStream` hook.
|
|
142
|
+
* Accepts the same options as `useStream` from `@langchain/react`, plus
|
|
143
|
+
* `cloud` and `adapters`.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```tsx
|
|
147
|
+
* import { useStreamRuntime } from "@assistant-ui/react-langchain";
|
|
148
|
+
* import { AssistantRuntimeProvider, Thread } from "@assistant-ui/react";
|
|
149
|
+
*
|
|
150
|
+
* function App() {
|
|
151
|
+
* const runtime = useStreamRuntime({
|
|
152
|
+
* assistantId: "agent",
|
|
153
|
+
* apiUrl: "http://localhost:2024",
|
|
154
|
+
* });
|
|
155
|
+
*
|
|
156
|
+
* return (
|
|
157
|
+
* <AssistantRuntimeProvider runtime={runtime}>
|
|
158
|
+
* <Thread />
|
|
159
|
+
* </AssistantRuntimeProvider>
|
|
160
|
+
* );
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
const useStreamRuntime = (rawOptions) => {
|
|
165
|
+
const { cloud, unstable_threadListAdapter, create, delete: deleteFn, ...options } = rawOptions;
|
|
166
|
+
const optionsRef = useRef(options);
|
|
167
|
+
optionsRef.current = options;
|
|
168
|
+
const cloudAdapter = useCloudThreadListAdapter({
|
|
169
|
+
cloud,
|
|
170
|
+
create,
|
|
171
|
+
delete: deleteFn
|
|
172
|
+
});
|
|
173
|
+
return useRemoteThreadListRuntime({
|
|
174
|
+
runtimeHook: function RuntimeHook() {
|
|
175
|
+
return useStreamThreadRuntime(optionsRef.current);
|
|
176
|
+
},
|
|
177
|
+
adapter: unstable_threadListAdapter ?? cloudAdapter,
|
|
178
|
+
allowNesting: true
|
|
179
|
+
});
|
|
223
180
|
};
|
|
224
181
|
/**
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
});
|
|
182
|
+
* Read the current LangGraph interrupt state from the runtime extras.
|
|
183
|
+
*/
|
|
184
|
+
const useLangChainInterruptState = () => {
|
|
185
|
+
return useAuiState((s) => {
|
|
186
|
+
const extras = s.thread.extras;
|
|
187
|
+
if (!extras) return void 0;
|
|
188
|
+
return asLangChainRuntimeExtras(extras).interrupt;
|
|
189
|
+
});
|
|
234
190
|
};
|
|
235
191
|
/**
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
192
|
+
* Returns a function to submit raw state updates to the LangGraph agent,
|
|
193
|
+
* bypassing the normal message flow. Useful for sending interrupt resume
|
|
194
|
+
* commands.
|
|
195
|
+
*/
|
|
196
|
+
const useLangChainSubmit = () => {
|
|
197
|
+
const aui = useAui();
|
|
198
|
+
return (values, options) => {
|
|
199
|
+
const extras = aui.thread().getState().extras;
|
|
200
|
+
const { submit } = asLangChainRuntimeExtras(extras);
|
|
201
|
+
return submit(values, options);
|
|
202
|
+
};
|
|
247
203
|
};
|
|
248
204
|
/**
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
205
|
+
* Submit a list of LangChain-shaped messages on the current thread.
|
|
206
|
+
* Parity helper for migrating from `useLangGraphSend`. Routes to
|
|
207
|
+
* `useStream().submit({ [messagesKey]: messages }, options)`.
|
|
208
|
+
*/
|
|
209
|
+
const useLangChainSend = () => {
|
|
210
|
+
const aui = useAui();
|
|
211
|
+
return (messages, options) => {
|
|
212
|
+
const { submit, messagesKey } = asLangChainRuntimeExtras(aui.thread().getState().extras);
|
|
213
|
+
return submit({ [messagesKey]: messages }, options);
|
|
214
|
+
};
|
|
259
215
|
};
|
|
260
216
|
/**
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
217
|
+
* Submit a `useStream` command (e.g. interrupt resume). Parity helper
|
|
218
|
+
* for migrating from `useLangGraphSendCommand`. Note that v1's command
|
|
219
|
+
* shape (`{ resume?, goto?, update? }`) differs from the legacy
|
|
220
|
+
* `{ resume: string }` form — to carry a payload, use the input or
|
|
221
|
+
* `stream.respond` instead.
|
|
222
|
+
*/
|
|
223
|
+
const useLangChainSendCommand = () => {
|
|
224
|
+
const submit = useLangChainSubmit();
|
|
225
|
+
return (command) => submit(null, { command });
|
|
270
226
|
};
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
});
|
|
227
|
+
function useLangChainState(key, defaultValue) {
|
|
228
|
+
return useAuiState((s) => {
|
|
229
|
+
const extras = s.thread.extras;
|
|
230
|
+
if (!extras) return defaultValue;
|
|
231
|
+
const value = asLangChainRuntimeExtras(extras).values[key];
|
|
232
|
+
return value !== void 0 ? value : defaultValue;
|
|
233
|
+
});
|
|
279
234
|
}
|
|
235
|
+
//#endregion
|
|
236
|
+
export { useLangChainInterruptState, useLangChainSend, useLangChainSendCommand, useLangChainState, useLangChainSubmit, useStreamRuntime };
|
|
237
|
+
|
|
280
238
|
//# sourceMappingURL=useStreamRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStreamRuntime.js","sourceRoot":"","sources":["../src/useStreamRuntime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAQlD,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,EAC3B,0BAA0B,EAC1B,kBAAkB,GAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,SAAS,EAAyB,M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,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,MAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;IACpC,OAAO,CAAC,OAAgC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AACzE,CAAC,CAAC;AAeF,MAAM,UAAU,iBAAiB,CAC/B,GAAW,EACX,YAAgB;IAEhB,OAAO,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE;QACvB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;QAC/B,IAAI,CAAC,MAAM;YAAE,OAAO,YAAY,CAAC;QACjC,MAAM,KAAK,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,CAAkB,CAAC;QAC5E,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
1
|
+
{"version":3,"file":"useStreamRuntime.js","names":["_exhaustiveCheck"],"sources":["../src/useStreamRuntime.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useRef, useState } from \"react\";\nimport type {\n AppendMessage,\n AttachmentAdapter,\n FeedbackAdapter,\n RemoteThreadListAdapter,\n SpeechSynthesisAdapter,\n} from \"@assistant-ui/core\";\nimport {\n useCloudThreadListAdapter,\n useExternalStoreRuntime,\n useExternalMessageConverter,\n useRemoteThreadListRuntime,\n useToolInvocations,\n type ToolExecutionStatus,\n} from \"@assistant-ui/core/react\";\nimport { useAui, useAuiState } from \"@assistant-ui/store\";\nimport type { AssistantCloud } from \"assistant-cloud\";\nimport { useStream, type UseStreamOptions } from \"@langchain/react\";\nimport type { LangChainBaseMessage, LangChainToolCall } from \"./types\";\nimport { convertLangChainBaseMessage, getMessageType } from \"./convertMessages\";\n\nconst symbolLangChainRuntimeExtras = Symbol(\"langchain-runtime-extras\");\n\ntype LangChainRuntimeExtras = {\n [symbolLangChainRuntimeExtras]: true;\n interrupt: { value?: unknown } | undefined;\n interrupts: readonly { value?: unknown }[];\n submit: (\n values: Record<string, unknown> | null | undefined,\n options?: Record<string, unknown>,\n ) => Promise<void>;\n values: Record<string, unknown>;\n messagesKey: string;\n};\n\nconst asLangChainRuntimeExtras = (extras: unknown): LangChainRuntimeExtras => {\n if (\n typeof extras !== \"object\" ||\n extras == null ||\n !(symbolLangChainRuntimeExtras in extras)\n )\n throw new Error(\n \"This method can only be called when you are using useStreamRuntime\",\n );\n return extras as LangChainRuntimeExtras;\n};\n\ntype LangChainRuntimeExtraOptions = {\n cloud?: AssistantCloud | undefined;\n adapters?:\n | {\n attachments?: AttachmentAdapter | undefined;\n speech?: SpeechSynthesisAdapter | undefined;\n feedback?: FeedbackAdapter | undefined;\n }\n | undefined;\n /**\n * When the user sends a new message while previous tool calls are\n * still pending, automatically submit `tool` messages that cancel\n * them so the agent's tool-call accounting stays consistent.\n * Defaults to `true`.\n */\n autoCancelPendingToolCalls?: boolean | undefined;\n /**\n * Routes the Cancel button's click to `useStream().stop()`. On by\n * default. Pass `false` to disable the Cancel button.\n */\n unstable_allowCancellation?: boolean | undefined;\n /**\n * Custom `RemoteThreadListAdapter`. When provided, replaces the\n * cloud-backed thread list adapter.\n */\n unstable_threadListAdapter?: RemoteThreadListAdapter | undefined;\n /** Custom thread-creation hook, forwarded to the cloud adapter. */\n create?: (() => Promise<{ externalId: string | undefined }>) | undefined;\n /** Custom thread-deletion hook, forwarded to the cloud adapter. */\n delete?: ((threadId: string) => Promise<void>) | undefined;\n};\n\nconst getPendingToolCalls = (\n messages: readonly LangChainBaseMessage[],\n): LangChainToolCall[] => {\n const pending = new Map<string, LangChainToolCall>();\n for (const m of messages) {\n const type = getMessageType(m);\n if (type === \"ai\") {\n for (const tc of m.tool_calls ?? []) pending.set(tc.id, tc);\n } else if (type === \"tool\" && m.tool_call_id) {\n pending.delete(m.tool_call_id);\n }\n }\n return [...pending.values()];\n};\n\n// Distribute the intersection through the union arms of `UseStreamOptions`\n// (`AgentServerOptions | CustomAdapterOptions`). Writing `UseStreamOptions & X`\n// directly collapses arm tracking, so `Omit<…, \"cloud\">` and the like would\n// produce a flattened structural type that no longer matches either arm.\nexport type UseStreamRuntimeOptions = UseStreamOptions extends infer O\n ? O extends UseStreamOptions\n ? O & LangChainRuntimeExtraOptions\n : never\n : never;\n\nconst 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) => part.type === \"file\" || part.type === \"image\",\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.map((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 return {\n type: \"file\" as const,\n data: part.data,\n mime_type: part.mimeType,\n metadata: { filename: part.filename ?? \"file\" },\n source_type: \"base64\" as const,\n };\n case \"tool-call\":\n throw new Error(\"Tool call appends are not supported.\");\n default: {\n const _exhaustiveCheck:\n | \"reasoning\"\n | \"source\"\n | \"audio\"\n | \"data\"\n | \"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\ntype DistributiveOmit<T, K extends keyof any> = T extends unknown\n ? Omit<T, K>\n : never;\n\nconst useStreamThreadRuntime = (\n options: DistributiveOmit<\n UseStreamRuntimeOptions,\n \"cloud\" | \"unstable_threadListAdapter\" | \"create\" | \"delete\"\n >,\n) => {\n const { adapters, autoCancelPendingToolCalls, unstable_allowCancellation } =\n options;\n const messagesKey = options.messagesKey ?? \"messages\";\n\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n const externalId = useAuiState((s) => s.threadListItem.externalId) as\n | string\n | null;\n // Mutate in place rather than `{ ...options, threadId }`: spreading\n // `UseStreamOptions` (a discriminated union on `transport`) into an object\n // literal merges both arms' transport types, breaking arm assignment.\n options.threadId = externalId;\n\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n const stream = useStream(options);\n\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n const [toolStatuses, setToolStatuses] = useState<\n Record<string, ToolExecutionStatus>\n >({});\n const hasExecutingTools = Object.values(toolStatuses).some(\n (s) => s?.type === \"executing\",\n );\n const effectiveIsRunning = stream.isLoading || hasExecutingTools;\n\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n const threadMessages = useExternalMessageConverter({\n callback: convertLangChainBaseMessage,\n messages: stream.messages as LangChainBaseMessage[],\n isRunning: effectiveIsRunning,\n });\n\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n const [runtimeRef] = useState(() => ({\n get current() {\n return runtime;\n },\n }));\n\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n const streamRef = useRef(stream);\n streamRef.current = stream;\n\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n const toolInvocations = useToolInvocations({\n state: {\n messages: threadMessages,\n isRunning: effectiveIsRunning,\n },\n getTools: () => runtimeRef.current.thread.getModelContext().tools,\n onResult: (command) => {\n if (command.type === \"add-tool-result\") {\n void streamRef.current.submit(\n {\n [messagesKey]: [\n {\n type: \"tool\",\n name: command.toolName,\n tool_call_id: command.toolCallId,\n content: JSON.stringify(command.result),\n status: command.isError ? \"error\" : \"success\",\n },\n ],\n },\n {},\n );\n }\n },\n setToolStatuses,\n });\n\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n const extras = useMemo(\n (): LangChainRuntimeExtras => ({\n [symbolLangChainRuntimeExtras]: true,\n interrupt: stream.interrupt,\n interrupts: stream.interrupts,\n submit: stream.submit,\n values: stream.values,\n messagesKey,\n }),\n [\n stream.interrupt,\n stream.interrupts,\n stream.submit,\n stream.values,\n messagesKey,\n ],\n );\n\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n const runtime = useExternalStoreRuntime({\n isRunning: effectiveIsRunning,\n messages: threadMessages,\n adapters,\n extras,\n onNew: async (msg) => {\n await toolInvocations.abort();\n const content = getMessageContent(msg);\n const cancellations =\n autoCancelPendingToolCalls !== false\n ? getPendingToolCalls(\n streamRef.current.messages as readonly LangChainBaseMessage[],\n ).map((t) => ({\n type: \"tool\" as const,\n name: t.name,\n tool_call_id: t.id,\n content: JSON.stringify({ cancelled: true }),\n status: \"error\" as const,\n }))\n : [];\n await stream.submit({\n [messagesKey]: [...cancellations, { type: \"human\", content }],\n });\n },\n onAddToolResult: async ({\n toolCallId,\n toolName,\n result,\n isError,\n artifact,\n }) => {\n await stream.submit({\n [messagesKey]: [\n {\n type: \"tool\",\n name: toolName,\n tool_call_id: toolCallId,\n content: JSON.stringify(result),\n ...(artifact !== undefined && { artifact }),\n status: isError ? \"error\" : \"success\",\n },\n ],\n });\n },\n onCancel:\n unstable_allowCancellation !== false\n ? async () => {\n await stream.stop();\n await toolInvocations.abort();\n }\n : undefined,\n });\n\n return runtime;\n};\n\n/**\n * Creates an assistant-ui runtime backed by LangChain's `useStream` hook.\n * Accepts the same options as `useStream` from `@langchain/react`, plus\n * `cloud` and `adapters`.\n *\n * @example\n * ```tsx\n * import { useStreamRuntime } from \"@assistant-ui/react-langchain\";\n * import { AssistantRuntimeProvider, Thread } from \"@assistant-ui/react\";\n *\n * function App() {\n * const runtime = useStreamRuntime({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * });\n *\n * return (\n * <AssistantRuntimeProvider runtime={runtime}>\n * <Thread />\n * </AssistantRuntimeProvider>\n * );\n * }\n * ```\n */\nexport const useStreamRuntime = (rawOptions: UseStreamRuntimeOptions) => {\n const {\n cloud,\n unstable_threadListAdapter,\n create,\n delete: deleteFn,\n ...options\n } = rawOptions;\n\n const optionsRef = useRef(options);\n optionsRef.current = options;\n\n const cloudAdapter = useCloudThreadListAdapter({\n cloud,\n create,\n delete: deleteFn,\n });\n const adapter = unstable_threadListAdapter ?? cloudAdapter;\n\n return useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n // biome-ignore lint/correctness/useHookAtTopLevel: intentional conditional/nested hook usage\n return useStreamThreadRuntime(optionsRef.current);\n },\n adapter,\n allowNesting: true,\n });\n};\n\n/**\n * Read the current LangGraph interrupt state from the runtime extras.\n */\nexport const useLangChainInterruptState = () => {\n return useAuiState((s) => {\n const extras = s.thread.extras;\n if (!extras) return undefined;\n return asLangChainRuntimeExtras(extras).interrupt;\n });\n};\n\n/**\n * Returns a function to submit raw state updates to the LangGraph agent,\n * bypassing the normal message flow. Useful for sending interrupt resume\n * commands.\n */\nexport const useLangChainSubmit = () => {\n const aui = useAui();\n return (\n values: Record<string, unknown> | null | undefined,\n options?: Record<string, unknown>,\n ) => {\n const extras = aui.thread().getState().extras;\n const { submit } = asLangChainRuntimeExtras(extras);\n return submit(values, options);\n };\n};\n\n/**\n * Submit a list of LangChain-shaped messages on the current thread.\n * Parity helper for migrating from `useLangGraphSend`. Routes to\n * `useStream().submit({ [messagesKey]: messages }, options)`.\n */\nexport const useLangChainSend = () => {\n const aui = useAui();\n return (\n messages: readonly LangChainBaseMessage[],\n options?: Record<string, unknown>,\n ) => {\n const { submit, messagesKey } = asLangChainRuntimeExtras(\n aui.thread().getState().extras,\n );\n return submit({ [messagesKey]: messages }, options);\n };\n};\n\n/**\n * Submit a `useStream` command (e.g. interrupt resume). Parity helper\n * for migrating from `useLangGraphSendCommand`. Note that v1's command\n * shape (`{ resume?, goto?, update? }`) differs from the legacy\n * `{ resume: string }` form — to carry a payload, use the input or\n * `stream.respond` instead.\n */\nexport const useLangChainSendCommand = () => {\n const submit = useLangChainSubmit();\n return (command: Record<string, unknown>) => submit(null, { command });\n};\n\n/**\n * Read a custom LangGraph state key from the current thread. Mirrors\n * `useStream().values[key]` from `@langchain/react` and updates when the\n * stream emits new state.\n *\n * @example\n * ```tsx\n * const todos = useLangChainState<Todo[]>(\"todos\");\n * const files = useLangChainState<Record<string, string>>(\"files\", {});\n * ```\n */\nexport function useLangChainState<T>(key: string): T | undefined;\nexport function useLangChainState<T>(key: string, defaultValue: T): T;\nexport function useLangChainState<T>(\n key: string,\n defaultValue?: T,\n): T | undefined {\n return useAuiState((s) => {\n const extras = s.thread.extras;\n if (!extras) return defaultValue;\n const value = asLangChainRuntimeExtras(extras).values[key] as T | undefined;\n return value !== undefined ? value : defaultValue;\n });\n}\n"],"mappings":";;;;;;;AAwBA,MAAM,+BAA+B,OAAO,0BAA0B;AActE,MAAM,4BAA4B,WAA4C;CAC5E,IACE,OAAO,WAAW,YAClB,UAAU,QACV,EAAE,gCAAgC,SAElC,MAAM,IAAI,MACR,oEACF;CACF,OAAO;AACT;AAkCA,MAAM,uBACJ,aACwB;CACxB,MAAM,0BAAU,IAAI,IAA+B;CACnD,KAAK,MAAM,KAAK,UAAU;EACxB,MAAM,OAAO,eAAe,CAAC;EAC7B,IAAI,SAAS,MACX,KAAK,MAAM,MAAM,EAAE,cAAc,CAAC,GAAG,QAAQ,IAAI,GAAG,IAAI,EAAE;OACrD,IAAI,SAAS,UAAU,EAAE,cAC9B,QAAQ,OAAO,EAAE,YAAY;CAEjC;CACA,OAAO,CAAC,GAAG,QAAQ,OAAO,CAAC;AAC7B;AAYA,MAAM,qBAAqB,QAAuB;CAChD,MAAM,aAAa,CACjB,GAAG,IAAI,SACP,GAAI,IAAI,aAAa,SAAS,MAAM,EAAE,OAAO,KAAK,CAAC,CACrD;CAEA,MAAM,aAAa,WAAW,MAC3B,SAAS,KAAK,SAAS,UAAU,KAAK,SAAS,OAClD;CACA,MAAM,UAAU,WAAW,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AAS,EAAE,OAAO;EACxB,IAAI,CAAC,QAAQ,OAAO;EACpB,MAAM,QAAQ,yBAAyB,MAAM,EAAE,OAAO;EACtD,OAAO,UAAU,KAAA,IAAY,QAAQ;CACvC,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react-langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "LangChain useStream adapter for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"langchain",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
],
|
|
30
30
|
"sideEffects": false,
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@assistant-ui/core": "^0.2.
|
|
33
|
-
"@assistant-ui/store": "^0.2.
|
|
32
|
+
"@assistant-ui/core": "^0.2.5",
|
|
33
|
+
"@assistant-ui/store": "^0.2.12",
|
|
34
34
|
"assistant-cloud": "*",
|
|
35
|
-
"assistant-stream": "^0.3.
|
|
35
|
+
"assistant-stream": "^0.3.16"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@langchain/react": "^1.0.2",
|
|
@@ -45,15 +45,15 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@langchain/core": "^1.1.
|
|
49
|
-
"@langchain/langgraph-sdk": "^1.9.
|
|
50
|
-
"@langchain/react": "^1.0.
|
|
48
|
+
"@langchain/core": "^1.1.47",
|
|
49
|
+
"@langchain/langgraph-sdk": "^1.9.4",
|
|
50
|
+
"@langchain/react": "^1.0.4",
|
|
51
51
|
"@testing-library/react": "^16.3.2",
|
|
52
|
-
"@types/react": "^19.2.
|
|
52
|
+
"@types/react": "^19.2.15",
|
|
53
53
|
"jsdom": "^29.1.1",
|
|
54
|
-
"react": "^19.2.
|
|
55
|
-
"vitest": "^4.1.
|
|
56
|
-
"@assistant-ui/x-buildutils": "0.0.
|
|
54
|
+
"react": "^19.2.6",
|
|
55
|
+
"vitest": "^4.1.7",
|
|
56
|
+
"@assistant-ui/x-buildutils": "0.0.9"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public",
|
package/src/useStreamRuntime.ts
CHANGED
|
@@ -137,8 +137,12 @@ const getMessageContent = (msg: AppendMessage) => {
|
|
|
137
137
|
case "tool-call":
|
|
138
138
|
throw new Error("Tool call appends are not supported.");
|
|
139
139
|
default: {
|
|
140
|
-
const _exhaustiveCheck:
|
|
141
|
-
|
|
140
|
+
const _exhaustiveCheck:
|
|
141
|
+
| "reasoning"
|
|
142
|
+
| "source"
|
|
143
|
+
| "audio"
|
|
144
|
+
| "data"
|
|
145
|
+
| "generative-ui" = type;
|
|
142
146
|
throw new Error(
|
|
143
147
|
`Unsupported append message part type: ${_exhaustiveCheck}`,
|
|
144
148
|
);
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,GACnB,8BAA2B;AAC5B,YAAY,EAAE,uBAAuB,EAAE,8BAA2B;AAElE,OAAO,EAAE,2BAA2B,EAAE,6BAA0B;AAEhE,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,GAClB,mBAAgB"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,GACnB,8BAA2B;AAG5B,OAAO,EAAE,2BAA2B,EAAE,6BAA0B"}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|