@assistant-ui/react-statewire 0.2.0 → 0.4.0

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/types.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Assistant } from "@assistant-ui/react";
2
2
  import { AttachmentAdapter, LanguageModelConfig, LanguageModelV1CallSettings, ThreadMessage, ToolExecutionStatus } from "@assistant-ui/core";
3
- import { ToolModelContentPart } from "assistant-stream";
4
3
  import { ReadonlyJSONValue } from "assistant-stream/utils";
5
4
  //#region src/types.d.ts
6
5
  type UserCommands = Assistant.Commands[keyof Assistant.Commands];
@@ -9,45 +8,124 @@ type TextPart = {
9
8
  readonly type: "text";
10
9
  readonly text: string;
11
10
  };
12
- type ImagePart = {
13
- readonly type: "image";
14
- readonly image: string;
11
+ type FilePart = {
12
+ readonly type: "file";
13
+ readonly mediaType: string;
14
+ readonly url: string;
15
+ readonly filename?: string;
15
16
  };
16
- type UserMessagePart = TextPart | ImagePart;
17
- type UserMessage = {
17
+ type RunUserMessage = {
18
+ readonly id: string;
18
19
  readonly role: "user";
19
- readonly parts: readonly UserMessagePart[];
20
+ readonly parts: readonly (TextPart | FilePart)[];
21
+ readonly metadata?: Record<string, unknown>;
20
22
  };
21
- type AssistantMessage = {
22
- readonly role: "assistant";
23
- readonly parts: readonly TextPart[];
23
+ /** Queue placement fields, flat on the command. Absent is load-bearing: it means default placement; `null` names a queue boundary. */
24
+ type RunPlacement = {
25
+ readonly insertAfter?: string | null;
26
+ readonly insertBefore?: string | null;
24
27
  };
25
- type MessageAddCommand = {
26
- readonly type: "message/add";
27
- readonly message: UserMessage | AssistantMessage;
28
- readonly parentId: string | null;
29
- readonly sourceId: string | null;
30
- /**
31
- * How the host handles the message while a run is active: `"queue"`
32
- * appends to the queue, `"steer"` moves it to the front and interrupts
33
- * the run. Absent, the host decides. Ignored when the host is idle.
34
- */
35
- readonly behavior?: "queue" | "steer";
28
+ type RunEnqueueCommand = {
29
+ readonly type: "run/enqueue";
30
+ } & ({
31
+ readonly message: RunUserMessage;
32
+ /** Branch anchor: the newest message the client knows on its intended branch, null asserting an empty thread. Required on adds; optional on edits of queued items. */
33
+ readonly anchorMessageId?: string | null;
34
+ } | {
35
+ readonly messageId: string;
36
+ }) & RunPlacement;
37
+ type RunSteerCommand = {
38
+ readonly type: "run/steer";
39
+ } & ({
40
+ readonly message: RunUserMessage;
41
+ /** Branch anchor: the newest message the client knows on its intended branch, null asserting an empty thread. Required on adds; optional on edits of queued items. */
42
+ readonly anchorMessageId?: string | null;
43
+ } | {
44
+ readonly messageId: string;
45
+ }) & RunPlacement;
46
+ type RunDequeueCommand = {
47
+ readonly type: "run/dequeue";
48
+ readonly messageId: string;
49
+ };
50
+ type RunEditCommand = {
51
+ readonly type: "run/edit";
52
+ readonly message: RunUserMessage;
53
+ readonly sourceId: string;
36
54
  };
37
- type ToolResultAddCommand = {
38
- readonly type: "tool-result/add";
55
+ type RunContinueCommand = {
56
+ readonly type: "run/continue";
57
+ };
58
+ type ToolCallInputRequest = {
59
+ readonly type: "tool-call";
60
+ readonly id: string;
39
61
  readonly toolCallId: string;
40
- readonly toolName: string;
41
- readonly result: ReadonlyJSONValue;
42
- readonly isError: boolean;
62
+ };
63
+ type ToolApprovalInputRequest = {
64
+ readonly type: "tool-approval";
65
+ readonly id: string;
66
+ readonly toolCallId: string;
67
+ };
68
+ type CustomInputRequest = {
69
+ readonly type: string;
70
+ readonly id: string;
71
+ readonly [key: string]: ReadonlyJSONValue | undefined;
72
+ };
73
+ /** A host request parking the run until answered; open union for custom types. */
74
+ type InputRequest = ToolCallInputRequest | ToolApprovalInputRequest | CustomInputRequest;
75
+ type ToolCallInputResponse = {
76
+ readonly output: ReadonlyJSONValue;
77
+ /** Default false; when true, `output` carries the error payload. */
78
+ readonly isError?: boolean;
43
79
  readonly artifact?: ReadonlyJSONValue;
44
- readonly modelContent?: readonly ToolModelContentPart[];
45
80
  };
46
- type AssistantTransportCommand = MessageAddCommand | ToolResultAddCommand | UserCommands;
81
+ type ToolApprovalInputResponse = {
82
+ readonly decision: "approve" | "reject" | "edit" | "respond";
83
+ readonly editedArgs?: ReadonlyJSONValue;
84
+ readonly message?: string;
85
+ };
86
+ type InputResponse = ReadonlyJSONValue;
87
+ type RunInputCommand = {
88
+ readonly type: "run/input";
89
+ readonly requestId: string;
90
+ readonly response: InputResponse;
91
+ };
92
+ /** An input request projected out of the host state with its response echo. */
93
+ type InputRequestState = InputRequest & {
94
+ readonly response: InputResponse | null;
95
+ };
96
+ type RunReloadCommand = {
97
+ readonly type: "run/reload";
98
+ readonly sourceId: string;
99
+ /** Client-generated id of the regenerated assistant message. */
100
+ readonly messageId: string;
101
+ };
102
+ type RunCommand = RunEnqueueCommand | RunSteerCommand | RunDequeueCommand | RunEditCommand | RunContinueCommand | RunReloadCommand | RunInputCommand;
103
+ type AssistantTransportCommand = RunCommand | UserCommands;
104
+ /** A queued message projected out of the host state, wire shape. */
105
+ type RunQueueItem = {
106
+ readonly id: string;
107
+ readonly parts: readonly (TextPart | FilePart)[];
108
+ };
47
109
  type AssistantTransportState = {
48
110
  readonly messages: readonly ThreadMessage[];
49
111
  readonly state?: ReadonlyJSONValue;
50
112
  readonly isRunning: boolean;
113
+ /**
114
+ * The host's regular queue lane projected out of the state. Returning it
115
+ * (even empty) turns on the server-side queue: sends become `run/enqueue`
116
+ * / `run/steer` commands and item controls send the `run/*` queue
117
+ * commands. Presence must be stable across conversions and excludes the
118
+ * client-local `capabilities.queue` buffer.
119
+ */
120
+ readonly queue?: readonly RunQueueItem[];
121
+ /** The host's steer lane; requires `queue`. Absent means empty. */
122
+ readonly steerQueue?: readonly RunQueueItem[];
123
+ /**
124
+ * The host's parked input requests projected out of the state. Returning it
125
+ * (even empty) routes tool results and approvals with a matching pending
126
+ * request through `run/input`. Presence must be stable across conversions.
127
+ */
128
+ readonly inputRequests?: readonly InputRequestState[];
51
129
  };
52
130
  type AssistantTransportConnectionMetadata = {
53
131
  pendingCommands: AssistantTransportCommand[];
@@ -98,13 +176,16 @@ type AssistantTransportOptions<T> = {
98
176
  /**
99
177
  * Buffer messages sent during a run in an in-memory queue and dispatch
100
178
  * them once the run settles. Steering interrupts the active run.
179
+ * Mutually exclusive with the converter's `queue` projection.
101
180
  */
102
181
  queue?: boolean | undefined;
182
+ /** The host supports `run/continue` (a continue affordance on aborted runs). */
183
+ continue?: boolean | undefined;
103
184
  } | undefined;
104
185
  adapters?: {
105
186
  attachments?: AttachmentAdapter | undefined;
106
187
  } | undefined;
107
188
  };
108
189
  //#endregion
109
- export { AssistantMessage, AssistantTransportCommand, AssistantTransportConnectionMetadata, AssistantTransportOptions, AssistantTransportProtocol, AssistantTransportState, AssistantTransportStateConverter, HeadersValue, ImagePart, MessageAddCommand, SendCommandsRequestBody, TextPart, ToolResultAddCommand, UserCommands, UserExternalState, UserMessage, UserMessagePart };
190
+ export { AssistantTransportCommand, AssistantTransportConnectionMetadata, AssistantTransportOptions, AssistantTransportProtocol, AssistantTransportState, AssistantTransportStateConverter, CustomInputRequest, FilePart, HeadersValue, InputRequest, InputRequestState, InputResponse, RunCommand, RunContinueCommand, RunDequeueCommand, RunEditCommand, RunEnqueueCommand, RunInputCommand, RunPlacement, RunQueueItem, RunReloadCommand, RunSteerCommand, RunUserMessage, SendCommandsRequestBody, TextPart, ToolApprovalInputRequest, ToolApprovalInputResponse, ToolCallInputRequest, ToolCallInputResponse, UserCommands, UserExternalState };
110
191
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;KAWY,eAAe,UAAU,eAAe,UAAU;KAClD,0BAA0B,UAAU,8BAC5C,0BACA,UAAU,oBAAoB,UAAU;KAEhC;WACD;WACA;;KAGC;WACD;WACA;;KAGC,kBAAkB,WAAW;KAE7B;WACD;WACA,gBAAgB;;KAGf;WACD;WACA,gBAAgB;;KAGf;WACD;WACA,SAAS,cAAc;WACvB;WACA;;;;;;WAMA;;KAGC;WACD;WACA;WACA;WACA,QAAQ;WACR;WACA,WAAW;WACX,wBAAwB;;KAGvB,4BACR,oBACA,uBACA;KAEQ;WACD,mBAAmB;WACnB,QAAQ;WACR;;KAGC;EACV,iBAAiB;EACjB;EACA,cAAc,eAAe;;KAGnB,iCAAiC,MAC3C,OAAO,GACP,oBAAoB,yCACjB;KAEO,eAAe,yBAAyB;KAExC;KAEA;EACV,UAAU;EACV;EACA;EACA,OAAO;EACP,cAAc;EACd,QAAQ;EACR;EACA;GACC;;KAGS,0BAA0B;EACpC,cAAc;EACd,WAAW,iCAAiC;EAC5C;EACA;EACA,WAAW;EACX,SAAS,sBAAsB,QAAQ;EACvC,uBAAuB;;EAEvB,+BAEM,MAAM,4BACH,0BAA0B,QAAQ;EAE3C,eAAe,UAAU;EACzB;EACA,YAEM,OAAO,OACP;IACE,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;eAE7B;;;;;EAMhB,aACM;IACA,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;IACrC,QAAQ;;EAGd;IAEM;;;;;IAKA;;EAGN;IAEM,cAAc"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;KAUY,eAAe,UAAU,eAAe,UAAU;KAClD,0BAA0B,UAAU,8BAC5C,0BACA,UAAU,oBAAoB,UAAU;KAEhC;WACD;WACA;;KAGC;WACD;WACA;WACA;WACA;;KAGC;WACD;WACA;WACA,iBAAiB,WAAW;WAC5B,WAAW;;;KAIV;WACD;WACA;;KAGC;WACD;;WAGI,SAAS;;WAET;;WAEA;KAEb;KAEU;WACD;;WAGI,SAAS;;WAET;;WAEA;KAEb;KAEU;WACD;WACA;;KAGC;WACD;WACA,SAAS;WACT;;KAGC;WACD;;KAGC;WACD;WACA;WACA;;KAGC;WACD;WACA;WACA;;KAGC;WACD;WACA;YACC,cAAc;;;KAId,eACR,uBACA,2BACA;KAEQ;WACD,QAAQ;;WAER;WACA,WAAW;;KAGV;WACD;WACA,aAAa;WACb;;KAGC,gBAAgB;KAEhB;WACD;WACA;WACA,UAAU;;;KAIT,oBAAoB;WACrB,UAAU;;KAGT;WACD;WACA;;WAEA;;KAGC,aACR,oBACA,kBACA,oBACA,iBACA,qBACA,mBACA;KAEQ,4BAA4B,aAAa;;KAGzC;WACD;WACA,iBAAiB,WAAW;;KAG3B;WACD,mBAAmB;WACnB,QAAQ;WACR;;;;;;;;WAQA,iBAAiB;;WAEjB,sBAAsB;;;;;;WAMtB,yBAAyB;;KAGxB;EACV,iBAAiB;EACjB;EACA,cAAc,eAAe;;KAGnB,iCAAiC,MAC3C,OAAO,GACP,oBAAoB,yCACjB;KAEO,eAAe,yBAAyB;KAExC;KAEA;EACV,UAAU;EACV;EACA;EACA,OAAO;EACP,cAAc;EACd,QAAQ;EACR;EACA;GACC;;KAGS,0BAA0B;EACpC,cAAc;EACd,WAAW,iCAAiC;EAC5C;EACA;EACA,WAAW;EACX,SAAS,sBAAsB,QAAQ;EACvC,uBAAuB;;EAEvB,+BAEM,MAAM,4BACH,0BAA0B,QAAQ;EAE3C,eAAe,UAAU;EACzB;EACA,YAEM,OAAO,OACP;IACE,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;eAE7B;;;;;EAMhB,aACM;IACA,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;IACrC,QAAQ;;EAGd;IAEM;;;;;;IAMA;;IAEA;;EAGN;IAEM,cAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/react-statewire",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "assistant-ui thread binding for statewire backends",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,12 +21,12 @@ import type {
21
21
  AppendMessage,
22
22
  MessageQueueController,
23
23
  MessageQueueDriver,
24
+ RespondToToolApprovalOptions,
24
25
  ResumeToolCallOptions,
25
26
  ThreadMessage,
26
27
  ToolExecutionStatus,
27
28
  } from "@assistant-ui/core";
28
29
  import { ToolInvocationTracker } from "@assistant-ui/core/internal";
29
- import type { ReadonlyJSONObject } from "assistant-stream/utils";
30
30
  import { useStatewire } from "statewire";
31
31
  import { AssistantTransportHost } from "./host";
32
32
  import type {
@@ -36,12 +36,20 @@ import type {
36
36
  HostRunContext,
37
37
  SendOptions,
38
38
  } from "./host";
39
+ import {
40
+ createRunQueueAdapter,
41
+ resolveReloadCommand,
42
+ toWireMessage,
43
+ viewedLeafId,
44
+ } from "./runCommands";
45
+ import {
46
+ resolveToolApprovalInput,
47
+ resolveToolResultInput,
48
+ } from "./inputRequests";
39
49
  import type {
40
- MessageAddCommand,
41
- ToolResultAddCommand,
42
50
  AssistantTransportCommand,
43
51
  AssistantTransportOptions,
44
- UserMessagePart,
52
+ InputRequestState,
45
53
  } from "./types";
46
54
 
47
55
  const EMPTY_TOOL_STATUSES: Record<string, ToolExecutionStatus> = {};
@@ -57,6 +65,8 @@ export type AssistantTransportExtras = {
57
65
  sendCommand: (command: AssistantTransportCommand) => void;
58
66
  reconnect: () => void;
59
67
  state: unknown;
68
+ /** The host's parked input requests; absent when the converter does not project them. */
69
+ inputRequests?: readonly InputRequestState[];
60
70
  };
61
71
 
62
72
  export const asAssistantTransportExtras = (
@@ -74,38 +84,6 @@ export const asAssistantTransportExtras = (
74
84
  return extras as AssistantTransportExtras;
75
85
  };
76
86
 
77
- export const convertAppendMessageToCommand = (
78
- message: AppendMessage,
79
- ): MessageAddCommand | null => {
80
- if (message.role !== "user")
81
- throw new Error("Only user messages are supported");
82
-
83
- const parts: UserMessagePart[] = [];
84
- const content = [
85
- ...message.content,
86
- ...(message.attachments?.flatMap((a) => a.content) ?? []),
87
- ];
88
- for (const contentPart of content) {
89
- if (contentPart.type === "text") {
90
- parts.push({ type: "text", text: contentPart.text });
91
- } else if (contentPart.type === "image") {
92
- parts.push({ type: "image", image: contentPart.image });
93
- }
94
- }
95
-
96
- if (parts.length === 0) return null;
97
-
98
- return {
99
- type: "message/add",
100
- message: {
101
- role: "user",
102
- parts,
103
- },
104
- parentId: message.parentId,
105
- sourceId: message.sourceId,
106
- };
107
- };
108
-
109
87
  const messagesContainToolCall = (
110
88
  messages: readonly ThreadMessage[],
111
89
  toolCallId: string,
@@ -184,7 +162,12 @@ const useAssistantTransportThread = (
184
162
  const messages = convertedRef.current
185
163
  .messages as readonly ThreadMessage[];
186
164
  if (!messagesContainToolCall(messages, command.toolCallId)) return;
187
- dispatch({ ...command, type: "tool-result/add" });
165
+ dispatch(
166
+ resolveToolResultInput(
167
+ convertedRef.current.inputRequests ?? [],
168
+ command,
169
+ ),
170
+ );
188
171
  },
189
172
  onStatusesChange: (statuses) => {
190
173
  setToolStatuses(
@@ -211,25 +194,38 @@ const useAssistantTransportThread = (
211
194
  [toolInvocations],
212
195
  );
213
196
 
197
+ const inputRequests = converted.inputRequests;
198
+ const [inputSeam] = useState(() => ({
199
+ present: inputRequests !== undefined,
200
+ }));
201
+ if (inputSeam.present !== (inputRequests !== undefined))
202
+ throw new Error(
203
+ "statewire: the converter's inputRequests projection must be stable — it was " +
204
+ (inputSeam.present ? "defined" : "undefined") +
205
+ " on first convert and changed since",
206
+ );
207
+
214
208
  const extras = useMemo(
215
209
  (): AssistantTransportExtras => ({
216
210
  [symbolAssistantTransportExtras]: true,
217
211
  sendCommand: dispatch,
218
212
  reconnect: connection.reconnect,
219
213
  state: agentState,
214
+ ...(inputRequests !== undefined && { inputRequests }),
220
215
  }),
221
- [dispatch, connection.reconnect, agentState],
216
+ [dispatch, connection.reconnect, agentState, inputRequests],
222
217
  );
223
218
 
224
219
  const handleAppend = (message: AppendMessage) => {
225
220
  const startRun = message.startRun ?? message.role === "user";
226
- const command = convertAppendMessageToCommand(message);
221
+ const command: AssistantTransportCommand = {
222
+ type: "run/steer",
223
+ message: toWireMessage(message, crypto.randomUUID()),
224
+ anchorMessageId: viewedLeafId(convertedRef.current.messages),
225
+ };
227
226
  void commands.setParentId(message.parentId).catch(() => {});
228
227
 
229
- const send = () => {
230
- if (!command) return;
231
- dispatch(command, { schedule: startRun });
232
- };
228
+ const send = () => dispatch(command, { schedule: startRun });
233
229
  if (startRun) {
234
230
  // abort in-flight tool executions so their late results cannot race the new turn
235
231
  void toolInvocations.abort().then(send);
@@ -238,6 +234,17 @@ const useAssistantTransportThread = (
238
234
  }
239
235
  };
240
236
 
237
+ const handleEdit = (message: AppendMessage) => {
238
+ if (message.sourceId == null)
239
+ throw new Error("statewire: run/edit requires a sourceId");
240
+ const command: AssistantTransportCommand = {
241
+ type: "run/edit",
242
+ message: toWireMessage(message, crypto.randomUUID()),
243
+ sourceId: message.sourceId,
244
+ };
245
+ void toolInvocations.abort().then(() => dispatch(command));
246
+ };
247
+
241
248
  const handleCancel = () => {
242
249
  void toolInvocations.abort();
243
250
  void commands.cancel().catch(() => {});
@@ -258,6 +265,38 @@ const useAssistantTransportThread = (
258
265
  cancel: handleCancel,
259
266
  };
260
267
 
268
+ const queueProjection = converted.queue;
269
+ const steerProjection = converted.steerQueue;
270
+ if (steerProjection !== undefined && queueProjection === undefined)
271
+ throw new Error(
272
+ "statewire: the converter's steerQueue projection requires the queue projection",
273
+ );
274
+ if (queueProjection !== undefined && options.capabilities?.queue)
275
+ throw new Error(
276
+ "statewire: the converter's queue projection excludes capabilities.queue",
277
+ );
278
+ const [queueSeam] = useState(() => ({
279
+ present: queueProjection !== undefined,
280
+ }));
281
+ if (queueSeam.present !== (queueProjection !== undefined))
282
+ throw new Error(
283
+ "statewire: the converter's queue projection must be stable — it was " +
284
+ (queueSeam.present ? "defined" : "undefined") +
285
+ " on first convert and changed since",
286
+ );
287
+ const serverQueue = useMemo(
288
+ () =>
289
+ queueProjection
290
+ ? createRunQueueAdapter(
291
+ converted.messages,
292
+ queueProjection,
293
+ steerProjection,
294
+ dispatch,
295
+ )
296
+ : undefined,
297
+ [converted.messages, queueProjection, steerProjection, dispatch],
298
+ );
299
+
261
300
  const enableQueue = options.capabilities?.queue === true;
262
301
  const queueRef = useRef<MessageQueueController | null>(null);
263
302
  if (enableQueue && !queueRef.current) {
@@ -306,18 +345,22 @@ const useAssistantTransportThread = (
306
345
  extras,
307
346
  attachmentAdapter: options.adapters?.attachments,
308
347
  onNew: handleAppend,
309
- ...(messageQueue && {
310
- queue: {
311
- ...messageQueue.adapter,
312
- items: queueItems,
313
- steerItems: steerQueueItems,
314
- },
315
- }),
316
- ...(options.capabilities?.edit && { onEdit: handleAppend }),
348
+ ...(serverQueue
349
+ ? { queue: serverQueue }
350
+ : messageQueue && {
351
+ queue: {
352
+ ...messageQueue.adapter,
353
+ items: queueItems,
354
+ steerItems: steerQueueItems,
355
+ },
356
+ }),
357
+ ...(options.capabilities?.edit && { onEdit: handleEdit }),
317
358
  onReload: (parentId: string | null) => {
318
- void toolInvocations.abort().then(() => {
319
- void commands.reload(parentId).catch(() => {});
320
- });
359
+ const command = resolveReloadCommand(
360
+ convertedRef.current.messages,
361
+ parentId,
362
+ );
363
+ void toolInvocations.abort().then(() => dispatch(command));
321
364
  },
322
365
  onCancel: () => {
323
366
  // user cancel drops pending lanes; a steer interrupt (driver.cancel) keeps them
@@ -325,25 +368,30 @@ const useAssistantTransportThread = (
325
368
  handleCancel();
326
369
  },
327
370
  onResume: () => {
371
+ if (options.capabilities?.continue) {
372
+ dispatch({ type: "run/continue" });
373
+ return;
374
+ }
328
375
  if (!options.resumeApi)
329
376
  throw new Error("Must pass resumeApi to options to resume runs");
330
377
  void commands.resume().catch(() => {});
331
378
  },
332
- onAddToolResult: (toolOptions: AddToolResultOptions) => {
333
- const command: ToolResultAddCommand = {
334
- type: "tool-result/add",
335
- toolCallId: toolOptions.toolCallId,
336
- result: toolOptions.result as ReadonlyJSONObject,
337
- toolName: toolOptions.toolName,
338
- isError: toolOptions.isError,
339
- ...(toolOptions.artifact && { artifact: toolOptions.artifact }),
340
- ...(toolOptions.modelContent !== undefined && {
341
- modelContent: toolOptions.modelContent,
342
- }),
343
- };
344
-
345
- dispatch(command);
346
- },
379
+ ...(inputRequests !== undefined && {
380
+ onAddToolResult: (toolOptions: AddToolResultOptions) =>
381
+ dispatch(
382
+ resolveToolResultInput(
383
+ convertedRef.current.inputRequests!,
384
+ toolOptions,
385
+ ),
386
+ ),
387
+ onRespondToToolApproval: (options: RespondToToolApprovalOptions) =>
388
+ dispatch(
389
+ resolveToolApprovalInput(
390
+ convertedRef.current.inputRequests!,
391
+ options,
392
+ ),
393
+ ),
394
+ }),
347
395
  onResumeToolCall: ({ toolCallId, payload }: ResumeToolCallOptions) => {
348
396
  if (!toolInvocations.resume(toolCallId, payload))
349
397
  throw new Error(`Tool call ${toolCallId} is not waiting for resume.`);