@assistant-ui/react-statewire 0.11.2 → 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.
Files changed (39) hide show
  1. package/dist/AssistantTransportThread.d.ts +19 -6
  2. package/dist/AssistantTransportThread.d.ts.map +1 -1
  3. package/dist/AssistantTransportThread.js +22 -15
  4. package/dist/AssistantTransportThread.js.map +1 -1
  5. package/dist/StatewireThread.d.ts +27 -15
  6. package/dist/StatewireThread.d.ts.map +1 -1
  7. package/dist/StatewireThread.js +37 -37
  8. package/dist/StatewireThread.js.map +1 -1
  9. package/dist/hooks.d.ts +3 -1
  10. package/dist/hooks.d.ts.map +1 -1
  11. package/dist/hooks.js +11 -2
  12. package/dist/hooks.js.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +2 -2
  15. package/dist/inputRequests.d.ts +2 -2
  16. package/dist/inputRequests.d.ts.map +1 -1
  17. package/dist/inputRequests.js +4 -2
  18. package/dist/inputRequests.js.map +1 -1
  19. package/dist/runCommands.d.ts +15 -4
  20. package/dist/runCommands.d.ts.map +1 -1
  21. package/dist/runCommands.js +27 -11
  22. package/dist/runCommands.js.map +1 -1
  23. package/dist/runsOptimistic.d.ts.map +1 -1
  24. package/dist/runsOptimistic.js +6 -6
  25. package/dist/runsOptimistic.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/AssistantTransportThread.ts +53 -16
  28. package/src/StatewireThread.runs.test.tsx +69 -55
  29. package/src/StatewireThread.test.tsx +40 -53
  30. package/src/StatewireThread.ts +89 -78
  31. package/src/athena.e2e.test.tsx +4 -2
  32. package/src/hooks.ts +11 -0
  33. package/src/index.ts +1 -0
  34. package/src/inputRequests.ts +4 -0
  35. package/src/legacy-diff.test.tsx +2 -1
  36. package/src/runCommands.ts +48 -10
  37. package/src/runsOptimistic.test.ts +64 -26
  38. package/src/runsOptimistic.ts +10 -7
  39. package/src/transport.test.tsx +46 -9
@@ -14,6 +14,7 @@ import { resource, withKey } from "@assistant-ui/tap";
14
14
  import { StatewireSSE } from "statewire";
15
15
  import { useStatewireCommands, useStatewireState } from "statewire/host";
16
16
  import { StatewireThread } from "./StatewireThread";
17
+ import { asAssistantTransportExtras } from "./AssistantTransportThread";
17
18
  import { runsMaterialize } from "./runsMaterialize";
18
19
  import { useStatewireRuns } from "./hooks";
19
20
  import { sendCommand, toThreadMessage } from "./__tests__/testHelpers";
