@assistant-ui/react 0.12.14 → 0.12.16
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 -305
- 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 -295
- 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 +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/ActionBarInteractionContext.d.ts +6 -0
- package/dist/primitives/actionBar/ActionBarInteractionContext.d.ts.map +1 -0
- package/dist/primitives/actionBar/ActionBarInteractionContext.js +5 -0
- package/dist/primitives/actionBar/ActionBarInteractionContext.js.map +1 -0
- package/dist/primitives/actionBar/ActionBarRoot.d.ts.map +1 -1
- package/dist/primitives/actionBar/ActionBarRoot.js +18 -4
- package/dist/primitives/actionBar/ActionBarRoot.js.map +1 -1
- package/dist/primitives/actionBar/useActionBarFloatStatus.d.ts +2 -1
- package/dist/primitives/actionBar/useActionBarFloatStatus.d.ts.map +1 -1
- package/dist/primitives/actionBar/useActionBarFloatStatus.js +3 -2
- package/dist/primitives/actionBar/useActionBarFloatStatus.js.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.d.ts.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.js +35 -2
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.js.map +1 -1
- package/dist/utils/createActionButton.js +1 -1
- package/dist/utils/createActionButton.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 +1 -0
- package/dist/utils/json/is-json.d.ts.map +1 -1
- package/dist/utils/json/is-json.js +5 -3
- package/dist/utils/json/is-json.js.map +1 -1
- package/package.json +8 -8
- 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.test.ts +225 -2
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +4 -439
- 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 -465
- package/src/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.ts +1 -27
- 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/ActionBarInteractionContext.ts +13 -0
- package/src/primitives/actionBar/ActionBarRoot.tsx +38 -8
- package/src/primitives/actionBar/useActionBarFloatStatus.ts +4 -1
- package/src/primitives/actionBarMore/ActionBarMoreRoot.tsx +52 -2
- package/src/tests/BaseComposerRuntimeCore.test.ts +2 -3
- package/src/tests/external-message-converter.test.ts +80 -0
- package/src/utils/createActionButton.tsx +1 -1
- package/src/utils/json/is-json-equal.ts +48 -0
- package/src/utils/json/is-json.ts +6 -3
|
@@ -1,83 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return "image";
|
|
4
|
-
if (contentType.startsWith("text/"))
|
|
5
|
-
return "document";
|
|
6
|
-
return "file";
|
|
7
|
-
};
|
|
8
|
-
export class CloudFileAttachmentAdapter {
|
|
9
|
-
cloud;
|
|
10
|
-
accept = "*";
|
|
11
|
-
constructor(cloud) {
|
|
12
|
-
this.cloud = cloud;
|
|
13
|
-
}
|
|
14
|
-
uploadedUrls = new Map();
|
|
15
|
-
async *add({ file, }) {
|
|
16
|
-
const id = crypto.randomUUID();
|
|
17
|
-
const type = guessAttachmentType(file.type);
|
|
18
|
-
let attachment = {
|
|
19
|
-
id,
|
|
20
|
-
type,
|
|
21
|
-
name: file.name,
|
|
22
|
-
contentType: file.type,
|
|
23
|
-
file,
|
|
24
|
-
status: { type: "running", reason: "uploading", progress: 0 },
|
|
25
|
-
};
|
|
26
|
-
yield attachment;
|
|
27
|
-
try {
|
|
28
|
-
const { signedUrl, publicUrl } = await this.cloud.files.generatePresignedUploadUrl({
|
|
29
|
-
filename: file.name,
|
|
30
|
-
});
|
|
31
|
-
await fetch(signedUrl, {
|
|
32
|
-
method: "PUT",
|
|
33
|
-
body: file,
|
|
34
|
-
headers: {
|
|
35
|
-
"Content-Type": file.type,
|
|
36
|
-
},
|
|
37
|
-
mode: "cors",
|
|
38
|
-
});
|
|
39
|
-
this.uploadedUrls.set(id, publicUrl);
|
|
40
|
-
attachment = {
|
|
41
|
-
...attachment,
|
|
42
|
-
status: { type: "requires-action", reason: "composer-send" },
|
|
43
|
-
};
|
|
44
|
-
yield attachment;
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
attachment = {
|
|
48
|
-
...attachment,
|
|
49
|
-
status: { type: "incomplete", reason: "error" },
|
|
50
|
-
};
|
|
51
|
-
yield attachment;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async remove(attachment) {
|
|
55
|
-
this.uploadedUrls.delete(attachment.id);
|
|
56
|
-
}
|
|
57
|
-
async send(attachment) {
|
|
58
|
-
const url = this.uploadedUrls.get(attachment.id);
|
|
59
|
-
if (!url)
|
|
60
|
-
throw new Error("Attachment not uploaded");
|
|
61
|
-
this.uploadedUrls.delete(attachment.id);
|
|
62
|
-
let content;
|
|
63
|
-
if (attachment.type === "image") {
|
|
64
|
-
content = [{ type: "image", image: url, filename: attachment.name }];
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
content = [
|
|
68
|
-
{
|
|
69
|
-
type: "file",
|
|
70
|
-
data: url,
|
|
71
|
-
mimeType: attachment.contentType ?? "",
|
|
72
|
-
filename: attachment.name,
|
|
73
|
-
},
|
|
74
|
-
];
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
...attachment,
|
|
78
|
-
status: { type: "complete" },
|
|
79
|
-
content,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
1
|
+
"use client";
|
|
2
|
+
export { CloudFileAttachmentAdapter } from "@assistant-ui/core/react";
|
|
83
3
|
//# sourceMappingURL=CloudFileAttachmentAdapter.js.map
|
package/dist/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudFileAttachmentAdapter.js","sourceRoot":"","sources":["../../../../../src/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CloudFileAttachmentAdapter.js","sourceRoot":"","sources":["../../../../../src/legacy-runtime/runtime-cores/adapters/attachment/CloudFileAttachmentAdapter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { AssistantTransportCommand, AssistantTransportState } from "./types.js";
|
|
3
|
-
type UseToolInvocationsParams = {
|
|
4
|
-
state: AssistantTransportState;
|
|
5
|
-
getTools: () => Record<string, Tool> | undefined;
|
|
6
|
-
onResult: (command: AssistantTransportCommand) => void;
|
|
7
|
-
setToolStatuses: (updater: Record<string, ToolExecutionStatus> | ((prev: Record<string, ToolExecutionStatus>) => Record<string, ToolExecutionStatus>)) => void;
|
|
8
|
-
};
|
|
9
|
-
export type ToolExecutionStatus = {
|
|
10
|
-
type: "executing";
|
|
11
|
-
} | {
|
|
12
|
-
type: "interrupt";
|
|
13
|
-
payload: {
|
|
14
|
-
type: "human";
|
|
15
|
-
payload: unknown;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export declare function useToolInvocations({ state, getTools, onResult, setToolStatuses, }: UseToolInvocationsParams): {
|
|
19
|
-
reset: () => void;
|
|
20
|
-
abort: () => Promise<void>;
|
|
21
|
-
resume: (toolCallId: string, payload: unknown) => void;
|
|
22
|
-
};
|
|
23
|
-
export {};
|
|
1
|
+
export { useToolInvocations, type ToolExecutionStatus, } from "@assistant-ui/core/react";
|
|
24
2
|
//# sourceMappingURL=useToolInvocations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToolInvocations.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useToolInvocations.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,KAAK,mBAAmB,GACzB,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,306 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { createAssistantStreamController, ToolResponse, unstable_toolResultStream, } from "assistant-stream";
|
|
3
|
-
import { AssistantMetaTransformStream, } from "assistant-stream/utils";
|
|
4
|
-
const isArgsTextComplete = (argsText) => {
|
|
5
|
-
try {
|
|
6
|
-
JSON.parse(argsText);
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
export function useToolInvocations({ state, getTools, onResult, setToolStatuses, }) {
|
|
14
|
-
const lastToolStates = useRef({});
|
|
15
|
-
const humanInputRef = useRef(new Map());
|
|
16
|
-
const acRef = useRef(new AbortController());
|
|
17
|
-
const executingCountRef = useRef(0);
|
|
18
|
-
const settledResolversRef = useRef([]);
|
|
19
|
-
const toolCallIdAliasesRef = useRef(new Map());
|
|
20
|
-
const ignoredResultToolCallIdsRef = useRef(new Set());
|
|
21
|
-
const rewriteCounterRef = useRef(0);
|
|
22
|
-
const getLogicalToolCallId = (toolCallId) => {
|
|
23
|
-
return toolCallIdAliasesRef.current.get(toolCallId) ?? toolCallId;
|
|
24
|
-
};
|
|
25
|
-
const shouldIgnoreAndCleanupResult = (toolCallId) => {
|
|
26
|
-
if (!ignoredResultToolCallIdsRef.current.has(toolCallId))
|
|
27
|
-
return false;
|
|
28
|
-
ignoredResultToolCallIdsRef.current.delete(toolCallId);
|
|
29
|
-
toolCallIdAliasesRef.current.delete(toolCallId);
|
|
30
|
-
return true;
|
|
31
|
-
};
|
|
32
|
-
const getWrappedTools = () => {
|
|
33
|
-
const tools = getTools();
|
|
34
|
-
if (!tools)
|
|
35
|
-
return undefined;
|
|
36
|
-
return Object.fromEntries(Object.entries(tools).map(([name, tool]) => {
|
|
37
|
-
const execute = tool.execute;
|
|
38
|
-
const streamCall = tool.streamCall;
|
|
39
|
-
const wrappedTool = {
|
|
40
|
-
...tool,
|
|
41
|
-
...(execute !== undefined && {
|
|
42
|
-
execute: (...[args, context]) => execute(args, {
|
|
43
|
-
...context,
|
|
44
|
-
toolCallId: getLogicalToolCallId(context.toolCallId),
|
|
45
|
-
}),
|
|
46
|
-
}),
|
|
47
|
-
...(streamCall !== undefined && {
|
|
48
|
-
streamCall: (...[reader, context]) => streamCall(reader, {
|
|
49
|
-
...context,
|
|
50
|
-
toolCallId: getLogicalToolCallId(context.toolCallId),
|
|
51
|
-
}),
|
|
52
|
-
}),
|
|
53
|
-
};
|
|
54
|
-
return [name, wrappedTool];
|
|
55
|
-
}));
|
|
56
|
-
};
|
|
57
|
-
const [controller] = useState(() => {
|
|
58
|
-
const [stream, controller] = createAssistantStreamController();
|
|
59
|
-
const transform = unstable_toolResultStream(getWrappedTools, () => acRef.current?.signal ?? new AbortController().signal, (toolCallId, payload) => {
|
|
60
|
-
const logicalToolCallId = getLogicalToolCallId(toolCallId);
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
// Reject previous human input request if it exists
|
|
63
|
-
const previous = humanInputRef.current.get(logicalToolCallId);
|
|
64
|
-
if (previous) {
|
|
65
|
-
previous.reject(new Error("Human input request was superseded by a new request"));
|
|
66
|
-
}
|
|
67
|
-
humanInputRef.current.set(logicalToolCallId, { resolve, reject });
|
|
68
|
-
setToolStatuses((prev) => ({
|
|
69
|
-
...prev,
|
|
70
|
-
[logicalToolCallId]: {
|
|
71
|
-
type: "interrupt",
|
|
72
|
-
payload: { type: "human", payload },
|
|
73
|
-
},
|
|
74
|
-
}));
|
|
75
|
-
});
|
|
76
|
-
}, {
|
|
77
|
-
onExecutionStart: (toolCallId) => {
|
|
78
|
-
if (ignoredResultToolCallIdsRef.current.has(toolCallId)) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const logicalToolCallId = getLogicalToolCallId(toolCallId);
|
|
82
|
-
executingCountRef.current++;
|
|
83
|
-
setToolStatuses((prev) => ({
|
|
84
|
-
...prev,
|
|
85
|
-
[logicalToolCallId]: { type: "executing" },
|
|
86
|
-
}));
|
|
87
|
-
},
|
|
88
|
-
onExecutionEnd: (toolCallId) => {
|
|
89
|
-
if (ignoredResultToolCallIdsRef.current.has(toolCallId)) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const logicalToolCallId = getLogicalToolCallId(toolCallId);
|
|
93
|
-
executingCountRef.current--;
|
|
94
|
-
setToolStatuses((prev) => {
|
|
95
|
-
const next = { ...prev };
|
|
96
|
-
delete next[logicalToolCallId];
|
|
97
|
-
return next;
|
|
98
|
-
});
|
|
99
|
-
// Resolve any waiting abort promises when all tools have settled
|
|
100
|
-
if (executingCountRef.current === 0) {
|
|
101
|
-
settledResolversRef.current.forEach((resolve) => resolve());
|
|
102
|
-
settledResolversRef.current = [];
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
stream
|
|
107
|
-
.pipeThrough(transform)
|
|
108
|
-
.pipeThrough(new AssistantMetaTransformStream())
|
|
109
|
-
.pipeTo(new WritableStream({
|
|
110
|
-
write(chunk) {
|
|
111
|
-
if (chunk.type === "result") {
|
|
112
|
-
if (shouldIgnoreAndCleanupResult(chunk.meta.toolCallId)) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const logicalToolCallId = getLogicalToolCallId(chunk.meta.toolCallId);
|
|
116
|
-
if (logicalToolCallId !== chunk.meta.toolCallId) {
|
|
117
|
-
toolCallIdAliasesRef.current.delete(chunk.meta.toolCallId);
|
|
118
|
-
}
|
|
119
|
-
// the tool call result was already set by the backend
|
|
120
|
-
if (lastToolStates.current[logicalToolCallId]?.hasResult)
|
|
121
|
-
return;
|
|
122
|
-
onResult({
|
|
123
|
-
type: "add-tool-result",
|
|
124
|
-
toolCallId: logicalToolCallId,
|
|
125
|
-
toolName: chunk.meta.toolName,
|
|
126
|
-
result: chunk.result,
|
|
127
|
-
isError: chunk.isError,
|
|
128
|
-
...(chunk.artifact && { artifact: chunk.artifact }),
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
}));
|
|
133
|
-
return controller;
|
|
134
|
-
});
|
|
135
|
-
const ignoredToolIds = useRef(new Set());
|
|
136
|
-
const isInitialState = useRef(true);
|
|
137
|
-
useEffect(() => {
|
|
138
|
-
const createToolState = ({ controller, streamToolCallId, }) => ({
|
|
139
|
-
argsText: "",
|
|
140
|
-
hasResult: false,
|
|
141
|
-
argsComplete: false,
|
|
142
|
-
streamToolCallId,
|
|
143
|
-
controller,
|
|
144
|
-
});
|
|
145
|
-
const setToolState = (toolCallId, state) => {
|
|
146
|
-
lastToolStates.current[toolCallId] = state;
|
|
147
|
-
return state;
|
|
148
|
-
};
|
|
149
|
-
const patchToolState = (toolCallId, state, patch) => {
|
|
150
|
-
return setToolState(toolCallId, { ...state, ...patch });
|
|
151
|
-
};
|
|
152
|
-
const processMessages = (messages) => {
|
|
153
|
-
messages.forEach((message) => {
|
|
154
|
-
message.content.forEach((content) => {
|
|
155
|
-
if (content.type === "tool-call") {
|
|
156
|
-
if (isInitialState.current) {
|
|
157
|
-
ignoredToolIds.current.add(content.toolCallId);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
if (ignoredToolIds.current.has(content.toolCallId)) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
let lastState = lastToolStates.current[content.toolCallId];
|
|
164
|
-
if (!lastState) {
|
|
165
|
-
toolCallIdAliasesRef.current.set(content.toolCallId, content.toolCallId);
|
|
166
|
-
const toolCallController = controller.addToolCallPart({
|
|
167
|
-
toolName: content.toolName,
|
|
168
|
-
toolCallId: content.toolCallId,
|
|
169
|
-
});
|
|
170
|
-
lastState = setToolState(content.toolCallId, createToolState({
|
|
171
|
-
controller: toolCallController,
|
|
172
|
-
streamToolCallId: content.toolCallId,
|
|
173
|
-
}));
|
|
174
|
-
}
|
|
175
|
-
if (content.argsText !== lastState.argsText) {
|
|
176
|
-
if (lastState.argsComplete) {
|
|
177
|
-
if (process.env.NODE_ENV !== "production") {
|
|
178
|
-
console.warn("argsText updated after controller was closed:", {
|
|
179
|
-
previous: lastState.argsText,
|
|
180
|
-
next: content.argsText,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
if (!content.argsText.startsWith(lastState.argsText)) {
|
|
186
|
-
// Check if this is key reordering (both are complete JSON)
|
|
187
|
-
// This happens when transitioning from streaming to complete state
|
|
188
|
-
// and the provider returns keys in a different order
|
|
189
|
-
if (isArgsTextComplete(lastState.argsText) &&
|
|
190
|
-
isArgsTextComplete(content.argsText)) {
|
|
191
|
-
lastState.controller.argsText.close();
|
|
192
|
-
patchToolState(content.toolCallId, lastState, {
|
|
193
|
-
argsText: content.argsText,
|
|
194
|
-
argsComplete: true,
|
|
195
|
-
});
|
|
196
|
-
return; // Continue to next content part
|
|
197
|
-
}
|
|
198
|
-
if (process.env.NODE_ENV !== "production") {
|
|
199
|
-
console.warn("argsText rewrote previous snapshot, restarting tool args stream:", {
|
|
200
|
-
previous: lastState.argsText,
|
|
201
|
-
next: content.argsText,
|
|
202
|
-
toolCallId: content.toolCallId,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
ignoredResultToolCallIdsRef.current.add(lastState.streamToolCallId);
|
|
206
|
-
lastState.controller.argsText.close();
|
|
207
|
-
const streamToolCallId = `${content.toolCallId}:rewrite:${rewriteCounterRef.current++}`;
|
|
208
|
-
toolCallIdAliasesRef.current.set(streamToolCallId, content.toolCallId);
|
|
209
|
-
const toolCallController = controller.addToolCallPart({
|
|
210
|
-
toolName: content.toolName,
|
|
211
|
-
toolCallId: streamToolCallId,
|
|
212
|
-
});
|
|
213
|
-
if (process.env.NODE_ENV !== "production") {
|
|
214
|
-
console.warn("started replacement stream tool call", {
|
|
215
|
-
toolCallId: content.toolCallId,
|
|
216
|
-
streamToolCallId,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
lastState = setToolState(content.toolCallId, {
|
|
220
|
-
...createToolState({
|
|
221
|
-
controller: toolCallController,
|
|
222
|
-
streamToolCallId,
|
|
223
|
-
}),
|
|
224
|
-
hasResult: lastState.hasResult,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
const argsTextDelta = content.argsText.slice(lastState.argsText.length);
|
|
228
|
-
lastState.controller.argsText.append(argsTextDelta);
|
|
229
|
-
const shouldClose = isArgsTextComplete(content.argsText);
|
|
230
|
-
if (shouldClose) {
|
|
231
|
-
lastState.controller.argsText.close();
|
|
232
|
-
}
|
|
233
|
-
patchToolState(content.toolCallId, lastState, {
|
|
234
|
-
argsText: content.argsText,
|
|
235
|
-
argsComplete: shouldClose,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (content.result !== undefined && !lastState.hasResult) {
|
|
240
|
-
patchToolState(content.toolCallId, lastState, {
|
|
241
|
-
hasResult: true,
|
|
242
|
-
argsComplete: true,
|
|
243
|
-
});
|
|
244
|
-
lastState.controller.setResponse(new ToolResponse({
|
|
245
|
-
result: content.result,
|
|
246
|
-
artifact: content.artifact,
|
|
247
|
-
isError: content.isError,
|
|
248
|
-
}));
|
|
249
|
-
lastState.controller.close();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
// Recursively process nested messages
|
|
253
|
-
if (content.messages) {
|
|
254
|
-
processMessages(content.messages);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
};
|
|
260
|
-
processMessages(state.messages);
|
|
261
|
-
if (isInitialState.current) {
|
|
262
|
-
isInitialState.current = false;
|
|
263
|
-
}
|
|
264
|
-
}, [state, controller]);
|
|
265
|
-
const abort = () => {
|
|
266
|
-
humanInputRef.current.forEach(({ reject }) => {
|
|
267
|
-
reject(new Error("Tool execution aborted"));
|
|
268
|
-
});
|
|
269
|
-
humanInputRef.current.clear();
|
|
270
|
-
acRef.current.abort();
|
|
271
|
-
acRef.current = new AbortController();
|
|
272
|
-
// Return a promise that resolves when all executing tools have settled
|
|
273
|
-
if (executingCountRef.current === 0) {
|
|
274
|
-
return Promise.resolve();
|
|
275
|
-
}
|
|
276
|
-
return new Promise((resolve) => {
|
|
277
|
-
settledResolversRef.current.push(resolve);
|
|
278
|
-
});
|
|
279
|
-
};
|
|
280
|
-
return {
|
|
281
|
-
reset: () => {
|
|
282
|
-
isInitialState.current = true;
|
|
283
|
-
void abort().finally(() => {
|
|
284
|
-
toolCallIdAliasesRef.current.clear();
|
|
285
|
-
ignoredResultToolCallIdsRef.current.clear();
|
|
286
|
-
rewriteCounterRef.current = 0;
|
|
287
|
-
});
|
|
288
|
-
},
|
|
289
|
-
abort,
|
|
290
|
-
resume: (toolCallId, payload) => {
|
|
291
|
-
const handlers = humanInputRef.current.get(toolCallId);
|
|
292
|
-
if (handlers) {
|
|
293
|
-
humanInputRef.current.delete(toolCallId);
|
|
294
|
-
setToolStatuses((prev) => ({
|
|
295
|
-
...prev,
|
|
296
|
-
[toolCallId]: { type: "executing" },
|
|
297
|
-
}));
|
|
298
|
-
handlers.resolve(payload);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
throw new Error(`Tool call ${toolCallId} is not waiting for human input`);
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
};
|
|
305
|
-
}
|
|
1
|
+
export { useToolInvocations, } from "@assistant-ui/core/react";
|
|
306
2
|
//# sourceMappingURL=useToolInvocations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useToolInvocations.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,+BAA+B,EAE/B,YAAY,EACZ,yBAAyB,GAE1B,MAAM,kBAAkB,CAAC;AAK1B,OAAO,EACL,4BAA4B,GAE7B,MAAM,wBAAwB,CAAC;AAEhC,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAE,EAAE;IAC9C,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC;AA2BF,MAA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,OAAO,GAAG,IAAI,CAAC;YAC9B,KAAK,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;gBACxB,oBAAoB,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;gBACrC,2BAA2B,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC5C,iBAAiB,CAAC,OAAO,GAAG,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC;QACD,KAAK;QACL,MAAM,EAAE,CAAC,UAAkB,EAAE,OAAgB,EAAE,EAAE;YAC/C,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACvD,IAAI,QAAQ,EAAE,CAAC;gBACb,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACzC,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;oBACzB,GAAG,IAAI;oBACP,CAAC,UAAU,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;iBACpC,CAAC,CAAC,CAAC;gBACJ,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,aAAa,UAAU,iCAAiC,CACzD,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"useToolInvocations.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAEnB,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { ThreadState } from "../../runtime/index.js";
|
|
3
|
-
import { useExternalMessageConverter } from "./external-message-converter.js";
|
|
4
|
-
export declare const createMessageConverter: <T extends object>(callback: useExternalMessageConverter.Callback<T>) => {
|
|
5
|
-
useThreadMessages: ({ messages, isRunning, joinStrategy, metadata, }: {
|
|
6
|
-
messages: T[];
|
|
7
|
-
isRunning: boolean;
|
|
8
|
-
joinStrategy?: "concat-content" | "none" | undefined;
|
|
9
|
-
metadata?: useExternalMessageConverter.Metadata;
|
|
10
|
-
}) => ThreadMessage[];
|
|
11
|
-
toThreadMessages: (messages: T[], isRunning?: boolean, metadata?: useExternalMessageConverter.Metadata) => ThreadMessage[];
|
|
12
|
-
toOriginalMessages: (input: ThreadState | ThreadMessage | ThreadMessage["content"][number]) => unknown[];
|
|
13
|
-
toOriginalMessage: (input: ThreadState | ThreadMessage | ThreadMessage["content"][number]) => {};
|
|
14
|
-
useOriginalMessage: () => {};
|
|
15
|
-
useOriginalMessages: () => unknown[];
|
|
16
|
-
};
|
|
1
|
+
export { createMessageConverter } from "@assistant-ui/core/react";
|
|
17
2
|
//# sourceMappingURL=createMessageConverter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMessageConverter.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/createMessageConverter.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"createMessageConverter.d.ts","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/createMessageConverter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,50 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import { useExternalMessageConverter, convertExternalMessages, } from "./external-message-converter.js";
|
|
4
|
-
import { getExternalStoreMessages } from "./getExternalStoreMessage.js";
|
|
5
|
-
export const createMessageConverter = (callback) => {
|
|
6
|
-
const result = {
|
|
7
|
-
useThreadMessages: ({ messages, isRunning, joinStrategy, metadata, }) => {
|
|
8
|
-
return useExternalMessageConverter({
|
|
9
|
-
callback,
|
|
10
|
-
messages,
|
|
11
|
-
isRunning,
|
|
12
|
-
joinStrategy,
|
|
13
|
-
metadata,
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
toThreadMessages: (messages, isRunning = false, metadata = {}) => {
|
|
17
|
-
return convertExternalMessages(messages, callback, isRunning, metadata);
|
|
18
|
-
},
|
|
19
|
-
toOriginalMessages: (input) => {
|
|
20
|
-
const messages = getExternalStoreMessages(input);
|
|
21
|
-
if (messages.length === 0)
|
|
22
|
-
throw new Error("No original messages found");
|
|
23
|
-
return messages;
|
|
24
|
-
},
|
|
25
|
-
toOriginalMessage: (input) => {
|
|
26
|
-
const messages = result.toOriginalMessages(input);
|
|
27
|
-
return messages[0];
|
|
28
|
-
},
|
|
29
|
-
useOriginalMessage: () => {
|
|
30
|
-
const messageMessages = result.useOriginalMessages();
|
|
31
|
-
const first = messageMessages[0];
|
|
32
|
-
return first;
|
|
33
|
-
},
|
|
34
|
-
useOriginalMessages: () => {
|
|
35
|
-
const aui = useAui();
|
|
36
|
-
const partMessages = useAuiState((s) => {
|
|
37
|
-
if (aui.part.source)
|
|
38
|
-
return getExternalStoreMessages(s.part);
|
|
39
|
-
return undefined;
|
|
40
|
-
});
|
|
41
|
-
const messageMessages = useAuiState((s) => getExternalStoreMessages(s.message));
|
|
42
|
-
const messages = partMessages ?? messageMessages;
|
|
43
|
-
if (messages.length === 0)
|
|
44
|
-
throw new Error("No original messages found");
|
|
45
|
-
return messages;
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
return result;
|
|
49
|
-
};
|
|
2
|
+
export { createMessageConverter } from "@assistant-ui/core/react";
|
|
50
3
|
//# sourceMappingURL=createMessageConverter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMessageConverter.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/createMessageConverter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"createMessageConverter.js","sourceRoot":"","sources":["../../../../src/legacy-runtime/runtime-cores/external-store/createMessageConverter.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -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"}
|