@assistant-ui/react-ai-sdk 0.10.11 → 0.10.13
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/rsc/useVercelRSCRuntime.js +1 -1
- package/dist/rsc/useVercelRSCRuntime.js.map +1 -1
- package/dist/ui/utils/convertMessage.d.ts.map +1 -1
- package/dist/ui/utils/convertMessage.js +54 -48
- package/dist/ui/utils/convertMessage.js.map +1 -1
- package/dist/useChatRuntime.d.ts +1 -2
- package/dist/useChatRuntime.d.ts.map +1 -1
- package/dist/useChatRuntime.js.map +1 -1
- package/dist/useCloudRuntime.d.ts +12 -0
- package/dist/useCloudRuntime.d.ts.map +1 -0
- package/dist/useCloudRuntime.js +15 -0
- package/dist/useCloudRuntime.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +1 -0
- package/src/rsc/useVercelRSCRuntime.tsx +1 -1
- package/src/ui/utils/convertMessage.ts +62 -61
- package/src/useChatRuntime.ts +4 -1
- package/src/useCloudRuntime.ts +21 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./rsc";
|
|
2
2
|
export * from "./ui";
|
|
3
3
|
export * from "./useChatRuntime";
|
|
4
|
+
export * from "./useCloudRuntime";
|
|
4
5
|
export { toLanguageModelMessages, toLanguageModelTools, fromLanguageModelMessages, fromLanguageModelTools, useDangerousInBrowserRuntime, } from "@assistant-ui/react-edge";
|
|
5
6
|
export { frontendTools } from "./frontendTools";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,MAAM,CAAC;AACrB,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,MAAM,CAAC;AACrB,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAElC,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./rsc\";\nexport * from \"./ui\";\nexport * from \"./useChatRuntime\";\n\nexport {\n toLanguageModelMessages,\n toLanguageModelTools,\n fromLanguageModelMessages,\n fromLanguageModelTools,\n useDangerousInBrowserRuntime,\n} from \"@assistant-ui/react-edge\";\nexport { frontendTools } from \"./frontendTools\";\n"],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AAEd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./rsc\";\nexport * from \"./ui\";\nexport * from \"./useChatRuntime\";\nexport * from \"./useCloudRuntime\";\n\nexport {\n toLanguageModelMessages,\n toLanguageModelTools,\n fromLanguageModelMessages,\n fromLanguageModelTools,\n useDangerousInBrowserRuntime,\n} from \"@assistant-ui/react-edge\";\nexport { frontendTools } from \"./frontendTools\";\n"],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;","names":[]}
|
|
@@ -22,7 +22,7 @@ var useVercelRSCRuntime = (adapter) => {
|
|
|
22
22
|
throw new Error("You must pass a onNew function to useVercelRSCRuntime");
|
|
23
23
|
const convertFn = useMemo(() => {
|
|
24
24
|
return adapter.convertMessage?.bind(adapter) ?? ((m) => m);
|
|
25
|
-
}, [adapter
|
|
25
|
+
}, [adapter]);
|
|
26
26
|
const callback = useCallback(
|
|
27
27
|
(m) => {
|
|
28
28
|
return vercelToThreadMessage(convertFn, m);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rsc/useVercelRSCRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport type { VercelRSCAdapter } from \"./VercelRSCAdapter\";\nimport {\n ExternalStoreAdapter,\n ThreadMessageLike,\n useExternalMessageConverter,\n useExternalStoreRuntime,\n} from \"@assistant-ui/react\";\nimport { VercelRSCMessage } from \"./VercelRSCMessage\";\nimport { useCallback, useMemo } from \"react\";\nimport { symbolInternalRSCExtras } from \"./utils/RSCThreadExtras\";\n\nconst vercelToThreadMessage = <T,>(\n converter: (message: T) => VercelRSCMessage,\n rawMessage: T,\n): ThreadMessageLike => {\n const message = converter(rawMessage);\n\n return {\n id: message.id,\n role: message.role,\n content: [{ type: \"text\", text: \"[Developer: Please set up RSCDisplay]\" }],\n createdAt: message.createdAt,\n };\n};\n\nexport const useVercelRSCRuntime = <T extends WeakKey>(\n adapter: VercelRSCAdapter<T>,\n) => {\n const onNew = adapter.onNew;\n if (!onNew)\n throw new Error(\"You must pass a onNew function to useVercelRSCRuntime\");\n\n const convertFn = useMemo(() => {\n return (\n adapter.convertMessage?.bind(adapter) ?? ((m: T) => m as VercelRSCMessage)\n );\n }, [adapter
|
|
1
|
+
{"version":3,"sources":["../../src/rsc/useVercelRSCRuntime.tsx"],"sourcesContent":["\"use client\";\n\nimport type { VercelRSCAdapter } from \"./VercelRSCAdapter\";\nimport {\n ExternalStoreAdapter,\n ThreadMessageLike,\n useExternalMessageConverter,\n useExternalStoreRuntime,\n} from \"@assistant-ui/react\";\nimport { VercelRSCMessage } from \"./VercelRSCMessage\";\nimport { useCallback, useMemo } from \"react\";\nimport { symbolInternalRSCExtras } from \"./utils/RSCThreadExtras\";\n\nconst vercelToThreadMessage = <T,>(\n converter: (message: T) => VercelRSCMessage,\n rawMessage: T,\n): ThreadMessageLike => {\n const message = converter(rawMessage);\n\n return {\n id: message.id,\n role: message.role,\n content: [{ type: \"text\", text: \"[Developer: Please set up RSCDisplay]\" }],\n createdAt: message.createdAt,\n };\n};\n\nexport const useVercelRSCRuntime = <T extends WeakKey>(\n adapter: VercelRSCAdapter<T>,\n) => {\n const onNew = adapter.onNew;\n if (!onNew)\n throw new Error(\"You must pass a onNew function to useVercelRSCRuntime\");\n\n const convertFn = useMemo(() => {\n return (\n adapter.convertMessage?.bind(adapter) ?? ((m: T) => m as VercelRSCMessage)\n );\n }, [adapter]);\n const callback = useCallback(\n (m: T) => {\n return vercelToThreadMessage(convertFn, m);\n },\n [convertFn],\n );\n\n const messages = useExternalMessageConverter({\n callback,\n isRunning: adapter.isRunning ?? false,\n messages: adapter.messages,\n });\n\n const eAdapter: ExternalStoreAdapter = {\n isRunning: adapter.isRunning,\n messages,\n onNew,\n onEdit: adapter.onEdit,\n onReload: adapter.onReload,\n adapters: adapter.adapters,\n unstable_capabilities: {\n copy: false,\n },\n extras: {\n [symbolInternalRSCExtras]: { convertFn },\n },\n };\n\n const runtime = useExternalStoreRuntime(eAdapter);\n return runtime;\n};\n"],"mappings":";;;AAGA;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,aAAa,eAAe;AACrC,SAAS,+BAA+B;AAExC,IAAM,wBAAwB,CAC5B,WACA,eACsB;AACtB,QAAM,UAAU,UAAU,UAAU;AAEpC,SAAO;AAAA,IACL,IAAI,QAAQ;AAAA,IACZ,MAAM,QAAQ;AAAA,IACd,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,wCAAwC,CAAC;AAAA,IACzE,WAAW,QAAQ;AAAA,EACrB;AACF;AAEO,IAAM,sBAAsB,CACjC,YACG;AACH,QAAM,QAAQ,QAAQ;AACtB,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,uDAAuD;AAEzE,QAAM,YAAY,QAAQ,MAAM;AAC9B,WACE,QAAQ,gBAAgB,KAAK,OAAO,MAAM,CAAC,MAAS;AAAA,EAExD,GAAG,CAAC,OAAO,CAAC;AACZ,QAAM,WAAW;AAAA,IACf,CAAC,MAAS;AACR,aAAO,sBAAsB,WAAW,CAAC;AAAA,IAC3C;AAAA,IACA,CAAC,SAAS;AAAA,EACZ;AAEA,QAAM,WAAW,4BAA4B;AAAA,IAC3C;AAAA,IACA,WAAW,QAAQ,aAAa;AAAA,IAChC,UAAU,QAAQ;AAAA,EACpB,CAAC;AAED,QAAM,WAAiC;AAAA,IACrC,WAAW,QAAQ;AAAA,IACnB;AAAA,IACA;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB,UAAU,QAAQ;AAAA,IAClB,UAAU,QAAQ;AAAA,IAClB,uBAAuB;AAAA,MACrB,MAAM;AAAA,IACR;AAAA,IACA,QAAQ;AAAA,MACN,CAAC,uBAAuB,GAAG,EAAE,UAAU;AAAA,IACzC;AAAA,EACF;AAEA,QAAM,UAAU,wBAAwB,QAAQ;AAChD,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessage.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/convertMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"convertMessage.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/convertMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAsE3C,eAAO,MAAM,qBAAqB;;;;;;;0HAjDpB,sDACR;yHAES,sDACI;;;CAuIlB,CAAC"}
|
|
@@ -2,6 +2,57 @@
|
|
|
2
2
|
import {
|
|
3
3
|
unstable_createMessageConverter
|
|
4
4
|
} from "@assistant-ui/react";
|
|
5
|
+
var convertParts = (message) => {
|
|
6
|
+
if (message.parts && message.parts.length > 0) {
|
|
7
|
+
return message.parts.filter((p) => p.type !== "step-start").map((part) => {
|
|
8
|
+
const type = part.type;
|
|
9
|
+
switch (type) {
|
|
10
|
+
case "text":
|
|
11
|
+
return {
|
|
12
|
+
type: "text",
|
|
13
|
+
text: part.text
|
|
14
|
+
};
|
|
15
|
+
case "tool-invocation":
|
|
16
|
+
return {
|
|
17
|
+
type: "tool-call",
|
|
18
|
+
toolName: part.toolInvocation.toolName,
|
|
19
|
+
toolCallId: part.toolInvocation.toolCallId,
|
|
20
|
+
argsText: JSON.stringify(part.toolInvocation.args),
|
|
21
|
+
args: part.toolInvocation.args,
|
|
22
|
+
result: part.toolInvocation.state === "result" && part.toolInvocation.result
|
|
23
|
+
};
|
|
24
|
+
case "reasoning":
|
|
25
|
+
return {
|
|
26
|
+
type: "reasoning",
|
|
27
|
+
text: part.reasoning
|
|
28
|
+
};
|
|
29
|
+
case "source":
|
|
30
|
+
return {
|
|
31
|
+
type: "source",
|
|
32
|
+
...part.source
|
|
33
|
+
};
|
|
34
|
+
case "file":
|
|
35
|
+
return {
|
|
36
|
+
type: "file",
|
|
37
|
+
data: part.data,
|
|
38
|
+
mimeType: part.mimeType
|
|
39
|
+
};
|
|
40
|
+
default: {
|
|
41
|
+
const _unsupported = type;
|
|
42
|
+
throw new Error(
|
|
43
|
+
`You have a message with an unsupported part type. The type ${_unsupported} is not supported.`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return message.content ? [
|
|
50
|
+
{
|
|
51
|
+
type: "text",
|
|
52
|
+
text: message.content
|
|
53
|
+
}
|
|
54
|
+
] : [];
|
|
55
|
+
};
|
|
5
56
|
var AISDKMessageConverter = unstable_createMessageConverter(
|
|
6
57
|
(message) => {
|
|
7
58
|
switch (message.role) {
|
|
@@ -10,7 +61,7 @@ var AISDKMessageConverter = unstable_createMessageConverter(
|
|
|
10
61
|
role: "user",
|
|
11
62
|
id: message.id,
|
|
12
63
|
createdAt: message.createdAt,
|
|
13
|
-
content: message
|
|
64
|
+
content: convertParts(message),
|
|
14
65
|
attachments: message.experimental_attachments?.map(
|
|
15
66
|
(attachment, idx) => ({
|
|
16
67
|
id: idx.toString(),
|
|
@@ -27,59 +78,14 @@ var AISDKMessageConverter = unstable_createMessageConverter(
|
|
|
27
78
|
role: "system",
|
|
28
79
|
id: message.id,
|
|
29
80
|
createdAt: message.createdAt,
|
|
30
|
-
content: message
|
|
81
|
+
content: convertParts(message)
|
|
31
82
|
};
|
|
32
83
|
case "assistant":
|
|
33
84
|
return {
|
|
34
85
|
role: "assistant",
|
|
35
86
|
id: message.id,
|
|
36
87
|
createdAt: message.createdAt,
|
|
37
|
-
content: message
|
|
38
|
-
const type = part.type;
|
|
39
|
-
switch (type) {
|
|
40
|
-
case "text":
|
|
41
|
-
return {
|
|
42
|
-
type: "text",
|
|
43
|
-
text: part.text
|
|
44
|
-
};
|
|
45
|
-
case "tool-invocation":
|
|
46
|
-
return {
|
|
47
|
-
type: "tool-call",
|
|
48
|
-
toolName: part.toolInvocation.toolName,
|
|
49
|
-
toolCallId: part.toolInvocation.toolCallId,
|
|
50
|
-
argsText: JSON.stringify(part.toolInvocation.args),
|
|
51
|
-
args: part.toolInvocation.args,
|
|
52
|
-
result: part.toolInvocation.state === "result" && part.toolInvocation.result
|
|
53
|
-
};
|
|
54
|
-
case "reasoning":
|
|
55
|
-
return {
|
|
56
|
-
type: "reasoning",
|
|
57
|
-
text: part.reasoning
|
|
58
|
-
};
|
|
59
|
-
case "source":
|
|
60
|
-
return {
|
|
61
|
-
type: "source",
|
|
62
|
-
...part.source
|
|
63
|
-
};
|
|
64
|
-
case "file":
|
|
65
|
-
return {
|
|
66
|
-
type: "file",
|
|
67
|
-
data: part.data,
|
|
68
|
-
mimeType: part.mimeType
|
|
69
|
-
};
|
|
70
|
-
default: {
|
|
71
|
-
const _unsupported2 = type;
|
|
72
|
-
throw new Error(
|
|
73
|
-
`You have a message with an unsupported part type. The type ${_unsupported2} is not supported.`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}) ?? (message.content ? [
|
|
78
|
-
{
|
|
79
|
-
type: "text",
|
|
80
|
-
text: message.content
|
|
81
|
-
}
|
|
82
|
-
] : []),
|
|
88
|
+
content: convertParts(message),
|
|
83
89
|
metadata: {
|
|
84
90
|
unstable_annotations: message.annotations,
|
|
85
91
|
unstable_data: Array.isArray(message.data) ? message.data : message.data ? [message.data] : void 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ui/utils/convertMessage.ts"],"sourcesContent":["import { Message } from \"@ai-sdk/ui-utils\";\nimport {\n unstable_createMessageConverter,\n type ReasoningContentPart,\n type ToolCallContentPart,\n type TextContentPart,\n type CompleteAttachment,\n type SourceContentPart,\n type FileContentPart,\n} from \"@assistant-ui/react\";\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/ui/utils/convertMessage.ts"],"sourcesContent":["import { Message } from \"@ai-sdk/ui-utils\";\nimport {\n unstable_createMessageConverter,\n type ReasoningContentPart,\n type ToolCallContentPart,\n type TextContentPart,\n type CompleteAttachment,\n type SourceContentPart,\n type FileContentPart,\n} from \"@assistant-ui/react\";\n\nconst convertParts = (message: Message) => {\n if (message.parts && message.parts.length > 0) {\n return message.parts\n .filter((p) => p.type !== \"step-start\")\n .map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return {\n type: \"text\",\n text: part.text,\n } satisfies TextContentPart;\n case \"tool-invocation\":\n return {\n type: \"tool-call\",\n toolName: part.toolInvocation.toolName,\n toolCallId: part.toolInvocation.toolCallId,\n argsText: JSON.stringify(part.toolInvocation.args),\n args: part.toolInvocation.args,\n result:\n part.toolInvocation.state === \"result\" &&\n part.toolInvocation.result,\n } satisfies ToolCallContentPart;\n case \"reasoning\":\n return {\n type: \"reasoning\",\n text: part.reasoning,\n } satisfies ReasoningContentPart;\n case \"source\":\n return {\n type: \"source\",\n ...part.source,\n } satisfies SourceContentPart;\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n } satisfies FileContentPart;\n default: {\n const _unsupported: never = type;\n throw new Error(\n `You have a message with an unsupported part type. The type ${_unsupported} is not supported.`,\n );\n }\n }\n });\n }\n\n return message.content\n ? [\n {\n type: \"text\",\n text: message.content,\n } satisfies TextContentPart,\n ]\n : [];\n};\n\nexport const AISDKMessageConverter = unstable_createMessageConverter(\n (message: Message) => {\n switch (message.role) {\n case \"user\":\n return {\n role: \"user\",\n id: message.id,\n createdAt: message.createdAt,\n content: convertParts(message),\n attachments: message.experimental_attachments?.map(\n (attachment, idx) =>\n ({\n id: idx.toString(),\n type: \"file\",\n name: attachment.name ?? attachment.url,\n content: [],\n contentType: attachment.contentType ?? \"unknown/unknown\",\n status: { type: \"complete\" },\n }) satisfies CompleteAttachment,\n ),\n };\n\n case \"system\":\n return {\n role: \"system\",\n id: message.id,\n createdAt: message.createdAt,\n content: convertParts(message),\n };\n\n case \"assistant\":\n return {\n role: \"assistant\",\n id: message.id,\n createdAt: message.createdAt,\n content: convertParts(message),\n metadata: {\n unstable_annotations: message.annotations,\n unstable_data: Array.isArray(message.data)\n ? message.data\n : message.data\n ? [message.data]\n : undefined,\n },\n };\n\n case \"data\": {\n type MaybeSupportedDataMessage =\n | { type?: \"unsafe_other\" }\n | ToolCallContentPart\n | {\n type: \"tool-result\";\n toolCallId: string;\n result: any;\n };\n\n if (\n !message.data ||\n !(typeof message.data === \"object\") ||\n Array.isArray(message.data)\n )\n return [];\n\n const data = message.data as MaybeSupportedDataMessage;\n\n if (data.type === \"tool-call\") {\n return {\n role: \"assistant\",\n id: message.id,\n createdAt: message.createdAt,\n content: [data],\n };\n } else if (data.type === \"tool-result\") {\n return {\n role: \"tool\",\n id: message.id,\n toolCallId: data.toolCallId,\n result: data.result,\n };\n }\n return [];\n }\n\n default:\n const _unsupported: \"function\" | \"tool\" = message.role;\n throw new Error(\n `You have a message with an unsupported role. The role ${_unsupported} is not supported.`,\n );\n }\n },\n);\n"],"mappings":"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","names":[]}
|
package/dist/useChatRuntime.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EdgeRuntimeOptions } from "@assistant-ui/react-edge";
|
|
2
|
-
type UseChatRuntimeOptions = Omit<EdgeRuntimeOptions, "unstable_AISDKInterop">;
|
|
2
|
+
export type UseChatRuntimeOptions = Omit<EdgeRuntimeOptions, "unstable_AISDKInterop">;
|
|
3
3
|
export declare const useChatRuntime: (options: UseChatRuntimeOptions) => import("@assistant-ui/react").AssistantRuntime;
|
|
4
|
-
export {};
|
|
5
4
|
//# sourceMappingURL=useChatRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChatRuntime.d.ts","sourceRoot":"","sources":["../src/useChatRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,0BAA0B,CAAC;AAE9E,
|
|
1
|
+
{"version":3,"file":"useChatRuntime.d.ts","sourceRoot":"","sources":["../src/useChatRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,0BAA0B,CAAC;AAE9E,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACtC,kBAAkB,EAClB,uBAAuB,CACxB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,SAAS,qBAAqB,mDAK5D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useChatRuntime.ts"],"sourcesContent":["import { EdgeRuntimeOptions, useEdgeRuntime } from \"@assistant-ui/react-edge\";\n\
|
|
1
|
+
{"version":3,"sources":["../src/useChatRuntime.ts"],"sourcesContent":["import { EdgeRuntimeOptions, useEdgeRuntime } from \"@assistant-ui/react-edge\";\n\nexport type UseChatRuntimeOptions = Omit<\n EdgeRuntimeOptions,\n \"unstable_AISDKInterop\"\n>;\n\nexport const useChatRuntime = (options: UseChatRuntimeOptions) => {\n return useEdgeRuntime({\n ...options,\n unstable_AISDKInterop: \"v2\",\n });\n};\n"],"mappings":";AAAA,SAA6B,sBAAsB;AAO5C,IAAM,iBAAiB,CAAC,YAAmC;AAChE,SAAO,eAAe;AAAA,IACpB,GAAG;AAAA,IACH,uBAAuB;AAAA,EACzB,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AssistantCloud } from "@assistant-ui/react";
|
|
2
|
+
import { UseChatRuntimeOptions } from "./useChatRuntime";
|
|
3
|
+
type UseCloudRuntimeOptions = Omit<UseChatRuntimeOptions, "api"> & {
|
|
4
|
+
cloud: AssistantCloud;
|
|
5
|
+
assistantId: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated This is under active development and not yet ready for prod use.
|
|
9
|
+
*/
|
|
10
|
+
export declare const useCloudRuntime: (options: UseCloudRuntimeOptions) => import("@assistant-ui/react").AssistantRuntime;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=useCloudRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCloudRuntime.d.ts","sourceRoot":"","sources":["../src/useCloudRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAkB,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzE,KAAK,sBAAsB,GAAG,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,GAAG;IACjE,KAAK,EAAE,cAAc,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,sBAAsB,mDAS9D,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/useCloudRuntime.ts
|
|
2
|
+
import { useChatRuntime } from "./useChatRuntime.js";
|
|
3
|
+
var useCloudRuntime = (options) => {
|
|
4
|
+
const opts = options.cloud.runs.__internal_getAssistantOptions(
|
|
5
|
+
options.assistantId
|
|
6
|
+
);
|
|
7
|
+
return useChatRuntime({
|
|
8
|
+
...options,
|
|
9
|
+
...opts
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
useCloudRuntime
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=useCloudRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/useCloudRuntime.ts"],"sourcesContent":["import { AssistantCloud } from \"@assistant-ui/react\";\nimport { useChatRuntime, UseChatRuntimeOptions } from \"./useChatRuntime\";\n\ntype UseCloudRuntimeOptions = Omit<UseChatRuntimeOptions, \"api\"> & {\n cloud: AssistantCloud;\n assistantId: string;\n};\n\n/**\n * @deprecated This is under active development and not yet ready for prod use.\n */\nexport const useCloudRuntime = (options: UseCloudRuntimeOptions) => {\n const opts = options.cloud.runs.__internal_getAssistantOptions(\n options.assistantId,\n );\n\n return useChatRuntime({\n ...options,\n ...opts,\n });\n};\n"],"mappings":";AACA,SAAS,sBAA6C;AAU/C,IAAM,kBAAkB,CAAC,YAAoC;AAClE,QAAM,OAAO,QAAQ,MAAM,KAAK;AAAA,IAC9B,QAAQ;AAAA,EACV;AAEA,SAAO,eAAe;AAAA,IACpB,GAAG;AAAA,IACH,GAAG;AAAA,EACL,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react-ai-sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"@types/json-schema": "^7.0.15",
|
|
25
25
|
"zod": "^3.25.28",
|
|
26
26
|
"zustand": "^5.0.5",
|
|
27
|
-
"@assistant-ui/react-edge": "0.2.
|
|
27
|
+
"@assistant-ui/react-edge": "0.2.11"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@assistant-ui/react": "^0.10.
|
|
30
|
+
"@assistant-ui/react": "^0.10.18",
|
|
31
31
|
"@types/react": "*",
|
|
32
32
|
"react": "^18 || ^19 || ^19.0.0-rc"
|
|
33
33
|
},
|
package/src/index.ts
CHANGED
|
@@ -36,7 +36,7 @@ export const useVercelRSCRuntime = <T extends WeakKey>(
|
|
|
36
36
|
return (
|
|
37
37
|
adapter.convertMessage?.bind(adapter) ?? ((m: T) => m as VercelRSCMessage)
|
|
38
38
|
);
|
|
39
|
-
}, [adapter
|
|
39
|
+
}, [adapter]);
|
|
40
40
|
const callback = useCallback(
|
|
41
41
|
(m: T) => {
|
|
42
42
|
return vercelToThreadMessage(convertFn, m);
|
|
@@ -9,6 +9,65 @@ import {
|
|
|
9
9
|
type FileContentPart,
|
|
10
10
|
} from "@assistant-ui/react";
|
|
11
11
|
|
|
12
|
+
const convertParts = (message: Message) => {
|
|
13
|
+
if (message.parts && message.parts.length > 0) {
|
|
14
|
+
return message.parts
|
|
15
|
+
.filter((p) => p.type !== "step-start")
|
|
16
|
+
.map((part) => {
|
|
17
|
+
const type = part.type;
|
|
18
|
+
switch (type) {
|
|
19
|
+
case "text":
|
|
20
|
+
return {
|
|
21
|
+
type: "text",
|
|
22
|
+
text: part.text,
|
|
23
|
+
} satisfies TextContentPart;
|
|
24
|
+
case "tool-invocation":
|
|
25
|
+
return {
|
|
26
|
+
type: "tool-call",
|
|
27
|
+
toolName: part.toolInvocation.toolName,
|
|
28
|
+
toolCallId: part.toolInvocation.toolCallId,
|
|
29
|
+
argsText: JSON.stringify(part.toolInvocation.args),
|
|
30
|
+
args: part.toolInvocation.args,
|
|
31
|
+
result:
|
|
32
|
+
part.toolInvocation.state === "result" &&
|
|
33
|
+
part.toolInvocation.result,
|
|
34
|
+
} satisfies ToolCallContentPart;
|
|
35
|
+
case "reasoning":
|
|
36
|
+
return {
|
|
37
|
+
type: "reasoning",
|
|
38
|
+
text: part.reasoning,
|
|
39
|
+
} satisfies ReasoningContentPart;
|
|
40
|
+
case "source":
|
|
41
|
+
return {
|
|
42
|
+
type: "source",
|
|
43
|
+
...part.source,
|
|
44
|
+
} satisfies SourceContentPart;
|
|
45
|
+
case "file":
|
|
46
|
+
return {
|
|
47
|
+
type: "file",
|
|
48
|
+
data: part.data,
|
|
49
|
+
mimeType: part.mimeType,
|
|
50
|
+
} satisfies FileContentPart;
|
|
51
|
+
default: {
|
|
52
|
+
const _unsupported: never = type;
|
|
53
|
+
throw new Error(
|
|
54
|
+
`You have a message with an unsupported part type. The type ${_unsupported} is not supported.`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return message.content
|
|
62
|
+
? [
|
|
63
|
+
{
|
|
64
|
+
type: "text",
|
|
65
|
+
text: message.content,
|
|
66
|
+
} satisfies TextContentPart,
|
|
67
|
+
]
|
|
68
|
+
: [];
|
|
69
|
+
};
|
|
70
|
+
|
|
12
71
|
export const AISDKMessageConverter = unstable_createMessageConverter(
|
|
13
72
|
(message: Message) => {
|
|
14
73
|
switch (message.role) {
|
|
@@ -17,8 +76,7 @@ export const AISDKMessageConverter = unstable_createMessageConverter(
|
|
|
17
76
|
role: "user",
|
|
18
77
|
id: message.id,
|
|
19
78
|
createdAt: message.createdAt,
|
|
20
|
-
content: message
|
|
21
|
-
|
|
79
|
+
content: convertParts(message),
|
|
22
80
|
attachments: message.experimental_attachments?.map(
|
|
23
81
|
(attachment, idx) =>
|
|
24
82
|
({
|
|
@@ -37,7 +95,7 @@ export const AISDKMessageConverter = unstable_createMessageConverter(
|
|
|
37
95
|
role: "system",
|
|
38
96
|
id: message.id,
|
|
39
97
|
createdAt: message.createdAt,
|
|
40
|
-
content: message
|
|
98
|
+
content: convertParts(message),
|
|
41
99
|
};
|
|
42
100
|
|
|
43
101
|
case "assistant":
|
|
@@ -45,63 +103,7 @@ export const AISDKMessageConverter = unstable_createMessageConverter(
|
|
|
45
103
|
role: "assistant",
|
|
46
104
|
id: message.id,
|
|
47
105
|
createdAt: message.createdAt,
|
|
48
|
-
content:
|
|
49
|
-
message.parts
|
|
50
|
-
?.filter((p) => p.type !== "step-start")
|
|
51
|
-
.map((part) => {
|
|
52
|
-
const type = part.type;
|
|
53
|
-
switch (type) {
|
|
54
|
-
case "text":
|
|
55
|
-
return {
|
|
56
|
-
type: "text",
|
|
57
|
-
text: part.text,
|
|
58
|
-
} satisfies TextContentPart;
|
|
59
|
-
case "tool-invocation":
|
|
60
|
-
return {
|
|
61
|
-
type: "tool-call",
|
|
62
|
-
toolName: part.toolInvocation.toolName,
|
|
63
|
-
toolCallId: part.toolInvocation.toolCallId,
|
|
64
|
-
argsText: JSON.stringify(part.toolInvocation.args),
|
|
65
|
-
args: part.toolInvocation.args,
|
|
66
|
-
result:
|
|
67
|
-
part.toolInvocation.state === "result" &&
|
|
68
|
-
part.toolInvocation.result,
|
|
69
|
-
} satisfies ToolCallContentPart;
|
|
70
|
-
case "reasoning":
|
|
71
|
-
return {
|
|
72
|
-
type: "reasoning",
|
|
73
|
-
text: part.reasoning,
|
|
74
|
-
} satisfies ReasoningContentPart;
|
|
75
|
-
|
|
76
|
-
case "source":
|
|
77
|
-
return {
|
|
78
|
-
type: "source",
|
|
79
|
-
...part.source,
|
|
80
|
-
} satisfies SourceContentPart;
|
|
81
|
-
|
|
82
|
-
case "file":
|
|
83
|
-
return {
|
|
84
|
-
type: "file",
|
|
85
|
-
data: part.data,
|
|
86
|
-
mimeType: part.mimeType,
|
|
87
|
-
} satisfies FileContentPart;
|
|
88
|
-
|
|
89
|
-
default: {
|
|
90
|
-
const _unsupported: never = type;
|
|
91
|
-
throw new Error(
|
|
92
|
-
`You have a message with an unsupported part type. The type ${_unsupported} is not supported.`,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}) ??
|
|
97
|
-
(message.content
|
|
98
|
-
? [
|
|
99
|
-
{
|
|
100
|
-
type: "text",
|
|
101
|
-
text: message.content,
|
|
102
|
-
} satisfies TextContentPart,
|
|
103
|
-
]
|
|
104
|
-
: []),
|
|
106
|
+
content: convertParts(message),
|
|
105
107
|
metadata: {
|
|
106
108
|
unstable_annotations: message.annotations,
|
|
107
109
|
unstable_data: Array.isArray(message.data)
|
|
@@ -150,7 +152,6 @@ export const AISDKMessageConverter = unstable_createMessageConverter(
|
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
default:
|
|
153
|
-
// TODO handle tool and function messages
|
|
154
155
|
const _unsupported: "function" | "tool" = message.role;
|
|
155
156
|
throw new Error(
|
|
156
157
|
`You have a message with an unsupported role. The role ${_unsupported} is not supported.`,
|
package/src/useChatRuntime.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { EdgeRuntimeOptions, useEdgeRuntime } from "@assistant-ui/react-edge";
|
|
2
2
|
|
|
3
|
-
type UseChatRuntimeOptions = Omit<
|
|
3
|
+
export type UseChatRuntimeOptions = Omit<
|
|
4
|
+
EdgeRuntimeOptions,
|
|
5
|
+
"unstable_AISDKInterop"
|
|
6
|
+
>;
|
|
4
7
|
|
|
5
8
|
export const useChatRuntime = (options: UseChatRuntimeOptions) => {
|
|
6
9
|
return useEdgeRuntime({
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AssistantCloud } from "@assistant-ui/react";
|
|
2
|
+
import { useChatRuntime, UseChatRuntimeOptions } from "./useChatRuntime";
|
|
3
|
+
|
|
4
|
+
type UseCloudRuntimeOptions = Omit<UseChatRuntimeOptions, "api"> & {
|
|
5
|
+
cloud: AssistantCloud;
|
|
6
|
+
assistantId: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated This is under active development and not yet ready for prod use.
|
|
11
|
+
*/
|
|
12
|
+
export const useCloudRuntime = (options: UseCloudRuntimeOptions) => {
|
|
13
|
+
const opts = options.cloud.runs.__internal_getAssistantOptions(
|
|
14
|
+
options.assistantId,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
return useChatRuntime({
|
|
18
|
+
...options,
|
|
19
|
+
...opts,
|
|
20
|
+
});
|
|
21
|
+
};
|