@nimbus-dev/client 0.17.3 → 0.19.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 +45 -8
- package/dist/agents.d.ts +28 -5
- package/dist/agents.d.ts.map +1 -1
- package/dist/agents.js +20 -0
- package/dist/agents.js.map +1 -1
- package/dist/ask-stream.d.ts.map +1 -1
- package/dist/ask-stream.js +25 -45
- package/dist/ask-stream.js.map +1 -1
- package/dist/event-queue.d.ts +29 -0
- package/dist/event-queue.d.ts.map +1 -0
- package/dist/event-queue.js +42 -0
- package/dist/event-queue.js.map +1 -0
- package/dist/index.cjs +369 -266
- 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/ipc-transport.d.ts.map +1 -1
- package/dist/ipc-transport.js +7 -1
- package/dist/ipc-transport.js.map +1 -1
- package/dist/mock-client.d.ts +17 -17
- package/dist/mock-client.d.ts.map +1 -1
- package/dist/mock-client.js +150 -129
- package/dist/mock-client.js.map +1 -1
- package/dist/nimbus-client.d.ts +82 -30
- package/dist/nimbus-client.d.ts.map +1 -1
- package/dist/nimbus-client.js +60 -30
- package/dist/nimbus-client.js.map +1 -1
- package/dist/stream-events.d.ts +7 -0
- package/dist/stream-events.d.ts.map +1 -1
- package/dist/validate.d.ts +7 -8
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +61 -21
- package/dist/validate.js.map +1 -1
- package/dist/workflow-stream.d.ts +8 -1
- package/dist/workflow-stream.d.ts.map +1 -1
- package/dist/workflow-stream.js +29 -41
- package/dist/workflow-stream.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -31,8 +31,10 @@ const out = await client.queryItems({ services: ["github"], limit: 10 });
|
|
|
31
31
|
await client.close();
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
To point at a specific socket instead, pass it as an override — e.g. a
|
|
35
|
-
with
|
|
34
|
+
To point at a specific socket instead, pass it as an override — e.g. a gateway
|
|
35
|
+
relocated with `NIMBUS_GATEWAY_SOCKET`, which this client does not read (only the
|
|
36
|
+
`gateway.json` state file records that relocation, so a missing or stale state
|
|
37
|
+
file leaves discovery on the platform default):
|
|
36
38
|
|
|
37
39
|
```typescript
|
|
38
40
|
const { socketPath } = await discoverSocketPath({ override: "/tmp/nimbus-gateway.sock" });
|
|
@@ -50,7 +52,7 @@ covers these gateway namespaces:
|
|
|
50
52
|
| Namespace | Methods |
|
|
51
53
|
| --- | --- |
|
|
52
54
|
| Ask / agents | `agentInvoke`, the nine briefs (`agentsExpert`, `agentsImpact`, `agentsCatchup`, `agentsGhost`, `agentsConflicts`, `agentsHuddle`, `agentsJanitor`, `agentsPreflight`, `agentsWhy`) + `agentsWhyPeek` |
|
|
53
|
-
| Index & search | `queryItems`, `searchRanked`, `querySql` |
|
|
55
|
+
| Index & search | `queryItems`, `searchRanked`, `searchRankedWithRetrieval`, `querySql` |
|
|
54
56
|
| Sessions | `getSessionTranscript`, `sessionAppend`, `sessionRecall`, `sessionList`, `sessionClear` |
|
|
55
57
|
| Audit | `auditList`, `auditVerify`, `auditGetSummary`, `auditToolCalls` |
|
|
56
58
|
| Egress | `egressHead`, `egressList`, `egressVerify`, `egressProveWindow` |
|
|
@@ -65,6 +67,41 @@ Streaming and subscriptions: `askStream` (`AskStreamHandle`), `workflowRunStream
|
|
|
65
67
|
`subscribeConnectorConfigChanged` (`ConnectorConfigChanged`),
|
|
66
68
|
`subscribeAgentBrief` (`AgentBriefEvent`), and `cancelStream`.
|
|
67
69
|
|
|
70
|
+
### Answering a typed confirmation
|
|
71
|
+
|
|
72
|
+
A Wave 4 connector write is approved only when the owner types the confirm text the
|
|
73
|
+
Gateway names. `subscribeHitl` delivers that text as `HitlRequest.confirmText` (absent on
|
|
74
|
+
an ordinary request); reply with what the person typed, and say where the answer came from:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
client.subscribeHitl(async (req) => {
|
|
78
|
+
// EVERY request is put to the person. `askPerson` and `askPersonToType` are yours to write:
|
|
79
|
+
// they show `req.prompt` and return what the person decided or typed.
|
|
80
|
+
if (req.confirmText === undefined) {
|
|
81
|
+
const approved = await askPerson(req.prompt);
|
|
82
|
+
await client.consentRespond({ requestId: req.requestId, approved, answerSource: "human" });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// A typed confirmation: the person's text IS the decision. Send what they typed, unchanged.
|
|
86
|
+
// `null` means they dismissed the prompt.
|
|
87
|
+
const typed = await askPersonToType(req.prompt, req.confirmText);
|
|
88
|
+
await client.consentRespond({
|
|
89
|
+
requestId: req.requestId,
|
|
90
|
+
approved: typed !== null,
|
|
91
|
+
...(typed === null ? {} : { typed }),
|
|
92
|
+
answerSource: "human",
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Report `answerSource: "human"` only when a person answered that request. An answer your code
|
|
98
|
+
decided is `"auto"`; one a script or a flag supplied is `"script"`.
|
|
99
|
+
|
|
100
|
+
The Gateway compares `typed` to `confirmText` exactly (no trimming, case-sensitive); a
|
|
101
|
+
missing or wrong value denies the write. `answerSource` is optional: omitted, the Gateway
|
|
102
|
+
records `unknown`, and a Wave 4 write is never approved by `auto` or `script`. Any value
|
|
103
|
+
outside the three listed is rejected before it is sent.
|
|
104
|
+
|
|
68
105
|
### Validated responses
|
|
69
106
|
|
|
70
107
|
Every `NimbusClient` method validates the Gateway's JSON-RPC result before
|
|
@@ -119,11 +156,11 @@ const provablyLocal = sound && EGRESS_COVERAGE_CLASSES.every(observed);
|
|
|
119
156
|
|
|
120
157
|
Releases are automated by [release-please](https://github.com/googleapis/release-please).
|
|
121
158
|
Merged [Conventional Commits](https://www.conventionalcommits.org/) on `main` open a
|
|
122
|
-
release PR; merging it
|
|
123
|
-
|
|
124
|
-
Actions OIDC / npm **trusted-publisher**. There is
|
|
125
|
-
trusted-publisher binding authenticates the workflow
|
|
126
|
-
attestation (see [`SECURITY.md`](./SECURITY.md)).
|
|
159
|
+
release PR; merging it runs `.github/workflows/release.yml`, which tags the release
|
|
160
|
+
(`client-vX.Y.Z`) and publishes `@nimbus-dev/client` to npm with
|
|
161
|
+
`npm publish --provenance` via GitHub Actions OIDC / npm **trusted-publisher**. There is
|
|
162
|
+
**no long-lived npm token** — the trusted-publisher binding authenticates the workflow
|
|
163
|
+
and attaches a verifiable provenance attestation (see [`SECURITY.md`](./SECURITY.md)).
|
|
127
164
|
|
|
128
165
|
## See also
|
|
129
166
|
|
package/dist/agents.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export type WhyParams = {
|
|
|
51
51
|
ref: string;
|
|
52
52
|
line?: number;
|
|
53
53
|
};
|
|
54
|
-
|
|
54
|
+
type AgentParamsMap = {
|
|
55
55
|
expert: ExpertParams;
|
|
56
56
|
impact: ImpactParams;
|
|
57
57
|
catchup: CatchupParams;
|
|
@@ -61,8 +61,30 @@ export type AgentParamsFor<A extends AgentName> = {
|
|
|
61
61
|
janitor: JanitorParams;
|
|
62
62
|
preflight: PreflightParams;
|
|
63
63
|
why: WhyParams;
|
|
64
|
-
}
|
|
65
|
-
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Resolves to `Name` unchanged; the `extends AgentName` constraint is its whole purpose. Wrapping a
|
|
67
|
+
* union in it is a compile-time subset check: a member the SDK's `AgentName` does not contain fails
|
|
68
|
+
* to compile at the wrapping site, and nothing is emitted at runtime.
|
|
69
|
+
*/
|
|
70
|
+
type KnownToTheSdk<Name extends AgentName> = Name;
|
|
71
|
+
/**
|
|
72
|
+
* The agents THIS CLIENT implements a method for — nine of them.
|
|
73
|
+
*
|
|
74
|
+
* Deliberately not `AgentName`, which is the gateway's full roster and grows without this package:
|
|
75
|
+
* SDK 2.0.0 added `decisions`, `glossary` and `ownership`, and typing the dispatch over the whole
|
|
76
|
+
* union made every lookup an error, because there is no `agentsDecisions()` here to look up. Adding
|
|
77
|
+
* those three is a feature — methods, param and brief types, mock fixtures, a README row — not
|
|
78
|
+
* something a dependency bump should perform silently.
|
|
79
|
+
*
|
|
80
|
+
* The narrowing tolerates ADDITIONS and still refuses REMOVALS: the {@link KnownToTheSdk} wrapper
|
|
81
|
+
* stops compiling if any of the nine ceases to be an `AgentName`, which is the direction that would
|
|
82
|
+
* leave this client calling a gateway method that no longer exists.
|
|
83
|
+
*/
|
|
84
|
+
export type SupportedAgentName = KnownToTheSdk<keyof AgentParamsMap>;
|
|
85
|
+
export declare const SUPPORTED_AGENT_NAMES: readonly SupportedAgentName[];
|
|
86
|
+
export type AgentParamsFor<A extends SupportedAgentName> = AgentParamsMap[A];
|
|
87
|
+
export type AgentBriefEvent<A extends SupportedAgentName> = {
|
|
66
88
|
ok: true;
|
|
67
89
|
sessionId: string;
|
|
68
90
|
brief: string;
|
|
@@ -85,7 +107,8 @@ export declare class AgentTimeoutError extends Error {
|
|
|
85
107
|
constructor(agent: AgentName, sessionId: string, timeoutMs: number);
|
|
86
108
|
}
|
|
87
109
|
/** Narrow a `<agent>.briefReady` payload, or null if it is malformed. */
|
|
88
|
-
export declare function parseBriefReady<A extends
|
|
110
|
+
export declare function parseBriefReady<A extends SupportedAgentName>(agent: A, params: unknown): AgentBriefEvent<A> | null;
|
|
89
111
|
/** Narrow a `<agent>.briefError` payload, or null if it is malformed. */
|
|
90
|
-
export declare function parseBriefError<A extends
|
|
112
|
+
export declare function parseBriefError<A extends SupportedAgentName>(params: unknown): AgentBriefEvent<A> | null;
|
|
113
|
+
export {};
|
|
91
114
|
//# sourceMappingURL=agents.d.ts.map
|
package/dist/agents.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,KAAK,SAAS,EAAgB,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE9E,eAAO,MAAM,wBAAwB,QAAS,CAAC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,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,YAAY,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAK9D;CACF;AAED,mEAAmE;AACnE,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,YAAY,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAKjE;CACF;AAMD,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,CAAC,SAAS,kBAAkB,EAC1D,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,OAAO,GACd,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI,CAM3B;AAED,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,CAAC,SAAS,kBAAkB,EAC1D,MAAM,EAAE,OAAO,GACd,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI,CAK3B"}
|
package/dist/agents.js
CHANGED
|
@@ -8,6 +8,26 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { BRIEF_GUARDS } from "@nimbus-dev/sdk";
|
|
10
10
|
export const DEFAULT_AGENT_TIMEOUT_MS = 30_000;
|
|
11
|
+
/**
|
|
12
|
+
* The same nine at RUNTIME, for callers that need to enumerate them (the conformance gate does).
|
|
13
|
+
*
|
|
14
|
+
* Built from an object checked with `satisfies Record<SupportedAgentName, true>` rather than written
|
|
15
|
+
* as a bare array: a name added to {@link AgentParamsMap} and forgotten here fails to compile, where
|
|
16
|
+
* a hand-kept array would simply be one short and every loop over it would silently skip the new
|
|
17
|
+
* agent.
|
|
18
|
+
*/
|
|
19
|
+
const SUPPORTED_AGENTS = {
|
|
20
|
+
expert: true,
|
|
21
|
+
impact: true,
|
|
22
|
+
catchup: true,
|
|
23
|
+
ghost: true,
|
|
24
|
+
conflicts: true,
|
|
25
|
+
huddle: true,
|
|
26
|
+
janitor: true,
|
|
27
|
+
preflight: true,
|
|
28
|
+
why: true,
|
|
29
|
+
};
|
|
30
|
+
export const SUPPORTED_AGENT_NAMES = Object.keys(SUPPORTED_AGENTS);
|
|
11
31
|
/** Thrown when the gateway emits `<agent>.briefError` for our session. */
|
|
12
32
|
export class AgentBriefError extends Error {
|
|
13
33
|
agent;
|
package/dist/agents.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAkB,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AAE9E,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAkB,YAAY,EAAiB,MAAM,iBAAiB,CAAC;AAE9E,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAuE/C;;;;;;;GAOG;AACH,MAAM,gBAAgB,GAAG;IACvB,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,IAAI;IACX,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,IAAI;IACf,GAAG,EAAE,IAAI;CAC0C,CAAC;AAEtD,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAkC,CAAC;AAQpG,0EAA0E;AAC1E,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,KAAK,CAAY;IACjB,SAAS,CAAS;IAC3B,YAAY,KAAgB,EAAE,SAAiB,EAAE,MAAc;Q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C;AAED,yEAAyE;AACzE,MAAM,UAAU,eAAe,CAC7B,MAAe;IAEf,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACpC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC5E,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACzC,CAAC"}
|
package/dist/ask-stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-stream.d.ts","sourceRoot":"","sources":["../src/ask-stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ask-stream.d.ts","sourceRoot":"","sources":["../src/ask-stream.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAEzF,wBAAgB,eAAe,CAC7B,GAAG,EAAE,SAAS,EACd,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,gBAAqB,GAC1B,eAAe,CAqNjB"}
|
package/dist/ask-stream.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { createEventQueue } from "./event-queue.js";
|
|
1
2
|
export function createAskStream(ipc, input, opts = {}) {
|
|
2
|
-
const
|
|
3
|
-
const waiters = [];
|
|
4
|
-
let done = false;
|
|
3
|
+
const events = createEventQueue();
|
|
5
4
|
let streamIdResolved;
|
|
6
5
|
let cancelled = false;
|
|
7
6
|
let unsubscribers = [];
|
|
@@ -10,28 +9,13 @@ export function createAskStream(ipc, input, opts = {}) {
|
|
|
10
9
|
// note below), so tokens pipelined in the same socket chunk as the RPC response
|
|
11
10
|
// are not lost.
|
|
12
11
|
let early = [];
|
|
13
|
-
const push = (ev) => {
|
|
14
|
-
if (done)
|
|
15
|
-
return;
|
|
16
|
-
if (waiters.length > 0) {
|
|
17
|
-
const w = waiters.shift();
|
|
18
|
-
w.resolve({ value: ev, done: false });
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
queue.push(ev);
|
|
22
|
-
};
|
|
23
12
|
const finish = () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
unsubscribers = [];
|
|
31
|
-
while (waiters.length > 0) {
|
|
32
|
-
const w = waiters.shift();
|
|
33
|
-
w.resolve({ value: undefined, done: true });
|
|
34
|
-
}
|
|
13
|
+
events.close(() => {
|
|
14
|
+
early = [];
|
|
15
|
+
for (const u of unsubscribers)
|
|
16
|
+
u();
|
|
17
|
+
unsubscribers = [];
|
|
18
|
+
});
|
|
35
19
|
};
|
|
36
20
|
const cancelUpstream = async (sid) => {
|
|
37
21
|
await ipc.call("engine.cancelStream", { streamId: sid }).catch(() => undefined);
|
|
@@ -57,20 +41,20 @@ export function createAskStream(ipc, input, opts = {}) {
|
|
|
57
41
|
const onToken = whenMatched((params) => {
|
|
58
42
|
const text = params.text;
|
|
59
43
|
if (typeof text === "string")
|
|
60
|
-
push({ type: "token", text });
|
|
44
|
+
events.push({ type: "token", text });
|
|
61
45
|
});
|
|
62
46
|
const onDone = whenMatched((params) => {
|
|
63
47
|
const meta = params.meta ?? {};
|
|
64
48
|
const reply = typeof meta.reply === "string" ? meta.reply : "";
|
|
65
49
|
const sessionId = typeof meta.sessionId === "string" ? meta.sessionId : "";
|
|
66
|
-
push({ type: "done", reply, sessionId });
|
|
50
|
+
events.push({ type: "done", reply, sessionId });
|
|
67
51
|
finish();
|
|
68
52
|
});
|
|
69
53
|
const onError = whenMatched((params) => {
|
|
70
54
|
const p = params;
|
|
71
55
|
const code = typeof p.code === "string" ? p.code : "stream_error";
|
|
72
56
|
const message = typeof p.error === "string" ? p.error : "Stream error";
|
|
73
|
-
push({ type: "error", code, message });
|
|
57
|
+
events.push({ type: "error", code, message });
|
|
74
58
|
finish();
|
|
75
59
|
});
|
|
76
60
|
const onSubTask = whenMatched((params) => {
|
|
@@ -85,13 +69,18 @@ export function createAskStream(ipc, input, opts = {}) {
|
|
|
85
69
|
progress: p.progress,
|
|
86
70
|
}
|
|
87
71
|
: { type: "subTaskProgress", subTaskId: p.subTaskId, status: p.status };
|
|
88
|
-
push(ev);
|
|
72
|
+
events.push(ev);
|
|
89
73
|
});
|
|
90
74
|
const onHitl = whenMatched((params) => {
|
|
91
75
|
const p = params;
|
|
92
76
|
if (typeof p.requestId !== "string" || typeof p.prompt !== "string")
|
|
93
77
|
return;
|
|
94
|
-
push({
|
|
78
|
+
events.push({
|
|
79
|
+
type: "hitlBatch",
|
|
80
|
+
requestId: p.requestId,
|
|
81
|
+
prompt: p.prompt,
|
|
82
|
+
details: p.details,
|
|
83
|
+
});
|
|
95
84
|
});
|
|
96
85
|
// Register notification handlers *before* sending engine.askStream. The RPC
|
|
97
86
|
// response and the first stream notifications flow over the same socket and are
|
|
@@ -115,7 +104,7 @@ export function createAskStream(ipc, input, opts = {}) {
|
|
|
115
104
|
* for `failAll` to reject. Without this handler a gateway that dies mid-answer
|
|
116
105
|
* leaves the consumer's `for await` waiting forever — `failAll` runs over an
|
|
117
106
|
* empty pending map, `notifyClosed` over an empty handler set, and nothing ever
|
|
118
|
-
*
|
|
107
|
+
* settles a parked `next()`.
|
|
119
108
|
*
|
|
120
109
|
* Registered here rather than in each consumer so every caller inherits it; the
|
|
121
110
|
* CLI already hand-rolls this for its own notification-waits.
|
|
@@ -125,7 +114,7 @@ export function createAskStream(ipc, input, opts = {}) {
|
|
|
125
114
|
* the handle behind it) reachable from the live connection.
|
|
126
115
|
*/
|
|
127
116
|
const onTransportClose = (err) => {
|
|
128
|
-
push({ type: "error", code: "transport_closed", message: err.message });
|
|
117
|
+
events.push({ type: "error", code: "transport_closed", message: err.message });
|
|
129
118
|
finish();
|
|
130
119
|
};
|
|
131
120
|
ipc.onClose(onTransportClose);
|
|
@@ -146,7 +135,7 @@ export function createAskStream(ipc, input, opts = {}) {
|
|
|
146
135
|
const result = await ipc.call("engine.askStream", params);
|
|
147
136
|
const sid = result?.streamId;
|
|
148
137
|
if (typeof sid !== "string") {
|
|
149
|
-
push({ type: "error", code: "no_stream_id", message: "Gateway returned no streamId" });
|
|
138
|
+
events.push({ type: "error", code: "no_stream_id", message: "Gateway returned no streamId" });
|
|
150
139
|
finish();
|
|
151
140
|
throw new Error("no_stream_id");
|
|
152
141
|
}
|
|
@@ -157,13 +146,13 @@ export function createAskStream(ipc, input, opts = {}) {
|
|
|
157
146
|
for (const run of buffered)
|
|
158
147
|
run();
|
|
159
148
|
// A cancel/return that fired before the id resolved still needs to reach the
|
|
160
|
-
// gateway now that we know the streamId — check this before the `
|
|
149
|
+
// gateway now that we know the streamId — check this before the `closed` guard.
|
|
161
150
|
if (cancelled) {
|
|
162
151
|
await cancelUpstream(sid);
|
|
163
152
|
finish();
|
|
164
153
|
return sid;
|
|
165
154
|
}
|
|
166
|
-
if (
|
|
155
|
+
if (events.closed)
|
|
167
156
|
return sid;
|
|
168
157
|
if (opts.signal !== undefined) {
|
|
169
158
|
const signal = opts.signal;
|
|
@@ -182,7 +171,7 @@ export function createAskStream(ipc, input, opts = {}) {
|
|
|
182
171
|
// A failed stream start (transport/RPC rejection) surfaces as an error event
|
|
183
172
|
// so a `for await` consumer can distinguish it from a clean empty stream.
|
|
184
173
|
// No-op if the stream already finished (e.g. the no_stream_id path above).
|
|
185
|
-
push({
|
|
174
|
+
events.push({
|
|
186
175
|
type: "error",
|
|
187
176
|
code: "stream_start_failed",
|
|
188
177
|
message: err instanceof Error ? err.message : String(err),
|
|
@@ -204,16 +193,7 @@ export function createAskStream(ipc, input, opts = {}) {
|
|
|
204
193
|
[Symbol.asyncIterator]() {
|
|
205
194
|
return {
|
|
206
195
|
next() {
|
|
207
|
-
|
|
208
|
-
const ev = queue.shift();
|
|
209
|
-
return Promise.resolve({ value: ev, done: false });
|
|
210
|
-
}
|
|
211
|
-
if (done) {
|
|
212
|
-
return Promise.resolve({ value: undefined, done: true });
|
|
213
|
-
}
|
|
214
|
-
return new Promise((resolve, reject) => {
|
|
215
|
-
waiters.push({ resolve, reject });
|
|
216
|
-
});
|
|
196
|
+
return events.next();
|
|
217
197
|
},
|
|
218
198
|
return() {
|
|
219
199
|
// Breaking out of `for await` must also tell the gateway to stop.
|
package/dist/ask-stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ask-stream.js","sourceRoot":"","sources":["../src/ask-stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ask-stream.js","sourceRoot":"","sources":["../src/ask-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIpD,MAAM,UAAU,eAAe,CAC7B,GAAc,EACd,KAAa,EACb,IAAI,GAAqB,EAAE;IAE3B,MAAM,MAAM,GAAG,gBAAgB,EAAe,CAAC;IAC/C,IAAI,gBAAoC,CAAC;IACzC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,aAAa,GAAsB,EAAE,CAAC;IAC1C,8EAA8E;IAC9E,iFAAiF;IACjF,gFAAgF;IAChF,gBAAgB;IAChB,IAAI,KAAK,GAAsB,EAAE,CAAC;IAElC,MAAM,MAAM,GAAG,GAAS,EAAE;QACxB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,KAAK,GAAG,EAAE,CAAC;YACX,KAAK,MAAM,CAAC,IAAI,aAAa;gBAAE,CAAC,EAAE,CAAC;YACnC,aAAa,GAAG,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,KAAK,EAAE,GAAW,EAAiB,EAAE;QAC1D,MAAM,GAAG,CAAC,IAAI,CAAC,qBAAqB,EAAE,EA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,CAAC;QACH,MAAM,EAAE,CAAC;IACX,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAoB;QAC9B,gGAAgG;QAChG,IAAI,QAAQ;YACV,OAAO,gBAAgB,IAAI,EAAE,CAAC;QAChC,CAAC;QACD,KAAK,CAAC,MAAM;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,MAAM,GAAG,GAAG,gBAAgB,CAAC;YAC7B,IAAI,GAAG,KAAK,SAAS;gBAAE,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;YACjD,MAAM,EAAE,CAAC;QACX,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC;YACpB,OAAO;gBACL,IAAI;oBACF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;gBACvB,CAAC;gBACD,MAAM;oBACJ,kEAAkE;oBAClE,SAAS,GAAG,IAAI,CAAC;oBACjB,MAAM,GAAG,GAAG,gBAAgB,CAAC;oBAC7B,IAAI,GAAG,KAAK,SAAS;wBAAE,KAAK,cAAc,CAAC,GAAG,CAAC,CAAC;oBAChD,MAAM,EAAE,CAAC;oBACT,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,SAAmC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;gBACrF,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The push-to-pull buffer behind `askStream` and `workflowRunStream`.
|
|
3
|
+
*
|
|
4
|
+
* Both handles turn Gateway notifications, which arrive whenever the Gateway sends
|
|
5
|
+
* them, into an `AsyncIterator` that a consumer pulls with `for await`. That bridge is
|
|
6
|
+
* the same in both, so it lives here once. What differs between them (which
|
|
7
|
+
* notifications feed it, and what ending the stream tears down) stays in each handle
|
|
8
|
+
* and reaches the queue as the `teardown` passed to {@link EventQueue.close}.
|
|
9
|
+
*/
|
|
10
|
+
export type EventQueue<T> = {
|
|
11
|
+
/** Hand `ev` to the oldest parked {@link EventQueue.next}, or buffer it. A no-op once closed. */
|
|
12
|
+
push(ev: T): void;
|
|
13
|
+
/**
|
|
14
|
+
* End the stream. Only the first call does anything: it marks the queue closed, runs
|
|
15
|
+
* `teardown`, then settles EVERY parked `next()` with `done` (not just the first,
|
|
16
|
+
* since nothing else will ever settle the rest).
|
|
17
|
+
*/
|
|
18
|
+
close(teardown?: () => void): void;
|
|
19
|
+
/** Whether {@link EventQueue.close} has run. */
|
|
20
|
+
readonly closed: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The next event. Events buffered before {@link EventQueue.close} still drain after
|
|
23
|
+
* it, which is how a terminal event pushed just before closing reaches the consumer.
|
|
24
|
+
* An empty, closed queue reports `done`; an empty, open one parks until a push or close.
|
|
25
|
+
*/
|
|
26
|
+
next(): Promise<IteratorResult<T>>;
|
|
27
|
+
};
|
|
28
|
+
export declare function createEventQueue<T>(): EventQueue<T>;
|
|
29
|
+
//# sourceMappingURL=event-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-queue.d.ts","sourceRoot":"","sources":["../src/event-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC1B,iGAAiG;IACjG,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;IAClB;;;;OAIG;IACH,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IACnC,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAsCnD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function createEventQueue() {
|
|
2
|
+
const buffer = [];
|
|
3
|
+
const waiters = [];
|
|
4
|
+
let closed = false;
|
|
5
|
+
return {
|
|
6
|
+
push(ev) {
|
|
7
|
+
if (closed)
|
|
8
|
+
return;
|
|
9
|
+
const waiter = waiters.shift();
|
|
10
|
+
if (waiter !== undefined) {
|
|
11
|
+
waiter({ value: ev, done: false });
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
buffer.push(ev);
|
|
15
|
+
},
|
|
16
|
+
close(teardown) {
|
|
17
|
+
if (closed)
|
|
18
|
+
return;
|
|
19
|
+
closed = true;
|
|
20
|
+
teardown?.();
|
|
21
|
+
let waiter = waiters.shift();
|
|
22
|
+
while (waiter !== undefined) {
|
|
23
|
+
waiter({ value: undefined, done: true });
|
|
24
|
+
waiter = waiters.shift();
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
get closed() {
|
|
28
|
+
return closed;
|
|
29
|
+
},
|
|
30
|
+
next() {
|
|
31
|
+
if (buffer.length > 0) {
|
|
32
|
+
return Promise.resolve({ value: buffer.shift(), done: false });
|
|
33
|
+
}
|
|
34
|
+
if (closed)
|
|
35
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
waiters.push(resolve);
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=event-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-queue.js","sourceRoot":"","sources":["../src/event-queue.ts"],"names":[],"mappings":"AA4BA,MAAM,UAAU,gBAAgB;IAC9B,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,MAAM,OAAO,GAA+C,EAAE,CAAC;IAC/D,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,OAAO;QACL,IAAI,CAAC,EAAK;YACR,IAAI,MAAM;gBAAE,OAAO;YACnB,MAAM,MAAM,GAAG,OAAO,C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