@assistant-ui/react 0.12.21 → 0.12.23
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/client/ExternalThread.d.ts.map +1 -1
- package/dist/client/ExternalThread.js +8 -2
- package/dist/client/ExternalThread.js.map +1 -1
- package/dist/client/InMemoryThreadList.d.ts.map +1 -1
- package/dist/client/InMemoryThreadList.js +2 -0
- package/dist/client/InMemoryThreadList.js.map +1 -1
- package/dist/client/SingleThreadList.d.ts.map +1 -1
- package/dist/client/SingleThreadList.js +2 -0
- package/dist/client/SingleThreadList.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +3 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +4 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.d.ts +3 -1
- package/dist/primitives/actionBar/ActionBarCopy.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.d.ts +4 -2
- package/dist/primitives/actionBar/ActionBarEdit.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.d.ts +3 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js +1 -1
- package/dist/primitives/actionBar/ActionBarExportMarkdown.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.d.ts +4 -2
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.d.ts +4 -2
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarReload.d.ts +4 -2
- package/dist/primitives/actionBar/ActionBarReload.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarRoot.d.ts +4 -2
- package/dist/primitives/actionBar/ActionBarRoot.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarRoot.js +1 -1
- package/dist/primitives/actionBar/ActionBarRoot.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarSpeak.d.ts +4 -2
- package/dist/primitives/actionBar/ActionBarSpeak.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.d.ts +4 -2
- package/dist/primitives/actionBar/ActionBarStopSpeaking.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js +1 -1
- package/dist/primitives/actionBar/ActionBarStopSpeaking.js.map +1 -1
- package/dist/primitives/attachment/AttachmentRemove.d.ts +4 -2
- package/dist/primitives/attachment/AttachmentRemove.d.ts.map +1 -1
- package/dist/primitives/attachment/AttachmentRoot.d.ts +5 -3
- package/dist/primitives/attachment/AttachmentRoot.d.ts.map +1 -1
- package/dist/primitives/attachment/AttachmentRoot.js +1 -1
- package/dist/primitives/attachment/AttachmentRoot.js.map +1 -1
- package/dist/primitives/attachment/AttachmentThumb.d.ts +5 -3
- package/dist/primitives/attachment/AttachmentThumb.d.ts.map +1 -1
- package/dist/primitives/attachment/AttachmentThumb.js +1 -1
- package/dist/primitives/attachment/AttachmentThumb.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNext.d.ts +4 -2
- package/dist/primitives/branchPicker/BranchPickerNext.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts +4 -2
- package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerRoot.d.ts +4 -2
- package/dist/primitives/branchPicker/BranchPickerRoot.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerRoot.js +1 -1
- package/dist/primitives/branchPicker/BranchPickerRoot.js.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.d.ts +4 -2
- package/dist/primitives/chainOfThought/ChainOfThoughtAccordionTrigger.d.ts.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtRoot.d.ts +5 -3
- package/dist/primitives/chainOfThought/ChainOfThoughtRoot.d.ts.map +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtRoot.js +1 -1
- package/dist/primitives/chainOfThought/ChainOfThoughtRoot.js.map +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.d.ts +3 -1
- package/dist/primitives/composer/ComposerAddAttachment.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.d.ts +3 -0
- package/dist/primitives/composer/ComposerAttachmentDropzone.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +18 -8
- package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
- package/dist/primitives/composer/ComposerCancel.d.ts +4 -2
- package/dist/primitives/composer/ComposerCancel.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerDictate.d.ts +4 -2
- package/dist/primitives/composer/ComposerDictate.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerDictationTranscript.d.ts +5 -3
- package/dist/primitives/composer/ComposerDictationTranscript.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerDictationTranscript.js +1 -1
- package/dist/primitives/composer/ComposerDictationTranscript.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts +5 -0
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +23 -6
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerQuote.d.ts +13 -7
- package/dist/primitives/composer/ComposerQuote.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerQuote.js +1 -1
- package/dist/primitives/composer/ComposerQuote.js.map +1 -1
- package/dist/primitives/composer/ComposerRoot.d.ts +5 -3
- package/dist/primitives/composer/ComposerRoot.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerRoot.js +1 -1
- package/dist/primitives/composer/ComposerRoot.js.map +1 -1
- package/dist/primitives/composer/ComposerSend.d.ts +4 -2
- package/dist/primitives/composer/ComposerSend.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerStopDictation.d.ts +4 -2
- package/dist/primitives/composer/ComposerStopDictation.d.ts.map +1 -1
- package/dist/primitives/composer/mention/ComposerMentionBack.d.ts +5 -3
- package/dist/primitives/composer/mention/ComposerMentionBack.d.ts.map +1 -1
- package/dist/primitives/composer/mention/ComposerMentionBack.js +1 -1
- package/dist/primitives/composer/mention/ComposerMentionBack.js.map +1 -1
- package/dist/primitives/composer/mention/ComposerMentionCategories.d.ts +8 -4
- package/dist/primitives/composer/mention/ComposerMentionCategories.d.ts.map +1 -1
- package/dist/primitives/composer/mention/ComposerMentionCategories.js +1 -1
- package/dist/primitives/composer/mention/ComposerMentionCategories.js.map +1 -1
- package/dist/primitives/composer/mention/ComposerMentionItems.d.ts +8 -4
- package/dist/primitives/composer/mention/ComposerMentionItems.d.ts.map +1 -1
- package/dist/primitives/composer/mention/ComposerMentionItems.js +1 -1
- package/dist/primitives/composer/mention/ComposerMentionItems.js.map +1 -1
- package/dist/primitives/composer/mention/ComposerMentionPopover.d.ts +5 -3
- package/dist/primitives/composer/mention/ComposerMentionPopover.d.ts.map +1 -1
- package/dist/primitives/composer/mention/ComposerMentionPopover.js +1 -1
- package/dist/primitives/composer/mention/ComposerMentionPopover.js.map +1 -1
- package/dist/primitives/error/ErrorMessage.d.ts +5 -3
- package/dist/primitives/error/ErrorMessage.d.ts.map +1 -1
- package/dist/primitives/error/ErrorMessage.js +1 -1
- package/dist/primitives/error/ErrorMessage.js.map +1 -1
- package/dist/primitives/error/ErrorRoot.d.ts +5 -3
- package/dist/primitives/error/ErrorRoot.d.ts.map +1 -1
- package/dist/primitives/error/ErrorRoot.js +1 -1
- package/dist/primitives/error/ErrorRoot.js.map +1 -1
- package/dist/primitives/message/MessageRoot.d.ts +5 -3
- package/dist/primitives/message/MessageRoot.d.ts.map +1 -1
- package/dist/primitives/message/MessageRoot.js +1 -1
- package/dist/primitives/message/MessageRoot.js.map +1 -1
- package/dist/primitives/messagePart/MessagePartImage.d.ts +5 -3
- package/dist/primitives/messagePart/MessagePartImage.d.ts.map +1 -1
- package/dist/primitives/messagePart/MessagePartImage.js +1 -1
- package/dist/primitives/messagePart/MessagePartImage.js.map +1 -1
- package/dist/primitives/messagePart/MessagePartText.d.ts +5 -3
- package/dist/primitives/messagePart/MessagePartText.d.ts.map +1 -1
- package/dist/primitives/queueItem/QueueItemRemove.d.ts +4 -2
- package/dist/primitives/queueItem/QueueItemRemove.d.ts.map +1 -1
- package/dist/primitives/queueItem/QueueItemSteer.d.ts +4 -2
- package/dist/primitives/queueItem/QueueItemSteer.d.ts.map +1 -1
- package/dist/primitives/queueItem/QueueItemText.d.ts +5 -3
- package/dist/primitives/queueItem/QueueItemText.d.ts.map +1 -1
- package/dist/primitives/queueItem/QueueItemText.js +1 -1
- package/dist/primitives/queueItem/QueueItemText.js.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.d.ts +5 -3
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.d.ts.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarQuote.js.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.d.ts +5 -3
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.d.ts.map +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js +1 -1
- package/dist/primitives/selectionToolbar/SelectionToolbarRoot.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionDescription.d.ts +5 -3
- package/dist/primitives/suggestion/SuggestionDescription.d.ts.map +1 -1
- package/dist/primitives/suggestion/SuggestionDescription.js +1 -1
- package/dist/primitives/suggestion/SuggestionDescription.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionTitle.d.ts +5 -3
- package/dist/primitives/suggestion/SuggestionTitle.d.ts.map +1 -1
- package/dist/primitives/suggestion/SuggestionTitle.js +1 -1
- package/dist/primitives/suggestion/SuggestionTitle.js.map +1 -1
- package/dist/primitives/suggestion/SuggestionTrigger.d.ts +3 -1
- package/dist/primitives/suggestion/SuggestionTrigger.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadRoot.d.ts +5 -3
- package/dist/primitives/thread/ThreadRoot.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadRoot.js +1 -1
- package/dist/primitives/thread/ThreadRoot.js.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.d.ts +4 -2
- package/dist/primitives/thread/ThreadScrollToBottom.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadSuggestion.d.ts +3 -1
- package/dist/primitives/thread/ThreadSuggestion.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.d.ts +4 -2
- package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js +1 -1
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/thread/ThreadViewportFooter.d.ts +5 -3
- package/dist/primitives/thread/ThreadViewportFooter.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewportFooter.js +1 -1
- package/dist/primitives/thread/ThreadViewportFooter.js.map +1 -1
- package/dist/primitives/threadList/ThreadListNew.d.ts +4 -2
- package/dist/primitives/threadList/ThreadListNew.d.ts.map +1 -1
- package/dist/primitives/threadList/ThreadListNew.js +1 -1
- package/dist/primitives/threadList/ThreadListNew.js.map +1 -1
- package/dist/primitives/threadList/ThreadListRoot.d.ts +5 -3
- package/dist/primitives/threadList/ThreadListRoot.d.ts.map +1 -1
- package/dist/primitives/threadList/ThreadListRoot.js +1 -1
- package/dist/primitives/threadList/ThreadListRoot.js.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemArchive.d.ts +4 -2
- package/dist/primitives/threadListItem/ThreadListItemArchive.d.ts.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemDelete.d.ts +4 -2
- package/dist/primitives/threadListItem/ThreadListItemDelete.d.ts.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemRoot.d.ts +5 -3
- package/dist/primitives/threadListItem/ThreadListItemRoot.d.ts.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemRoot.js +1 -1
- package/dist/primitives/threadListItem/ThreadListItemRoot.js.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemTrigger.d.ts +4 -2
- package/dist/primitives/threadListItem/ThreadListItemTrigger.d.ts.map +1 -1
- package/dist/primitives/threadListItem/ThreadListItemUnarchive.d.ts +4 -2
- package/dist/primitives/threadListItem/ThreadListItemUnarchive.d.ts.map +1 -1
- package/dist/utils/Primitive.d.ts +106 -0
- package/dist/utils/Primitive.d.ts.map +1 -0
- package/dist/utils/Primitive.js +54 -0
- package/dist/utils/Primitive.js.map +1 -0
- package/dist/utils/createActionButton.d.ts +5 -3
- package/dist/utils/createActionButton.d.ts.map +1 -1
- package/dist/utils/createActionButton.js +1 -1
- package/dist/utils/createActionButton.js.map +1 -1
- package/package.json +7 -8
- package/src/client/ExternalThread.ts +8 -2
- package/src/client/InMemoryThreadList.ts +3 -0
- package/src/client/SingleThreadList.ts +2 -0
- package/src/index.ts +21 -6
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +7 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts +4 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.test.ts +186 -3
- package/src/primitives/actionBar/ActionBarCopy.tsx +1 -1
- package/src/primitives/actionBar/ActionBarExportMarkdown.tsx +1 -1
- package/src/primitives/actionBar/ActionBarFeedbackNegative.tsx +1 -1
- package/src/primitives/actionBar/ActionBarFeedbackPositive.tsx +1 -1
- package/src/primitives/actionBar/ActionBarRoot.tsx +1 -1
- package/src/primitives/actionBar/ActionBarStopSpeaking.tsx +1 -1
- package/src/primitives/attachment/AttachmentRoot.tsx +1 -1
- package/src/primitives/attachment/AttachmentThumb.tsx +1 -1
- package/src/primitives/branchPicker/BranchPickerRoot.tsx +1 -1
- package/src/primitives/chainOfThought/ChainOfThoughtRoot.tsx +1 -1
- package/src/primitives/composer/ComposerAttachmentDropzone.tsx +41 -18
- package/src/primitives/composer/ComposerDictationTranscript.tsx +1 -1
- package/src/primitives/composer/ComposerInput.tsx +43 -17
- package/src/primitives/composer/ComposerQuote.tsx +1 -1
- package/src/primitives/composer/ComposerRoot.tsx +1 -1
- package/src/primitives/composer/mention/ComposerMentionBack.tsx +1 -1
- package/src/primitives/composer/mention/ComposerMentionCategories.tsx +1 -1
- package/src/primitives/composer/mention/ComposerMentionItems.tsx +1 -1
- package/src/primitives/composer/mention/ComposerMentionPopover.tsx +1 -1
- package/src/primitives/error/ErrorMessage.tsx +1 -1
- package/src/primitives/error/ErrorRoot.tsx +1 -1
- package/src/primitives/message/MessageRoot.tsx +1 -1
- package/src/primitives/messagePart/MessagePartImage.tsx +1 -1
- package/src/primitives/messagePart/MessagePartText.tsx +1 -1
- package/src/primitives/queueItem/QueueItemText.tsx +1 -1
- package/src/primitives/selectionToolbar/SelectionToolbarQuote.tsx +1 -1
- package/src/primitives/selectionToolbar/SelectionToolbarRoot.tsx +1 -1
- package/src/primitives/suggestion/SuggestionDescription.tsx +1 -1
- package/src/primitives/suggestion/SuggestionTitle.tsx +1 -1
- package/src/primitives/thread/ThreadRoot.tsx +1 -1
- package/src/primitives/thread/ThreadViewport.tsx +1 -1
- package/src/primitives/thread/ThreadViewportFooter.tsx +1 -1
- package/src/primitives/threadList/ThreadListNew.tsx +1 -1
- package/src/primitives/threadList/ThreadListRoot.tsx +1 -1
- package/src/primitives/threadListItem/ThreadListItemRoot.tsx +1 -1
- package/src/utils/Primitive.test.tsx +99 -0
- package/src/utils/Primitive.tsx +100 -0
- package/src/utils/createActionButton.tsx +1 -1
package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.ts
CHANGED
|
@@ -147,6 +147,10 @@ const useAssistantTransportThreadRuntime = <T>(
|
|
|
147
147
|
...(parentIdRef.current !== undefined && {
|
|
148
148
|
parentId: parentIdRef.current,
|
|
149
149
|
}),
|
|
150
|
+
// nested (new format, aligned with AssistantChatTransport)
|
|
151
|
+
callSettings: context.callSettings,
|
|
152
|
+
config: context.config,
|
|
153
|
+
// @deprecated spread at top level — use nested `callSettings`/`config` instead. Will be removed in a future version.
|
|
150
154
|
...context.callSettings,
|
|
151
155
|
...context.config,
|
|
152
156
|
...(bodyValue ?? {}),
|
|
@@ -19,7 +19,13 @@ const createState = (
|
|
|
19
19
|
const createAssistantMessage = (
|
|
20
20
|
argsText: string,
|
|
21
21
|
args: Record<string, unknown>,
|
|
22
|
-
options?: {
|
|
22
|
+
options?: {
|
|
23
|
+
result?: ReadonlyJSONValue;
|
|
24
|
+
isError?: boolean;
|
|
25
|
+
toolCallId?: string;
|
|
26
|
+
toolName?: string;
|
|
27
|
+
nestedMessages?: ThreadAssistantMessage[];
|
|
28
|
+
},
|
|
23
29
|
): ThreadAssistantMessage => ({
|
|
24
30
|
id: "m-1",
|
|
25
31
|
role: "assistant",
|
|
@@ -35,12 +41,13 @@ const createAssistantMessage = (
|
|
|
35
41
|
content: [
|
|
36
42
|
{
|
|
37
43
|
type: "tool-call",
|
|
38
|
-
toolCallId: "tool-1",
|
|
39
|
-
toolName: "weatherSearch",
|
|
44
|
+
toolCallId: options?.toolCallId ?? "tool-1",
|
|
45
|
+
toolName: options?.toolName ?? "weatherSearch",
|
|
40
46
|
args: args as ReadonlyJSONObject,
|
|
41
47
|
argsText,
|
|
42
48
|
...(options?.result !== undefined && { result: options.result }),
|
|
43
49
|
...(options?.isError !== undefined && { isError: options.isError }),
|
|
50
|
+
...(options?.nestedMessages && { messages: options.nestedMessages }),
|
|
44
51
|
},
|
|
45
52
|
],
|
|
46
53
|
});
|
|
@@ -228,6 +235,182 @@ describe("useToolInvocations", () => {
|
|
|
228
235
|
expect(Object.keys(statuses)).not.toContain("tool-1:rewrite:0");
|
|
229
236
|
});
|
|
230
237
|
|
|
238
|
+
it("does not execute tool calls loaded asynchronously with existing results", async () => {
|
|
239
|
+
const execute = vi.fn(async () => ({ forecast: "ok" }));
|
|
240
|
+
const getTools = () => ({
|
|
241
|
+
weatherSearch: {
|
|
242
|
+
parameters: { type: "object", properties: {} },
|
|
243
|
+
execute,
|
|
244
|
+
} satisfies Tool,
|
|
245
|
+
});
|
|
246
|
+
const onResult = vi.fn();
|
|
247
|
+
const setToolStatuses = vi.fn();
|
|
248
|
+
|
|
249
|
+
const { rerender } = renderHook(
|
|
250
|
+
({ state }: { state: AssistantTransportState }) =>
|
|
251
|
+
useToolInvocations({
|
|
252
|
+
state,
|
|
253
|
+
getTools,
|
|
254
|
+
onResult,
|
|
255
|
+
setToolStatuses,
|
|
256
|
+
}),
|
|
257
|
+
{
|
|
258
|
+
initialProps: {
|
|
259
|
+
state: createState([]),
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
act(() => {
|
|
265
|
+
rerender({
|
|
266
|
+
state: createState([
|
|
267
|
+
createAssistantMessage(
|
|
268
|
+
'{"query":"London"}',
|
|
269
|
+
{ query: "London" },
|
|
270
|
+
{ result: { source: "history" } },
|
|
271
|
+
),
|
|
272
|
+
]),
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
await waitFor(() => {
|
|
277
|
+
expect(execute).not.toHaveBeenCalled();
|
|
278
|
+
expect(onResult).not.toHaveBeenCalled();
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("does not re-execute asynchronously loaded resolved tool calls after reset", async () => {
|
|
283
|
+
const execute = vi.fn(async () => ({ forecast: "ok" }));
|
|
284
|
+
const getTools = () => ({
|
|
285
|
+
weatherSearch: {
|
|
286
|
+
parameters: { type: "object", properties: {} },
|
|
287
|
+
execute,
|
|
288
|
+
} satisfies Tool,
|
|
289
|
+
});
|
|
290
|
+
const onResult = vi.fn();
|
|
291
|
+
const setToolStatuses = vi.fn();
|
|
292
|
+
|
|
293
|
+
const { result, rerender } = renderHook(
|
|
294
|
+
({ state }: { state: AssistantTransportState }) =>
|
|
295
|
+
useToolInvocations({
|
|
296
|
+
state,
|
|
297
|
+
getTools,
|
|
298
|
+
onResult,
|
|
299
|
+
setToolStatuses,
|
|
300
|
+
}),
|
|
301
|
+
{
|
|
302
|
+
initialProps: {
|
|
303
|
+
state: createState([]),
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
act(() => {
|
|
309
|
+
rerender({
|
|
310
|
+
state: createState([
|
|
311
|
+
createAssistantMessage('{"query":"London"}', { query: "London" }),
|
|
312
|
+
]),
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
await waitFor(() => {
|
|
317
|
+
expect(execute).toHaveBeenCalledTimes(1);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
act(() => {
|
|
321
|
+
result.current.reset();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
await act(async () => {
|
|
325
|
+
await Promise.resolve();
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
act(() => {
|
|
329
|
+
rerender({
|
|
330
|
+
state: createState([]),
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
act(() => {
|
|
335
|
+
rerender({
|
|
336
|
+
state: createState([
|
|
337
|
+
createAssistantMessage(
|
|
338
|
+
'{"query":"London"}',
|
|
339
|
+
{ query: "London" },
|
|
340
|
+
{ result: { source: "history" } },
|
|
341
|
+
),
|
|
342
|
+
]),
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
await waitFor(() => {
|
|
347
|
+
expect(execute).toHaveBeenCalledTimes(1);
|
|
348
|
+
expect(onResult).toHaveBeenCalledTimes(1);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("still processes nested unresolved tool calls when the parent tool call is already resolved", async () => {
|
|
353
|
+
const executeParent = vi.fn(async () => ({ scope: "parent" }));
|
|
354
|
+
const executeChild = vi.fn(async () => ({ scope: "child" }));
|
|
355
|
+
const getTools = () => ({
|
|
356
|
+
resolvedOnly: {
|
|
357
|
+
parameters: { type: "object", properties: {} },
|
|
358
|
+
execute: executeParent,
|
|
359
|
+
} satisfies Tool,
|
|
360
|
+
childTool: {
|
|
361
|
+
parameters: { type: "object", properties: {} },
|
|
362
|
+
execute: executeChild,
|
|
363
|
+
} satisfies Tool,
|
|
364
|
+
});
|
|
365
|
+
const onResult = vi.fn();
|
|
366
|
+
const setToolStatuses = vi.fn();
|
|
367
|
+
|
|
368
|
+
const nestedMessage = createAssistantMessage(
|
|
369
|
+
'{"query":"nested"}',
|
|
370
|
+
{ query: "nested" },
|
|
371
|
+
{
|
|
372
|
+
toolCallId: "tool-child",
|
|
373
|
+
toolName: "childTool",
|
|
374
|
+
},
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
const { rerender } = renderHook(
|
|
378
|
+
({ state }: { state: AssistantTransportState }) =>
|
|
379
|
+
useToolInvocations({
|
|
380
|
+
state,
|
|
381
|
+
getTools,
|
|
382
|
+
onResult,
|
|
383
|
+
setToolStatuses,
|
|
384
|
+
}),
|
|
385
|
+
{
|
|
386
|
+
initialProps: {
|
|
387
|
+
state: createState([]),
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
act(() => {
|
|
393
|
+
rerender({
|
|
394
|
+
state: createState([
|
|
395
|
+
createAssistantMessage(
|
|
396
|
+
'{"query":"parent"}',
|
|
397
|
+
{ query: "parent" },
|
|
398
|
+
{
|
|
399
|
+
result: { source: "history" },
|
|
400
|
+
toolName: "resolvedOnly",
|
|
401
|
+
nestedMessages: [nestedMessage],
|
|
402
|
+
},
|
|
403
|
+
),
|
|
404
|
+
]),
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
await waitFor(() => {
|
|
409
|
+
expect(executeParent).not.toHaveBeenCalled();
|
|
410
|
+
expect(executeChild).toHaveBeenCalledTimes(1);
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
|
|
231
414
|
it("does not close args stream early for non-executable tool snapshots", () => {
|
|
232
415
|
const getTools = () => ({
|
|
233
416
|
weatherSearch: {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
import { ActionButtonProps } from "../../utils/createActionButton";
|
|
5
5
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
6
|
-
import { Primitive } from "
|
|
6
|
+
import { Primitive } from "../../utils/Primitive";
|
|
7
7
|
import { useActionBarCopy } from "@assistant-ui/core/react";
|
|
8
8
|
import { useAuiState } from "@assistant-ui/store";
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { forwardRef, useCallback } from "react";
|
|
4
4
|
import { ActionButtonProps } from "../../utils/createActionButton";
|
|
5
5
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
6
|
-
import { Primitive } from "
|
|
6
|
+
import { Primitive } from "../../utils/Primitive";
|
|
7
7
|
import { useAuiState, useAui } from "@assistant-ui/store";
|
|
8
8
|
|
|
9
9
|
const useActionBarExportMarkdown = ({
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
import { ActionButtonProps } from "../../utils/createActionButton";
|
|
5
5
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
6
|
-
import { Primitive } from "
|
|
6
|
+
import { Primitive } from "../../utils/Primitive";
|
|
7
7
|
import { useAuiState } from "@assistant-ui/store";
|
|
8
8
|
import { useActionBarFeedbackNegative as useActionBarFeedbackNegativeBehavior } from "@assistant-ui/core/react";
|
|
9
9
|
|
|
@@ -4,7 +4,7 @@ import { forwardRef } from "react";
|
|
|
4
4
|
import { ActionButtonProps } from "../../utils/createActionButton";
|
|
5
5
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
6
6
|
import { useAuiState } from "@assistant-ui/store";
|
|
7
|
-
import { Primitive } from "
|
|
7
|
+
import { Primitive } from "../../utils/Primitive";
|
|
8
8
|
import { useActionBarFeedbackPositive as useActionBarFeedbackPositiveBehavior } from "@assistant-ui/core/react";
|
|
9
9
|
|
|
10
10
|
const useActionBarFeedbackPositive = () => {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
import { ActionButtonProps } from "../../utils/createActionButton";
|
|
5
5
|
import { useEscapeKeydown } from "@radix-ui/react-use-escape-keydown";
|
|
6
|
-
import { Primitive } from "
|
|
6
|
+
import { Primitive } from "../../utils/Primitive";
|
|
7
7
|
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
8
8
|
import { useActionBarStopSpeaking as useActionBarStopSpeakingBehavior } from "@assistant-ui/core/react";
|
|
9
9
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { Primitive } from "
|
|
3
|
+
import { Primitive } from "../../utils/Primitive";
|
|
4
4
|
import { ComponentPropsWithoutRef, ComponentRef, forwardRef } from "react";
|
|
5
5
|
|
|
6
6
|
type PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { ComponentPropsWithoutRef, forwardRef, type ComponentRef } from "react";
|
|
4
4
|
import { useAuiState } from "@assistant-ui/store";
|
|
5
|
-
import { Primitive } from "
|
|
5
|
+
import { Primitive } from "../../utils/Primitive";
|
|
6
6
|
|
|
7
7
|
type PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
8
8
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { Primitive } from "
|
|
3
|
+
import { Primitive } from "../../utils/Primitive";
|
|
4
4
|
import { type ComponentRef, forwardRef, ComponentPropsWithoutRef } from "react";
|
|
5
5
|
import { MessagePrimitiveIf as If } from "../message/MessageIf";
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { Primitive } from "
|
|
3
|
+
import { Primitive } from "../../utils/Primitive";
|
|
4
4
|
import { type ComponentRef, forwardRef, ComponentPropsWithoutRef } from "react";
|
|
5
5
|
|
|
6
6
|
type PrimitiveDivProps = ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
forwardRef,
|
|
5
|
+
useCallback,
|
|
6
|
+
useState,
|
|
7
|
+
type ReactElement,
|
|
8
|
+
cloneElement,
|
|
9
|
+
isValidElement,
|
|
10
|
+
} from "react";
|
|
4
11
|
|
|
12
|
+
import { composeEventHandlers } from "@radix-ui/primitive";
|
|
5
13
|
import { Slot } from "radix-ui";
|
|
6
14
|
import React from "react";
|
|
7
15
|
import { useAui } from "@assistant-ui/store";
|
|
@@ -10,6 +18,7 @@ export namespace ComposerPrimitiveAttachmentDropzone {
|
|
|
10
18
|
export type Element = HTMLDivElement;
|
|
11
19
|
export type Props = React.HTMLAttributes<HTMLDivElement> & {
|
|
12
20
|
asChild?: boolean | undefined;
|
|
21
|
+
render?: ReactElement | undefined;
|
|
13
22
|
disabled?: boolean | undefined;
|
|
14
23
|
};
|
|
15
24
|
}
|
|
@@ -17,7 +26,7 @@ export namespace ComposerPrimitiveAttachmentDropzone {
|
|
|
17
26
|
export const ComposerPrimitiveAttachmentDropzone = forwardRef<
|
|
18
27
|
HTMLDivElement,
|
|
19
28
|
ComposerPrimitiveAttachmentDropzone.Props
|
|
20
|
-
>(({ disabled, asChild = false, children, ...rest }, ref) => {
|
|
29
|
+
>(({ disabled, asChild = false, render, children, ...rest }, ref) => {
|
|
21
30
|
const [isDragging, setIsDragging] = useState(false);
|
|
22
31
|
const aui = useAui();
|
|
23
32
|
|
|
@@ -68,25 +77,39 @@ export const ComposerPrimitiveAttachmentDropzone = forwardRef<
|
|
|
68
77
|
[disabled, aui],
|
|
69
78
|
);
|
|
70
79
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
const mergedProps = {
|
|
81
|
+
...(isDragging ? { "data-dragging": "true" } : null),
|
|
82
|
+
...rest,
|
|
83
|
+
onDragEnterCapture: composeEventHandlers(
|
|
84
|
+
rest.onDragEnterCapture,
|
|
85
|
+
handleDragEnterCapture,
|
|
86
|
+
),
|
|
87
|
+
onDragOverCapture: composeEventHandlers(
|
|
88
|
+
rest.onDragOverCapture,
|
|
89
|
+
handleDragOverCapture,
|
|
90
|
+
),
|
|
91
|
+
onDragLeaveCapture: composeEventHandlers(
|
|
92
|
+
rest.onDragLeaveCapture,
|
|
93
|
+
handleDragLeaveCapture,
|
|
94
|
+
),
|
|
95
|
+
onDropCapture: composeEventHandlers(rest.onDropCapture, handleDrop),
|
|
96
|
+
ref,
|
|
76
97
|
};
|
|
77
98
|
|
|
78
|
-
|
|
99
|
+
if (render && isValidElement(render)) {
|
|
100
|
+
const renderChildren =
|
|
101
|
+
children !== undefined
|
|
102
|
+
? children
|
|
103
|
+
: (render.props as Record<string, unknown>).children;
|
|
104
|
+
return (
|
|
105
|
+
<Slot.Root {...mergedProps}>
|
|
106
|
+
{cloneElement(render, undefined, renderChildren as React.ReactNode)}
|
|
107
|
+
</Slot.Root>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
79
110
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{...(isDragging ? { "data-dragging": "true" } : null)}
|
|
83
|
-
ref={ref}
|
|
84
|
-
{...dragProps}
|
|
85
|
-
{...rest}
|
|
86
|
-
>
|
|
87
|
-
{children}
|
|
88
|
-
</Comp>
|
|
89
|
-
);
|
|
111
|
+
const Comp = asChild ? Slot.Root : "div";
|
|
112
|
+
return <Comp {...mergedProps}>{children}</Comp>;
|
|
90
113
|
});
|
|
91
114
|
|
|
92
115
|
ComposerPrimitiveAttachmentDropzone.displayName =
|
|
@@ -6,10 +6,14 @@ import { Slot } from "radix-ui";
|
|
|
6
6
|
import {
|
|
7
7
|
ClipboardEvent,
|
|
8
8
|
type KeyboardEvent,
|
|
9
|
+
type ReactElement,
|
|
10
|
+
type ReactNode,
|
|
9
11
|
forwardRef,
|
|
10
12
|
useCallback,
|
|
11
13
|
useEffect,
|
|
12
14
|
useRef,
|
|
15
|
+
cloneElement,
|
|
16
|
+
isValidElement,
|
|
13
17
|
} from "react";
|
|
14
18
|
import TextareaAutosize, {
|
|
15
19
|
type TextareaAutosizeProps,
|
|
@@ -32,6 +36,10 @@ export namespace ComposerPrimitiveInput {
|
|
|
32
36
|
* When true, the component will merge its props with its child.
|
|
33
37
|
*/
|
|
34
38
|
asChild?: boolean | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* A React element to use as the input container, with props merged in.
|
|
41
|
+
*/
|
|
42
|
+
render?: ReactElement | undefined;
|
|
35
43
|
/**
|
|
36
44
|
* Whether to cancel message composition when Escape is pressed.
|
|
37
45
|
* @default true
|
|
@@ -118,6 +126,7 @@ export const ComposerPrimitiveInput = forwardRef<
|
|
|
118
126
|
{
|
|
119
127
|
autoFocus = false,
|
|
120
128
|
asChild,
|
|
129
|
+
render,
|
|
121
130
|
disabled: disabledProp,
|
|
122
131
|
onChange,
|
|
123
132
|
onKeyDown,
|
|
@@ -146,8 +155,6 @@ export const ComposerPrimitiveInput = forwardRef<
|
|
|
146
155
|
return s.composer.text;
|
|
147
156
|
});
|
|
148
157
|
|
|
149
|
-
const Component = asChild ? Slot.Root : TextareaAutosize;
|
|
150
|
-
|
|
151
158
|
const isDisabled =
|
|
152
159
|
useAuiState(
|
|
153
160
|
(s) => s.thread.isDisabled || s.composer.dictation?.inputDisabled,
|
|
@@ -277,14 +284,15 @@ export const ComposerPrimitiveInput = forwardRef<
|
|
|
277
284
|
return aui.on("threadListItem.switchedTo", focus);
|
|
278
285
|
}, [unstable_focusOnThreadSwitched, focus, aui]);
|
|
279
286
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
onChange
|
|
287
|
+
const inputProps = {
|
|
288
|
+
name: "input" as const,
|
|
289
|
+
value,
|
|
290
|
+
...rest,
|
|
291
|
+
ref: ref as React.ForwardedRef<HTMLTextAreaElement>,
|
|
292
|
+
disabled: isDisabled,
|
|
293
|
+
onChange: composeEventHandlers(
|
|
294
|
+
onChange,
|
|
295
|
+
(e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
288
296
|
if (!aui.composer().getState().isEditing) return;
|
|
289
297
|
flushResourcesSync(() => {
|
|
290
298
|
aui.composer().setText(e.target.value);
|
|
@@ -292,17 +300,35 @@ export const ComposerPrimitiveInput = forwardRef<
|
|
|
292
300
|
mentionInternalContext?.setCursorPosition(
|
|
293
301
|
e.target.selectionStart ?? e.target.value.length,
|
|
294
302
|
);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
303
|
+
},
|
|
304
|
+
),
|
|
305
|
+
onKeyDown: composeEventHandlers(onKeyDown, handleKeyPress),
|
|
306
|
+
onSelect: composeEventHandlers(
|
|
307
|
+
onSelect,
|
|
308
|
+
(e: React.SyntheticEvent<HTMLTextAreaElement>) => {
|
|
298
309
|
const target = e.target as HTMLTextAreaElement;
|
|
299
310
|
mentionInternalContext?.setCursorPosition(
|
|
300
311
|
target.selectionStart ?? target.value.length,
|
|
301
312
|
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
313
|
+
},
|
|
314
|
+
),
|
|
315
|
+
onPaste: composeEventHandlers(onPaste, handlePaste),
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
if (render && isValidElement(render)) {
|
|
319
|
+
const renderChildren =
|
|
320
|
+
(rest as any).children !== undefined
|
|
321
|
+
? ((rest as any).children as ReactNode)
|
|
322
|
+
: ((render.props as Record<string, unknown>).children as ReactNode);
|
|
323
|
+
return (
|
|
324
|
+
<Slot.Root {...inputProps}>
|
|
325
|
+
{cloneElement(render, undefined, renderChildren)}
|
|
326
|
+
</Slot.Root>
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const Component = asChild ? Slot.Root : TextareaAutosize;
|
|
331
|
+
return <Component {...inputProps} />;
|
|
306
332
|
},
|
|
307
333
|
);
|
|
308
334
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { Primitive } from "
|
|
3
|
+
import { Primitive } from "../../utils/Primitive";
|
|
4
4
|
import { type ComponentRef, forwardRef, ComponentPropsWithoutRef } from "react";
|
|
5
5
|
import { useMessageError } from "@assistant-ui/core/react";
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { Primitive } from "
|
|
3
|
+
import { Primitive } from "../../utils/Primitive";
|
|
4
4
|
import { type ComponentRef, forwardRef, ComponentPropsWithoutRef } from "react";
|
|
5
5
|
import { useMessagePartImage } from "./useMessagePartImage";
|
|
6
6
|
|