@assistant-ui/react-statewire 0.12.0 → 0.13.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.
@@ -35,6 +35,7 @@ type QueueEntry = {
35
35
  type ServerState = {
36
36
  messages: { id: string; role: "user" | "assistant"; text: string }[];
37
37
  running: boolean;
38
+ runId?: string | null;
38
39
  queue: QueueEntry[];
39
40
  steerQueue: QueueEntry[];
40
41
  inputRequests: StatewireThread.InputRequestState[];
@@ -74,6 +75,7 @@ const converter: StatewireThread.StateConverter<ServerState> = (
74
75
 
75
76
  const createServer = (init?: {
76
77
  messages?: ServerState["messages"];
78
+ runId?: string | null;
77
79
  queue?: ServerState["queue"];
78
80
  steerQueue?: ServerState["steerQueue"];
79
81
  inputRequests?: ServerState["inputRequests"];
@@ -89,6 +91,7 @@ const createServer = (init?: {
89
91
  const [state] = useStatewireState<ServerState>(() => ({
90
92
  messages: init?.messages ?? [],
91
93
  running: false,
94
+ runId: init?.runId ?? null,
92
95
  queue: init?.queue ?? [],
93
96
  steerQueue: init?.steerQueue ?? [],
94
97
  inputRequests: init?.inputRequests ?? [],
@@ -305,34 +308,6 @@ describe("StatewireThread", () => {
305
308
  expect((observed.at(-1) as ServerState).messages[0]!.text).toBe("welcome");
306
309
  });
307
310
 
308
- it("reports loading until the snapshot, then ready", async () => {
309
- const cell: { attach?: () => void } = {};
310
- const transport = resource(() => {
311
- const [attached, setAttached] = useState(false);
312
- cell.attach = () => setAttached(true);
313
- const [state] = useStatewireState<ServerState>(() => ({
314
- ...INITIAL_STATE,
315
- messages: [{ id: "m1", role: "user", text: "hi" }],
316
- }));
317
- const commands = useStatewireCommands({});
318
- return { state: attached ? state : undefined, commands };
319
- })();
320
-
321
- const { aui } = mountThread({
322
- transport,
323
- converter,
324
- initialState: undefined,
325
- });
326
-
327
- expect(threadStatus(aui())).toBe("loading");
328
- expect(aui().thread().getState().messages).toEqual([]);
329
-
330
- cell.attach!();
331
-
332
- await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
333
- expect(threadTexts(aui)).toEqual(["hi"]);
334
- });
335
-
336
311
  it("round-trips an appended message through the run/steer command", async () => {
337
312
  const server = createServer();
338
313
  const { aui } = mountThread({ transport: server.transport, converter });
@@ -705,6 +680,7 @@ describe("StatewireThread", () => {
705
680
  meta,
706
681
  ) => ({
707
682
  ...converter(state, meta),
683
+ ...(state.runId != null && { runId: state.runId }),
708
684
  queue: state.queue,
709
685
  steerQueue: state.steerQueue,
710
686
  });
@@ -836,6 +812,7 @@ describe("StatewireThread", () => {
836
812
 
837
813
  it("sends item controls as run/* commands with placement", async () => {
838
814
  const server = createServer({
815
+ runId: "run-1",
839
816
  queue: [textEntry("q1", "first"), textEntry("q2", "second")],
840
817
  steerQueue: [textEntry("s1", "urgent")],
841
818
  });
@@ -852,6 +829,7 @@ describe("StatewireThread", () => {
852
829
  await waitFor(() =>
853
830
  expect(server.received).toContainEqual({
854
831
  type: "run/steer",
832
+ runId: "run-1",
855
833
  messageId: "q1",
856
834
  insertAfter: null,
857
835
  }),
@@ -872,6 +850,7 @@ describe("StatewireThread", () => {
872
850
  await waitFor(() =>
873
851
  expect(server.received).toContainEqual({
874
852
  type: "run/steer",
853
+ runId: "run-1",
875
854
  messageId: "s1",
876
855
  insertBefore: null,
877
856
  }),
@@ -885,6 +864,7 @@ describe("StatewireThread", () => {
885
864
  await waitFor(() =>
886
865
  expect(server.received).toContainEqual({
887
866
  type: "run/enqueue",
867
+ runId: "run-1",
888
868
  messageId: "q1",
889
869
  insertAfter: "q2",
890
870
  }),
@@ -897,6 +877,7 @@ describe("StatewireThread", () => {
897
877
  await waitFor(() =>
898
878
  expect(server.received).toContainEqual({
899
879
  type: "run/dequeue",
880
+ runId: "run-1",
900
881
  messageId: "q1",
901
882
  }),
902
883
  );
@@ -956,8 +937,9 @@ describe("StatewireThread", () => {
956
937
  await waitFor(() =>
957
938
  expect(server.received).toContainEqual({
958
939
  type: "run/edit",
940
+ runId: expect.any(String),
959
941
  sourceId: "h1",
960
- rollbackTo: null,
942
+ runAnchorMessageId: null,
961
943
  message: {
962
944
  id: expect.any(String),
963
945
  role: "user",
@@ -997,8 +979,9 @@ describe("StatewireThread", () => {
997
979
  expect(server.received).toEqual([
998
980
  {
999
981
  type: "run/edit",
982
+ runId: expect.any(String),
1000
983
  sourceId: "h1",
1001
- rollbackTo: null,
984
+ runAnchorMessageId: null,
1002
985
  message: {
1003
986
  id: expect.any(String),
1004
987
  role: "user",
@@ -1287,8 +1270,9 @@ describe("StatewireThread", () => {
1287
1270
  await waitFor(() =>
1288
1271
  expect(server.received).toContainEqual({
1289
1272
  type: "run/reload",
1273
+ runId: expect.any(String),
1290
1274
  sourceId: "a1",
1291
- rollbackTo: "h1",
1275
+ runAnchorMessageId: "h1",
1292
1276
  }),
1293
1277
  );
1294
1278
  });
@@ -1310,8 +1294,9 @@ describe("StatewireThread", () => {
1310
1294
  await waitFor(() =>
1311
1295
  expect(server.received).toContainEqual({
1312
1296
  type: "run/reload",
1297
+ runId: expect.any(String),
1313
1298
  sourceId: "a0",
1314
- rollbackTo: null,
1299
+ runAnchorMessageId: null,
1315
1300
  }),
1316
1301
  );
1317
1302
  });
@@ -1349,8 +1334,9 @@ describe("StatewireThread", () => {
1349
1334
  expect(server.received).toEqual([
1350
1335
  {
1351
1336
  type: "run/edit",
1337
+ runId: expect.any(String),
1352
1338
  sourceId: "h1",
1353
- rollbackTo: null,
1339
+ runAnchorMessageId: null,
1354
1340
  message: {
1355
1341
  id: expect.any(String),
1356
1342
  role: "user",
@@ -32,8 +32,8 @@ import {
32
32
  createRunQueueAdapter,
33
33
  resolveEditCommand,
34
34
  resolveReloadCommand,
35
+ sendFields,
35
36
  toWireMessage,
36
- viewedLeafId,
37
37
  } from "./runCommands";
38
38
  import {
39
39
  resolveToolApprovalInput,
@@ -47,19 +47,7 @@ type AnyOptions =
47
47
  | StatewireThread.Options<any>
48
48
  | StatewireThread.RunsOptions<any>;
49
49
 
50
- const LOADING_STATE: StatewireThread.State = { messages: [], isRunning: false };
51
-
52
- const READY_RUNS: StatewireThread.Runs = {
53
- status: "ready",
54
- runId: null,
55
- queue: [],
56
- steerQueue: [],
57
- dispatching: null,
58
- error: null,
59
- };
60
-
61
- const LOADING_RUNS: StatewireThread.Runs = {
62
- status: "loading",
50
+ const RESTING_RUNS: StatewireThread.Runs = {
63
51
  runId: null,
64
52
  queue: [],
65
53
  steerQueue: [],
@@ -204,26 +192,32 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
204
192
  [dispatch],
205
193
  );
206
194
 
207
- const runs = useMemo((): StatewireThread.Runs | undefined => {
208
- if (runsOption === undefined) return undefined;
209
- if (state === undefined) return LOADING_RUNS;
195
+ const { status, runs } = useMemo((): {
196
+ status: StatewireThread.ThreadStatus;
197
+ runs?: StatewireThread.Runs;
198
+ } => {
199
+ if (runsOption === undefined) return { status: "ready" };
210
200
  const mount = (runsOption === true ? state : runsOption(state)) as
211
- | StatewireThread.RunsState
201
+ | { runs?: readonly StatewireThread.RunState[] }
212
202
  | undefined;
213
- const entry = mount?.runs?.[0];
214
- return entry === undefined
215
- ? READY_RUNS
216
- : {
217
- status: entry.status,
218
- runId: entry.runId,
219
- queue: entry.queue,
220
- steerQueue: entry.steerQueue,
221
- dispatching: entry.dispatching,
222
- ...(entry.inputRequests !== undefined && {
223
- inputRequests: entry.inputRequests,
224
- }),
225
- error: entry.error,
226
- };
203
+ const entries = mount?.runs;
204
+ const entry = entries?.[0];
205
+ return {
206
+ status: entries === undefined ? "loading" : (entry?.status ?? "ready"),
207
+ runs:
208
+ entry === undefined
209
+ ? RESTING_RUNS
210
+ : {
211
+ runId: entry.runId,
212
+ queue: entry.queue,
213
+ steerQueue: entry.steerQueue,
214
+ dispatching: entry.dispatching,
215
+ ...(entry.inputRequests !== undefined && {
216
+ inputRequests: entry.inputRequests,
217
+ }),
218
+ error: entry.error,
219
+ },
220
+ };
227
221
  }, [runsOption, state]);
228
222
 
229
223
  const { converter } = options;
@@ -238,19 +232,18 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
238
232
  );
239
233
  const converted = useMemo(
240
234
  (): StatewireThread.State =>
241
- state === undefined
242
- ? LOADING_STATE
243
- : (converter(
244
- state,
245
- metadata as StatewireThread.ConnectionMetadata & {
246
- runs: StatewireThread.Runs;
247
- },
248
- ) as StatewireThread.State),
235
+ converter(
236
+ state,
237
+ metadata as StatewireThread.ConnectionMetadata & {
238
+ runs: StatewireThread.Runs;
239
+ },
240
+ ) as StatewireThread.State,
249
241
  [converter, state, metadata],
250
242
  );
251
243
  // Dispatch limbo is a materialize concern: the fold makes the record
252
244
  // concrete in state before conversion.
253
245
  const messages = converted.messages;
246
+ const liveRunId = runs !== undefined ? runs.runId : (converted.runId ?? null);
254
247
  const queueItems = runs !== undefined ? runs.queue : converted.queue;
255
248
  const steerQueueItems =
256
249
  runs !== undefined ? runs.steerQueue : converted.steerQueue;
@@ -258,16 +251,10 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
258
251
  throw new Error(
259
252
  "statewire: the converter's steerQueue projection requires the queue projection",
260
253
  );
261
- // Seams anchor at the first real convert; the loading placeholder projects nothing.
262
254
  const [queueSeam] = useState(() => ({
263
- present: undefined as boolean | undefined,
255
+ present: queueItems !== undefined,
264
256
  }));
265
- if (state !== undefined && queueSeam.present === undefined)
266
- queueSeam.present = queueItems !== undefined;
267
- if (
268
- queueSeam.present !== undefined &&
269
- queueSeam.present !== (queueItems !== undefined)
270
- )
257
+ if (queueSeam.present !== (queueItems !== undefined))
271
258
  throw new Error(
272
259
  "statewire: the converter's queue projection must be stable — it was " +
273
260
  (queueSeam.present ? "defined" : "undefined") +
@@ -279,39 +266,28 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
279
266
  queueItems
280
267
  ? createRunQueueAdapter(
281
268
  messages,
269
+ liveRunId,
282
270
  queueItems,
283
271
  steerQueueItems,
284
272
  dispatch,
285
273
  dispatchSend,
286
274
  )
287
275
  : undefined,
288
- [messages, queueItems, steerQueueItems, dispatch, dispatchSend],
276
+ [messages, liveRunId, queueItems, steerQueueItems, dispatch, dispatchSend],
289
277
  );
290
278
 
291
279
  const inputRequests =
292
280
  runs !== undefined ? (runs.inputRequests ?? []) : converted.inputRequests;
293
281
  const [inputSeam] = useState(() => ({
294
- present: undefined as boolean | undefined,
282
+ present: inputRequests !== undefined,
295
283
  }));
296
- if (state !== undefined && inputSeam.present === undefined)
297
- inputSeam.present = inputRequests !== undefined;
298
- if (
299
- inputSeam.present !== undefined &&
300
- inputSeam.present !== (inputRequests !== undefined)
301
- )
284
+ if (inputSeam.present !== (inputRequests !== undefined))
302
285
  throw new Error(
303
286
  "statewire: the converter's inputRequests projection must be stable — it was " +
304
287
  (inputSeam.present ? "defined" : "undefined") +
305
288
  " on first convert and changed since",
306
289
  );
307
290
 
308
- const status: StatewireThread.ThreadStatus =
309
- runs !== undefined
310
- ? runs.status
311
- : state === undefined
312
- ? "loading"
313
- : "ready";
314
-
315
291
  const extras = useMemo(
316
292
  (): AssistantTransportExtras => ({
317
293
  [symbolAssistantTransportExtras]: true,
@@ -328,29 +304,32 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
328
304
  const handleAppend = (message: AppendMessage) => {
329
305
  dispatchSend(
330
306
  message.sourceId != null
331
- ? resolveEditCommand(messages, message)
307
+ ? resolveEditCommand(messages, message, liveRunId)
332
308
  : {
333
309
  type: "run/steer",
334
- message: toWireMessage(message, crypto.randomUUID()),
335
- anchorMessageId: viewedLeafId(messages),
310
+ ...sendFields(
311
+ messages,
312
+ liveRunId,
313
+ toWireMessage(message, crypto.randomUUID()),
314
+ ),
336
315
  },
337
316
  message,
338
317
  );
339
318
  };
340
319
 
341
320
  const handleReload = (parentId: string | null) => {
342
- dispatch(resolveReloadCommand(messages, parentId));
321
+ dispatch(resolveReloadCommand(messages, parentId, liveRunId));
343
322
  };
344
323
 
345
324
  const handleEdit = (message: AppendMessage) => {
346
- dispatch(resolveEditCommand(messages, message));
325
+ dispatch(resolveEditCommand(messages, message, liveRunId));
347
326
  };
348
327
 
349
328
  const thread = useResource(
350
329
  ExternalThread({
351
330
  messages: messages as readonly ExternalThreadMessage[],
352
331
  isRunning:
353
- runs !== undefined ? runs.status === "running" : converted.isRunning,
332
+ runs !== undefined ? status === "running" : converted.isRunning,
354
333
  state: converted.state,
355
334
  extras,
356
335
  attachmentAdapter: options.adapters?.attachments,
@@ -360,14 +339,22 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
360
339
  ...(queue && { queue }),
361
340
  ...(options.capabilities?.edit && { onEdit: handleEdit }),
362
341
  ...(options.capabilities?.continue && {
363
- onResume: () => dispatch({ type: "run/continue" }),
342
+ onResume: () =>
343
+ dispatch({
344
+ type: "run/continue",
345
+ ...(liveRunId !== null && { runId: liveRunId }),
346
+ }),
364
347
  }),
365
348
  ...(options.capabilities?.reload && { onReload: handleReload }),
366
349
  ...(inputRequests !== undefined && {
367
350
  onAddToolResult: (toolOptions: AddToolResultOptions) =>
368
- dispatch(resolveToolResultInput(inputRequests, toolOptions)),
351
+ dispatch(
352
+ resolveToolResultInput(inputRequests, toolOptions, liveRunId),
353
+ ),
369
354
  onRespondToToolApproval: (approval: RespondToToolApprovalOptions) =>
370
- dispatch(resolveToolApprovalInput(inputRequests, approval)),
355
+ dispatch(
356
+ resolveToolApprovalInput(inputRequests, approval, liveRunId),
357
+ ),
371
358
  }),
372
359
  onCancel: () => {
373
360
  const payload = latest.current.stopPayload?.();
@@ -435,11 +422,13 @@ export namespace StatewireThread {
435
422
 
436
423
  export type RunEnqueueCommand = {
437
424
  readonly type: "run/enqueue";
425
+ /** The run this command targets — the live run's id, or a fresh client-minted uuid on run-creating sends. */
426
+ readonly runId: string;
438
427
  } & (
439
428
  | {
440
429
  readonly message: UserMessage;
441
- /** 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. */
442
- readonly anchorMessageId?: string | null;
430
+ /** Run anchor: the message the new content grows after, null asserting an empty thread. Present on run-creating sends; absent when targeting the live run. */
431
+ readonly runAnchorMessageId?: string | null;
443
432
  }
444
433
  | { readonly messageId: string }
445
434
  ) &
@@ -447,11 +436,13 @@ export namespace StatewireThread {
447
436
 
448
437
  export type RunSteerCommand = {
449
438
  readonly type: "run/steer";
439
+ /** The run this command targets — the live run's id, or a fresh client-minted uuid on run-creating sends. */
440
+ readonly runId: string;
450
441
  } & (
451
442
  | {
452
443
  readonly message: UserMessage;
453
- /** 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. */
454
- readonly anchorMessageId?: string | null;
444
+ /** Run anchor: the message the new content grows after, null asserting an empty thread. Present on run-creating sends; absent when targeting the live run. */
445
+ readonly runAnchorMessageId?: string | null;
455
446
  }
456
447
  | { readonly messageId: string }
457
448
  ) &
@@ -459,19 +450,23 @@ export namespace StatewireThread {
459
450
 
460
451
  export type RunDequeueCommand = {
461
452
  readonly type: "run/dequeue";
453
+ readonly runId: string;
462
454
  readonly messageId: string;
463
455
  };
464
456
 
465
457
  export type RunEditCommand = {
466
458
  readonly type: "run/edit";
459
+ /** The live run's id when redirecting it, or a fresh client-minted uuid when idle. */
460
+ readonly runId: string;
467
461
  readonly message: UserMessage;
468
462
  readonly sourceId: string;
469
463
  /** Asserts `sourceId`'s parent — the rewind target; null names the root. */
470
- readonly rollbackTo: string | null;
464
+ readonly runAnchorMessageId: string | null;
471
465
  };
472
466
 
473
467
  export type RunContinueCommand = {
474
468
  readonly type: "run/continue";
469
+ readonly runId?: string;
475
470
  };
476
471
 
477
472
  export type ToolCallInputRequest = {
@@ -515,6 +510,7 @@ export namespace StatewireThread {
515
510
 
516
511
  export type RunInputCommand = {
517
512
  readonly type: "run/input";
513
+ readonly runId?: string;
518
514
  readonly requestId: string;
519
515
  readonly response: InputResponse;
520
516
  };
@@ -526,9 +522,11 @@ export namespace StatewireThread {
526
522
 
527
523
  export type RunReloadCommand = {
528
524
  readonly type: "run/reload";
525
+ /** The live run's id when redirecting it, or a fresh client-minted uuid when idle. */
526
+ readonly runId: string;
529
527
  readonly sourceId: string;
530
528
  /** Asserts `sourceId`'s parent — the rewind target; null names the root. */
531
- readonly rollbackTo: string | null;
529
+ readonly runAnchorMessageId: string | null;
532
530
  };
533
531
 
534
532
  export type RunCommand =
@@ -575,7 +573,7 @@ export namespace StatewireThread {
575
573
  /** Run subsystem status replicated by the host. */
576
574
  export type RunStatus = "running" | "stopped" | "error" | "input-required";
577
575
 
578
- /** The thread's status: `"loading"` while awaiting the attach snapshot, `"ready"` while resting, otherwise the run's status. */
576
+ /** The thread's status, derived from the state: `"loading"` while the runs mount is absent, `"ready"` while resting, otherwise the run's status. */
579
577
  export type ThreadStatus = "loading" | "ready" | RunStatus;
580
578
 
581
579
  /** A queue-lane entry as replicated: the user message plus host-stamped `meta`. */
@@ -616,7 +614,7 @@ export namespace StatewireThread {
616
614
 
617
615
  /** A replicated run entry — one element of the mount's `runs` array. */
618
616
  export type RunState = {
619
- /** The run's identity — minted at dispatch, persists through input-required, null in error/stop. */
617
+ /** The run's identity — client-minted, adopted by the host at run creation; persists through steers, input-required, and error/stop, retiring only when the queue drains and the run completes. */
620
618
  readonly runId: string | null;
621
619
  readonly status: RunStatus;
622
620
  readonly queue: readonly RunsQueueEntry[];
@@ -644,10 +642,9 @@ export namespace StatewireThread {
644
642
  readonly runs: readonly RunState[];
645
643
  };
646
644
 
647
- /** The run subsystem's typed read — `runs[0]` of the selected mount with unsettled commands folded in, ready defaults while resting, loading defaults while awaiting the attach snapshot. */
645
+ /** The run subsystem's typed read — `runs[0]` of the selected mount with unsettled commands folded in, resting defaults while no entry is live. */
648
646
  export type Runs = {
649
- readonly status: ThreadStatus;
650
- /** The live run's id — non-null in running and input-required; stamped onto `run/stop`. */
647
+ /** The live run's id — non-null whenever a run entry is live (running, input-required, error/stop); the target for `run/*` sends. */
651
648
  readonly runId: string | null;
652
649
  readonly queue: readonly RunsQueueEntry[];
653
650
  readonly steerQueue: readonly RunsQueueEntry[];
@@ -694,8 +691,8 @@ export namespace StatewireThread {
694
691
 
695
692
  export type Options<T> = {
696
693
  transport: Transport<T>;
697
- /** Preloads the thread: published and interactive from the first render, replaced by the attach snapshot. Omitted, the thread stays loading until attach. */
698
- initialState?: T | undefined;
694
+ /** The pre-attach state, replaced by the attach snapshot. With runs, `runs: []` projects ready (interactive from the first render); an absent runs mount projects loading until attach. */
695
+ initialState: T;
699
696
  converter: StateConverter<T>;
700
697
  runs?: undefined;
701
698
  /**
@@ -321,13 +321,14 @@ describe("deep-agent e2e", () => {
321
321
  expect(r1.body.commands).toEqual([
322
322
  {
323
323
  type: "run/steer",
324
+ runId: expect.any(String),
324
325
  trackingId: "track-0",
325
326
  message: {
326
327
  id: expect.any(String),
327
328
  role: "user",
328
329
  parts: [{ type: "text", text: "what's the weather in SF?" }],
329
330
  },
330
- anchorMessageId: null,
331
+ runAnchorMessageId: null,
331
332
  },
332
333
  ]);
333
334
 
@@ -571,6 +572,7 @@ describe("deep-agent e2e", () => {
571
572
  expect(fetchMock.requests[0]!.body.commands).toEqual([
572
573
  {
573
574
  type: "run/edit",
575
+ runId: expect.any(String),
574
576
  trackingId: "track-0",
575
577
  message: {
576
578
  id: expect.any(String),
@@ -578,7 +580,7 @@ describe("deep-agent e2e", () => {
578
580
  parts: [{ type: "text", text: "better question" }],
579
581
  },
580
582
  sourceId: "h2",
581
- rollbackTo: "a1",
583
+ runAnchorMessageId: "a1",
582
584
  },
583
585
  ]);
584
586
  expect("parentId" in fetchMock.requests[0]!.body).toBe(false);
@@ -19,6 +19,7 @@ export const resolveToolResultInput = (
19
19
  isError: boolean;
20
20
  artifact?: ReadonlyJSONValue | undefined;
21
21
  },
22
+ runId: string | null,
22
23
  ): AssistantTransportThread.RunInputCommand => {
23
24
  const request = inputRequests.find(
24
25
  (r) => r.type === "tool-call" && r.toolCallId === options.toolCallId,
@@ -30,6 +31,7 @@ export const resolveToolResultInput = (
30
31
  assertUnanswered(request);
31
32
  return {
32
33
  type: "run/input",
34
+ ...(runId !== null && { runId }),
33
35
  requestId: request.id,
34
36
  response: {
35
37
  output: options.result,
@@ -42,6 +44,7 @@ export const resolveToolResultInput = (
42
44
  export const resolveToolApprovalInput = (
43
45
  inputRequests: readonly AssistantTransportThread.InputRequestState[],
44
46
  options: RespondToToolApprovalOptions,
47
+ runId: string | null,
45
48
  ): AssistantTransportThread.RunInputCommand => {
46
49
  const request = inputRequests.find(
47
50
  (r) => r.type === "tool-approval" && r.id === options.approvalId,
@@ -53,6 +56,7 @@ export const resolveToolApprovalInput = (
53
56
  assertUnanswered(request);
54
57
  return {
55
58
  type: "run/input",
59
+ ...(runId !== null && { runId }),
56
60
  requestId: request.id,
57
61
  response: {
58
62
  decision: options.approved ? "approve" : "reject",
@@ -66,12 +66,13 @@ const renameWire = (commands: unknown) =>
66
66
  c.type === "add-message"
67
67
  ? {
68
68
  type: "run/steer",
69
+ runId: expect.any(String),
69
70
  message: {
70
71
  id: expect.any(String),
71
72
  role: c.message.role,
72
73
  parts: c.message.parts,
73
74
  },
74
- anchorMessageId: expect.toSatisfy(
75
+ runAnchorMessageId: expect.toSatisfy(
75
76
  (v) => v === null || typeof v === "string",
76
77
  ),
77
78
  }