@niq.run/worker-sdk 0.6.0 → 0.8.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 +28 -0
- package/dist/baseworker.d.ts +57 -4
- package/dist/baseworker.d.ts.map +1 -1
- package/dist/baseworker.js +134 -6
- package/dist/baseworker.js.map +1 -1
- package/dist/help.d.ts +33 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +74 -0
- package/dist/help.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/readme.d.ts +24 -0
- package/dist/readme.d.ts.map +1 -0
- package/dist/readme.js +78 -0
- package/dist/readme.js.map +1 -0
- package/dist/types/events.d.ts +7 -0
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js +7 -0
- package/dist/types/events.js.map +1 -1
- package/dist/types/extension.d.ts +11 -4
- package/dist/types/extension.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -202,6 +202,34 @@ for await (const evt of worker.channel.events()) {
|
|
|
202
202
|
}
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
+
#### Meta capabilities (`worker.readme` / `worker.help`)
|
|
206
|
+
|
|
207
|
+
`registerReadme` and `registerHelp` add the two generic self-description
|
|
208
|
+
capabilities. Both are ordinary extensions, so they ride `worker.ready` and are
|
|
209
|
+
reached through the normal request/reply path:
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
// worker.readme — this worker's own guide. A declaration may replace it with
|
|
213
|
+
// `readme`, extend it with `readme_append`, and interpolate `{{key}}` from
|
|
214
|
+
// params.
|
|
215
|
+
worker.registerReadme(
|
|
216
|
+
"Read this worker's usage guide: what it does and how to call it.",
|
|
217
|
+
() => "# echo\n\nEchoes the text you send.",
|
|
218
|
+
{ name: "echo" },
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
// worker.help — per-event help, like a CLI's -h. Without custom guides every
|
|
222
|
+
// registered event gets a guide rendered from its declared schemas. A guide
|
|
223
|
+
// returns null/undefined to fall back to that generic guide.
|
|
224
|
+
worker.registerHelp({
|
|
225
|
+
echo: (params) => (params["mode"] === "fast" ? "# fast echo" : undefined),
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Callers send `{ event_name: "echo" }` and may add `{ params: { … } }` to pick a
|
|
230
|
+
more specific guide; omitting `event_name` lists every served event. Mirrors
|
|
231
|
+
Go's `BaseWorker.RegisterReadme` / `RegisterHelp`.
|
|
232
|
+
|
|
205
233
|
### CLI helpers (writing a worker `start` entrypoint)
|
|
206
234
|
|
|
207
235
|
Out-of-process workers ship a `src/start.ts` (compiled to the package `bin`) to
|
package/dist/baseworker.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Event, EventPattern, Extension, ExtensionHandler, ToolCall, WorkerSideChannel } from "./types/index.js";
|
|
2
|
+
import type { HelpFunc } from "./help.js";
|
|
2
3
|
/**
|
|
3
4
|
* BaseWorker — the shared base implementation every worker builds on,
|
|
4
5
|
* mirroring Go `pkg/baseworker.BaseWorker`. It holds identity, subscription
|
|
@@ -31,11 +32,62 @@ export declare class BaseWorker {
|
|
|
31
32
|
* JSON Schema.
|
|
32
33
|
*/
|
|
33
34
|
register(ext: Extension, handler: ExtensionHandler): void;
|
|
35
|
+
/**
|
|
36
|
+
* Register the generic `worker.readme` capability: a directed worker.readme
|
|
37
|
+
* call is answered with this worker's own guide.
|
|
38
|
+
*
|
|
39
|
+
* `text` runs per request so the guide can include live state. `params` is the
|
|
40
|
+
* declaration's construction params, read for two optional keys that let a
|
|
41
|
+
* declaration customize the guide without touching the worker's code:
|
|
42
|
+
*
|
|
43
|
+
* readme replaces the built-in guide
|
|
44
|
+
* readme_append is appended after it
|
|
45
|
+
*
|
|
46
|
+
* Both render `{{key}}` placeholders from params (see readme.ts). Mirrors Go's
|
|
47
|
+
* `BaseWorker.RegisterReadme`.
|
|
48
|
+
*/
|
|
49
|
+
registerReadme(description: string, text: () => string, params?: Record<string, unknown>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Register the generic `worker.help` capability: a directed worker.help call
|
|
52
|
+
* is answered with help for ONE of this worker's events.
|
|
53
|
+
*
|
|
54
|
+
* The request shape is:
|
|
55
|
+
*
|
|
56
|
+
* { event_name: "spawn", params: { worker: "reason" } }
|
|
57
|
+
*
|
|
58
|
+
* `event_name` names an event this worker serves; `params` is an optional
|
|
59
|
+
* selector a `HelpFunc` may use. Omitting `event_name` returns an index of
|
|
60
|
+
* every served event.
|
|
61
|
+
*
|
|
62
|
+
* `guides` is keyed by event and may be omitted — without one, every event
|
|
63
|
+
* still gets a generic guide rendered from its declared description,
|
|
64
|
+
* parameters and response. A guide wins only when it returns a string; a
|
|
65
|
+
* selector it does not recognize falls back to the generic guide. The map is
|
|
66
|
+
* read-only after registration; call `registerHelp` again to replace it.
|
|
67
|
+
*
|
|
68
|
+
* Mirrors Go's `BaseWorker.RegisterHelp`.
|
|
69
|
+
*/
|
|
70
|
+
registerHelp(guides?: Record<string, HelpFunc>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Select the guide for one worker.help request. Internal extensions are only
|
|
73
|
+
* visible to their owner, mirroring dispatchExtension's scope rule. Throws for
|
|
74
|
+
* an event the worker does not serve (answered as request.failed).
|
|
75
|
+
*/
|
|
76
|
+
private helpText;
|
|
34
77
|
/**
|
|
35
78
|
* Route an event to the registered extension matching its event type.
|
|
36
79
|
* Returns whether a handler ran; the first matching registration wins. Async
|
|
37
80
|
* handlers are not awaited.
|
|
38
81
|
*
|
|
82
|
+
* An `internal` extension is self-scoped: a request from any other worker is
|
|
83
|
+
* refused before the handler runs (a `request.rejected` when the event carries
|
|
84
|
+
* a request id). The bus stamps the sender's worker id, so a peer cannot pose
|
|
85
|
+
* as the owner.
|
|
86
|
+
*
|
|
87
|
+
* A request that matches no extension is answered with `request.failed` rather
|
|
88
|
+
* than dropped, so the caller's pending call cannot wait forever on a worker
|
|
89
|
+
* that does not serve that event.
|
|
90
|
+
*
|
|
39
91
|
* `worker.discover` is protocol traffic rather than an extension: it is
|
|
40
92
|
* answered here with the contract last passed to {@link announceReady} (a
|
|
41
93
|
* directed, transient `worker.ready` to the asker), mirroring Go's
|
|
@@ -48,13 +100,14 @@ export declare class BaseWorker {
|
|
|
48
100
|
extensions(): Extension[];
|
|
49
101
|
/**
|
|
50
102
|
* Render the registry into the `worker.ready` "watch" wire format.
|
|
51
|
-
* `
|
|
52
|
-
* peer-facing broadcast leaves them out (they are not
|
|
103
|
+
* `includeInternal` controls whether Internal extensions are rendered: a
|
|
104
|
+
* peer-facing broadcast leaves them out (they are not advertised to peers;
|
|
105
|
+
* visibility only — the bus ACL, not this parameter, gates dispatch).
|
|
53
106
|
*/
|
|
54
|
-
watchEntries(
|
|
107
|
+
watchEntries(includeInternal: boolean): Record<string, unknown>[];
|
|
55
108
|
/**
|
|
56
109
|
* Broadcast this worker's presence on the bus: the externally callable
|
|
57
|
-
* contract (
|
|
110
|
+
* contract (Internal left out), self excluded via `exclude_worker_id`.
|
|
58
111
|
* `publishes` is the wire form of the events this worker declares it emits
|
|
59
112
|
* (`worker.ready` "publishes").
|
|
60
113
|
*
|
package/dist/baseworker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseworker.d.ts","sourceRoot":"","sources":["../src/baseworker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"baseworker.d.ts","sourceRoot":"","sources":["../src/baseworker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,KAAK,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KAAK,GAAG,QAAQ,CAQlD;AAED,mEAAmE;AACnE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACV,MAAM,CAIR"}
|
package/dist/baseworker.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { EventType } from "./types/index.js";
|
|
2
2
|
import { createEvent } from "./createEvent.js";
|
|
3
|
-
import {
|
|
3
|
+
import { eventHelp, helpIndex, visibleEventNames } from "./help.js";
|
|
4
|
+
import { readmeText } from "./readme.js";
|
|
5
|
+
import { s, toJsonSchema } from "./schema.js";
|
|
4
6
|
/**
|
|
5
7
|
* BaseWorker — the shared base implementation every worker builds on,
|
|
6
8
|
* mirroring Go `pkg/baseworker.BaseWorker`. It holds identity, subscription
|
|
@@ -42,11 +44,122 @@ export class BaseWorker {
|
|
|
42
44
|
}
|
|
43
45
|
this.regs.set(extensionKey(ext), { ext: normalized, handler });
|
|
44
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Register the generic `worker.readme` capability: a directed worker.readme
|
|
49
|
+
* call is answered with this worker's own guide.
|
|
50
|
+
*
|
|
51
|
+
* `text` runs per request so the guide can include live state. `params` is the
|
|
52
|
+
* declaration's construction params, read for two optional keys that let a
|
|
53
|
+
* declaration customize the guide without touching the worker's code:
|
|
54
|
+
*
|
|
55
|
+
* readme replaces the built-in guide
|
|
56
|
+
* readme_append is appended after it
|
|
57
|
+
*
|
|
58
|
+
* Both render `{{key}}` placeholders from params (see readme.ts). Mirrors Go's
|
|
59
|
+
* `BaseWorker.RegisterReadme`.
|
|
60
|
+
*/
|
|
61
|
+
registerReadme(description, text, params) {
|
|
62
|
+
this.register({
|
|
63
|
+
event: EventType.WorkerReadme,
|
|
64
|
+
response: s.string("the worker's self-description (its readme text)"),
|
|
65
|
+
description,
|
|
66
|
+
parameters: s.object({}),
|
|
67
|
+
}, (evt) => {
|
|
68
|
+
const tc = parseToolCall(evt);
|
|
69
|
+
if (!tc.callID)
|
|
70
|
+
return;
|
|
71
|
+
void this.replyCompleted(tc.callerID, tc.callID, readmeText(text, params), tc.traceID);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Register the generic `worker.help` capability: a directed worker.help call
|
|
76
|
+
* is answered with help for ONE of this worker's events.
|
|
77
|
+
*
|
|
78
|
+
* The request shape is:
|
|
79
|
+
*
|
|
80
|
+
* { event_name: "spawn", params: { worker: "reason" } }
|
|
81
|
+
*
|
|
82
|
+
* `event_name` names an event this worker serves; `params` is an optional
|
|
83
|
+
* selector a `HelpFunc` may use. Omitting `event_name` returns an index of
|
|
84
|
+
* every served event.
|
|
85
|
+
*
|
|
86
|
+
* `guides` is keyed by event and may be omitted — without one, every event
|
|
87
|
+
* still gets a generic guide rendered from its declared description,
|
|
88
|
+
* parameters and response. A guide wins only when it returns a string; a
|
|
89
|
+
* selector it does not recognize falls back to the generic guide. The map is
|
|
90
|
+
* read-only after registration; call `registerHelp` again to replace it.
|
|
91
|
+
*
|
|
92
|
+
* Mirrors Go's `BaseWorker.RegisterHelp`.
|
|
93
|
+
*/
|
|
94
|
+
registerHelp(guides) {
|
|
95
|
+
this.register({
|
|
96
|
+
event: EventType.WorkerHelp,
|
|
97
|
+
response: s.string("the requested help text (markdown)"),
|
|
98
|
+
description: "Read help for one of this worker's events, like a CLI's -h. Pass " +
|
|
99
|
+
"event_name to explain that event; params may select a more specific " +
|
|
100
|
+
'guide (e.g. { worker: "reason" } for spawn). Omit event_name to list ' +
|
|
101
|
+
"every event this worker serves.",
|
|
102
|
+
parameters: s.object({
|
|
103
|
+
event_name: s.optional(s.string("Event to explain (e.g. spawn). Empty lists all served events.")),
|
|
104
|
+
params: s.optional(s.object({}, 'Optional selector for an event-specific guide, e.g. { worker: "reason" }.')),
|
|
105
|
+
}),
|
|
106
|
+
}, (evt) => {
|
|
107
|
+
const tc = parseToolCall(evt);
|
|
108
|
+
if (!tc.callID)
|
|
109
|
+
return;
|
|
110
|
+
try {
|
|
111
|
+
const text = this.helpText(evt, tc.args, guides);
|
|
112
|
+
void this.replyCompleted(tc.callerID, tc.callID, text, tc.traceID);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
void this.replyFailed(tc.callerID, tc.callID, errorMessage(err), tc.traceID);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Select the guide for one worker.help request. Internal extensions are only
|
|
121
|
+
* visible to their owner, mirroring dispatchExtension's scope rule. Throws for
|
|
122
|
+
* an event the worker does not serve (answered as request.failed).
|
|
123
|
+
*/
|
|
124
|
+
helpText(evt, args, guides) {
|
|
125
|
+
const includeInternal = evt.worker_id === this.id;
|
|
126
|
+
const exts = this.extensions();
|
|
127
|
+
const name = argString(args, "event_name").trim();
|
|
128
|
+
const rawParams = args["params"];
|
|
129
|
+
const params = isRecord(rawParams) ? rawParams : {};
|
|
130
|
+
if (name === "")
|
|
131
|
+
return helpIndex(this.id, exts, includeInternal);
|
|
132
|
+
for (const ext of exts) {
|
|
133
|
+
if (ext.event !== name)
|
|
134
|
+
continue;
|
|
135
|
+
if (ext.internal && !includeInternal) {
|
|
136
|
+
throw new Error(`worker.help: ${this.id} does not expose event ${JSON.stringify(name)}`);
|
|
137
|
+
}
|
|
138
|
+
const guide = guides?.[ext.event];
|
|
139
|
+
if (typeof guide === "function") {
|
|
140
|
+
const text = guide(params);
|
|
141
|
+
if (text !== null && text !== undefined)
|
|
142
|
+
return text;
|
|
143
|
+
}
|
|
144
|
+
return eventHelp(ext, Object.keys(params).length > 0);
|
|
145
|
+
}
|
|
146
|
+
throw new Error(`worker.help: ${this.id} does not serve event ${JSON.stringify(name)}; ` +
|
|
147
|
+
`served events: ${visibleEventNames(exts, includeInternal).join(", ")}`);
|
|
148
|
+
}
|
|
45
149
|
/**
|
|
46
150
|
* Route an event to the registered extension matching its event type.
|
|
47
151
|
* Returns whether a handler ran; the first matching registration wins. Async
|
|
48
152
|
* handlers are not awaited.
|
|
49
153
|
*
|
|
154
|
+
* An `internal` extension is self-scoped: a request from any other worker is
|
|
155
|
+
* refused before the handler runs (a `request.rejected` when the event carries
|
|
156
|
+
* a request id). The bus stamps the sender's worker id, so a peer cannot pose
|
|
157
|
+
* as the owner.
|
|
158
|
+
*
|
|
159
|
+
* A request that matches no extension is answered with `request.failed` rather
|
|
160
|
+
* than dropped, so the caller's pending call cannot wait forever on a worker
|
|
161
|
+
* that does not serve that event.
|
|
162
|
+
*
|
|
50
163
|
* `worker.discover` is protocol traffic rather than an extension: it is
|
|
51
164
|
* answered here with the contract last passed to {@link announceReady} (a
|
|
52
165
|
* directed, transient `worker.ready` to the asker), mirroring Go's
|
|
@@ -64,9 +177,20 @@ export class BaseWorker {
|
|
|
64
177
|
for (const { ext, handler } of this.regs.values()) {
|
|
65
178
|
if (ext.event !== evt.type)
|
|
66
179
|
continue;
|
|
180
|
+
if (ext.internal && evt.worker_id !== this.id) {
|
|
181
|
+
if (evt.request_id) {
|
|
182
|
+
void this.replyRejected(evt.worker_id, evt.request_id, `internal capability: only ${this.id} may invoke it`, evt.trace_id);
|
|
183
|
+
}
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
67
186
|
void handler(evt);
|
|
68
187
|
return true;
|
|
69
188
|
}
|
|
189
|
+
// No registration matched: answer a request so the caller cannot hang on a
|
|
190
|
+
// silent drop. Notifications have nothing waiting.
|
|
191
|
+
if (evt.request_id) {
|
|
192
|
+
void this.replyFailed(evt.worker_id, evt.request_id, `no handler for event ${evt.type}`, evt.trace_id);
|
|
193
|
+
}
|
|
70
194
|
return false;
|
|
71
195
|
}
|
|
72
196
|
/** Snapshot of the registered extensions (insertion order). */
|
|
@@ -75,13 +199,14 @@ export class BaseWorker {
|
|
|
75
199
|
}
|
|
76
200
|
/**
|
|
77
201
|
* Render the registry into the `worker.ready` "watch" wire format.
|
|
78
|
-
* `
|
|
79
|
-
* peer-facing broadcast leaves them out (they are not
|
|
202
|
+
* `includeInternal` controls whether Internal extensions are rendered: a
|
|
203
|
+
* peer-facing broadcast leaves them out (they are not advertised to peers;
|
|
204
|
+
* visibility only — the bus ACL, not this parameter, gates dispatch).
|
|
80
205
|
*/
|
|
81
|
-
watchEntries(
|
|
206
|
+
watchEntries(includeInternal) {
|
|
82
207
|
const out = [];
|
|
83
208
|
for (const ext of this.extensions()) {
|
|
84
|
-
if (ext.
|
|
209
|
+
if (ext.internal && !includeInternal)
|
|
85
210
|
continue;
|
|
86
211
|
const entry = {
|
|
87
212
|
event: ext.event,
|
|
@@ -99,7 +224,7 @@ export class BaseWorker {
|
|
|
99
224
|
}
|
|
100
225
|
/**
|
|
101
226
|
* Broadcast this worker's presence on the bus: the externally callable
|
|
102
|
-
* contract (
|
|
227
|
+
* contract (Internal left out), self excluded via `exclude_worker_id`.
|
|
103
228
|
* `publishes` is the wire form of the events this worker declares it emits
|
|
104
229
|
* (`worker.ready` "publishes").
|
|
105
230
|
*
|
|
@@ -243,6 +368,9 @@ export function argInt(args, key, def) {
|
|
|
243
368
|
function extensionKey(ext) {
|
|
244
369
|
return `${ext.event}\x00`;
|
|
245
370
|
}
|
|
371
|
+
function errorMessage(err) {
|
|
372
|
+
return err instanceof Error ? err.message : String(err);
|
|
373
|
+
}
|
|
246
374
|
function isRecord(v) {
|
|
247
375
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
248
376
|
}
|
package/dist/baseworker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseworker.js","sourceRoot":"","sources":["../src/baseworker.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW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,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
|
package/dist/help.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering helpers for `worker.help` — the TS mirror of Go's
|
|
3
|
+
* `baseworker/help.go`.
|
|
4
|
+
*
|
|
5
|
+
* `worker.help` is the per-event counterpart of `worker.readme`, like a CLI's
|
|
6
|
+
* `-h`: `event_name` names one of the worker's events, and `params` may select
|
|
7
|
+
* a more specific guide. The reusable registration lives on `BaseWorker`
|
|
8
|
+
* (`registerHelp`); this file only renders the answers.
|
|
9
|
+
*/
|
|
10
|
+
import type { Extension } from "./types/index.js";
|
|
11
|
+
/**
|
|
12
|
+
* Render a custom guide for one event, selected by the request's `params`
|
|
13
|
+
* (e.g. `{ worker: "reason" }` for spawn). Return `null`/`undefined` when these
|
|
14
|
+
* params do not match: the generic guide built from the event's declared
|
|
15
|
+
* contract is returned instead.
|
|
16
|
+
*
|
|
17
|
+
* `params` is `{}` when the request carried none, so lookups are always safe.
|
|
18
|
+
*/
|
|
19
|
+
export type HelpFunc = (params: Record<string, unknown>) => string | null | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Render the worker's capability list — the "no event_name" half of
|
|
22
|
+
* `worker.help`. Sorted by event type so the index is stable.
|
|
23
|
+
*/
|
|
24
|
+
export declare function helpIndex(id: string, exts: Extension[], includeInternal: boolean): string;
|
|
25
|
+
/**
|
|
26
|
+
* Render the generic guide for one event from its declared contract. It is
|
|
27
|
+
* what a worker gets without writing any help text, and the fallback for params
|
|
28
|
+
* a custom `HelpFunc` does not recognize.
|
|
29
|
+
*/
|
|
30
|
+
export declare function eventHelp(ext: Extension, paramsGiven: boolean): string;
|
|
31
|
+
/** Event names the caller may see, sorted. */
|
|
32
|
+
export declare function visibleEventNames(exts: Extension[], includeInternal: boolean): string[];
|
|
33
|
+
//# sourceMappingURL=help.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,CACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC5B,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAE/B;;;GAGG;AACH,wBAAgB,SAAS,CACvB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,SAAS,EAAE,EACjB,eAAe,EAAE,OAAO,GACvB,MAAM,CAiBR;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,GAAG,MAAM,CAwBtE;AAYD,8CAA8C;AAC9C,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,EAAE,EACjB,eAAe,EAAE,OAAO,GACvB,MAAM,EAAE,CAEV"}
|
package/dist/help.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering helpers for `worker.help` — the TS mirror of Go's
|
|
3
|
+
* `baseworker/help.go`.
|
|
4
|
+
*
|
|
5
|
+
* `worker.help` is the per-event counterpart of `worker.readme`, like a CLI's
|
|
6
|
+
* `-h`: `event_name` names one of the worker's events, and `params` may select
|
|
7
|
+
* a more specific guide. The reusable registration lives on `BaseWorker`
|
|
8
|
+
* (`registerHelp`); this file only renders the answers.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Render the worker's capability list — the "no event_name" half of
|
|
12
|
+
* `worker.help`. Sorted by event type so the index is stable.
|
|
13
|
+
*/
|
|
14
|
+
export function helpIndex(id, exts, includeInternal) {
|
|
15
|
+
const out = [`# ${id} — help`, ""];
|
|
16
|
+
out.push("Call any event below by sending it to this worker with a request id; " +
|
|
17
|
+
"the reply arrives as `request.completed`.", "");
|
|
18
|
+
for (const ext of visibleExtensions(exts, includeInternal)) {
|
|
19
|
+
const desc = summary(ext.description ?? "");
|
|
20
|
+
out.push(`- \`${ext.event}\` — ${desc === "" ? "(no description)" : desc}`);
|
|
21
|
+
}
|
|
22
|
+
out.push("", "Ask for one event with `{\"event_name\": \"<event>\"}`. " +
|
|
23
|
+
"Some events also accept `params` to pick a more specific guide.");
|
|
24
|
+
return out.join("\n");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Render the generic guide for one event from its declared contract. It is
|
|
28
|
+
* what a worker gets without writing any help text, and the fallback for params
|
|
29
|
+
* a custom `HelpFunc` does not recognize.
|
|
30
|
+
*/
|
|
31
|
+
export function eventHelp(ext, paramsGiven) {
|
|
32
|
+
const out = [`# ${ext.event}`, ""];
|
|
33
|
+
const desc = (ext.description ?? "").trim();
|
|
34
|
+
if (desc !== "")
|
|
35
|
+
out.push(desc, "");
|
|
36
|
+
if (ext.parameters) {
|
|
37
|
+
out.push("## Arguments", "", "```json", prettyJson(ext.parameters), "```", "");
|
|
38
|
+
}
|
|
39
|
+
if (ext.response) {
|
|
40
|
+
out.push("## Reply", "", "```json", prettyJson(ext.response), "```", "");
|
|
41
|
+
}
|
|
42
|
+
out.push("## How to call", "", "Send this event to the worker as a request: the payload IS the " +
|
|
43
|
+
"arguments object above, and the reply echoes the same request id as " +
|
|
44
|
+
"`request.completed`.");
|
|
45
|
+
if (paramsGiven) {
|
|
46
|
+
out.push("", "No event-specific guide matched `params`; this is the declared contract.");
|
|
47
|
+
}
|
|
48
|
+
return out.join("\n");
|
|
49
|
+
}
|
|
50
|
+
/** Extensions the caller may see, sorted by event type. */
|
|
51
|
+
function visibleExtensions(exts, includeInternal) {
|
|
52
|
+
return exts
|
|
53
|
+
.filter((ext) => includeInternal || !ext.internal)
|
|
54
|
+
.sort((a, b) => (a.event < b.event ? -1 : a.event > b.event ? 1 : 0));
|
|
55
|
+
}
|
|
56
|
+
/** Event names the caller may see, sorted. */
|
|
57
|
+
export function visibleEventNames(exts, includeInternal) {
|
|
58
|
+
return visibleExtensions(exts, includeInternal).map((ext) => ext.event);
|
|
59
|
+
}
|
|
60
|
+
/** Keep a one-line description one line, so the index stays scannable. */
|
|
61
|
+
function summary(desc) {
|
|
62
|
+
const trimmed = desc.trim();
|
|
63
|
+
const i = trimmed.indexOf("\n");
|
|
64
|
+
return i >= 0 ? trimmed.slice(0, i) : trimmed;
|
|
65
|
+
}
|
|
66
|
+
function prettyJson(v) {
|
|
67
|
+
try {
|
|
68
|
+
return JSON.stringify(v, null, 2) ?? String(v);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return String(v);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=help.js.map
|
package/dist/help.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH;;;GAGG;AACH,MAAM,UAAU,SAAS,CACvB,EAAU,EACV,IAAiB,EACjB,eAAwB;IAExB,MAAM,GAAG,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IACnC,GAAG,CAAC,IAAI,CACN,uEAAuE;QACrE,2CAA2C,EAC7C,EAAE,CACH,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,iBAAiB,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;QAC5C,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,KAAK,QAAQ,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9E,CAAC;IACD,GAAG,CAAC,IAAI,CACN,EAAE,EACF,0DAA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,CAAC,QAAQ,CAAC;SACjD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,iBAAiB,CAC/B,IAAiB,EACjB,eAAwB;IAExB,OAAO,iBAAiB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAC1E,CAAC;AAED,0EAA0E;AAC1E,SAAS,OAAO,CAAC,IAAY;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAChD,CAAC;AAED,SAAS,UAAU,CAAC,CAAU;IAC5B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { HTTPWorkerClient } from "./client.js";
|
|
2
2
|
export type { HTTPWorkerClientOptions } from "./client.js";
|
|
3
3
|
export { BaseWorker, parseToolCall, argString, argInt } from "./baseworker.js";
|
|
4
|
+
export type { HelpFunc } from "./help.js";
|
|
4
5
|
export { replyValue, replyText } from "./reply.js";
|
|
5
6
|
export { s, isOptionalSchema, type JsonSchema } from "./schema.js";
|
|
6
7
|
export { parseCliArgs, busConnFromArgs, runWorkerApp, BUS_CLI_FLAGS } from "./cli.js";
|
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,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
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;AAC/E,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,CAAC,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACtF,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,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,YAAY,EACjB,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.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;AAG/C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,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;AAG/E,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,CAAC,EAAE,gBAAgB,EAAmB,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGtF,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,GAcV,MAAM,kBAAkB,CAAC"}
|
package/dist/readme.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for `worker.readme` — the TS mirror of Go's `baseworker/readme.go`.
|
|
3
|
+
*
|
|
4
|
+
* A worker's readme is its own guide (what it is for, which events it serves).
|
|
5
|
+
* A declaration can customize the built-in text without code changes:
|
|
6
|
+
*
|
|
7
|
+
* readme replaces the built-in guide
|
|
8
|
+
* readme_append is appended after it
|
|
9
|
+
*
|
|
10
|
+
* Both render `{{key}}` placeholders from the declaration params (top-level
|
|
11
|
+
* keys; list values join with ", "; an unknown key is left untouched).
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Apply a declaration's readme customization over a worker's built-in guide.
|
|
15
|
+
* Mirrors Go's `readmeText`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readmeText(builtin: () => string, params?: Record<string, unknown>): string;
|
|
18
|
+
/**
|
|
19
|
+
* Replace `{{key}}` with the params value. A placeholder with no matching key
|
|
20
|
+
* stays untouched, so ordinary prose and JSON braces are safe. Mirrors Go's
|
|
21
|
+
* `renderParams`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function renderParams(text: string, params?: Record<string, unknown>): string;
|
|
24
|
+
//# sourceMappingURL=readme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readme.d.ts","sourceRoot":"","sources":["../src/readme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;GAGG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,MAAM,MAAM,EACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAYR;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAuBR"}
|
package/dist/readme.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for `worker.readme` — the TS mirror of Go's `baseworker/readme.go`.
|
|
3
|
+
*
|
|
4
|
+
* A worker's readme is its own guide (what it is for, which events it serves).
|
|
5
|
+
* A declaration can customize the built-in text without code changes:
|
|
6
|
+
*
|
|
7
|
+
* readme replaces the built-in guide
|
|
8
|
+
* readme_append is appended after it
|
|
9
|
+
*
|
|
10
|
+
* Both render `{{key}}` placeholders from the declaration params (top-level
|
|
11
|
+
* keys; list values join with ", "; an unknown key is left untouched).
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Apply a declaration's readme customization over a worker's built-in guide.
|
|
15
|
+
* Mirrors Go's `readmeText`.
|
|
16
|
+
*/
|
|
17
|
+
export function readmeText(builtin, params) {
|
|
18
|
+
let text = builtin();
|
|
19
|
+
const override = params?.["readme"];
|
|
20
|
+
if (typeof override === "string" && override !== "") {
|
|
21
|
+
text = override;
|
|
22
|
+
}
|
|
23
|
+
const appendText = params?.["readme_append"];
|
|
24
|
+
if (typeof appendText === "string" && appendText !== "") {
|
|
25
|
+
if (text !== "" && !text.endsWith("\n"))
|
|
26
|
+
text += "\n";
|
|
27
|
+
text += appendText;
|
|
28
|
+
}
|
|
29
|
+
return renderParams(text, params);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Replace `{{key}}` with the params value. A placeholder with no matching key
|
|
33
|
+
* stays untouched, so ordinary prose and JSON braces are safe. Mirrors Go's
|
|
34
|
+
* `renderParams`.
|
|
35
|
+
*/
|
|
36
|
+
export function renderParams(text, params) {
|
|
37
|
+
if (!params || Object.keys(params).length === 0 || !text.includes("{{")) {
|
|
38
|
+
return text;
|
|
39
|
+
}
|
|
40
|
+
let out = "";
|
|
41
|
+
let rest = text;
|
|
42
|
+
for (;;) {
|
|
43
|
+
const i = rest.indexOf("{{");
|
|
44
|
+
if (i < 0)
|
|
45
|
+
break;
|
|
46
|
+
const after = rest.slice(i + 2);
|
|
47
|
+
const j = after.indexOf("}}");
|
|
48
|
+
if (j < 0)
|
|
49
|
+
break;
|
|
50
|
+
out += rest.slice(0, i);
|
|
51
|
+
const key = after.slice(0, j).trim();
|
|
52
|
+
if (Object.prototype.hasOwnProperty.call(params, key)) {
|
|
53
|
+
out += paramText(params[key]);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
out += rest.slice(i, i + j + 4);
|
|
57
|
+
}
|
|
58
|
+
rest = after.slice(j + 2);
|
|
59
|
+
}
|
|
60
|
+
out += rest;
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** Render one params value: strings verbatim, lists comma-joined, else JSON. */
|
|
64
|
+
function paramText(v) {
|
|
65
|
+
if (v === null || v === undefined)
|
|
66
|
+
return "";
|
|
67
|
+
if (typeof v === "string")
|
|
68
|
+
return v;
|
|
69
|
+
if (Array.isArray(v))
|
|
70
|
+
return v.map(paramText).join(", ");
|
|
71
|
+
try {
|
|
72
|
+
return JSON.stringify(v) ?? "";
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return "";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=readme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readme.js","sourceRoot":"","sources":["../src/readme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;GAGG;AACH,MAAM,UAAU,UAAU,CACxB,OAAqB,EACrB,MAAgC;IAEhC,IAAI,IAAI,GAAG,OAAO,EAAE,CAAC;IACrB,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;IACpC,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;QACpD,IAAI,GAAG,QAAQ,CAAC;IAClB,CAAC;IACD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C,EAAE,CAAC;YACtD,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5B,CAAC;IACD,GAAG,IAAI,IAAI,CAAC;IACZ,OAAO,GAAG,CAAC;AACb,CAAC;AAED,gFAAgF;AAChF,SAAS,SAAS,CAAC,CAAU;IAC3B,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAC7C,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACpC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/dist/types/events.d.ts
CHANGED
|
@@ -14,6 +14,13 @@ export declare const EventType: {
|
|
|
14
14
|
readonly WorkerDiscover: "worker.discover";
|
|
15
15
|
readonly WorkerInput: "worker.input";
|
|
16
16
|
readonly WorkerAbort: "worker.abort";
|
|
17
|
+
/** Ask a worker to describe itself: its own usage guide (mirrors worker.readme). */
|
|
18
|
+
readonly WorkerReadme: "worker.readme";
|
|
19
|
+
/**
|
|
20
|
+
* Ask a worker for help on ONE of the events it serves, like a CLI's `-h`.
|
|
21
|
+
* `event_name` selects the event; `params` may select a more specific guide.
|
|
22
|
+
*/
|
|
23
|
+
readonly WorkerHelp: "worker.help";
|
|
17
24
|
readonly WorkerUpdate: "worker.update";
|
|
18
25
|
readonly WorkerQuery: "worker.query";
|
|
19
26
|
readonly RequestCompleted: "request.completed";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/types/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS;;;;;;IAOpB,oFAAoF;;IAEpF;;;OAGG;;;;;;;;;CAmBK,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC"}
|
package/dist/types/events.js
CHANGED
|
@@ -15,6 +15,13 @@ export const EventType = {
|
|
|
15
15
|
WorkerDiscover: "worker.discover",
|
|
16
16
|
WorkerInput: "worker.input",
|
|
17
17
|
WorkerAbort: "worker.abort",
|
|
18
|
+
/** Ask a worker to describe itself: its own usage guide (mirrors worker.readme). */
|
|
19
|
+
WorkerReadme: "worker.readme",
|
|
20
|
+
/**
|
|
21
|
+
* Ask a worker for help on ONE of the events it serves, like a CLI's `-h`.
|
|
22
|
+
* `event_name` selects the event; `params` may select a more specific guide.
|
|
23
|
+
*/
|
|
24
|
+
WorkerHelp: "worker.help",
|
|
18
25
|
// Worker meta invocation channels. Some extensions still register these
|
|
19
26
|
// (their op/subject payloads discriminate); reason's own meta capabilities
|
|
20
27
|
// use dedicated event types (see pkg/reason in the main repo).
|
package/dist/types/events.js.map
CHANGED
|
@@ -1 +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;
|
|
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;IAC3B,oFAAoF;IACpF,YAAY,EAAE,eAAe;IAC7B;;;OAGG;IACH,UAAU,EAAE,aAAa;IAEzB,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"}
|
|
@@ -27,11 +27,18 @@ export interface Extension {
|
|
|
27
27
|
/** The event type the extension responds to — its identity. */
|
|
28
28
|
event: string;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
30
|
+
* Internal marks an extension that belongs to the worker's OWN view: it is
|
|
31
|
+
* not advertised in the peer-facing `worker.ready` announcement (directory /
|
|
32
|
+
* WebUI / PTC), and a request from any other worker is refused before the
|
|
33
|
+
* handler runs (a `request.rejected` when the event carries a request id). The
|
|
34
|
+
* declaring worker still invokes it normally, and the self-directed ready
|
|
35
|
+
* keeps it in its own tool list.
|
|
36
|
+
*
|
|
37
|
+
* This is a scope rule, not a general access control: it says the capability
|
|
38
|
+
* is meaningful only to its owner. Whether another worker may address this one
|
|
39
|
+
* at all is still the bus ACL's job.
|
|
33
40
|
*/
|
|
34
|
-
|
|
41
|
+
internal?: boolean;
|
|
35
42
|
description?: string;
|
|
36
43
|
/**
|
|
37
44
|
* The request's JSON Schema — what a caller must pass as the event payload.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../src/types/extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;IACd
|
|
1
|
+
{"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["../../src/types/extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEpE,uFAAuF;AACvF,MAAM,WAAW,QAAQ;IACvB,8DAA8D;IAC9D,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB"}
|