@xtrape/capsule-contracts-node 0.4.0 → 0.5.1
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 +90 -27
- package/dist/index.cjs +289 -106
- package/dist/index.d.cts +4724 -1510
- package/dist/index.d.ts +4724 -1510
- package/dist/index.js +256 -106
- package/package.json +7 -6
- package/spec/.source +1 -1
- package/spec/enums/audit-actions.json +2 -2
- package/spec/enums/id-prefixes.json +1 -1
- package/spec/enums/status-enums.json +2 -2
- package/spec/errors.json +2 -2
- package/spec/errors.md +1 -1
- package/spec/openapi/opstage-ce-v0.1.yaml +14 -14
- package/spec/worker-compatibility-v0.4.json +53 -0
- package/dist/src/index.d.ts +0 -4245
- package/dist/src/index.js +0 -210
- package/dist/tests/bus.spec.d.ts +0 -1
- package/dist/tests/bus.spec.js +0 -52
- package/dist/tests/schema-validation.spec.d.ts +0 -1
- package/dist/tests/schema-validation.spec.js +0 -155
- package/dist/tests/schema.spec.d.ts +0 -1
- package/dist/tests/schema.spec.js +0 -223
package/NOTICE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright 2026 Xtrape
|
|
1
|
+
Xtrape Contracts 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,18 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Xtrape Contracts for Node.js
|
|
2
2
|
|
|
3
|
-
> TypeScript contracts and Zod schemas for Xtrape
|
|
3
|
+
> TypeScript contracts and Zod schemas for Xtrape Agent, Worker, and Panel wire
|
|
4
4
|
> protocols.
|
|
5
5
|
|
|
6
|
+
The npm name `@xtrape/capsule-contracts-node` is a legacy compatibility
|
|
7
|
+
identifier. `Capsule` is not a current Xtrape concept. New code should use the
|
|
8
|
+
canonical `Worker*` exports; the existing `Capsule*` exports and `services` wire
|
|
9
|
+
field remain available until a versioned protocol migration removes them.
|
|
10
|
+
|
|
11
|
+
## Contract Authority Boundary
|
|
12
|
+
|
|
13
|
+
| Name | Role |
|
|
14
|
+
|---|---|
|
|
15
|
+
| `xtrape-contracts` | The **future language-neutral schema authority** for Xtrape contracts (not yet a separate repository). |
|
|
16
|
+
| `xtrape-contracts-nodejs` (this repo) | The **TypeScript / Zod runtime validation and type implementation**. |
|
|
17
|
+
|
|
18
|
+
Until a standalone `xtrape-contracts` exists, this package hosts the executable
|
|
19
|
+
TypeScript schemas, but it is **not** a separate conceptual authority: the
|
|
20
|
+
canonical model lives in [`xtrape-docs`](https://forgejo.xtrape.com/xtrape/xtrape-docs)
|
|
21
|
+
(`runtime-platform/02..04`, `architecture/11`). When the two disagree, the
|
|
22
|
+
canonical architecture docs win and this package is corrected to match.
|
|
23
|
+
|
|
24
|
+
## Xtrape CE 0.1 Phase 0 Contracts
|
|
25
|
+
|
|
26
|
+
The CE 0.1 runtime loop (`Telegram → server-ce → demo xtrape-service → reply`)
|
|
27
|
+
depends on a **frozen** set of schemas, exported from this package and validated
|
|
28
|
+
by `tests/ce-contracts.spec.ts` (including a field/enum surface guard):
|
|
29
|
+
|
|
30
|
+
| Export | Used by |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `CE_CONTRACT_VERSION` (`1`) | version negotiation across agent ↔ server-ce |
|
|
33
|
+
| `ServiceManifestSchema` / `ServiceManifest` | service registration descriptor |
|
|
34
|
+
| `ServiceInstanceSchema` / `ServiceInstance` | registered instance with resolvable address |
|
|
35
|
+
| `AgentHeartbeatSchema` / `AgentHeartbeat` | heartbeat / health reporting |
|
|
36
|
+
| `ConversationMessageSchema` / `ConversationMessage` | message routing + reply envelope |
|
|
37
|
+
| `ErrorModelSchema` / `ErrorModel` (+ `CeErrorCode`) | structured error responses |
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { ServiceManifestSchema, CE_CONTRACT_VERSION } from "@xtrape/capsule-contracts-node";
|
|
41
|
+
|
|
42
|
+
const manifest = ServiceManifestSchema.parse({
|
|
43
|
+
contractVersion: CE_CONTRACT_VERSION,
|
|
44
|
+
service: { id: "demo-echo-service", name: "Demo Echo Service", version: "0.1.0" },
|
|
45
|
+
runtime: { language: "node", agent: "xtrape-agent-node" },
|
|
46
|
+
capabilities: ["status.query"],
|
|
47
|
+
message: { supportedTypes: ["QUERY"] },
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
These schemas are frozen for CE 0.1: changing a field or enum is a contract
|
|
52
|
+
change that must bump `CE_CONTRACT_VERSION` and update the surface guard. See the
|
|
53
|
+
matching examples in `xtrape-docs/docs/runtime-platform/01-phase-0-runtime-mvp.md`.
|
|
54
|
+
|
|
6
55
|
[](./LICENSE)
|
|
7
56
|
[](https://xtrape-com.github.io/xtrape-capsule-site/)
|
|
8
57
|
[](https://xtrape-com.github.io/xtrape-capsule-site/contracts/overview)
|
|
9
58
|
|
|
10
|
-
`@xtrape/capsule-contracts-node` is the
|
|
11
|
-
|
|
59
|
+
`@xtrape/capsule-contracts-node` is the current published TypeScript contract
|
|
60
|
+
package for Panel CE, Agent SDKs, and Worker integrations. It exports Zod
|
|
12
61
|
schemas, inferred TypeScript types, enum values, ID helpers, pagination helpers,
|
|
13
62
|
and protocol error helpers for the Agent/Admin/System wire contracts.
|
|
14
63
|
|
|
15
|
-
> **Package status:** Xtrape
|
|
64
|
+
> **Package status:** Xtrape is currently in **Public Review** before
|
|
16
65
|
> the `v0.1.0 Public Preview` release. This package is **published to npm** under the
|
|
17
66
|
> `public-review` dist-tag. APIs, contracts, deployment instructions, and SDK
|
|
18
67
|
> interfaces may still change.
|
|
@@ -39,15 +88,28 @@ pnpm build
|
|
|
39
88
|
The package currently exports:
|
|
40
89
|
|
|
41
90
|
- Zod itself as `z` for consumers that want one compatible Zod instance.
|
|
42
|
-
- Status enum arrays and types: `AgentStatus`, `
|
|
91
|
+
- Status enum arrays and types: `AgentStatus`, `WorkerStatus` (plus the legacy
|
|
92
|
+
`CapsuleServiceStatus` alias),
|
|
43
93
|
`HealthStatus`, `CommandStatus`, `DangerLevel`, `AuditActorType`,
|
|
44
94
|
`AuditResult`, `TokenStatus`, `AgentMode`.
|
|
45
95
|
- Admin schemas: users, sessions, registration token requests/responses.
|
|
46
96
|
- Agent schemas: registration, heartbeat, service report, command result.
|
|
47
|
-
-
|
|
97
|
+
- Worker schemas: Worker Manifest, Worker Runtime Report, Worker Instance,
|
|
98
|
+
health, config, Action, and Worker Instance detail. Legacy
|
|
99
|
+
Capsule-named aliases remain available for wire compatibility.
|
|
48
100
|
- Command schemas: create command, command detail, command result.
|
|
49
101
|
- Audit and dashboard schemas.
|
|
50
102
|
- System health/version schemas.
|
|
103
|
+
|
|
104
|
+
The additive v0.4 Worker endpoint aliases and their legacy mappings are recorded
|
|
105
|
+
in `spec/worker-compatibility-v0.4.json`. The older CE v0.1 OpenAPI file remains
|
|
106
|
+
the historical baseline rather than being silently rewritten into a different
|
|
107
|
+
protocol version.
|
|
108
|
+
|
|
109
|
+
> **Known contract drift:** the historical structured sources still disagree on
|
|
110
|
+
> some Command and effective-status enum values. The `WorkerStatus` export is an
|
|
111
|
+
> alias of the currently shipped binding; it does not claim that the unresolved
|
|
112
|
+
> enum migration documented in `xtrape-docs` has been completed.
|
|
51
113
|
- Helpers: `parseSort`, `paginate`, `HttpError`, `ListQueryBase`.
|
|
52
114
|
|
|
53
115
|
## Validate Agent Registration
|
|
@@ -69,12 +131,12 @@ import { registerAgentRequestSchema } from "@xtrape/capsule-contracts-node";
|
|
|
69
131
|
const request = registerAgentRequestSchema.parse(input);
|
|
70
132
|
```
|
|
71
133
|
|
|
72
|
-
## v0.3
|
|
134
|
+
## v0.3 External-Agent Compatibility and Metadata
|
|
73
135
|
|
|
74
|
-
v0.3 adds the
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
136
|
+
v0.3 adds the legacy `ophub` Agent-mode wire value for the historical Go
|
|
137
|
+
external-Agent runtime. It represents one or more local Workers. It is not the
|
|
138
|
+
canonical Gateway role: Gateway routes Agent/control-plane traffic while
|
|
139
|
+
preserving Agent protocol semantics.
|
|
78
140
|
|
|
79
141
|
```ts
|
|
80
142
|
import { RegisterAgentRequestSchema, ServiceReportRequestSchema } from "@xtrape/capsule-contracts-node";
|
|
@@ -83,7 +145,7 @@ RegisterAgentRequestSchema.parse({
|
|
|
83
145
|
registrationToken: "opstage_reg_...",
|
|
84
146
|
agent: {
|
|
85
147
|
code: "ophub-a",
|
|
86
|
-
name: "
|
|
148
|
+
name: "External Agent A",
|
|
87
149
|
mode: "ophub",
|
|
88
150
|
runtime: "go",
|
|
89
151
|
},
|
|
@@ -112,7 +174,7 @@ ServiceReportRequestSchema.parse({
|
|
|
112
174
|
```
|
|
113
175
|
|
|
114
176
|
Capability metadata is implemented as declarative service metadata. Event
|
|
115
|
-
metadata is intentionally a foundation for future
|
|
177
|
+
metadata is intentionally a foundation for future legacy event routing work; `designOnly`
|
|
116
178
|
events must not be treated as a working event bus.
|
|
117
179
|
|
|
118
180
|
## Validate Service Report
|
|
@@ -169,7 +231,7 @@ Services:
|
|
|
169
231
|
- `DOWN`
|
|
170
232
|
- `UNKNOWN`
|
|
171
233
|
|
|
172
|
-
|
|
234
|
+
Xtrape Panel may derive an operator-facing `effectiveStatus` such as:
|
|
173
235
|
|
|
174
236
|
- `HEALTHY`
|
|
175
237
|
- `UNHEALTHY`
|
|
@@ -218,7 +280,7 @@ const prepare = ActionPrepareResultSchema.parse({
|
|
|
218
280
|
});
|
|
219
281
|
```
|
|
220
282
|
|
|
221
|
-
When reported back to
|
|
283
|
+
When reported back to Xtrape Panel for an `ACTION_PREPARE` command, this shape is
|
|
222
284
|
placed under `ReportCommandResultRequest.data`. Command result reporting still
|
|
223
285
|
uses `ReportCommandResultRequestSchema`:
|
|
224
286
|
|
|
@@ -285,6 +347,7 @@ Currently exported codes include:
|
|
|
285
347
|
- `FORBIDDEN`
|
|
286
348
|
- `NOT_FOUND`
|
|
287
349
|
- `CONFLICT`
|
|
350
|
+
- `CAPSULE_SERVICE_CODE_TAKEN` (persisted compatibility identifier for a Worker ownership conflict)
|
|
288
351
|
- `CSRF_INVALID`
|
|
289
352
|
- `ACTION_REQUIRES_CONFIRMATION`
|
|
290
353
|
- `COMMAND_EXPIRED`
|
|
@@ -334,21 +397,21 @@ const response = paginate(items, query.page, query.pageSize, total);
|
|
|
334
397
|
## Used By
|
|
335
398
|
|
|
336
399
|
- [`xtrape-capsule-ce`](https://github.com/xtrape-com/xtrape-capsule-ce) —
|
|
337
|
-
|
|
400
|
+
Xtrape Panel CE backend validation and protocol handling.
|
|
338
401
|
- [`xtrape-capsule-agent-node`](https://github.com/xtrape-com/xtrape-capsule-agent-node)
|
|
339
402
|
— Node embedded Agent SDK request/response types.
|
|
340
403
|
- [`xtrape-capsule-demo`](https://github.com/xtrape-com/xtrape-capsule-demo)
|
|
341
|
-
— End-to-end runnable
|
|
404
|
+
— End-to-end runnable Worker that imports these schemas through
|
|
342
405
|
the Agent SDK.
|
|
343
|
-
-
|
|
344
|
-
|
|
406
|
+
- Worker implementations that want local validation before reporting to
|
|
407
|
+
Xtrape Panel.
|
|
345
408
|
|
|
346
409
|
## Compatibility
|
|
347
410
|
|
|
348
411
|
| Package | Compatible with |
|
|
349
412
|
| -------------------------------------- | ---------------------------------------- |
|
|
350
|
-
| `@xtrape/capsule-contracts-node@0.2.x` |
|
|
351
|
-
| `@xtrape/capsule-contracts-node@0.1.x` |
|
|
413
|
+
| `@xtrape/capsule-contracts-node@0.2.x` | Xtrape Panel CE `0.2.x` and Agent SDK `0.2.x` |
|
|
414
|
+
| `@xtrape/capsule-contracts-node@0.1.x` | Xtrape Panel CE `0.1.x` and Agent SDK `0.1.x` |
|
|
352
415
|
|
|
353
416
|
Pin matching minor versions across CE, Agent SDK, and Contracts. The wire
|
|
354
417
|
protocol may still evolve before `v1.0`.
|
|
@@ -375,7 +438,7 @@ guarantees per schema group are:
|
|
|
375
438
|
| ---------------------------------------------------------------------------------------------------------------- | :---------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
376
439
|
| Status enums (`AgentStatus`, `CapsuleServiceStatus`, `HealthStatus`, `CommandStatus`, `DangerLevel`, `TokenStatus`) | Stable | New values may be added in minor versions; existing values will not be removed before `v1.0`. |
|
|
377
440
|
| Agent ↔ Backend wire schemas (`RegisterAgentRequest`, `AgentHeartbeat*`, `ServiceReport*`, `ReportCommandResult*`) | Evolving | Field shape is stable; additive optional fields may land in minor versions. Required fields will not be added before `v1.0` without a deprecation cycle. |
|
|
378
|
-
|
|
|
441
|
+
| Worker shapes (`WorkerManifest`, `WorkerRuntimeReport`, `WorkerInstance`, `HealthReportInput`, `ConfigItemInput`, `ActionDefinitionInput`) | Evolving | Legacy aliases retain the existing physical wire shapes. |
|
|
379
442
|
| Persisted shapes (`Agent`, `CapsuleService`, `ConfigItem`, `ActionDefinition`, `Command*`, `AuditEvent`, `User`) | Evolving | Track CE storage; safe to consume read-only. |
|
|
380
443
|
| `ActionPrepareResultSchema` | Provisional | Added in `0.1.0-public-review.0`. Field shape may still tighten before `v1.0`. |
|
|
381
444
|
| `Command.type` enum | Evolving | Currently `ACTION_PREPARE` / `ACTION_EXECUTE`. New types may be added. |
|
|
@@ -392,7 +455,7 @@ Breaking changes will be called out in `CHANGELOG.md`.
|
|
|
392
455
|
- Health contract: https://xtrape-com.github.io/xtrape-capsule-site/contracts/health
|
|
393
456
|
- Actions contract: https://xtrape-com.github.io/xtrape-capsule-site/contracts/actions
|
|
394
457
|
- Errors: https://xtrape-com.github.io/xtrape-capsule-site/contracts/errors
|
|
395
|
-
-
|
|
458
|
+
- Xtrape Panel CE: https://xtrape-com.github.io/xtrape-capsule-site/opstage-ce/overview
|
|
396
459
|
|
|
397
460
|
## Contributing
|
|
398
461
|
|
|
@@ -402,12 +465,12 @@ contract validation safety guidance.
|
|
|
402
465
|
|
|
403
466
|
## License
|
|
404
467
|
|
|
405
|
-
Apache-2.0. "Xtrape"
|
|
468
|
+
Apache-2.0. "Xtrape" and "Opstage" are trademarks of their
|
|
406
469
|
respective owners; the open-source license does not grant trademark rights.
|
|
407
470
|
|
|
408
|
-
## v0.4
|
|
471
|
+
## v0.4 legacy event routing Experimental
|
|
409
472
|
|
|
410
|
-
`v0.4` adds an experimental
|
|
473
|
+
`v0.4` adds an experimental legacy event routing contract surface for CE's built-in SQLite-backed in-process event-to-command router. It is intentionally small, single-node, and disabled by default; it is **not** a standalone Bus Server, external broker (NATS / RabbitMQ / Redis Streams / Kafka), workflow DSL, or service mesh. No fan-out (`maxCommandsPerEvent`) in v0.4 — one matched route produces at most one `ACTION_EXECUTE` command.
|
|
411
474
|
|
|
412
475
|
Key exports:
|
|
413
476
|
|