@assistant-ui/react 0.11.21 → 0.11.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/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/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 +12 -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 +6 -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 +6 -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 +2 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js +3 -0
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js.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 +3 -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/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/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/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/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 +4 -0
- package/dist/types/MessagePartTypes.d.ts.map +1 -1
- package/dist/utils/smooth/SmoothContext.d.ts +6 -6
- package/package.json +2 -2
- 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 +7 -1
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.tsx +4 -1
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.tsx +8 -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 +5 -0
- package/src/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.tsx +4 -0
- package/src/legacy-runtime/runtime-cores/utils/MessageRepository.tsx +1 -1
- package/src/model-context/frame/AssistantFrameProvider.ts +5 -0
- 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
@@ -0,0 +1,161 @@
|
|
1
|
+
"use client";
|
2
|
+
import {
|
3
|
+
resource,
|
4
|
+
tapMemo,
|
5
|
+
tapState,
|
6
|
+
tapInlineResource,
|
7
|
+
} from "@assistant-ui/tap";
|
8
|
+
import { AttachmentClientApi } from "./types/Attachment";
|
9
|
+
import { MessageClientState, MessageClientApi } from "./types/Message";
|
10
|
+
import { MessagePartClientState, MessagePartClientApi } from "./types/Part";
|
11
|
+
import { tapLookupResources } from "./util-hooks/tapLookupResources";
|
12
|
+
import { tapApi } from "../utils/tap-store";
|
13
|
+
import {
|
14
|
+
ThreadAssistantMessagePart,
|
15
|
+
ThreadUserMessagePart,
|
16
|
+
Attachment,
|
17
|
+
ThreadMessage,
|
18
|
+
} from "../types";
|
19
|
+
import { NoOpComposerClient } from "./NoOpComposerClient";
|
20
|
+
|
21
|
+
const ThreadMessagePartClient = resource(
|
22
|
+
({ part }: { part: ThreadAssistantMessagePart | ThreadUserMessagePart }) => {
|
23
|
+
const state = tapMemo<MessagePartClientState>(() => {
|
24
|
+
return {
|
25
|
+
...part,
|
26
|
+
status: { type: "complete" },
|
27
|
+
};
|
28
|
+
}, [part]);
|
29
|
+
|
30
|
+
return tapApi<MessagePartClientApi>(
|
31
|
+
{
|
32
|
+
getState: () => state,
|
33
|
+
addToolResult: () => {
|
34
|
+
throw new Error("Not supported");
|
35
|
+
},
|
36
|
+
resumeToolCall: () => {
|
37
|
+
throw new Error("Not supported");
|
38
|
+
},
|
39
|
+
},
|
40
|
+
{
|
41
|
+
key:
|
42
|
+
state.type === "tool-call"
|
43
|
+
? "toolCallId-" + state.toolCallId
|
44
|
+
: undefined,
|
45
|
+
},
|
46
|
+
);
|
47
|
+
},
|
48
|
+
);
|
49
|
+
const ThreadMessageAttachmentClient = resource(
|
50
|
+
({ attachment }: { attachment: Attachment }) => {
|
51
|
+
return tapApi<AttachmentClientApi>(
|
52
|
+
{
|
53
|
+
getState: () => attachment,
|
54
|
+
remove: () => {
|
55
|
+
throw new Error("Not supported");
|
56
|
+
},
|
57
|
+
},
|
58
|
+
{
|
59
|
+
key: attachment.id,
|
60
|
+
},
|
61
|
+
);
|
62
|
+
},
|
63
|
+
);
|
64
|
+
export type ThreadMessageClientProps = {
|
65
|
+
message: ThreadMessage;
|
66
|
+
isLast?: boolean;
|
67
|
+
branchNumber?: number;
|
68
|
+
branchCount?: number;
|
69
|
+
};
|
70
|
+
export const ThreadMessageClient = resource(
|
71
|
+
({
|
72
|
+
message,
|
73
|
+
isLast = true,
|
74
|
+
branchNumber = 1,
|
75
|
+
branchCount = 1,
|
76
|
+
}: ThreadMessageClientProps) => {
|
77
|
+
const [isCopiedState, setIsCopied] = tapState(false);
|
78
|
+
const [isHoveringState, setIsHovering] = tapState(false);
|
79
|
+
|
80
|
+
const parts = tapLookupResources(
|
81
|
+
message.content.map((_, idx) =>
|
82
|
+
ThreadMessagePartClient({ part: message.content[idx]! }, { key: idx }),
|
83
|
+
),
|
84
|
+
);
|
85
|
+
|
86
|
+
const attachments = tapLookupResources(
|
87
|
+
message.attachments?.map((_, idx) =>
|
88
|
+
ThreadMessageAttachmentClient(
|
89
|
+
{ attachment: message.attachments![idx]! },
|
90
|
+
{ key: idx },
|
91
|
+
),
|
92
|
+
) ?? [],
|
93
|
+
);
|
94
|
+
|
95
|
+
const composerState = tapInlineResource(
|
96
|
+
NoOpComposerClient({ type: "edit" }),
|
97
|
+
);
|
98
|
+
|
99
|
+
const state = tapMemo<MessageClientState>(() => {
|
100
|
+
return {
|
101
|
+
...message,
|
102
|
+
parts: parts.state,
|
103
|
+
composer: composerState.state,
|
104
|
+
parentId: null,
|
105
|
+
isLast,
|
106
|
+
branchNumber,
|
107
|
+
branchCount,
|
108
|
+
speech: undefined,
|
109
|
+
submittedFeedback: undefined,
|
110
|
+
isCopied: isCopiedState,
|
111
|
+
isHovering: isHoveringState,
|
112
|
+
};
|
113
|
+
}, [message, isCopiedState, isHoveringState, isLast]);
|
114
|
+
|
115
|
+
return tapApi<MessageClientApi>({
|
116
|
+
getState: () => state,
|
117
|
+
composer: composerState.api,
|
118
|
+
part: (selector) => {
|
119
|
+
if ("index" in selector) {
|
120
|
+
return parts.api({ index: selector.index });
|
121
|
+
} else {
|
122
|
+
return parts.api({ key: "toolCallId-" + selector.toolCallId });
|
123
|
+
}
|
124
|
+
},
|
125
|
+
attachment: (selector) => {
|
126
|
+
if ("id" in selector) {
|
127
|
+
return attachments.api({ key: selector.id });
|
128
|
+
} else {
|
129
|
+
return attachments.api(selector);
|
130
|
+
}
|
131
|
+
},
|
132
|
+
reload: () => {
|
133
|
+
throw new Error("Not supported in ThreadMessageProvider");
|
134
|
+
},
|
135
|
+
speak: () => {
|
136
|
+
throw new Error("Not supported in ThreadMessageProvider");
|
137
|
+
},
|
138
|
+
stopSpeaking: () => {
|
139
|
+
throw new Error("Not supported in ThreadMessageProvider");
|
140
|
+
},
|
141
|
+
submitFeedback: () => {
|
142
|
+
throw new Error("Not supported in ThreadMessageProvider");
|
143
|
+
},
|
144
|
+
switchToBranch: () => {
|
145
|
+
throw new Error("Not supported in ThreadMessageProvider");
|
146
|
+
},
|
147
|
+
getCopyText: () => {
|
148
|
+
return message.content
|
149
|
+
.map((part) => {
|
150
|
+
if ("text" in part && typeof part.text === "string") {
|
151
|
+
return part.text;
|
152
|
+
}
|
153
|
+
return "";
|
154
|
+
})
|
155
|
+
.join("\n");
|
156
|
+
},
|
157
|
+
setIsCopied,
|
158
|
+
setIsHovering,
|
159
|
+
});
|
160
|
+
},
|
161
|
+
);
|
package/src/client/types/Part.ts
CHANGED
@@ -26,6 +26,12 @@ export type MessagePartClientApi = {
|
|
26
26
|
*/
|
27
27
|
addToolResult(result: any | ToolResponse<any>): void;
|
28
28
|
|
29
|
+
/**
|
30
|
+
* Resume a tool call that is waiting for human input with a payload.
|
31
|
+
* This is useful when a tool has requested human input and is waiting for a response.
|
32
|
+
*/
|
33
|
+
resumeToolCall(payload: unknown): void;
|
34
|
+
|
29
35
|
/** @internal */
|
30
|
-
__internal_getRuntime(): MessagePartRuntime
|
36
|
+
__internal_getRuntime?(): MessagePartRuntime;
|
31
37
|
};
|
@@ -130,6 +130,16 @@ export type ThreadClientApi = {
|
|
130
130
|
*/
|
131
131
|
stopSpeaking(): void;
|
132
132
|
|
133
|
+
/**
|
134
|
+
* Start the voice session for the thread. Establishes any necessary media connections.
|
135
|
+
*/
|
136
|
+
startVoice(): Promise<void>;
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Stop the currently active voice session.
|
140
|
+
*/
|
141
|
+
stopVoice(): Promise<void>;
|
142
|
+
|
133
143
|
/** @internal */
|
134
|
-
__internal_getRuntime(): ThreadRuntime
|
144
|
+
__internal_getRuntime?(): ThreadRuntime;
|
135
145
|
};
|
@@ -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) {
|