@@ -43,8 +44,8 @@ type ServerRunEntry = {
43
44
 
44
45
  type RunsServerState = {
45
46
  messages: { id: string; role: "user" | "assistant"; text: string }[];
46
- status: StatewireThread.RunStatus;
47
- runs: ServerRunEntry[];
47
+ status: Exclude<StatewireThread.ThreadStatus, "loading">;
48
+ runs?: ServerRunEntry[];
48
49
  };
49
50
 
50
51
  const INITIAL_STATE: RunsServerState = {
@@ -53,6 +54,9 @@ const INITIAL_STATE: RunsServerState = {
53
54
  runs: [],
54
55
  };
55
56
 
57
+ const threadStatus = (aui: ReturnType<typeof useAui>) =>
58
+ asAssistantTransportExtras(aui.thread().getState().extras).status;
59
+
56
60
  const withRun = (
57
61
  entry: Partial<ServerRunEntry> & { status: StatewireThread.RunStatus },
58
62
  ): Partial<RunsServerState> => ({
@@ -241,7 +245,7 @@ describe("StatewireThread runs mode", () => {
241
245
  });
242
246
  const { aui, runs } = mountThread({ transport: server.transport });
243
247
 
244
- await waitFor(() => expect(runs().status).toBe("running"));
248
+ await waitFor(() => expect(threadStatus(aui())).toBe("running"));
245
249
  expect(runs().runId).toBe("run-1");
246
250
  expect(runs().queue.map((e) => e.id)).toEqual(["q1"]);
247
251
  expect(runs().steerQueue.map((e) => e.id)).toEqual(["s1"]);
@@ -258,9 +262,9 @@ describe("StatewireThread runs mode", () => {
258
262
  });
259
263
 
260
264
  it("delivers the runs read to the converter as meta.runs", async () => {
261
- const server = createServer(withRun({ status: "stopped" }));
265
+ const server = createServer(withRun({ status: "stopped", runId: "run-5" }));
262
266
  const observed: StatewireThread.Runs[] = [];
263
- mountThread({
267
+ const { aui } = mountThread({
264
268
  transport: server.transport,
265
269
  converter: (state, meta) => {
266
270
  observed.push(meta.runs);
@@ -268,8 +272,8 @@ describe("StatewireThread runs mode", () => {
268
272
  },
269
273
  });
270
274
 
271
- await waitFor(() => expect(observed.at(-1)!.status).toBe("stopped"));
272
- expect(observed.at(-1)!.runId).toBeNull();
275
+ await waitFor(() => expect(observed.at(-1)!.runId).toBe("run-5"));
276
+ expect(threadStatus(aui())).toBe("stopped");
273
277
  });
274
278
 
275
279
  it("stamps the live run's id onto run/stop", async () => {
@@ -340,13 +344,14 @@ describe("StatewireThread runs mode", () => {
340
344
  await waitFor(() =>
341
345
  expect(server.received).toContainEqual({
342
346
  type: "run/input",
347
+ runId: "run-1",
343
348
  requestId: "r1",
344
349
  response: { decision: "approve" },
345
350
  }),
346
351
  );
347
352
 
348
353
  act(() => {
349
- server.cell.state!.runs[0]!.inputRequests![0]!.response = {
354
+ server.cell.state!.runs![0]!.inputRequests![0]!.response = {
350
355
  decision: "approve",
351
356
  };
352
357
  });
@@ -419,7 +424,7 @@ describe("StatewireThread runs mode", () => {
419
424
 
420
425
  act(() => {
421
426
  server.cell.state!.messages.push({ id: "d1", role: "user", text: "go" });
422
- server.cell.state!.runs[0]!.dispatching = null;
427
+ server.cell.state!.runs![0]!.dispatching = null;
423
428
  });
424
429
  await waitFor(() => expect(runs().dispatching).toBeNull());
425
430
  expect(
@@ -454,12 +459,12 @@ describe("StatewireThread runs mode", () => {
454
459
  },
455
460
  }),
456
461
  });
457
- const { aui, runs } = mountThread({
462
+ const { aui } = mountThread({
458
463
  transport: server.transport,
459
464
  materialize: rollbackMaterialize,
460
465
  });
461
466
 
462
- await waitFor(() => expect(runs().status).toBe("running"));
467
+ await waitFor(() => expect(threadStatus(aui())).toBe("running"));
463
468
  expect(
464
469
  aui()
465
470
  .thread()
@@ -484,12 +489,12 @@ describe("StatewireThread runs mode", () => {
484
489
  },
485
490
  }),
486
491
  });
487
- const { aui, runs } = mountThread({
492
+ const { aui } = mountThread({
488
493
  transport: server.transport,
489
494
  materialize: rollbackMaterialize,
490
495
  });
491
496
 
492
- await waitFor(() => expect(runs().status).toBe("running"));
497
+ await waitFor(() => expect(threadStatus(aui())).toBe("running"));
493
498
  expect(
494
499
  aui()
495
500
  .thread()
@@ -520,12 +525,12 @@ describe("StatewireThread runs mode", () => {
520
525
  },
521
526
  }),
522
527
  });
523
- const { aui, runs } = mountThread({
528
+ const { aui } = mountThread({
524
529
  transport: server.transport,
525
530
  materialize: rollbackMaterialize,
526
531
  });
527
532
 
528
- await waitFor(() => expect(runs().status).toBe("running"));
533
+ await waitFor(() => expect(threadStatus(aui())).toBe("running"));
529
534
  expect(
530
535
  aui()
531
536
  .thread()
@@ -540,16 +545,16 @@ describe("StatewireThread runs mode", () => {
540
545
  );
541
546
  const { aui, runs } = mountThread({ transport: server.transport });
542
547
 
543
- await waitFor(() => expect(runs().status).toBe("running"));
548
+ await waitFor(() => expect(threadStatus(aui())).toBe("running"));
544
549
  act(() => {
545
550
  sendCommand(aui, {
546
551
  type: "run/steer",
552
+ runId: "run-1",
547
553
  message: {
548
554
  id: "s1",
549
555
  role: "user",
550
556
  parts: [{ type: "text", text: "hello" }],
551
557
  },
552
- anchorMessageId: null,
553
558
  });
554
559
  });
555
560
 
@@ -561,40 +566,54 @@ describe("StatewireThread runs mode", () => {
561
566
  expect(server.received.map((c) => c.method)).toEqual(["run/steer"]);
562
567
  });
563
568
 
564
- it("anchors a mid-run send below the converter's in-flight assistant bubble", async () => {
569
+ it("targets the live run for a mid-run send, no anchor", async () => {
565
570
  const server = createRemoteServer({
566
571
  messages: [{ id: "u1", role: "user", text: "hi" }],
567
572
  ...withRun({ status: "running", runId: "run-1" }),
568
573
  });
569
- const { aui, runs } = mountThread({
574
+ const { aui } = mountThread({ transport: server.transport });
575
+
576
+ await waitFor(() => expect(threadStatus(aui())).toBe("running"));
577
+ act(() => {
578
+ aui().thread().append("hi2");
579
+ });
580
+
581
+ await waitFor(() => expect(server.received).toHaveLength(1));
582
+ const sent = server.received[0]!.params[0] as Record<string, unknown>;
583
+ expect(sent).toMatchObject({ runId: "run-1" });
584
+ expect("runAnchorMessageId" in sent).toBe(false);
585
+ });
586
+
587
+ it("anchors a run-creating send below the converter's in-flight assistant bubble", async () => {
588
+ const server = createRemoteServer({
589
+ messages: [{ id: "u1", role: "user", text: "hi" }],
590
+ });
591
+ const { aui } = mountThread({
570
592
  transport: server.transport,
571
593
  converter: (state) => ({
572
594
  messages: [
573
595
  ...state.messages.map(toThreadMessage),
574
- ...(state.status === "running"
575
- ? [
576
- {
577
- id: "__pending_assistant__",
578
- role: "assistant",
579
- createdAt: new Date(0),
580
- content: [],
581
- status: { type: "running" },
582
- metadata: { custom: {} },
583
- } as unknown as ExternalThreadMessage,
584
- ]
585
- : []),
596
+ {
597
+ id: "__pending_assistant__",
598
+ role: "assistant",
599
+ createdAt: new Date(0),
600
+ content: [],
601
+ status: { type: "running" },
602
+ metadata: { custom: {} },
603
+ } as unknown as ExternalThreadMessage,
586
604
  ],
587
605
  }),
588
606
  });
589
607
 
590
- await waitFor(() => expect(runs().status).toBe("running"));
608
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
591
609
  act(() => {
592
610
  aui().thread().append("hi2");
593
611
  });
594
612
 
595
613
  await waitFor(() => expect(server.received).toHaveLength(1));
596
614
  expect(server.received[0]!.params[0]).toMatchObject({
597
- anchorMessageId: "u1",
615
+ runId: expect.any(String),
616
+ runAnchorMessageId: "u1",
598
617
  });
599
618
  });
600
619
 
@@ -605,15 +624,16 @@ describe("StatewireThread runs mode", () => {
605
624
  materialize: rollbackMaterialize,
606
625
  });
607
626
 
608
- await waitFor(() =>
609
- expect(aui().thread().getState().isLoading).toBe(false),
610
- );
627
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
611
628
  act(() => {
612
629
  aui().thread().append("go");
613
630
  });
614
631
 
615
- await waitFor(() => expect(runs().status).toBe("running"));
616
- expect(runs().runId).toMatch(/^optimistic-/);
632
+ await waitFor(() => expect(threadStatus(aui())).toBe("running"));
633
+ await waitFor(() => expect(server.received).toHaveLength(1));
634
+ expect(runs().runId).toBe(
635
+ (server.received[0]!.params[0] as { runId: string }).runId,
636
+ );
617
637
  expect(runs().steerQueue).toEqual([]);
618
638
  // The predicted dispatching entry renders like a canonical one.
619
639
  expect(runs().dispatching!.messages).toHaveLength(1);
@@ -631,14 +651,14 @@ describe("StatewireThread runs mode", () => {
631
651
  materialize: rollbackMaterialize,
632
652
  });
633
653
 
634
- expect(aui().thread().getState().isLoading).toBe(false);
654
+ expect(threadStatus(aui())).toBe("ready");
635
655
  act(() => {
636
656
  aui().thread().append("hello");
637
657
  });
638
658
 
639
659
  // The pre-attach send renders through the same optimistic + materialize folds.
640
- await waitFor(() => expect(runs().status).toBe("running"));
641
- expect(runs().runId).toMatch(/^optimistic-/);
660
+ await waitFor(() => expect(threadStatus(aui())).toBe("running"));
661
+ expect(runs().runId).toEqual(expect.any(String));
642
662
  expect(aui().thread().getState().messages).toHaveLength(1);
643
663
  expect(server.received).toEqual([]);
644
664
 
@@ -649,7 +669,7 @@ describe("StatewireThread runs mode", () => {
649
669
  expect(server.received.map((c) => c.method)).toEqual(["run/enqueue"]),
650
670
  );
651
671
  expect(aui().thread().getState().messages).toHaveLength(1);
652
- expect(runs().status).toBe("running");
672
+ expect(threadStatus(aui())).toBe("running");
653
673
  });
654
674
 
655
675
  it("preloads again after a transport swap on a persistent thread", async () => {
@@ -705,32 +725,28 @@ describe("StatewireThread runs mode", () => {
705
725
  // The new source's held snapshot leaves the swapped thread on the preload,
706
726
  // interactive, with no bleed-through from the previous snapshot.
707
727
  await waitFor(() => expect(aui().thread().getState().messages).toEqual([]));
708
- expect(aui().thread().getState().isLoading).toBe(false);
728
+ expect(threadStatus(aui())).toBe("ready");
709
729
 
710
730
  serverB.release();
711
- await waitFor(() =>
712
- expect(aui().thread().getState().isLoading).toBe(false),
713
- );
731
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
714
732
  });
715
733
 
716
- it("stays loading until the snapshot when initialState is omitted", async () => {
734
+ it("stays loading until the snapshot when initialState omits the runs mount", async () => {
717
735
  const server = createRemoteServer(
718
736
  { messages: [{ id: "m1", role: "user", text: "hi" }] },
719
737
  { hold: true },
720
738
  );
721
739
  const { aui } = mountThread({
722
740
  transport: server.transport,
723
- initialState: undefined,
741
+ initialState: { messages: [], status: "ready" },
724
742
  });
725
743
 
726
- expect(aui().thread().getState().isLoading).toBe(true);
744
+ expect(threadStatus(aui())).toBe("loading");
727
745
  expect(aui().thread().getState().messages).toEqual([]);
728
746
 
729
747
  server.release();
730
748
 
731
- await waitFor(() =>
732
- expect(aui().thread().getState().isLoading).toBe(false),
733
- );
749
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
734
750
  expect(
735
751
  aui()
736
752
  .thread()
@@ -760,9 +776,7 @@ describe("StatewireThread runs mode", () => {
760
776
  },
761
777
  });
762
778
 
763
- await waitFor(() =>
764
- expect(aui().thread().getState().isLoading).toBe(false),
765
- );
779
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
766
780
  act(() => {
767
781
  aui().thread().append("hi");
768
782
  });
@@ -35,11 +35,15 @@ 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[];
41
42
  };
42
43
 
44
+ const threadStatus = (aui: ReturnType<typeof useAui>) =>
45
+ asAssistantTransportExtras(aui.thread().getState().extras).status;
46
+
43
47
  const textOf = (message: { parts: StatewireThread.UserMessage["parts"] }) =>
44
48
  message.parts.flatMap((p) => (p.type === "text" ? [p.text] : [])).join("");
45
49
 
@@ -71,6 +75,7 @@ const converter: StatewireThread.StateConverter<ServerState> = (
71
75
 
72
76
  const createServer = (init?: {
73
77
  messages?: ServerState["messages"];
78
+ runId?: string | null;
74
79
  queue?: ServerState["queue"];
75
80
  steerQueue?: ServerState["steerQueue"];
76
81
  inputRequests?: ServerState["inputRequests"];
@@ -86,6 +91,7 @@ const createServer = (init?: {
86
91
  const [state] = useStatewireState<ServerState>(() => ({
87
92
  messages: init?.messages ?? [],
88
93
  running: false,
94
+ runId: init?.runId ?? null,
89
95
  queue: init?.queue ?? [],
90
96
  steerQueue: init?.steerQueue ?? [],
91
97
  inputRequests: init?.inputRequests ?? [],
@@ -254,7 +260,7 @@ describe("StatewireThread", () => {
254
260
  await waitFor(() =>
255
261
  expect(threadTexts(aui)).toEqual(["hi", "hello there"]),
256
262
  );
257
- expect(aui().thread().getState().isLoading).toBe(false);
263
+ expect(threadStatus(aui())).toBe("ready");
258
264
  expect(aui().thread().getState().isRunning).toBe(false);
259
265
  });
260
266
 
@@ -293,12 +299,12 @@ describe("StatewireThread", () => {
293
299
 
294
300
  expect(observed[0]).toBe(initialState);
295
301
  expect(threadTexts(aui)).toEqual(["local"]);
296
- expect(aui().thread().getState().isLoading).toBe(false);
302
+ expect(threadStatus(aui())).toBe("ready");
297
303
 
298
304
  cell.attach!();
299
305
 
300
306
  await waitFor(() => expect(threadTexts(aui)).toEqual(["welcome"]));
301
- expect(aui().thread().getState().isLoading).toBe(false);
307
+ expect(threadStatus(aui())).toBe("ready");
302
308
  expect((observed.at(-1) as ServerState).messages[0]!.text).toBe("welcome");
303
309
  });
304
310
 
@@ -393,9 +399,7 @@ describe("StatewireThread", () => {
393
399
  },
394
400
  });
395
401
 
396
- await waitFor(() =>
397
- expect(aui().thread().getState().isLoading).toBe(false),
398
- );
402
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
399
403
  sendCommand(aui, {
400
404
  type: "reject-me",
401
405
  } as unknown as AssistantTransportThread.Command);
@@ -460,9 +464,7 @@ describe("StatewireThread", () => {
460
464
  updates.push(update);
461
465
  },
462
466
  });
463
- await waitFor(() =>
464
- expect(aui().thread().getState().isLoading).toBe(false),
465
- );
467
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
466
468
 
467
469
  aui().thread().composer().setText("hello");
468
470
  aui().thread().composer().send();
@@ -482,9 +484,7 @@ describe("StatewireThread", () => {
482
484
  it("keeps the composer cleared when the send is accepted", async () => {
483
485
  const server = createServer();
484
486
  const { aui } = mountThread({ transport: server.transport, converter });
485
- await waitFor(() =>
486
- expect(aui().thread().getState().isLoading).toBe(false),
487
- );
487
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
488
488
 
489
489
  aui().thread().composer().setText("hello");
490
490
  aui().thread().composer().send();
@@ -505,9 +505,7 @@ describe("StatewireThread", () => {
505
505
  errors.push(error);
506
506
  },
507
507
  });
508
- await waitFor(() =>
509
- expect(aui().thread().getState().isLoading).toBe(false),
510
- );
508
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
511
509
 
512
510
  aui().thread().composer().setText("hello");
513
511
  aui().thread().composer().send();
@@ -671,9 +669,7 @@ describe("StatewireThread", () => {
671
669
  inputRequests: [],
672
670
  });
673
671
  const { aui } = mountThread({ transport: mock.transport, converter });
674
- await waitFor(() =>
675
- expect(aui().thread().getState().isLoading).toBe(false),
676
- );
672
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
677
673
  expect(mock.commands).toEqual([]);
678
674
  });
679
675
  });
@@ -684,6 +680,7 @@ describe("StatewireThread", () => {
684
680
  meta,
685
681
  ) => ({
686
682
  ...converter(state, meta),
683
+ ...(state.runId != null && { runId: state.runId }),
687
684
  queue: state.queue,
688
685
  steerQueue: state.steerQueue,
689
686
  });
@@ -815,6 +812,7 @@ describe("StatewireThread", () => {
815
812
 
816
813
  it("sends item controls as run/* commands with placement", async () => {
817
814
  const server = createServer({
815
+ runId: "run-1",
818
816
  queue: [textEntry("q1", "first"), textEntry("q2", "second")],
819
817
  steerQueue: [textEntry("s1", "urgent")],
820
818
  });
@@ -831,6 +829,7 @@ describe("StatewireThread", () => {
831
829
  await waitFor(() =>
832
830
  expect(server.received).toContainEqual({
833
831
  type: "run/steer",
832
+ runId: "run-1",
834
833
  messageId: "q1",
835
834
  insertAfter: null,
836
835
  }),
@@ -851,6 +850,7 @@ describe("StatewireThread", () => {
851
850
  await waitFor(() =>
852
851
  expect(server.received).toContainEqual({
853
852
  type: "run/steer",
853
+ runId: "run-1",
854
854
  messageId: "s1",
855
855
  insertBefore: null,
856
856
  }),
@@ -864,6 +864,7 @@ describe("StatewireThread", () => {
864
864
  await waitFor(() =>
865
865
  expect(server.received).toContainEqual({
866
866
  type: "run/enqueue",
867
+ runId: "run-1",
867
868
  messageId: "q1",
868
869
  insertAfter: "q2",
869
870
  }),
@@ -876,6 +877,7 @@ describe("StatewireThread", () => {
876
877
  await waitFor(() =>
877
878
  expect(server.received).toContainEqual({
878
879
  type: "run/dequeue",
880
+ runId: "run-1",
879
881
  messageId: "q1",
880
882
  }),
881
883
  );
@@ -935,8 +937,9 @@ describe("StatewireThread", () => {
935
937
  await waitFor(() =>
936
938
  expect(server.received).toContainEqual({
937
939
  type: "run/edit",
940
+ runId: expect.any(String),
938
941
  sourceId: "h1",
939
- rollbackTo: null,
942
+ runAnchorMessageId: null,
940
943
  message: {
941
944
  id: expect.any(String),
942
945
  role: "user",
@@ -976,8 +979,9 @@ describe("StatewireThread", () => {
976
979
  expect(server.received).toEqual([
977
980
  {
978
981
  type: "run/edit",
982
+ runId: expect.any(String),
979
983
  sourceId: "h1",
980
- rollbackTo: null,
984
+ runAnchorMessageId: null,
981
985
  message: {
982
986
  id: expect.any(String),
983
987
  role: "user",
@@ -996,9 +1000,7 @@ describe("StatewireThread", () => {
996
1000
  capabilities: { continue: true },
997
1001
  });
998
1002
 
999
- await waitFor(() =>
1000
- expect(aui().thread().getState().isLoading).toBe(false),
1001
- );
1003
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1002
1004
 
1003
1005
  aui().thread().resumeRun({ parentId: null });
1004
1006
 
@@ -1017,9 +1019,7 @@ describe("StatewireThread", () => {
1017
1019
  converter: queueConverter,
1018
1020
  });
1019
1021
 
1020
- await waitFor(() =>
1021
- expect(aui().thread().getState().isLoading).toBe(false),
1022
- );
1022
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1023
1023
 
1024
1024
  expect(() => aui().thread().resumeRun({ parentId: null })).toThrow(
1025
1025
  /does not support resuming/,
@@ -1071,9 +1071,7 @@ describe("StatewireThread", () => {
1071
1071
  converter: toolConverter(),
1072
1072
  });
1073
1073
 
1074
- await waitFor(() =>
1075
- expect(aui().thread().getState().isLoading).toBe(false),
1076
- );
1074
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1077
1075
  toolCallPart(aui).addToolResult({ ok: true });
1078
1076
 
1079
1077
  await waitFor(() =>
@@ -1092,9 +1090,7 @@ describe("StatewireThread", () => {
1092
1090
  converter: toolConverter(),
1093
1091
  });
1094
1092
 
1095
- await waitFor(() =>
1096
- expect(aui().thread().getState().isLoading).toBe(false),
1097
- );
1093
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1098
1094
  expect(() => toolCallPart(aui).addToolResult({ ok: true })).toThrow(
1099
1095
  'statewire: no tool-call input request for tool call "tc1"',
1100
1096
  );
@@ -1117,9 +1113,7 @@ describe("StatewireThread", () => {
1117
1113
  converter: toolConverter(),
1118
1114
  });
1119
1115
 
1120
- await waitFor(() =>
1121
- expect(aui().thread().getState().isLoading).toBe(false),
1122
- );
1116
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1123
1117
  expect(() => toolCallPart(aui).addToolResult({ ok: true })).toThrow(
1124
1118
  'statewire: input request "req1" is already answered',
1125
1119
  );
@@ -1141,9 +1135,7 @@ describe("StatewireThread", () => {
1141
1135
  converter: toolConverter({ id: "req2" }),
1142
1136
  });
1143
1137
 
1144
- await waitFor(() =>
1145
- expect(aui().thread().getState().isLoading).toBe(false),
1146
- );
1138
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1147
1139
  toolCallPart(aui).respondToToolApproval({ approved: true });
1148
1140
 
1149
1141
  await waitFor(() =>
@@ -1199,9 +1191,7 @@ describe("StatewireThread", () => {
1199
1191
  },
1200
1192
  });
1201
1193
 
1202
- await waitFor(() =>
1203
- expect(aui().thread().getState().isLoading).toBe(false),
1204
- );
1194
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1205
1195
  expect(() => toolCallPart(aui).addToolResult({ ok: true })).toThrow(
1206
1196
  /does not support tool results/,
1207
1197
  );
@@ -1280,8 +1270,9 @@ describe("StatewireThread", () => {
1280
1270
  await waitFor(() =>
1281
1271
  expect(server.received).toContainEqual({
1282
1272
  type: "run/reload",
1273
+ runId: expect.any(String),
1283
1274
  sourceId: "a1",
1284
- rollbackTo: "h1",
1275
+ runAnchorMessageId: "h1",
1285
1276
  }),
1286
1277
  );
1287
1278
  });
@@ -1303,8 +1294,9 @@ describe("StatewireThread", () => {
1303
1294
  await waitFor(() =>
1304
1295
  expect(server.received).toContainEqual({
1305
1296
  type: "run/reload",
1297
+ runId: expect.any(String),
1306
1298
  sourceId: "a0",
1307
- rollbackTo: null,
1299
+ runAnchorMessageId: null,
1308
1300
  }),
1309
1301
  );
1310
1302
  });
@@ -1313,9 +1305,7 @@ describe("StatewireThread", () => {
1313
1305
  const server = createServer();
1314
1306
  const { aui } = mountThread({ transport: server.transport, converter });
1315
1307
 
1316
- await waitFor(() =>
1317
- expect(aui().thread().getState().isLoading).toBe(false),
1318
- );
1308
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1319
1309
  expect(aui().thread().getState().capabilities.reload).toBe(false);
1320
1310
  });
1321
1311
 
@@ -1344,8 +1334,9 @@ describe("StatewireThread", () => {
1344
1334
  expect(server.received).toEqual([
1345
1335
  {
1346
1336
  type: "run/edit",
1337
+ runId: expect.any(String),
1347
1338
  sourceId: "h1",
1348
- rollbackTo: null,
1339
+ runAnchorMessageId: null,
1349
1340
  message: {
1350
1341
  id: expect.any(String),
1351
1342
  role: "user",
@@ -1396,9 +1387,7 @@ describe("StatewireThread", () => {
1396
1387
  converter: trackStatuses(seen),
1397
1388
  });
1398
1389
 
1399
- await waitFor(() =>
1400
- expect(aui().thread().getState().isLoading).toBe(false),
1401
- );
1390
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1402
1391
  expect(seen).toEqual(["connecting", "live"]);
1403
1392
 
1404
1393
  await mock.finish("superseded", "taken over");
@@ -1430,9 +1419,7 @@ describe("StatewireThread", () => {
1430
1419
  converter: trackStatuses(seen),
1431
1420
  });
1432
1421
 
1433
- await waitFor(() =>
1434
- expect(aui().thread().getState().isLoading).toBe(false),
1435
- );
1422
+ await waitFor(() => expect(threadStatus(aui())).toBe("ready"));
1436
1423
  await mock.finish("superseded");
1437
1424
  await waitFor(() => expect(seen.at(-1)).toBe("gone"));
1438
1425