@niq.run/worker-sdk 0.1.0 → 0.3.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 +55 -3
- package/dist/baseworker.d.ts +70 -0
- package/dist/baseworker.d.ts.map +1 -0
- package/dist/baseworker.js +163 -0
- package/dist/baseworker.js.map +1 -0
- package/dist/baseworker.test.d.ts +2 -0
- package/dist/baseworker.test.d.ts.map +1 -0
- package/dist/baseworker.test.js +181 -0
- package/dist/baseworker.test.js.map +1 -0
- package/dist/client.d.ts +15 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +57 -3
- package/dist/client.js.map +1 -1
- package/dist/client.test.js +47 -2
- package/dist/client.test.js.map +1 -1
- package/dist/createEvent.d.ts +1 -1
- package/dist/createEvent.d.ts.map +1 -1
- package/dist/createEvent.test.js +2 -2
- package/dist/createEvent.test.js.map +1 -1
- package/dist/env.d.ts +26 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +33 -0
- package/dist/env.js.map +1 -0
- package/dist/env.test.d.ts +2 -0
- package/dist/env.test.d.ts.map +1 -0
- package/dist/env.test.js +31 -0
- package/dist/env.test.js.map +1 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/sse.d.ts +1 -1
- package/dist/sse.d.ts.map +1 -1
- package/dist/types/channel.d.ts +35 -0
- package/dist/types/channel.d.ts.map +1 -0
- package/dist/types/channel.js +2 -0
- package/dist/types/channel.js.map +1 -0
- package/dist/types/event.d.ts +54 -0
- package/dist/types/event.d.ts.map +1 -0
- package/dist/types/event.js +2 -0
- package/dist/types/event.js.map +1 -0
- package/dist/types/events.d.ts +26 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +34 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/extension.d.ts +37 -0
- package/dist/types/extension.d.ts.map +1 -0
- package/dist/types/extension.js +2 -0
- package/dist/types/extension.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/message.d.ts +28 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +2 -0
- package/dist/types/message.js.map +1 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -21,22 +21,31 @@ export class HTTPWorkerClient {
|
|
|
21
21
|
workerID;
|
|
22
22
|
credential;
|
|
23
23
|
fetchImpl;
|
|
24
|
+
logger;
|
|
24
25
|
es;
|
|
25
26
|
controller;
|
|
26
27
|
connected = false;
|
|
27
28
|
closed = false;
|
|
29
|
+
reconnectPromise;
|
|
28
30
|
constructor(opts) {
|
|
29
31
|
this.id = opts.workerID;
|
|
30
32
|
this.baseURL = opts.baseURL.replace(/\/+$/, "");
|
|
31
33
|
this.workerID = opts.workerID;
|
|
32
34
|
this.credential = opts.credential;
|
|
33
35
|
this.fetchImpl = opts.fetchImpl ?? fetch;
|
|
36
|
+
this.logger = opts.logger;
|
|
34
37
|
}
|
|
35
38
|
async connect() {
|
|
36
39
|
if (this.connected)
|
|
37
40
|
return;
|
|
38
41
|
if (this.closed)
|
|
39
42
|
throw new Error("niq: client is closed");
|
|
43
|
+
const { es, controller } = await this.openSSE();
|
|
44
|
+
this.es = es;
|
|
45
|
+
this.controller = controller;
|
|
46
|
+
this.connected = true;
|
|
47
|
+
}
|
|
48
|
+
async openSSE() {
|
|
40
49
|
const url = `${this.baseURL}/events?worker_id=${encodeURIComponent(this.workerID)}&credential=${encodeURIComponent(this.credential)}`;
|
|
41
50
|
const controller = new AbortController();
|
|
42
51
|
let resp;
|
|
@@ -49,7 +58,36 @@ export class HTTPWorkerClient {
|
|
|
49
58
|
if (!resp.ok || !resp.body) {
|
|
50
59
|
throw new Error(`niq: SSE connect failed with status ${resp.status}`);
|
|
51
60
|
}
|
|
52
|
-
|
|
61
|
+
return { es: resp.body, controller };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Re-establish the SSE stream (the client's session anchor on the bus).
|
|
65
|
+
* Used when the bus no longer has a session for us (publish 400
|
|
66
|
+
* "worker not connected"), e.g. after the bus restarted or our connection
|
|
67
|
+
* was silently torn down. Concurrent callers share one in-flight attempt.
|
|
68
|
+
*/
|
|
69
|
+
reconnectSSE() {
|
|
70
|
+
if (!this.reconnectPromise) {
|
|
71
|
+
this.reconnectPromise = this.doReconnect()
|
|
72
|
+
.catch((err) => {
|
|
73
|
+
this.connected = false;
|
|
74
|
+
this.logger?.debug?.(`niq: reconnect failed: ${err.message}`);
|
|
75
|
+
throw err;
|
|
76
|
+
})
|
|
77
|
+
.finally(() => {
|
|
78
|
+
this.reconnectPromise = undefined;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return this.reconnectPromise;
|
|
82
|
+
}
|
|
83
|
+
async doReconnect() {
|
|
84
|
+
this.logger?.debug?.("niq: session lost; reconnecting SSE");
|
|
85
|
+
// Tear down the current stream so the bus releases the old session.
|
|
86
|
+
this.controller?.abort();
|
|
87
|
+
this.connected = false;
|
|
88
|
+
// Reopen /events (re-registers the session), then resume publishing.
|
|
89
|
+
const { es, controller } = await this.openSSE();
|
|
90
|
+
this.es = es;
|
|
53
91
|
this.controller = controller;
|
|
54
92
|
this.connected = true;
|
|
55
93
|
}
|
|
@@ -105,9 +143,25 @@ export class HTTPWorkerClient {
|
|
|
105
143
|
catch (err) {
|
|
106
144
|
throw new Error(`niq: publish failed: ${err.message}`);
|
|
107
145
|
}
|
|
146
|
+
if (resp.ok)
|
|
147
|
+
return;
|
|
148
|
+
const detail = await resp.text().catch(() => "");
|
|
149
|
+
// The bus has no session for us (400 "worker not connected"): the SSE
|
|
150
|
+
// anchor was silently torn down (bus restart, dropped connection).
|
|
151
|
+
// Re-establish it and retry this publish once.
|
|
152
|
+
if (resp.status === 400 &&
|
|
153
|
+
detail.includes("worker not connected") &&
|
|
154
|
+
!this.closed) {
|
|
155
|
+
await this.reconnectSSE();
|
|
156
|
+
resp = await this.fetchImpl(`${this.baseURL}/publish`, {
|
|
157
|
+
method: "POST",
|
|
158
|
+
headers: { "Content-Type": "application/json" },
|
|
159
|
+
body: JSON.stringify(body),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
108
162
|
if (!resp.ok) {
|
|
109
|
-
const
|
|
110
|
-
throw new Error(`niq: publish failed (${resp.status}): ${
|
|
163
|
+
const retryDetail = await resp.text().catch(() => "");
|
|
164
|
+
throw new Error(`niq: publish failed (${resp.status}): ${retryDetail}`);
|
|
111
165
|
}
|
|
112
166
|
}
|
|
113
167
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAyB5C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,gBAAgB;IAClB,EAAE,CAAS;IAEH,OAAO,CAAS;IAChB,QAAQ,CAAS;IACjB,UAAU,CAAS;IACnB,SAAS,CAAe;IACxB,MAAM,CAAmC;IAElD,EAAE,CAA8B;IAChC,UAAU,CAAmB;IAC7B,SAAS,GAAG,KAAK,CAAC;IAClB,MAAM,GAAG,KAAK,CAAC;IACf,gBAAgB,CAAiB;IAEzC,YAAY,IAA6B;QACvC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,UAAU,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C,CAAC;YACtD,MAAM,IAAI,KAAK,CACb,wBAAwB,IAAI,CAAC,MAAM,MAAM,WAAW,EAAE,CACvD,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
package/dist/client.test.js
CHANGED
|
@@ -29,7 +29,7 @@ describe("publish wire shape", () => {
|
|
|
29
29
|
fetchImpl,
|
|
30
30
|
});
|
|
31
31
|
await client.connect();
|
|
32
|
-
await client.send({ id: "e1", type: "tool.
|
|
32
|
+
await client.send({ id: "e1", type: "tool.request", status: "created", worker_id: "attacker", payload: {}, timestamp: 1 }, "target");
|
|
33
33
|
expect(body).toEqual({
|
|
34
34
|
worker_id: "w1",
|
|
35
35
|
credential: "secret",
|
|
@@ -37,7 +37,7 @@ describe("publish wire shape", () => {
|
|
|
37
37
|
events: [
|
|
38
38
|
{
|
|
39
39
|
id: "e1",
|
|
40
|
-
type: "tool.
|
|
40
|
+
type: "tool.request",
|
|
41
41
|
status: "created",
|
|
42
42
|
worker_id: "w1", // overwritten at the edge
|
|
43
43
|
payload: {},
|
|
@@ -59,6 +59,51 @@ describe("publish wire shape", () => {
|
|
|
59
59
|
await expect(client.send({ id: "e", type: "x", status: "created", worker_id: "", payload: {}, timestamp: 1 })).rejects.toThrow(/at least one target/);
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
|
+
describe("reconnect on session loss", () => {
|
|
63
|
+
it("re-establishes the SSE session and retries a publish that hit 'worker not connected'", async () => {
|
|
64
|
+
let eventsHit = 0;
|
|
65
|
+
let publishHit = 0;
|
|
66
|
+
const fetchImpl = (async (url) => {
|
|
67
|
+
if (isEvents(String(url))) {
|
|
68
|
+
eventsHit++;
|
|
69
|
+
return new Response(sseStream(["{}"]), { status: 200 });
|
|
70
|
+
}
|
|
71
|
+
publishHit++;
|
|
72
|
+
if (publishHit === 1) {
|
|
73
|
+
// First publish: the bus has no session for us.
|
|
74
|
+
return new Response("worker not connected", { status: 400 });
|
|
75
|
+
}
|
|
76
|
+
return new Response(JSON.stringify({ status: "ok" }), { status: 200 });
|
|
77
|
+
});
|
|
78
|
+
const client = new HTTPWorkerClient({
|
|
79
|
+
baseURL: "http://localhost:8080",
|
|
80
|
+
workerID: "w1",
|
|
81
|
+
credential: "secret",
|
|
82
|
+
fetchImpl,
|
|
83
|
+
});
|
|
84
|
+
await client.connect();
|
|
85
|
+
expect(eventsHit).toBe(1);
|
|
86
|
+
await client.send({ id: "e1", type: "x", status: "created", worker_id: "w1", payload: {}, timestamp: 1 }, "target");
|
|
87
|
+
expect(eventsHit).toBe(2); // reconnect opened /events again
|
|
88
|
+
expect(publishHit).toBe(2); // original 400 + successful retry
|
|
89
|
+
});
|
|
90
|
+
it("still throws when the retry also fails with a non-session error", async () => {
|
|
91
|
+
const fetchImpl = (async (url) => {
|
|
92
|
+
if (isEvents(String(url))) {
|
|
93
|
+
return new Response(sseStream(["{}"]), { status: 200 });
|
|
94
|
+
}
|
|
95
|
+
return new Response("boom", { status: 500 });
|
|
96
|
+
});
|
|
97
|
+
const client = new HTTPWorkerClient({
|
|
98
|
+
baseURL: "http://localhost:8080",
|
|
99
|
+
workerID: "w1",
|
|
100
|
+
credential: "secret",
|
|
101
|
+
fetchImpl,
|
|
102
|
+
});
|
|
103
|
+
await client.connect();
|
|
104
|
+
await expect(client.send({ id: "e1", type: "x", status: "created", worker_id: "w1", payload: {}, timestamp: 1 }, "target")).rejects.toThrow(/500/);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
62
107
|
describe("SSE parsing", () => {
|
|
63
108
|
it("parses JSON events from the event stream", async () => {
|
|
64
109
|
const fetchImpl = (async () => new Response(sseStream([
|
package/dist/client.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.test.js","sourceRoot":"","sources":["../src/client.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC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I,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnB,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/createEvent.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEvent.d.ts","sourceRoot":"","sources":["../src/createEvent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,
|
|
1
|
+
{"version":3,"file":"createEvent.d.ts","sourceRoot":"","sources":["../src/createEvent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,kBAAkB,CAAC;AAG3D;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACrC,GAAG,SAAa,GACf,KAAK,CAUP"}
|
package/dist/createEvent.test.js
CHANGED
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from "vitest";
|
|
|
2
2
|
import { createEvent } from "./createEvent.js";
|
|
3
3
|
describe("createEvent", () => {
|
|
4
4
|
it("fills deterministic defaults", () => {
|
|
5
|
-
const evt = createEvent("tool.
|
|
6
|
-
expect(evt.type).toBe("tool.
|
|
5
|
+
const evt = createEvent("tool.request", { tool: "x" }, 1_700_000_000_000);
|
|
6
|
+
expect(evt.type).toBe("tool.request");
|
|
7
7
|
expect(evt.status).toBe("created");
|
|
8
8
|
expect(evt.payload).toEqual({ tool: "x" });
|
|
9
9
|
expect(evt.worker_id).toBe(""); // stamped by the client at publish time
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createEvent.test.js","sourceRoot":"","sources":["../src/createEvent.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,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,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAC3B,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAC/C,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-variable bootstrap for workers launched by the niq project
|
|
3
|
+
* supervisor. When the bus launches an external worker, it injects the
|
|
4
|
+
* connection parameters as env vars (see `internal/project/external.go`
|
|
5
|
+
* `buildEnv`) so the process can connect on its own — no config file needed.
|
|
6
|
+
*/
|
|
7
|
+
/** The env var names injected by the niq supervisor. */
|
|
8
|
+
export declare const BUS_ENV_VARS: {
|
|
9
|
+
readonly busURL: "NIQ_BUS_URL";
|
|
10
|
+
readonly workerID: "NIQ_WORKER_ID";
|
|
11
|
+
readonly credential: "NIQ_WORKER_CREDENTIAL";
|
|
12
|
+
};
|
|
13
|
+
/** Connection parameters read from the supervisor-injected environment. */
|
|
14
|
+
export interface BusEnv {
|
|
15
|
+
baseURL: string;
|
|
16
|
+
workerID: string;
|
|
17
|
+
credential: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Read the bus connection parameters from the environment. Throws with a
|
|
21
|
+
* clear message naming every missing variable — they are all required.
|
|
22
|
+
*
|
|
23
|
+
* `env` is injectable for tests; defaults to `process.env`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function readBusEnv(env?: Record<string, string | undefined>): BusEnv;
|
|
26
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wDAAwD;AACxD,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAEX,2EAA2E;AAC3E,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,MAAM,CAgBR"}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment-variable bootstrap for workers launched by the niq project
|
|
3
|
+
* supervisor. When the bus launches an external worker, it injects the
|
|
4
|
+
* connection parameters as env vars (see `internal/project/external.go`
|
|
5
|
+
* `buildEnv`) so the process can connect on its own — no config file needed.
|
|
6
|
+
*/
|
|
7
|
+
/** The env var names injected by the niq supervisor. */
|
|
8
|
+
export const BUS_ENV_VARS = {
|
|
9
|
+
busURL: "NIQ_BUS_URL",
|
|
10
|
+
workerID: "NIQ_WORKER_ID",
|
|
11
|
+
credential: "NIQ_WORKER_CREDENTIAL",
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Read the bus connection parameters from the environment. Throws with a
|
|
15
|
+
* clear message naming every missing variable — they are all required.
|
|
16
|
+
*
|
|
17
|
+
* `env` is injectable for tests; defaults to `process.env`.
|
|
18
|
+
*/
|
|
19
|
+
export function readBusEnv(env = process.env) {
|
|
20
|
+
const baseURL = env[BUS_ENV_VARS.busURL]?.trim() || "";
|
|
21
|
+
const workerID = env[BUS_ENV_VARS.workerID]?.trim() || "";
|
|
22
|
+
const credential = env[BUS_ENV_VARS.credential]?.trim() || "";
|
|
23
|
+
const missing = Object.keys(BUS_ENV_VARS)
|
|
24
|
+
.filter((k) => ({ busURL: baseURL, workerID, credential })[k] === "")
|
|
25
|
+
.map((k) => BUS_ENV_VARS[k]);
|
|
26
|
+
if (missing.length > 0) {
|
|
27
|
+
throw new Error(`niq: missing environment variable(s): ${missing.join(", ")}. ` +
|
|
28
|
+
`These are injected automatically when the worker is launched by the ` +
|
|
29
|
+
`niq project supervisor, or set them manually to connect to a bus.`);
|
|
30
|
+
}
|
|
31
|
+
return { baseURL: baseURL.replace(/\/+$/, ""), workerID, credential };
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wDAAwD;AACxD,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,aAAa;IACrB,QAAQ,EAAE,eAAe;IACzB,UAAU,EAAE,uBAAuB;CAC3B,CAAC;AASX;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB,MAA0C,OAAO,CAAC,GAAG;IAErD,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACvD,MAAM,QAAQ,GAAG,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC1D,MAAM,UAAU,GAAG,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAE9D,MAAM,OAAO,GAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAsC;SAC5E,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;SACpE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,yCAAyC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YAC7D,sEAAsE;YACtE,mEAAmE,CACtE,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.test.d.ts","sourceRoot":"","sources":["../src/env.test.ts"],"names":[],"mappings":""}
|
package/dist/env.test.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { BUS_ENV_VARS, readBusEnv } from "./env.js";
|
|
3
|
+
describe("readBusEnv", () => {
|
|
4
|
+
it("reads all three variables", () => {
|
|
5
|
+
const env = {
|
|
6
|
+
[BUS_ENV_VARS.busURL]: "http://localhost:8080/",
|
|
7
|
+
[BUS_ENV_VARS.workerID]: "hello@me",
|
|
8
|
+
[BUS_ENV_VARS.credential]: "secret",
|
|
9
|
+
};
|
|
10
|
+
expect(readBusEnv(env)).toEqual({
|
|
11
|
+
baseURL: "http://localhost:8080",
|
|
12
|
+
workerID: "hello@me",
|
|
13
|
+
credential: "secret",
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
it("throws naming every missing variable", () => {
|
|
17
|
+
const env = { [BUS_ENV_VARS.workerID]: "hello@me" };
|
|
18
|
+
expect(() => readBusEnv(env)).toThrow(BUS_ENV_VARS.busURL);
|
|
19
|
+
expect(() => readBusEnv(env)).toThrow(BUS_ENV_VARS.credential);
|
|
20
|
+
expect(() => readBusEnv(env)).toThrow(/missing environment variable/);
|
|
21
|
+
});
|
|
22
|
+
it("treats whitespace-only values as missing", () => {
|
|
23
|
+
const env = {
|
|
24
|
+
[BUS_ENV_VARS.busURL]: " ",
|
|
25
|
+
[BUS_ENV_VARS.workerID]: "hello@me",
|
|
26
|
+
[BUS_ENV_VARS.credential]: "secret",
|
|
27
|
+
};
|
|
28
|
+
expect(() => readBusEnv(env)).toThrow(BUS_ENV_VARS.busURL);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=env.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.test.js","sourceRoot":"","sources":["../src/env.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEpD,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,GAAG,GAAG;YACV,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,wBAAwB;YAC/C,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,UAAU;YACnC,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,QAAQ;SACpC,CAAC;QACF,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;YAC9B,OAAO,EAAE,uBAAuB;YAChC,QAAQ,EAAE,UAAU;YACpB,UAAU,EAAE,QAAQ;SACrB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;QACpD,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC3D,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAC/D,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CACnC,8BAA8B,CAC/B,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,GAAG,GAAG;YACV,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,KAAK;YAC5B,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,UAAU;YACnC,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,QAAQ;SACpC,CAAC;QACF,MAAM,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export { HTTPWorkerClient } from "./client.js";
|
|
2
2
|
export type { HTTPWorkerClientOptions } from "./client.js";
|
|
3
|
-
export
|
|
3
|
+
export { BaseWorker, parseToolCall, argString, argInt } from "./baseworker.js";
|
|
4
4
|
export { createEvent } from "./createEvent.js";
|
|
5
|
-
export {
|
|
6
|
-
export type { EventTypeName } from "./events.js";
|
|
5
|
+
export { BUS_ENV_VARS, readBusEnv, type BusEnv } from "./env.js";
|
|
7
6
|
export { newId } from "./id.js";
|
|
8
7
|
export { parseEventStream } from "./sse.js";
|
|
9
|
-
export type
|
|
8
|
+
export { EventType, type Event, type EventPattern, type EventStatus, type EventTypeName, type Extension, type ExtensionHandler, type Identity, type MessageType, type RequestType, type ToolCall, type WorkerMessage, type WorkerSideChannel, } from "./types/index.js";
|
|
10
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EACL,SAAS,EACT,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { HTTPWorkerClient } from "./client.js";
|
|
2
|
+
export { BaseWorker, parseToolCall, argString, argInt } from "./baseworker.js";
|
|
2
3
|
export { createEvent } from "./createEvent.js";
|
|
3
|
-
export {
|
|
4
|
+
export { BUS_ENV_VARS, readBusEnv } from "./env.js";
|
|
4
5
|
export { newId } from "./id.js";
|
|
5
6
|
export { parseEventStream } from "./sse.js";
|
|
7
|
+
export { EventType, } from "./types/index.js";
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAe,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EACL,SAAS,GAaV,MAAM,kBAAkB,CAAC"}
|
package/dist/sse.d.ts
CHANGED
package/dist/sse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;GAQG;AACH,wBAAuB,gBAAgB,CACrC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,cAAc,CAAC,KAAK,CAAC,CAiCvB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Event } from "./event.js";
|
|
2
|
+
/**
|
|
3
|
+
* WorkerSideChannel — the worker's view of a connection to the bus.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors `core/bus.WorkerSideChannel`. Implementations hide whether the bus
|
|
6
|
+
* is in-process, over HTTP, or behind a relay; the interface is the same.
|
|
7
|
+
*
|
|
8
|
+
* Semantics of Send vs Broadcast (deliberately distinct, not interchangeable):
|
|
9
|
+
* - Send — "I know who should handle this." Directed to explicit targets.
|
|
10
|
+
* targets must be non-empty (use Broadcast for undirected).
|
|
11
|
+
* - Broadcast — "Whoever is interested handles it." Delivered to all online
|
|
12
|
+
* workers whose subscription matches. If no one subscribes, the
|
|
13
|
+
* event silently disappears — a valid end of the execution path.
|
|
14
|
+
*/
|
|
15
|
+
export interface WorkerSideChannel {
|
|
16
|
+
/** Transport-level connection identifier (this worker's ID). */
|
|
17
|
+
readonly id: string;
|
|
18
|
+
/**
|
|
19
|
+
* Establish the connection to the bus. No-op if already connected.
|
|
20
|
+
* @throws if the transport rejects the connection (bad credential, etc.)
|
|
21
|
+
*/
|
|
22
|
+
connect(): Promise<void>;
|
|
23
|
+
/** Send a directed event to specific target workers. targets must be non-empty. */
|
|
24
|
+
send(event: Event, ...targets: string[]): Promise<void>;
|
|
25
|
+
/** Broadcast an event to all matching subscribers. */
|
|
26
|
+
broadcast(event: Event): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Iterate events routed to this worker (directed or broadcast).
|
|
29
|
+
* The stream ends when the connection closes.
|
|
30
|
+
*/
|
|
31
|
+
events(): AsyncIterable<Event>;
|
|
32
|
+
/** Close the connection and release resources. */
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/types/channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB,mFAAmF;IACnF,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD,sDAAsD;IACtD,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC;;;OAGG;IACH,MAAM,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;IAE/B,kDAAkD;IAClD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.js","sourceRoot":"","sources":["../../src/types/channel.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Lifecycle stage of an event. Mirrors `core/event.EventStatus`. */
|
|
2
|
+
export type EventStatus = "created" | "routed" | "delivered";
|
|
3
|
+
/**
|
|
4
|
+
* Subscription declaration: an event of a type, optionally from a specific
|
|
5
|
+
* source worker. Mirrors `core/event.EventPattern`.
|
|
6
|
+
*
|
|
7
|
+
* `type` supports exact match, `"*"` (any), and `"Prefix.*"` (prefix wildcard —
|
|
8
|
+
* also matches the bare prefix, e.g. `"github.*"` matches `"github"` and
|
|
9
|
+
* `"github.issue.new"`). An empty `type` matches nothing (fails closed).
|
|
10
|
+
*/
|
|
11
|
+
export interface EventPattern {
|
|
12
|
+
type: string;
|
|
13
|
+
source_id?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The core data unit of the niq event bus. Field names are the wire names
|
|
17
|
+
* (`snake_case`) and must match `core/event.Event` exactly.
|
|
18
|
+
*
|
|
19
|
+
* Note on authorship: the bus overwrites `worker_id` on receipt (anti-spoofing).
|
|
20
|
+
* The worker MUST supply `id` and `timestamp` — the bus does not fill them.
|
|
21
|
+
* Use {@link createEvent} to get these right.
|
|
22
|
+
*/
|
|
23
|
+
export interface Event {
|
|
24
|
+
id: string;
|
|
25
|
+
type: string;
|
|
26
|
+
status: EventStatus;
|
|
27
|
+
payload: Record<string, unknown>;
|
|
28
|
+
worker_id: string;
|
|
29
|
+
target_worker_id?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Pairs a request with its response: the request carries it, and the
|
|
32
|
+
* response echoes it back (JSON-RPC id semantics). Empty means the event
|
|
33
|
+
* is a notification — no response is expected. Mirrors `Event.RequestId`.
|
|
34
|
+
*/
|
|
35
|
+
request_id?: string;
|
|
36
|
+
trace_id?: string;
|
|
37
|
+
specversion?: string;
|
|
38
|
+
dataschema?: string;
|
|
39
|
+
timestamp: number;
|
|
40
|
+
recipients?: string[];
|
|
41
|
+
/**
|
|
42
|
+
* Names a worker the sender does not want to receive this event even if it
|
|
43
|
+
* matches broadcast subscriptions; the bus skips it when routing broadcasts
|
|
44
|
+
* (ignored for directed sends). Mirrors `Event.ExcludeWorkerID`.
|
|
45
|
+
*/
|
|
46
|
+
exclude_worker_id?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Marks live-streaming UI transients (streaming deltas, partial tool
|
|
49
|
+
* output). The bus delivers them live but skips them on persistence.
|
|
50
|
+
* Mirrors `Event.Transient`.
|
|
51
|
+
*/
|
|
52
|
+
transient?: boolean;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/types/event.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal bus protocol event types.
|
|
3
|
+
*
|
|
4
|
+
* Every worker must use these exact names to interoperate — a worker
|
|
5
|
+
* implementing a capability must publish/subscribe with the matching event
|
|
6
|
+
* type. Worker-specific domain events (e.g. `reason.*`, `timer.*`) are not
|
|
7
|
+
* listed here; they are defined by their owning worker.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors `core/event` constants.
|
|
10
|
+
*/
|
|
11
|
+
export declare const EventType: {
|
|
12
|
+
readonly WorkerReady: "worker.ready";
|
|
13
|
+
readonly WorkerGone: "worker.gone";
|
|
14
|
+
readonly WorkerDiscover: "worker.discover";
|
|
15
|
+
readonly WorkerInput: "worker.input";
|
|
16
|
+
readonly WorkerAbort: "worker.abort";
|
|
17
|
+
readonly WorkerUpdate: "worker.update";
|
|
18
|
+
readonly WorkerQuery: "worker.query";
|
|
19
|
+
readonly RequestCompleted: "request.completed";
|
|
20
|
+
readonly RequestFailed: "request.failed";
|
|
21
|
+
readonly RequestRejected: "request.rejected";
|
|
22
|
+
readonly RequestProgressed: "request.progressed";
|
|
23
|
+
readonly RequestCancel: "request.cancel";
|
|
24
|
+
};
|
|
25
|
+
export type EventTypeName = (typeof EventType)[keyof typeof EventType];
|
|
26
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;CAwBZ,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal bus protocol event types.
|
|
3
|
+
*
|
|
4
|
+
* Every worker must use these exact names to interoperate — a worker
|
|
5
|
+
* implementing a capability must publish/subscribe with the matching event
|
|
6
|
+
* type. Worker-specific domain events (e.g. `reason.*`, `timer.*`) are not
|
|
7
|
+
* listed here; they are defined by their owning worker.
|
|
8
|
+
*
|
|
9
|
+
* Mirrors `core/event` constants.
|
|
10
|
+
*/
|
|
11
|
+
export const EventType = {
|
|
12
|
+
// Worker presence and lifecycle.
|
|
13
|
+
WorkerReady: "worker.ready",
|
|
14
|
+
WorkerGone: "worker.gone",
|
|
15
|
+
WorkerDiscover: "worker.discover",
|
|
16
|
+
WorkerInput: "worker.input",
|
|
17
|
+
WorkerAbort: "worker.abort",
|
|
18
|
+
// Worker meta invocation channels. Some extensions still register these
|
|
19
|
+
// (their op/subject payloads discriminate); reason's own meta capabilities
|
|
20
|
+
// use dedicated event types (see pkg/reason in the main repo).
|
|
21
|
+
WorkerUpdate: "worker.update",
|
|
22
|
+
WorkerQuery: "worker.query",
|
|
23
|
+
// Request-response pairing convention: any invocation of a capability is
|
|
24
|
+
// answered with one of these, echoing the request's `request_id`.
|
|
25
|
+
// request.completed carries the result; request.failed / request.rejected
|
|
26
|
+
// carry the error; request.progressed streams partial results;
|
|
27
|
+
// request.cancel is sent by the caller to cancel a pending one.
|
|
28
|
+
RequestCompleted: "request.completed",
|
|
29
|
+
RequestFailed: "request.failed",
|
|
30
|
+
RequestRejected: "request.rejected",
|
|
31
|
+
RequestProgressed: "request.progressed",
|
|
32
|
+
RequestCancel: "request.cancel",
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,iCAAiC;IACjC,WAAW,EAAE,cAAc;IAC3B,UAAU,EAAE,aAAa;IACzB,cAAc,EAAE,iBAAiB;IACjC,WAAW,EAAE,cAAc;IAC3B,WAAW,EAAE,cAAc;IAE3B,wEAAwE;IACxE,2EAA2E;IAC3E,+DAA+D;IAC/D,YAAY,EAAE,eAAe;IAC7B,WAAW,EAAE,cAAc;IAE3B,yEAAyE;IACzE,kEAAkE;IAClE,0EAA0E;IAC1E,+DAA+D;IAC/D,gEAAgE;IAChE,gBAAgB,EAAE,mBAAmB;IACrC,aAAa,EAAE,gBAAgB;IAC/B,eAAe,EAAE,kBAAkB;IACnC,iBAAiB,EAAE,oBAAoB;IACvC,aAAa,EAAE,gBAAgB;CACvB,CAAC"}
|