@assistant-ui/react-statewire 0.13.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 +62 -97
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +31 -46
- 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.map +1 -1
- package/dist/runCommands.d.ts +8 -24
- package/dist/runCommands.d.ts.map +1 -1
- package/dist/runCommands.js +3 -3
- package/dist/runCommands.js.map +1 -1
- package/dist/runsOptimistic.d.ts.map +1 -1
- package/dist/runsOptimistic.js +3 -2
- package/dist/runsOptimistic.js.map +1 -1
- package/package.json +4 -5
- package/src/StatewireThread.runs.test.tsx +10 -15
- package/src/StatewireThread.test.tsx +227 -405
- package/src/StatewireThread.ts +98 -210
- package/src/__tests__/testHelpers.tsx +6 -226
- package/src/hooks.ts +11 -32
- package/src/index.ts +2 -4
- package/src/inputRequests.ts +6 -8
- package/src/runCommands.ts +17 -23
- package/src/runsOptimistic.ts +5 -3
- package/dist/AssistantTransportThread.d.ts +0 -227
- package/dist/AssistantTransportThread.d.ts.map +0 -1
- package/dist/AssistantTransportThread.js +0 -264
- 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 -791
- package/src/athena.e2e.test.tsx +0 -654
- package/src/host.ts +0 -437
- package/src/legacy-diff.test.tsx +0 -628
- 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 -3001
package/src/StatewireThread.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import { resource, useResource } from "@assistant-ui/tap";
|
|
3
3
|
import type { ResourceElement } from "@assistant-ui/tap";
|
|
4
|
-
import { ExternalThread } from "@assistant-ui/
|
|
5
|
-
import type { ExternalThreadMessage } from "@assistant-ui/
|
|
4
|
+
import { ExternalThread } from "@assistant-ui/core/store";
|
|
5
|
+
import type { ExternalThreadMessage } from "@assistant-ui/core/store";
|
|
6
|
+
import type { Assistant } from "@assistant-ui/core";
|
|
6
7
|
import {
|
|
7
8
|
forwardTransformScopes,
|
|
8
9
|
useAssistantClientRef,
|
|
@@ -12,7 +13,6 @@ import type {
|
|
|
12
13
|
AddToolResultOptions,
|
|
13
14
|
AppendMessage,
|
|
14
15
|
AttachmentAdapter,
|
|
15
|
-
ExternalThreadQueueAdapter,
|
|
16
16
|
FeedbackAdapter,
|
|
17
17
|
ModelContext,
|
|
18
18
|
RespondToToolApprovalOptions,
|
|
@@ -23,11 +23,6 @@ import { toToolsJSONSchema } from "assistant-stream";
|
|
|
23
23
|
import type { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
24
24
|
import { useStatewire } from "statewire";
|
|
25
25
|
import type { Statewire, StatewireClient } from "statewire";
|
|
26
|
-
import { symbolAssistantTransportExtras } from "./AssistantTransportThread";
|
|
27
|
-
import type {
|
|
28
|
-
AssistantTransportExtras,
|
|
29
|
-
AssistantTransportThread,
|
|
30
|
-
} from "./AssistantTransportThread";
|
|
31
26
|
import {
|
|
32
27
|
createRunQueueAdapter,
|
|
33
28
|
resolveEditCommand,
|
|
@@ -43,9 +38,22 @@ import { runsOptimistic } from "./runsOptimistic";
|
|
|
43
38
|
|
|
44
39
|
type AnyCommands = Record<string, (...args: any[]) => unknown>;
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
export const symbolStatewireExtras = Symbol("statewire-extras");
|
|
42
|
+
|
|
43
|
+
export const asStatewireExtras = (extras: unknown): StatewireThread.Extras => {
|
|
44
|
+
if (
|
|
45
|
+
typeof extras !== "object" ||
|
|
46
|
+
extras == null ||
|
|
47
|
+
!(symbolStatewireExtras in extras)
|
|
48
|
+
)
|
|
49
|
+
throw new Error(
|
|
50
|
+
"This method can only be called when you are using StatewireThread",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return extras as StatewireThread.Extras;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const NO_INPUT_REQUESTS: readonly StatewireThread.InputRequestState[] = [];
|
|
49
57
|
|
|
50
58
|
const RESTING_RUNS: StatewireThread.Runs = {
|
|
51
59
|
runId: null,
|
|
@@ -66,7 +74,9 @@ const ambientContextOf = (context: ModelContext): Record<string, unknown> => ({
|
|
|
66
74
|
...(context.config !== undefined && { config: context.config }),
|
|
67
75
|
});
|
|
68
76
|
|
|
69
|
-
const useStatewireThread = (
|
|
77
|
+
const useStatewireThread = (
|
|
78
|
+
options: StatewireThread.Options<any>,
|
|
79
|
+
): ClientOutput<"thread"> => {
|
|
70
80
|
const latest = useRef(options);
|
|
71
81
|
latest.current = options;
|
|
72
82
|
|
|
@@ -82,48 +92,17 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
|
|
|
82
92
|
),
|
|
83
93
|
);
|
|
84
94
|
|
|
85
|
-
const runsOption = options.runs;
|
|
86
|
-
const [runsSeam] = useState(() => runsOption !== undefined);
|
|
87
|
-
if (runsSeam !== (runsOption !== undefined))
|
|
88
|
-
throw new Error(
|
|
89
|
-
"statewire: the runs option must be stable — it was " +
|
|
90
|
-
(runsSeam ? "set" : "unset") +
|
|
91
|
-
" on first render and changed since",
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const materializeOption = (options as StatewireThread.RunsOptions<unknown>)
|
|
95
|
-
.materialize;
|
|
96
|
-
const [materializeSeam] = useState(() => materializeOption !== undefined);
|
|
97
|
-
if (materializeSeam !== (materializeOption !== undefined))
|
|
98
|
-
throw new Error(
|
|
99
|
-
"statewire: the materialize option must be stable — it was " +
|
|
100
|
-
(materializeSeam ? "set" : "unset") +
|
|
101
|
-
" on first render and changed since",
|
|
102
|
-
);
|
|
103
|
-
|
|
104
95
|
const { state, commands, connection, setContext } = useStatewire<
|
|
105
96
|
unknown,
|
|
106
97
|
AnyCommands
|
|
107
98
|
>({
|
|
108
99
|
transport: options.transport,
|
|
109
100
|
initialState: options.initialState,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
draft,
|
|
116
|
-
command,
|
|
117
|
-
ctx,
|
|
118
|
-
);
|
|
119
|
-
},
|
|
120
|
-
}),
|
|
121
|
-
...(materializeSeam && {
|
|
122
|
-
materialize: (draft: {}) =>
|
|
123
|
-
(latest.current as StatewireThread.RunsOptions<unknown>).materialize!(
|
|
124
|
-
draft,
|
|
125
|
-
),
|
|
126
|
-
}),
|
|
101
|
+
optimistic: (draft, command, ctx) => {
|
|
102
|
+
runsOptimistic(draft, command, ctx);
|
|
103
|
+
latest.current.optimistic?.(draft, command, ctx);
|
|
104
|
+
},
|
|
105
|
+
materialize: (draft: {}) => latest.current.materialize?.(draft),
|
|
127
106
|
onCommandChange: (update, ctx) => {
|
|
128
107
|
if (update.status === "acked" || update.status === "settled")
|
|
129
108
|
retire(update.params[0]);
|
|
@@ -194,13 +173,11 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
|
|
|
194
173
|
|
|
195
174
|
const { status, runs } = useMemo((): {
|
|
196
175
|
status: StatewireThread.ThreadStatus;
|
|
197
|
-
runs
|
|
176
|
+
runs: StatewireThread.Runs;
|
|
198
177
|
} => {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
| undefined;
|
|
203
|
-
const entries = mount?.runs;
|
|
178
|
+
const entries = (
|
|
179
|
+
state as { runs?: readonly StatewireThread.RunState[] } | undefined
|
|
180
|
+
)?.runs;
|
|
204
181
|
const entry = entries?.[0];
|
|
205
182
|
return {
|
|
206
183
|
status: entries === undefined ? "loading" : (entry?.status ?? "ready"),
|
|
@@ -218,7 +195,7 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
|
|
|
218
195
|
error: entry.error,
|
|
219
196
|
},
|
|
220
197
|
};
|
|
221
|
-
}, [
|
|
198
|
+
}, [state]);
|
|
222
199
|
|
|
223
200
|
const { converter } = options;
|
|
224
201
|
const metadata = useMemo(
|
|
@@ -226,77 +203,43 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
|
|
|
226
203
|
pendingCommands: [...pending],
|
|
227
204
|
isSending: pending.length > 0,
|
|
228
205
|
connection,
|
|
229
|
-
|
|
206
|
+
runs,
|
|
230
207
|
}),
|
|
231
208
|
[pending, connection, runs],
|
|
232
209
|
);
|
|
233
210
|
const converted = useMemo(
|
|
234
|
-
(): StatewireThread.State =>
|
|
235
|
-
converter(
|
|
236
|
-
state,
|
|
237
|
-
metadata as StatewireThread.ConnectionMetadata & {
|
|
238
|
-
runs: StatewireThread.Runs;
|
|
239
|
-
},
|
|
240
|
-
) as StatewireThread.State,
|
|
211
|
+
(): StatewireThread.State => converter(state, metadata),
|
|
241
212
|
[converter, state, metadata],
|
|
242
213
|
);
|
|
243
214
|
// Dispatch limbo is a materialize concern: the fold makes the record
|
|
244
215
|
// concrete in state before conversion.
|
|
245
216
|
const messages = converted.messages;
|
|
246
|
-
const liveRunId = runs
|
|
247
|
-
const queueItems = runs !== undefined ? runs.queue : converted.queue;
|
|
248
|
-
const steerQueueItems =
|
|
249
|
-
runs !== undefined ? runs.steerQueue : converted.steerQueue;
|
|
250
|
-
if (steerQueueItems !== undefined && queueItems === undefined)
|
|
251
|
-
throw new Error(
|
|
252
|
-
"statewire: the converter's steerQueue projection requires the queue projection",
|
|
253
|
-
);
|
|
254
|
-
const [queueSeam] = useState(() => ({
|
|
255
|
-
present: queueItems !== undefined,
|
|
256
|
-
}));
|
|
257
|
-
if (queueSeam.present !== (queueItems !== undefined))
|
|
258
|
-
throw new Error(
|
|
259
|
-
"statewire: the converter's queue projection must be stable — it was " +
|
|
260
|
-
(queueSeam.present ? "defined" : "undefined") +
|
|
261
|
-
" on first convert and changed since",
|
|
262
|
-
);
|
|
217
|
+
const liveRunId = runs.runId;
|
|
263
218
|
|
|
264
219
|
const queue = useMemo(
|
|
265
|
-
()
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
: undefined,
|
|
276
|
-
[messages, liveRunId, queueItems, steerQueueItems, dispatch, dispatchSend],
|
|
220
|
+
() =>
|
|
221
|
+
createRunQueueAdapter(
|
|
222
|
+
messages,
|
|
223
|
+
liveRunId,
|
|
224
|
+
runs.queue,
|
|
225
|
+
runs.steerQueue,
|
|
226
|
+
dispatch,
|
|
227
|
+
dispatchSend,
|
|
228
|
+
),
|
|
229
|
+
[messages, liveRunId, runs, dispatch, dispatchSend],
|
|
277
230
|
);
|
|
278
231
|
|
|
279
|
-
const inputRequests =
|
|
280
|
-
runs !== undefined ? (runs.inputRequests ?? []) : converted.inputRequests;
|
|
281
|
-
const [inputSeam] = useState(() => ({
|
|
282
|
-
present: inputRequests !== undefined,
|
|
283
|
-
}));
|
|
284
|
-
if (inputSeam.present !== (inputRequests !== undefined))
|
|
285
|
-
throw new Error(
|
|
286
|
-
"statewire: the converter's inputRequests projection must be stable — it was " +
|
|
287
|
-
(inputSeam.present ? "defined" : "undefined") +
|
|
288
|
-
" on first convert and changed since",
|
|
289
|
-
);
|
|
232
|
+
const inputRequests = runs.inputRequests ?? NO_INPUT_REQUESTS;
|
|
290
233
|
|
|
291
234
|
const extras = useMemo(
|
|
292
|
-
():
|
|
293
|
-
[
|
|
235
|
+
(): StatewireThread.Extras => ({
|
|
236
|
+
[symbolStatewireExtras]: true,
|
|
294
237
|
sendCommand: dispatch,
|
|
295
238
|
reconnect: connection.reconnect,
|
|
296
239
|
state,
|
|
297
240
|
status,
|
|
298
|
-
|
|
299
|
-
|
|
241
|
+
inputRequests,
|
|
242
|
+
runs,
|
|
300
243
|
}),
|
|
301
244
|
[dispatch, connection.reconnect, state, status, inputRequests, runs],
|
|
302
245
|
);
|
|
@@ -328,15 +271,14 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
|
|
|
328
271
|
const thread = useResource(
|
|
329
272
|
ExternalThread({
|
|
330
273
|
messages: messages as readonly ExternalThreadMessage[],
|
|
331
|
-
isRunning:
|
|
332
|
-
runs !== undefined ? status === "running" : converted.isRunning,
|
|
274
|
+
isRunning: status === "running",
|
|
333
275
|
state: converted.state,
|
|
334
276
|
extras,
|
|
335
277
|
attachmentAdapter: options.adapters?.attachments,
|
|
336
278
|
speechAdapter: options.adapters?.speech,
|
|
337
279
|
feedbackAdapter: options.adapters?.feedback,
|
|
338
280
|
onNew: handleAppend,
|
|
339
|
-
|
|
281
|
+
queue,
|
|
340
282
|
...(options.capabilities?.edit && { onEdit: handleEdit }),
|
|
341
283
|
...(options.capabilities?.continue && {
|
|
342
284
|
onResume: () =>
|
|
@@ -346,16 +288,10 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
|
|
|
346
288
|
}),
|
|
347
289
|
}),
|
|
348
290
|
...(options.capabilities?.reload && { onReload: handleReload }),
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
),
|
|
354
|
-
onRespondToToolApproval: (approval: RespondToToolApprovalOptions) =>
|
|
355
|
-
dispatch(
|
|
356
|
-
resolveToolApprovalInput(inputRequests, approval, liveRunId),
|
|
357
|
-
),
|
|
358
|
-
}),
|
|
291
|
+
onAddToolResult: (toolOptions: AddToolResultOptions) =>
|
|
292
|
+
dispatch(resolveToolResultInput(inputRequests, toolOptions, liveRunId)),
|
|
293
|
+
onRespondToToolApproval: (approval: RespondToToolApprovalOptions) =>
|
|
294
|
+
dispatch(resolveToolApprovalInput(inputRequests, approval, liveRunId)),
|
|
359
295
|
onCancel: () => {
|
|
360
296
|
const payload = latest.current.stopPayload?.();
|
|
361
297
|
if (
|
|
@@ -365,16 +301,11 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
|
|
|
365
301
|
Array.isArray(payload))
|
|
366
302
|
)
|
|
367
303
|
throw new Error("statewire: stopPayload must return a plain object");
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
: [payload]
|
|
374
|
-
: [{ ...payload, runId }];
|
|
375
|
-
void commands["run/stop"]!(...args).catch((error: Error) => {
|
|
376
|
-
latest.current.onError?.(error);
|
|
377
|
-
});
|
|
304
|
+
void commands["run/stop"]!({ ...payload, runId: runs.runId }).catch(
|
|
305
|
+
(error: Error) => {
|
|
306
|
+
latest.current.onError?.(error);
|
|
307
|
+
},
|
|
308
|
+
);
|
|
378
309
|
},
|
|
379
310
|
}),
|
|
380
311
|
);
|
|
@@ -382,19 +313,26 @@ const useStatewireThread = (options: AnyOptions): ClientOutput<"thread"> => {
|
|
|
382
313
|
return thread;
|
|
383
314
|
};
|
|
384
315
|
|
|
385
|
-
export const StatewireThread
|
|
386
|
-
<T
|
|
387
|
-
|
|
388
|
-
)
|
|
389
|
-
<T>(
|
|
390
|
-
options: StatewireThread.Options<T>,
|
|
391
|
-
): ResourceElement<ClientOutput<"thread">>;
|
|
392
|
-
} = (options: AnyOptions): ResourceElement<ClientOutput<"thread">> =>
|
|
393
|
-
resource(useStatewireThread)(options);
|
|
316
|
+
export const StatewireThread = <T>(
|
|
317
|
+
options: StatewireThread.Options<T>,
|
|
318
|
+
): ResourceElement<ClientOutput<"thread">> =>
|
|
319
|
+
resource(useStatewireThread)(options as StatewireThread.Options<any>);
|
|
394
320
|
|
|
395
321
|
export namespace StatewireThread {
|
|
322
|
+
type UserCommands = Assistant.Commands[keyof Assistant.Commands];
|
|
323
|
+
|
|
396
324
|
export type Transport<T> = ResourceElement<Statewire<T | undefined, any>>;
|
|
397
325
|
|
|
326
|
+
export type Extras = {
|
|
327
|
+
[symbolStatewireExtras]: true;
|
|
328
|
+
sendCommand: (command: Command) => void;
|
|
329
|
+
reconnect: () => void;
|
|
330
|
+
state: unknown;
|
|
331
|
+
status: ThreadStatus;
|
|
332
|
+
inputRequests: readonly InputRequestState[];
|
|
333
|
+
runs: Runs;
|
|
334
|
+
};
|
|
335
|
+
|
|
398
336
|
export type TextPart = {
|
|
399
337
|
readonly type: "text";
|
|
400
338
|
readonly text: string;
|
|
@@ -493,19 +431,6 @@ export namespace StatewireThread {
|
|
|
493
431
|
| ToolApprovalInputRequest
|
|
494
432
|
| CustomInputRequest;
|
|
495
433
|
|
|
496
|
-
export type ToolCallInputResponse = {
|
|
497
|
-
readonly output: ReadonlyJSONValue;
|
|
498
|
-
/** Default false; when true, `output` carries the error payload. */
|
|
499
|
-
readonly isError?: boolean;
|
|
500
|
-
readonly artifact?: ReadonlyJSONValue;
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
export type ToolApprovalInputResponse = {
|
|
504
|
-
readonly decision: "approve" | "reject" | "edit" | "respond";
|
|
505
|
-
readonly editedArgs?: ReadonlyJSONValue;
|
|
506
|
-
readonly message?: string;
|
|
507
|
-
};
|
|
508
|
-
|
|
509
434
|
export type InputResponse = ReadonlyJSONValue;
|
|
510
435
|
|
|
511
436
|
export type RunInputCommand = {
|
|
@@ -538,38 +463,14 @@ export namespace StatewireThread {
|
|
|
538
463
|
| RunReloadCommand
|
|
539
464
|
| RunInputCommand;
|
|
540
465
|
|
|
541
|
-
export type Command =
|
|
466
|
+
export type Command = RunCommand | UserCommands;
|
|
542
467
|
|
|
543
468
|
/** A queued message projected out of the host state, wire shape. */
|
|
544
|
-
export type
|
|
469
|
+
export type RunQueueItem = {
|
|
545
470
|
readonly id: string;
|
|
546
471
|
readonly parts: readonly (TextPart | FilePart)[];
|
|
547
472
|
};
|
|
548
473
|
|
|
549
|
-
export type State = {
|
|
550
|
-
readonly messages: readonly ThreadMessage[];
|
|
551
|
-
readonly state?: ReadonlyJSONValue;
|
|
552
|
-
readonly isRunning: boolean;
|
|
553
|
-
/** The live run's id projected out of the host state; stamped onto `run/stop`. */
|
|
554
|
-
readonly runId?: string | null;
|
|
555
|
-
/**
|
|
556
|
-
* The host's regular queue lane projected out of the state. Returning it
|
|
557
|
-
* (even empty) turns on the queue capability: sends become `run/enqueue`
|
|
558
|
-
* / `run/steer` commands and item controls send the `run/*` queue
|
|
559
|
-
* commands. Presence must be stable across conversions.
|
|
560
|
-
*/
|
|
561
|
-
readonly queue?: readonly QueueItem[];
|
|
562
|
-
/** The host's steer lane; requires `queue`. Absent means empty. */
|
|
563
|
-
readonly steerQueue?: readonly QueueItem[];
|
|
564
|
-
/**
|
|
565
|
-
* The host's parked input requests projected out of the state. Returning
|
|
566
|
-
* it (even empty) routes tool results and approvals with a matching
|
|
567
|
-
* pending request through `run/input`. Presence must be stable across
|
|
568
|
-
* conversions.
|
|
569
|
-
*/
|
|
570
|
-
readonly inputRequests?: readonly InputRequestState[];
|
|
571
|
-
};
|
|
572
|
-
|
|
573
474
|
/** Run subsystem status replicated by the host. */
|
|
574
475
|
export type RunStatus = "running" | "stopped" | "error" | "input-required";
|
|
575
476
|
|
|
@@ -642,7 +543,7 @@ export namespace StatewireThread {
|
|
|
642
543
|
readonly runs: readonly RunState[];
|
|
643
544
|
};
|
|
644
545
|
|
|
645
|
-
/** The run subsystem's typed read — `runs[0]` of the
|
|
546
|
+
/** The run subsystem's typed read — `runs[0]` of the state with unsettled commands folded in, resting defaults while no entry is live. */
|
|
646
547
|
export type Runs = {
|
|
647
548
|
/** The live run's id — non-null whenever a run entry is live (running, input-required, error/stop); the target for `run/*` sends. */
|
|
648
549
|
readonly runId: string | null;
|
|
@@ -660,25 +561,20 @@ export namespace StatewireThread {
|
|
|
660
561
|
isSending: boolean;
|
|
661
562
|
/** Statewire connection status; local transports are always `live`. */
|
|
662
563
|
connection: StatewireClient.ConnectionState;
|
|
663
|
-
/** The typed runs read
|
|
664
|
-
runs
|
|
564
|
+
/** The typed runs read. */
|
|
565
|
+
runs: Runs;
|
|
665
566
|
};
|
|
666
567
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
connectionMetadata: ConnectionMetadata,
|
|
670
|
-
) => State;
|
|
671
|
-
|
|
672
|
-
/** Converter output in runs mode: app-owned keys only — the lib projects the run mounts itself. */
|
|
673
|
-
export type RunsConverterState = {
|
|
568
|
+
/** Converter output: app-owned keys only — the lib projects the run mounts itself. */
|
|
569
|
+
export type State = {
|
|
674
570
|
readonly messages: readonly ThreadMessage[];
|
|
675
571
|
readonly state?: ReadonlyJSONValue;
|
|
676
572
|
};
|
|
677
573
|
|
|
678
|
-
export type
|
|
574
|
+
export type StateConverter<T> = (
|
|
679
575
|
state: T,
|
|
680
|
-
connectionMetadata: ConnectionMetadata
|
|
681
|
-
) =>
|
|
576
|
+
connectionMetadata: ConnectionMetadata,
|
|
577
|
+
) => State;
|
|
682
578
|
|
|
683
579
|
/**
|
|
684
580
|
* Payload of the built-in `run/stop` command. `reason` is the one well-known
|
|
@@ -691,10 +587,18 @@ export namespace StatewireThread {
|
|
|
691
587
|
|
|
692
588
|
export type Options<T> = {
|
|
693
589
|
transport: Transport<T>;
|
|
694
|
-
/** The pre-attach state, replaced by the attach snapshot.
|
|
590
|
+
/** The pre-attach state, replaced by the attach snapshot. `runs: []` projects ready (interactive from the first render); an absent runs mount projects loading until attach. */
|
|
695
591
|
initialState: T;
|
|
696
592
|
converter: StateConverter<T>;
|
|
697
|
-
runs
|
|
593
|
+
/** Folds app-owned keys for an unsettled command into the draft; runs after the lib's run-dialect reducer. */
|
|
594
|
+
optimistic?:
|
|
595
|
+
| StatewireClient.Optimistic<
|
|
596
|
+
T,
|
|
597
|
+
Record<string, (...args: any[]) => unknown>
|
|
598
|
+
>
|
|
599
|
+
| undefined;
|
|
600
|
+
/** Makes dispatch records concrete in the draft (runs after the optimistic folds); without it, dispatch limbo stays out of `messages`. */
|
|
601
|
+
materialize?: StatewireClient.Materialize<NonNullable<T>> | undefined;
|
|
698
602
|
/**
|
|
699
603
|
* "command-send" mirrors the client's ambient model context (system,
|
|
700
604
|
* tools, callSettings, config) to the server over the command channel —
|
|
@@ -738,25 +642,9 @@ export namespace StatewireThread {
|
|
|
738
642
|
}
|
|
739
643
|
| undefined;
|
|
740
644
|
};
|
|
741
|
-
|
|
742
|
-
/** Options with the runs read enabled: the lib types the run mounts and the converter returns app-owned keys only. */
|
|
743
|
-
export type RunsOptions<T> = Omit<Options<T>, "converter" | "runs"> & {
|
|
744
|
-
/** `true` reads the run mounts off the state root; a selector picks a nested mount. */
|
|
745
|
-
runs: true | ((state: T) => unknown);
|
|
746
|
-
converter: RunsStateConverter<T>;
|
|
747
|
-
/** Folds app-owned keys for an unsettled command into the draft; runs after the lib's run-dialect reducer. */
|
|
748
|
-
optimistic?:
|
|
749
|
-
| StatewireClient.Optimistic<
|
|
750
|
-
T,
|
|
751
|
-
Record<string, (...args: any[]) => unknown>
|
|
752
|
-
>
|
|
753
|
-
| undefined;
|
|
754
|
-
/** Makes dispatch records concrete in the draft (runs after the optimistic folds); without it, dispatch limbo stays out of `messages`. */
|
|
755
|
-
materialize?: StatewireClient.Materialize<NonNullable<T>> | undefined;
|
|
756
|
-
};
|
|
757
645
|
}
|
|
758
646
|
|
|
759
|
-
declare module "@assistant-ui/
|
|
647
|
+
declare module "@assistant-ui/core" {
|
|
760
648
|
namespace Assistant {
|
|
761
649
|
interface Commands {
|
|
762
650
|
runEnqueue: StatewireThread.RunEnqueueCommand;
|