@assistant-ui/react 0.11.20 → 0.11.22
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/augmentations.d.ts +20 -9
- package/dist/augmentations.d.ts.map +1 -1
- package/dist/client/AssistantClient.d.ts +6 -7
- package/dist/client/AssistantClient.d.ts.map +1 -1
- package/dist/client/AssistantClient.js +9 -4
- package/dist/client/AssistantClient.js.map +1 -1
- package/dist/client/NoOpComposerClient.d.ts +9 -0
- package/dist/client/NoOpComposerClient.d.ts.map +1 -0
- package/dist/client/NoOpComposerClient.js +59 -0
- package/dist/client/NoOpComposerClient.js.map +1 -0
- package/dist/client/ThreadMessageClient.d.ts +14 -0
- package/dist/client/ThreadMessageClient.d.ts.map +1 -0
- package/dist/client/ThreadMessageClient.js +140 -0
- package/dist/client/ThreadMessageClient.js.map +1 -0
- package/dist/client/types/Part.d.ts +5 -0
- package/dist/client/types/Part.d.ts.map +1 -1
- package/dist/client/types/Thread.d.ts +8 -0
- package/dist/client/types/Thread.d.ts.map +1 -1
- package/dist/context/providers/MessageProvider.d.ts +1 -8
- package/dist/context/providers/MessageProvider.d.ts.map +1 -1
- package/dist/context/providers/MessageProvider.js +4 -181
- package/dist/context/providers/MessageProvider.js.map +1 -1
- package/dist/context/providers/TextMessagePartProvider.d.ts.map +1 -1
- package/dist/context/providers/TextMessagePartProvider.js +3 -1
- package/dist/context/providers/TextMessagePartProvider.js.map +1 -1
- package/dist/context/react/AssistantApiContext.d.ts +3 -1
- package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
- package/dist/context/react/AssistantApiContext.js +17 -4
- package/dist/context/react/AssistantApiContext.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +5 -1
- package/dist/internal.js.map +1 -1
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.js +9 -10
- package/dist/legacy-runtime/client/MessagePartRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/ThreadRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ThreadRuntimeClient.js +6 -0
- package/dist/legacy-runtime/client/ThreadRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts +1 -1
- package/dist/legacy-runtime/cloud/useCloudThreadListRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/AssistantContext.js +1 -1
- package/dist/legacy-runtime/hooks/AssistantContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.js +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/ComposerContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/ComposerContext.js +1 -1
- package/dist/legacy-runtime/hooks/ComposerContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/MessageContext.d.ts.map +1 -1
- package/dist/legacy-runtime/hooks/MessageContext.js +1 -1
- package/dist/legacy-runtime/hooks/MessageContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.js +1 -1
- package/dist/legacy-runtime/hooks/MessagePartContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadContext.js +1 -1
- package/dist/legacy-runtime/hooks/ThreadContext.js.map +1 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js +1 -1
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js.map +1 -1
- package/dist/legacy-runtime/runtime/MessagePartRuntime.d.ts +6 -0
- package/dist/legacy-runtime/runtime/MessagePartRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime/MessagePartRuntime.js +13 -0
- package/dist/legacy-runtime/runtime/MessagePartRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts +1 -0
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +2 -0
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.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 +5 -2
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts +2 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js +3 -3
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts +9 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js +48 -7
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts +2 -1
- package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts +7 -1
- package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.d.ts +5 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts +2 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js +12 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts +4 -1
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js +5 -1
- package/dist/legacy-runtime/runtime-cores/external-store/auto-status.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.d.ts +3 -2
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.js +6 -4
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts +8 -3
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js +20 -6
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts +3 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js +4 -0
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts +1 -1
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js +4 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +2 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.js +1 -3
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +2 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.d.ts +3 -3
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.d.ts +2 -2
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js +1 -1
- package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js.map +1 -1
- package/dist/model-context/frame/AssistantFrameProvider.d.ts.map +1 -1
- package/dist/model-context/frame/AssistantFrameProvider.js +6 -1
- package/dist/model-context/frame/AssistantFrameProvider.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNext.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerNext.js +7 -3
- package/dist/primitives/branchPicker/BranchPickerNext.js.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerPrevious.d.ts.map +1 -1
- package/dist/primitives/branchPicker/BranchPickerPrevious.js +7 -3
- package/dist/primitives/branchPicker/BranchPickerPrevious.js.map +1 -1
- package/dist/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/primitives/message/MessageParts.js +12 -3
- package/dist/primitives/message/MessageParts.js.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.d.ts.map +1 -1
- package/dist/primitives/message/MessagePartsGrouped.js +11 -2
- package/dist/primitives/message/MessagePartsGrouped.js.map +1 -1
- package/dist/tests/setup.js +8 -8
- package/dist/tests/setup.js.map +1 -1
- package/dist/types/AssistantTypes.d.ts +2 -2
- package/dist/types/AssistantTypes.d.ts.map +1 -1
- package/dist/types/MessagePartComponentTypes.d.ts +1 -0
- package/dist/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/types/MessagePartTypes.d.ts +1 -0
- package/dist/types/MessagePartTypes.d.ts.map +1 -1
- package/dist/utils/smooth/SmoothContext.d.ts +6 -6
- package/package.json +10 -10
- package/src/augmentations.ts +21 -24
- package/src/client/AssistantClient.ts +15 -8
- package/src/client/NoOpComposerClient.tsx +56 -0
- package/src/client/ThreadMessageClient.tsx +161 -0
- package/src/client/types/Attachment.ts +1 -1
- package/src/client/types/Composer.ts +1 -1
- package/src/client/types/Message.ts +1 -1
- package/src/client/types/Part.ts +7 -1
- package/src/client/types/Thread.ts +11 -1
- package/src/client/types/ThreadListItem.ts +1 -1
- package/src/context/providers/MessageProvider.tsx +4 -222
- package/src/context/providers/TextMessagePartProvider.tsx +3 -1
- package/src/context/react/AssistantApiContext.tsx +27 -5
- package/src/index.ts +3 -0
- package/src/internal.ts +4 -0
- package/src/legacy-runtime/client/MessagePartRuntimeClient.ts +12 -13
- package/src/legacy-runtime/client/ThreadRuntimeClient.ts +6 -0
- package/src/legacy-runtime/hooks/AssistantContext.ts +1 -1
- package/src/legacy-runtime/hooks/AttachmentContext.ts +3 -1
- package/src/legacy-runtime/hooks/ComposerContext.ts +3 -1
- package/src/legacy-runtime/hooks/MessageContext.ts +3 -1
- package/src/legacy-runtime/hooks/MessagePartContext.ts +1 -1
- package/src/legacy-runtime/hooks/ThreadContext.ts +1 -1
- package/src/legacy-runtime/hooks/ThreadListItemContext.ts +1 -1
- package/src/legacy-runtime/runtime/MessagePartRuntime.ts +23 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +2 -0
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +10 -3
- package/src/legacy-runtime/runtime-cores/assistant-transport/useConvertedState.ts +4 -2
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +73 -6
- package/src/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.tsx +2 -0
- package/src/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.tsx +8 -1
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.tsx +4 -1
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.tsx +15 -1
- package/src/legacy-runtime/runtime-cores/external-store/auto-status.tsx +11 -3
- package/src/legacy-runtime/runtime-cores/external-store/createMessageConverter.tsx +9 -2
- package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.tsx +33 -5
- package/src/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.tsx +6 -0
- package/src/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.tsx +5 -0
- package/src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +1 -4
- package/src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx +3 -3
- package/src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.tsx +2 -1
- package/src/legacy-runtime/runtime-cores/utils/MessageRepository.tsx +1 -1
- package/src/model-context/frame/AssistantFrameProvider.ts +5 -0
- package/src/primitives/branchPicker/BranchPickerNext.tsx +11 -3
- package/src/primitives/branchPicker/BranchPickerPrevious.tsx +11 -3
- package/src/primitives/message/MessageParts.tsx +11 -3
- package/src/primitives/message/MessagePartsGrouped.tsx +10 -2
- package/src/types/AssistantTypes.ts +2 -2
- package/src/types/MessagePartComponentTypes.tsx +1 -0
- package/src/types/MessagePartTypes.ts +1 -0
@@ -6,230 +6,12 @@ import {
|
|
6
6
|
AssistantApi,
|
7
7
|
createAssistantApiField,
|
8
8
|
} from "../react/AssistantApiContext";
|
9
|
-
import {
|
10
|
-
MessageClientApi,
|
11
|
-
MessageClientState,
|
12
|
-
} from "../../client/types/Message";
|
13
|
-
import {
|
14
|
-
resource,
|
15
|
-
tapInlineResource,
|
16
|
-
tapMemo,
|
17
|
-
tapState,
|
18
|
-
} from "@assistant-ui/tap";
|
19
9
|
import { useResource } from "@assistant-ui/tap/react";
|
20
|
-
import { asStore
|
21
|
-
import {
|
22
|
-
ThreadAssistantMessagePart,
|
23
|
-
ThreadMessage,
|
24
|
-
ThreadUserMessagePart,
|
25
|
-
} from "../../types/AssistantTypes";
|
10
|
+
import { asStore } from "../../utils/tap-store";
|
26
11
|
import {
|
27
|
-
|
28
|
-
|
29
|
-
} from "../../client/
|
30
|
-
import {
|
31
|
-
MessagePartClientApi,
|
32
|
-
MessagePartClientState,
|
33
|
-
} from "../../client/types/Part";
|
34
|
-
import { tapLookupResources } from "../../client/util-hooks/tapLookupResources";
|
35
|
-
import { Attachment } from "../../types";
|
36
|
-
import { AttachmentClientApi } from "../../client/types/Attachment";
|
37
|
-
|
38
|
-
const NoOpComposerClient = resource(({ type }: { type: "edit" | "thread" }) => {
|
39
|
-
const state = tapMemo<ComposerClientState>(() => {
|
40
|
-
return {
|
41
|
-
isEditing: false,
|
42
|
-
isEmpty: true,
|
43
|
-
text: "",
|
44
|
-
attachmentAccept: "*",
|
45
|
-
attachments: [],
|
46
|
-
role: "user",
|
47
|
-
runConfig: {},
|
48
|
-
canCancel: false,
|
49
|
-
type: type,
|
50
|
-
};
|
51
|
-
}, [type]);
|
52
|
-
|
53
|
-
return tapApi<ComposerClientApi>({
|
54
|
-
getState: () => state,
|
55
|
-
setText: () => {
|
56
|
-
throw new Error("Not supported");
|
57
|
-
},
|
58
|
-
setRole: () => {
|
59
|
-
throw new Error("Not supported");
|
60
|
-
},
|
61
|
-
setRunConfig: () => {
|
62
|
-
throw new Error("Not supported");
|
63
|
-
},
|
64
|
-
addAttachment: () => {
|
65
|
-
throw new Error("Not supported");
|
66
|
-
},
|
67
|
-
clearAttachments: () => {
|
68
|
-
throw new Error("Not supported");
|
69
|
-
},
|
70
|
-
attachment: () => {
|
71
|
-
throw new Error("Not supported");
|
72
|
-
},
|
73
|
-
reset: () => {
|
74
|
-
throw new Error("Not supported");
|
75
|
-
},
|
76
|
-
send: () => {
|
77
|
-
throw new Error("Not supported");
|
78
|
-
},
|
79
|
-
cancel: () => {
|
80
|
-
throw new Error("Not supported");
|
81
|
-
},
|
82
|
-
beginEdit: () => {
|
83
|
-
throw new Error("Not supported");
|
84
|
-
},
|
85
|
-
__internal_getRuntime: () => null,
|
86
|
-
});
|
87
|
-
});
|
88
|
-
|
89
|
-
const ThreadMessagePartClient = resource(
|
90
|
-
({ part }: { part: ThreadAssistantMessagePart | ThreadUserMessagePart }) => {
|
91
|
-
const state = tapMemo<MessagePartClientState>(() => {
|
92
|
-
return {
|
93
|
-
...part,
|
94
|
-
status: { type: "complete" },
|
95
|
-
};
|
96
|
-
}, [part]);
|
97
|
-
|
98
|
-
return tapApi<MessagePartClientApi>(
|
99
|
-
{
|
100
|
-
getState: () => state,
|
101
|
-
addToolResult: () => {
|
102
|
-
throw new Error("Not supported");
|
103
|
-
},
|
104
|
-
__internal_getRuntime: () => null,
|
105
|
-
},
|
106
|
-
{
|
107
|
-
key:
|
108
|
-
state.type === "tool-call"
|
109
|
-
? "toolCallId-" + state.toolCallId
|
110
|
-
: undefined,
|
111
|
-
},
|
112
|
-
);
|
113
|
-
},
|
114
|
-
);
|
115
|
-
|
116
|
-
const ThreadMessageAttachmentClient = resource(
|
117
|
-
({ attachment }: { attachment: Attachment }) => {
|
118
|
-
return tapApi<AttachmentClientApi>(
|
119
|
-
{
|
120
|
-
getState: () => attachment,
|
121
|
-
remove: () => {
|
122
|
-
throw new Error("Not supported");
|
123
|
-
},
|
124
|
-
__internal_getRuntime: () => null,
|
125
|
-
},
|
126
|
-
{
|
127
|
-
key: attachment.id,
|
128
|
-
},
|
129
|
-
);
|
130
|
-
},
|
131
|
-
);
|
132
|
-
|
133
|
-
type ThreadMessageClientProps = {
|
134
|
-
message: ThreadMessage;
|
135
|
-
isLast?: boolean;
|
136
|
-
branchNumber?: number;
|
137
|
-
branchCount?: number;
|
138
|
-
};
|
139
|
-
|
140
|
-
const ThreadMessageClient = resource(
|
141
|
-
({
|
142
|
-
message,
|
143
|
-
isLast = true,
|
144
|
-
branchNumber = 1,
|
145
|
-
branchCount = 1,
|
146
|
-
}: ThreadMessageClientProps) => {
|
147
|
-
const [isCopiedState, setIsCopied] = tapState(false);
|
148
|
-
const [isHoveringState, setIsHovering] = tapState(false);
|
149
|
-
|
150
|
-
const parts = tapLookupResources(
|
151
|
-
message.content.map((_, idx) =>
|
152
|
-
ThreadMessagePartClient({ part: message.content[idx]! }, { key: idx }),
|
153
|
-
),
|
154
|
-
);
|
155
|
-
|
156
|
-
const attachments = tapLookupResources(
|
157
|
-
message.attachments?.map((_, idx) =>
|
158
|
-
ThreadMessageAttachmentClient(
|
159
|
-
{ attachment: message.attachments![idx]! },
|
160
|
-
{ key: idx },
|
161
|
-
),
|
162
|
-
) ?? [],
|
163
|
-
);
|
164
|
-
|
165
|
-
const composerState = tapInlineResource(
|
166
|
-
NoOpComposerClient({ type: "edit" }),
|
167
|
-
);
|
168
|
-
|
169
|
-
const state = tapMemo<MessageClientState>(() => {
|
170
|
-
return {
|
171
|
-
...message,
|
172
|
-
parts: parts.state,
|
173
|
-
composer: composerState.state,
|
174
|
-
parentId: null,
|
175
|
-
isLast,
|
176
|
-
branchNumber,
|
177
|
-
branchCount,
|
178
|
-
speech: undefined,
|
179
|
-
submittedFeedback: undefined,
|
180
|
-
isCopied: isCopiedState,
|
181
|
-
isHovering: isHoveringState,
|
182
|
-
};
|
183
|
-
}, [message, isCopiedState, isHoveringState, isLast]);
|
184
|
-
|
185
|
-
return tapApi<MessageClientApi>({
|
186
|
-
getState: () => state,
|
187
|
-
composer: composerState.api,
|
188
|
-
part: (selector) => {
|
189
|
-
if ("index" in selector) {
|
190
|
-
return parts.api({ index: selector.index });
|
191
|
-
} else {
|
192
|
-
return parts.api({ key: "toolCallId-" + selector.toolCallId });
|
193
|
-
}
|
194
|
-
},
|
195
|
-
attachment: (selector) => {
|
196
|
-
if ("id" in selector) {
|
197
|
-
return attachments.api({ key: selector.id });
|
198
|
-
} else {
|
199
|
-
return attachments.api(selector);
|
200
|
-
}
|
201
|
-
},
|
202
|
-
reload: () => {
|
203
|
-
throw new Error("Not supported in ThreadMessageProvider");
|
204
|
-
},
|
205
|
-
speak: () => {
|
206
|
-
throw new Error("Not supported in ThreadMessageProvider");
|
207
|
-
},
|
208
|
-
stopSpeaking: () => {
|
209
|
-
throw new Error("Not supported in ThreadMessageProvider");
|
210
|
-
},
|
211
|
-
submitFeedback: () => {
|
212
|
-
throw new Error("Not supported in ThreadMessageProvider");
|
213
|
-
},
|
214
|
-
switchToBranch: () => {
|
215
|
-
throw new Error("Not supported in ThreadMessageProvider");
|
216
|
-
},
|
217
|
-
getCopyText: () => {
|
218
|
-
return message.content
|
219
|
-
.map((part) => {
|
220
|
-
if ("text" in part && typeof part.text === "string") {
|
221
|
-
return part.text;
|
222
|
-
}
|
223
|
-
return "";
|
224
|
-
})
|
225
|
-
.join("\n");
|
226
|
-
},
|
227
|
-
setIsCopied,
|
228
|
-
setIsHovering,
|
229
|
-
__internal_getRuntime: () => null,
|
230
|
-
});
|
231
|
-
},
|
232
|
-
);
|
12
|
+
ThreadMessageClientProps,
|
13
|
+
ThreadMessageClient,
|
14
|
+
} from "../../client/ThreadMessageClient";
|
233
15
|
|
234
16
|
export const MessageProvider: FC<
|
235
17
|
PropsWithChildren<ThreadMessageClientProps>
|
@@ -46,6 +46,10 @@ import {
|
|
46
46
|
} from "../../client/types/ThreadList";
|
47
47
|
import { ThreadViewportProvider } from "../providers/ThreadViewportProvider";
|
48
48
|
import { DevToolsProviderApi } from "../../devtools/DevToolsHooks";
|
49
|
+
import {
|
50
|
+
AssistantClientProps,
|
51
|
+
useAssistantClient,
|
52
|
+
} from "../../client/AssistantClient";
|
49
53
|
|
50
54
|
export type AssistantState = {
|
51
55
|
readonly threads: ThreadListClientState;
|
@@ -132,7 +136,7 @@ export type AssistantApi = {
|
|
132
136
|
// temp
|
133
137
|
registerModelContextProvider(provider: ModelContextProvider): void;
|
134
138
|
/** @internal */
|
135
|
-
__internal_getRuntime(): AssistantRuntime
|
139
|
+
__internal_getRuntime?(): AssistantRuntime;
|
136
140
|
};
|
137
141
|
|
138
142
|
export const createAssistantApiField = <
|
@@ -231,15 +235,33 @@ const AssistantApiContext = createContext<AssistantApi>({
|
|
231
235
|
"Registering model context providers is only available inside <AssistantProvider />",
|
232
236
|
);
|
233
237
|
},
|
234
|
-
__internal_getRuntime: () => {
|
235
|
-
return null;
|
236
|
-
},
|
237
238
|
});
|
238
239
|
|
239
|
-
|
240
|
+
const useAssistantApiImpl = (): AssistantApi => {
|
240
241
|
return useContext(AssistantApiContext);
|
241
242
|
};
|
242
243
|
|
244
|
+
const useExtendedAssistantApiImpl = (
|
245
|
+
config: AssistantClientProps,
|
246
|
+
): AssistantApi => {
|
247
|
+
const api = useAssistantApiImpl();
|
248
|
+
const api2 = useAssistantClient(config);
|
249
|
+
const extendedApi = useMemo(() => extendApi(api, api2), [api, api2]);
|
250
|
+
return extendedApi;
|
251
|
+
};
|
252
|
+
|
253
|
+
export function useAssistantApi(): AssistantApi;
|
254
|
+
export function useAssistantApi(config: AssistantClientProps): AssistantApi;
|
255
|
+
export function useAssistantApi(config?: AssistantClientProps): AssistantApi {
|
256
|
+
if (config) {
|
257
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
258
|
+
return useExtendedAssistantApiImpl(config);
|
259
|
+
} else {
|
260
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
261
|
+
return useAssistantApiImpl();
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
243
265
|
const mergeFns = <TArgs extends Array<unknown>>(
|
244
266
|
fn1: (...args: TArgs) => void,
|
245
267
|
fn2: (...args: TArgs) => void,
|
package/src/index.ts
CHANGED
package/src/internal.ts
CHANGED
@@ -14,5 +14,9 @@ export {
|
|
14
14
|
export { fromThreadMessageLike } from "./legacy-runtime/runtime-cores/external-store/ThreadMessageLike";
|
15
15
|
export { getAutoStatus } from "./legacy-runtime/runtime-cores/external-store/auto-status";
|
16
16
|
export { splitLocalRuntimeOptions } from "./legacy-runtime/runtime-cores/local/LocalRuntimeOptions";
|
17
|
+
export {
|
18
|
+
useToolInvocations,
|
19
|
+
type ToolExecutionStatus,
|
20
|
+
} from "./legacy-runtime/runtime-cores/assistant-transport/useToolInvocations";
|
17
21
|
|
18
22
|
export * from "./utils/smooth";
|
@@ -7,20 +7,19 @@ export const MessagePartClient = resource(
|
|
7
7
|
({ runtime }: { runtime: MessagePartRuntime }) => {
|
8
8
|
const runtimeState = tapSubscribable(runtime);
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
getState: () => runtimeState,
|
10
|
+
const api: MessagePartClientApi = {
|
11
|
+
getState: () => runtimeState,
|
13
12
|
|
14
|
-
|
13
|
+
addToolResult: (result) => runtime.addToolResult(result),
|
14
|
+
resumeToolCall: (payload) => runtime.resumeToolCall(payload),
|
15
|
+
__internal_getRuntime: () => runtime,
|
16
|
+
};
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
: undefined,
|
23
|
-
},
|
24
|
-
);
|
18
|
+
return tapApi<MessagePartClientApi>(api, {
|
19
|
+
key:
|
20
|
+
runtimeState.type === "tool-call"
|
21
|
+
? "toolCallId-" + runtimeState.toolCallId
|
22
|
+
: undefined,
|
23
|
+
});
|
25
24
|
},
|
26
25
|
);
|
@@ -125,6 +125,12 @@ export const ThreadClient = resource(
|
|
125
125
|
import: runtime.import,
|
126
126
|
reset: runtime.reset,
|
127
127
|
stopSpeaking: runtime.stopSpeaking,
|
128
|
+
startVoice: async () => {
|
129
|
+
throw new Error("startVoice is not supported in this runtime");
|
130
|
+
},
|
131
|
+
stopVoice: async () => {
|
132
|
+
throw new Error("stopVoice is not supported in this runtime");
|
133
|
+
},
|
128
134
|
|
129
135
|
message: (selector) => {
|
130
136
|
if ("id" in selector) {
|
@@ -38,7 +38,7 @@ export function useAssistantRuntime(options?: {
|
|
38
38
|
optional?: boolean | undefined;
|
39
39
|
}) {
|
40
40
|
const api = useAssistantApi();
|
41
|
-
const runtime = api.__internal_getRuntime();
|
41
|
+
const runtime = api.__internal_getRuntime?.() ?? null;
|
42
42
|
|
43
43
|
if (!runtime && !options?.optional) {
|
44
44
|
throw new Error("AssistantRuntime is not available");
|
@@ -15,7 +15,9 @@ export function useAttachmentRuntime(options?: {
|
|
15
15
|
}): AttachmentRuntime | null {
|
16
16
|
const api = useAssistantApi();
|
17
17
|
const runtime = useAssistantState(() =>
|
18
|
-
api.attachment.source
|
18
|
+
api.attachment.source
|
19
|
+
? (api.attachment().__internal_getRuntime?.() ?? null)
|
20
|
+
: null,
|
19
21
|
);
|
20
22
|
if (!runtime && !options?.optional) {
|
21
23
|
throw new Error("AttachmentRuntime is not available");
|
@@ -53,7 +53,9 @@ export function useComposerRuntime(options?: {
|
|
53
53
|
}): ComposerRuntime | null {
|
54
54
|
const api = useAssistantApi();
|
55
55
|
const runtime = useAssistantState(() =>
|
56
|
-
api.composer.source
|
56
|
+
api.composer.source
|
57
|
+
? (api.composer().__internal_getRuntime?.() ?? null)
|
58
|
+
: null,
|
57
59
|
);
|
58
60
|
if (!runtime && !options?.optional) {
|
59
61
|
throw new Error("ComposerRuntime is not available");
|
@@ -48,7 +48,9 @@ export function useMessageRuntime(options?: {
|
|
48
48
|
}) {
|
49
49
|
const api = useAssistantApi();
|
50
50
|
const runtime = useAssistantState(() =>
|
51
|
-
api.message.source
|
51
|
+
api.message.source
|
52
|
+
? (api.message().__internal_getRuntime?.() ?? null)
|
53
|
+
: null,
|
52
54
|
);
|
53
55
|
if (!runtime && !options?.optional) {
|
54
56
|
throw new Error("MessageRuntime is not available");
|
@@ -15,7 +15,7 @@ export function useMessagePartRuntime(options?: {
|
|
15
15
|
}) {
|
16
16
|
const api = useAssistantApi();
|
17
17
|
const runtime = useAssistantState(() =>
|
18
|
-
api.part.source ? api.part().__internal_getRuntime() : null,
|
18
|
+
api.part.source ? (api.part().__internal_getRuntime?.() ?? null) : null,
|
19
19
|
);
|
20
20
|
if (!runtime && !options?.optional) {
|
21
21
|
throw new Error("MessagePartRuntime is not available");
|
@@ -43,7 +43,7 @@ export function useThreadRuntime(options?: {
|
|
43
43
|
export function useThreadRuntime(options?: { optional?: boolean | undefined }) {
|
44
44
|
const api = useAssistantApi();
|
45
45
|
const runtime = useAssistantState(() =>
|
46
|
-
api.thread.source ? api.thread().__internal_getRuntime() : null,
|
46
|
+
api.thread.source ? (api.thread().__internal_getRuntime?.() ?? null) : null,
|
47
47
|
);
|
48
48
|
if (!runtime && !options?.optional) {
|
49
49
|
throw new Error("ThreadRuntime is not available");
|
@@ -16,7 +16,7 @@ export function useThreadListItemRuntime(options?: {
|
|
16
16
|
const api = useAssistantApi();
|
17
17
|
const runtime = useAssistantState(() =>
|
18
18
|
api.threadListItem.source
|
19
|
-
? api.threadListItem().__internal_getRuntime()
|
19
|
+
? (api.threadListItem().__internal_getRuntime?.() ?? null)
|
20
20
|
: null,
|
21
21
|
);
|
22
22
|
if (!runtime && !options?.optional) {
|
@@ -30,6 +30,12 @@ export type MessagePartRuntime = {
|
|
30
30
|
*/
|
31
31
|
addToolResult(result: any | ToolResponse<any>): void;
|
32
32
|
|
33
|
+
/**
|
34
|
+
* Resume an interrupted tool call with a payload.
|
35
|
+
* This is useful when a tool has interrupted its execution and is waiting for user input.
|
36
|
+
*/
|
37
|
+
resumeToolCall(payload: unknown): void;
|
38
|
+
|
33
39
|
readonly path: MessagePartRuntimePath;
|
34
40
|
getState(): MessagePartState;
|
35
41
|
subscribe(callback: () => void): Unsubscribe;
|
@@ -50,6 +56,7 @@ export class MessagePartRuntimeImpl implements MessagePartRuntime {
|
|
50
56
|
|
51
57
|
protected __internal_bindMethods() {
|
52
58
|
this.addToolResult = this.addToolResult.bind(this);
|
59
|
+
this.resumeToolCall = this.resumeToolCall.bind(this);
|
53
60
|
this.getState = this.getState.bind(this);
|
54
61
|
this.subscribe = this.subscribe.bind(this);
|
55
62
|
}
|
@@ -88,6 +95,22 @@ export class MessagePartRuntimeImpl implements MessagePartRuntime {
|
|
88
95
|
});
|
89
96
|
}
|
90
97
|
|
98
|
+
public resumeToolCall(payload: unknown) {
|
99
|
+
const state = this.contentBinding.getState();
|
100
|
+
if (!state) throw new Error("Message part is not available");
|
101
|
+
|
102
|
+
if (state.type !== "tool-call")
|
103
|
+
throw new Error("Tried to resume tool call on non-tool message part");
|
104
|
+
|
105
|
+
if (!this.threadApi) throw new Error("Thread API is not available");
|
106
|
+
|
107
|
+
const toolCallId = state.toolCallId;
|
108
|
+
this.threadApi.getState().resumeToolCall({
|
109
|
+
toolCallId,
|
110
|
+
payload,
|
111
|
+
});
|
112
|
+
}
|
113
|
+
|
91
114
|
public subscribe(callback: () => void) {
|
92
115
|
return this.contentBinding.subscribe(callback);
|
93
116
|
}
|
@@ -2,6 +2,7 @@ import { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
2
2
|
import { ThreadMessage } from "../../../types";
|
3
3
|
import { AttachmentAdapter, ThreadHistoryAdapter } from "..";
|
4
4
|
import { UserCommands } from "../../../augmentations";
|
5
|
+
import type { ToolExecutionStatus } from "./useToolInvocations";
|
5
6
|
|
6
7
|
// Message part types
|
7
8
|
export type TextPart = {
|
@@ -56,6 +57,7 @@ export type AssistantTransportState = {
|
|
56
57
|
export type AssistantTransportConnectionMetadata = {
|
57
58
|
pendingCommands: AssistantTransportCommand[];
|
58
59
|
isSending: boolean;
|
60
|
+
toolStatuses: Record<string, ToolExecutionStatus>;
|
59
61
|
};
|
60
62
|
|
61
63
|
export type AssistantTransportStateConverter<T> = (
|
package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
"use client";
|
2
2
|
|
3
3
|
import {
|
4
|
-
ReadonlyJSONObject,
|
5
|
-
ReadonlyJSONValue,
|
4
|
+
type ReadonlyJSONObject,
|
5
|
+
type ReadonlyJSONValue,
|
6
6
|
asAsyncIterableStream,
|
7
7
|
} from "assistant-stream/utils";
|
8
8
|
import { AppendMessage } from "../../../types";
|
@@ -26,7 +26,7 @@ import {
|
|
26
26
|
import { useCommandQueue } from "./commandQueue";
|
27
27
|
import { useRunManager } from "./runManager";
|
28
28
|
import { useConvertedState } from "./useConvertedState";
|
29
|
-
import { useToolInvocations } from "./useToolInvocations";
|
29
|
+
import { ToolExecutionStatus, useToolInvocations } from "./useToolInvocations";
|
30
30
|
import { toAISDKTools, getEnabledTools, createRequestHeaders } from "./utils";
|
31
31
|
import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThreadListRuntime";
|
32
32
|
import { InMemoryThreadListAdapter } from "../remote-thread-list/adapter/in-memory";
|
@@ -177,6 +177,11 @@ const useAssistantTransportThreadRuntime = <T,>(
|
|
177
177
|
},
|
178
178
|
});
|
179
179
|
|
180
|
+
// Tool execution status state
|
181
|
+
const [toolStatuses, setToolStatuses] = useState<
|
182
|
+
Record<string, ToolExecutionStatus>
|
183
|
+
>({});
|
184
|
+
|
180
185
|
// Reactive conversion of agent state + connection metadata → UI state
|
181
186
|
const pendingCommands = useMemo(
|
182
187
|
() => [...commandQueue.state.inTransit, ...commandQueue.state.queued],
|
@@ -187,6 +192,7 @@ const useAssistantTransportThreadRuntime = <T,>(
|
|
187
192
|
agentStateRef.current,
|
188
193
|
pendingCommands,
|
189
194
|
runManager.isRunning,
|
195
|
+
toolStatuses,
|
190
196
|
);
|
191
197
|
|
192
198
|
// Create runtime
|
@@ -266,6 +272,7 @@ const useAssistantTransportThreadRuntime = <T,>(
|
|
266
272
|
state: converted,
|
267
273
|
getTools: () => runtime.thread.getModelContext().tools,
|
268
274
|
onResult: commandQueue.enqueue,
|
275
|
+
setToolStatuses,
|
269
276
|
});
|
270
277
|
|
271
278
|
return runtime;
|
@@ -4,15 +4,17 @@ import type {
|
|
4
4
|
AssistantTransportState,
|
5
5
|
AssistantTransportStateConverter,
|
6
6
|
} from "./types";
|
7
|
+
import type { ToolExecutionStatus } from "./useToolInvocations";
|
7
8
|
|
8
9
|
export function useConvertedState<T>(
|
9
10
|
converter: AssistantTransportStateConverter<T>,
|
10
11
|
agentState: T,
|
11
12
|
pendingCommands: AssistantTransportCommand[],
|
12
13
|
isSending: boolean,
|
14
|
+
toolStatuses: Record<string, ToolExecutionStatus>,
|
13
15
|
): AssistantTransportState {
|
14
16
|
return useMemo(
|
15
|
-
() => converter(agentState, { pendingCommands, isSending }),
|
16
|
-
[converter, agentState, pendingCommands, isSending],
|
17
|
+
() => converter(agentState, { pendingCommands, isSending, toolStatuses }),
|
18
|
+
[converter, agentState, pendingCommands, isSending, toolStatuses],
|
17
19
|
);
|
18
20
|
}
|