@assistant-ui/react-statewire 0.13.0 → 0.15.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 (57) hide show
  1. package/dist/StatewireThread.d.ts +86 -105
  2. package/dist/StatewireThread.d.ts.map +1 -1
  3. package/dist/StatewireThread.js +36 -51
  4. package/dist/StatewireThread.js.map +1 -1
  5. package/dist/hooks.d.ts +6 -9
  6. package/dist/hooks.d.ts.map +1 -1
  7. package/dist/hooks.js +9 -20
  8. package/dist/hooks.js.map +1 -1
  9. package/dist/index.d.ts +2 -3
  10. package/dist/index.js +2 -3
  11. package/dist/inputRequests.d.ts +4 -4
  12. package/dist/inputRequests.d.ts.map +1 -1
  13. package/dist/inputRequests.js +1 -1
  14. package/dist/inputRequests.js.map +1 -1
  15. package/dist/runCommands.d.ts +8 -24
  16. package/dist/runCommands.d.ts.map +1 -1
  17. package/dist/runCommands.js +3 -3
  18. package/dist/runCommands.js.map +1 -1
  19. package/dist/runsOptimistic.d.ts.map +1 -1
  20. package/dist/runsOptimistic.js +30 -13
  21. package/dist/runsOptimistic.js.map +1 -1
  22. package/package.json +4 -5
  23. package/src/StatewireThread.runs.test.tsx +65 -33
  24. package/src/StatewireThread.test.tsx +228 -426
  25. package/src/StatewireThread.ts +133 -224
  26. package/src/__tests__/testHelpers.tsx +6 -226
  27. package/src/hooks.ts +11 -32
  28. package/src/index.ts +2 -4
  29. package/src/inputRequests.ts +7 -9
  30. package/src/runCommands.ts +17 -23
  31. package/src/runsMaterialize.test.ts +7 -8
  32. package/src/runsOptimistic.test.ts +86 -19
  33. package/src/runsOptimistic.ts +49 -19
  34. package/dist/AssistantTransportThread.d.ts +0 -227
  35. package/dist/AssistantTransportThread.d.ts.map +0 -1
  36. package/dist/AssistantTransportThread.js +0 -264
  37. package/dist/AssistantTransportThread.js.map +0 -1
  38. package/dist/host.d.ts +0 -38
  39. package/dist/host.d.ts.map +0 -1
  40. package/dist/host.js +0 -299
  41. package/dist/host.js.map +0 -1
  42. package/dist/replayBoundaryStream.d.ts +0 -6
  43. package/dist/replayBoundaryStream.d.ts.map +0 -1
  44. package/dist/replayBoundaryStream.js +0 -49
  45. package/dist/replayBoundaryStream.js.map +0 -1
  46. package/dist/stateOps.d.ts +0 -10
  47. package/dist/stateOps.d.ts.map +0 -1
  48. package/dist/stateOps.js +0 -114
  49. package/dist/stateOps.js.map +0 -1
  50. package/src/AssistantTransportThread.ts +0 -791
  51. package/src/athena.e2e.test.tsx +0 -654
  52. package/src/host.ts +0 -437
  53. package/src/legacy-diff.test.tsx +0 -628
  54. package/src/replayBoundaryStream.ts +0 -71
  55. package/src/stateOps.test.ts +0 -165
  56. package/src/stateOps.ts +0 -126
  57. package/src/transport.test.tsx +0 -3001
@@ -18,8 +18,6 @@ const mount = (entry?: Draft): Draft =>
18
18
  runId: null,
19
19
  queue: [],
20
20
  steerQueue: [],
21
- dispatching: null,
22
- error: null,
23
21
  ...entry,
24
22
  },
25
23
  ],
@@ -70,8 +68,8 @@ describe("runsOptimistic", () => {
70
68
  expect(run(draft).status).toBe("running");
71
69
  expect(run(draft).runId).toBe("run-1");
72
70
  expect(run(draft).steerQueue.map((e: Draft) => e.id)).toEqual(["s1", "s2"]);
73
- expect(run(draft).dispatching).toBeNull();
74
- expect(run(draft).error).toBeNull();
71
+ expect(run(draft).dispatching).toBeUndefined();
72
+ expect(run(draft).error).toBeUndefined();
75
73
  });
