@assistant-ui/react-ai-sdk 1.1.21 → 1.3.0
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/README.md +1 -1
- package/dist/ui/adapters/aiSDKFormatAdapter.d.ts +2 -2
- package/dist/ui/adapters/aiSDKFormatAdapter.d.ts.map +1 -1
- package/dist/ui/adapters/aiSDKFormatAdapter.js +3 -4
- package/dist/ui/adapters/aiSDKFormatAdapter.js.map +1 -1
- package/dist/ui/use-chat/useAISDKRuntime.js +2 -2
- package/dist/ui/use-chat/useChatRuntime.js +2 -2
- package/dist/ui/use-chat/useChatRuntime.js.map +1 -1
- package/dist/ui/use-chat/useExternalHistory.d.ts.map +1 -1
- package/dist/ui/use-chat/useExternalHistory.js +3 -4
- package/dist/ui/use-chat/useExternalHistory.js.map +1 -1
- package/dist/ui/utils/convertMessage.d.ts.map +1 -1
- package/dist/ui/utils/convertMessage.js +5 -42
- package/dist/ui/utils/convertMessage.js.map +1 -1
- package/package.json +8 -7
- package/src/ui/adapters/aiSDKFormatAdapter.ts +4 -5
- package/src/ui/use-chat/useAISDKRuntime.tsx +2 -2
- package/src/ui/use-chat/useChatRuntime.tsx +2 -2
- package/src/ui/use-chat/useExternalHistory.tsx +4 -5
- package/src/ui/utils/convertMessage.ts +11 -51
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Vercel AI SDK integration for `@assistant-ui/react`.
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- Seamless integration with Vercel AI SDK
|
|
7
|
+
- Seamless integration with Vercel AI SDK v6
|
|
8
8
|
- Automatic system message and frontend tools forwarding via `AssistantChatTransport`
|
|
9
9
|
- Support for custom transport configuration
|
|
10
10
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UIMessage } from "ai";
|
|
1
|
+
import type { UIMessage } from "ai";
|
|
2
2
|
import { MessageFormatAdapter } from "@assistant-ui/react";
|
|
3
3
|
export type AISDKStorageFormat = Omit<UIMessage, "id">;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const aiSDKV6FormatAdapter: MessageFormatAdapter<UIMessage, AISDKStorageFormat>;
|
|
5
5
|
//# sourceMappingURL=aiSDKFormatAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSDKFormatAdapter.d.ts","sourceRoot":"","sources":["../../../src/ui/adapters/aiSDKFormatAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"aiSDKFormatAdapter.d.ts","sourceRoot":"","sources":["../../../src/ui/adapters/aiSDKFormatAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EACL,oBAAoB,EAGrB,MAAM,qBAAqB,CAAC;AAG7B,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAEvD,eAAO,MAAM,oBAAoB,EAAE,oBAAoB,CACrD,SAAS,EACT,kBAAkB,CA4BnB,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export const
|
|
2
|
-
format: "ai-sdk/
|
|
1
|
+
export const aiSDKV6FormatAdapter = {
|
|
2
|
+
format: "ai-sdk/v6",
|
|
3
3
|
encode({ message: { id, parts, ...message }, }) {
|
|
4
|
-
// Filter out FileContentParts until they are supported
|
|
5
4
|
return {
|
|
6
5
|
...message,
|
|
7
|
-
parts
|
|
6
|
+
parts,
|
|
8
7
|
};
|
|
9
8
|
},
|
|
10
9
|
decode(stored) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiSDKFormatAdapter.js","sourceRoot":"","sources":["../../../src/ui/adapters/aiSDKFormatAdapter.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,oBAAoB,GAG7B;IACF,MAAM,EAAE,WAAW;IAEnB,MAAM,CAAC,EACL,OAAO,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,GACL;QAC7B,
|
|
1
|
+
{"version":3,"file":"aiSDKFormatAdapter.js","sourceRoot":"","sources":["../../../src/ui/adapters/aiSDKFormatAdapter.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,oBAAoB,GAG7B;IACF,MAAM,EAAE,WAAW;IAEnB,MAAM,CAAC,EACL,OAAO,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,GACL;QAC7B,OAAO;YACL,GAAG,OAAO;YACV,KAAK;SACN,CAAC;IACJ,CAAC;IAED,MAAM,CACJ,MAA+C;QAE/C,OAAO;YACL,QAAQ,EAAE,MAAM,CAAC,SAAS;YAC1B,OAAO,EAAE;gBACP,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,GAAG,MAAM,CAAC,OAAO;aAClB;SACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAkB;QACtB,OAAO,OAAO,CAAC,EAAE,CAAC;IACpB,CAAC;CACF,CAAC"}
|
|
@@ -7,7 +7,7 @@ import { toCreateMessage } from "../utils/toCreateMessage.js";
|
|
|
7
7
|
import { vercelAttachmentAdapter } from "../utils/vercelAttachmentAdapter.js";
|
|
8
8
|
import { getVercelAIMessages } from "../getVercelAIMessages.js";
|
|
9
9
|
import { AISDKMessageConverter } from "../utils/convertMessage.js";
|
|
10
|
-
import {
|
|
10
|
+
import { aiSDKV6FormatAdapter, } from "../adapters/aiSDKFormatAdapter.js";
|
|
11
11
|
import { useExternalHistory } from "./useExternalHistory.js";
|
|
12
12
|
export const useAISDKRuntime = (chatHelpers, { adapters, toCreateMessage: customToCreateMessage, cancelPendingToolCallsOnSend = true, } = {}) => {
|
|
13
13
|
const contextAdapters = useRuntimeAdapters();
|
|
@@ -46,7 +46,7 @@ export const useAISDKRuntime = (chatHelpers, { adapters, toCreateMessage: custom
|
|
|
46
46
|
},
|
|
47
47
|
setToolStatuses,
|
|
48
48
|
});
|
|
49
|
-
const isLoading = useExternalHistory(runtimeRef, adapters?.history ?? contextAdapters?.history, AISDKMessageConverter.toThreadMessages,
|
|
49
|
+
const isLoading = useExternalHistory(runtimeRef, adapters?.history ?? contextAdapters?.history, AISDKMessageConverter.toThreadMessages, aiSDKV6FormatAdapter, (messages) => {
|
|
50
50
|
chatHelpers.setMessages(messages);
|
|
51
51
|
});
|
|
52
52
|
const completePendingToolCalls = async () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useChat } from "@ai-sdk/react";
|
|
3
|
-
import { unstable_useCloudThreadListAdapter, unstable_useRemoteThreadListRuntime,
|
|
3
|
+
import { unstable_useCloudThreadListAdapter, unstable_useRemoteThreadListRuntime, useAuiState, } from "@assistant-ui/react";
|
|
4
4
|
import { useAISDKRuntime, } from "./useAISDKRuntime.js";
|
|
5
5
|
import { AssistantChatTransport } from "./AssistantChatTransport.js";
|
|
6
6
|
import { useEffect, useMemo, useRef } from "react";
|
|
@@ -22,7 +22,7 @@ const useDynamicChatTransport = (transport) => {
|
|
|
22
22
|
const useChatThreadRuntime = (options) => {
|
|
23
23
|
const { adapters, transport: transportOptions, toCreateMessage, ...chatOptions } = options ?? {};
|
|
24
24
|
const transport = useDynamicChatTransport(transportOptions ?? new AssistantChatTransport());
|
|
25
|
-
const id =
|
|
25
|
+
const id = useAuiState(({ threadListItem }) => threadListItem.id);
|
|
26
26
|
const chat = useChat({
|
|
27
27
|
...chatOptions,
|
|
28
28
|
id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useChatRuntime.js","sourceRoot":"","sources":["../../../src/ui/use-chat/useChatRuntime.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAkB,MAAM,eAAe,CAAC;AAExD,OAAO,EAEL,kCAAkC,EAClC,mCAAmC,EACnC,
|
|
1
|
+
{"version":3,"file":"use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EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,EAC3D,UAAU,uBAAuB,CAAC,QAAQ,CAAC,KAC1C,yBAWF,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,QAAQ,EACzC,YAAY,SAAS,CAAC,gBAAgB,CAAC,EACvC,gBAAgB,oBAAoB,GAAG,SAAS,EAChD,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,EAC3D,sBAAsB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,CAAC,EACzD,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"useExternalHistory.d.ts","sourceRoot":"","sources":["../../../src/ui/use-chat/useExternalHistory.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,oBAAoB,EAEpB,uBAAuB,EACvB,yBAAyB,EAG1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAA+B,SAAS,EAAe,MAAM,OAAO,CAAC;AAI5E,eAAO,MAAM,2BAA2B,GAAI,QAAQ,EAClD,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,EAC3D,UAAU,uBAAuB,CAAC,QAAQ,CAAC,KAC1C,yBAWF,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,QAAQ,EACzC,YAAY,SAAS,CAAC,gBAAgB,CAAC,EACvC,gBAAgB,oBAAoB,GAAG,SAAS,EAChD,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,EAC3D,sBAAsB,oBAAoB,CAAC,QAAQ,EAAE,GAAG,CAAC,EACzD,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,IAAI,YA+F9C,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { getExternalStoreMessages, INTERNAL,
|
|
2
|
+
import { getExternalStoreMessages, INTERNAL, useAui, } from "@assistant-ui/react";
|
|
3
3
|
import { useRef, useEffect, useState, useCallback } from "react";
|
|
4
4
|
const { MessageRepository } = INTERNAL;
|
|
5
5
|
export const toExportedMessageRepository = (toThreadMessages, messages) => {
|
|
@@ -16,8 +16,8 @@ export const toExportedMessageRepository = (toThreadMessages, messages) => {
|
|
|
16
16
|
};
|
|
17
17
|
export const useExternalHistory = (runtimeRef, historyAdapter, toThreadMessages, storageFormatAdapter, onSetMessages) => {
|
|
18
18
|
const loadedRef = useRef(false);
|
|
19
|
-
const
|
|
20
|
-
const optionalThreadListItem = useCallback(() => (
|
|
19
|
+
const aui = useAui();
|
|
20
|
+
const optionalThreadListItem = useCallback(() => (aui.threadListItem.source ? aui.threadListItem() : null), [aui]);
|
|
21
21
|
const [isLoading, setIsLoading] = useState(false);
|
|
22
22
|
const historyIds = useRef(new Set());
|
|
23
23
|
const onSetMessagesRef = useRef(() => onSetMessages);
|
|
@@ -60,7 +60,6 @@ export const useExternalHistory = (runtimeRef, historyAdapter, toThreadMessages,
|
|
|
60
60
|
loadHistory();
|
|
61
61
|
}
|
|
62
62
|
}, [
|
|
63
|
-
api,
|
|
64
63
|
historyAdapter,
|
|
65
64
|
storageFormatAdapter,
|
|
66
65
|
toThreadMessages,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalHistory.js","sourceRoot":"","sources":["../../../src/ui/use-chat/useExternalHistory.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAKL,wBAAwB,EAGxB,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"useExternalHistory.js","sourceRoot":"","sources":["../../../src/ui/use-chat/useExternalHistory.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAKL,wBAAwB,EAGxB,QAAQ,EACR,MAAM,GACP,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAa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,CAAC,CAAC,MAAM,CAAC;wBAC9D,QAAQ;wBACR,OAAO,EAAE,wBAAwB,CAAW,OAAO,CAAC,CAAC,CAAC,CAAE;qBACzD,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,cAAc,EAAE,oBAAoB,EAAE,UAAU,CAAC,CAAC,CAAC;IAEvD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessage.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/convertMessage.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"convertMessage.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/convertMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/D,OAAO,EAOL,KAAK,2BAA2B,EAEjC,MAAM,qBAAqB,CAAC;AA8H7B,eAAO,MAAM,qBAAqB;;;;;;;;0HA5GJ,sDAAyB;yHAIjC,sDACF;;;CAqKnB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isToolUIPart } from "ai";
|
|
1
|
+
import { isToolUIPart, getToolName } from "ai";
|
|
2
2
|
import { unstable_createMessageConverter, } from "@assistant-ui/react";
|
|
3
3
|
function stripClosingDelimiters(json) {
|
|
4
4
|
return json.replace(/[}\]"]+$/, "");
|
|
@@ -25,9 +25,11 @@ const convertParts = (message, metadata) => {
|
|
|
25
25
|
text: part.text,
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
// Handle tool
|
|
28
|
+
// Handle tool parts (both static tool-* and dynamic-tool)
|
|
29
|
+
// In AI SDK v6, isToolUIPart returns true for both static and dynamic tools
|
|
29
30
|
if (isToolUIPart(part)) {
|
|
30
|
-
|
|
31
|
+
// Use getToolName which works for both static and dynamic tools
|
|
32
|
+
const toolName = getToolName(part);
|
|
31
33
|
const toolCallId = part.toolCallId;
|
|
32
34
|
// Extract args and result based on state
|
|
33
35
|
let args = {};
|
|
@@ -70,45 +72,6 @@ const convertParts = (message, metadata) => {
|
|
|
70
72
|
}),
|
|
71
73
|
};
|
|
72
74
|
}
|
|
73
|
-
// Handle dynamic-tool parts
|
|
74
|
-
if (type === "dynamic-tool") {
|
|
75
|
-
const toolName = part.toolName;
|
|
76
|
-
const toolCallId = part.toolCallId;
|
|
77
|
-
// Extract args and result based on state
|
|
78
|
-
let args = {};
|
|
79
|
-
let result;
|
|
80
|
-
let isError = false;
|
|
81
|
-
if (part.state === "input-streaming" ||
|
|
82
|
-
part.state === "input-available") {
|
|
83
|
-
args = part.input || {};
|
|
84
|
-
}
|
|
85
|
-
else if (part.state === "output-available") {
|
|
86
|
-
args = part.input || {};
|
|
87
|
-
result = part.output;
|
|
88
|
-
}
|
|
89
|
-
else if (part.state === "output-error") {
|
|
90
|
-
args = part.input || {};
|
|
91
|
-
isError = true;
|
|
92
|
-
result = { error: part.errorText };
|
|
93
|
-
}
|
|
94
|
-
const toolStatus = metadata.toolStatuses?.[toolCallId];
|
|
95
|
-
return {
|
|
96
|
-
type: "tool-call",
|
|
97
|
-
toolName,
|
|
98
|
-
toolCallId,
|
|
99
|
-
argsText: JSON.stringify(args),
|
|
100
|
-
args,
|
|
101
|
-
result,
|
|
102
|
-
isError,
|
|
103
|
-
...(toolStatus?.type === "interrupt" && {
|
|
104
|
-
interrupt: toolStatus.payload,
|
|
105
|
-
status: {
|
|
106
|
-
type: "requires-action",
|
|
107
|
-
reason: "interrupt",
|
|
108
|
-
},
|
|
109
|
-
}),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
75
|
// Handle source-url parts
|
|
113
76
|
if (type === "source-url") {
|
|
114
77
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertMessage.js","sourceRoot":"","sources":["../../../src/ui/utils/convertMessage.ts"],"names":[],"mappings":"AAAA,OAAO,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,OAAO,CAAC,QAA2B;aAC9C,CAAC;QAEJ,KAAK,WAAW;YACd,OAAO;gBACL,IAAI,EAAE,WAAW;gBACjB,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,SAAS;gBACT,OAAO,EAAE,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC;gBACxC,QAAQ,EAAE,OAAO,CAAC,QAA2B;aAC9C,CAAC;QAEJ;YACE,OAAO,CAAC,IAAI,CAAC,6BAA6B,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YAC1D,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@assistant-ui/react-ai-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Vercel AI SDK adapter for assistant-ui",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-sdk",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
],
|
|
32
32
|
"sideEffects": false,
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@ai-sdk/react": "^
|
|
35
|
-
"ai": "^
|
|
34
|
+
"@ai-sdk/react": "^3.0.44",
|
|
35
|
+
"ai": "^6.0.42",
|
|
36
36
|
"zod": "^4.3.5"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@assistant-ui/react": "^0.
|
|
39
|
+
"@assistant-ui/react": "^0.12.0",
|
|
40
40
|
"@types/react": "*",
|
|
41
41
|
"assistant-cloud": "*",
|
|
42
42
|
"react": "^18 || ^19"
|
|
@@ -51,10 +51,11 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/json-schema": "^7.0.15",
|
|
54
|
-
"@types/react": "^19.2.
|
|
54
|
+
"@types/react": "^19.2.9",
|
|
55
55
|
"react": "^19.2.3",
|
|
56
|
-
"@assistant-ui/react": "0.
|
|
57
|
-
"@assistant-ui/x-buildutils": "0.0.1"
|
|
56
|
+
"@assistant-ui/react": "0.12.0",
|
|
57
|
+
"@assistant-ui/x-buildutils": "0.0.1",
|
|
58
|
+
"assistant-stream": "0.2.47"
|
|
58
59
|
},
|
|
59
60
|
"publishConfig": {
|
|
60
61
|
"access": "public",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UIMessage } from "ai";
|
|
1
|
+
import type { UIMessage } from "ai";
|
|
2
2
|
import {
|
|
3
3
|
MessageFormatAdapter,
|
|
4
4
|
MessageFormatItem,
|
|
@@ -8,19 +8,18 @@ import {
|
|
|
8
8
|
// Storage format for AI SDK messages - just the UIMessage
|
|
9
9
|
export type AISDKStorageFormat = Omit<UIMessage, "id">;
|
|
10
10
|
|
|
11
|
-
export const
|
|
11
|
+
export const aiSDKV6FormatAdapter: MessageFormatAdapter<
|
|
12
12
|
UIMessage,
|
|
13
13
|
AISDKStorageFormat
|
|
14
14
|
> = {
|
|
15
|
-
format: "ai-sdk/
|
|
15
|
+
format: "ai-sdk/v6",
|
|
16
16
|
|
|
17
17
|
encode({
|
|
18
18
|
message: { id, parts, ...message },
|
|
19
19
|
}: MessageFormatItem<UIMessage>): AISDKStorageFormat {
|
|
20
|
-
// Filter out FileContentParts until they are supported
|
|
21
20
|
return {
|
|
22
21
|
...message,
|
|
23
|
-
parts
|
|
22
|
+
parts,
|
|
24
23
|
};
|
|
25
24
|
},
|
|
26
25
|
|
|
@@ -22,7 +22,7 @@ import { getVercelAIMessages } from "../getVercelAIMessages";
|
|
|
22
22
|
import { AISDKMessageConverter } from "../utils/convertMessage";
|
|
23
23
|
import {
|
|
24
24
|
type AISDKStorageFormat,
|
|
25
|
-
|
|
25
|
+
aiSDKV6FormatAdapter,
|
|
26
26
|
} from "../adapters/aiSDKFormatAdapter";
|
|
27
27
|
import { useExternalHistory } from "./useExternalHistory";
|
|
28
28
|
|
|
@@ -113,7 +113,7 @@ export const useAISDKRuntime = <UI_MESSAGE extends UIMessage = UIMessage>(
|
|
|
113
113
|
AISDKMessageConverter.toThreadMessages as (
|
|
114
114
|
messages: UI_MESSAGE[],
|
|
115
115
|
) => ThreadMessage[],
|
|
116
|
-
|
|
116
|
+
aiSDKV6FormatAdapter as MessageFormatAdapter<
|
|
117
117
|
UI_MESSAGE,
|
|
118
118
|
AISDKStorageFormat
|
|
119
119
|
>,
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
AssistantRuntime,
|
|
7
7
|
unstable_useCloudThreadListAdapter,
|
|
8
8
|
unstable_useRemoteThreadListRuntime,
|
|
9
|
-
|
|
9
|
+
useAuiState,
|
|
10
10
|
} from "@assistant-ui/react";
|
|
11
11
|
import {
|
|
12
12
|
useAISDKRuntime,
|
|
@@ -61,7 +61,7 @@ const useChatThreadRuntime = <UI_MESSAGE extends UIMessage = UIMessage>(
|
|
|
61
61
|
transportOptions ?? new AssistantChatTransport(),
|
|
62
62
|
);
|
|
63
63
|
|
|
64
|
-
const id =
|
|
64
|
+
const id = useAuiState(({ threadListItem }) => threadListItem.id);
|
|
65
65
|
const chat = useChat({
|
|
66
66
|
...chatOptions,
|
|
67
67
|
id,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
MessageFormatRepository,
|
|
10
10
|
ExportedMessageRepository,
|
|
11
11
|
INTERNAL,
|
|
12
|
-
|
|
12
|
+
useAui,
|
|
13
13
|
} from "@assistant-ui/react";
|
|
14
14
|
import { useRef, useEffect, useState, RefObject, useCallback } from "react";
|
|
15
15
|
|
|
@@ -40,10 +40,10 @@ export const useExternalHistory = <TMessage,>(
|
|
|
40
40
|
) => {
|
|
41
41
|
const loadedRef = useRef(false);
|
|
42
42
|
|
|
43
|
-
const
|
|
43
|
+
const aui = useAui();
|
|
44
44
|
const optionalThreadListItem = useCallback(
|
|
45
|
-
() => (
|
|
46
|
-
[
|
|
45
|
+
() => (aui.threadListItem.source ? aui.threadListItem() : null),
|
|
46
|
+
[aui],
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
const [isLoading, setIsLoading] = useState(false);
|
|
@@ -98,7 +98,6 @@ export const useExternalHistory = <TMessage,>(
|
|
|
98
98
|
loadHistory();
|
|
99
99
|
}
|
|
100
100
|
}, [
|
|
101
|
-
api,
|
|
102
101
|
historyAdapter,
|
|
103
102
|
storageFormatAdapter,
|
|
104
103
|
toThreadMessages,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isToolUIPart, type UIMessage } from "ai";
|
|
1
|
+
import { isToolUIPart, getToolName, type UIMessage } from "ai";
|
|
2
2
|
import {
|
|
3
3
|
unstable_createMessageConverter,
|
|
4
4
|
type ReasoningMessagePart,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type useExternalMessageConverter,
|
|
10
10
|
type ThreadMessageLike,
|
|
11
11
|
} from "@assistant-ui/react";
|
|
12
|
+
import type { ReadonlyJSONObject } from "assistant-stream/utils";
|
|
12
13
|
|
|
13
14
|
type MessageMetadata = ThreadMessageLike["metadata"];
|
|
14
15
|
|
|
@@ -45,26 +46,28 @@ const convertParts = (
|
|
|
45
46
|
} satisfies ReasoningMessagePart;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
// Handle tool
|
|
49
|
+
// Handle tool parts (both static tool-* and dynamic-tool)
|
|
50
|
+
// In AI SDK v6, isToolUIPart returns true for both static and dynamic tools
|
|
49
51
|
if (isToolUIPart(part)) {
|
|
50
|
-
|
|
52
|
+
// Use getToolName which works for both static and dynamic tools
|
|
53
|
+
const toolName = getToolName(part);
|
|
51
54
|
const toolCallId = part.toolCallId;
|
|
52
55
|
|
|
53
56
|
// Extract args and result based on state
|
|
54
|
-
let args:
|
|
55
|
-
let result:
|
|
57
|
+
let args: ReadonlyJSONObject = {};
|
|
58
|
+
let result: unknown;
|
|
56
59
|
let isError = false;
|
|
57
60
|
|
|
58
61
|
if (
|
|
59
62
|
part.state === "input-streaming" ||
|
|
60
63
|
part.state === "input-available"
|
|
61
64
|
) {
|
|
62
|
-
args = part.input || {};
|
|
65
|
+
args = (part.input as ReadonlyJSONObject) || {};
|
|
63
66
|
} else if (part.state === "output-available") {
|
|
64
|
-
args = part.input || {};
|
|
67
|
+
args = (part.input as ReadonlyJSONObject) || {};
|
|
65
68
|
result = part.output;
|
|
66
69
|
} else if (part.state === "output-error") {
|
|
67
|
-
args = part.input || {};
|
|
70
|
+
args = (part.input as ReadonlyJSONObject) || {};
|
|
68
71
|
isError = true;
|
|
69
72
|
result = { error: part.errorText };
|
|
70
73
|
}
|
|
@@ -95,49 +98,6 @@ const convertParts = (
|
|
|
95
98
|
} satisfies ToolCallMessagePart;
|
|
96
99
|
}
|
|
97
100
|
|
|
98
|
-
// Handle dynamic-tool parts
|
|
99
|
-
if (type === "dynamic-tool") {
|
|
100
|
-
const toolName = part.toolName;
|
|
101
|
-
const toolCallId = part.toolCallId;
|
|
102
|
-
|
|
103
|
-
// Extract args and result based on state
|
|
104
|
-
let args: any = {};
|
|
105
|
-
let result: any;
|
|
106
|
-
let isError = false;
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
part.state === "input-streaming" ||
|
|
110
|
-
part.state === "input-available"
|
|
111
|
-
) {
|
|
112
|
-
args = part.input || {};
|
|
113
|
-
} else if (part.state === "output-available") {
|
|
114
|
-
args = part.input || {};
|
|
115
|
-
result = part.output;
|
|
116
|
-
} else if (part.state === "output-error") {
|
|
117
|
-
args = part.input || {};
|
|
118
|
-
isError = true;
|
|
119
|
-
result = { error: part.errorText };
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const toolStatus = metadata.toolStatuses?.[toolCallId];
|
|
123
|
-
return {
|
|
124
|
-
type: "tool-call",
|
|
125
|
-
toolName,
|
|
126
|
-
toolCallId,
|
|
127
|
-
argsText: JSON.stringify(args),
|
|
128
|
-
args,
|
|
129
|
-
result,
|
|
130
|
-
isError,
|
|
131
|
-
...(toolStatus?.type === "interrupt" && {
|
|
132
|
-
interrupt: toolStatus.payload,
|
|
133
|
-
status: {
|
|
134
|
-
type: "requires-action" as const,
|
|
135
|
-
reason: "interrupt",
|
|
136
|
-
},
|
|
137
|
-
}),
|
|
138
|
-
} satisfies ToolCallMessagePart;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
101
|
// Handle source-url parts
|
|
142
102
|
if (type === "source-url") {
|
|
143
103
|
return {
|