@nimbus-dev/client 0.15.1 → 0.17.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/README.md +1 -0
- package/dist/index.cjs +1948 -1855
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mock-client.d.ts +4 -1
- package/dist/mock-client.d.ts.map +1 -1
- package/dist/mock-client.js +20 -1
- package/dist/mock-client.js.map +1 -1
- package/dist/nimbus-client.d.ts +113 -7
- package/dist/nimbus-client.d.ts.map +1 -1
- package/dist/nimbus-client.js +61 -6
- package/dist/nimbus-client.js.map +1 -1
- package/dist/stream-events.d.ts +25 -4
- package/dist/stream-events.d.ts.map +1 -1
- package/dist/validate.d.ts +4 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +61 -6
- package/dist/validate.js.map +1 -1
- package/dist/workflow-stream.d.ts +11 -14
- package/dist/workflow-stream.d.ts.map +1 -1
- package/dist/workflow-stream.js +38 -14
- package/dist/workflow-stream.js.map +1 -1
- package/package.json +2 -2
package/dist/workflow-stream.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
/**
|
|
2
3
|
* Stream a workflow run's per-step output.
|
|
3
4
|
*
|
|
4
5
|
* Shape note — this is NOT `askStream`. `engine.askStream` returns a `streamId`
|
|
5
|
-
* immediately and every notification carries it
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* immediately and every notification carries it. `workflow.run` is a single RPC
|
|
7
|
+
* that resolves only with the final `WorkflowRunResult`, so a gateway-minted id
|
|
8
|
+
* could never arrive in time. The CLIENT therefore mints the id here, sends it
|
|
9
|
+
* with the run, and filters `agent.chunk` by it — which is also what makes the
|
|
10
|
+
* run cancellable.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* There is also no cancel: the gateway exposes no `workflow.cancel`. Breaking out
|
|
18
|
-
* of the `for await` detaches the listener, but the run continues server-side and
|
|
19
|
-
* `result` still settles.
|
|
12
|
+
* Chunks with no `streamId` are accepted rather than dropped. A gateway that
|
|
13
|
+
* predates chunk tagging emits bare `{ text }`, and filtering those out would
|
|
14
|
+
* silently produce an empty stream; against such a gateway the old caveat still
|
|
15
|
+
* holds — one streaming workflow at a time per connection, not interleaved with
|
|
16
|
+
* a streaming `ask` — because its chunks genuinely cannot be told apart. Chunks
|
|
17
|
+
* tagged for a DIFFERENT run are always ignored.
|
|
20
18
|
*/
|
|
21
19
|
export function createWorkflowRunStream(ipc, params, validate) {
|
|
22
20
|
const queue = [];
|
|
23
21
|
const waiters = [];
|
|
24
22
|
let done = false;
|
|
25
23
|
let detach;
|
|
24
|
+
// Minted, not received: workflow.run resolves too late for a gateway id to be
|
|
25
|
+
// useful. Unique per run — the gateway rejects reuse of a live id with -32602.
|
|
26
|
+
const streamId = params.streamId ?? randomUUID();
|
|
26
27
|
const push = (ev) => {
|
|
27
28
|
if (done)
|
|
28
29
|
return;
|
|
@@ -48,6 +49,11 @@ export function createWorkflowRunStream(ipc, params, validate) {
|
|
|
48
49
|
const onChunk = (p) => {
|
|
49
50
|
if (typeof p !== "object" || p === null)
|
|
50
51
|
return;
|
|
52
|
+
const tag = p.streamId;
|
|
53
|
+
// An absent tag means an older gateway that cannot tag at all — take it.
|
|
54
|
+
// A tag that is not ours belongs to another run or a concurrent ask.
|
|
55
|
+
if (typeof tag === "string" && tag !== streamId)
|
|
56
|
+
return;
|
|
51
57
|
const text = p.text;
|
|
52
58
|
if (typeof text === "string")
|
|
53
59
|
push({ type: "chunk", text });
|
|
@@ -68,6 +74,7 @@ export function createWorkflowRunStream(ipc, params, validate) {
|
|
|
68
74
|
sessionId: params.sessionId,
|
|
69
75
|
agent: params.agent,
|
|
70
76
|
paramsOverride: params.paramsOverride,
|
|
77
|
+
streamId,
|
|
71
78
|
});
|
|
72
79
|
return validate("workflow.run", raw);
|
|
73
80
|
}
|
|
@@ -87,6 +94,23 @@ export function createWorkflowRunStream(ipc, params, validate) {
|
|
|
87
94
|
});
|
|
88
95
|
return {
|
|
89
96
|
result,
|
|
97
|
+
streamId,
|
|
98
|
+
async cancel() {
|
|
99
|
+
// Deliberately does NOT finish() the stream. Cancellation lands at the
|
|
100
|
+
// next step boundary, so the run keeps emitting and then settles with
|
|
101
|
+
// status "cancelled" — closing here would drop that terminal result,
|
|
102
|
+
// which is the only confirmation the cancel took effect.
|
|
103
|
+
try {
|
|
104
|
+
const raw = await ipc.call("workflow.cancel", { streamId });
|
|
105
|
+
const flag = raw?.cancelled;
|
|
106
|
+
return { cancelled: flag === true };
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// A gateway with no workflow.cancel rejects the method. Nothing was
|
|
110
|
+
// cancelled, and the run carries on — report that rather than throw.
|
|
111
|
+
return { cancelled: false };
|
|
112
|
+
}
|
|
113
|
+
},
|
|
90
114
|
[Symbol.asyncIterator]() {
|
|
91
115
|
return {
|
|
92
116
|
next() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-stream.js","sourceRoot":"","sources":["../src/workflow-stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow-stream.js","sourceRoot":"","sources":["../src/workflow-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAezC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,uBAAuB,CACrC,GAAc,EACd,MAA+B,EAC/B,QAA6D;IAE7D,MAAM,KAAK,GAAuB,EAAE,CAAC;IACrC,MAAM,OAAO,GAAc,EAAE,CAAC;IAC9B,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,IAAI,MAAgC,CAAC;IACrC,8EAA8E;IAC9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ACT,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAwC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC1F,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimbus-dev/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@nimbus-dev/sdk": "^1.6.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@biomejs/biome": "^2.5.
|
|
47
|
+
"@biomejs/biome": "^2.5.7",
|
|
48
48
|
"@types/bun": "^1.3.14",
|
|
49
49
|
"typescript": "^7.0.2"
|
|
50
50
|
}
|