@xtrape/capsule-agent-node 0.4.0 → 0.6.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/NOTICE +3 -3
- package/README.md +137 -63
- package/dist/index.cjs +315 -16
- package/dist/index.d.cts +167 -17
- package/dist/index.d.ts +167 -17
- package/dist/index.js +315 -15
- package/package.json +9 -8
package/NOTICE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright 2026 Xtrape
|
|
1
|
+
Xtrape Embedded Agent SDK for Node.js
|
|
2
|
+
Copyright 2026 Xtrape contributors
|
|
3
3
|
|
|
4
|
-
This product includes software developed by the Xtrape
|
|
4
|
+
This product includes software developed by the Xtrape contributors.
|
package/README.md
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Xtrape Embedded Agent SDK for Node.js
|
|
2
2
|
|
|
3
|
-
> Node.js
|
|
3
|
+
> Node.js Embedded Agent SDK for connecting Workers to the Xtrape control plane.
|
|
4
|
+
|
|
5
|
+
The npm name `@xtrape/capsule-agent-node`, the `CapsuleAgent` export, and some
|
|
6
|
+
existing wire fields are legacy compatibility identifiers. `Capsule` is not a
|
|
7
|
+
current Xtrape concept. New integrations should use `XtrapeAgent` and the
|
|
8
|
+
`worker` option.
|
|
4
9
|
|
|
5
10
|
[](./LICENSE)
|
|
6
|
-
[](https://forgejo.xtrape.com/xtrape/xtrape-docs)
|
|
12
|
+
[](https://forgejo.xtrape.com/xtrape/xtrape-docs)
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
The package supports the Node.js Embedded Agent mode for one Worker. Multi-Worker
|
|
15
|
+
ownership belongs to a sidecar or external Agent. Gateway, when present, routes
|
|
16
|
+
Agent/control-plane traffic and does not replace the Agent role.
|
|
10
17
|
|
|
11
|
-
> **Package status:**
|
|
12
|
-
>
|
|
13
|
-
>
|
|
14
|
-
> interfaces may still change.
|
|
18
|
+
> **Package status:** This package follows the unified Xtrape `0.6.0` release
|
|
19
|
+
> train. The npm package name remains a compatibility identifier, but release
|
|
20
|
+
> versioning now follows the shared Xtrape train version.
|
|
15
21
|
|
|
16
22
|
## Install
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
This repository tracks the `0.6.0` snapshot train. Until the `0.6.0` npm cut is
|
|
25
|
+
published, install the latest published compatibility package:
|
|
19
26
|
|
|
20
27
|
```bash
|
|
21
|
-
pnpm add @xtrape/capsule-agent-node
|
|
28
|
+
pnpm add @xtrape/capsule-agent-node@^0.5.0
|
|
22
29
|
```
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
During v0.3 development, this repository may use a local workspace, GitHub
|
|
27
|
-
branch dependency, or `0.3.0-rc.x` package for
|
|
28
|
-
`@xtrape/capsule-contracts-node` until the final `0.3.0` package is published.
|
|
31
|
+
For source-level snapshot integration, use a local checkout of this repository
|
|
32
|
+
and align the rest of the release train separately.
|
|
29
33
|
|
|
30
34
|
For this repository itself:
|
|
31
35
|
|
|
@@ -34,34 +38,96 @@ pnpm install
|
|
|
34
38
|
pnpm build
|
|
35
39
|
```
|
|
36
40
|
|
|
41
|
+
## Xtrape CE Phase 0 Service Agent
|
|
42
|
+
|
|
43
|
+
For the Xtrape CE 0.1 runtime loop (`Telegram → xtrape-server-ce → xtrape-service
|
|
44
|
+
→ reply`), use `CeServiceAgent` (or the `serveCeService` bootstrap). An
|
|
45
|
+
`xtrape-service` registers an instance to `xtrape-server-ce`, heartbeats, and
|
|
46
|
+
replies to `ConversationMessage`s. `Service` and `Worker` are roles here, not the
|
|
47
|
+
legacy `Capsule` concept.
|
|
48
|
+
|
|
49
|
+
### One-call bootstrap
|
|
50
|
+
|
|
51
|
+
`serveCeService` starts an HTTP listener (`POST /messages`, `GET /health`),
|
|
52
|
+
registers the instance (sending the registration token if server-ce requires
|
|
53
|
+
one), and runs heartbeats — so a service does not copy-paste lifecycle code:
|
|
54
|
+
|
|
55
|
+
For deployed or containerized use, set `address` to the callback URL that
|
|
56
|
+
`xtrape-server-ce` can actually reach and allowlist, for example
|
|
57
|
+
`http://demo-service:8080`. The SDK only derives a default address when you
|
|
58
|
+
bind to an explicit local-only host such as `127.0.0.1`.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { serveCeService } from "@xtrape/capsule-agent-node";
|
|
62
|
+
|
|
63
|
+
const svc = await serveCeService({
|
|
64
|
+
serverUrl: process.env.XTRAPE_SERVER_URL ?? "http://localhost:3000",
|
|
65
|
+
registrationToken: process.env.SERVER_CE_REGISTRATION_TOKEN,
|
|
66
|
+
port: 8080,
|
|
67
|
+
// required in deployed/containerized environments
|
|
68
|
+
address: process.env.SERVICE_ADDRESS ?? "http://demo-service:8080",
|
|
69
|
+
manifest: {
|
|
70
|
+
contractVersion: 1,
|
|
71
|
+
service: { id: "demo-echo-service", name: "Demo Echo Service", version: "0.6.0" },
|
|
72
|
+
runtime: { language: "node", agent: "xtrape-agent-nodejs" },
|
|
73
|
+
capabilities: ["status.query"],
|
|
74
|
+
message: { supportedTypes: ["QUERY"] },
|
|
75
|
+
},
|
|
76
|
+
handler: (msg) => `echo: ${msg.content}`,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
process.on("SIGTERM", () => void svc.close()); // stop heartbeat + deregister + close
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Lower-level agent
|
|
83
|
+
|
|
84
|
+
When the service already runs its own HTTP server, use `CeServiceAgent` directly:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { CeServiceAgent } from "@xtrape/capsule-agent-node";
|
|
88
|
+
|
|
89
|
+
const agent = new CeServiceAgent({
|
|
90
|
+
serverUrl: "http://localhost:3000",
|
|
91
|
+
registrationToken: process.env.SERVER_CE_REGISTRATION_TOKEN,
|
|
92
|
+
address: "http://127.0.0.1:8080",
|
|
93
|
+
manifest: /* ServiceManifest */ undefined as never,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const stop = await agent.start(); // register + heartbeat
|
|
97
|
+
// in your POST /messages route:
|
|
98
|
+
const reply = await agent.handleMessage(requestJson, (m) => `echo: ${m.content}`);
|
|
99
|
+
// on shutdown:
|
|
100
|
+
await stop(); // stop heartbeat + deregister
|
|
101
|
+
```
|
|
102
|
+
|
|
37
103
|
## Minimal Example
|
|
38
104
|
|
|
39
|
-
This example
|
|
105
|
+
This example uses the canonical alias `XtrapeAgent`, configures
|
|
40
106
|
providers with `.health()` / `.configs()`, register Actions with `.action()`,
|
|
41
107
|
then call `start()`.
|
|
42
108
|
|
|
43
109
|
```ts
|
|
44
|
-
import {
|
|
110
|
+
import { XtrapeAgent } from "@xtrape/capsule-agent-node";
|
|
45
111
|
|
|
46
|
-
const agent = new
|
|
112
|
+
const agent = new XtrapeAgent({
|
|
47
113
|
backendUrl: process.env.OPSTAGE_BACKEND_URL ?? "http://localhost:8080",
|
|
48
114
|
registrationToken: process.env.OPSTAGE_REGISTRATION_TOKEN,
|
|
49
115
|
tokenStore: { file: "./data/agent-token.txt" },
|
|
50
|
-
// Optional. If omitted, the SDK derives
|
|
51
|
-
// Provide it explicitly when one Agent owns multiple
|
|
116
|
+
// Optional. If omitted, the SDK derives Agent identity from `worker`.
|
|
117
|
+
// Provide it explicitly when one Agent owns multiple Workers on
|
|
52
118
|
// the same host, or when you want a stable agent code that survives
|
|
53
119
|
// service renames.
|
|
54
120
|
agent: {
|
|
55
|
-
code: "hello-
|
|
56
|
-
name: "Hello
|
|
121
|
+
code: "hello-worker-agent",
|
|
122
|
+
name: "Hello Worker Agent",
|
|
57
123
|
runtime: "nodejs",
|
|
58
124
|
},
|
|
59
|
-
|
|
60
|
-
code: "hello-
|
|
61
|
-
name: "Hello
|
|
125
|
+
worker: {
|
|
126
|
+
code: "hello-worker",
|
|
127
|
+
name: "Hello Worker",
|
|
62
128
|
version: "0.1.0",
|
|
63
129
|
runtime: "nodejs",
|
|
64
|
-
description: "Minimal
|
|
130
|
+
description: "Minimal Worker example",
|
|
65
131
|
},
|
|
66
132
|
});
|
|
67
133
|
|
|
@@ -112,10 +178,12 @@ await agent.start();
|
|
|
112
178
|
|
|
113
179
|
## How Registration Works
|
|
114
180
|
|
|
115
|
-
1. An operator creates a single-use
|
|
116
|
-
|
|
181
|
+
1. An operator creates a single-use registration credential in Panel CE (the
|
|
182
|
+
current API calls it a Registration Token).
|
|
183
|
+
2. The Worker starts with `registrationToken` and calls the Agent registration
|
|
117
184
|
API.
|
|
118
|
-
3.
|
|
185
|
+
3. The control plane returns an Agent ID and Agent credential (currently named
|
|
186
|
+
an Agent token).
|
|
119
187
|
4. The SDK stores the issued credentials in `tokenStore.file` as `<agentId>:<agentToken>`.
|
|
120
188
|
5. Future restarts reuse the stored Agent token; the Registration Token is not
|
|
121
189
|
needed again.
|
|
@@ -123,14 +191,15 @@ await agent.start();
|
|
|
123
191
|
If the token file is lost or the Agent is revoked, create a new Registration
|
|
124
192
|
Token and restart the service with it.
|
|
125
193
|
|
|
126
|
-
##
|
|
194
|
+
## Worker Manifest
|
|
127
195
|
|
|
128
|
-
The `
|
|
196
|
+
The `worker` option describes the Worker reported to the control plane. The old
|
|
197
|
+
`service` option remains accepted for compatibility:
|
|
129
198
|
|
|
130
199
|
```ts
|
|
131
|
-
|
|
132
|
-
code: "hello-
|
|
133
|
-
name: "Hello
|
|
200
|
+
worker: {
|
|
201
|
+
code: "hello-worker", // stable unique Worker code
|
|
202
|
+
name: "Hello Worker", // operator-facing display name
|
|
134
203
|
description: "...", // optional
|
|
135
204
|
version: "0.1.0", // service version
|
|
136
205
|
runtime: "nodejs", // nodejs | java | python | go | other
|
|
@@ -138,8 +207,9 @@ service: {
|
|
|
138
207
|
}
|
|
139
208
|
```
|
|
140
209
|
|
|
141
|
-
The SDK wraps this as a
|
|
142
|
-
`schemaVersion: "1.0"`, and `agentMode: "embedded"`.
|
|
210
|
+
The SDK wraps this as a Worker manifest with `kind: "Worker"`,
|
|
211
|
+
`schemaVersion: "1.0"`, and `agentMode: "embedded"`. Existing Panel versions
|
|
212
|
+
continue accepting it through the legacy reported-service wire envelope.
|
|
143
213
|
|
|
144
214
|
## Health Reporting
|
|
145
215
|
|
|
@@ -153,13 +223,13 @@ agent.health(async () => ({
|
|
|
153
223
|
}));
|
|
154
224
|
```
|
|
155
225
|
|
|
156
|
-
The provider runs for heartbeats and
|
|
226
|
+
The provider runs for heartbeats and Worker Runtime Reports. Do not include secrets in
|
|
157
227
|
`details`.
|
|
158
228
|
|
|
159
229
|
Agent health providers return protocol-level `HealthStatus` values: `UP`,
|
|
160
230
|
`DEGRADED`, `DOWN`, `UNKNOWN`.
|
|
161
231
|
|
|
162
|
-
|
|
232
|
+
Xtrape Panel may derive an operator-facing `effectiveStatus`: `HEALTHY`, `UNHEALTHY`,
|
|
163
233
|
`STALE`, `OFFLINE`.
|
|
164
234
|
|
|
165
235
|
## Config Reporting
|
|
@@ -186,8 +256,9 @@ agent.configs(() => [
|
|
|
186
256
|
]);
|
|
187
257
|
```
|
|
188
258
|
|
|
189
|
-
|
|
190
|
-
|
|
259
|
+
Config Definitions and safe observations are reported to Panel for visibility.
|
|
260
|
+
The Worker or deployment platform remains the configuration owner; current CE
|
|
261
|
+
does not push arbitrary values into the Worker.
|
|
191
262
|
|
|
192
263
|
## Actions
|
|
193
264
|
|
|
@@ -207,12 +278,12 @@ agent.action({
|
|
|
207
278
|
});
|
|
208
279
|
```
|
|
209
280
|
|
|
210
|
-
Action metadata is published in the
|
|
281
|
+
Action metadata is published in the Worker Runtime Report. The SDK intentionally strips
|
|
211
282
|
runtime-only handler functions before reporting the Action Catalog.
|
|
212
283
|
|
|
213
284
|
## Action Prepare / Execute
|
|
214
285
|
|
|
215
|
-
|
|
286
|
+
Xtrape Panel uses two Command types for actions:
|
|
216
287
|
|
|
217
288
|
1. `ACTION_PREPARE` — created when the UI opens an Action panel. The SDK calls
|
|
218
289
|
`prepare()` if present and returns dynamic form metadata such as
|
|
@@ -229,8 +300,8 @@ The embedded Agent starts three loops by default:
|
|
|
229
300
|
|
|
230
301
|
| Loop | Default | Purpose |
|
|
231
302
|
| -------------- | ---------: | ---------------------------------- |
|
|
232
|
-
| Heartbeat | 30 seconds | Agent liveness
|
|
233
|
-
|
|
|
303
|
+
| Heartbeat | 30 seconds | Agent liveness |
|
|
304
|
+
| Worker report | 60 seconds | Manifest, config observations, Actions, health |
|
|
234
305
|
| Command poll | 5 seconds | Fetch and execute pending Commands |
|
|
235
306
|
|
|
236
307
|
You can override intervals:
|
|
@@ -240,7 +311,7 @@ new CapsuleAgent({
|
|
|
240
311
|
// ...
|
|
241
312
|
intervals: {
|
|
242
313
|
heartbeatMs: 30_000,
|
|
243
|
-
|
|
314
|
+
workerReportMs: 60_000,
|
|
244
315
|
commandPollMs: 5_000,
|
|
245
316
|
},
|
|
246
317
|
});
|
|
@@ -265,7 +336,7 @@ Security recommendations:
|
|
|
265
336
|
|
|
266
337
|
- chmod the containing directory so only the service user can read it;
|
|
267
338
|
- never commit token files;
|
|
268
|
-
- rotate by revoking the Agent in
|
|
339
|
+
- rotate by revoking the Agent in Xtrape Panel and registering a new one;
|
|
269
340
|
- prefer secret managers for production wrappers when available.
|
|
270
341
|
|
|
271
342
|
## Security Notes
|
|
@@ -342,7 +413,7 @@ try {
|
|
|
342
413
|
process.exit(65);
|
|
343
414
|
}
|
|
344
415
|
if (err instanceof NetworkError) {
|
|
345
|
-
console.error("could not reach
|
|
416
|
+
console.error("could not reach Xtrape Panel:", err.message);
|
|
346
417
|
process.exit(75);
|
|
347
418
|
}
|
|
348
419
|
throw err;
|
|
@@ -390,10 +461,13 @@ and `logger` are configured, `structuredLogger` wins.
|
|
|
390
461
|
|
|
391
462
|
| Package | Compatible with |
|
|
392
463
|
| ---------------------------------- | ------------------------------------------------------------- |
|
|
393
|
-
|
|
|
464
|
+
| repository line `0.6.0` | current Xtrape `0.6.0` snapshot train |
|
|
465
|
+
| `@xtrape/capsule-agent-node@0.1.x` | Xtrape Panel CE `0.1.x` and `@xtrape/capsule-contracts-node@0.1.x` |
|
|
394
466
|
|
|
395
|
-
Use matching
|
|
396
|
-
|
|
467
|
+
Use matching release-train versions across CE, Agent SDK, and Contracts. During
|
|
468
|
+
the current `0.6.0` snapshot phase, published compatibility packages may lag
|
|
469
|
+
the repository line until the train npm cut is published. The wire protocol may
|
|
470
|
+
still change before `v1.0`.
|
|
397
471
|
|
|
398
472
|
## Troubleshooting
|
|
399
473
|
|
|
@@ -405,16 +479,16 @@ The token is single-use and short-lived.
|
|
|
405
479
|
(registration tokens flip to `USED` on first use).
|
|
406
480
|
- Check the token has not expired. Operators set `expiresInSeconds` when
|
|
407
481
|
creating the token; the default in CE is short.
|
|
408
|
-
- Check the token has not been revoked from the
|
|
482
|
+
- Check the token has not been revoked from the Xtrape Panel console.
|
|
409
483
|
- Re-create a fresh token in the console and start the agent with it.
|
|
410
484
|
|
|
411
485
|
### Agent reports `ECONNREFUSED` / cannot reach backend
|
|
412
486
|
|
|
413
487
|
- Confirm `OPSTAGE_BACKEND_URL` resolves from inside the container or host
|
|
414
488
|
where the agent runs. The default of `http://localhost:8080` only works if
|
|
415
|
-
the agent runs on the same host as
|
|
489
|
+
the agent runs on the same host as Xtrape Panel.
|
|
416
490
|
- If you sit behind a reverse proxy, point `backendUrl` at the proxy URL —
|
|
417
|
-
not the internal
|
|
491
|
+
not the internal Xtrape Panel container address.
|
|
418
492
|
- Outbound HTTPS through corporate proxies: respect `HTTPS_PROXY` /
|
|
419
493
|
`NO_PROXY` env vars (`undici` honors them via `setGlobalDispatcher`).
|
|
420
494
|
|
|
@@ -427,7 +501,7 @@ The token is single-use and short-lived.
|
|
|
427
501
|
file exists but contains anything else, delete it and re-register with a
|
|
428
502
|
fresh registration token.
|
|
429
503
|
- Token revocation: an operator may have revoked the agent or the agent
|
|
430
|
-
token from the console. Inspect the agent's status in
|
|
504
|
+
token from the console. Inspect the agent's status in Xtrape Panel; if it shows
|
|
431
505
|
`REVOKED` or `DISABLED`, that's the cause.
|
|
432
506
|
|
|
433
507
|
### Heartbeats succeed but action results never arrive
|
|
@@ -443,10 +517,10 @@ The token is single-use and short-lived.
|
|
|
443
517
|
|
|
444
518
|
## Documentation
|
|
445
519
|
|
|
446
|
-
-
|
|
447
|
-
- Node embedded Agent guide: https://xtrape
|
|
448
|
-
- Action model: https://xtrape
|
|
449
|
-
-
|
|
520
|
+
- Public docs repo: https://forgejo.xtrape.com/xtrape/xtrape-site
|
|
521
|
+
- Node embedded Agent guide: https://forgejo.xtrape.com/xtrape/xtrape-site/src/branch/main/docs/agents/node-embedded-agent.md
|
|
522
|
+
- Action model: https://forgejo.xtrape.com/xtrape/xtrape-site/src/branch/main/docs/agents/action-model.md
|
|
523
|
+
- Xtrape Panel CE docs: https://forgejo.xtrape.com/xtrape/xtrape-site/src/branch/main/docs/opstage-ce/overview.md
|
|
450
524
|
|
|
451
525
|
## Contributing
|
|
452
526
|
|
|
@@ -456,10 +530,10 @@ safety guidance.
|
|
|
456
530
|
|
|
457
531
|
## License
|
|
458
532
|
|
|
459
|
-
Apache-2.0. "Xtrape"
|
|
533
|
+
Apache-2.0. "Xtrape" and "Opstage" are trademarks of their
|
|
460
534
|
respective owners; the open-source license does not grant trademark rights.
|
|
461
535
|
|
|
462
|
-
## v0.4 Experimental
|
|
536
|
+
## v0.4 Experimental legacy event routing Hook
|
|
463
537
|
|
|
464
538
|
The SDK exposes a minimal experimental publish hook into CE's built-in SQLite-backed in-process event-to-command router:
|
|
465
539
|
|
|
@@ -470,7 +544,7 @@ await agent.publishBusEvent({
|
|
|
470
544
|
});
|
|
471
545
|
```
|
|
472
546
|
|
|
473
|
-
The hook posts to
|
|
547
|
+
The hook posts to Xtrape Panel CE as the registered embedded agent and defaults `sourceServiceCode` to the configured service code.
|
|
474
548
|
|
|
475
549
|
Typed errors for Bus failure modes:
|
|
476
550
|
|
|
@@ -478,4 +552,4 @@ Typed errors for Bus failure modes:
|
|
|
478
552
|
- `BusRateLimitedError` — `BUS_RATE_LIMITED` (429)
|
|
479
553
|
- `BusDepthExceededError` — `BUS_DEPTH_EXCEEDED` (422)
|
|
480
554
|
|
|
481
|
-
|
|
555
|
+
legacy event routing is experimental in v0.4: not a standalone Bus Server, external broker, workflow engine, or service mesh API.
|