76
74
 
77
75
  it("dispatches an idle steer: the whole lane rides dispatching, in lane order", () => {
@@ -79,7 +77,7 @@ describe("runsOptimistic", () => {
79
77
  status: "input-required",
80
78
  runId: "run-1",
81
79
  steerQueue: [message("s1")],
82
- inputRequests: [{ type: "custom", id: "r1", response: null }],
80
+ inputRequests: [{ type: "custom", id: "r1" }],
83
81
  });
84
82
  apply(draft, "run/steer", {
85
83
  type: "run/steer",
@@ -89,7 +87,7 @@ describe("runsOptimistic", () => {
89
87
  expect(draft.status).toBe("running");
90
88
  expect(run(draft).runId).toBe("run-1");
91
89
  expect(run(draft).steerQueue).toEqual([]);
92
- expect(run(draft).dispatching.trigger).toBe("message-send");
90
+ expect(run(draft).dispatching.trigger).toBe("send-message");
93
91
  expect(run(draft).dispatching.messages.map((e: Draft) => e.id)).toEqual([
94
92
  "s1",
95
93
  "s2",
@@ -107,10 +105,23 @@ describe("runsOptimistic", () => {
107
105
  expect(ready.status).toBe("running");
108
106
  expect(run(ready).runId).toBe("mint-1");
109
107
  expect(run(ready).queue).toEqual([]);
108
+ expect(run(ready).dispatching.trigger).toBe("send-message");
110
109
  expect(run(ready).dispatching.messages.map((e: Draft) => e.id)).toEqual([
111
110
  "a",
112
111
  ]);
113
112
 
113
+ const errored = mount({ status: "error", runId: "run-1" });
114
+ apply(errored, "run/enqueue", {
115
+ type: "run/enqueue",
116
+ runId: "run-1",
117
+ message: message("a"),
118
+ });
119
+ expect(errored.status).toBe("running");
120
+ expect(run(errored).dispatching).toEqual({
121
+ trigger: "error-continue",
122
+ messages: [message("a")],
123
+ });
124
+
114
125
  const stopped = mount({
115
126
  status: "stopped",
116
127
  runId: "run-1",
@@ -144,7 +155,7 @@ describe("runsOptimistic", () => {
144
155
  const draft = mount({
145
156
  status: "running",
146
157
  runId: "r",
147
- dispatching: { trigger: "message-send", messages: [message("d1")] },
158
+ dispatching: { trigger: "send-message", messages: [message("d1")] },
148
159
  });
149
160
  apply(draft, "run/enqueue", {
150
161
  type: "run/enqueue",
@@ -198,7 +209,7 @@ describe("runsOptimistic", () => {
198
209
  const draft = mount({
199
210
  status: "input-required",
200
211
  runId: "run-1",
201
- inputRequests: [{ type: "custom", id: "r1", response: null }],
212
+ inputRequests: [{ type: "custom", id: "r1" }],
202
213
  });
203
214
  apply(draft, "run/edit", {
204
215
  type: "run/edit",
@@ -211,12 +222,69 @@ describe("runsOptimistic", () => {
211
222
  expect(run(draft).runId).toBe("run-1");
212
223
  expect(run(draft).inputRequests).toBeUndefined();
213
224
  expect(run(draft).dispatching).toEqual({
214
- trigger: "message-edit",
225
+ trigger: "edit-message",
215
226
  messages: [message("m2b")],
216
227
  rollbackTo: "a1",
217
228
  });
218
229
  });
219
230
 
231
+ it("run/edit while running stages the stopping window", () => {
232
+ const draft = mount({
233
+ status: "running",
234
+ runId: "run-1",
235
+ dispatching: { trigger: "send-message", messages: [message("m1")] },
236
+ });
237
+ apply(draft, "run/edit", {
238
+ type: "run/edit",
239
+ runId: "run-1",
240
+ message: message("m1b"),
241
+ sourceId: "m1",
242
+ runAnchorMessageId: "p0",
243
+ });
244
+ expect(draft.status).toBe("running");
245
+ expect(run(draft).status).toBe("running");
246
+ expect(run(draft).stopping).toEqual({ reason: "edit-message" });
247
+ expect(run(draft).nextDispatch).toEqual({
248
+ trigger: "edit-message",
249
+ messages: [message("m1b")],
250
+ rollbackTo: "p0",
251
+ });
252
+ expect(run(draft).dispatching.messages.map((e: Draft) => e.id)).toEqual([
253
+ "m1",
254
+ ]);
255
+ });
256
+
257
+ it("run/reload while running stages the stopping window", () => {
258
+ const draft = mount({ status: "running", runId: "run-1" });
259
+ apply(draft, "run/reload", {
260
+ type: "run/reload",
261
+ runId: "run-1",
262
+ sourceId: "a1",
263
+ runAnchorMessageId: "m1",
264
+ });
265
+ expect(run(draft).stopping).toEqual({ reason: "reload-message" });
266
+ expect(run(draft).nextDispatch).toEqual({
267
+ trigger: "reload-message",
268
+ messages: [],
269
+ rollbackTo: "m1",
270
+ });
271
+ });
272
+
273
+ it("run/stop opens the window and clears a staged rewind", () => {
274
+ const draft = mount({ status: "running", runId: "run-1" });
275
+ apply(draft, "run/edit", {
276
+ type: "run/edit",
277
+ runId: "run-1",
278
+ message: message("m1b"),
279
+ sourceId: "m1",
280
+ runAnchorMessageId: "p0",
281
+ });
282
+ apply(draft, "run/stop", { runId: "run-1" });
283
+ expect(run(draft).stopping).toEqual({ reason: "stop" });
284
+ expect(run(draft).nextDispatch).toBeUndefined();
285
+ expect(run(draft).status).toBe("running");
286
+ });
287
+
220
288
  it("run/reload predicts the rewind dispatch record", () => {
221
289
  const draft = mount({
222
290
  status: "stopped",
@@ -231,9 +299,9 @@ describe("runsOptimistic", () => {
231
299
  });
232
300
  expect(draft.status).toBe("running");
233
301
  expect(run(draft).runId).toBe("run-1");
234
- expect(run(draft).error).toBeNull();
302
+ expect(run(draft).error).toBeUndefined();
235
303
  expect(run(draft).dispatching).toEqual({
236
- trigger: "message-reload",
304
+ trigger: "reload-message",
237
305
  messages: [],
238
306
  rollbackTo: null,
239
307
  });
@@ -266,8 +334,7 @@ describe("runsOptimistic", () => {
266
334
  status: "running",
267
335
  queue: [],
268
336
  steerQueue: [],
269
- dispatching: { trigger: "message-send", messages: [message("s1")] },
270
- error: null,
337
+ dispatching: { trigger: "send-message", messages: [message("s1")] },
271
338
  });
272
339
  });
273
340
 
@@ -276,8 +343,8 @@ describe("runsOptimistic", () => {
276
343
  status: "input-required",
277
344
  runId: "run-1",
278
345
  inputRequests: [
279
- { type: "custom", id: "r1", response: null },
280
- { type: "custom", id: "r2", response: null },
346
+ { type: "custom", id: "r1" },
347
+ { type: "custom", id: "r2" },
281
348
  ],
282
349
  });
283
350
  apply(draft, "run/input", {
@@ -306,7 +373,7 @@ describe("runsOptimistic", () => {
306
373
  runId: "run-1",
307
374
  inputRequests: [
308
375
  { type: "custom", id: "r1", response: { ok: true } },
309
- { type: "custom", id: "r2", response: null },
376
+ { type: "custom", id: "r2" },
310
377
  ],
311
378
  });
312
379
  apply(draft, "run/steer", {
@@ -323,14 +390,14 @@ describe("runsOptimistic", () => {
323
390
  ]);
324
391
  });
325
392
 
326
- it("leaves the draft untouched for run/stop and unknown moves", () => {
327
- const draft = mount({ status: "running", runId: "run-1" });
393
+ it("leaves the draft untouched for unknown moves and idle run/stop", () => {
394
+ const draft = mount({ status: "stopped", runId: "run-1" });
328
395
  apply(draft, "run/stop", { runId: "run-1" });
329
396
  apply(draft, "run/enqueue", {
330
397
  type: "run/enqueue",
331
398
  runId: "run-1",
332
399
  messageId: "ghost",
333
400
  });
334
- expect(draft).toEqual(mount({ status: "running", runId: "run-1" }));
401
+ expect(draft).toEqual(mount({ status: "stopped", runId: "run-1" }));
335
402
  });
336
403
  });
@@ -9,18 +9,22 @@ type LaneEntry = {
9
9
  meta?: unknown;
10
10
  };
11
11
 
12
+ type Dispatch = {
13
+ trigger: string;
14
+ messages: LaneEntry[];
15
+ rollbackTo?: string | null;
16
+ };
17
+
12
18
  type RunEntry = {
13
19
  runId: string | null;
14
20
  status: StatewireThread.RunStatus;
15
21
  queue: LaneEntry[];
16
22
  steerQueue: LaneEntry[];
17
- dispatching: {
18
- trigger: string;
19
- messages: LaneEntry[];
20
- rollbackTo?: string | null;
21
- } | null;
22
- inputRequests?: { id: string; response: unknown }[];
23
- error: unknown;
23
+ dispatching?: Dispatch;
24
+ stopping?: { reason: "stop" | "edit-message" | "reload-message" };
25
+ nextDispatch?: Dispatch;
26
+ inputRequests?: { id: string; response?: unknown }[];
27
+ error?: unknown;
24
28
  };
25
29
 
26
30
  type RunsDraft = {
@@ -34,13 +38,11 @@ const startRun = (draft: RunsDraft, runId: string): RunEntry => {
34
38
  status: "running",
35
39
  queue: [],
36
40
  steerQueue: [],
37
- dispatching: null,
38
- error: null,
39
41
  });
40
42
  entry.status = "running";
41
43
  // A live run keeps its identity; a mint folds the client-generated id.
42
44
  if (entry.runId === null) entry.runId = runId;
43
- entry.error = null;
45
+ delete entry.error;
44
46
  delete entry.inputRequests;
45
47
  draft.status = "running";
46
48
  return entry;
@@ -103,6 +105,12 @@ const enqueueOrSteer = (
103
105
  run.queue.length === 0 &&
104
106
  run.steerQueue.length === 0));
105
107
  if (direct) {
108
+ const trigger =
109
+ status === "error"
110
+ ? "error-continue"
111
+ : status === "stopped"
112
+ ? "stop-continue"
113
+ : "send-message";
106
114
  const target = startRun(draft, runId);
107
115
  if (steer) {
108
116
  // The whole steer lane rides the dispatch, in lane order.
@@ -110,15 +118,16 @@ const enqueueOrSteer = (
110
118
  target.steerQueue.splice(sourceIndex, 0, entry);
111
119
  else target.steerQueue.push(entry);
112
120
  target.dispatching = {
113
- trigger: "message-send",
121
+ trigger,
114
122
  messages: target.steerQueue.splice(0),
115
123
  };
116
- } else target.dispatching = { trigger: "message-send", messages: [entry] };
124
+ } else target.dispatching = { trigger, messages: [entry] };
117
125
  return;
118
126
  }
119
127
  const continues = steer && status !== "running";
120
128
 
121
- if (run === undefined) return;
129
+ if (run === undefined)
130
+ throw new Error("statewire: non-direct fold without a run entry");
122
131
  const lane = steer ? run.steerQueue : run.queue;
123
132
  const hasPlacement =
124
133
  command.insertAfter !== undefined || command.insertBefore !== undefined;
@@ -127,6 +136,13 @@ const enqueueOrSteer = (
127
136
  if (continues) startRun(draft, runId);
128
137
  };
129
138
 
139
+ const stageRewind = (run: RunEntry, dispatch: Dispatch): void => {
140
+ run.stopping = {
141
+ reason: dispatch.trigger as "edit-message" | "reload-message",
142
+ };
143
+ run.nextDispatch = dispatch;
144
+ };
145
+
130
146
  /** The run dialect's optimistic reducer: folds an unsettled `run/*` command into the mount draft. */
131
147
  export const runsOptimistic = (
132
148
  mount: unknown,
@@ -152,21 +168,34 @@ export const runsOptimistic = (
152
168
  case "run/edit": {
153
169
  const { message, runAnchorMessageId } = command
154
170
  .params[0] as StatewireThread.RunEditCommand;
155
- startRun(draft, runId).dispatching = {
156
- trigger: "message-edit",
171
+ const dispatch: Dispatch = {
172
+ trigger: "edit-message",
157
173
  messages: [{ ...message }],
158
174
  rollbackTo: runAnchorMessageId,
159
175
  };
176
+ const run = draft.runs?.[0];
177
+ if (run?.status === "running") stageRewind(run, dispatch);
178
+ else startRun(draft, runId).dispatching = dispatch;
160
179
  break;
161
180
  }
162
181
  case "run/reload": {
163
182
  const { runAnchorMessageId } = command
164
183
  .params[0] as StatewireThread.RunReloadCommand;
165
- startRun(draft, runId).dispatching = {
166
- trigger: "message-reload",
184
+ const dispatch: Dispatch = {
185
+ trigger: "reload-message",
167
186
  messages: [],
168
187
  rollbackTo: runAnchorMessageId,
169
188
  };
189
+ const run = draft.runs?.[0];
190
+ if (run?.status === "running") stageRewind(run, dispatch);
191
+ else startRun(draft, runId).dispatching = dispatch;
192
+ break;
193
+ }
194
+ case "run/stop": {
195
+ const run = draft.runs?.[0];
196
+ if (run?.status !== "running") break;
197
+ run.stopping = { reason: "stop" };
198
+ delete run.nextDispatch;
170
199
  break;
171
200
  }
172
201
  case "run/continue": {
@@ -190,10 +219,11 @@ export const runsOptimistic = (
190
219
  const { requestId, response } = command
191
220
  .params[0] as StatewireThread.RunInputCommand;
192
221
  const requests = draft.runs?.[0]?.inputRequests;
193
- const target = requests?.find((r) => r.id === requestId);
222
+ if (requests === undefined) break;
223
+ const target = requests.find((r) => r.id === requestId);
194
224
  if (target === undefined) break;
195
225
  target.response = response;
196
- if (requests!.every((r) => r.response !== null)) startRun(draft, runId);
226
+ if (requests.every((r) => "response" in r)) startRun(draft, runId);
197
227
  break;
198
228
  }
199
229
  default:
@@ -1,227 +0,0 @@
1
- import { StatewireThread } from "./StatewireThread.js";
2
- import { ResourceElement } from "@assistant-ui/tap";
3
- import { Assistant } from "@assistant-ui/react";
4
- import { ClientOutput } from "@assistant-ui/store";
5
- import { AttachmentAdapter, LanguageModelConfig, LanguageModelV1CallSettings, ThreadMessage } from "@assistant-ui/core";
6
- import { StatewireClient } from "statewire";
7
- import { ReadonlyJSONValue } from "assistant-stream/utils";
8
- //#region src/AssistantTransportThread.d.ts
9
- declare const symbolAssistantTransportExtras: unique symbol;
10
- type AssistantTransportExtras = {
11
- [symbolAssistantTransportExtras]: true;
12
- sendCommand: (command: AssistantTransportThread.Command) => void;
13
- reconnect: () => void;
14
- state: unknown;
15
- /** The thread status; present iff StatewireThread. */
16
- status?: StatewireThread.ThreadStatus;
17
- /** The host's parked input requests; absent when the converter does not project them. */
18
- inputRequests?: readonly AssistantTransportThread.InputRequestState[];
19
- /** The typed runs read; present iff StatewireThread runs with the `runs` option. */
20
- runs?: StatewireThread.Runs;
21
- };
22
- declare const asAssistantTransportExtras: (extras: unknown) => AssistantTransportExtras;
23
- declare const AssistantTransportThread: <T>(options: AssistantTransportThread.Options<T>) => ResourceElement<ClientOutput<"thread">>;
24
- declare namespace AssistantTransportThread {
25
- type UserCommands = Assistant.Commands[keyof Assistant.Commands];
26
- export type TextPart = {
27
- readonly type: "text";
28
- readonly text: string;
29
- };
30
- export type FilePart = {
31
- readonly type: "file";
32
- readonly mediaType: string;
33
- readonly url: string;
34
- readonly filename?: string;
35
- };
36
- export type RunUserMessage = {
37
- readonly id: string;
38
- readonly role: "user";
39
- readonly parts: readonly (TextPart | FilePart)[];
40
- readonly metadata?: Record<string, unknown>;
41
- };
42
- /** Queue placement fields, flat on the command. Absent is load-bearing: it means default placement; `null` names a queue boundary. */
43
- export type RunPlacement = {
44
- readonly insertAfter?: string | null;
45
- readonly insertBefore?: string | null;
46
- };
47
- export type RunEnqueueCommand = {
48
- readonly type: "run/enqueue";
49
- /** The run this command targets — the live run's id, or a fresh client-minted uuid on run-creating sends. */
50
- readonly runId: string;
51
- } & ({
52
- readonly message: RunUserMessage;
53
- /** 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. */
54
- readonly runAnchorMessageId?: string | null;
55
- } | {
56
- readonly messageId: string;
57
- }) & RunPlacement;
58
- export type RunSteerCommand = {
59
- readonly type: "run/steer";
60
- /** The run this command targets — the live run's id, or a fresh client-minted uuid on run-creating sends. */
61
- readonly runId: string;
62
- } & ({
63
- readonly message: RunUserMessage;
64
- /** 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. */
65
- readonly runAnchorMessageId?: string | null;
66
- } | {
67
- readonly messageId: string;
68
- }) & RunPlacement;
69
- export type RunDequeueCommand = {
70
- readonly type: "run/dequeue";
71
- readonly runId: string;
72
- readonly messageId: string;
73
- };
74
- export type RunEditCommand = {
75
- readonly type: "run/edit";
76
- /** The live run's id when redirecting it, or a fresh client-minted uuid when idle. */
77
- readonly runId: string;
78
- readonly message: RunUserMessage;
79
- readonly sourceId: string;
80
- /** Asserts `sourceId`'s parent — the rewind target; null names the root. */
81
- readonly runAnchorMessageId: string | null;
82
- };
83
- export type RunContinueCommand = {
84
- readonly type: "run/continue";
85
- readonly runId?: string;
86
- };
87
- export type ToolCallInputRequest = {
88
- readonly type: "tool-call";
89
- readonly id: string;
90
- readonly toolCallId: string;
91
- };
92
- export type ToolApprovalInputRequest = {
93
- readonly type: "tool-approval";
94
- readonly id: string;
95
- readonly toolCallId: string;
96
- };
97
- export type CustomInputRequest = {
98
- readonly type: string;
99
- readonly id: string;
100
- readonly [key: string]: ReadonlyJSONValue | undefined;
101
- };
102
- /** A host request parking the run until answered; open union for custom types. */
103
- export type InputRequest = ToolCallInputRequest | ToolApprovalInputRequest | CustomInputRequest;
104
- export type ToolCallInputResponse = {
105
- readonly output: ReadonlyJSONValue;
106
- /** Default false; when true, `output` carries the error payload. */
107
- readonly isError?: boolean;
108
- readonly artifact?: ReadonlyJSONValue;
109
- };
110
- export type ToolApprovalInputResponse = {
111
- readonly decision: "approve" | "reject" | "edit" | "respond";
112
- readonly editedArgs?: ReadonlyJSONValue;
113
- readonly message?: string;
114
- };
115
- export type InputResponse = ReadonlyJSONValue;
116
- export type RunInputCommand = {
117
- readonly type: "run/input";
118
- readonly runId?: string;
119
- readonly requestId: string;
120
- readonly response: InputResponse;
121
- };
122
- /** An input request projected out of the host state with its response echo. */
123
- export type InputRequestState = InputRequest & {
124
- readonly response: InputResponse | null;
125
- };
126
- export type RunReloadCommand = {
127
- readonly type: "run/reload";
128
- /** The live run's id when redirecting it, or a fresh client-minted uuid when idle. */
129
- readonly runId: string;
130
- readonly sourceId: string;
131
- /** Asserts `sourceId`'s parent — the rewind target; null names the root. */
132
- readonly runAnchorMessageId: string | null;
133
- };
134
- export type RunCommand = RunEnqueueCommand | RunSteerCommand | RunDequeueCommand | RunEditCommand | RunContinueCommand | RunReloadCommand | RunInputCommand;
135
- export type Command = RunCommand | UserCommands;
136
- /** A queued message projected out of the host state, wire shape. */
137
- export type RunQueueItem = {
138
- readonly id: string;
139
- readonly parts: readonly (TextPart | FilePart)[];
140
- };
141
- export type State = {
142
- readonly messages: readonly ThreadMessage[];
143
- readonly state?: ReadonlyJSONValue;
144
- readonly isRunning: boolean;
145
- /**
146
- * The host's regular queue lane projected out of the state. Returning it
147
- * (even empty) turns on the server-side queue: sends become `run/enqueue`
148
- * / `run/steer` commands and item controls send the `run/*` queue
149
- * commands. Presence must be stable across conversions and excludes the
150
- * client-local `capabilities.queue` buffer.
151
- */
152
- readonly queue?: readonly RunQueueItem[];
153
- /** The host's steer lane; requires `queue`. Absent means empty. */
154
- readonly steerQueue?: readonly RunQueueItem[];
155
- /**
156
- * The host's parked input requests projected out of the state. Returning it
157
- * (even empty) routes tool results and approvals with a matching pending
158
- * request through `run/input`. Presence must be stable across conversions.
159
- */
160
- readonly inputRequests?: readonly AssistantTransportThread.InputRequestState[];
161
- };
162
- export type StateConverter<T> = (state: T) => State;
163
- /** Folds an unsettled command into a draft of the client state; called once per pending command, in send order, re-run on every state change. A throwing fold logs and drops that command's update. */
164
- export type Optimistic<T> = (draft: T, command: Command, ctx: StatewireClient.OptimisticContext) => void;
165
- export type HeadersValue = Record<string, string> | Headers;
166
- export type Protocol = "data-stream" | "assistant-transport";
167
- export type SendCommandsRequestBody = {
168
- commands: Command[];
169
- state: unknown;
170
- system: string | undefined;
171
- tools: Record<string, unknown> | undefined;
172
- callSettings: LanguageModelV1CallSettings | undefined;
173
- config: LanguageModelConfig | undefined;
174
- threadId: string | null;
175
- parentId?: string | null;
176
- [key: string]: unknown;
177
- };
178
- export type Options<T> = {
179
- initialState: T;
180
- converter: StateConverter<T>;
181
- optimistic?: Optimistic<T> | undefined;
182
- /** Folds the lib's run-dialect optimistic reducer before `optimistic`: `true` reads the run mounts off the state root; a selector picks a nested mount. */
183
- runs?: true | ((state: T) => unknown) | undefined;
184
- /** Makes dispatch records concrete in the draft (runs after the optimistic folds); without it, dispatch limbo stays out of `messages`. */
185
- materialize?: StatewireClient.Materialize<NonNullable<T>> | undefined;
186
- api: string;
187
- resumeApi?: string | undefined;
188
- protocol?: Protocol | undefined;
189
- headers: HeadersValue | (() => Promise<HeadersValue>);
190
- body?: object | (() => Promise<object | undefined>) | undefined;
191
- /** Transform the fully assembled request body before it is sent. */
192
- prepareSendCommandsRequest?: ((body: SendCommandsRequestBody) => Record<string, unknown> | Promise<Record<string, unknown>>) | undefined;
193
- onResponse?: ((response: Response) => void) | undefined;
194
- onFinish?: (() => void) | undefined;
195
- onError?: ((error: Error, params: {
196
- commands: Command[];
197
- updateState: (updater: (state: T) => T) => void;
198
- }) => void | Promise<void>) | undefined;
199
- /**
200
- * Called when commands are cancelled. After an error, queued commands are
201
- * cancelled once `onError` settles; `error` then carries the cause.
202
- */
203
- onCancel?: ((params: {
204
- commands: Command[];
205
- updateState: (updater: (state: T) => T) => void;
206
- error?: Error;
207
- }) => void) | undefined;
208
- capabilities?: {
209
- edit?: boolean | undefined;
210
- /**
211
- * Buffer messages sent during a run in an in-memory queue and dispatch
212
- * them once the run settles. Steering interrupts the active run.
213
- * Mutually exclusive with the converter's `queue` projection.
214
- */
215
- queue?: boolean | undefined;
216
- /** The host supports `run/continue` (a continue affordance on aborted runs). */
217
- continue?: boolean | undefined;
218
- } | undefined;
219
- adapters?: {
220
- attachments?: AttachmentAdapter | undefined;
221
- } | undefined;
222
- };
223
- export {};
224
- }
225
- //#endregion
226
- export { AssistantTransportExtras, AssistantTransportThread, asAssistantTransportExtras, symbolAssistantTransportExtras };
227
- //# sourceMappingURL=AssistantTransportThread.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AssistantTransportThread.d.ts","names":[],"sources":["../src/AssistantTransportThread.ts"],"mappings":";;;;;;;;cA6Da;KAID;GACT;EACD,cAAc,SAAS,yBAAyB;EAChD;EACA;;EAEA,SAAS,gBAAgB;;EAEzB,yBAAyB,yBAAyB;;EAElD,OAAO,gBAAgB;;cAGZ,6BACX,oBACC;cAobU,2BAA4B,GACvC,SAAS,yBAAyB,QAAQ,OACzC,gBAAgB;kBAKF;OACV,eAAe,UAAU,eAAe,UAAU;cAE3C;aACD;aACA;;cAGC;aACD;aACA;aACA;aACA;;cAGC;aACD;aACA;aACA,iBAAiB,WAAW;aAC5B,WAAW;;;cAIV;aACD;aACA;;cAGC;aACD;;aAEA;;aAGI,SAAS;;aAET;;aAEA;OAEb;cAEU;aACD;;aAEA;;aAGI,SAAS;;aAET;;aAEA;OAEb;cAEU;aACD;aACA;aACA;;cAGC;aACD;;aAEA;aACA,SAAS;aACT;;aAEA;;cAGC;aACD;aACA;;cAGC;aACD;aACA;aACA;;cAGC;aACD;aACA;aACA;;cAGC;aACD;aACA;cACC,cAAc;;;cAId,eACR,uBACA,2BACA;cAEQ;aACD,QAAQ;;aAER;aACA,WAAW;;cAGV;aACD;aACA,aAAa;aACb;;cAGC,gBAAgB;cAEhB;aACD;aACA;aACA;aACA,UAAU;;;cAIT,oBAAoB;aACrB,UAAU;;cAGT;aACD;;aAEA;aACA;;aAEA;;cAGC,aACR,oBACA,kBACA,oBACA,iBACA,qBACA,mBACA;cAEQ,UAAU,aAAa;;cAGvB;aACD;aACA,iBAAiB,WAAW;;cAG3B;aACD,mBAAmB;aACnB,QAAQ;aACR;;;;;;;;aAQA,iBAAiB;;aAEjB,sBAAsB;;;;;;aAMtB,yBAAyB,yBAAyB;;cAGjD,eAAe,MAAM,OAAO,MAAM;;cAGlC,WAAW,MACrB,OAAO,GACP,SAAS,SACT,KAAK,gBAAgB;cAGX,eAAe,yBAAyB;cAExC;cAEA;IACV,UAAU;IACV;IACA;IACA,OAAO;IACP,cAAc;IACd,QAAQ;IACR;IACA;KACC;;cAGS,QAAQ;IAClB,cAAc;IACd,WAAW,eAAe;IAC1B,aAAa,WAAW;;IAExB,gBAAgB,OAAO;;IAEvB,cAAc,gBAAgB,YAAY,YAAY;IACtD;IACA;IACA,WAAW;IACX,SAAS,sBAAsB,QAAQ;IACvC,uBAAuB;;IAEvB,+BAEM,MAAM,4BACH,0BAA0B,QAAQ;IAE3C,eAAe,UAAU;IACzB;IACA,YAEM,OAAO,OACP;MACE,UAAU;MACV,cAAc,UAAU,OAAO,MAAM;iBAE7B;;;;;IAMhB,aACM;MACA,UAAU;MACV,cAAc,UAAU,OAAO,MAAM;MACrC,QAAQ;;IAGd;MAEM;;;;;;MAMA;;MAEA;;IAGN;MAEM,cAAc"}