@assistant-ui/react 0.12.15 → 0.12.17
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.d.ts +1 -4
- package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.js +2 -527
- package/dist/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +96 -96
- package/dist/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.d.ts +1 -16
- package/dist/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.js +1 -14
- package/dist/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.d.ts +1 -13
- package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.js +2 -82
- package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts +1 -23
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js +1 -410
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.d.ts +1 -16
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/createMessageConverter.js +1 -48
- 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 +1 -33
- 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 +1 -307
- package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.d.ts +1 -3
- package/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.js +1 -17
- package/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.d.ts +2 -26
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.js +1 -13
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts +1 -3
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.js +1 -51
- package/dist/legacy-runtime/runtime-cores/local/useLocalRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +1 -96
- 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 -110
- 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 +1 -112
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js +1 -439
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.d.ts +1 -12
- 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 +1 -102
- 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 +1 -3
- 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 +1 -46
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarCopy.js +7 -20
- package/dist/primitives/actionBar/ActionBarCopy.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarEdit.js +3 -8
- package/dist/primitives/actionBar/ActionBarEdit.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js +4 -7
- package/dist/primitives/actionBar/ActionBarFeedbackNegative.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js +5 -7
- package/dist/primitives/actionBar/ActionBarFeedbackPositive.js.map +1 -1
- package/dist/primitives/actionBar/ActionBarReload.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarReload.js +3 -10
- package/dist/primitives/actionBar/ActionBarReload.js.map +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAddAttachment.js +5 -4
- package/dist/primitives/composer/ComposerAddAttachment.js.map +1 -1
- package/dist/primitives/composer/ComposerCancel.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerCancel.js +3 -8
- package/dist/primitives/composer/ComposerCancel.js.map +1 -1
- package/dist/primitives/composer/ComposerSend.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerSend.js +3 -8
- package/dist/primitives/composer/ComposerSend.js.map +1 -1
- package/dist/utils/createActionButton.js +1 -1
- package/dist/utils/createActionButton.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/internal.ts +1 -1
- package/src/legacy-runtime/cloud/AssistantCloudThreadHistoryAdapter.ts +2 -784
- package/src/legacy-runtime/runtime-cores/adapters/RuntimeAdapterProvider.tsx +5 -43
- package/src/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.ts +2 -100
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +4 -580
- package/src/legacy-runtime/runtime-cores/external-store/createMessageConverter.ts +1 -76
- package/src/legacy-runtime/runtime-cores/external-store/external-message-converter.ts +4 -483
- package/src/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.ts +1 -27
- package/src/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.ts +2 -35
- package/src/legacy-runtime/runtime-cores/local/useLocalRuntime.ts +1 -67
- package/src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +1 -178
- package/src/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.tsx +1 -529
- package/src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx +1 -152
- package/src/legacy-runtime/runtime-cores/remote-thread-list/useRemoteThreadListRuntime.ts +1 -80
- package/src/primitives/actionBar/ActionBarCopy.tsx +7 -26
- package/src/primitives/actionBar/ActionBarEdit.ts +3 -10
- package/src/primitives/actionBar/ActionBarFeedbackNegative.tsx +4 -9
- package/src/primitives/actionBar/ActionBarFeedbackPositive.tsx +5 -9
- package/src/primitives/actionBar/ActionBarReload.ts +3 -16
- package/src/primitives/composer/ComposerAddAttachment.ts +5 -4
- package/src/primitives/composer/ComposerCancel.ts +3 -10
- package/src/primitives/composer/ComposerSend.ts +3 -13
- package/src/tests/BaseComposerRuntimeCore.test.ts +2 -3
- package/src/utils/createActionButton.tsx +1 -1
|
@@ -1,34 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { ToolExecutionStatus } from "../assistant-transport/useToolInvocations.js";
|
|
3
|
-
import { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
4
|
-
import type { MessageTiming, ThreadMessage } from "@assistant-ui/core";
|
|
5
|
-
export declare namespace useExternalMessageConverter {
|
|
6
|
-
type Message = (ThreadMessageLike & {
|
|
7
|
-
readonly convertConfig?: {
|
|
8
|
-
readonly joinStrategy?: "concat-content" | "none";
|
|
9
|
-
};
|
|
10
|
-
}) | {
|
|
11
|
-
role: "tool";
|
|
12
|
-
toolCallId: string;
|
|
13
|
-
toolName?: string | undefined;
|
|
14
|
-
result: any;
|
|
15
|
-
artifact?: any;
|
|
16
|
-
isError?: boolean;
|
|
17
|
-
messages?: readonly ThreadMessage[];
|
|
18
|
-
};
|
|
19
|
-
type Metadata = {
|
|
20
|
-
readonly toolStatuses?: Record<string, ToolExecutionStatus>;
|
|
21
|
-
readonly error?: ReadonlyJSONValue;
|
|
22
|
-
readonly messageTiming?: Record<string, MessageTiming>;
|
|
23
|
-
};
|
|
24
|
-
type Callback<T> = (message: T, metadata: Metadata) => Message | Message[];
|
|
25
|
-
}
|
|
26
|
-
export declare const convertExternalMessages: <T extends WeakKey>(messages: T[], callback: useExternalMessageConverter.Callback<T>, isRunning: boolean, metadata: useExternalMessageConverter.Metadata) => ThreadMessage[];
|
|
27
|
-
export declare const useExternalMessageConverter: <T extends WeakKey>({ callback, messages, isRunning, joinStrategy, metadata, }: {
|
|
28
|
-
callback: useExternalMessageConverter.Callback<T>;
|
|
29
|
-
messages: T[];
|
|
30
|
-
isRunning: boolean;
|
|
31
|
-
joinStrategy?: "concat-content" | "none" | undefined;
|
|
32
|
-
metadata?: useExternalMessageConverter.Metadata | undefined;
|
|
33
|
-
}) => ThreadMessage[];
|
|
1
|
+
export { useExternalMessageConverter, convertExternalMessages, } from "@assistant-ui/core/react";
|
|
34
2
|
//# sourceMappingURL=external-message-converter.d.ts.map
|
package/dist/legacy-runtime/runtime-cores/external-store/external-message-converter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-message-converter.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/external-message-converter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"external-message-converter.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/external-message-converter.ts"],"names":[],"mappings":"AACA,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,309 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import { ThreadMessageConverter } from "./ThreadMessageConverter.js";
|
|
4
|
-
import { getExternalStoreMessages, symbolInnerMessage, bindExternalStoreMessage, } from "./getExternalStoreMessage.js";
|
|
5
|
-
import { fromThreadMessageLike } from "./ThreadMessageLike.js";
|
|
6
|
-
import { getAutoStatus, isAutoStatus } from "./auto-status.js";
|
|
7
|
-
import { generateErrorMessageId } from "@assistant-ui/core/internal";
|
|
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
|
-
};
|
|
2
|
+
export { useExternalMessageConverter, convertExternalMessages, } from "@assistant-ui/core/react";
|
|
309
3
|
//# sourceMappingURL=external-message-converter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-message-converter.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/external-message-converter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,sBAAsB,EAAE,oCAAiC;AAClE,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,wBAAwB,GACzB,qCAAkC;AACnC,OAAO,EAAE,qBAAqB,EAAqB,+BAA4B;AAC/E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,yBAAsB;AAG5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AAC,QAAQ,EAAE,EACd,UAAU,CACX,CAAC;YACF,wBAAwB,CAAC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;YACrD,OAAO,UAAU,CAAC;QACpB,CAAC,CACF,CAAC;QAEF,wBAAwB,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QAEnD,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACzB,MAAM,WAAW,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;gBACrD,cAAc,CAAC,IAAI,CAAC,2BAA2B,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QAED,OAAO,cAAc,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"}
|
|
1
|
+
{"version":3,"file":"external-message-converter.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/external-message-converter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { AssistantRuntime } from "../../runtime/AssistantRuntime.js";
|
|
3
|
-
export declare const useExternalStoreRuntime: <T>(store: ExternalStoreAdapter<T>) => AssistantRuntime;
|
|
1
|
+
export { useExternalStoreRuntime } from "@assistant-ui/core/react";
|
|
4
2
|
//# sourceMappingURL=useExternalStoreRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalStoreRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useExternalStoreRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import { ExternalStoreRuntimeCore } from "./ExternalStoreRuntimeCore.js";
|
|
4
|
-
import { AssistantRuntimeImpl, } from "../../runtime/AssistantRuntime.js";
|
|
5
|
-
import { useRuntimeAdapters } from "../adapters/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
|
-
};
|
|
2
|
+
export { useExternalStoreRuntime } from "@assistant-ui/core/react";
|
|
19
3
|
//# sourceMappingURL=useExternalStoreRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalStoreRuntime.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useExternalStoreRuntime.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,28 +1,4 @@
|
|
|
1
1
|
export type { LocalRuntimeOptionsBase } from "@assistant-ui/core";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { AssistantCloud } from "assistant-cloud";
|
|
5
|
-
export type LocalRuntimeOptions = Omit<LocalRuntimeOptionsBase, "adapters"> & {
|
|
6
|
-
cloud?: AssistantCloud | undefined;
|
|
7
|
-
initialMessages?: readonly ThreadMessageLike[] | undefined;
|
|
8
|
-
adapters?: Omit<LocalRuntimeOptionsBase["adapters"], "chatModel"> | undefined;
|
|
9
|
-
};
|
|
10
|
-
export declare const splitLocalRuntimeOptions: <T extends LocalRuntimeOptions>(options: T) => {
|
|
11
|
-
localRuntimeOptions: {
|
|
12
|
-
cloud: AssistantCloud | undefined;
|
|
13
|
-
initialMessages: readonly ThreadMessageLike[] | undefined;
|
|
14
|
-
maxSteps: number | undefined;
|
|
15
|
-
adapters: Omit<{
|
|
16
|
-
chatModel: import("@assistant-ui/core").ChatModelAdapter;
|
|
17
|
-
history?: import("@assistant-ui/core").ThreadHistoryAdapter | undefined;
|
|
18
|
-
attachments?: import("@assistant-ui/core").AttachmentAdapter | undefined;
|
|
19
|
-
speech?: import("@assistant-ui/core").SpeechSynthesisAdapter | undefined;
|
|
20
|
-
dictation?: import("@assistant-ui/core").DictationAdapter | undefined;
|
|
21
|
-
feedback?: import("@assistant-ui/core").FeedbackAdapter | undefined;
|
|
22
|
-
suggestion?: import("@assistant-ui/core").SuggestionAdapter | undefined;
|
|
23
|
-
}, "chatModel"> | undefined;
|
|
24
|
-
unstable_humanToolNames: string[] | undefined;
|
|
25
|
-
};
|
|
26
|
-
otherOptions: Omit<T, "adapters" | "maxSteps" | "unstable_humanToolNames" | "cloud" | "initialMessages">;
|
|
27
|
-
};
|
|
2
|
+
export type { LocalRuntimeOptions } from "@assistant-ui/core/react";
|
|
3
|
+
export { splitLocalRuntimeOptions } from "@assistant-ui/core/react";
|
|
28
4
|
//# sourceMappingURL=LocalRuntimeOptions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalRuntimeOptions.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"LocalRuntimeOptions.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClE,YAAY,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
const { cloud, initialMessages, maxSteps, adapters, unstable_humanToolNames, ...rest } = options;
|
|
3
|
-
return {
|
|
4
|
-
localRuntimeOptions: {
|
|
5
|
-
cloud,
|
|
6
|
-
initialMessages,
|
|
7
|
-
maxSteps,
|
|
8
|
-
adapters,
|
|
9
|
-
unstable_humanToolNames,
|
|
10
|
-
},
|
|
11
|
-
otherOptions: rest,
|
|
12
|
-
};
|
|
13
|
-
};
|
|
1
|
+
export { splitLocalRuntimeOptions } from "@assistant-ui/core/react";
|
|
14
2
|
//# sourceMappingURL=LocalRuntimeOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalRuntimeOptions.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LocalRuntimeOptions.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { LocalRuntimeOptions } from "./LocalRuntimeOptions.js";
|
|
3
|
-
export declare const useLocalRuntime: (adapter: ChatModelAdapter, { cloud, ...options }?: LocalRuntimeOptions) => import("@assistant-ui/core").AssistantRuntime;
|
|
1
|
+
export { useLocalRuntime } from "@assistant-ui/core/react";
|
|
4
2
|
//# sourceMappingURL=useLocalRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/useLocalRuntime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocalRuntime.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/useLocalRuntime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,53 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import { LocalRuntimeCore } from "./LocalRuntimeCore.js";
|
|
4
|
-
import { useRuntimeAdapters } from "../adapters/RuntimeAdapterProvider.js";
|
|
5
|
-
import { useRemoteThreadListRuntime } from "../remote-thread-list/useRemoteThreadListRuntime.js";
|
|
6
|
-
import { useCloudThreadListAdapter } from "../remote-thread-list/adapter/cloud.js";
|
|
7
|
-
import { AssistantRuntimeImpl } from "../../../internal.js";
|
|
8
|
-
import { useAuiState } from "@assistant-ui/store";
|
|
9
|
-
const useLocalThreadRuntime = (adapter, { initialMessages, ...options }) => {
|
|
10
|
-
const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};
|
|
11
|
-
const opt = {
|
|
12
|
-
...options,
|
|
13
|
-
adapters: {
|
|
14
|
-
...threadListAdapters,
|
|
15
|
-
...options.adapters,
|
|
16
|
-
chatModel: adapter,
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));
|
|
20
|
-
const threadIdRef = useRef(undefined);
|
|
21
|
-
threadIdRef.current = useAuiState((s) => s.threadListItem.remoteId);
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
runtime.threads
|
|
24
|
-
.getMainThreadRuntimeCore()
|
|
25
|
-
.__internal_setGetThreadId(() => threadIdRef.current);
|
|
26
|
-
}, [runtime]);
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
return () => {
|
|
29
|
-
runtime.threads.getMainThreadRuntimeCore().detach();
|
|
30
|
-
};
|
|
31
|
-
}, [runtime]);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);
|
|
34
|
-
runtime.threads.getMainThreadRuntimeCore().__internal_load();
|
|
35
|
-
});
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (!modelContext)
|
|
38
|
-
return undefined;
|
|
39
|
-
return runtime.registerModelContextProvider(modelContext);
|
|
40
|
-
}, [modelContext, runtime]);
|
|
41
|
-
return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);
|
|
42
|
-
};
|
|
43
|
-
export const useLocalRuntime = (adapter, { cloud, ...options } = {}) => {
|
|
44
|
-
const cloudAdapter = useCloudThreadListAdapter({ cloud });
|
|
45
|
-
return useRemoteThreadListRuntime({
|
|
46
|
-
runtimeHook: function RuntimeHook() {
|
|
47
|
-
return useLocalThreadRuntime(adapter, options);
|
|
48
|
-
},
|
|
49
|
-
adapter: cloudAdapter,
|
|
50
|
-
allowNesting: true,
|
|
51
|
-
});
|
|
52
|
-
};
|
|
2
|
+
export { useLocalRuntime } from "@assistant-ui/core/react";
|
|
53
3
|
//# sourceMappingURL=useLocalRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalRuntime.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/useLocalRuntime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useLocalRuntime.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/local/useLocalRuntime.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC"}
|