@assistant-ui/react-statewire 0.4.3 → 0.5.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/AssistantTransportThread.d.ts +193 -4
- package/dist/AssistantTransportThread.d.ts.map +1 -1
- package/dist/AssistantTransportThread.js +12 -16
- package/dist/AssistantTransportThread.js.map +1 -1
- package/dist/StatewireThread.d.ts +92 -11
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +74 -45
- package/dist/StatewireThread.js.map +1 -1
- package/dist/hooks.d.ts +8 -3
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +10 -1
- package/dist/hooks.js.map +1 -1
- package/dist/host.d.ts +5 -5
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +3 -38
- package/dist/index.js +2 -2
- 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 -7
- package/dist/runCommands.d.ts.map +1 -1
- package/dist/runCommands.js +25 -11
- package/dist/runCommands.js.map +1 -1
- package/dist/runsOptimistic.d.ts +7 -0
- package/dist/runsOptimistic.d.ts.map +1 -0
- package/dist/runsOptimistic.js +92 -0
- package/dist/runsOptimistic.js.map +1 -0
- package/package.json +3 -3
- package/src/AssistantTransportThread.ts +267 -24
- package/src/StatewireThread.runs.test.tsx +405 -0
- package/src/StatewireThread.test.tsx +180 -3
- package/src/StatewireThread.ts +223 -80
- package/src/__tests__/testHelpers.tsx +11 -17
- package/src/athena.e2e.test.tsx +15 -19
- package/src/hooks.ts +19 -2
- package/src/host.ts +11 -13
- package/src/index.ts +2 -36
- package/src/inputRequests.ts +8 -6
- package/src/legacy-diff.test.tsx +4 -7
- package/src/runCommands.ts +42 -28
- package/src/runsOptimistic.test.ts +225 -0
- package/src/runsOptimistic.ts +164 -0
- package/src/transport.test.tsx +12 -16
- package/dist/index.d.ts.map +0 -1
- package/dist/types.d.ts +0 -189
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -0
- package/src/types.ts +0 -255
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { Statewire, StatewireClient } from "statewire";
|
|
2
|
+
import type { StatewireThread } from "./StatewireThread";
|
|
3
|
+
|
|
4
|
+
type LaneEntry = {
|
|
5
|
+
id: string;
|
|
6
|
+
role: "user";
|
|
7
|
+
parts: readonly (StatewireThread.TextPart | StatewireThread.FilePart)[];
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
meta?: unknown;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type RunEntry = {
|
|
13
|
+
runId: string | null;
|
|
14
|
+
status: StatewireThread.RunStatus;
|
|
15
|
+
queue: LaneEntry[];
|
|
16
|
+
steerQueue: LaneEntry[];
|
|
17
|
+
inputRequests?: { id: string; response: unknown }[];
|
|
18
|
+
error: unknown;
|
|
19
|
+
runLeafMessageId: string | null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type RunsDraft = {
|
|
23
|
+
status: StatewireThread.RunStatus;
|
|
24
|
+
runs: RunEntry[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const startRun = (draft: RunsDraft, runId: string): void => {
|
|
28
|
+
const entry = (draft.runs[0] ??= {
|
|
29
|
+
runId: null,
|
|
30
|
+
status: "running",
|
|
31
|
+
queue: [],
|
|
32
|
+
steerQueue: [],
|
|
33
|
+
error: null,
|
|
34
|
+
runLeafMessageId: null,
|
|
35
|
+
});
|
|
36
|
+
entry.status = "running";
|
|
37
|
+
entry.runId = runId;
|
|
38
|
+
entry.error = null;
|
|
39
|
+
delete entry.inputRequests;
|
|
40
|
+
draft.status = "running";
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const insert = (
|
|
44
|
+
lane: LaneEntry[],
|
|
45
|
+
entry: LaneEntry,
|
|
46
|
+
{ insertAfter, insertBefore }: StatewireThread.Placement,
|
|
47
|
+
): void => {
|
|
48
|
+
const index =
|
|
49
|
+
insertAfter !== undefined
|
|
50
|
+
? insertAfter === null
|
|
51
|
+
? 0
|
|
52
|
+
: lane.findIndex((e) => e.id === insertAfter) + 1
|
|
53
|
+
: insertBefore === undefined || insertBefore === null
|
|
54
|
+
? lane.length
|
|
55
|
+
: lane.findIndex((e) => e.id === insertBefore);
|
|
56
|
+
lane.splice(index < 0 ? lane.length : index, 0, entry);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const enqueueOrSteer = (
|
|
60
|
+
draft: RunsDraft,
|
|
61
|
+
command: StatewireThread.RunEnqueueCommand | StatewireThread.RunSteerCommand,
|
|
62
|
+
runId: string,
|
|
63
|
+
): void => {
|
|
64
|
+
const run = draft.runs[0];
|
|
65
|
+
const id = "message" in command ? command.message.id : command.messageId;
|
|
66
|
+
const sourceLane =
|
|
67
|
+
run === undefined
|
|
68
|
+
? undefined
|
|
69
|
+
: [run.queue, run.steerQueue].find((l) => l.some((e) => e.id === id));
|
|
70
|
+
|
|
71
|
+
let entry: LaneEntry;
|
|
72
|
+
let sourceIndex = -1;
|
|
73
|
+
if (sourceLane !== undefined) {
|
|
74
|
+
sourceIndex = sourceLane.findIndex((e) => e.id === id);
|
|
75
|
+
entry = sourceLane.splice(sourceIndex, 1)[0]!;
|
|
76
|
+
if ("message" in command) {
|
|
77
|
+
entry.parts = command.message.parts;
|
|
78
|
+
if (command.message.metadata !== undefined)
|
|
79
|
+
entry.metadata = command.message.metadata;
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
if (!("message" in command)) return;
|
|
83
|
+
entry = { ...command.message };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const dispatching =
|
|
87
|
+
command.type === "run/steer"
|
|
88
|
+
? draft.status !== "running"
|
|
89
|
+
: sourceLane === undefined &&
|
|
90
|
+
(draft.status === "ready" ||
|
|
91
|
+
((draft.status === "stopped" || draft.status === "error") &&
|
|
92
|
+
run !== undefined &&
|
|
93
|
+
run.queue.length === 0 &&
|
|
94
|
+
run.steerQueue.length === 0));
|
|
95
|
+
if (dispatching) {
|
|
96
|
+
if (command.type === "run/steer" && run !== undefined) run.steerQueue = [];
|
|
97
|
+
startRun(draft, runId);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (run === undefined) return;
|
|
102
|
+
const lane = command.type === "run/steer" ? run.steerQueue : run.queue;
|
|
103
|
+
const hasPlacement =
|
|
104
|
+
command.insertAfter !== undefined || command.insertBefore !== undefined;
|
|
105
|
+
if (sourceLane === lane && !hasPlacement) lane.splice(sourceIndex, 0, entry);
|
|
106
|
+
else insert(lane, entry, command);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/** The run dialect's optimistic reducer: folds an unsettled `run/*` command into the mount draft. */
|
|
110
|
+
export const runsOptimistic = (
|
|
111
|
+
mount: unknown,
|
|
112
|
+
command: Statewire.Command<Record<string, (...args: any[]) => unknown>>,
|
|
113
|
+
ctx: StatewireClient.OptimisticContext,
|
|
114
|
+
): void => {
|
|
115
|
+
const draft = mount as RunsDraft;
|
|
116
|
+
const runId = `optimistic-${ctx.seq}`;
|
|
117
|
+
switch (command.method) {
|
|
118
|
+
case "run/enqueue":
|
|
119
|
+
case "run/steer": {
|
|
120
|
+
enqueueOrSteer(
|
|
121
|
+
draft,
|
|
122
|
+
command.params[0] as
|
|
123
|
+
| StatewireThread.RunEnqueueCommand
|
|
124
|
+
| StatewireThread.RunSteerCommand,
|
|
125
|
+
runId,
|
|
126
|
+
);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case "run/edit":
|
|
130
|
+
case "run/reload": {
|
|
131
|
+
startRun(draft, runId);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case "run/continue": {
|
|
135
|
+
const run = draft.runs[0];
|
|
136
|
+
if (run !== undefined) run.steerQueue = [];
|
|
137
|
+
startRun(draft, runId);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case "run/dequeue": {
|
|
141
|
+
const { messageId } = command
|
|
142
|
+
.params[0] as StatewireThread.RunDequeueCommand;
|
|
143
|
+
const run = draft.runs[0];
|
|
144
|
+
if (run === undefined) break;
|
|
145
|
+
for (const lane of [run.queue, run.steerQueue]) {
|
|
146
|
+
const index = lane.findIndex((e) => e.id === messageId);
|
|
147
|
+
if (index !== -1) lane.splice(index, 1);
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case "run/input": {
|
|
152
|
+
const { requestId, response } = command
|
|
153
|
+
.params[0] as StatewireThread.RunInputCommand;
|
|
154
|
+
const requests = draft.runs[0]?.inputRequests;
|
|
155
|
+
const target = requests?.find((r) => r.id === requestId);
|
|
156
|
+
if (target === undefined) break;
|
|
157
|
+
target.response = response;
|
|
158
|
+
if (requests!.every((r) => r.response !== null)) startRun(draft, runId);
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
default:
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
};
|
package/src/transport.test.tsx
CHANGED
|
@@ -20,11 +20,7 @@ import {
|
|
|
20
20
|
useAssistantTransportSendCommand,
|
|
21
21
|
useAssistantTransportState,
|
|
22
22
|
} from "./hooks";
|
|
23
|
-
|
|
24
|
-
AssistantTransportCommand,
|
|
25
|
-
AssistantTransportConnectionMetadata,
|
|
26
|
-
InputRequestState,
|
|
27
|
-
} from "./types";
|
|
23
|
+
|
|
28
24
|
import {
|
|
29
25
|
INITIAL_STATE,
|
|
30
26
|
abortableStream,
|
|
@@ -142,7 +138,7 @@ describe("AssistantTransportThread", () => {
|
|
|
142
138
|
return server.response;
|
|
143
139
|
});
|
|
144
140
|
|
|
145
|
-
const metas:
|
|
141
|
+
const metas: AssistantTransportThread.ConnectionMetadata[] = [];
|
|
146
142
|
const converter: typeof defaultConverter = (state, meta) => {
|
|
147
143
|
metas.push(meta);
|
|
148
144
|
return defaultConverter(state, meta);
|
|
@@ -328,7 +324,7 @@ describe("AssistantTransportThread", () => {
|
|
|
328
324
|
return server.response;
|
|
329
325
|
});
|
|
330
326
|
|
|
331
|
-
const errored:
|
|
327
|
+
const errored: AssistantTransportThread.Command[][] = [];
|
|
332
328
|
const { aui } = mountThread({
|
|
333
329
|
onError: (_error, { commands }) => {
|
|
334
330
|
errored.push(commands);
|
|
@@ -401,7 +397,7 @@ describe("AssistantTransportThread", () => {
|
|
|
401
397
|
const fetchMock = installFetch();
|
|
402
398
|
fetchMock.setHandler(({ init }) => abortableStream(init).response);
|
|
403
399
|
|
|
404
|
-
const cancelled:
|
|
400
|
+
const cancelled: AssistantTransportThread.Command[][] = [];
|
|
405
401
|
const errors: string[] = [];
|
|
406
402
|
const { aui } = mountThread({
|
|
407
403
|
onCancel: ({ commands, error }) => {
|
|
@@ -1087,7 +1083,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1087
1083
|
return server.response;
|
|
1088
1084
|
});
|
|
1089
1085
|
|
|
1090
|
-
const metas:
|
|
1086
|
+
const metas: AssistantTransportThread.ConnectionMetadata[] = [];
|
|
1091
1087
|
const { aui } = mountThread({ converter: toolCallConverter(metas) });
|
|
1092
1088
|
aui()
|
|
1093
1089
|
.modelContext()
|
|
@@ -1322,7 +1318,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1322
1318
|
resolveExecute = resolve;
|
|
1323
1319
|
});
|
|
1324
1320
|
|
|
1325
|
-
const metas:
|
|
1321
|
+
const metas: AssistantTransportThread.ConnectionMetadata[] = [];
|
|
1326
1322
|
const { aui } = mountThread({ converter: toolCallConverter(metas) });
|
|
1327
1323
|
aui()
|
|
1328
1324
|
.modelContext()
|
|
@@ -1374,7 +1370,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1374
1370
|
return server.response;
|
|
1375
1371
|
});
|
|
1376
1372
|
|
|
1377
|
-
const metas:
|
|
1373
|
+
const metas: AssistantTransportThread.ConnectionMetadata[] = [];
|
|
1378
1374
|
const { aui } = mountThread({ converter: toolCallConverter(metas) });
|
|
1379
1375
|
aui()
|
|
1380
1376
|
.modelContext()
|
|
@@ -1432,7 +1428,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1432
1428
|
return server.response;
|
|
1433
1429
|
});
|
|
1434
1430
|
|
|
1435
|
-
const metas:
|
|
1431
|
+
const metas: AssistantTransportThread.ConnectionMetadata[] = [];
|
|
1436
1432
|
const { aui } = mountThread({ converter: toolCallConverter(metas) });
|
|
1437
1433
|
aui()
|
|
1438
1434
|
.modelContext()
|
|
@@ -1481,7 +1477,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1481
1477
|
return server.response;
|
|
1482
1478
|
});
|
|
1483
1479
|
|
|
1484
|
-
const metas:
|
|
1480
|
+
const metas: AssistantTransportThread.ConnectionMetadata[] = [];
|
|
1485
1481
|
const { aui } = mountThread({ converter: toolCallConverter(metas) });
|
|
1486
1482
|
aui()
|
|
1487
1483
|
.modelContext()
|
|
@@ -1824,7 +1820,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1824
1820
|
|
|
1825
1821
|
const captured: {
|
|
1826
1822
|
state?: TestState;
|
|
1827
|
-
send?: (command:
|
|
1823
|
+
send?: (command: AssistantTransportThread.Command) => void;
|
|
1828
1824
|
} = {};
|
|
1829
1825
|
const HookCapture: FC = () => {
|
|
1830
1826
|
captured.state = useAssistantTransportState() as TestState;
|
|
@@ -1846,7 +1842,7 @@ describe("AssistantTransportThread", () => {
|
|
|
1846
1842
|
type S = TestState & { toolCall?: { id: string; result?: string } };
|
|
1847
1843
|
const converter = (
|
|
1848
1844
|
state: S,
|
|
1849
|
-
meta:
|
|
1845
|
+
meta: AssistantTransportThread.ConnectionMetadata,
|
|
1850
1846
|
) => {
|
|
1851
1847
|
const tc = state.toolCall;
|
|
1852
1848
|
return {
|
|
@@ -2350,7 +2346,7 @@ describe("server queue projection", () => {
|
|
|
2350
2346
|
describe("input requests", () => {
|
|
2351
2347
|
type InputState = TestState & {
|
|
2352
2348
|
toolCall?: { id: string; name: string; argsText: string };
|
|
2353
|
-
inputRequests?: InputRequestState[];
|
|
2349
|
+
inputRequests?: AssistantTransportThread.InputRequestState[];
|
|
2354
2350
|
};
|
|
2355
2351
|
|
|
2356
2352
|
const requestConverter = (approval?: {
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;kBAUiB;OACH,QAAQ,KAAK,0BAAgC;OAC7C,UAAU;OACV,WAAW;OACX,QAAQ;OACR,qBAAqB;OACrB,eAAe,KAAK,iCAAuC;OAC3D,aAAa;OACb,oBAAoB;OACpB,kBAAkB;OAClB,oBAAoB;OACpB,iBAAiB;OACjB,qBAAqB;OACrB,mBAAmB;OACnB,kBAAkB;OAClB,eAAe;OACf,uBAAuB;OACvB,2BAA2B;OAC3B,qBAAqB;OACrB,oBAAoB;OACpB,gBAAgB;OAChB,wBAAwB;OACxB,4BAA4B;OAC5B,iBAAiB;OACjB,eAAe;OACf,eAAe;OACf,0BAA0B;OAC1B,WAAW;OACX,WAAW;OACX,eAAe"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { Assistant } from "@assistant-ui/react";
|
|
2
|
-
import { AttachmentAdapter, LanguageModelConfig, LanguageModelV1CallSettings, ThreadMessage, ToolExecutionStatus } from "@assistant-ui/core";
|
|
3
|
-
import { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
type UserCommands = Assistant.Commands[keyof Assistant.Commands];
|
|
6
|
-
type UserExternalState = keyof Assistant.ExternalState extends never ? Record<string, unknown> : Assistant.ExternalState[keyof Assistant.ExternalState];
|
|
7
|
-
type TextPart = {
|
|
8
|
-
readonly type: "text";
|
|
9
|
-
readonly text: string;
|
|
10
|
-
};
|
|
11
|
-
type FilePart = {
|
|
12
|
-
readonly type: "file";
|
|
13
|
-
readonly mediaType: string;
|
|
14
|
-
readonly url: string;
|
|
15
|
-
readonly filename?: string;
|
|
16
|
-
};
|
|
17
|
-
type RunUserMessage = {
|
|
18
|
-
readonly id: string;
|
|
19
|
-
readonly role: "user";
|
|
20
|
-
readonly parts: readonly (TextPart | FilePart)[];
|
|
21
|
-
readonly metadata?: Record<string, unknown>;
|
|
22
|
-
};
|
|
23
|
-
/** Queue placement fields, flat on the command. Absent is load-bearing: it means default placement; `null` names a queue boundary. */
|
|
24
|
-
type RunPlacement = {
|
|
25
|
-
readonly insertAfter?: string | null;
|
|
26
|
-
readonly insertBefore?: string | null;
|
|
27
|
-
};
|
|
28
|
-
type RunEnqueueCommand = {
|
|
29
|
-
readonly type: "run/enqueue";
|
|
30
|
-
} & ({
|
|
31
|
-
readonly message: RunUserMessage;
|
|
32
|
-
/** 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. */
|
|
33
|
-
readonly anchorMessageId?: string | null;
|
|
34
|
-
} | {
|
|
35
|
-
readonly messageId: string;
|
|
36
|
-
}) & RunPlacement;
|
|
37
|
-
type RunSteerCommand = {
|
|
38
|
-
readonly type: "run/steer";
|
|
39
|
-
} & ({
|
|
40
|
-
readonly message: RunUserMessage;
|
|
41
|
-
/** 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. */
|
|
42
|
-
readonly anchorMessageId?: string | null;
|
|
43
|
-
} | {
|
|
44
|
-
readonly messageId: string;
|
|
45
|
-
}) & RunPlacement;
|
|
46
|
-
type RunDequeueCommand = {
|
|
47
|
-
readonly type: "run/dequeue";
|
|
48
|
-
readonly messageId: string;
|
|
49
|
-
};
|
|
50
|
-
type RunEditCommand = {
|
|
51
|
-
readonly type: "run/edit";
|
|
52
|
-
readonly message: RunUserMessage;
|
|
53
|
-
readonly sourceId: string;
|
|
54
|
-
};
|
|
55
|
-
type RunContinueCommand = {
|
|
56
|
-
readonly type: "run/continue";
|
|
57
|
-
};
|
|
58
|
-
type ToolCallInputRequest = {
|
|
59
|
-
readonly type: "tool-call";
|
|
60
|
-
readonly id: string;
|
|
61
|
-
readonly toolCallId: string;
|
|
62
|
-
};
|
|
63
|
-
type ToolApprovalInputRequest = {
|
|
64
|
-
readonly type: "tool-approval";
|
|
65
|
-
readonly id: string;
|
|
66
|
-
readonly toolCallId: string;
|
|
67
|
-
};
|
|
68
|
-
type CustomInputRequest = {
|
|
69
|
-
readonly type: string;
|
|
70
|
-
readonly id: string;
|
|
71
|
-
readonly [key: string]: ReadonlyJSONValue | undefined;
|
|
72
|
-
};
|
|
73
|
-
/** A host request parking the run until answered; open union for custom types. */
|
|
74
|
-
type InputRequest = ToolCallInputRequest | ToolApprovalInputRequest | CustomInputRequest;
|
|
75
|
-
type ToolCallInputResponse = {
|
|
76
|
-
readonly output: ReadonlyJSONValue;
|
|
77
|
-
/** Default false; when true, `output` carries the error payload. */
|
|
78
|
-
readonly isError?: boolean;
|
|
79
|
-
readonly artifact?: ReadonlyJSONValue;
|
|
80
|
-
};
|
|
81
|
-
type ToolApprovalInputResponse = {
|
|
82
|
-
readonly decision: "approve" | "reject" | "edit" | "respond";
|
|
83
|
-
readonly editedArgs?: ReadonlyJSONValue;
|
|
84
|
-
readonly message?: string;
|
|
85
|
-
};
|
|
86
|
-
type InputResponse = ReadonlyJSONValue;
|
|
87
|
-
type RunInputCommand = {
|
|
88
|
-
readonly type: "run/input";
|
|
89
|
-
readonly requestId: string;
|
|
90
|
-
readonly response: InputResponse;
|
|
91
|
-
};
|
|
92
|
-
/** An input request projected out of the host state with its response echo. */
|
|
93
|
-
type InputRequestState = InputRequest & {
|
|
94
|
-
readonly response: InputResponse | null;
|
|
95
|
-
};
|
|
96
|
-
type RunReloadCommand = {
|
|
97
|
-
readonly type: "run/reload";
|
|
98
|
-
readonly sourceId: string;
|
|
99
|
-
};
|
|
100
|
-
type RunCommand = RunEnqueueCommand | RunSteerCommand | RunDequeueCommand | RunEditCommand | RunContinueCommand | RunReloadCommand | RunInputCommand;
|
|
101
|
-
type AssistantTransportCommand = RunCommand | UserCommands;
|
|
102
|
-
/** A queued message projected out of the host state, wire shape. */
|
|
103
|
-
type RunQueueItem = {
|
|
104
|
-
readonly id: string;
|
|
105
|
-
readonly parts: readonly (TextPart | FilePart)[];
|
|
106
|
-
};
|
|
107
|
-
type AssistantTransportState = {
|
|
108
|
-
readonly messages: readonly ThreadMessage[];
|
|
109
|
-
readonly state?: ReadonlyJSONValue;
|
|
110
|
-
readonly isRunning: boolean;
|
|
111
|
-
/**
|
|
112
|
-
* The host's regular queue lane projected out of the state. Returning it
|
|
113
|
-
* (even empty) turns on the server-side queue: sends become `run/enqueue`
|
|
114
|
-
* / `run/steer` commands and item controls send the `run/*` queue
|
|
115
|
-
* commands. Presence must be stable across conversions and excludes the
|
|
116
|
-
* client-local `capabilities.queue` buffer.
|
|
117
|
-
*/
|
|
118
|
-
readonly queue?: readonly RunQueueItem[];
|
|
119
|
-
/** The host's steer lane; requires `queue`. Absent means empty. */
|
|
120
|
-
readonly steerQueue?: readonly RunQueueItem[];
|
|
121
|
-
/**
|
|
122
|
-
* The host's parked input requests projected out of the state. Returning it
|
|
123
|
-
* (even empty) routes tool results and approvals with a matching pending
|
|
124
|
-
* request through `run/input`. Presence must be stable across conversions.
|
|
125
|
-
*/
|
|
126
|
-
readonly inputRequests?: readonly InputRequestState[];
|
|
127
|
-
};
|
|
128
|
-
type AssistantTransportConnectionMetadata = {
|
|
129
|
-
pendingCommands: AssistantTransportCommand[];
|
|
130
|
-
isSending: boolean;
|
|
131
|
-
toolStatuses: Record<string, ToolExecutionStatus>;
|
|
132
|
-
};
|
|
133
|
-
type AssistantTransportStateConverter<T> = (state: T, connectionMetadata: AssistantTransportConnectionMetadata) => AssistantTransportState;
|
|
134
|
-
type HeadersValue = Record<string, string> | Headers;
|
|
135
|
-
type AssistantTransportProtocol = "data-stream" | "assistant-transport";
|
|
136
|
-
type SendCommandsRequestBody = {
|
|
137
|
-
commands: AssistantTransportCommand[];
|
|
138
|
-
state: unknown;
|
|
139
|
-
system: string | undefined;
|
|
140
|
-
tools: Record<string, unknown> | undefined;
|
|
141
|
-
callSettings: LanguageModelV1CallSettings | undefined;
|
|
142
|
-
config: LanguageModelConfig | undefined;
|
|
143
|
-
threadId: string | null;
|
|
144
|
-
parentId?: string | null;
|
|
145
|
-
[key: string]: unknown;
|
|
146
|
-
};
|
|
147
|
-
type AssistantTransportOptions<T> = {
|
|
148
|
-
initialState: T;
|
|
149
|
-
converter: AssistantTransportStateConverter<T>;
|
|
150
|
-
api: string;
|
|
151
|
-
resumeApi?: string | undefined;
|
|
152
|
-
protocol?: AssistantTransportProtocol | undefined;
|
|
153
|
-
headers: HeadersValue | (() => Promise<HeadersValue>);
|
|
154
|
-
body?: object | (() => Promise<object | undefined>) | undefined;
|
|
155
|
-
/** Transform the fully assembled request body before it is sent. */
|
|
156
|
-
prepareSendCommandsRequest?: ((body: SendCommandsRequestBody) => Record<string, unknown> | Promise<Record<string, unknown>>) | undefined;
|
|
157
|
-
onResponse?: ((response: Response) => void) | undefined;
|
|
158
|
-
onFinish?: (() => void) | undefined;
|
|
159
|
-
onError?: ((error: Error, params: {
|
|
160
|
-
commands: AssistantTransportCommand[];
|
|
161
|
-
updateState: (updater: (state: T) => T) => void;
|
|
162
|
-
}) => void | Promise<void>) | undefined;
|
|
163
|
-
/**
|
|
164
|
-
* Called when commands are cancelled. After an error, queued commands are
|
|
165
|
-
* cancelled once `onError` settles; `error` then carries the cause.
|
|
166
|
-
*/
|
|
167
|
-
onCancel?: ((params: {
|
|
168
|
-
commands: AssistantTransportCommand[];
|
|
169
|
-
updateState: (updater: (state: T) => T) => void;
|
|
170
|
-
error?: Error;
|
|
171
|
-
}) => void) | undefined;
|
|
172
|
-
capabilities?: {
|
|
173
|
-
edit?: boolean | undefined;
|
|
174
|
-
/**
|
|
175
|
-
* Buffer messages sent during a run in an in-memory queue and dispatch
|
|
176
|
-
* them once the run settles. Steering interrupts the active run.
|
|
177
|
-
* Mutually exclusive with the converter's `queue` projection.
|
|
178
|
-
*/
|
|
179
|
-
queue?: boolean | undefined;
|
|
180
|
-
/** The host supports `run/continue` (a continue affordance on aborted runs). */
|
|
181
|
-
continue?: boolean | undefined;
|
|
182
|
-
} | undefined;
|
|
183
|
-
adapters?: {
|
|
184
|
-
attachments?: AttachmentAdapter | undefined;
|
|
185
|
-
} | undefined;
|
|
186
|
-
};
|
|
187
|
-
//#endregion
|
|
188
|
-
export { AssistantTransportCommand, AssistantTransportConnectionMetadata, AssistantTransportOptions, AssistantTransportProtocol, AssistantTransportState, AssistantTransportStateConverter, CustomInputRequest, FilePart, HeadersValue, InputRequest, InputRequestState, InputResponse, RunCommand, RunContinueCommand, RunDequeueCommand, RunEditCommand, RunEnqueueCommand, RunInputCommand, RunPlacement, RunQueueItem, RunReloadCommand, RunSteerCommand, RunUserMessage, SendCommandsRequestBody, TextPart, ToolApprovalInputRequest, ToolApprovalInputResponse, ToolCallInputRequest, ToolCallInputResponse, UserCommands, UserExternalState };
|
|
189
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;KAUY,eAAe,UAAU,eAAe,UAAU;KAClD,0BAA0B,UAAU,8BAC5C,0BACA,UAAU,oBAAoB,UAAU;KAEhC;WACD;WACA;;KAGC;WACD;WACA;WACA;WACA;;KAGC;WACD;WACA;WACA,iBAAiB,WAAW;WAC5B,WAAW;;;KAIV;WACD;WACA;;KAGC;WACD;;WAGI,SAAS;;WAET;;WAEA;KAEb;KAEU;WACD;;WAGI,SAAS;;WAET;;WAEA;KAEb;KAEU;WACD;WACA;;KAGC;WACD;WACA,SAAS;WACT;;KAGC;WACD;;KAGC;WACD;WACA;WACA;;KAGC;WACD;WACA;WACA;;KAGC;WACD;WACA;YACC,cAAc;;;KAId,eACR,uBACA,2BACA;KAEQ;WACD,QAAQ;;WAER;WACA,WAAW;;KAGV;WACD;WACA,aAAa;WACb;;KAGC,gBAAgB;KAEhB;WACD;WACA;WACA,UAAU;;;KAIT,oBAAoB;WACrB,UAAU;;KAGT;WACD;WACA;;KAGC,aACR,oBACA,kBACA,oBACA,iBACA,qBACA,mBACA;KAEQ,4BAA4B,aAAa;;KAGzC;WACD;WACA,iBAAiB,WAAW;;KAG3B;WACD,mBAAmB;WACnB,QAAQ;WACR;;;;;;;;WAQA,iBAAiB;;WAEjB,sBAAsB;;;;;;WAMtB,yBAAyB;;KAGxB;EACV,iBAAiB;EACjB;EACA,cAAc,eAAe;;KAGnB,iCAAiC,MAC3C,OAAO,GACP,oBAAoB,yCACjB;KAEO,eAAe,yBAAyB;KAExC;KAEA;EACV,UAAU;EACV;EACA;EACA,OAAO;EACP,cAAc;EACd,QAAQ;EACR;EACA;GACC;;KAGS,0BAA0B;EACpC,cAAc;EACd,WAAW,iCAAiC;EAC5C;EACA;EACA,WAAW;EACX,SAAS,sBAAsB,QAAQ;EACvC,uBAAuB;;EAEvB,+BAEM,MAAM,4BACH,0BAA0B,QAAQ;EAE3C,eAAe,UAAU;EACzB;EACA,YAEM,OAAO,OACP;IACE,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;eAE7B;;;;;EAMhB,aACM;IACA,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;IACrC,QAAQ;;EAGd;IAEM;;;;;;IAMA;;IAEA;;EAGN;IAEM,cAAc"}
|
package/dist/types.js
DELETED
|
File without changes
|