@womp/spark-agent 15.0.0 → 15.0.2
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/CHANGELOG.md +24 -0
- package/dist/server/express.js +27 -7
- package/dist/server/service.js +19 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,30 @@ Notable changes to `@womp/spark-agent`, newest first. Versions follow
|
|
|
4
4
|
[Semantic Versioning](https://semver.org/). Add an entry with each version bump; describe what
|
|
5
5
|
changed for hosts and users, and how to migrate across breaking changes.
|
|
6
6
|
|
|
7
|
+
## 15.0.2 — 2026-10-22
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- The Express `/runs/:runId/stream` route ends when its client disconnects. A write waiting for
|
|
12
|
+
`drain` on a backed-up response waited forever once the client left, because a closed response
|
|
13
|
+
emits `close`, not `drain`. That covers a large chunk, or the closing `[DONE]` written after the
|
|
14
|
+
client has already gone. The route never reached its cleanup, so it kept its request, response and
|
|
15
|
+
socket, and, when stuck mid-stream, its `streamRun` listener and every later chunk of the run. The
|
|
16
|
+
route now also listens for `close` before its first lookup, so a client that leaves during it is
|
|
17
|
+
noticed.
|
|
18
|
+
- `SparkAgentService.streamRun` ends when its signal aborts while it is reading the run. Before, it
|
|
19
|
+
then waited for the run's next chunk, or forever for a run waiting on the user.
|
|
20
|
+
|
|
21
|
+
## 15.0.1 — 2026-10-21
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- Stopping a run or a goal while the model is streaming its answer ends the run as cancelled with
|
|
26
|
+
the stop's own reason. `SparkAgentService` aborted with a plain `Error`, which the AI SDK does not
|
|
27
|
+
recognise as an abort, so it reported the cut-off answer as `Failed to process successful
|
|
28
|
+
response`. Hosts showed that as an unreadable AI response until the stored run replaced it. The
|
|
29
|
+
stop, cancel and shutdown reasons are now named `AbortError`; their messages are unchanged.
|
|
30
|
+
|
|
7
31
|
## 15.0.0 — 2026-10-21
|
|
8
32
|
|
|
9
33
|
Procedural materials are FlowIR only. The native-JSON helper path and its skills are removed.
|
package/dist/server/express.js
CHANGED
|
@@ -33,10 +33,26 @@ function parseSequence(value) {
|
|
|
33
33
|
function encodeFilename(value) {
|
|
34
34
|
return encodeURIComponent(value).replace(/[!'()*]/gu, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Writes one SSE frame, waiting for `drain` when the socket is backed up.
|
|
38
|
+
* `drain` never fires once the client is gone, so the wait also ends when
|
|
39
|
+
* `signal` aborts (the response closed). Without that, a client that
|
|
40
|
+
* disconnected mid-backpressure left the stream route waiting forever, and its
|
|
41
|
+
* `streamRun` listener collecting the rest of the run's chunks for good.
|
|
42
|
+
*/
|
|
43
|
+
async function write(response, value, signal) {
|
|
44
|
+
if (signal.aborted || response.destroyed)
|
|
45
|
+
return;
|
|
37
46
|
if (response.write(value))
|
|
38
47
|
return;
|
|
39
|
-
|
|
48
|
+
try {
|
|
49
|
+
await once(response, "drain", { signal });
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (signal.aborted)
|
|
53
|
+
return;
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
40
56
|
}
|
|
41
57
|
export function createSparkAgentRouter(options) {
|
|
42
58
|
const router = express.Router();
|
|
@@ -118,10 +134,14 @@ export function createSparkAgentRouter(options) {
|
|
|
118
134
|
response.json({ run: await options.service.cancelRun(ownerId, request.params.runId) });
|
|
119
135
|
});
|
|
120
136
|
router.get("/runs/:runId/stream", async (request, response) => {
|
|
121
|
-
|
|
122
|
-
|
|
137
|
+
// Listening for `close` before the first await: a client that leaves
|
|
138
|
+
// while the owner or run is being looked up still ends this stream.
|
|
123
139
|
const abortController = new AbortController();
|
|
124
140
|
response.on("close", () => abortController.abort());
|
|
141
|
+
const ownerId = await resolveOwnerId(request);
|
|
142
|
+
await options.service.getRun(ownerId, request.params.runId);
|
|
143
|
+
if (response.destroyed)
|
|
144
|
+
abortController.abort();
|
|
125
145
|
response.status(200);
|
|
126
146
|
response.set({
|
|
127
147
|
"Cache-Control": "no-cache, no-transform",
|
|
@@ -144,16 +164,16 @@ export function createSparkAgentRouter(options) {
|
|
|
144
164
|
if (heartbeatTimer !== undefined)
|
|
145
165
|
clearTimeout(heartbeatTimer);
|
|
146
166
|
if (next.type === "heartbeat") {
|
|
147
|
-
await write(response, ": ping\n\n");
|
|
167
|
+
await write(response, ": ping\n\n", abortController.signal);
|
|
148
168
|
continue;
|
|
149
169
|
}
|
|
150
170
|
if (next.result.done)
|
|
151
171
|
break;
|
|
152
172
|
const chunk = next.result.value;
|
|
153
|
-
await write(response, `id: ${chunk.sequence}\ndata: ${JSON.stringify(chunk)}\n\n
|
|
173
|
+
await write(response, `id: ${chunk.sequence}\ndata: ${JSON.stringify(chunk)}\n\n`, abortController.signal);
|
|
154
174
|
pending = chunks.next();
|
|
155
175
|
}
|
|
156
|
-
await write(response, "data: [DONE]\n\n");
|
|
176
|
+
await write(response, "data: [DONE]\n\n", abortController.signal);
|
|
157
177
|
}
|
|
158
178
|
finally {
|
|
159
179
|
await chunks.return(undefined);
|
package/dist/server/service.js
CHANGED
|
@@ -24,6 +24,16 @@ function sleep(ms) {
|
|
|
24
24
|
timer.unref();
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* The reason a run is stopped with on purpose. It must be NAMED `AbortError`:
|
|
29
|
+
* the AI SDK recognises an abort by that name only, so a plain Error that cuts
|
|
30
|
+
* off a streaming model response is reported as the response failing
|
|
31
|
+
* (`AI_APICallError: Failed to process successful response`), and a user's
|
|
32
|
+
* stop reached their chat as "a response that couldn't be read".
|
|
33
|
+
*/
|
|
34
|
+
function stopReason(message) {
|
|
35
|
+
return Object.assign(new Error(message), { name: "AbortError" });
|
|
36
|
+
}
|
|
27
37
|
function runNotSaved(cause) {
|
|
28
38
|
return new Error(RUN_NOT_SAVED_ERROR, { cause });
|
|
29
39
|
}
|
|
@@ -281,7 +291,7 @@ export class SparkAgentService {
|
|
|
281
291
|
}
|
|
282
292
|
});
|
|
283
293
|
if (interrupt) {
|
|
284
|
-
this.controllers.get(interrupt)?.abort(
|
|
294
|
+
this.controllers.get(interrupt)?.abort(stopReason("Goal stopped by the user."));
|
|
285
295
|
await this.executions.get(interrupt);
|
|
286
296
|
result.goal = (await this.getConversation(ownerId, conversationId)).goal;
|
|
287
297
|
}
|
|
@@ -330,7 +340,7 @@ export class SparkAgentService {
|
|
|
330
340
|
async close() {
|
|
331
341
|
this.closing = true;
|
|
332
342
|
for (const controller of this.controllers.values())
|
|
333
|
-
controller.abort(
|
|
343
|
+
controller.abort(stopReason("Standalone host is shutting down"));
|
|
334
344
|
await Promise.all([...this.executions.values()]);
|
|
335
345
|
}
|
|
336
346
|
async submitMessage(input) {
|
|
@@ -458,7 +468,7 @@ export class SparkAgentService {
|
|
|
458
468
|
return this.getRun(ownerId, runId);
|
|
459
469
|
throw new Error("The run's executor is unavailable; cancellation could not be confirmed.");
|
|
460
470
|
}
|
|
461
|
-
controller.abort(
|
|
471
|
+
controller.abort(stopReason("Run cancelled by the user."));
|
|
462
472
|
// Drain receipts and pending host work before publishing a terminal state.
|
|
463
473
|
await execution;
|
|
464
474
|
return this.getRun(ownerId, runId);
|
|
@@ -508,7 +518,12 @@ export class SparkAgentService {
|
|
|
508
518
|
resolve();
|
|
509
519
|
};
|
|
510
520
|
signal.addEventListener("abort", onAbort, { once: true });
|
|
511
|
-
|
|
521
|
+
// An abort while the run was being read has already fired, so the
|
|
522
|
+
// listener above never would: without this the stream waited for
|
|
523
|
+
// the run's next chunk, or forever for a run parked on the user.
|
|
524
|
+
if (signal.aborted)
|
|
525
|
+
onAbort();
|
|
526
|
+
else if (notification !== observedNotification || queue.length > 0)
|
|
512
527
|
wake?.();
|
|
513
528
|
});
|
|
514
529
|
}
|