@assistant-ui/react-statewire 0.8.0 → 0.9.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.
@@ -175,7 +175,7 @@ describe("runsOptimistic", () => {
175
175
  expect(run(draft).steerQueue).toEqual([]);
176
176
  });
177
177
 
178
- it("run/edit, run/reload, and run/continue start the run optimistically", () => {
178
+ it("run/edit predicts the rewind dispatch record", () => {
179
179
  const draft = mount({
180
180
  status: "input-required",
181
181
  runId: "run-1",
@@ -185,11 +185,36 @@ describe("runsOptimistic", () => {
185
185
  type: "run/edit",
186
186
  message: message("m2b"),
187
187
  sourceId: "m2",
188
+ rollbackTo: "a1",
188
189
  });
189
190
  expect(draft.status).toBe("running");
190
191
  expect(run(draft).runId).toBe("optimistic-7");
191
192
  expect(run(draft).inputRequests).toBeUndefined();
193
+ expect(run(draft).dispatching).toEqual({
194
+ trigger: "message-edit",
195
+ messages: [message("m2b")],
196
+ rollbackTo: "a1",
197
+ });
198
+ });
199
+
200
+ it("run/reload predicts the rewind dispatch record", () => {
201
+ const draft = mount({ status: "stopped", error: { message: "boom" } });
202
+ apply(draft, "run/reload", {
203
+ type: "run/reload",
204
+ sourceId: "a1",
205
+ rollbackTo: null,
206
+ });
207
+ expect(draft.status).toBe("running");
208
+ expect(run(draft).runId).toBe("optimistic-7");
209
+ expect(run(draft).error).toBeNull();
210
+ expect(run(draft).dispatching).toEqual({
211
+ trigger: "message-reload",
212
+ messages: [],
213
+ rollbackTo: null,
214
+ });
215
+ });
192
216
 
217
+ it("run/continue starts the run and drains the steer lane optimistically", () => {
193
218
  const stopped = mount({ status: "stopped", steerQueue: [message("s1")] });
194
219
  apply(stopped, "run/continue", { type: "run/continue" });
195
220
  expect(stopped.status).toBe("running");
@@ -144,9 +144,26 @@ export const runsOptimistic = (
144
144
  );
145
145
  break;
146
146
  }
147
- case "run/edit":
147
+ case "run/edit": {
148
+ const { message, rollbackTo } = command
149
+ .params[0] as StatewireThread.RunEditCommand;
150
+ startRun(draft, runId);
151
+ draft.runs[0]!.dispatching = {
152
+ trigger: "message-edit",
153
+ messages: [{ ...message }],
154
+ rollbackTo,
155
+ };
156
+ break;
157
+ }
148
158
  case "run/reload": {
159
+ const { rollbackTo } = command
160
+ .params[0] as StatewireThread.RunReloadCommand;
149
161
  startRun(draft, runId);
162
+ draft.runs[0]!.dispatching = {
163
+ trigger: "message-reload",
164
+ messages: [],
165
+ rollbackTo,
166
+ };
150
167
  break;
151
168
  }
152
169
  case "run/continue": {
@@ -1322,6 +1322,7 @@ describe("AssistantTransportThread", () => {
1322
1322
  parts: [{ type: "text", text: "edited" }],
1323
1323
  },
1324
1324
  sourceId: "u2",
1325
+ rollbackTo: "a1",
1325
1326
  },
1326
1327
  ]);
1327
1328
  expect("parentId" in fetchMock.requests[0]!.body).toBe(false);
@@ -2059,6 +2060,7 @@ describe("reload", () => {
2059
2060
  {
2060
2061
  type: "run/reload",
2061
2062
  sourceId: "m2",
2063
+ rollbackTo: "m1",
2062
2064
  },
2063
2065
  ]);
2064
2066
  expect("parentId" in fetchMock.requests[1]!.body).toBe(false);
@@ -2093,6 +2095,7 @@ describe("reload", () => {
2093
2095
  {
2094
2096
  type: "run/reload",
2095
2097
  sourceId: "m2",
2098
+ rollbackTo: "m1",
2096
2099
  },
2097
2100
  ]);
2098
2101
  });