@assistant-ui/react-statewire 0.12.0 → 0.14.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/StatewireThread.d.ts +83 -108
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +54 -79
- package/dist/StatewireThread.js.map +1 -1
- package/dist/hooks.d.ts +6 -9
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +9 -20
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/inputRequests.d.ts +4 -4
- package/dist/inputRequests.d.ts.map +1 -1
- package/dist/inputRequests.js +4 -2
- package/dist/inputRequests.js.map +1 -1
- package/dist/runCommands.d.ts +14 -19
- package/dist/runCommands.d.ts.map +1 -1
- package/dist/runCommands.js +29 -13
- package/dist/runCommands.js.map +1 -1
- package/dist/runsOptimistic.d.ts.map +1 -1
- package/dist/runsOptimistic.js +9 -8
- package/dist/runsOptimistic.js.map +1 -1
- package/package.json +4 -5
- package/src/StatewireThread.runs.test.tsx +67 -54
- package/src/StatewireThread.test.tsx +239 -431
- package/src/StatewireThread.ts +151 -266
- package/src/__tests__/testHelpers.tsx +6 -226
- package/src/hooks.ts +11 -32
- package/src/index.ts +2 -4
- package/src/inputRequests.ts +10 -8
- package/src/runCommands.ts +63 -31
- package/src/runsOptimistic.test.ts +64 -26
- package/src/runsOptimistic.ts +14 -9
- package/dist/AssistantTransportThread.d.ts +0 -216
- package/dist/AssistantTransportThread.d.ts.map +0 -1
- package/dist/AssistantTransportThread.js +0 -257
- package/dist/AssistantTransportThread.js.map +0 -1
- package/dist/host.d.ts +0 -38
- package/dist/host.d.ts.map +0 -1
- package/dist/host.js +0 -299
- package/dist/host.js.map +0 -1
- package/dist/replayBoundaryStream.d.ts +0 -6
- package/dist/replayBoundaryStream.d.ts.map +0 -1
- package/dist/replayBoundaryStream.js +0 -49
- package/dist/replayBoundaryStream.js.map +0 -1
- package/dist/stateOps.d.ts +0 -10
- package/dist/stateOps.d.ts.map +0 -1
- package/dist/stateOps.js +0 -114
- package/dist/stateOps.js.map +0 -1
- package/src/AssistantTransportThread.ts +0 -756
- package/src/athena.e2e.test.tsx +0 -652
- package/src/host.ts +0 -437
- package/src/legacy-diff.test.tsx +0 -627
- package/src/replayBoundaryStream.ts +0 -71
- package/src/stateOps.test.ts +0 -165
- package/src/stateOps.ts +0 -126
- package/src/transport.test.tsx +0 -2964
|
@@ -45,8 +45,8 @@ describe("runsOptimistic", () => {
|
|
|
45
45
|
const draft = mount({ status: "running", runId: "run-1" });
|
|
46
46
|
apply(draft, "run/steer", {
|
|
47
47
|
type: "run/steer",
|
|
48
|
+
runId: "run-1",
|
|
48
49
|
message: message("s1"),
|
|
49
|
-
anchorMessageId: null,
|
|
50
50
|
});
|
|
51
51
|
expect(run(draft).steerQueue.map((e: Draft) => e.id)).toEqual(["s1"]);
|
|
52
52
|
expect(draft.status).toBe("running");
|
|
@@ -57,17 +57,18 @@ describe("runsOptimistic", () => {
|
|
|
57
57
|
it("parks a steer in the lane after a stop and predicts the continue run", () => {
|
|
58
58
|
const draft = mount({
|
|
59
59
|
status: "stopped",
|
|
60
|
+
runId: "run-1",
|
|
60
61
|
steerQueue: [message("s1")],
|
|
61
62
|
error: { message: "boom" },
|
|
62
63
|
});
|
|
63
64
|
apply(draft, "run/steer", {
|
|
64
65
|
type: "run/steer",
|
|
66
|
+
runId: "run-1",
|
|
65
67
|
message: message("s2"),
|
|
66
|
-
anchorMessageId: null,
|
|
67
68
|
});
|
|
68
69
|
expect(draft.status).toBe("running");
|
|
69
70
|
expect(run(draft).status).toBe("running");
|
|
70
|
-
expect(run(draft).runId).toBe("
|
|
71
|
+
expect(run(draft).runId).toBe("run-1");
|
|
71
72
|
expect(run(draft).steerQueue.map((e: Draft) => e.id)).toEqual(["s1", "s2"]);
|
|
72
73
|
expect(run(draft).dispatching).toBeNull();
|
|
73
74
|
expect(run(draft).error).toBeNull();
|
|
@@ -82,11 +83,11 @@ describe("runsOptimistic", () => {
|
|
|
82
83
|
});
|
|
83
84
|
apply(draft, "run/steer", {
|
|
84
85
|
type: "run/steer",
|
|
86
|
+
runId: "run-1",
|
|
85
87
|
message: message("s2"),
|
|
86
|
-
anchorMessageId: null,
|
|
87
88
|
});
|
|
88
89
|
expect(draft.status).toBe("running");
|
|
89
|
-
expect(run(draft).runId).toBe("
|
|
90
|
+
expect(run(draft).runId).toBe("run-1");
|
|
90
91
|
expect(run(draft).steerQueue).toEqual([]);
|
|
91
92
|
expect(run(draft).dispatching.trigger).toBe("message-send");
|
|
92
93
|
expect(run(draft).dispatching.messages.map((e: Draft) => e.id)).toEqual([
|
|
@@ -99,21 +100,26 @@ describe("runsOptimistic", () => {
|
|
|
99
100
|
const ready = mount();
|
|
100
101
|
apply(ready, "run/enqueue", {
|
|
101
102
|
type: "run/enqueue",
|
|
103
|
+
runId: "mint-1",
|
|
102
104
|
message: message("a"),
|
|
103
|
-
|
|
105
|
+
runAnchorMessageId: null,
|
|
104
106
|
});
|
|
105
107
|
expect(ready.status).toBe("running");
|
|
106
|
-
expect(run(ready).runId).toBe("
|
|
108
|
+
expect(run(ready).runId).toBe("mint-1");
|
|
107
109
|
expect(run(ready).queue).toEqual([]);
|
|
108
110
|
expect(run(ready).dispatching.messages.map((e: Draft) => e.id)).toEqual([
|
|
109
111
|
"a",
|
|
110
112
|
]);
|
|
111
113
|
|
|
112
|
-
const stopped = mount({
|
|
114
|
+
const stopped = mount({
|
|
115
|
+
status: "stopped",
|
|
116
|
+
runId: "run-1",
|
|
117
|
+
queue: [message("q1")],
|
|
118
|
+
});
|
|
113
119
|
apply(stopped, "run/enqueue", {
|
|
114
120
|
type: "run/enqueue",
|
|
121
|
+
runId: "run-1",
|
|
115
122
|
message: message("a"),
|
|
116
|
-
anchorMessageId: null,
|
|
117
123
|
});
|
|
118
124
|
expect(stopped.status).toBe("stopped");
|
|
119
125
|
expect(run(stopped).queue.map((e: Draft) => e.id)).toEqual(["q1", "a"]);
|
|
@@ -127,8 +133,8 @@ describe("runsOptimistic", () => {
|
|
|
127
133
|
});
|
|
128
134
|
apply(draft, "run/enqueue", {
|
|
129
135
|
type: "run/enqueue",
|
|
136
|
+
runId: "r",
|
|
130
137
|
message: message("x"),
|
|
131
|
-
anchorMessageId: null,
|
|
132
138
|
insertAfter: "a",
|
|
133
139
|
});
|
|
134
140
|
expect(run(draft).queue.map((e: Draft) => e.id)).toEqual(["a", "x", "b"]);
|
|
@@ -142,10 +148,14 @@ describe("runsOptimistic", () => {
|
|
|
142
148
|
});
|
|
143
149
|
apply(draft, "run/enqueue", {
|
|
144
150
|
type: "run/enqueue",
|
|
151
|
+
runId: "r",
|
|
145
152
|
message: message("d1"),
|
|
146
|
-
anchorMessageId: null,
|
|
147
153
|
});
|
|
148
|
-
apply(draft, "run/steer", {
|
|
154
|
+
apply(draft, "run/steer", {
|
|
155
|
+
type: "run/steer",
|
|
156
|
+
runId: "r",
|
|
157
|
+
messageId: "d1",
|
|
158
|
+
});
|
|
149
159
|
expect(run(draft).queue).toEqual([]);
|
|
150
160
|
expect(run(draft).steerQueue).toEqual([]);
|
|
151
161
|
expect(run(draft).dispatching.messages.map((e: Draft) => e.id)).toEqual([
|
|
@@ -159,19 +169,28 @@ describe("runsOptimistic", () => {
|
|
|
159
169
|
runId: "r",
|
|
160
170
|
queue: [{ ...message("q1"), meta: { m: 1 } }, message("q2")],
|
|
161
171
|
});
|
|
162
|
-
apply(draft, "run/steer", {
|
|
172
|
+
apply(draft, "run/steer", {
|
|
173
|
+
type: "run/steer",
|
|
174
|
+
runId: "r",
|
|
175
|
+
messageId: "q1",
|
|
176
|
+
});
|
|
163
177
|
expect(run(draft).queue.map((e: Draft) => e.id)).toEqual(["q2"]);
|
|
164
178
|
expect(run(draft).steerQueue.map((e: Draft) => e.id)).toEqual(["q1"]);
|
|
165
179
|
expect(run(draft).steerQueue[0].meta).toEqual({ m: 1 });
|
|
166
180
|
|
|
167
181
|
apply(draft, "run/enqueue", {
|
|
168
182
|
type: "run/enqueue",
|
|
183
|
+
runId: "r",
|
|
169
184
|
message: { ...message("q2"), parts: [{ type: "text", text: "new" }] },
|
|
170
185
|
});
|
|
171
186
|
expect(run(draft).queue.map((e: Draft) => e.id)).toEqual(["q2"]);
|
|
172
187
|
expect(run(draft).queue[0].parts).toEqual([{ type: "text", text: "new" }]);
|
|
173
188
|
|
|
174
|
-
apply(draft, "run/dequeue", {
|
|
189
|
+
apply(draft, "run/dequeue", {
|
|
190
|
+
type: "run/dequeue",
|
|
191
|
+
runId: "r",
|
|
192
|
+
messageId: "q1",
|
|
193
|
+
});
|
|
175
194
|
expect(run(draft).steerQueue).toEqual([]);
|
|
176
195
|
});
|
|
177
196
|
|
|
@@ -183,12 +202,13 @@ describe("runsOptimistic", () => {
|
|
|
183
202
|
});
|
|
184
203
|
apply(draft, "run/edit", {
|
|
185
204
|
type: "run/edit",
|
|
205
|
+
runId: "run-1",
|
|
186
206
|
message: message("m2b"),
|
|
187
207
|
sourceId: "m2",
|
|
188
|
-
|
|
208
|
+
runAnchorMessageId: "a1",
|
|
189
209
|
});
|
|
190
210
|
expect(draft.status).toBe("running");
|
|
191
|
-
expect(run(draft).runId).toBe("
|
|
211
|
+
expect(run(draft).runId).toBe("run-1");
|
|
192
212
|
expect(run(draft).inputRequests).toBeUndefined();
|
|
193
213
|
expect(run(draft).dispatching).toEqual({
|
|
194
214
|
trigger: "message-edit",
|
|
@@ -198,14 +218,19 @@ describe("runsOptimistic", () => {
|
|
|
198
218
|
});
|
|
199
219
|
|
|
200
220
|
it("run/reload predicts the rewind dispatch record", () => {
|
|
201
|
-
const draft = mount({
|
|
221
|
+
const draft = mount({
|
|
222
|
+
status: "stopped",
|
|
223
|
+
runId: "run-1",
|
|
224
|
+
error: { message: "boom" },
|
|
225
|
+
});
|
|
202
226
|
apply(draft, "run/reload", {
|
|
203
227
|
type: "run/reload",
|
|
228
|
+
runId: "run-1",
|
|
204
229
|
sourceId: "a1",
|
|
205
|
-
|
|
230
|
+
runAnchorMessageId: null,
|
|
206
231
|
});
|
|
207
232
|
expect(draft.status).toBe("running");
|
|
208
|
-
expect(run(draft).runId).toBe("
|
|
233
|
+
expect(run(draft).runId).toBe("run-1");
|
|
209
234
|
expect(run(draft).error).toBeNull();
|
|
210
235
|
expect(run(draft).dispatching).toEqual({
|
|
211
236
|
trigger: "message-reload",
|
|
@@ -215,9 +240,14 @@ describe("runsOptimistic", () => {
|
|
|
215
240
|
});
|
|
216
241
|
|
|
217
242
|
it("run/continue starts the run and drains the steer lane optimistically", () => {
|
|
218
|
-
const stopped = mount({
|
|
219
|
-
|
|
243
|
+
const stopped = mount({
|
|
244
|
+
status: "stopped",
|
|
245
|
+
runId: "run-1",
|
|
246
|
+
steerQueue: [message("s1")],
|
|
247
|
+
});
|
|
248
|
+
apply(stopped, "run/continue", { type: "run/continue", runId: "run-1" });
|
|
220
249
|
expect(stopped.status).toBe("running");
|
|
250
|
+
expect(run(stopped).runId).toBe("run-1");
|
|
221
251
|
expect(run(stopped).steerQueue).toEqual([]);
|
|
222
252
|
});
|
|
223
253
|
|
|
@@ -225,13 +255,14 @@ describe("runsOptimistic", () => {
|
|
|
225
255
|
const draft = mount();
|
|
226
256
|
apply(draft, "run/steer", {
|
|
227
257
|
type: "run/steer",
|
|
258
|
+
runId: "mint-1",
|
|
228
259
|
message: message("s1"),
|
|
229
|
-
|
|
260
|
+
runAnchorMessageId: null,
|
|
230
261
|
});
|
|
231
262
|
expect(draft.status).toBe("running");
|
|
232
263
|
expect(draft.runs).toHaveLength(1);
|
|
233
264
|
expect(run(draft)).toEqual({
|
|
234
|
-
runId: "
|
|
265
|
+
runId: "mint-1",
|
|
235
266
|
status: "running",
|
|
236
267
|
queue: [],
|
|
237
268
|
steerQueue: [],
|
|
@@ -251,6 +282,7 @@ describe("runsOptimistic", () => {
|
|
|
251
282
|
});
|
|
252
283
|
apply(draft, "run/input", {
|
|
253
284
|
type: "run/input",
|
|
285
|
+
runId: "run-1",
|
|
254
286
|
requestId: "r1",
|
|
255
287
|
response: { ok: true },
|
|
256
288
|
});
|
|
@@ -259,10 +291,12 @@ describe("runsOptimistic", () => {
|
|
|
259
291
|
|
|
260
292
|
apply(draft, "run/input", {
|
|
261
293
|
type: "run/input",
|
|
294
|
+
runId: "run-1",
|
|
262
295
|
requestId: "r2",
|
|
263
296
|
response: { ok: true },
|
|
264
297
|
});
|
|
265
298
|
expect(draft.status).toBe("running");
|
|
299
|
+
expect(run(draft).runId).toBe("run-1");
|
|
266
300
|
expect(run(draft).inputRequests).toBeUndefined();
|
|
267
301
|
});
|
|
268
302
|
|
|
@@ -277,11 +311,11 @@ describe("runsOptimistic", () => {
|
|
|
277
311
|
});
|
|
278
312
|
apply(draft, "run/steer", {
|
|
279
313
|
type: "run/steer",
|
|
314
|
+
runId: "run-1",
|
|
280
315
|
message: message("s1"),
|
|
281
|
-
anchorMessageId: null,
|
|
282
316
|
});
|
|
283
317
|
expect(draft.status).toBe("running");
|
|
284
|
-
expect(run(draft).runId).toBe("
|
|
318
|
+
expect(run(draft).runId).toBe("run-1");
|
|
285
319
|
expect(run(draft).inputRequests).toBeUndefined();
|
|
286
320
|
expect(run(draft).steerQueue).toEqual([]);
|
|
287
321
|
expect(run(draft).dispatching.messages.map((e: Draft) => e.id)).toEqual([
|
|
@@ -292,7 +326,11 @@ describe("runsOptimistic", () => {
|
|
|
292
326
|
it("leaves the draft untouched for run/stop and unknown moves", () => {
|
|
293
327
|
const draft = mount({ status: "running", runId: "run-1" });
|
|
294
328
|
apply(draft, "run/stop", { runId: "run-1" });
|
|
295
|
-
apply(draft, "run/enqueue", {
|
|
329
|
+
apply(draft, "run/enqueue", {
|
|
330
|
+
type: "run/enqueue",
|
|
331
|
+
runId: "run-1",
|
|
332
|
+
messageId: "ghost",
|
|
333
|
+
});
|
|
296
334
|
expect(draft).toEqual(mount({ status: "running", runId: "run-1" }));
|
|
297
335
|
});
|
|
298
336
|
});
|
package/src/runsOptimistic.ts
CHANGED
|
@@ -38,7 +38,8 @@ const startRun = (draft: RunsDraft, runId: string): RunEntry => {
|
|
|
38
38
|
error: null,
|
|
39
39
|
});
|
|
40
40
|
entry.status = "running";
|
|
41
|
-
|
|
41
|
+
// A live run keeps its identity; a mint folds the client-generated id.
|
|
42
|
+
if (entry.runId === null) entry.runId = runId;
|
|
42
43
|
entry.error = null;
|
|
43
44
|
delete entry.inputRequests;
|
|
44
45
|
draft.status = "running";
|
|
@@ -117,7 +118,8 @@ const enqueueOrSteer = (
|
|
|
117
118
|
}
|
|
118
119
|
const continues = steer && status !== "running";
|
|
119
120
|
|
|
120
|
-
if (run === undefined)
|
|
121
|
+
if (run === undefined)
|
|
122
|
+
throw new Error("statewire: non-direct fold without a run entry");
|
|
121
123
|
const lane = steer ? run.steerQueue : run.queue;
|
|
122
124
|
const hasPlacement =
|
|
123
125
|
command.insertAfter !== undefined || command.insertBefore !== undefined;
|
|
@@ -133,7 +135,9 @@ export const runsOptimistic = (
|
|
|
133
135
|
ctx: StatewireClient.OptimisticContext,
|
|
134
136
|
): void => {
|
|
135
137
|
const draft = mount as RunsDraft;
|
|
136
|
-
const
|
|
138
|
+
const commandRunId = (command.params[0] as { runId?: string } | undefined)
|
|
139
|
+
?.runId;
|
|
140
|
+
const runId = commandRunId ?? `optimistic-${ctx.seq}`;
|
|
137
141
|
switch (command.method) {
|
|
138
142
|
case "run/enqueue":
|
|
139
143
|
case "run/steer": {
|
|
@@ -147,22 +151,22 @@ export const runsOptimistic = (
|
|
|
147
151
|
break;
|
|
148
152
|
}
|
|
149
153
|
case "run/edit": {
|
|
150
|
-
const { message,
|
|
154
|
+
const { message, runAnchorMessageId } = command
|
|
151
155
|
.params[0] as StatewireThread.RunEditCommand;
|
|
152
156
|
startRun(draft, runId).dispatching = {
|
|
153
157
|
trigger: "message-edit",
|
|
154
158
|
messages: [{ ...message }],
|
|
155
|
-
rollbackTo,
|
|
159
|
+
rollbackTo: runAnchorMessageId,
|
|
156
160
|
};
|
|
157
161
|
break;
|
|
158
162
|
}
|
|
159
163
|
case "run/reload": {
|
|
160
|
-
const {
|
|
164
|
+
const { runAnchorMessageId } = command
|
|
161
165
|
.params[0] as StatewireThread.RunReloadCommand;
|
|
162
166
|
startRun(draft, runId).dispatching = {
|
|
163
167
|
trigger: "message-reload",
|
|
164
168
|
messages: [],
|
|
165
|
-
rollbackTo,
|
|
169
|
+
rollbackTo: runAnchorMessageId,
|
|
166
170
|
};
|
|
167
171
|
break;
|
|
168
172
|
}
|
|
@@ -187,10 +191,11 @@ export const runsOptimistic = (
|
|
|
187
191
|
const { requestId, response } = command
|
|
188
192
|
.params[0] as StatewireThread.RunInputCommand;
|
|
189
193
|
const requests = draft.runs?.[0]?.inputRequests;
|
|
190
|
-
|
|
194
|
+
if (requests === undefined) break;
|
|
195
|
+
const target = requests.find((r) => r.id === requestId);
|
|
191
196
|
if (target === undefined) break;
|
|
192
197
|
target.response = response;
|
|
193
|
-
if (requests
|
|
198
|
+
if (requests.every((r) => r.response !== null)) startRun(draft, runId);
|
|
194
199
|
break;
|
|
195
200
|
}
|
|
196
201
|
default:
|
|
@@ -1,216 +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
|
-
} & ({
|
|
50
|
-
readonly message: RunUserMessage;
|
|
51
|
-
/** 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. */
|
|
52
|
-
readonly anchorMessageId?: string | null;
|
|
53
|
-
} | {
|
|
54
|
-
readonly messageId: string;
|
|
55
|
-
}) & RunPlacement;
|
|
56
|
-
export type RunSteerCommand = {
|
|
57
|
-
readonly type: "run/steer";
|
|
58
|
-
} & ({
|
|
59
|
-
readonly message: RunUserMessage;
|
|
60
|
-
/** 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. */
|
|
61
|
-
readonly anchorMessageId?: string | null;
|
|
62
|
-
} | {
|
|
63
|
-
readonly messageId: string;
|
|
64
|
-
}) & RunPlacement;
|
|
65
|
-
export type RunDequeueCommand = {
|
|
66
|
-
readonly type: "run/dequeue";
|
|
67
|
-
readonly messageId: string;
|
|
68
|
-
};
|
|
69
|
-
export type RunEditCommand = {
|
|
70
|
-
readonly type: "run/edit";
|
|
71
|
-
readonly message: RunUserMessage;
|
|
72
|
-
readonly sourceId: string;
|
|
73
|
-
/** Asserts `sourceId`'s parent — the rewind target; null names the root. */
|
|
74
|
-
readonly rollbackTo: string | null;
|
|
75
|
-
};
|
|
76
|
-
export type RunContinueCommand = {
|
|
77
|
-
readonly type: "run/continue";
|
|
78
|
-
};
|
|
79
|
-
export type ToolCallInputRequest = {
|
|
80
|
-
readonly type: "tool-call";
|
|
81
|
-
readonly id: string;
|
|
82
|
-
readonly toolCallId: string;
|
|
83
|
-
};
|
|
84
|
-
export type ToolApprovalInputRequest = {
|
|
85
|
-
readonly type: "tool-approval";
|
|
86
|
-
readonly id: string;
|
|
87
|
-
readonly toolCallId: string;
|
|
88
|
-
};
|
|
89
|
-
export type CustomInputRequest = {
|
|
90
|
-
readonly type: string;
|
|
91
|
-
readonly id: string;
|
|
92
|
-
readonly [key: string]: ReadonlyJSONValue | undefined;
|
|
93
|
-
};
|
|
94
|
-
/** A host request parking the run until answered; open union for custom types. */
|
|
95
|
-
export type InputRequest = ToolCallInputRequest | ToolApprovalInputRequest | CustomInputRequest;
|
|
96
|
-
export type ToolCallInputResponse = {
|
|
97
|
-
readonly output: ReadonlyJSONValue;
|
|
98
|
-
/** Default false; when true, `output` carries the error payload. */
|
|
99
|
-
readonly isError?: boolean;
|
|
100
|
-
readonly artifact?: ReadonlyJSONValue;
|
|
101
|
-
};
|
|
102
|
-
export type ToolApprovalInputResponse = {
|
|
103
|
-
readonly decision: "approve" | "reject" | "edit" | "respond";
|
|
104
|
-
readonly editedArgs?: ReadonlyJSONValue;
|
|
105
|
-
readonly message?: string;
|
|
106
|
-
};
|
|
107
|
-
export type InputResponse = ReadonlyJSONValue;
|
|
108
|
-
export type RunInputCommand = {
|
|
109
|
-
readonly type: "run/input";
|
|
110
|
-
readonly requestId: string;
|
|
111
|
-
readonly response: InputResponse;
|
|
112
|
-
};
|
|
113
|
-
/** An input request projected out of the host state with its response echo. */
|
|
114
|
-
export type InputRequestState = InputRequest & {
|
|
115
|
-
readonly response: InputResponse | null;
|
|
116
|
-
};
|
|
117
|
-
export type RunReloadCommand = {
|
|
118
|
-
readonly type: "run/reload";
|
|
119
|
-
readonly sourceId: string;
|
|
120
|
-
/** Asserts `sourceId`'s parent — the rewind target; null names the root. */
|
|
121
|
-
readonly rollbackTo: string | null;
|
|
122
|
-
};
|
|
123
|
-
export type RunCommand = RunEnqueueCommand | RunSteerCommand | RunDequeueCommand | RunEditCommand | RunContinueCommand | RunReloadCommand | RunInputCommand;
|
|
124
|
-
export type Command = RunCommand | UserCommands;
|
|
125
|
-
/** A queued message projected out of the host state, wire shape. */
|
|
126
|
-
export type RunQueueItem = {
|
|
127
|
-
readonly id: string;
|
|
128
|
-
readonly parts: readonly (TextPart | FilePart)[];
|
|
129
|
-
};
|
|
130
|
-
export type State = {
|
|
131
|
-
readonly messages: readonly ThreadMessage[];
|
|
132
|
-
readonly state?: ReadonlyJSONValue;
|
|
133
|
-
readonly isRunning: boolean;
|
|
134
|
-
/**
|
|
135
|
-
* The host's regular queue lane projected out of the state. Returning it
|
|
136
|
-
* (even empty) turns on the server-side queue: sends become `run/enqueue`
|
|
137
|
-
* / `run/steer` commands and item controls send the `run/*` queue
|
|
138
|
-
* commands. Presence must be stable across conversions and excludes the
|
|
139
|
-
* client-local `capabilities.queue` buffer.
|
|
140
|
-
*/
|
|
141
|
-
readonly queue?: readonly RunQueueItem[];
|
|
142
|
-
/** The host's steer lane; requires `queue`. Absent means empty. */
|
|
143
|
-
readonly steerQueue?: readonly RunQueueItem[];
|
|
144
|
-
/**
|
|
145
|
-
* The host's parked input requests projected out of the state. Returning it
|
|
146
|
-
* (even empty) routes tool results and approvals with a matching pending
|
|
147
|
-
* request through `run/input`. Presence must be stable across conversions.
|
|
148
|
-
*/
|
|
149
|
-
readonly inputRequests?: readonly AssistantTransportThread.InputRequestState[];
|
|
150
|
-
};
|
|
151
|
-
export type StateConverter<T> = (state: T) => State;
|
|
152
|
-
/** 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. */
|
|
153
|
-
export type Optimistic<T> = (draft: T, command: Command, ctx: StatewireClient.OptimisticContext) => void;
|
|
154
|
-
export type HeadersValue = Record<string, string> | Headers;
|
|
155
|
-
export type Protocol = "data-stream" | "assistant-transport";
|
|
156
|
-
export type SendCommandsRequestBody = {
|
|
157
|
-
commands: Command[];
|
|
158
|
-
state: unknown;
|
|
159
|
-
system: string | undefined;
|
|
160
|
-
tools: Record<string, unknown> | undefined;
|
|
161
|
-
callSettings: LanguageModelV1CallSettings | undefined;
|
|
162
|
-
config: LanguageModelConfig | undefined;
|
|
163
|
-
threadId: string | null;
|
|
164
|
-
parentId?: string | null;
|
|
165
|
-
[key: string]: unknown;
|
|
166
|
-
};
|
|
167
|
-
export type Options<T> = {
|
|
168
|
-
initialState: T;
|
|
169
|
-
converter: StateConverter<T>;
|
|
170
|
-
optimistic?: Optimistic<T> | undefined;
|
|
171
|
-
/** 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. */
|
|
172
|
-
runs?: true | ((state: T) => unknown) | undefined;
|
|
173
|
-
/** Makes dispatch records concrete in the draft (runs after the optimistic folds); without it, dispatch limbo stays out of `messages`. */
|
|
174
|
-
materialize?: StatewireClient.Materialize<NonNullable<T>> | undefined;
|
|
175
|
-
api: string;
|
|
176
|
-
resumeApi?: string | undefined;
|
|
177
|
-
protocol?: Protocol | undefined;
|
|
178
|
-
headers: HeadersValue | (() => Promise<HeadersValue>);
|
|
179
|
-
body?: object | (() => Promise<object | undefined>) | undefined;
|
|
180
|
-
/** Transform the fully assembled request body before it is sent. */
|
|
181
|
-
prepareSendCommandsRequest?: ((body: SendCommandsRequestBody) => Record<string, unknown> | Promise<Record<string, unknown>>) | undefined;
|
|
182
|
-
onResponse?: ((response: Response) => void) | undefined;
|
|
183
|
-
onFinish?: (() => void) | undefined;
|
|
184
|
-
onError?: ((error: Error, params: {
|
|
185
|
-
commands: Command[];
|
|
186
|
-
updateState: (updater: (state: T) => T) => void;
|
|
187
|
-
}) => void | Promise<void>) | undefined;
|
|
188
|
-
/**
|
|
189
|
-
* Called when commands are cancelled. After an error, queued commands are
|
|
190
|
-
* cancelled once `onError` settles; `error` then carries the cause.
|
|
191
|
-
*/
|
|
192
|
-
onCancel?: ((params: {
|
|
193
|
-
commands: Command[];
|
|
194
|
-
updateState: (updater: (state: T) => T) => void;
|
|
195
|
-
error?: Error;
|
|
196
|
-
}) => void) | undefined;
|
|
197
|
-
capabilities?: {
|
|
198
|
-
edit?: boolean | undefined;
|
|
199
|
-
/**
|
|
200
|
-
* Buffer messages sent during a run in an in-memory queue and dispatch
|
|
201
|
-
* them once the run settles. Steering interrupts the active run.
|
|
202
|
-
* Mutually exclusive with the converter's `queue` projection.
|
|
203
|
-
*/
|
|
204
|
-
queue?: boolean | undefined;
|
|
205
|
-
/** The host supports `run/continue` (a continue affordance on aborted runs). */
|
|
206
|
-
continue?: boolean | undefined;
|
|
207
|
-
} | undefined;
|
|
208
|
-
adapters?: {
|
|
209
|
-
attachments?: AttachmentAdapter | undefined;
|
|
210
|
-
} | undefined;
|
|
211
|
-
};
|
|
212
|
-
export {};
|
|
213
|
-
}
|
|
214
|
-
//#endregion
|
|
215
|
-
export { AssistantTransportExtras, AssistantTransportThread, asAssistantTransportExtras, symbolAssistantTransportExtras };
|
|
216
|
-
//# 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;cA4ZU,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;;aAGI,SAAS;;aAET;;aAEA;OAEb;cAEU;aACD;;aAGI,SAAS;;aAET;;aAEA;OAEb;cAEU;aACD;aACA;;cAGC;aACD;aACA,SAAS;aACT;;aAEA;;cAGC;aACD;;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,UAAU;;;cAIT,oBAAoB;aACrB,UAAU;;cAGT;aACD;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"}
|