@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.
Files changed (115) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/adapters/aiSDKFormatAdapter.d.ts +2 -2
  4. package/dist/adapters/aiSDKFormatAdapter.d.ts.map +1 -0
  5. package/dist/adapters/vercelAttachmentAdapter.d.ts +1 -3
  6. package/dist/adapters/vercelAttachmentAdapter.d.ts.map +1 -1
  7. package/dist/adapters/vercelAttachmentAdapter.js +3 -3
  8. package/dist/adapters/vercelAttachmentAdapter.js.map +1 -1
  9. package/dist/aiSDKExtras.d.ts +4 -6
  10. package/dist/aiSDKExtras.d.ts.map +1 -1
  11. package/dist/converters/convertMessage.d.ts +34 -24
  12. package/dist/converters/convertMessage.d.ts.map +1 -1
  13. package/dist/converters/convertMessage.js +56 -12
  14. package/dist/converters/convertMessage.js.map +1 -1
  15. package/dist/converters/modelContentEnvelope.d.ts +6 -7
  16. package/dist/converters/modelContentEnvelope.d.ts.map +1 -1
  17. package/dist/converters/toCreateMessage.d.ts +2 -4
  18. package/dist/converters/toCreateMessage.d.ts.map +1 -1
  19. package/dist/converters/toolOutputConversion.d.ts +20 -22
  20. package/dist/converters/toolOutputConversion.d.ts.map +1 -1
  21. package/dist/hooks.d.ts +2 -4
  22. package/dist/hooks.d.ts.map +1 -1
  23. package/dist/index.d.ts +17 -14
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.native.d.ts +15 -12
  26. package/dist/index.native.d.ts.map +1 -0
  27. package/dist/model-context/injectInteractableContext.d.ts +2 -4
  28. package/dist/model-context/injectInteractableContext.d.ts.map +1 -1
  29. package/dist/model-context/injectQuoteContext.d.ts +1 -3
  30. package/dist/model-context/injectQuoteContext.d.ts.map +1 -1
  31. package/dist/runtime/AISDKChat.d.ts +2 -4
  32. package/dist/runtime/AISDKChat.d.ts.map +1 -1
  33. package/dist/runtime/AISDKChat.js +1 -1
  34. package/dist/runtime/AISDKChat.js.map +1 -1
  35. package/dist/runtime/AISDKThreads.d.ts +29 -31
  36. package/dist/runtime/AISDKThreads.d.ts.map +1 -1
  37. package/dist/runtime/AISDKThreads.js +22 -23
  38. package/dist/runtime/AISDKThreads.js.map +1 -1
  39. package/dist/runtime/sdkIdentity.d.ts +1 -3
  40. package/dist/runtime/sdkIdentity.d.ts.map +1 -1
  41. package/dist/runtime/sdkIdentity.js +1 -1
  42. package/dist/runtime/useAISDKRuntime.d.ts +76 -70
  43. package/dist/runtime/useAISDKRuntime.d.ts.map +1 -1
  44. package/dist/runtime/useAISDKRuntime.js +311 -77
  45. package/dist/runtime/useAISDKRuntime.js.map +1 -1
  46. package/dist/runtime/useChatRuntime.d.ts +6 -8
  47. package/dist/runtime/useChatRuntime.d.ts.map +1 -1
  48. package/dist/runtime/useChatRuntime.js +14 -10
  49. package/dist/runtime/useChatRuntime.js.map +1 -1
  50. package/dist/runtime/useChatThread.d.ts +94 -89
  51. package/dist/runtime/useChatThread.d.ts.map +1 -1
  52. package/dist/runtime/useChatThread.js +44 -15
  53. package/dist/runtime/useChatThread.js.map +1 -1
  54. package/dist/runtime/useExternalHistory.d.ts +7 -7
  55. package/dist/runtime/useExternalHistory.d.ts.map +1 -1
  56. package/dist/runtime/useExternalHistory.js +231 -60
  57. package/dist/runtime/useExternalHistory.js.map +1 -1
  58. package/dist/runtime/useResourceCleanup.d.ts +1 -3
  59. package/dist/runtime/useResourceCleanup.d.ts.map +1 -1
  60. package/dist/runtime/useResourceCleanup.js +38 -14
  61. package/dist/runtime/useResourceCleanup.js.map +1 -1
  62. package/dist/runtime/useStreamingTiming.d.ts +3 -5
  63. package/dist/runtime/useStreamingTiming.d.ts.map +1 -1
  64. package/dist/runtime/useStreamingTiming.js +1 -1
  65. package/dist/tools/frontendTools.d.ts +21 -23
  66. package/dist/tools/frontendTools.d.ts.map +1 -1
  67. package/dist/tools/generativeTools.d.ts +24 -26
  68. package/dist/tools/generativeTools.d.ts.map +1 -1
  69. package/dist/tools/mcp-stdio.node.d.ts +2 -2
  70. package/dist/tools/mcp-stdio.node.d.ts.map +1 -0
  71. package/dist/tools/mcp-stdio.unsupported.d.ts +2 -4
  72. package/dist/tools/mcp-stdio.unsupported.d.ts.map +1 -1
  73. package/dist/transport/AssistantChatTransport.d.ts +14 -16
  74. package/dist/transport/AssistantChatTransport.d.ts.map +1 -1
  75. package/dist/transport/AssistantChatTransport.js +9 -2
  76. package/dist/transport/AssistantChatTransport.js.map +1 -1
  77. package/dist/transport/resumable.d.ts +25 -27
  78. package/dist/transport/resumable.d.ts.map +1 -1
  79. package/dist/usage.d.ts +8 -10
  80. package/dist/usage.d.ts.map +1 -1
  81. package/dist/usage.js.map +1 -1
  82. package/dist/utils/getVercelAIMessages.d.ts +2 -4
  83. package/dist/utils/getVercelAIMessages.d.ts.map +1 -1
  84. package/dist/utils/sliceMessagesUntil.d.ts +1 -3
  85. package/dist/utils/sliceMessagesUntil.d.ts.map +1 -1
  86. package/package.json +13 -9
  87. package/src/adapters/vercelAttachmentAdapter.test.ts +23 -0
  88. package/src/adapters/vercelAttachmentAdapter.ts +2 -2
  89. package/src/converters/convertMessage.test.ts +541 -3
  90. package/src/converters/convertMessage.ts +123 -15
  91. package/src/index.native.ts +1 -1
  92. package/src/index.ts +1 -1
  93. package/src/runtime/AISDKChat.ts +0 -4
  94. package/src/runtime/AISDKThreads.cloud.test.ts +60 -2
  95. package/src/runtime/AISDKThreads.test.ts +105 -46
  96. package/src/runtime/AISDKThreads.ts +1 -1
  97. package/src/runtime/useAISDKRuntime.approval.integration.test.tsx +1639 -19
  98. package/src/runtime/useAISDKRuntime.approval.test.tsx +252 -9
  99. package/src/runtime/useAISDKRuntime.fast-refresh.test.tsx +182 -0
  100. package/src/runtime/useAISDKRuntime.test.ts +275 -5
  101. package/src/runtime/useAISDKRuntime.ts +533 -60
  102. package/src/runtime/useAISDKRuntime.voice.test.tsx +50 -1
  103. package/src/runtime/useChatRuntime.fast-refresh.test.tsx +94 -0
  104. package/src/runtime/useChatRuntime.integration.test.tsx +143 -65
  105. package/src/runtime/useChatRuntime.test.ts +11 -7
  106. package/src/runtime/useChatRuntime.ts +6 -2
  107. package/src/runtime/useChatThread.test.ts +166 -2
  108. package/src/runtime/useChatThread.transport.test.tsx +152 -0
  109. package/src/runtime/useChatThread.ts +89 -22
  110. package/src/runtime/useExternalHistory.test.ts +943 -3
  111. package/src/runtime/useExternalHistory.ts +378 -15
  112. package/src/runtime/useResourceCleanup.ts +41 -15
  113. package/src/transport/AssistantChatTransport.test.ts +164 -0
  114. package/src/transport/AssistantChatTransport.ts +22 -2
  115. package/src/usage.ts +1 -1
