@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/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "conversational-ui",
29
29
  "conversational-ai"
30
30
  ],
31
- "version": "0.11.39",
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.7",
52
- "@assistant-ui/tap": "^0.2.1",
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.39",
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.8",
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;
@@ -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
- onError: (error) => {
188
- const cmds = [...commandQueue.state.inTransit];
189
- options.onError?.(error as Error, {
190
- commands: cmds,
191
- updateState: (updater) => {
192
- agentStateRef.current = updater(agentStateRef.current);
193
- rerender((prev) => prev + 1);
194
- },
195
- });
196
- commandQueue.markDelivered();
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") {