@assistant-ui/react 0.11.39 → 0.11.41
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/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +8 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +23 -11
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/primitives/messagePart/useMessagePartData.d.ts.map +1 -1
- package/dist/primitives/messagePart/useMessagePartData.js.map +1 -1
- package/dist/tests/setup.js +14 -14
- package/dist/tests/setup.js.map +1 -1
- package/package.json +5 -5
- package/src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts +2 -2
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +8 -1
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +26 -11
- package/src/primitives/messagePart/useMessagePartData.tsx +0 -1
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"conversational-ui",
|
|
29
29
|
"conversational-ai"
|
|
30
30
|
],
|
|
31
|
-
"version": "0.11.
|
|
31
|
+
"version": "0.11.41",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"type": "module",
|
|
34
34
|
"exports": {
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
],
|
|
49
49
|
"sideEffects": false,
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"assistant-cloud": "^0.1.
|
|
52
|
-
"@assistant-ui/tap": "^0.2.
|
|
51
|
+
"assistant-cloud": "^0.1.8",
|
|
52
|
+
"@assistant-ui/tap": "^0.2.2",
|
|
53
53
|
"@radix-ui/primitive": "^1.1.3",
|
|
54
54
|
"@radix-ui/react-compose-refs": "^1.1.2",
|
|
55
55
|
"@radix-ui/react-context": "^1.1.3",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@radix-ui/react-use-callback-ref": "^1.1.1",
|
|
60
60
|
"@radix-ui/react-use-escape-keydown": "^1.1.1",
|
|
61
61
|
"@standard-schema/spec": "^1.0.0",
|
|
62
|
-
"assistant-stream": "^0.2.
|
|
62
|
+
"assistant-stream": "^0.2.41",
|
|
63
63
|
"json-schema": "^0.4.0",
|
|
64
64
|
"nanoid": "5.1.6",
|
|
65
65
|
"react-textarea-autosize": "^8.5.9",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"eslint": "^9",
|
|
89
89
|
"eslint-config-next": "16.0.3",
|
|
90
90
|
"tsx": "^4.20.6",
|
|
91
|
-
"vitest": "^4.0.
|
|
91
|
+
"vitest": "^4.0.10",
|
|
92
92
|
"@assistant-ui/x-buildutils": "0.0.1"
|
|
93
93
|
},
|
|
94
94
|
"publishConfig": {
|
|
@@ -11,7 +11,7 @@ export function useRunManager(config: {
|
|
|
11
11
|
onRun: (signal: AbortSignal) => Promise<void>;
|
|
12
12
|
onFinish?: (() => void) | undefined;
|
|
13
13
|
onCancel?: (() => void) | undefined;
|
|
14
|
-
onError?: ((error: Error) => void) | undefined;
|
|
14
|
+
onError?: ((error: Error) => void | Promise<void>) | undefined;
|
|
15
15
|
}): RunManager {
|
|
16
16
|
const [isRunning, setIsRunning] = useState(false);
|
|
17
17
|
const stateRef = useRef({
|
|
@@ -37,7 +37,7 @@ export function useRunManager(config: {
|
|
|
37
37
|
if (ac.signal.aborted) {
|
|
38
38
|
onCancelRef.current?.();
|
|
39
39
|
} else {
|
|
40
|
-
onErrorRef.current?.(error as Error);
|
|
40
|
+
await onErrorRef.current?.(error as Error);
|
|
41
41
|
}
|
|
42
42
|
} finally {
|
|
43
43
|
onFinishRef.current?.();
|
|
@@ -97,10 +97,17 @@ export type AssistantTransportOptions<T> = {
|
|
|
97
97
|
commands: AssistantTransportCommand[];
|
|
98
98
|
updateState: (updater: (state: T) => T) => void;
|
|
99
99
|
},
|
|
100
|
-
) => void
|
|
100
|
+
) => void | Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Called when commands are cancelled.
|
|
103
|
+
*
|
|
104
|
+
* When an error occurs, queued commands are automatically cancelled after `onError` settles.
|
|
105
|
+
* In this case, the `error` parameter contains the error that caused the cancellation.
|
|
106
|
+
*/
|
|
101
107
|
onCancel?: (params: {
|
|
102
108
|
commands: AssistantTransportCommand[];
|
|
103
109
|
updateState: (updater: (state: T) => T) => void;
|
|
110
|
+
error?: Error;
|
|
104
111
|
}) => void;
|
|
105
112
|
adapters?: {
|
|
106
113
|
attachments?: AttachmentAdapter | undefined;
|
package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx
CHANGED
|
@@ -174,6 +174,9 @@ const useAssistantTransportThreadRuntime = <T,>(
|
|
|
174
174
|
...commandQueue.state.inTransit,
|
|
175
175
|
...commandQueue.state.queued,
|
|
176
176
|
];
|
|
177
|
+
|
|
178
|
+
commandQueue.reset();
|
|
179
|
+
|
|
177
180
|
options.onCancel?.({
|
|
178
181
|
commands: cmds,
|
|
179
182
|
updateState: (updater) => {
|
|
@@ -181,19 +184,31 @@ const useAssistantTransportThreadRuntime = <T,>(
|
|
|
181
184
|
rerender((prev) => prev + 1);
|
|
182
185
|
},
|
|
183
186
|
});
|
|
187
|
+
},
|
|
188
|
+
onError: async (error) => {
|
|
189
|
+
const inTransitCmds = [...commandQueue.state.inTransit];
|
|
190
|
+
const queuedCmds = [...commandQueue.state.queued];
|
|
184
191
|
|
|
185
192
|
commandQueue.reset();
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
await options.onError?.(error as Error, {
|
|
196
|
+
commands: inTransitCmds,
|
|
197
|
+
updateState: (updater) => {
|
|
198
|
+
agentStateRef.current = updater(agentStateRef.current);
|
|
199
|
+
rerender((prev) => prev + 1);
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
} finally {
|
|
203
|
+
options.onCancel?.({
|
|
204
|
+
commands: queuedCmds,
|
|
205
|
+
updateState: (updater) => {
|
|
206
|
+
agentStateRef.current = updater(agentStateRef.current);
|
|
207
|
+
rerender((prev) => prev + 1);
|
|
208
|
+
},
|
|
209
|
+
error: error as Error,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
197
212
|
},
|
|
198
213
|
});
|
|
199
214
|
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import { useAssistantState } from "../../context";
|
|
4
4
|
import { DataMessagePart } from "../../types";
|
|
5
5
|
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7
6
|
export const useMessagePartData = <T = any,>(name?: string) => {
|
|
8
7
|
const part = useAssistantState(({ part }) => {
|
|
9
8
|
if (part.type !== "data") {
|