@@ -1,76 +1,82 @@
1
- import { JoinStrategy } from "@assistant-ui/core/react";
2
- import { AppendMessage, AssistantRuntime, ExternalStoreAdapter, ExternalStoreSharedOptions, MessageFormatRepository, RespondToToolApprovalOptions, SuggestionAdapter, ThreadHistoryAdapter } from "@assistant-ui/core";
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
- adapters?: (NonNullable<ExternalStoreAdapter["adapters"]> & {
9
- history?: ThreadHistoryAdapter | undefined;
10
- suggestion?: SuggestionAdapter | undefined;
11
- }) | undefined;
12
- toCreateMessage?: CustomToCreateMessageFunction;
13
- unstable_messageRepositoryInstance?: MessageRepository | undefined;
14
- /**
15
- * Whether to automatically cancel pending interactive tool calls when the user sends a new message.
16
- *
17
- * When enabled (default), the pending tool calls will be marked as failed with an error message
18
- * indicating the user cancelled the tool call by sending a new message.
19
- *
20
- * @default true
21
- */
22
- cancelPendingToolCallsOnSend?: boolean | undefined;
23
- /**
24
- * Called when `runtime.thread.resumeRun(config)` is invoked.
25
- *
26
- * When omitted, `resumeRun` throws `"Runtime does not support resuming runs."`.
27
- * Provide this to bridge resume invocations into a custom replay channel
28
- * (for example, an SSE reconnect endpoint keyed by turn id).
29
- */
30
- onResume?: ExternalStoreAdapter["onResume"];
31
- /**
32
- * Called when `runtime.thread.resumeToolCall(options)` is invoked for a tool call the in-process tracker does not own.
33
- *
34
- * When omitted, `resumeToolCall` throws `"Tool call ${toolCallId} is not waiting for resume."`.
35
- * Provide this to bridge resume-tool-call invocations into a custom handler.
36
- */
37
- onResumeToolCall?: ExternalStoreAdapter["onResumeToolCall"];
38
- /**
39
- * Answers tool approval requests through a host-owned channel instead of the AI SDK's `addToolApprovalResponse`.
40
- *
41
- * 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, and it lasts as long as this runtime: until then a second response to the same request rejects, and a runtime mounted again over the same chat shows the request open until the resumed run records its resolution in the chat.
42
- *
43
- * While a handler is set, an approval's `display`, `allowFreeform` and `options` reach the renderer, because the handler can receive answers the AI SDK cannot carry.
44
- */
45
- onRespondToToolApproval?: ((response: RespondToToolApprovalOptions, context: {
46
- toolCallId: string;
47
- toolName: string;
48
- /** Sends this response through the AI SDK's `addToolApprovalResponse`, which carries only `approved` and `reason`. */
49
- respondViaAISDK: () => Promise<void>;
50
- }) => Promise<void> | void) | undefined;
51
- /**
52
- * How consecutive assistant messages are rendered.
53
- *
54
- * `"concat-content"` (the default) merges them into a single thread message.
55
- * `"none"` keeps each assistant message as its own thread message, which is
56
- * useful when a backend persists proactive or consecutive assistant messages
57
- * as separate entries.
58
- */
59
- joinStrategy?: JoinStrategy | undefined;
60
- /**
61
- * A branch-aware AI SDK message tree seeded once when `useChat` is empty.
62
- * After that seed, live updates come only from `useChat`. A later empty
63
- * chat or a new object identity does not reload the tree.
64
- */
65
- messageRepository?: MessageFormatRepository<UI_MESSAGE>;
66
- /**
67
- * Called after an explicit `switchToBranch` (for example a BranchPicker
68
- * click). Complements `setMessages` and does not enable switching by itself.
69
- *
70
- * @deprecated This API is still under active development and might change without notice.
71
- */
72
- unstable_onBranchChange?: ExternalStoreAdapter["unstable_onBranchChange"];
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","names":[],"sources":["../../src/runtime/useAISDKRuntime.ts"],"mappings":";;;;;YAuEY,iCACV,mBAAmB,YAAY,WAE/B,SAAS,kBACN,gBAAgB;YA6BT,oBAAoB,mBAAmB,YAAY,aAC7D;EACE,YACK,YAAY;IACX,UAAU;IACV,aAAa;;EAGnB,kBAAkB;EAClB,qCAAqC;;;;;;;;;EASrC;;;;;;;;EAQA,WAAW;;;;;;;EAOX,mBAAmB;;;;;;;;EAQnB,4BAEM,UAAU,8BACV;IACE;IACA;;IAEA,uBAAuB;QAEtB;;;;;;;;;EAUT,eAAe;;;;;;EAMf,oBAAoB,wBAAwB;;;;;;;EAO5C,0BAA0B;;qBAsGjB,kBAAmB,mBAAmB,YAAY,WAC7D,aAAa,kBAAkB,QAAQ,cACvC,UAAS,oBAAoB,gBAAgB"}
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,EACl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