@assistant-ui/ai-sdk 0.0.7 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/adapters/aiSDKFormatAdapter.d.ts +2 -2
- package/dist/adapters/aiSDKFormatAdapter.d.ts.map +1 -0
- package/dist/adapters/vercelAttachmentAdapter.d.ts +1 -3
- package/dist/adapters/vercelAttachmentAdapter.d.ts.map +1 -1
- package/dist/adapters/vercelAttachmentAdapter.js +3 -3
- package/dist/adapters/vercelAttachmentAdapter.js.map +1 -1
- package/dist/aiSDKExtras.d.ts +4 -6
- package/dist/aiSDKExtras.d.ts.map +1 -1
- package/dist/converters/convertMessage.d.ts +34 -24
- package/dist/converters/convertMessage.d.ts.map +1 -1
- package/dist/converters/convertMessage.js +56 -12
- package/dist/converters/convertMessage.js.map +1 -1
- package/dist/converters/modelContentEnvelope.d.ts +6 -7
- package/dist/converters/modelContentEnvelope.d.ts.map +1 -1
- package/dist/converters/toCreateMessage.d.ts +2 -4
- package/dist/converters/toCreateMessage.d.ts.map +1 -1
- package/dist/converters/toolOutputConversion.d.ts +20 -22
- package/dist/converters/toolOutputConversion.d.ts.map +1 -1
- package/dist/hooks.d.ts +2 -4
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.d.ts +17 -14
- package/dist/index.d.ts.map +1 -0
- package/dist/index.native.d.ts +15 -12
- package/dist/index.native.d.ts.map +1 -0
- package/dist/model-context/injectInteractableContext.d.ts +2 -4
- package/dist/model-context/injectInteractableContext.d.ts.map +1 -1
- package/dist/model-context/injectQuoteContext.d.ts +1 -3
- package/dist/model-context/injectQuoteContext.d.ts.map +1 -1
- package/dist/runtime/AISDKChat.d.ts +2 -4
- package/dist/runtime/AISDKChat.d.ts.map +1 -1
- package/dist/runtime/AISDKChat.js +1 -1
- package/dist/runtime/AISDKChat.js.map +1 -1
- package/dist/runtime/AISDKThreads.d.ts +29 -31
- package/dist/runtime/AISDKThreads.d.ts.map +1 -1
- package/dist/runtime/AISDKThreads.js +22 -23
- package/dist/runtime/AISDKThreads.js.map +1 -1
- package/dist/runtime/sdkIdentity.d.ts +1 -3
- package/dist/runtime/sdkIdentity.d.ts.map +1 -1
- package/dist/runtime/sdkIdentity.js +1 -1
- package/dist/runtime/useAISDKRuntime.d.ts +76 -70
- package/dist/runtime/useAISDKRuntime.d.ts.map +1 -1
- package/dist/runtime/useAISDKRuntime.js +311 -77
- package/dist/runtime/useAISDKRuntime.js.map +1 -1
- package/dist/runtime/useChatRuntime.d.ts +6 -8
- package/dist/runtime/useChatRuntime.d.ts.map +1 -1
- package/dist/runtime/useChatRuntime.js +14 -10
- package/dist/runtime/useChatRuntime.js.map +1 -1
- package/dist/runtime/useChatThread.d.ts +94 -89
- package/dist/runtime/useChatThread.d.ts.map +1 -1
- package/dist/runtime/useChatThread.js +44 -15
- package/dist/runtime/useChatThread.js.map +1 -1
- package/dist/runtime/useExternalHistory.d.ts +7 -7
- package/dist/runtime/useExternalHistory.d.ts.map +1 -1
- package/dist/runtime/useExternalHistory.js +231 -60
- package/dist/runtime/useExternalHistory.js.map +1 -1
- package/dist/runtime/useResourceCleanup.d.ts +1 -3
- package/dist/runtime/useResourceCleanup.d.ts.map +1 -1
- package/dist/runtime/useResourceCleanup.js +38 -14
- package/dist/runtime/useResourceCleanup.js.map +1 -1
- package/dist/runtime/useStreamingTiming.d.ts +3 -5
- package/dist/runtime/useStreamingTiming.d.ts.map +1 -1
- package/dist/runtime/useStreamingTiming.js +1 -1
- package/dist/tools/frontendTools.d.ts +21 -23
- package/dist/tools/frontendTools.d.ts.map +1 -1
- package/dist/tools/generativeTools.d.ts +24 -26
- package/dist/tools/generativeTools.d.ts.map +1 -1
- package/dist/tools/mcp-stdio.node.d.ts +2 -2
- package/dist/tools/mcp-stdio.node.d.ts.map +1 -0
- package/dist/tools/mcp-stdio.unsupported.d.ts +2 -4
- package/dist/tools/mcp-stdio.unsupported.d.ts.map +1 -1
- package/dist/transport/AssistantChatTransport.d.ts +14 -16
- package/dist/transport/AssistantChatTransport.d.ts.map +1 -1
- package/dist/transport/AssistantChatTransport.js +9 -2
- package/dist/transport/AssistantChatTransport.js.map +1 -1
- package/dist/transport/resumable.d.ts +25 -27
- package/dist/transport/resumable.d.ts.map +1 -1
- package/dist/usage.d.ts +8 -10
- package/dist/usage.d.ts.map +1 -1
- package/dist/usage.js.map +1 -1
- package/dist/utils/getVercelAIMessages.d.ts +2 -4
- package/dist/utils/getVercelAIMessages.d.ts.map +1 -1
- package/dist/utils/sliceMessagesUntil.d.ts +1 -3
- package/dist/utils/sliceMessagesUntil.d.ts.map +1 -1
- package/package.json +13 -9
- package/src/adapters/vercelAttachmentAdapter.test.ts +23 -0
- package/src/adapters/vercelAttachmentAdapter.ts +2 -2
- package/src/converters/convertMessage.test.ts +541 -3
- package/src/converters/convertMessage.ts +123 -15
- package/src/index.native.ts +1 -1
- package/src/index.ts +1 -1
- package/src/runtime/AISDKChat.ts +0 -4
- package/src/runtime/AISDKThreads.cloud.test.ts +60 -2
- package/src/runtime/AISDKThreads.test.ts +105 -46
- package/src/runtime/AISDKThreads.ts +1 -1
- package/src/runtime/useAISDKRuntime.approval.integration.test.tsx +1639 -19
- package/src/runtime/useAISDKRuntime.approval.test.tsx +252 -9
- package/src/runtime/useAISDKRuntime.fast-refresh.test.tsx +182 -0
- package/src/runtime/useAISDKRuntime.test.ts +275 -5
- package/src/runtime/useAISDKRuntime.ts +533 -60
- package/src/runtime/useAISDKRuntime.voice.test.tsx +50 -1
- package/src/runtime/useChatRuntime.fast-refresh.test.tsx +94 -0
- package/src/runtime/useChatRuntime.integration.test.tsx +143 -65
- package/src/runtime/useChatRuntime.test.ts +11 -7
- package/src/runtime/useChatRuntime.ts +6 -2
- package/src/runtime/useChatThread.test.ts +166 -2
- package/src/runtime/useChatThread.transport.test.tsx +152 -0
- package/src/runtime/useChatThread.ts +89 -22
- package/src/runtime/useExternalHistory.test.ts +943 -3
- package/src/runtime/useExternalHistory.ts +378 -15
- package/src/runtime/useResourceCleanup.ts +41 -15
- package/src/transport/AssistantChatTransport.test.ts +164 -0
- package/src/transport/AssistantChatTransport.ts +22 -2
- package/src/usage.ts +1 -1
|
@@ -1,76 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { UIMessage, useChat, CreateUIMessage } from "@ai-sdk/react";
|
|
2
|
+
import { type JoinStrategy } from "@assistant-ui/core/react";
|
|
3
|
+
import type { SuggestionAdapter } from "@assistant-ui/core";
|
|
4
|
+
import type { ExternalStoreAdapter, ExternalStoreSharedOptions, ThreadHistoryAdapter, AssistantRuntime, MessageFormatRepository, AppendMessage, RespondToToolApprovalOptions } from "@assistant-ui/core";
|
|
3
5
|
import { MessageRepository } from "@assistant-ui/core/internal";
|
|
4
|
-
import { CreateUIMessage, UIMessage, useChat } from "@ai-sdk/react";
|
|
5
|
-
//#region src/runtime/useAISDKRuntime.d.ts
|
|
6
6
|
export type CustomToCreateMessageFunction = <UI_MESSAGE extends UIMessage = UIMessage>(message: AppendMessage) => CreateUIMessage<UI_MESSAGE>;
|
|
7
7
|
export type AISDKRuntimeAdapter<UI_MESSAGE extends UIMessage = UIMessage> = ExternalStoreSharedOptions & {
|
|
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
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
8
|
+
adapters?: (NonNullable<ExternalStoreAdapter["adapters"]> & {
|
|
9
|
+
history?: ThreadHistoryAdapter | undefined;
|
|
10
|
+
suggestion?: SuggestionAdapter | undefined;
|
|
11
|
+
}) | undefined;
|
|
12
|
+
toCreateMessage?: CustomToCreateMessageFunction;
|
|
13
|
+
unstable_messageRepositoryInstance?: MessageRepository | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The object a host answer belongs to, normally the `Chat` the runtime
|
|
16
|
+
* renders. A host answer never reaches the `useChat` messages, so without
|
|
17
|
+
* an owner it lives only as long as this runtime. With an owner, it
|
|
18
|
+
* survives runtime remounts over the same chat.
|
|
19
|
+
*/
|
|
20
|
+
unstable_hostApprovalOwner?: object | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to automatically cancel pending interactive tool calls when the user sends a new message.
|
|
23
|
+
*
|
|
24
|
+
* When enabled (default), the pending tool calls will be marked as failed with an error message
|
|
25
|
+
* indicating the user cancelled the tool call by sending a new message.
|
|
26
|
+
*
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
cancelPendingToolCallsOnSend?: boolean | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Called when `runtime.thread.resumeRun(config)` is invoked.
|
|
32
|
+
*
|
|
33
|
+
* When omitted, `resumeRun` throws `"Runtime does not support resuming runs."`.
|
|
34
|
+
* Provide this to bridge resume invocations into a custom replay channel
|
|
35
|
+
* (for example, an SSE reconnect endpoint keyed by turn id).
|
|
36
|
+
*/
|
|
37
|
+
onResume?: ExternalStoreAdapter["onResume"];
|
|
38
|
+
/**
|
|
39
|
+
* Called when `runtime.thread.resumeToolCall(options)` is invoked for a tool call the in-process tracker does not own.
|
|
40
|
+
*
|
|
41
|
+
* When omitted, `resumeToolCall` throws `"Tool call ${toolCallId} is not waiting for resume."`.
|
|
42
|
+
* Provide this to bridge resume-tool-call invocations into a custom handler.
|
|
43
|
+
*/
|
|
44
|
+
onResumeToolCall?: ExternalStoreAdapter["onResumeToolCall"];
|
|
45
|
+
/**
|
|
46
|
+
* Answers tool approval requests through a host-owned channel instead of the AI SDK's `addToolApprovalResponse`.
|
|
47
|
+
*
|
|
48
|
+
* Called for every approval request in the thread with the complete response, including option and free-form answers. Hand requests the host does not own to `respondViaAISDK`, which is what runs when this option is omitted. The answer applies to the approval when the handler starts and is removed if it throws. It is never written into the `useChat` messages, so `sendAutomaticallyWhen` cannot forward it. With a history adapter, the answer is stored with its message once the handler resolves and returns on reload. With `unstable_hostApprovalOwner`, in-memory answers survive runtime remounts over the same chat; without an owner or history adapter, they last only as long as the runtime. Bring the resumed run back into the chat, for example with `resumeStream`, and have the endpoint refuse a second resume.
|
|
49
|
+
*
|
|
50
|
+
* While a handler is set, an approval's `display`, `allowFreeform`, `dismissible` and `options` reach the renderer, because the handler can receive answers the AI SDK cannot carry. A stream declares them through the `approvalDescriptor` of its `tool-approval-request` chunk, the one approval field the AI SDK keeps opaque; the converter reads the request and answer fields from that descriptor when the approval itself lacks them.
|
|
51
|
+
*/
|
|
52
|
+
onRespondToToolApproval?: ((response: RespondToToolApprovalOptions, context: {
|
|
53
|
+
toolCallId: string;
|
|
54
|
+
toolName: string;
|
|
55
|
+
/** Sends this response through the AI SDK's `addToolApprovalResponse`, which carries only `approved` and `reason`. */
|
|
56
|
+
respondViaAISDK: () => Promise<void>;
|
|
57
|
+
}) => Promise<void> | void) | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* How consecutive assistant messages are rendered.
|
|
60
|
+
*
|
|
61
|
+
* `"concat-content"` (the default) merges them into a single thread message.
|
|
62
|
+
* `"none"` keeps each assistant message as its own thread message, which is
|
|
63
|
+
* useful when a backend persists proactive or consecutive assistant messages
|
|
64
|
+
* as separate entries.
|
|
65
|
+
*/
|
|
66
|
+
joinStrategy?: JoinStrategy | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* A branch-aware AI SDK message tree seeded once when `useChat` is empty.
|
|
69
|
+
* After that seed, live updates come only from `useChat`. A later empty
|
|
70
|
+
* chat or a new object identity does not reload the tree.
|
|
71
|
+
*/
|
|
72
|
+
messageRepository?: MessageFormatRepository<UI_MESSAGE>;
|
|
73
|
+
/**
|
|
74
|
+
* Called after an explicit `switchToBranch` (for example a BranchPicker
|
|
75
|
+
* click). Complements `setMessages` and does not enable switching by itself.
|
|
76
|
+
*
|
|
77
|
+
* @deprecated This API is still under active development and might change without notice.
|
|
78
|
+
*/
|
|
79
|
+
unstable_onBranchChange?: ExternalStoreAdapter["unstable_onBranchChange"];
|
|
73
80
|
};
|
|
74
81
|
export declare const useAISDKRuntime: <UI_MESSAGE extends UIMessage = UIMessage>(chatHelpers: ReturnType<typeof useChat<UI_MESSAGE>>, adapter?: AISDKRuntimeAdapter<UI_MESSAGE>) => AssistantRuntime;
|
|
75
|
-
//#endregion
|
|
76
82
|
//# sourceMappingURL=useAISDKRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAISDKRuntime.d.ts","
|
|
1
|
+
{"version":3,"file":"useAISDKRuntime.d.ts","sourceRoot":"","sources":["../../src/runtime/useAISDKRuntime.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,eAAe,EAEhB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,oBAAoB,CA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