@assistant-ui/core 0.1.2 → 0.1.5
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/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +2 -4
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/react/AssistantRuntimeProvider.d.ts +10 -0
- package/dist/react/AssistantRuntimeProvider.d.ts.map +1 -0
- package/dist/react/AssistantRuntimeProvider.js +16 -0
- package/dist/react/AssistantRuntimeProvider.js.map +1 -0
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts +15 -0
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -0
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +154 -0
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -0
- package/dist/react/adapters/TitleGenerationAdapter.d.ts +6 -0
- package/dist/react/adapters/TitleGenerationAdapter.d.ts.map +1 -0
- package/dist/react/adapters/TitleGenerationAdapter.js +15 -0
- package/dist/react/adapters/TitleGenerationAdapter.js.map +1 -0
- package/dist/react/index.d.ts +5 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +8 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/primitive-hooks/index.d.ts +15 -0
- package/dist/react/primitive-hooks/index.d.ts.map +1 -0
- package/dist/react/primitive-hooks/index.js +15 -0
- package/dist/react/primitive-hooks/index.js.map +1 -0
- package/dist/react/primitive-hooks/useActionBarCopy.d.ts +10 -0
- package/dist/react/primitive-hooks/useActionBarCopy.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useActionBarCopy.js +26 -0
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -0
- package/dist/react/primitive-hooks/useActionBarEdit.d.ts +5 -0
- package/dist/react/primitive-hooks/useActionBarEdit.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useActionBarEdit.js +11 -0
- package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -0
- package/dist/react/primitive-hooks/useActionBarFeedback.d.ts +9 -0
- package/dist/react/primitive-hooks/useActionBarFeedback.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useActionBarFeedback.js +19 -0
- package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -0
- package/dist/react/primitive-hooks/useActionBarReload.d.ts +5 -0
- package/dist/react/primitive-hooks/useActionBarReload.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useActionBarReload.js +13 -0
- package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -0
- package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts +6 -0
- package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +11 -0
- package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -0
- package/dist/react/primitive-hooks/useComposerCancel.d.ts +5 -0
- package/dist/react/primitive-hooks/useComposerCancel.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useComposerCancel.js +11 -0
- package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -0
- package/dist/react/primitive-hooks/useComposerSend.d.ts +5 -0
- package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useComposerSend.js +11 -0
- package/dist/react/primitive-hooks/useComposerSend.js.map +1 -0
- package/dist/react/primitive-hooks/useEditComposerCancel.d.ts +4 -0
- package/dist/react/primitive-hooks/useEditComposerCancel.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useEditComposerCancel.js +10 -0
- package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -0
- package/dist/react/primitive-hooks/useEditComposerSend.d.ts +5 -0
- package/dist/react/primitive-hooks/useEditComposerSend.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useEditComposerSend.js +11 -0
- package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -0
- package/dist/react/primitive-hooks/useMessageBranching.d.ts +7 -0
- package/dist/react/primitive-hooks/useMessageBranching.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useMessageBranching.js +15 -0
- package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -0
- package/dist/react/primitive-hooks/useMessageReload.d.ts +5 -0
- package/dist/react/primitive-hooks/useMessageReload.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useMessageReload.js +11 -0
- package/dist/react/primitive-hooks/useMessageReload.js.map +1 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts +2 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.js +5 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.js.map +1 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.d.ts +2 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.js +5 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.js.map +1 -0
- package/dist/react/primitive-hooks/useThreadMessages.d.ts +3 -0
- package/dist/react/primitive-hooks/useThreadMessages.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useThreadMessages.js +5 -0
- package/dist/react/primitive-hooks/useThreadMessages.js.map +1 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +97 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +111 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +115 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +444 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts +18 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts.map +1 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.js +14 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +5 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +528 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +15 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +83 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts +62 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/auiV0.js +74 -0
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -0
- package/dist/react/runtimes/cloud/index.d.ts +4 -0
- package/dist/react/runtimes/cloud/index.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/index.js +4 -0
- package/dist/react/runtimes/cloud/index.js.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +13 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +103 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -0
- package/dist/react/runtimes/createMessageConverter.d.ts +17 -0
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -0
- package/dist/react/runtimes/createMessageConverter.js +50 -0
- package/dist/react/runtimes/createMessageConverter.js.map +1 -0
- package/dist/react/runtimes/external-message-converter.d.ts +34 -0
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -0
- package/dist/react/runtimes/external-message-converter.js +309 -0
- package/dist/react/runtimes/external-message-converter.js.map +1 -0
- package/dist/react/runtimes/index.d.ts +11 -0
- package/dist/react/runtimes/index.d.ts.map +1 -0
- package/dist/react/runtimes/index.js +11 -0
- package/dist/react/runtimes/index.js.map +1 -0
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts +4 -0
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/useExternalStoreRuntime.js +19 -0
- package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -0
- package/dist/react/runtimes/useLocalRuntime.d.ts +28 -0
- package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/useLocalRuntime.js +64 -0
- package/dist/react/runtimes/useLocalRuntime.js.map +1 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts +4 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +48 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -0
- package/dist/react/runtimes/useToolInvocations.d.ts +38 -0
- package/dist/react/runtimes/useToolInvocations.d.ts.map +1 -0
- package/dist/react/runtimes/useToolInvocations.js +411 -0
- package/dist/react/runtimes/useToolInvocations.js.map +1 -0
- package/dist/react/types/store-augmentation.d.ts +0 -1
- package/dist/react/types/store-augmentation.d.ts.map +1 -1
- package/dist/react/types/store-augmentation.js +1 -1
- package/dist/react/types/store-augmentation.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +2 -0
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -2
- package/dist/store/index.js.map +1 -1
- package/dist/utils/json/is-json-equal.d.ts +2 -0
- package/dist/utils/json/is-json-equal.d.ts.map +1 -0
- package/dist/utils/json/is-json-equal.js +31 -0
- package/dist/utils/json/is-json-equal.js.map +1 -0
- package/dist/utils/json/is-json.d.ts +6 -0
- package/dist/utils/json/is-json.d.ts.map +1 -0
- package/dist/utils/json/is-json.js +33 -0
- package/dist/utils/json/is-json.js.map +1 -0
- package/package.json +11 -10
- package/src/model-context/frame/provider.ts +2 -6
- package/src/react/AssistantRuntimeProvider.tsx +33 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +227 -0
- package/src/react/adapters/TitleGenerationAdapter.ts +20 -0
- package/src/react/index.ts +17 -1
- package/src/react/primitive-hooks/index.ts +20 -0
- package/src/react/primitive-hooks/useActionBarCopy.ts +38 -0
- package/src/react/primitive-hooks/useActionBarEdit.ts +13 -0
- package/src/react/primitive-hooks/useActionBarFeedback.ts +28 -0
- package/src/react/primitive-hooks/useActionBarReload.ts +18 -0
- package/src/react/primitive-hooks/useComposerAddAttachment.ts +17 -0
- package/src/react/primitive-hooks/useComposerCancel.ts +13 -0
- package/src/react/primitive-hooks/useComposerSend.ts +15 -0
- package/src/react/primitive-hooks/useEditComposerCancel.ts +12 -0
- package/src/react/primitive-hooks/useEditComposerSend.ts +13 -0
- package/src/react/primitive-hooks/useMessageBranching.ts +18 -0
- package/src/react/primitive-hooks/useMessageReload.ts +13 -0
- package/src/react/primitive-hooks/useThreadIsEmpty.ts +5 -0
- package/src/react/primitive-hooks/useThreadIsRunning.ts +5 -0
- package/src/react/primitive-hooks/useThreadMessages.ts +6 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +176 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +534 -0
- package/src/react/runtimes/RuntimeAdapterProvider.tsx +40 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +785 -0
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +101 -0
- package/src/react/runtimes/cloud/auiV0.ts +160 -0
- package/src/react/runtimes/cloud/index.ts +3 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +154 -0
- package/src/react/runtimes/createMessageConverter.ts +77 -0
- package/src/react/runtimes/external-message-converter.ts +487 -0
- package/src/react/runtimes/index.ts +36 -0
- package/src/react/runtimes/useExternalStoreRuntime.ts +27 -0
- package/src/react/runtimes/useLocalRuntime.ts +101 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +76 -0
- package/src/react/runtimes/useToolInvocations.ts +594 -0
- package/src/react/types/store-augmentation.ts +0 -2
- package/src/runtime/base/base-composer-runtime-core.ts +2 -0
- package/src/store/index.ts +1 -2
- package/src/tests/no-unsafe-process-env.test.ts +58 -0
- package/src/utils/json/is-json-equal.ts +48 -0
- package/src/utils/json/is-json.ts +58 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { ThreadMessageConverter } from "../../runtimes/external-store/thread-message-converter.js";
|
|
4
|
+
import { getExternalStoreMessages, symbolInnerMessage, bindExternalStoreMessage, } from "../../runtime/utils/external-store-message.js";
|
|
5
|
+
import { fromThreadMessageLike, } from "../../runtime/utils/thread-message-like.js";
|
|
6
|
+
import { getAutoStatus, isAutoStatus } from "../../runtime/utils/auto-status.js";
|
|
7
|
+
import { generateErrorMessageId } from "../../utils/id.js";
|
|
8
|
+
const mergeInnerMessages = (existing, incoming) => ({
|
|
9
|
+
[symbolInnerMessage]: [
|
|
10
|
+
...(existing[symbolInnerMessage] ?? []),
|
|
11
|
+
...(incoming[symbolInnerMessage] ?? []),
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
const joinExternalMessages = (messages) => {
|
|
15
|
+
const assistantMessage = {
|
|
16
|
+
role: "assistant",
|
|
17
|
+
content: [],
|
|
18
|
+
};
|
|
19
|
+
for (const output of messages) {
|
|
20
|
+
if (output.role === "tool") {
|
|
21
|
+
const toolCallIdx = assistantMessage.content.findIndex((c) => c.type === "tool-call" && c.toolCallId === output.toolCallId);
|
|
22
|
+
// Ignore orphaned tool results so one bad tool message does not
|
|
23
|
+
// prevent rendering the rest of the conversation.
|
|
24
|
+
if (toolCallIdx !== -1) {
|
|
25
|
+
const toolCall = assistantMessage.content[toolCallIdx];
|
|
26
|
+
if (output.toolName !== undefined) {
|
|
27
|
+
if (toolCall.toolName !== output.toolName)
|
|
28
|
+
throw new Error(`Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`);
|
|
29
|
+
}
|
|
30
|
+
assistantMessage.content[toolCallIdx] = {
|
|
31
|
+
...toolCall,
|
|
32
|
+
...{
|
|
33
|
+
[symbolInnerMessage]: [
|
|
34
|
+
...(toolCall[symbolInnerMessage] ?? []),
|
|
35
|
+
output,
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
result: output.result,
|
|
39
|
+
artifact: output.artifact,
|
|
40
|
+
isError: output.isError,
|
|
41
|
+
messages: output.messages,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const role = output.role;
|
|
47
|
+
const content = (typeof output.content === "string"
|
|
48
|
+
? [{ type: "text", text: output.content }]
|
|
49
|
+
: output.content).map((c) => ({
|
|
50
|
+
...c,
|
|
51
|
+
...{ [symbolInnerMessage]: [output] },
|
|
52
|
+
}));
|
|
53
|
+
switch (role) {
|
|
54
|
+
case "system":
|
|
55
|
+
case "user":
|
|
56
|
+
return {
|
|
57
|
+
...output,
|
|
58
|
+
content,
|
|
59
|
+
};
|
|
60
|
+
case "assistant":
|
|
61
|
+
if (assistantMessage.content.length === 0) {
|
|
62
|
+
assistantMessage.id = output.id;
|
|
63
|
+
assistantMessage.createdAt ??= output.createdAt;
|
|
64
|
+
assistantMessage.status ??= output.status;
|
|
65
|
+
if (output.attachments) {
|
|
66
|
+
assistantMessage.attachments = [
|
|
67
|
+
...(assistantMessage.attachments ?? []),
|
|
68
|
+
...output.attachments,
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
if (output.metadata) {
|
|
72
|
+
assistantMessage.metadata ??= {};
|
|
73
|
+
if (output.metadata.unstable_state) {
|
|
74
|
+
assistantMessage.metadata.unstable_state =
|
|
75
|
+
output.metadata.unstable_state;
|
|
76
|
+
}
|
|
77
|
+
if (output.metadata.unstable_annotations) {
|
|
78
|
+
assistantMessage.metadata.unstable_annotations = [
|
|
79
|
+
...(assistantMessage.metadata.unstable_annotations ?? []),
|
|
80
|
+
...output.metadata.unstable_annotations,
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
if (output.metadata.unstable_data) {
|
|
84
|
+
assistantMessage.metadata.unstable_data = [
|
|
85
|
+
...(assistantMessage.metadata.unstable_data ?? []),
|
|
86
|
+
...output.metadata.unstable_data,
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
if (output.metadata.steps) {
|
|
90
|
+
assistantMessage.metadata.steps = [
|
|
91
|
+
...(assistantMessage.metadata.steps ?? []),
|
|
92
|
+
...output.metadata.steps,
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
if (output.metadata.custom) {
|
|
96
|
+
assistantMessage.metadata.custom = {
|
|
97
|
+
...(assistantMessage.metadata.custom ?? {}),
|
|
98
|
+
...output.metadata.custom,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (output.metadata.timing) {
|
|
102
|
+
assistantMessage.metadata.timing = output.metadata.timing;
|
|
103
|
+
}
|
|
104
|
+
if (output.metadata.submittedFeedback) {
|
|
105
|
+
assistantMessage.metadata.submittedFeedback =
|
|
106
|
+
output.metadata.submittedFeedback;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// TODO keep this in sync
|
|
110
|
+
}
|
|
111
|
+
// Add content parts, merging reasoning parts with same parentId
|
|
112
|
+
for (const part of content) {
|
|
113
|
+
if (part.type === "tool-call") {
|
|
114
|
+
const existingIdx = assistantMessage.content.findIndex((c) => c.type === "tool-call" && c.toolCallId === part.toolCallId);
|
|
115
|
+
if (existingIdx !== -1) {
|
|
116
|
+
const existing = assistantMessage.content[existingIdx];
|
|
117
|
+
assistantMessage.content[existingIdx] = {
|
|
118
|
+
...existing,
|
|
119
|
+
...part,
|
|
120
|
+
...mergeInnerMessages(existing, part),
|
|
121
|
+
};
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (part.type === "reasoning" &&
|
|
126
|
+
"parentId" in part &&
|
|
127
|
+
part.parentId) {
|
|
128
|
+
const existingIdx = assistantMessage.content.findIndex((c) => c.type === "reasoning" &&
|
|
129
|
+
"parentId" in c &&
|
|
130
|
+
c.parentId === part.parentId);
|
|
131
|
+
if (existingIdx !== -1) {
|
|
132
|
+
const existing = assistantMessage.content[existingIdx];
|
|
133
|
+
assistantMessage.content[existingIdx] = {
|
|
134
|
+
...existing,
|
|
135
|
+
text: `${existing.text}\n\n${part.text}`,
|
|
136
|
+
...mergeInnerMessages(existing, part),
|
|
137
|
+
};
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
assistantMessage.content.push(part);
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
default: {
|
|
145
|
+
const unsupportedRole = role;
|
|
146
|
+
throw new Error(`Unknown message role: ${unsupportedRole}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return assistantMessage;
|
|
152
|
+
};
|
|
153
|
+
const chunkExternalMessages = (callbackResults, joinStrategy) => {
|
|
154
|
+
const results = [];
|
|
155
|
+
let isAssistant = false;
|
|
156
|
+
let pendingNone = false; // true if the previous assistant message had joinStrategy "none"
|
|
157
|
+
let inputs = [];
|
|
158
|
+
let outputs = [];
|
|
159
|
+
const flush = () => {
|
|
160
|
+
if (outputs.length) {
|
|
161
|
+
results.push({
|
|
162
|
+
inputs,
|
|
163
|
+
outputs,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
inputs = [];
|
|
167
|
+
outputs = [];
|
|
168
|
+
isAssistant = false;
|
|
169
|
+
pendingNone = false;
|
|
170
|
+
};
|
|
171
|
+
for (const callbackResult of callbackResults) {
|
|
172
|
+
for (const output of callbackResult.outputs) {
|
|
173
|
+
if ((pendingNone && output.role !== "tool") ||
|
|
174
|
+
!isAssistant ||
|
|
175
|
+
output.role === "user" ||
|
|
176
|
+
output.role === "system") {
|
|
177
|
+
flush();
|
|
178
|
+
}
|
|
179
|
+
isAssistant = output.role === "assistant" || output.role === "tool";
|
|
180
|
+
if (inputs.at(-1) !== callbackResult.input) {
|
|
181
|
+
inputs.push(callbackResult.input);
|
|
182
|
+
}
|
|
183
|
+
outputs.push(output);
|
|
184
|
+
if (output.role === "assistant" &&
|
|
185
|
+
(output.convertConfig?.joinStrategy === "none" ||
|
|
186
|
+
joinStrategy === "none")) {
|
|
187
|
+
pendingNone = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
flush();
|
|
192
|
+
return results;
|
|
193
|
+
};
|
|
194
|
+
function createErrorAssistantMessage(error) {
|
|
195
|
+
const msg = {
|
|
196
|
+
id: generateErrorMessageId(),
|
|
197
|
+
role: "assistant",
|
|
198
|
+
content: [],
|
|
199
|
+
status: { type: "incomplete", reason: "error", error },
|
|
200
|
+
createdAt: new Date(),
|
|
201
|
+
metadata: {
|
|
202
|
+
unstable_state: null,
|
|
203
|
+
unstable_annotations: [],
|
|
204
|
+
unstable_data: [],
|
|
205
|
+
custom: {},
|
|
206
|
+
steps: [],
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
bindExternalStoreMessage(msg, []);
|
|
210
|
+
return msg;
|
|
211
|
+
}
|
|
212
|
+
export const convertExternalMessages = (messages, callback, isRunning, metadata) => {
|
|
213
|
+
const callbackResults = [];
|
|
214
|
+
for (const message of messages) {
|
|
215
|
+
const output = callback(message, metadata);
|
|
216
|
+
const outputs = Array.isArray(output) ? output : [output];
|
|
217
|
+
const result = { input: message, outputs };
|
|
218
|
+
callbackResults.push(result);
|
|
219
|
+
}
|
|
220
|
+
const chunks = chunkExternalMessages(callbackResults);
|
|
221
|
+
const result = chunks.map((message, idx) => {
|
|
222
|
+
const isLast = idx === chunks.length - 1;
|
|
223
|
+
const joined = joinExternalMessages(message.outputs);
|
|
224
|
+
const hasPendingToolCalls = typeof joined.content === "object" &&
|
|
225
|
+
joined.content.some((c) => c.type === "tool-call" && c.result === undefined);
|
|
226
|
+
const autoStatus = getAutoStatus(isLast, isRunning, hasPendingToolCalls, hasPendingToolCalls, isLast ? metadata.error : undefined);
|
|
227
|
+
const newMessage = fromThreadMessageLike(joined, idx.toString(), autoStatus);
|
|
228
|
+
bindExternalStoreMessage(newMessage, message.inputs);
|
|
229
|
+
return newMessage;
|
|
230
|
+
});
|
|
231
|
+
if (metadata.error) {
|
|
232
|
+
const lastMessage = result.at(-1);
|
|
233
|
+
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
234
|
+
result.push(createErrorAssistantMessage(metadata.error));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
};
|
|
239
|
+
export const useExternalMessageConverter = ({ callback, messages, isRunning, joinStrategy, metadata, }) => {
|
|
240
|
+
const state = useMemo(() => ({
|
|
241
|
+
metadata: metadata ?? {},
|
|
242
|
+
callback,
|
|
243
|
+
callbackCache: new WeakMap(),
|
|
244
|
+
chunkCache: new WeakMap(),
|
|
245
|
+
converterCache: new ThreadMessageConverter(),
|
|
246
|
+
}), [callback, metadata]);
|
|
247
|
+
return useMemo(() => {
|
|
248
|
+
const callbackResults = [];
|
|
249
|
+
for (const message of messages) {
|
|
250
|
+
let result = state.callbackCache.get(message);
|
|
251
|
+
if (!result) {
|
|
252
|
+
const output = state.callback(message, state.metadata);
|
|
253
|
+
const outputs = Array.isArray(output) ? output : [output];
|
|
254
|
+
result = { input: message, outputs };
|
|
255
|
+
state.callbackCache.set(message, result);
|
|
256
|
+
}
|
|
257
|
+
callbackResults.push(result);
|
|
258
|
+
}
|
|
259
|
+
const chunks = chunkExternalMessages(callbackResults, joinStrategy).map((m) => {
|
|
260
|
+
const key = m.outputs[0];
|
|
261
|
+
if (!key)
|
|
262
|
+
return m;
|
|
263
|
+
const cached = state.chunkCache.get(key);
|
|
264
|
+
if (cached && shallowArrayEqual(cached.outputs, m.outputs))
|
|
265
|
+
return cached;
|
|
266
|
+
state.chunkCache.set(key, m);
|
|
267
|
+
return m;
|
|
268
|
+
});
|
|
269
|
+
const threadMessages = state.converterCache.convertMessages(chunks, (cache, message, idx) => {
|
|
270
|
+
const isLast = idx === chunks.length - 1;
|
|
271
|
+
const joined = joinExternalMessages(message.outputs);
|
|
272
|
+
const hasSuspendedToolCalls = typeof joined.content === "object" &&
|
|
273
|
+
joined.content.some((c) => c.type === "tool-call" && c.result === undefined);
|
|
274
|
+
const hasPendingToolCalls = typeof joined.content === "object" &&
|
|
275
|
+
joined.content.some((c) => c.type === "tool-call" && c.result === undefined);
|
|
276
|
+
const autoStatus = getAutoStatus(isLast, isRunning, hasSuspendedToolCalls, hasPendingToolCalls, isLast ? state.metadata.error : undefined);
|
|
277
|
+
if (cache &&
|
|
278
|
+
(cache.role !== "assistant" ||
|
|
279
|
+
!isAutoStatus(cache.status) ||
|
|
280
|
+
cache.status === autoStatus)) {
|
|
281
|
+
const inputs = getExternalStoreMessages(cache);
|
|
282
|
+
if (shallowArrayEqual(inputs, message.inputs)) {
|
|
283
|
+
return cache;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
const newMessage = fromThreadMessageLike(joined, idx.toString(), autoStatus);
|
|
287
|
+
bindExternalStoreMessage(newMessage, message.inputs);
|
|
288
|
+
return newMessage;
|
|
289
|
+
});
|
|
290
|
+
bindExternalStoreMessage(threadMessages, messages);
|
|
291
|
+
if (state.metadata.error) {
|
|
292
|
+
const lastMessage = threadMessages.at(-1);
|
|
293
|
+
if (!lastMessage || lastMessage.role !== "assistant") {
|
|
294
|
+
threadMessages.push(createErrorAssistantMessage(state.metadata.error));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return threadMessages;
|
|
298
|
+
}, [state, messages, isRunning, joinStrategy]);
|
|
299
|
+
};
|
|
300
|
+
const shallowArrayEqual = (a, b) => {
|
|
301
|
+
if (a.length !== b.length)
|
|
302
|
+
return false;
|
|
303
|
+
for (let i = 0; i < a.length; i++) {
|
|
304
|
+
if (a[i] !== b[i])
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
return true;
|
|
308
|
+
};
|
|
309
|
+
//# sourceMappingURL=external-message-converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-message-converter.js","sourceRoot":"","sources":["../../../src/react/runtimes/external-message-converter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,kEAA+D;AAChG,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,wBAAwB,GACzB,sDAAmD;AACpD,OAAO,EACL,qBAAqB,GAEtB,mDAAgD;AACjD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,2CAAwC;AAG9E,OAAO,EAAE,sBAAsB,EAAE,0BAAuB;AAmDxD,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAE,QAAgB,EAAE,EAAE,CAAC,CAAC;IAClE,CAAC,kBAAkB,CAAC,EAAE;QACpB,GAAG,CAAE,QAAgB,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAChD,GAAG,CAAE,QAAgB,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC;KACjD;CACF,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,CAC3B,QAAwD,EACrC,EAAE;IACrB,MAAM,gBAAgB,GAGlB;QACF,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,EAAE;KACZ,CAAC;IACF,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC9B,IAAI,MAAM,CAAC,IAAI,KAA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c,CAAC;IACxB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,CAAY,EAAE,CAAY,EAAE,EAAE;IACvD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAClC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { RuntimeAdapterProvider, useRuntimeAdapters, type RuntimeAdapters, } from "./RuntimeAdapterProvider.js";
|
|
2
|
+
export { useToolInvocations, type ToolExecutionStatus, type AssistantTransportState, type AddToolResultCommand, } from "./useToolInvocations.js";
|
|
3
|
+
export { useExternalStoreRuntime } from "./useExternalStoreRuntime.js";
|
|
4
|
+
export { useExternalMessageConverter, convertExternalMessages, } from "./external-message-converter.js";
|
|
5
|
+
export { createMessageConverter } from "./createMessageConverter.js";
|
|
6
|
+
export { RemoteThreadListHookInstanceManager } from "./RemoteThreadListHookInstanceManager.js";
|
|
7
|
+
export { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore.js";
|
|
8
|
+
export { useRemoteThreadListRuntime } from "./useRemoteThreadListRuntime.js";
|
|
9
|
+
export { useCloudThreadListAdapter, useAssistantCloudThreadHistoryAdapter, CloudFileAttachmentAdapter, } from "./cloud/index.js";
|
|
10
|
+
export { useLocalRuntime, splitLocalRuntimeOptions, type LocalRuntimeOptions, } from "./useLocalRuntime.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/runtimes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,eAAe,GACrB,oCAAiC;AAElC,OAAO,EACL,kBAAkB,EAClB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,GAC1B,gCAA6B;AAE9B,OAAO,EAAE,uBAAuB,EAAE,qCAAkC;AAEpE,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GACxB,wCAAqC;AACtC,OAAO,EAAE,sBAAsB,EAAE,oCAAiC;AAElE,OAAO,EAAE,mCAAmC,EAAE,iDAA8C;AAC5F,OAAO,EAAE,qCAAqC,EAAE,mDAAgD;AAChG,OAAO,EAAE,0BAA0B,EAAE,wCAAqC;AAE1E,OAAO,EACL,yBAAyB,EACzB,qCAAqC,EACrC,0BAA0B,GAC3B,yBAAgB;AAEjB,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,KAAK,mBAAmB,GACzB,6BAA0B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { RuntimeAdapterProvider, useRuntimeAdapters, } from "./RuntimeAdapterProvider.js";
|
|
2
|
+
export { useToolInvocations, } from "./useToolInvocations.js";
|
|
3
|
+
export { useExternalStoreRuntime } from "./useExternalStoreRuntime.js";
|
|
4
|
+
export { useExternalMessageConverter, convertExternalMessages, } from "./external-message-converter.js";
|
|
5
|
+
export { createMessageConverter } from "./createMessageConverter.js";
|
|
6
|
+
export { RemoteThreadListHookInstanceManager } from "./RemoteThreadListHookInstanceManager.js";
|
|
7
|
+
export { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore.js";
|
|
8
|
+
export { useRemoteThreadListRuntime } from "./useRemoteThreadListRuntime.js";
|
|
9
|
+
export { useCloudThreadListAdapter, useAssistantCloudThreadHistoryAdapter, CloudFileAttachmentAdapter, } from "./cloud/index.js";
|
|
10
|
+
export { useLocalRuntime, splitLocalRuntimeOptions, } from "./useLocalRuntime.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/runtimes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,kBAAkB,GAEnB,oCAAiC;AAElC,OAAO,EACL,kBAAkB,GAInB,gCAA6B;AAE9B,OAAO,EAAE,uBAAuB,EAAE,qCAAkC;AAEpE,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GACxB,wCAAqC;AACtC,OAAO,EAAE,sBAAsB,EAAE,oCAAiC;AAElE,OAAO,EAAE,mCAAmC,EAAE,iDAA8C;AAC5F,OAAO,EAAE,qCAAqC,EAAE,mDAAgD;AAChG,OAAO,EAAE,0BAA0B,EAAE,wCAAqC;AAE1E,OAAO,EACL,yBAAyB,EACzB,qCAAqC,EACrC,0BAA0B,GAC3B,yBAAgB;AAEjB,OAAO,EACL,eAAe,EACf,wBAAwB,GAEzB,6BAA0B"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ExternalStoreAdapter } from "../../runtimes/external-store/external-store-adapter.js";
|
|
2
|
+
import type { AssistantRuntime } from "../../runtime/api/assistant-runtime.js";
|
|
3
|
+
export declare const useExternalStoreRuntime: <T>(store: ExternalStoreAdapter<T>) => AssistantRuntime;
|
|
4
|
+
//# sourceMappingURL=useExternalStoreRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useExternalStoreRuntime.d.ts","sourceRoot":"","sources":["../../../src/react/runtimes/useExternalStoreRuntime.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gEAA6D;AACjG,OAAO,KAAK,EAAE,gBAAgB,EAAE,+CAA4C;AAI5E,eAAO,MAAM,uBAAuB,GAAI,CAAC,EACvC,OAAO,oBAAoB,CAAC,CAAC,CAAC,KAC7B,gBAeF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { ExternalStoreRuntimeCore } from "../../runtimes/internal.js";
|
|
4
|
+
import { AssistantRuntimeImpl } from "../../runtime/internal.js";
|
|
5
|
+
import { useRuntimeAdapters } from "./RuntimeAdapterProvider.js";
|
|
6
|
+
export const useExternalStoreRuntime = (store) => {
|
|
7
|
+
const [runtime] = useState(() => new ExternalStoreRuntimeCore(store));
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
runtime.setAdapter(store);
|
|
10
|
+
});
|
|
11
|
+
const { modelContext } = useRuntimeAdapters() ?? {};
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!modelContext)
|
|
14
|
+
return undefined;
|
|
15
|
+
return runtime.registerModelContextProvider(modelContext);
|
|
16
|
+
}, [modelContext, runtime]);
|
|
17
|
+
return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=useExternalStoreRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useExternalStoreRuntime.js","sourceRoot":"","sources":["../../../src/react/runtimes/useExternalStoreRuntime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,mCAAgC;AAGnE,OAAO,EAAE,oBAAoB,EAAE,kCAA+B;AAC9D,OAAO,EAAE,kBAAkB,EAAE,oCAAiC;AAE9D,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,KAA8B,EACZ,EAAE;IACpB,MAAM,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;IAEtE,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,MAAM,EAAE,YAAY,EAAE,GAAG,kBAAkB,EAAE,IAAI,EAAE,CAAC;IAEpD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,YAAY;YAAE,OAAO,SAAS,CAAC;QACpC,OAAO,OAAO,CAAC,4BAA4B,CAAC,YAAY,CAAC,CAAC;IAC5D,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC;IAE5B,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AACrE,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AssistantRuntime, ChatModelAdapter, ThreadMessageLike } from "../../index.js";
|
|
2
|
+
import type { LocalRuntimeOptionsBase } from "../../runtimes/local/local-runtime-options.js";
|
|
3
|
+
import type { AssistantCloud } from "assistant-cloud";
|
|
4
|
+
export type LocalRuntimeOptions = Omit<LocalRuntimeOptionsBase, "adapters"> & {
|
|
5
|
+
cloud?: AssistantCloud | undefined;
|
|
6
|
+
initialMessages?: readonly ThreadMessageLike[] | undefined;
|
|
7
|
+
adapters?: Omit<LocalRuntimeOptionsBase["adapters"], "chatModel"> | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare const splitLocalRuntimeOptions: <T extends LocalRuntimeOptions>(options: T) => {
|
|
10
|
+
localRuntimeOptions: {
|
|
11
|
+
cloud: AssistantCloud | undefined;
|
|
12
|
+
initialMessages: readonly ThreadMessageLike[] | undefined;
|
|
13
|
+
maxSteps: number | undefined;
|
|
14
|
+
adapters: Omit<{
|
|
15
|
+
chatModel: ChatModelAdapter;
|
|
16
|
+
history?: import("../../adapters").ThreadHistoryAdapter | undefined;
|
|
17
|
+
attachments?: import("../../adapters").AttachmentAdapter | undefined;
|
|
18
|
+
speech?: import("../../adapters").SpeechSynthesisAdapter | undefined;
|
|
19
|
+
dictation?: import("../../adapters").DictationAdapter | undefined;
|
|
20
|
+
feedback?: import("../../adapters").FeedbackAdapter | undefined;
|
|
21
|
+
suggestion?: import("../../adapters").SuggestionAdapter | undefined;
|
|
22
|
+
}, "chatModel"> | undefined;
|
|
23
|
+
unstable_humanToolNames: string[] | undefined;
|
|
24
|
+
};
|
|
25
|
+
otherOptions: Omit<T, "initialMessages" | "adapters" | "maxSteps" | "unstable_humanToolNames" | "cloud">;
|
|
26
|
+
};
|
|
27
|
+
export declare const useLocalRuntime: (chatModel: ChatModelAdapter, { cloud, ...options }?: LocalRuntimeOptions) => AssistantRuntime;
|
|
28
|
+
//# sourceMappingURL=useLocalRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocalRuntime.d.ts","sourceRoot":"","sources":["../../../src/react/runtimes/useLocalRuntime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,uBAAoB;AACrB,OAAO,KAAK,EAAE,uBAAuB,EAAE,sDAAmD;AAM1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,uBAAuB,EAAE,UAAU,CAAC,GAAG;IAC5E,KAAK,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IACnC,eAAe,CAAC,EAAE,SAAS,iBAAiB,EAAE,GAAG,SAAS,CAAC;IAC3D,QAAQ,CAAC,EAAE,IAAI,CAAC,uBAAuB,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,GAAG,SAAS,CAAC;CAC/E,CAAC;AA8CF,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,mBAAmB,EACpE,SAAS,CAAC;;;;;;;;;;;;;;;;;CAqBX,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,WAAW,gBAAgB,EAC3B,wBAAuB,mBAAwB,KAC9C,gBASF,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { AssistantRuntimeImpl, LocalRuntimeCore } from "../../internal.js";
|
|
3
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
4
|
+
import { useRemoteThreadListRuntime } from "./useRemoteThreadListRuntime.js";
|
|
5
|
+
import { useCloudThreadListAdapter } from "./cloud/index.js";
|
|
6
|
+
import { useRuntimeAdapters } from "./RuntimeAdapterProvider.js";
|
|
7
|
+
const useLocalThreadRuntime = (chatModel, { initialMessages, ...options }) => {
|
|
8
|
+
const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};
|
|
9
|
+
const opt = {
|
|
10
|
+
...options,
|
|
11
|
+
adapters: {
|
|
12
|
+
...threadListAdapters,
|
|
13
|
+
...options.adapters,
|
|
14
|
+
chatModel,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));
|
|
18
|
+
const threadIdRef = useRef(undefined);
|
|
19
|
+
threadIdRef.current = useAuiState((s) => s.threadListItem.remoteId);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
runtime.threads
|
|
22
|
+
.getMainThreadRuntimeCore()
|
|
23
|
+
.__internal_setGetThreadId(() => threadIdRef.current);
|
|
24
|
+
}, [runtime]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
return () => {
|
|
27
|
+
runtime.threads.getMainThreadRuntimeCore().detach();
|
|
28
|
+
};
|
|
29
|
+
}, [runtime]);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);
|
|
32
|
+
runtime.threads.getMainThreadRuntimeCore().__internal_load();
|
|
33
|
+
});
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!modelContext)
|
|
36
|
+
return undefined;
|
|
37
|
+
return runtime.registerModelContextProvider(modelContext);
|
|
38
|
+
}, [modelContext, runtime]);
|
|
39
|
+
return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
|
|
40
|
+
};
|
|
41
|
+
export const splitLocalRuntimeOptions = (options) => {
|
|
42
|
+
const { cloud, initialMessages, maxSteps, adapters, unstable_humanToolNames, ...rest } = options;
|
|
43
|
+
return {
|
|
44
|
+
localRuntimeOptions: {
|
|
45
|
+
cloud,
|
|
46
|
+
initialMessages,
|
|
47
|
+
maxSteps,
|
|
48
|
+
adapters,
|
|
49
|
+
unstable_humanToolNames,
|
|
50
|
+
},
|
|
51
|
+
otherOptions: rest,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export const useLocalRuntime = (chatModel, { cloud, ...options } = {}) => {
|
|
55
|
+
const cloudAdapter = useCloudThreadListAdapter({ cloud });
|
|
56
|
+
return useRemoteThreadListRuntime({
|
|
57
|
+
runtimeHook: function RuntimeHook() {
|
|
58
|
+
return useLocalThreadRuntime(chatModel, options);
|
|
59
|
+
},
|
|
60
|
+
adapter: cloudAdapter,
|
|
61
|
+
allowNesting: true,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=useLocalRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocalRuntime.js","sourceRoot":"","sources":["../../../src/react/runtimes/useLocalRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAO7D,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,0BAAuB;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,wCAAqC;AAC1E,OAAO,EAAE,yBAAyB,EAAE,yBAAgB;AACpD,OAAO,EAAE,kBAAkB,EAAE,oCAAiC;AAS9D,MAAM,qBA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,CAAC,YAAY;YAAE,OAAO,SAAS,CAAC;QACpC,OAAO,OAAO,CAAC,4BAA4B,CAAC,YAAY,CAAC,CAAC;IAC5D,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC;IAE5B,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AACrE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,OAAU,EACV,EAAE;IACF,MAAM,EACJ,KAAK,EACL,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,uBAAuB,EACvB,GAAG,IAAI,EACR,GAAG,OAAO,CAAC;IAEZ,OAAO;QACL,mBAAmB,EAAE;YACnB,KAAK;YACL,eAAe;YACf,QAAQ;YACR,QAAQ;YACR,uBAAuB;SACxB;QACD,YAAY,EAAE,IAAI;KACnB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,SAA2B,EAC3B,EAAE,KAAK,EAAE,GAAG,OAAO,KAA0B,EAAE,EAC7B,EAAE;IACpB,MAAM,YAAY,GAAG,yBAAyB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1D,OAAO,0BAA0B,CAAC;QAChC,WAAW,EAAE,SAAS,WAAW;YAC/B,OAAO,qBAAqB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,EAAE,YAAY;QACrB,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RemoteThreadListOptions } from "../../runtimes/remote-thread-list/types.js";
|
|
2
|
+
import type { AssistantRuntime } from "../../runtime/api/assistant-runtime.js";
|
|
3
|
+
export declare const useRemoteThreadListRuntime: (options: RemoteThreadListOptions) => AssistantRuntime;
|
|
4
|
+
//# sourceMappingURL=useRemoteThreadListRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRemoteThreadListRuntime.d.ts","sourceRoot":"","sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,mDAAgD;AAEvF,OAAO,KAAK,EAAE,gBAAgB,EAAE,+CAA4C;AAkC5E,eAAO,MAAM,0BAA0B,GACrC,SAAS,uBAAuB,KAC/B,gBAkCF,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo, useRef, useCallback } from "react";
|
|
2
|
+
import { BaseAssistantRuntimeCore } from "../../runtime/base/base-assistant-runtime-core.js";
|
|
3
|
+
import { AssistantRuntimeImpl } from "../../runtime/api/assistant-runtime.js";
|
|
4
|
+
import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore.js";
|
|
5
|
+
import { useAui } from "@assistant-ui/store";
|
|
6
|
+
class RemoteThreadListRuntimeCore extends BaseAssistantRuntimeCore {
|
|
7
|
+
threads;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super();
|
|
10
|
+
this.threads = new RemoteThreadListThreadListRuntimeCore(options, this._contextProvider);
|
|
11
|
+
}
|
|
12
|
+
get RenderComponent() {
|
|
13
|
+
return this.threads.__internal_RenderComponent;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const useRemoteThreadListRuntimeImpl = (options) => {
|
|
17
|
+
const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
runtime.threads.__internal_setOptions(options);
|
|
20
|
+
runtime.threads.__internal_load();
|
|
21
|
+
}, [runtime, options]);
|
|
22
|
+
return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
|
|
23
|
+
};
|
|
24
|
+
export const useRemoteThreadListRuntime = (options) => {
|
|
25
|
+
const runtimeHookRef = useRef(options.runtimeHook);
|
|
26
|
+
runtimeHookRef.current = options.runtimeHook;
|
|
27
|
+
const stableRuntimeHook = useCallback(() => {
|
|
28
|
+
return runtimeHookRef.current();
|
|
29
|
+
}, []);
|
|
30
|
+
const stableOptions = useMemo(() => ({
|
|
31
|
+
adapter: options.adapter,
|
|
32
|
+
allowNesting: options.allowNesting,
|
|
33
|
+
runtimeHook: stableRuntimeHook,
|
|
34
|
+
}), [options.adapter, options.allowNesting, stableRuntimeHook]);
|
|
35
|
+
const aui = useAui();
|
|
36
|
+
const isNested = aui.threadListItem.source !== null;
|
|
37
|
+
if (isNested) {
|
|
38
|
+
if (!stableOptions.allowNesting) {
|
|
39
|
+
throw new Error("useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. " +
|
|
40
|
+
"Set allowNesting: true to allow nesting (the inner runtime will become a no-op).");
|
|
41
|
+
}
|
|
42
|
+
// If allowNesting is true and already inside a thread list context,
|
|
43
|
+
// just call the runtimeHook directly (no-op behavior)
|
|
44
|
+
return stableRuntimeHook();
|
|
45
|
+
}
|
|
46
|
+
return useRemoteThreadListRuntimeImpl(stableOptions);
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=useRemoteThreadListRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRemoteThreadListRuntime.js","sourceRoot":"","sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,0DAAuD;AAC1F,OAAO,EAAE,oBAAoB,EAAE,+CAA4C;AAI3E,OAAO,EAAE,qCAAqC,EAAE,mDAAgD;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,MAAM,2BACJ,SAAQ,wBAAwB;IAGhB,OAAO,CAAC;IAExB,YAAY,OA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AAO,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAC3D,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;IACrB,MAAM,QAAQ,GAAG,GAAG,CAAC,cAAc,CAAC,MAAM,KAAK,IAAI,CAAC;IAEpD,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACb,sFAAsF;gBACpF,kFAAkF,CACrF,CAAC;QACJ,CAAC;QAED,oEAAoE;QACpE,sDAAsD;QACtD,OAAO,iBAAiB,EAAE,CAAC;IAC7B,CAAC;IAED,OAAO,8BAA8B,CAAC,aAAa,CAAC,CAAC;AACvD,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Tool } from "assistant-stream";
|
|
2
|
+
import { type ReadonlyJSONValue } from "assistant-stream/utils";
|
|
3
|
+
import type { ThreadMessage } from "../../types/index.js";
|
|
4
|
+
export type AssistantTransportState = {
|
|
5
|
+
readonly messages: readonly ThreadMessage[];
|
|
6
|
+
readonly state?: ReadonlyJSONValue;
|
|
7
|
+
readonly isRunning: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type AddToolResultCommand = {
|
|
10
|
+
readonly type: "add-tool-result";
|
|
11
|
+
readonly toolCallId: string;
|
|
12
|
+
readonly toolName: string;
|
|
13
|
+
readonly result: ReadonlyJSONValue;
|
|
14
|
+
readonly isError: boolean;
|
|
15
|
+
readonly artifact?: ReadonlyJSONValue;
|
|
16
|
+
};
|
|
17
|
+
type UseToolInvocationsParams = {
|
|
18
|
+
state: AssistantTransportState;
|
|
19
|
+
getTools: () => Record<string, Tool> | undefined;
|
|
20
|
+
onResult: (command: AddToolResultCommand) => void;
|
|
21
|
+
setToolStatuses: (updater: Record<string, ToolExecutionStatus> | ((prev: Record<string, ToolExecutionStatus>) => Record<string, ToolExecutionStatus>)) => void;
|
|
22
|
+
};
|
|
23
|
+
export type ToolExecutionStatus = {
|
|
24
|
+
type: "executing";
|
|
25
|
+
} | {
|
|
26
|
+
type: "interrupt";
|
|
27
|
+
payload: {
|
|
28
|
+
type: "human";
|
|
29
|
+
payload: unknown;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export declare function useToolInvocations({ state, getTools, onResult, setToolStatuses, }: UseToolInvocationsParams): {
|
|
33
|
+
reset: () => void;
|
|
34
|
+
abort: () => Promise<void>;
|
|
35
|
+
resume: (toolCallId: string, payload: unknown) => void;
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=useToolInvocations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useToolInvocations.d.ts","sourceRoot":"","sources":["../../../src/react/runtimes/useToolInvocations.ts"],"names":[],"mappings":"AAGA,OAAO,EAKL,KAAK,IAAI,EACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,aAAa,EAAE,6BAAoB;AAEjD,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IAC5C,QAAQ,CAAC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CACvC,CAAC;AA0BF,KAAK,wBAAwB,GAAG;IAC9B,KAAK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