@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.
- package/dist/StatewireThread.d.ts +86 -105
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +36 -51
- 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 +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 +30 -13
- package/dist/runsOptimistic.js.map +1 -1
- package/package.json +4 -5
- package/src/StatewireThread.runs.test.tsx +65 -33
- package/src/StatewireThread.test.tsx +228 -426
- package/src/StatewireThread.ts +133 -224
- package/src/__tests__/testHelpers.tsx +6 -226
- package/src/hooks.ts +11 -32
- package/src/index.ts +2 -4
- package/src/inputRequests.ts +7 -9
- package/src/runCommands.ts +17 -23
- package/src/runsMaterialize.test.ts +7 -8
- package/src/runsOptimistic.test.ts +86 -19
- package/src/runsOptimistic.ts +49 -19
- 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/dist/host.js
DELETED
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import { createReplayBoundaryStream } from "./replayBoundaryStream.js";
|
|
2
|
-
import { translateStateOp } from "./stateOps.js";
|
|
3
|
-
import { useEffect, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
4
|
-
import { resource } from "@assistant-ui/tap";
|
|
5
|
-
import { createRequestHeaders } from "@assistant-ui/core";
|
|
6
|
-
import { AssistantTransportDecoder, DataStreamDecoder, toToolsJSONSchema } from "assistant-stream";
|
|
7
|
-
import { asAsyncIterableStream } from "assistant-stream/utils";
|
|
8
|
-
import { useStatewireCommands, useStatewireEmit, useStatewireState } from "statewire/host";
|
|
9
|
-
//#region src/host.ts
|
|
10
|
-
const commandsOf = (entries) => entries.map((e) => e.command);
|
|
11
|
-
const useHostLoop = (getOptions, ctl, getAgent) => {
|
|
12
|
-
const [s] = useState(() => ({
|
|
13
|
-
queue: {
|
|
14
|
-
queued: [],
|
|
15
|
-
inTransit: []
|
|
16
|
-
},
|
|
17
|
-
activeEntries: [],
|
|
18
|
-
parentId: void 0,
|
|
19
|
-
resumeRequested: false,
|
|
20
|
-
followUpRequested: false,
|
|
21
|
-
isReplaying: false,
|
|
22
|
-
disposed: false,
|
|
23
|
-
abortController: null,
|
|
24
|
-
queueVersion: 0
|
|
25
|
-
}));
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
s.disposed = false;
|
|
28
|
-
return () => {
|
|
29
|
-
s.disposed = true;
|
|
30
|
-
s.followUpRequested = false;
|
|
31
|
-
s.abortController?.abort();
|
|
32
|
-
};
|
|
33
|
-
}, [s]);
|
|
34
|
-
const setReplaying = (value) => {
|
|
35
|
-
if (s.isReplaying === value) return;
|
|
36
|
-
s.isReplaying = value;
|
|
37
|
-
ctl.apply([{
|
|
38
|
-
op: "replace",
|
|
39
|
-
path: ["isReplaying"],
|
|
40
|
-
value
|
|
41
|
-
}]);
|
|
42
|
-
};
|
|
43
|
-
const setSending = (value_0) => {
|
|
44
|
-
ctl.apply([{
|
|
45
|
-
op: "replace",
|
|
46
|
-
path: ["isSending"],
|
|
47
|
-
value: value_0
|
|
48
|
-
}]);
|
|
49
|
-
};
|
|
50
|
-
const replaceAgent = (next) => {
|
|
51
|
-
ctl.apply([{
|
|
52
|
-
op: "replace",
|
|
53
|
-
path: ["agent"],
|
|
54
|
-
value: next
|
|
55
|
-
}]);
|
|
56
|
-
};
|
|
57
|
-
const updateState = (updater) => {
|
|
58
|
-
replaceAgent(updater(getAgent()));
|
|
59
|
-
};
|
|
60
|
-
const applyChunkOps = (operations) => {
|
|
61
|
-
for (const operation of operations) {
|
|
62
|
-
const op = translateStateOp(getAgent(), operation);
|
|
63
|
-
if (op === void 0) continue;
|
|
64
|
-
ctl.apply([{
|
|
65
|
-
...op,
|
|
66
|
-
path: ["agent", ...op.path]
|
|
67
|
-
}]);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const setQueue = (next_0) => {
|
|
71
|
-
s.queue = next_0;
|
|
72
|
-
getOptions().queueCell.current = {
|
|
73
|
-
queued: commandsOf(next_0.queued),
|
|
74
|
-
inTransit: commandsOf(next_0.inTransit)
|
|
75
|
-
};
|
|
76
|
-
ctl.apply([{
|
|
77
|
-
op: "replace",
|
|
78
|
-
path: ["queueVersion"],
|
|
79
|
-
value: ++s.queueVersion
|
|
80
|
-
}]);
|
|
81
|
-
};
|
|
82
|
-
const takeQueuedIntoTransit = () => {
|
|
83
|
-
const { queued, inTransit } = s.queue;
|
|
84
|
-
if (queued.length === 0) return [];
|
|
85
|
-
setQueue({
|
|
86
|
-
queued: [],
|
|
87
|
-
inTransit: [...inTransit, ...queued]
|
|
88
|
-
});
|
|
89
|
-
return queued;
|
|
90
|
-
};
|
|
91
|
-
const drainQueue = () => {
|
|
92
|
-
const drained = s.queue;
|
|
93
|
-
setQueue({
|
|
94
|
-
queued: [],
|
|
95
|
-
inTransit: []
|
|
96
|
-
});
|
|
97
|
-
return drained;
|
|
98
|
-
};
|
|
99
|
-
const buildRequestBody = async (o, commands, runParentId) => {
|
|
100
|
-
const bodyValue = typeof o.body === "function" ? await o.body() : o.body;
|
|
101
|
-
const { modelContext, threadId } = o.getRunContext();
|
|
102
|
-
const requestBody = {
|
|
103
|
-
commands,
|
|
104
|
-
state: getAgent(),
|
|
105
|
-
system: modelContext.system,
|
|
106
|
-
tools: modelContext.tools ? toToolsJSONSchema(modelContext.tools) : void 0,
|
|
107
|
-
threadId,
|
|
108
|
-
...runParentId !== void 0 && { parentId: runParentId },
|
|
109
|
-
callSettings: modelContext.callSettings,
|
|
110
|
-
config: modelContext.config,
|
|
111
|
-
...modelContext.callSettings,
|
|
112
|
-
...modelContext.config,
|
|
113
|
-
...bodyValue ?? {}
|
|
114
|
-
};
|
|
115
|
-
if (!o.prepareSendCommandsRequest) return requestBody;
|
|
116
|
-
return o.prepareSendCommandsRequest(requestBody);
|
|
117
|
-
};
|
|
118
|
-
const run = async (signal) => {
|
|
119
|
-
const o_0 = getOptions();
|
|
120
|
-
const isResume = s.resumeRequested;
|
|
121
|
-
s.resumeRequested = false;
|
|
122
|
-
setReplaying(false);
|
|
123
|
-
s.activeEntries = isResume ? [] : takeQueuedIntoTransit();
|
|
124
|
-
if (s.activeEntries.length === 0 && !isResume && s.parentId === void 0) return;
|
|
125
|
-
const runParentId_0 = s.parentId;
|
|
126
|
-
s.parentId = void 0;
|
|
127
|
-
try {
|
|
128
|
-
await runRequest(o_0, isResume, runParentId_0, signal);
|
|
129
|
-
} catch (error) {
|
|
130
|
-
if (!signal.aborted && s.parentId === void 0) s.parentId = runParentId_0;
|
|
131
|
-
throw error;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const runRequest = async (o_1, isResume_0, runParentId_1, signal_0) => {
|
|
135
|
-
const headers = await createRequestHeaders(o_1.headers);
|
|
136
|
-
const requestBody_0 = await buildRequestBody(o_1, commandsOf(s.activeEntries), runParentId_1);
|
|
137
|
-
const response = await fetch(isResume_0 ? o_1.resumeApi : o_1.api, {
|
|
138
|
-
method: "POST",
|
|
139
|
-
headers,
|
|
140
|
-
body: JSON.stringify(requestBody_0),
|
|
141
|
-
signal: signal_0
|
|
142
|
-
});
|
|
143
|
-
o_1.onResponse?.(response);
|
|
144
|
-
if (!response.ok) throw new Error(`Status ${response.status}: ${await response.text()}`);
|
|
145
|
-
if (!response.body) throw new Error("Response body is null");
|
|
146
|
-
const body = await createReplayBoundaryStream(response, setReplaying);
|
|
147
|
-
const strict = !isResume_0;
|
|
148
|
-
const decoder = (o_1.protocol ?? "data-stream") === "assistant-transport" ? new AssistantTransportDecoder({ strict }) : new DataStreamDecoder({ strict });
|
|
149
|
-
let streamError;
|
|
150
|
-
let delivered = false;
|
|
151
|
-
const markDelivered = () => {
|
|
152
|
-
for (const entry of s.activeEntries) entry.execution.ack();
|
|
153
|
-
setQueue({
|
|
154
|
-
...s.queue,
|
|
155
|
-
inTransit: []
|
|
156
|
-
});
|
|
157
|
-
delivered = true;
|
|
158
|
-
};
|
|
159
|
-
const chunks = body.pipeThrough(decoder);
|
|
160
|
-
for await (const chunk of asAsyncIterableStream(chunks)) {
|
|
161
|
-
if (chunk.type === "error") {
|
|
162
|
-
streamError = chunk.error;
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
if (chunk.type !== "update-state" || chunk.operations.length === 0) continue;
|
|
166
|
-
applyChunkOps(chunk.operations);
|
|
167
|
-
if (!delivered) markDelivered();
|
|
168
|
-
}
|
|
169
|
-
if (streamError) throw new Error(streamError);
|
|
170
|
-
if (!delivered) markDelivered();
|
|
171
|
-
if (isResume_0 && s.queue.queued.length > 0) s.followUpRequested = true;
|
|
172
|
-
};
|
|
173
|
-
const resolveActive = () => {
|
|
174
|
-
for (const entry_0 of s.activeEntries.splice(0)) entry_0.execution.resolve();
|
|
175
|
-
};
|
|
176
|
-
const settleCancelled = () => {
|
|
177
|
-
setReplaying(false);
|
|
178
|
-
const { queued: queued_0, inTransit: inTransit_0 } = drainQueue();
|
|
179
|
-
resolveActive();
|
|
180
|
-
for (const entry_1 of [...inTransit_0, ...queued_0]) entry_1.execution.resolve();
|
|
181
|
-
getOptions().onCancel?.({
|
|
182
|
-
commands: commandsOf([...inTransit_0, ...queued_0]),
|
|
183
|
-
updateState
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
const settleFailed = async (error_0) => {
|
|
187
|
-
setReplaying(false);
|
|
188
|
-
const { queued: queued_1, inTransit: inTransit_1 } = drainQueue();
|
|
189
|
-
for (const entry_2 of inTransit_1) entry_2.execution.reject(error_0);
|
|
190
|
-
resolveActive();
|
|
191
|
-
try {
|
|
192
|
-
await getOptions().onError?.(error_0, {
|
|
193
|
-
commands: commandsOf(inTransit_1),
|
|
194
|
-
updateState
|
|
195
|
-
});
|
|
196
|
-
} finally {
|
|
197
|
-
getOptions().onCancel?.({
|
|
198
|
-
commands: commandsOf(queued_1),
|
|
199
|
-
updateState,
|
|
200
|
-
error: error_0
|
|
201
|
-
});
|
|
202
|
-
for (const entry of queued_1) entry.execution.resolve();
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
const startRun = () => {
|
|
206
|
-
s.followUpRequested = false;
|
|
207
|
-
const ac = new AbortController();
|
|
208
|
-
s.abortController = ac;
|
|
209
|
-
setSending(true);
|
|
210
|
-
setTimeout(async () => {
|
|
211
|
-
try {
|
|
212
|
-
await run(ac.signal);
|
|
213
|
-
resolveActive();
|
|
214
|
-
} catch (error_1) {
|
|
215
|
-
s.followUpRequested = false;
|
|
216
|
-
if (!s.disposed) {
|
|
217
|
-
if (ac.signal.aborted) settleCancelled();
|
|
218
|
-
else await settleFailed(error_1);
|
|
219
|
-
}
|
|
220
|
-
} finally {
|
|
221
|
-
if (s.disposed) s.abortController = null;
|
|
222
|
-
else {
|
|
223
|
-
getOptions().onFinish?.();
|
|
224
|
-
if (s.followUpRequested) startRun();
|
|
225
|
-
else {
|
|
226
|
-
s.abortController = null;
|
|
227
|
-
setSending(false);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}, 0);
|
|
232
|
-
};
|
|
233
|
-
const schedule = () => {
|
|
234
|
-
if (s.abortController) {
|
|
235
|
-
s.followUpRequested = true;
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
startRun();
|
|
239
|
-
};
|
|
240
|
-
return {
|
|
241
|
-
send: function(command, opts) {
|
|
242
|
-
let resolve;
|
|
243
|
-
let reject;
|
|
244
|
-
const promise = new Promise((res, rej) => {
|
|
245
|
-
resolve = res;
|
|
246
|
-
reject = rej;
|
|
247
|
-
});
|
|
248
|
-
setQueue({
|
|
249
|
-
queued: [...s.queue.queued, {
|
|
250
|
-
command,
|
|
251
|
-
execution: {
|
|
252
|
-
ack: this.ack,
|
|
253
|
-
resolve,
|
|
254
|
-
reject
|
|
255
|
-
}
|
|
256
|
-
}],
|
|
257
|
-
inTransit: s.queue.inTransit
|
|
258
|
-
});
|
|
259
|
-
if (opts?.schedule !== false) schedule();
|
|
260
|
-
return promise;
|
|
261
|
-
},
|
|
262
|
-
setParentId: (id) => {
|
|
263
|
-
s.parentId = id;
|
|
264
|
-
},
|
|
265
|
-
cancel: () => {
|
|
266
|
-
s.resumeRequested = false;
|
|
267
|
-
s.followUpRequested = false;
|
|
268
|
-
s.abortController?.abort();
|
|
269
|
-
},
|
|
270
|
-
resume: () => {
|
|
271
|
-
if (!getOptions().resumeApi) throw new Error("Must pass resumeApi to options to resume runs");
|
|
272
|
-
s.resumeRequested = true;
|
|
273
|
-
schedule();
|
|
274
|
-
},
|
|
275
|
-
importState: replaceAgent
|
|
276
|
-
};
|
|
277
|
-
};
|
|
278
|
-
const useAssistantTransportHost = (options) => {
|
|
279
|
-
const latestOptions = useRef(options);
|
|
280
|
-
latestOptions.current = options;
|
|
281
|
-
const [state, ctl] = useStatewireState(() => ({
|
|
282
|
-
agent: options.initialState,
|
|
283
|
-
queueVersion: 0,
|
|
284
|
-
isSending: false,
|
|
285
|
-
isReplaying: false
|
|
286
|
-
}));
|
|
287
|
-
const emit = useStatewireEmit();
|
|
288
|
-
const handlers = useHostLoop(() => latestOptions.current, ctl, () => ctl.snapshot().agent);
|
|
289
|
-
return {
|
|
290
|
-
state,
|
|
291
|
-
commands: useStatewireCommands(handlers),
|
|
292
|
-
emit
|
|
293
|
-
};
|
|
294
|
-
};
|
|
295
|
-
const AssistantTransportHost = resource(useAssistantTransportHost);
|
|
296
|
-
//#endregion
|
|
297
|
-
export { AssistantTransportHost };
|
|
298
|
-
|
|
299
|
-
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","names":["useEffect","useRef","useState","resource","createRequestHeaders","ModelContext","AssistantTransportDecoder","DataStreamDecoder","toToolsJSONSchema","AssistantTransportStateOperation","asAsyncIterableStream","Statewire","useStatewireCommands","useStatewireEmit","useStatewireState","StatewireHost","createReplayBoundaryStream","translateStateOp","AssistantTransportThread","SendOptions","schedule","HostRunContext","modelContext","threadId","HostQueue","queued","Command","inTransit","HostQueueCell","current","HostOptions","Options","getRunContext","queueCell","AssistantTransportHostState","agent","queueVersion","isSending","isReplaying","AssistantTransportHostCommands","send","command","opts","setParentId","parentId","cancel","resume","importState","state","EntrySettlement","ack","resolve","reject","error","QueueEntry","execution","EntryQueue","commandsOf","entries","map","e","LoopState","queue","activeEntries","resumeRequested","followUpRequested","disposed","abortController","AbortController","useHostLoop","getOptions","ctl","StateCtl","getAgent","s","undefined","abort","setReplaying","value","apply","op","path","setSending","replaceAgent","next","updateState","updater","applyChunkOps","operations","operation","setQueue","takeQueuedIntoTransit","length","drainQueue","drained","buildRequestBody","o","commands","runParentId","bodyValue","body","requestBody","Record","system","tools","callSettings","config","prepareSendCommandsRequest","SendCommandsRequestBody","run","signal","AbortSignal","isResume","runRequest","aborted","headers","response","fetch","resumeApi","api","method","JSON","stringify","onResponse","ok","Error","status","text","strict","decoder","protocol","streamError","delivered","markDelivered","entry","chunks","pipeThrough","chunk","type","resolveActive","splice","settleCancelled","onCancel","settleFailed","onError","startRun","ac","setTimeout","onFinish","this","Ctx","promise","Promise","res","rej","id","useAssistantTransportHost","options","latestOptions","initialState","emit","handlers","snapshot","AssistantTransportHost"],"sources":["../src/host.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport { createRequestHeaders } from \"@assistant-ui/core\";\nimport type { ModelContext } from \"@assistant-ui/core\";\nimport {\n AssistantTransportDecoder,\n DataStreamDecoder,\n toToolsJSONSchema,\n} from \"assistant-stream\";\nimport type { AssistantTransportStateOperation } from \"assistant-stream\";\nimport { asAsyncIterableStream } from \"assistant-stream/utils\";\nimport type { Statewire } from \"statewire\";\nimport {\n useStatewireCommands,\n useStatewireEmit,\n useStatewireState,\n} from \"statewire/host\";\nimport type { StatewireHost } from \"statewire/host\";\nimport { createReplayBoundaryStream } from \"./replayBoundaryStream\";\nimport { translateStateOp } from \"./stateOps\";\nimport type { AssistantTransportThread } from \"./AssistantTransportThread\";\n\nexport type SendOptions = {\n schedule?: boolean;\n};\n\nexport type HostRunContext = {\n modelContext: ModelContext;\n threadId: string | null;\n};\n\nexport type HostQueue = {\n queued: AssistantTransportThread.Command[];\n inTransit: AssistantTransportThread.Command[];\n};\n\n// Statewire state sanitizes values on apply; command objects must keep their\n// identity for converter-side caches, so the host publishes them through this\n// cell and bumps queueVersion in state to signal the change.\nexport type HostQueueCell = { current: HostQueue };\n\nexport type HostOptions = AssistantTransportThread.Options<unknown> & {\n getRunContext: () => HostRunContext;\n queueCell: HostQueueCell;\n};\n\nexport type AssistantTransportHostState = {\n agent: unknown;\n queueVersion: number;\n isSending: boolean;\n isReplaying: boolean;\n};\n\nexport type AssistantTransportHostCommands = {\n send(command: AssistantTransportThread.Command, opts?: SendOptions): void;\n setParentId(parentId: string | null): void;\n cancel(): void;\n resume(): void;\n importState(state: unknown): void;\n};\n\ntype EntrySettlement = {\n ack: () => void;\n resolve: () => void;\n reject: (error: unknown) => void;\n};\n\ntype QueueEntry = {\n command: AssistantTransportThread.Command;\n execution: EntrySettlement;\n};\n\ntype EntryQueue = {\n queued: QueueEntry[];\n inTransit: QueueEntry[];\n};\n\nconst commandsOf = (entries: QueueEntry[]) => entries.map((e) => e.command);\n\ntype LoopState = {\n queue: EntryQueue;\n activeEntries: QueueEntry[];\n parentId: string | null | undefined;\n resumeRequested: boolean;\n followUpRequested: boolean;\n isReplaying: boolean;\n disposed: boolean;\n abortController: AbortController | null;\n queueVersion: number;\n};\n\nconst useHostLoop = (\n getOptions: () => HostOptions,\n ctl: StatewireHost.StateCtl,\n getAgent: () => unknown,\n) => {\n const [s] = useState(\n (): LoopState => ({\n queue: { queued: [], inTransit: [] },\n activeEntries: [],\n parentId: undefined,\n resumeRequested: false,\n followUpRequested: false,\n isReplaying: false,\n disposed: false,\n abortController: null,\n queueVersion: 0,\n }),\n );\n\n useEffect(() => {\n s.disposed = false;\n return () => {\n s.disposed = true;\n s.followUpRequested = false;\n s.abortController?.abort();\n };\n }, [s]);\n\n const setReplaying = (value: boolean) => {\n if (s.isReplaying === value) return;\n s.isReplaying = value;\n ctl.apply([{ op: \"replace\", path: [\"isReplaying\"], value }]);\n };\n\n const setSending = (value: boolean) => {\n ctl.apply([{ op: \"replace\", path: [\"isSending\"], value }]);\n };\n\n const replaceAgent = (next: unknown) => {\n ctl.apply([{ op: \"replace\", path: [\"agent\"], value: next }]);\n };\n\n const updateState = (updater: (state: unknown) => unknown) => {\n replaceAgent(updater(getAgent()));\n };\n\n // Ops commit one-by-one — an op error leaves the chunk's prefix applied.\n const applyChunkOps = (\n operations: readonly AssistantTransportStateOperation[],\n ) => {\n for (const operation of operations) {\n const op = translateStateOp(getAgent(), operation);\n if (op === undefined) continue;\n ctl.apply([{ ...op, path: [\"agent\", ...op.path] }]);\n }\n };\n\n const setQueue = (next: EntryQueue) => {\n s.queue = next;\n getOptions().queueCell.current = {\n queued: commandsOf(next.queued),\n inTransit: commandsOf(next.inTransit),\n };\n ctl.apply([\n { op: \"replace\", path: [\"queueVersion\"], value: ++s.queueVersion },\n ]);\n };\n\n const takeQueuedIntoTransit = (): QueueEntry[] => {\n const { queued, inTransit } = s.queue;\n if (queued.length === 0) return [];\n setQueue({ queued: [], inTransit: [...inTransit, ...queued] });\n return queued;\n };\n\n const drainQueue = (): EntryQueue => {\n const drained = s.queue;\n setQueue({ queued: [], inTransit: [] });\n return drained;\n };\n\n const buildRequestBody = async (\n o: HostOptions,\n commands: AssistantTransportThread.Command[],\n runParentId: string | null | undefined,\n ) => {\n const bodyValue = typeof o.body === \"function\" ? await o.body() : o.body;\n const { modelContext, threadId } = o.getRunContext();\n\n const requestBody: Record<string, unknown> = {\n commands,\n state: getAgent(),\n system: modelContext.system,\n tools: modelContext.tools\n ? toToolsJSONSchema(modelContext.tools)\n : undefined,\n threadId,\n ...(runParentId !== undefined && { parentId: runParentId }),\n callSettings: modelContext.callSettings,\n config: modelContext.config,\n // deprecated top-level spread, kept for legacy parity\n ...modelContext.callSettings,\n ...modelContext.config,\n ...(bodyValue ?? {}),\n };\n\n if (!o.prepareSendCommandsRequest) return requestBody;\n return o.prepareSendCommandsRequest(\n requestBody as AssistantTransportThread.SendCommandsRequestBody,\n );\n };\n\n const run = async (signal: AbortSignal) => {\n const o = getOptions();\n const isResume = s.resumeRequested;\n s.resumeRequested = false;\n setReplaying(false);\n s.activeEntries = isResume ? [] : takeQueuedIntoTransit();\n if (s.activeEntries.length === 0 && !isResume && s.parentId === undefined)\n return;\n\n const runParentId = s.parentId;\n s.parentId = undefined;\n try {\n await runRequest(o, isResume, runParentId, signal);\n } catch (error) {\n if (!signal.aborted && s.parentId === undefined) s.parentId = runParentId;\n throw error;\n }\n };\n\n const runRequest = async (\n o: HostOptions,\n isResume: boolean,\n runParentId: string | null | undefined,\n signal: AbortSignal,\n ) => {\n const headers = await createRequestHeaders(o.headers);\n const requestBody = await buildRequestBody(\n o,\n commandsOf(s.activeEntries),\n runParentId,\n );\n\n const response = await fetch(isResume ? o.resumeApi! : o.api, {\n method: \"POST\",\n headers,\n body: JSON.stringify(requestBody),\n signal,\n });\n\n o.onResponse?.(response);\n\n if (!response.ok) {\n throw new Error(`Status ${response.status}: ${await response.text()}`);\n }\n if (!response.body) {\n throw new Error(\"Response body is null\");\n }\n\n const body = await createReplayBoundaryStream(response, setReplaying);\n const strict = !isResume;\n const decoder =\n (o.protocol ?? \"data-stream\") === \"assistant-transport\"\n ? new AssistantTransportDecoder({ strict })\n : new DataStreamDecoder({ strict });\n\n let streamError: string | undefined;\n let delivered = false;\n\n const markDelivered = () => {\n for (const entry of s.activeEntries) entry.execution.ack();\n setQueue({ ...s.queue, inTransit: [] });\n delivered = true;\n };\n\n const chunks = body.pipeThrough(decoder);\n for await (const chunk of asAsyncIterableStream(chunks)) {\n if (chunk.type === \"error\") {\n streamError = chunk.error;\n continue;\n }\n if (chunk.type !== \"update-state\" || chunk.operations.length === 0)\n continue;\n\n applyChunkOps(chunk.operations);\n\n // only after the chunk committed — a failing first chunk must leave\n // the commands in transit for onError (legacy parity)\n if (!delivered) markDelivered();\n }\n\n if (streamError) {\n throw new Error(streamError);\n }\n\n if (!delivered) markDelivered();\n\n // commands that coalesced into a resume run must not starve\n if (isResume && s.queue.queued.length > 0) s.followUpRequested = true;\n };\n\n const resolveActive = () => {\n for (const entry of s.activeEntries.splice(0)) entry.execution.resolve();\n };\n\n const settleCancelled = () => {\n setReplaying(false);\n const { queued, inTransit } = drainQueue();\n resolveActive();\n for (const entry of [...inTransit, ...queued]) entry.execution.resolve();\n getOptions().onCancel?.({\n commands: commandsOf([...inTransit, ...queued]),\n updateState,\n });\n };\n\n const settleFailed = async (error: Error) => {\n setReplaying(false);\n const { queued, inTransit } = drainQueue();\n for (const entry of inTransit) entry.execution.reject(error);\n resolveActive();\n try {\n await getOptions().onError?.(error, {\n commands: commandsOf(inTransit),\n updateState,\n });\n } finally {\n getOptions().onCancel?.({\n commands: commandsOf(queued),\n updateState,\n error,\n });\n for (const entry of queued) entry.execution.resolve();\n }\n };\n\n const startRun = () => {\n s.followUpRequested = false;\n const ac = new AbortController();\n s.abortController = ac;\n setSending(true);\n\n // macrotask: every command admitted this turn coalesces into the take\n setTimeout(async () => {\n try {\n await run(ac.signal);\n resolveActive();\n } catch (error) {\n s.followUpRequested = false;\n // disposed means unmounted mid-run: the abort is ours, no callbacks\n if (!s.disposed) {\n if (ac.signal.aborted) settleCancelled();\n else await settleFailed(error as Error);\n }\n } finally {\n if (s.disposed) {\n s.abortController = null;\n } else {\n getOptions().onFinish?.();\n if (s.followUpRequested) {\n startRun();\n } else {\n s.abortController = null;\n setSending(false);\n }\n }\n }\n }, 0);\n };\n\n const schedule = () => {\n if (s.abortController) {\n s.followUpRequested = true;\n return;\n }\n startRun();\n };\n\n return {\n send: function (\n this: StatewireHost.Ctx,\n command: AssistantTransportThread.Command,\n opts?: SendOptions,\n ) {\n let resolve!: () => void;\n let reject!: (error: unknown) => void;\n const promise = new Promise<void>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n setQueue({\n queued: [\n ...s.queue.queued,\n { command, execution: { ack: this.ack, resolve, reject } },\n ],\n inTransit: s.queue.inTransit,\n });\n if (opts?.schedule !== false) schedule();\n return promise;\n },\n setParentId: (id: string | null) => {\n s.parentId = id;\n },\n cancel: () => {\n s.resumeRequested = false;\n s.followUpRequested = false;\n s.abortController?.abort();\n },\n resume: () => {\n if (!getOptions().resumeApi)\n throw new Error(\"Must pass resumeApi to options to resume runs\");\n\n s.resumeRequested = true;\n schedule();\n },\n importState: replaceAgent,\n };\n};\n\nconst useAssistantTransportHost = (\n options: HostOptions,\n): Statewire<AssistantTransportHostState, AssistantTransportHostCommands> => {\n const latestOptions = useRef(options);\n latestOptions.current = options;\n\n const [state, ctl] = useStatewireState<AssistantTransportHostState>(() => ({\n agent: options.initialState,\n queueVersion: 0,\n isSending: false,\n isReplaying: false,\n }));\n const emit = useStatewireEmit();\n\n const handlers = useHostLoop(\n () => latestOptions.current,\n ctl,\n () => ctl.snapshot().agent,\n );\n\n const commands = useStatewireCommands(handlers);\n\n return { state, commands, emit };\n};\n\nexport const AssistantTransportHost = resource(useAssistantTransportHost);\n"],"mappings":";;;;;;;;;AA6EA,MAAMyD,cAAcC,YAA0BA,QAAQC,KAAKC,MAAMA,EAAEnB,OAAO;AAc1E,MAAM4B,eACJC,YACAC,KACAE,aACG;CACH,MAAM,CAACC,KAAKxE,gBACQ;EAChB4D,OAAO;GAAErC,QAAQ,CAAA;GAAIE,WAAW,CAAA;EAAG;EACnCoC,eAAe,CAAA;EACfnB,UAAU+B,KAAAA;EACVX,iBAAiB;EACjBC,mBAAmB;EACnB3B,aAAa;EACb4B,UAAU;EACVC,iBAAiB;EACjB/B,cAAc;CAChB,EACF;CAEApC,gBAAgB;EACd0E,EAAER,WAAW;EACb,aAAa;GACXQ,EAAER,WAAW;GACbQ,EAAET,oBAAoB;GACtBS,EAAEP,iBAAiBS,MAAM;EAC3B;CACF,GAAG,CAACF,CAAC,CAAC;CAEN,MAAMG,gBAAgBC,UAAmB;EACvC,IAAIJ,EAAEpC,gBAAgBwC,OAAO;EAC7BJ,EAAEpC,cAAcwC;EAChBP,IAAIQ,MAAM,CAAC;GAAEC,IAAI;GAAWC,MAAM,CAAC,aAAa;GAAGH;EAAM,CAAC,CAAC;CAC7D;CAEA,MAAMI,cAAcJ,YAAmB;EACrCP,IAAIQ,MAAM,CAAC;GAAEC,IAAI;GAAWC,MAAM,CAAC,WAAW;GA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AsD;EACzEqB,OAAO0H,QAAQE;EACf3H,cAAc;EACdC,WAAW;EACXC,aAAa;CACf,EAAE;CACF,MAAM0H,OAAOnJ,iBAAiB;CAE9B,MAAMoJ,WAAW5F,kBACTyF,cAAcjI,SACpB0C,WACMA,IAAI2F,SAAS,CAAC,CAAC/H,KACvB;CAIA,OAAO;EAAEa;EAAOiD,UAFCrF,qBAAqBqJ,QAEtBhE;EAAU+D;CAAK;AACjC;AAEA,MAAaG,yBAAyBhK,SAASyJ,yBAAyB"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region src/replayBoundaryStream.d.ts
|
|
2
|
-
declare const REPLAY_CONTENT_LENGTH_HEADER = "Aui-Replay-Content-Length";
|
|
3
|
-
declare const createReplayBoundaryStream: (response: Response, setReplaying: (value: boolean) => void) => Promise<ReadableStream<Uint8Array<ArrayBuffer>>>;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { REPLAY_CONTENT_LENGTH_HEADER, createReplayBoundaryStream };
|
|
6
|
-
//# sourceMappingURL=replayBoundaryStream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replayBoundaryStream.d.ts","names":[],"sources":["../src/replayBoundaryStream.ts"],"mappings":";cAAa;cAmBA,6BACX,UAAU,UACV,eAAe,4BACd,QAAQ,eAAe,WAAW"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
//#region src/replayBoundaryStream.ts
|
|
2
|
-
const REPLAY_CONTENT_LENGTH_HEADER = "Aui-Replay-Content-Length";
|
|
3
|
-
const waitForRender = () => new Promise((r) => setTimeout(r, 0));
|
|
4
|
-
const parseReplayContentLength = (headers) => {
|
|
5
|
-
const raw = headers.get(REPLAY_CONTENT_LENGTH_HEADER);
|
|
6
|
-
if (raw == null) return 0;
|
|
7
|
-
const trimmed = raw.trim();
|
|
8
|
-
const boundary = Number(trimmed);
|
|
9
|
-
if (!/^\d+$/.test(trimmed) || !Number.isSafeInteger(boundary)) throw new Error(`statewire: invalid ${REPLAY_CONTENT_LENGTH_HEADER} header "${raw}"`);
|
|
10
|
-
return boundary;
|
|
11
|
-
};
|
|
12
|
-
const createReplayBoundaryStream = async (response, setReplaying) => {
|
|
13
|
-
const body = response.body;
|
|
14
|
-
let remaining = parseReplayContentLength(response.headers);
|
|
15
|
-
if (remaining <= 0) return body;
|
|
16
|
-
setReplaying(true);
|
|
17
|
-
await waitForRender();
|
|
18
|
-
const finishReplay = async () => {
|
|
19
|
-
remaining = 0;
|
|
20
|
-
await waitForRender();
|
|
21
|
-
setReplaying(false);
|
|
22
|
-
await waitForRender();
|
|
23
|
-
};
|
|
24
|
-
return body.pipeThrough(new TransformStream({
|
|
25
|
-
async transform(chunk, controller) {
|
|
26
|
-
if (remaining === 0) {
|
|
27
|
-
controller.enqueue(chunk);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const replayPart = chunk.subarray(0, remaining);
|
|
31
|
-
remaining -= replayPart.byteLength;
|
|
32
|
-
controller.enqueue(replayPart);
|
|
33
|
-
if (remaining > 0) return;
|
|
34
|
-
await finishReplay();
|
|
35
|
-
if (replayPart.byteLength < chunk.byteLength) controller.enqueue(chunk.subarray(replayPart.byteLength));
|
|
36
|
-
},
|
|
37
|
-
async flush() {
|
|
38
|
-
if (remaining > 0) await finishReplay();
|
|
39
|
-
},
|
|
40
|
-
cancel() {
|
|
41
|
-
if (remaining > 0) setReplaying(false);
|
|
42
|
-
remaining = 0;
|
|
43
|
-
}
|
|
44
|
-
}));
|
|
45
|
-
};
|
|
46
|
-
//#endregion
|
|
47
|
-
export { REPLAY_CONTENT_LENGTH_HEADER, createReplayBoundaryStream };
|
|
48
|
-
|
|
49
|
-
//# sourceMappingURL=replayBoundaryStream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replayBoundaryStream.js","names":["REPLAY_CONTENT_LENGTH_HEADER","waitForRender","Promise","r","setTimeout","parseReplayContentLength","headers","Headers","raw","get","trimmed","trim","boundary","Number","test","isSafeInteger","Error","createReplayBoundaryStream","response","Response","setReplaying","value","ReadableStream","Uint8Array","ArrayBuffer","body","remaining","finishReplay","transformer","Transformer","cancel","transform","chunk","controller","enqueue","replayPart","subarray","byteLength","flush","pipeThrough","TransformStream"],"sources":["../src/replayBoundaryStream.ts"],"sourcesContent":["export const REPLAY_CONTENT_LENGTH_HEADER = \"Aui-Replay-Content-Length\";\n\nconst waitForRender = () => new Promise<void>((r) => setTimeout(r, 0));\n\nconst parseReplayContentLength = (headers: Headers): number => {\n const raw = headers.get(REPLAY_CONTENT_LENGTH_HEADER);\n if (raw == null) return 0;\n\n const trimmed = raw.trim();\n const boundary = Number(trimmed);\n if (!/^\\d+$/.test(trimmed) || !Number.isSafeInteger(boundary)) {\n throw new Error(\n `statewire: invalid ${REPLAY_CONTENT_LENGTH_HEADER} header \"${raw}\"`,\n );\n }\n return boundary;\n};\n\n// Gates replay bytes until isReplaying:true renders, then releases live bytes after isReplaying:false renders.\nexport const createReplayBoundaryStream = async (\n response: Response,\n setReplaying: (value: boolean) => void,\n): Promise<ReadableStream<Uint8Array<ArrayBuffer>>> => {\n const body = response.body!;\n let remaining = parseReplayContentLength(response.headers);\n\n if (remaining <= 0) {\n return body;\n }\n\n setReplaying(true);\n await waitForRender();\n\n // Let replay bytes drain before rendering live mode, then render live mode before releasing live bytes.\n const finishReplay = async () => {\n remaining = 0;\n await waitForRender();\n setReplaying(false);\n await waitForRender();\n };\n\n // TS's Transformer type predates the spec's cancel hook.\n const transformer: Transformer<\n Uint8Array<ArrayBuffer>,\n Uint8Array<ArrayBuffer>\n > & { cancel: () => void } = {\n async transform(chunk, controller) {\n if (remaining === 0) {\n controller.enqueue(chunk);\n return;\n }\n const replayPart = chunk.subarray(0, remaining);\n remaining -= replayPart.byteLength;\n controller.enqueue(replayPart);\n if (remaining > 0) return;\n await finishReplay();\n if (replayPart.byteLength < chunk.byteLength) {\n controller.enqueue(chunk.subarray(replayPart.byteLength));\n }\n },\n async flush() {\n if (remaining > 0) await finishReplay();\n },\n cancel() {\n if (remaining > 0) setReplaying(false);\n remaining = 0;\n },\n };\n\n return body.pipeThrough(new TransformStream(transformer));\n};\n"],"mappings":";AAAA,MAAaA,+BAA+B;AAE5C,MAAMC,sBAAsB,IAAIC,SAAeC,MAAMC,WAAWD,GAAG,CAAC,CAAC;AAErE,MAAME,4BAA4BC,YAA6B;CAC7D,MAAME,MAAMF,QAAQG,IAAIT,4BAA4B;CACpD,IAAIQ,OAAO,MAAM,OAAO;CAExB,MAAME,UAAUF,IAAIG,KAAK;CACzB,MAAMC,WAAWC,OAAOH,OAAO;CAC/B,IAAI,CAAC,QAAQI,KAAKJ,OAAO,KAAK,CAACG,OAAOE,cAAcH,QAAQ,GAC1D,MAAM,IAAII,MACR,sBAAsBhB,6BAA4B,WAAYQ,IAAG,EACnE;CAEF,OAAOI;AACT;AAGA,MAAaK,6BAA6B,OACxCC,UACAE,iBACqD;CACrD,MAAMK,OAAOP,SAASO;CACtB,IAAIC,YAAYrB,yBAAyBa,SAASZ,OAAO;CAEzD,IAAIoB,aAAa,GACf,OAAOD;CAGTL,aAAa,IAAI;CACjB,MAAMnB,cAAc;CAGpB,MAAM0B,eAAe,YAAY;EAC/BD,YAAY;EACZ,MAAMzB,cAAc;EACpBmB,aAAa,KAAK;EAClB,MAAMnB,cAAc;CACtB;CA8BA,OAAOwB,KAAKc,YAAY,IAAIC,gBAAgBZ;EAvB1C,MAAMG,UAAUC,OAAOC,YAAY;GACjC,IAAIP,cAAc,GAAG;IACnBO,WAAWC,QAAQF,KAAK;IACxB;GACF;GACA,MAAMG,aAAaH,MAAMI,SAAS,GAAGV,SAAS;GAC9CA,aAAaS,WAAWE;GACxBJ,WAAWC,QAAQC,UAAU;GAC7B,IAAIT,YAAY,GAAG;GACnB,MAAMC,aAAa;GACnB,IAAIQ,WAAWE,aAAaL,MAAMK,YAChCJ,WAAWC,QAAQF,MAAMI,SAASD,WAAWE,UAAU,CAAC;EAE5D;EACA,MAAMC,QAAQ;GACZ,IAAIZ,YAAY,GAAG,MAAMC,aAAa;EACxC;EACAG,SAAS;GACP,IAAIJ,YAAY,GAAGN,aAAa,KAAK;GACrCM,YAAY;EACd;CAG0CE,CAAW,CAAC;AAC1D"}
|
package/dist/stateOps.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Statewire } from "statewire";
|
|
2
|
-
import { AssistantTransportStateOperation } from "assistant-stream";
|
|
3
|
-
//#region src/stateOps.d.ts
|
|
4
|
-
type TranslatedOp = Extract<Statewire.Op, {
|
|
5
|
-
op: "replace" | "add";
|
|
6
|
-
}>;
|
|
7
|
-
declare const translateStateOp: (root: unknown, op: AssistantTransportStateOperation) => TranslatedOp | undefined;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { TranslatedOp, translateStateOp };
|
|
10
|
-
//# sourceMappingURL=stateOps.d.ts.map
|
package/dist/stateOps.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stateOps.d.ts","names":[],"sources":["../src/stateOps.ts"],"mappings":";;;KAGY,eAAe,QAAQ,UAAU;EAAM;;cA8BtC,mBACX,eACA,IAAI,qCACH"}
|
package/dist/stateOps.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
//#region src/stateOps.ts
|
|
2
|
-
const UNSAFE_SEGMENTS = /* @__PURE__ */ new Set([
|
|
3
|
-
"__proto__",
|
|
4
|
-
"constructor",
|
|
5
|
-
"prototype"
|
|
6
|
-
]);
|
|
7
|
-
const assertStringTarget = (current, op) => {
|
|
8
|
-
if (typeof current !== "string") throw new Error(`Expected string at path [${op.path.join(", ")}]`);
|
|
9
|
-
};
|
|
10
|
-
const vivified = (segments, from, op) => {
|
|
11
|
-
if (op.type === "append-text") assertStringTarget(void 0, op);
|
|
12
|
-
let value = op.value;
|
|
13
|
-
for (let i = segments.length - 1; i >= from; i--) value = { [segments[i]]: value };
|
|
14
|
-
return value;
|
|
15
|
-
};
|
|
16
|
-
const translateStateOp = (root, op) => {
|
|
17
|
-
const segments = op.path;
|
|
18
|
-
const unsafe = segments.find((segment) => UNSAFE_SEGMENTS.has(segment));
|
|
19
|
-
if (unsafe !== void 0) {
|
|
20
|
-
console.warn(`statewire: stripped op with unsafe path segment "${unsafe}"`);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const path = [];
|
|
24
|
-
let node = root;
|
|
25
|
-
for (let i = 0; i < segments.length; i++) {
|
|
26
|
-
if (node === null || node === void 0) return {
|
|
27
|
-
op: "replace",
|
|
28
|
-
path,
|
|
29
|
-
value: vivified(segments, i, op)
|
|
30
|
-
};
|
|
31
|
-
if (typeof node !== "object") throw new Error(`Invalid path: [${segments.slice(i).join(", ")}]`);
|
|
32
|
-
const key = segments[i];
|
|
33
|
-
const last = i === segments.length - 1;
|
|
34
|
-
if (Array.isArray(node)) {
|
|
35
|
-
const idx = Number(key);
|
|
36
|
-
if (Number.isNaN(idx)) throw new Error(`Expected array index at [${segments.slice(i).join(", ")}]`);
|
|
37
|
-
if (idx > node.length || idx < 0) throw new Error(`Insert array index out of bounds`);
|
|
38
|
-
const insert = idx === node.length;
|
|
39
|
-
if (last) {
|
|
40
|
-
if (op.type === "append-text") {
|
|
41
|
-
const current = insert ? void 0 : node[idx];
|
|
42
|
-
assertStringTarget(current, op);
|
|
43
|
-
return {
|
|
44
|
-
op: "add",
|
|
45
|
-
path: [
|
|
46
|
-
...path,
|
|
47
|
-
idx,
|
|
48
|
-
current.length
|
|
49
|
-
],
|
|
50
|
-
value: op.value
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
op: insert ? "add" : "replace",
|
|
55
|
-
path: [...path, idx],
|
|
56
|
-
value: op.value
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
if (insert || !Object.hasOwn(node, idx)) return {
|
|
60
|
-
op: insert ? "add" : "replace",
|
|
61
|
-
path: [...path, idx],
|
|
62
|
-
value: vivified(segments, i + 1, op)
|
|
63
|
-
};
|
|
64
|
-
path.push(idx);
|
|
65
|
-
node = node[idx];
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
const obj = node;
|
|
69
|
-
if (last) {
|
|
70
|
-
if (op.type === "append-text") {
|
|
71
|
-
const current = Object.hasOwn(obj, key) ? obj[key] : void 0;
|
|
72
|
-
assertStringTarget(current, op);
|
|
73
|
-
return {
|
|
74
|
-
op: "add",
|
|
75
|
-
path: [
|
|
76
|
-
...path,
|
|
77
|
-
key,
|
|
78
|
-
current.length
|
|
79
|
-
],
|
|
80
|
-
value: op.value
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
op: "replace",
|
|
85
|
-
path: [...path, key],
|
|
86
|
-
value: op.value
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
if (!Object.hasOwn(obj, key)) return {
|
|
90
|
-
op: "replace",
|
|
91
|
-
path: [...path, key],
|
|
92
|
-
value: vivified(segments, i + 1, op)
|
|
93
|
-
};
|
|
94
|
-
path.push(key);
|
|
95
|
-
node = obj[key];
|
|
96
|
-
}
|
|
97
|
-
if (op.type === "append-text") {
|
|
98
|
-
assertStringTarget(node, op);
|
|
99
|
-
return {
|
|
100
|
-
op: "add",
|
|
101
|
-
path: [node.length],
|
|
102
|
-
value: op.value
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
op: "replace",
|
|
107
|
-
path: [],
|
|
108
|
-
value: op.value
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
//#endregion
|
|
112
|
-
export { translateStateOp };
|
|
113
|
-
|
|
114
|
-
//# sourceMappingURL=stateOps.js.map
|
package/dist/stateOps.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stateOps.js","names":["AssistantTransportStateOperation","Statewire","TranslatedOp","Extract","Op","op","UNSAFE_SEGMENTS","Set","assertStringTarget","current","Error","path","join","vivified","segments","from","type","undefined","value","i","length","translateStateOp","root","unsafe","find","segment","has","console","warn","node","slice","key","last","Array","isArray","idx","Number","isNaN","insert","Object","hasOwn","push","obj","Record"],"sources":["../src/stateOps.ts"],"sourcesContent":["import type { AssistantTransportStateOperation } from \"assistant-stream\";\nimport type { Statewire } from \"statewire\";\n\nexport type TranslatedOp = Extract<Statewire.Op, { op: \"replace\" | \"add\" }>;\n\nconst UNSAFE_SEGMENTS = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nconst assertStringTarget = (\n current: unknown,\n op: AssistantTransportStateOperation,\n) => {\n if (typeof current !== \"string\") {\n throw new Error(`Expected string at path [${op.path.join(\", \")}]`);\n }\n};\n\n// Missing intermediates auto-vivify as nested objects, exactly like gorp's updatePath.\nconst vivified = (\n segments: readonly string[],\n from: number,\n op: AssistantTransportStateOperation,\n): unknown => {\n if (op.type === \"append-text\") assertStringTarget(undefined, op);\n let value: unknown = op.value;\n for (let i = segments.length - 1; i >= from; i--) {\n value = { [segments[i]!]: value };\n }\n return value;\n};\n\n// Expresses a gorp `update-state` op as a statewire op against the current\n// state, replicating GorpStreamAccumulator's path semantics — including its\n// errors. Ops with unsafe path segments are stripped with a warning.\nexport const translateStateOp = (\n root: unknown,\n op: AssistantTransportStateOperation,\n): TranslatedOp | undefined => {\n const segments = op.path;\n const unsafe = segments.find((segment) => UNSAFE_SEGMENTS.has(segment));\n if (unsafe !== undefined) {\n console.warn(`statewire: stripped op with unsafe path segment \"${unsafe}\"`);\n return undefined;\n }\n const path: (string | number)[] = [];\n let node: unknown = root;\n\n for (let i = 0; i < segments.length; i++) {\n if (node === null || node === undefined) {\n return { op: \"replace\", path, value: vivified(segments, i, op) };\n }\n if (typeof node !== \"object\") {\n throw new Error(`Invalid path: [${segments.slice(i).join(\", \")}]`);\n }\n const key = segments[i]!;\n const last = i === segments.length - 1;\n\n if (Array.isArray(node)) {\n // gorp parity: Number(\"\"), and thus an empty-string key, is index 0\n const idx = Number(key);\n if (Number.isNaN(idx)) {\n throw new Error(\n `Expected array index at [${segments.slice(i).join(\", \")}]`,\n );\n }\n if (idx > node.length || idx < 0) {\n throw new Error(`Insert array index out of bounds`);\n }\n const insert = idx === node.length;\n if (last) {\n if (op.type === \"append-text\") {\n const current = insert ? undefined : node[idx];\n assertStringTarget(current, op);\n return {\n op: \"add\",\n path: [...path, idx, (current as string).length],\n value: op.value,\n };\n }\n return {\n op: insert ? \"add\" : \"replace\",\n path: [...path, idx],\n value: op.value,\n };\n }\n if (insert || !Object.hasOwn(node, idx)) {\n return {\n op: insert ? \"add\" : \"replace\",\n path: [...path, idx],\n value: vivified(segments, i + 1, op),\n };\n }\n path.push(idx);\n node = node[idx];\n continue;\n }\n\n const obj = node as Record<string, unknown>;\n if (last) {\n if (op.type === \"append-text\") {\n const current = Object.hasOwn(obj, key) ? obj[key] : undefined;\n assertStringTarget(current, op);\n return {\n op: \"add\",\n path: [...path, key, (current as string).length],\n value: op.value,\n };\n }\n return { op: \"replace\", path: [...path, key], value: op.value };\n }\n if (!Object.hasOwn(obj, key)) {\n return {\n op: \"replace\",\n path: [...path, key],\n value: vivified(segments, i + 1, op),\n };\n }\n path.push(key);\n node = obj[key];\n }\n\n if (op.type === \"append-text\") {\n assertStringTarget(node, op);\n return { op: \"add\", path: [(node as string).length], value: op.value };\n }\n return { op: \"replace\", path: [], value: op.value };\n};\n"],"mappings":";AAKA,MAAMM,kCAAkB,IAAIC,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;AAEzE,MAAMC,sBACJC,SACAJ,OACG;CACH,IAAI,OAAOI,YAAY,UACrB,MAAM,IAAIC,MAAM,4BAA4BL,GAAGM,KAAKC,KAAK,IAAI,EAAC,EAAG;AAErE;AAGA,MAAMC,YACJC,UACAC,MACAV,OACY;CACZ,IAAIA,GAAGW,SAAS,eAAeR,mBAAmBS,KAAAA,GAAWZ,EAAE;CAC/D,IAAIa,QAAiBb,GAAGa;CACxB,KAAK,IAAIC,IAAIL,SAASM,SAAS,GAAGD,KAAKJ,MAAMI,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