@xtrape/capsule-contracts-node 0.1.0-public-review.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/LICENSE +48 -0
- package/NOTICE +4 -0
- package/README.md +295 -0
- package/dist/index.cjs +271 -0
- package/dist/index.d.cts +2741 -0
- package/dist/index.d.ts +2741 -0
- package/dist/index.js +179 -0
- package/package.json +63 -0
- package/spec/.source +1 -0
- package/spec/enums/audit-actions.json +213 -0
- package/spec/enums/id-prefixes.json +32 -0
- package/spec/enums/status-enums.json +128 -0
- package/spec/errors.json +128 -0
- package/spec/errors.md +166 -0
- package/spec/openapi/opstage-ce-v0.1.yaml +2085 -0
- package/spec/openapi/redocly.yaml +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License.
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on the Work and for which editorial revisions, annotations, elaborations, or other modifications represent an original work of authorship.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship intentionally submitted to Licensor for inclusion in the Work by the copyright owner or authorized representative.
|
|
26
|
+
|
|
27
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor grants You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and Derivative Works in Source or Object form.
|
|
28
|
+
|
|
29
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor grants You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable patent license to make, use, sell, offer to sell, import, and otherwise transfer the Work.
|
|
30
|
+
|
|
31
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works in any medium, with or without modifications, provided that You meet the following conditions:
|
|
32
|
+
|
|
33
|
+
(a) You must give recipients a copy of this License; and
|
|
34
|
+
(b) You must cause modified files to carry prominent notices; and
|
|
35
|
+
(c) You must retain copyright, patent, trademark, and attribution notices; and
|
|
36
|
+
(d) If the Work includes a NOTICE file, any Derivative Works that You distribute must include a readable copy of attribution notices from that NOTICE file.
|
|
37
|
+
|
|
38
|
+
5. Submission of Contributions. Unless explicitly stated otherwise, any Contribution submitted for inclusion in the Work shall be under the terms of this License.
|
|
39
|
+
|
|
40
|
+
6. Trademarks. This License does not grant permission to use trade names, trademarks, service marks, or product names of the Licensor.
|
|
41
|
+
|
|
42
|
+
7. Disclaimer of Warranty. Unless required by law or agreed to in writing, Licensor provides the Work on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
43
|
+
|
|
44
|
+
8. Limitation of Liability. In no event shall any Contributor be liable for damages arising from use of the Work.
|
|
45
|
+
|
|
46
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work, You may offer support, warranty, or other liability obligations only on Your own behalf.
|
|
47
|
+
|
|
48
|
+
END OF TERMS AND CONDITIONS
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# @xtrape/capsule-contracts-node
|
|
2
|
+
|
|
3
|
+
> TypeScript contracts and Zod schemas for Xtrape Capsule and Opstage wire
|
|
4
|
+
> protocols.
|
|
5
|
+
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
[](https://xtrape-com.github.io/xtrape-capsule-site/)
|
|
8
|
+
[](https://xtrape-com.github.io/xtrape-capsule-site/contracts/overview)
|
|
9
|
+
|
|
10
|
+
`@xtrape/capsule-contracts-node` is the shared TypeScript contract package for
|
|
11
|
+
Opstage CE, Agent SDKs, and Capsule Service integrations. It exports Zod
|
|
12
|
+
schemas, inferred TypeScript types, enum values, ID helpers, pagination helpers,
|
|
13
|
+
and protocol error helpers for the Agent/Admin/System wire contracts.
|
|
14
|
+
|
|
15
|
+
> **Package status:** Xtrape Capsule is currently in **Public Review** before
|
|
16
|
+
> the `v0.1.0 Public Preview` release. This package is prepared for npm
|
|
17
|
+
> publication under the `public-review` dist-tag. APIs, contracts, deployment
|
|
18
|
+
> instructions, and SDK interfaces may still change.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
During Public Review, install the prerelease package with:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @xtrape/capsule-contracts-node@public-review
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The current Public Review version may change before `v0.1.0`.
|
|
29
|
+
|
|
30
|
+
For this repository itself:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pnpm install
|
|
34
|
+
pnpm build
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## What is Included
|
|
38
|
+
|
|
39
|
+
The package currently exports:
|
|
40
|
+
|
|
41
|
+
- Zod itself as `z` for consumers that want one compatible Zod instance.
|
|
42
|
+
- Status enum arrays and types: `AgentStatus`, `CapsuleServiceStatus`,
|
|
43
|
+
`HealthStatus`, `CommandStatus`, `DangerLevel`, `AuditActorType`,
|
|
44
|
+
`AuditResult`, `TokenStatus`.
|
|
45
|
+
- Admin schemas: users, sessions, registration token requests/responses.
|
|
46
|
+
- Agent schemas: registration, heartbeat, service report, command result.
|
|
47
|
+
- Capsule Service schemas: manifest, health, config, action, service detail.
|
|
48
|
+
- Command schemas: create command, command detail, command result.
|
|
49
|
+
- Audit and dashboard schemas.
|
|
50
|
+
- System health/version schemas.
|
|
51
|
+
- Helpers: `newId`, `parseSort`, `paginate`, `HttpError`, `ListQueryBase`.
|
|
52
|
+
|
|
53
|
+
## Validate Agent Registration
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { RegisterAgentRequestSchema } from "@xtrape/capsule-contracts-node";
|
|
57
|
+
|
|
58
|
+
const request = RegisterAgentRequestSchema.parse(input);
|
|
59
|
+
|
|
60
|
+
// request.registrationToken starts with opstage_reg_
|
|
61
|
+
// request.agent.mode is embedded
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Lowercase aliases are also exported for backend compatibility:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { registerAgentRequestSchema } from "@xtrape/capsule-contracts-node";
|
|
68
|
+
|
|
69
|
+
const request = registerAgentRequestSchema.parse(input);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Validate Service Report
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { ServiceReportRequestSchema } from "@xtrape/capsule-contracts-node";
|
|
76
|
+
|
|
77
|
+
const report = ServiceReportRequestSchema.parse({
|
|
78
|
+
services: [
|
|
79
|
+
{
|
|
80
|
+
code: "hello-capsule",
|
|
81
|
+
name: "Hello Capsule",
|
|
82
|
+
version: "0.1.0",
|
|
83
|
+
runtime: "nodejs",
|
|
84
|
+
manifest: {
|
|
85
|
+
kind: "CapsuleService",
|
|
86
|
+
schemaVersion: "1.0",
|
|
87
|
+
code: "hello-capsule",
|
|
88
|
+
name: "Hello Capsule",
|
|
89
|
+
version: "0.1.0",
|
|
90
|
+
runtime: "nodejs",
|
|
91
|
+
agentMode: "embedded",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Validate Health Report
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
import { HealthReportInputSchema } from "@xtrape/capsule-contracts-node";
|
|
102
|
+
|
|
103
|
+
const health = HealthReportInputSchema.parse({
|
|
104
|
+
status: "UP",
|
|
105
|
+
message: "ok",
|
|
106
|
+
details: { uptimeSeconds: 123 },
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Allowed health statuses are:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { HealthStatus } from "@xtrape/capsule-contracts-node";
|
|
114
|
+
|
|
115
|
+
console.log(HealthStatus); // ["UP", "DEGRADED", "DOWN", "UNKNOWN"]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`HealthStatus` is the protocol-level status reported by Agents and Capsule
|
|
119
|
+
Services:
|
|
120
|
+
|
|
121
|
+
- `UP`
|
|
122
|
+
- `DEGRADED`
|
|
123
|
+
- `DOWN`
|
|
124
|
+
- `UNKNOWN`
|
|
125
|
+
|
|
126
|
+
Opstage may derive an operator-facing `effectiveStatus` such as:
|
|
127
|
+
|
|
128
|
+
- `HEALTHY`
|
|
129
|
+
- `UNHEALTHY`
|
|
130
|
+
- `STALE`
|
|
131
|
+
- `OFFLINE`
|
|
132
|
+
|
|
133
|
+
## Validate Config and Action Definitions
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import {
|
|
137
|
+
ConfigItemInputSchema,
|
|
138
|
+
ActionDefinitionInputSchema,
|
|
139
|
+
} from "@xtrape/capsule-contracts-node";
|
|
140
|
+
|
|
141
|
+
const config = ConfigItemInputSchema.parse({
|
|
142
|
+
key: "UPSTREAM_BASE_URL",
|
|
143
|
+
type: "string",
|
|
144
|
+
sensitive: false,
|
|
145
|
+
valuePreview: "https://api.example.test",
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const action = ActionDefinitionInputSchema.parse({
|
|
149
|
+
name: "reload-cache",
|
|
150
|
+
label: "Reload Cache",
|
|
151
|
+
dangerLevel: "MEDIUM",
|
|
152
|
+
requiresConfirmation: true,
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Validate Action Prepare Result
|
|
157
|
+
|
|
158
|
+
Action prepare responses are delivered as successful Command Results. The
|
|
159
|
+
SDK/backend convention is:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
import { ReportCommandResultRequestSchema } from "@xtrape/capsule-contracts-node";
|
|
163
|
+
|
|
164
|
+
const prepareResult = ReportCommandResultRequestSchema.parse({
|
|
165
|
+
success: true,
|
|
166
|
+
data: {
|
|
167
|
+
action: { name: "echo", label: "Echo", dangerLevel: "LOW" },
|
|
168
|
+
inputSchema: {
|
|
169
|
+
type: "object",
|
|
170
|
+
properties: { message: { type: "string", default: "hello" } },
|
|
171
|
+
},
|
|
172
|
+
initialPayload: { message: "hello" },
|
|
173
|
+
currentState: { service: "ready" },
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Validate Command Result
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import { ReportCommandResultRequestSchema } from "@xtrape/capsule-contracts-node";
|
|
182
|
+
|
|
183
|
+
const result = ReportCommandResultRequestSchema.parse({
|
|
184
|
+
success: true,
|
|
185
|
+
message: "Done",
|
|
186
|
+
data: { count: 1 },
|
|
187
|
+
startedAt: new Date().toISOString(),
|
|
188
|
+
finishedAt: new Date().toISOString(),
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Failed results should include an operator-safe message and structured error:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
ReportCommandResultRequestSchema.parse({
|
|
196
|
+
success: false,
|
|
197
|
+
message: "Provider challenge page detected.",
|
|
198
|
+
error: {
|
|
199
|
+
code: "ACTION_FAILED",
|
|
200
|
+
retryable: false,
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Error Codes
|
|
206
|
+
|
|
207
|
+
The `ErrorCode` export contains protocol-level error code constants currently
|
|
208
|
+
used by CE and SDKs:
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
import { ErrorCode } from "@xtrape/capsule-contracts-node";
|
|
212
|
+
|
|
213
|
+
throw new Error(ErrorCode.VALIDATION_FAILED);
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Currently exported codes include:
|
|
217
|
+
|
|
218
|
+
- `INTERNAL_ERROR`
|
|
219
|
+
- `VALIDATION_FAILED`
|
|
220
|
+
- `UNAUTHORIZED`
|
|
221
|
+
- `FORBIDDEN`
|
|
222
|
+
- `NOT_FOUND`
|
|
223
|
+
- `CONFLICT`
|
|
224
|
+
- `CSRF_INVALID`
|
|
225
|
+
- `ACTION_REQUIRES_CONFIRMATION`
|
|
226
|
+
- `COMMAND_EXPIRED`
|
|
227
|
+
- `TOKEN_REVOKED`
|
|
228
|
+
- `TOKEN_EXPIRED`
|
|
229
|
+
- `AGENT_REVOKED`
|
|
230
|
+
- `AGENT_DISABLED`
|
|
231
|
+
|
|
232
|
+
See the OpenAPI contract and docs site for endpoint-specific errors.
|
|
233
|
+
|
|
234
|
+
## ID Helpers
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
import { newId } from "@xtrape/capsule-contracts-node";
|
|
238
|
+
|
|
239
|
+
const commandId = newId("cmd_");
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Supported prefixes include `wks_`, `usr_`, `agt_`, `tok_`, `svc_`, `hlr_`,
|
|
243
|
+
`cfg_`, `act_`, `cmd_`, `crs_`, and `aud_`.
|
|
244
|
+
|
|
245
|
+
## List Helpers
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import {
|
|
249
|
+
ListQueryBase,
|
|
250
|
+
parseSort,
|
|
251
|
+
paginate,
|
|
252
|
+
} from "@xtrape/capsule-contracts-node";
|
|
253
|
+
|
|
254
|
+
const query = ListQueryBase.parse({ page: "1", pageSize: "20" });
|
|
255
|
+
const sort = parseSort("-createdAt", ["createdAt", "name"]);
|
|
256
|
+
const response = paginate(items, query.page, query.pageSize, total);
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Used By
|
|
260
|
+
|
|
261
|
+
- [`xtrape-capsule-ce`](https://github.com/xtrape-com/xtrape-capsule-ce) —
|
|
262
|
+
Opstage CE backend validation and protocol handling.
|
|
263
|
+
- [`xtrape-capsule-agent-node`](https://github.com/xtrape-com/xtrape-capsule-agent-node)
|
|
264
|
+
— Node embedded Agent SDK request/response types.
|
|
265
|
+
- Capsule Service implementations that want local validation before reporting to
|
|
266
|
+
Opstage.
|
|
267
|
+
|
|
268
|
+
## Compatibility
|
|
269
|
+
|
|
270
|
+
| Package | Compatible with |
|
|
271
|
+
| -------------------------------------- | ---------------------------------------- |
|
|
272
|
+
| `@xtrape/capsule-contracts-node@0.1.x` | Opstage CE `0.1.x` and Agent SDK `0.1.x` |
|
|
273
|
+
|
|
274
|
+
During Public Review and Public Preview, keep CE, Agent SDK, and Contracts on
|
|
275
|
+
matching minor versions. The wire protocol may still evolve before `v1.0`.
|
|
276
|
+
|
|
277
|
+
## Documentation
|
|
278
|
+
|
|
279
|
+
- Contracts overview: https://xtrape-com.github.io/xtrape-capsule-site/contracts/overview
|
|
280
|
+
- Manifest contract: https://xtrape-com.github.io/xtrape-capsule-site/contracts/manifest
|
|
281
|
+
- Health contract: https://xtrape-com.github.io/xtrape-capsule-site/contracts/health
|
|
282
|
+
- Actions contract: https://xtrape-com.github.io/xtrape-capsule-site/contracts/actions
|
|
283
|
+
- Errors: https://xtrape-com.github.io/xtrape-capsule-site/contracts/errors
|
|
284
|
+
- Opstage CE: https://xtrape-com.github.io/xtrape-capsule-site/opstage-ce/overview
|
|
285
|
+
|
|
286
|
+
## Contributing
|
|
287
|
+
|
|
288
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for schema change workflow and PR
|
|
289
|
+
checks. See [SECURITY.md](./SECURITY.md) for vulnerability reporting and
|
|
290
|
+
contract validation safety guidance.
|
|
291
|
+
|
|
292
|
+
## License
|
|
293
|
+
|
|
294
|
+
Apache-2.0. "Xtrape", "Xtrape Capsule", and "Opstage" are trademarks of their
|
|
295
|
+
respective owners; the open-source license does not grant trademark rights.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
ActionDefinitionInputSchema: () => ActionDefinitionInputSchema,
|
|
24
|
+
ActionDefinitionSchema: () => ActionDefinitionSchema,
|
|
25
|
+
AdminLoginRequestSchema: () => AdminLoginRequestSchema,
|
|
26
|
+
AdminSessionSchema: () => AdminSessionSchema,
|
|
27
|
+
AgentHeartbeatRequestSchema: () => AgentHeartbeatRequestSchema,
|
|
28
|
+
AgentHeartbeatResponseSchema: () => AgentHeartbeatResponseSchema,
|
|
29
|
+
AgentSchema: () => AgentSchema,
|
|
30
|
+
AgentStatus: () => AgentStatus,
|
|
31
|
+
AgentStatusSchema: () => AgentStatusSchema,
|
|
32
|
+
AnyJson: () => AnyJson,
|
|
33
|
+
AuditActorType: () => AuditActorType,
|
|
34
|
+
AuditEventSchema: () => AuditEventSchema,
|
|
35
|
+
AuditResult: () => AuditResult,
|
|
36
|
+
CapsuleManifestSchema: () => CapsuleManifestSchema,
|
|
37
|
+
CapsuleServiceDetailSchema: () => CapsuleServiceDetailSchema,
|
|
38
|
+
CapsuleServiceSchema: () => CapsuleServiceSchema,
|
|
39
|
+
CapsuleServiceStatus: () => CapsuleServiceStatus,
|
|
40
|
+
CapsuleServiceStatusSchema: () => CapsuleServiceStatusSchema,
|
|
41
|
+
CommandDetailSchema: () => CommandDetailSchema,
|
|
42
|
+
CommandResultSchema: () => CommandResultSchema,
|
|
43
|
+
CommandSchema: () => CommandSchema,
|
|
44
|
+
CommandStatus: () => CommandStatus,
|
|
45
|
+
CommandStatusSchema: () => CommandStatusSchema,
|
|
46
|
+
ConfigItemInputSchema: () => ConfigItemInputSchema,
|
|
47
|
+
ConfigItemSchema: () => ConfigItemSchema,
|
|
48
|
+
CreateActionCommandRequestSchema: () => CreateActionCommandRequestSchema,
|
|
49
|
+
CreateRegistrationTokenRequestSchema: () => CreateRegistrationTokenRequestSchema,
|
|
50
|
+
CreateRegistrationTokenResponseSchema: () => CreateRegistrationTokenResponseSchema,
|
|
51
|
+
DangerLevel: () => DangerLevel,
|
|
52
|
+
DangerLevelSchema: () => DangerLevelSchema,
|
|
53
|
+
DashboardSummarySchema: () => DashboardSummarySchema,
|
|
54
|
+
ErrorCode: () => ErrorCode,
|
|
55
|
+
HealthReportInputSchema: () => HealthReportInputSchema,
|
|
56
|
+
HealthReportSchema: () => HealthReportSchema,
|
|
57
|
+
HealthStatus: () => HealthStatus,
|
|
58
|
+
HealthStatusSchema: () => HealthStatusSchema,
|
|
59
|
+
HttpError: () => HttpError,
|
|
60
|
+
ListQueryBase: () => ListQueryBase,
|
|
61
|
+
RegisterAgentRequestSchema: () => RegisterAgentRequestSchema,
|
|
62
|
+
RegisterAgentResponseSchema: () => RegisterAgentResponseSchema,
|
|
63
|
+
RegistrationTokenSchema: () => RegistrationTokenSchema,
|
|
64
|
+
ReportCommandResultRequestSchema: () => ReportCommandResultRequestSchema,
|
|
65
|
+
ReportedServiceSchema: () => ReportedServiceSchema,
|
|
66
|
+
ServiceReportRequestSchema: () => ServiceReportRequestSchema,
|
|
67
|
+
SystemHealthSchema: () => SystemHealthSchema,
|
|
68
|
+
SystemVersionSchema: () => SystemVersionSchema,
|
|
69
|
+
TokenStatus: () => TokenStatus,
|
|
70
|
+
UserRole: () => UserRole,
|
|
71
|
+
UserSchema: () => UserSchema,
|
|
72
|
+
actionDefinitionInputSchema: () => actionDefinitionInputSchema,
|
|
73
|
+
adminLoginRequestSchema: () => adminLoginRequestSchema,
|
|
74
|
+
agentHeartbeatRequestSchema: () => agentHeartbeatRequestSchema,
|
|
75
|
+
configItemInputSchema: () => configItemInputSchema,
|
|
76
|
+
createActionCommandRequestSchema: () => createActionCommandRequestSchema,
|
|
77
|
+
createRegistrationTokenRequestSchema: () => createRegistrationTokenRequestSchema,
|
|
78
|
+
createUserRequestSchema: () => createUserRequestSchema,
|
|
79
|
+
healthReportInputSchema: () => healthReportInputSchema,
|
|
80
|
+
idPrefixes: () => idPrefixes,
|
|
81
|
+
newId: () => newId,
|
|
82
|
+
paginate: () => paginate,
|
|
83
|
+
parseSort: () => parseSort,
|
|
84
|
+
registerAgentRequestSchema: () => registerAgentRequestSchema,
|
|
85
|
+
reportCommandResultRequestSchema: () => reportCommandResultRequestSchema,
|
|
86
|
+
reportedServiceSchema: () => reportedServiceSchema,
|
|
87
|
+
resetUserPasswordRequestSchema: () => resetUserPasswordRequestSchema,
|
|
88
|
+
serviceReportRequestSchema: () => serviceReportRequestSchema,
|
|
89
|
+
updateUserRequestSchema: () => updateUserRequestSchema,
|
|
90
|
+
z: () => import_zod.z
|
|
91
|
+
});
|
|
92
|
+
module.exports = __toCommonJS(index_exports);
|
|
93
|
+
var import_nanoid = require("nanoid");
|
|
94
|
+
var import_zod = require("zod");
|
|
95
|
+
var AgentStatus = ["PENDING", "ONLINE", "OFFLINE", "DISABLED", "REVOKED"];
|
|
96
|
+
var CapsuleServiceStatus = ["UNKNOWN", "HEALTHY", "UNHEALTHY", "STALE", "OFFLINE"];
|
|
97
|
+
var HealthStatus = ["UP", "DEGRADED", "DOWN", "UNKNOWN"];
|
|
98
|
+
var CommandStatus = ["PENDING", "RUNNING", "SUCCEEDED", "FAILED", "EXPIRED", "CANCELLED"];
|
|
99
|
+
var DangerLevel = ["LOW", "MEDIUM", "HIGH"];
|
|
100
|
+
var AuditActorType = ["USER", "AGENT", "SYSTEM"];
|
|
101
|
+
var AuditResult = ["SUCCESS", "FAILURE"];
|
|
102
|
+
var TokenStatus = ["ACTIVE", "REVOKED", "EXPIRED", "USED"];
|
|
103
|
+
var ErrorCode = {
|
|
104
|
+
INTERNAL_ERROR: "INTERNAL_ERROR",
|
|
105
|
+
VALIDATION_FAILED: "VALIDATION_FAILED",
|
|
106
|
+
UNAUTHORIZED: "UNAUTHORIZED",
|
|
107
|
+
FORBIDDEN: "FORBIDDEN",
|
|
108
|
+
NOT_FOUND: "NOT_FOUND",
|
|
109
|
+
CONFLICT: "CONFLICT",
|
|
110
|
+
CSRF_INVALID: "CSRF_INVALID",
|
|
111
|
+
ACTION_REQUIRES_CONFIRMATION: "ACTION_REQUIRES_CONFIRMATION",
|
|
112
|
+
COMMAND_EXPIRED: "COMMAND_EXPIRED",
|
|
113
|
+
TOKEN_REVOKED: "TOKEN_REVOKED",
|
|
114
|
+
TOKEN_EXPIRED: "TOKEN_EXPIRED",
|
|
115
|
+
AGENT_REVOKED: "AGENT_REVOKED",
|
|
116
|
+
AGENT_DISABLED: "AGENT_DISABLED"
|
|
117
|
+
};
|
|
118
|
+
var idPrefixes = ["wks_", "usr_", "agt_", "tok_", "svc_", "hlr_", "cfg_", "act_", "cmd_", "crs_", "aud_"];
|
|
119
|
+
var NANO = (0, import_nanoid.customAlphabet)("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-", 21);
|
|
120
|
+
function newId(prefix) {
|
|
121
|
+
return `${prefix}${NANO()}`;
|
|
122
|
+
}
|
|
123
|
+
var AnyJson = import_zod.z.record(import_zod.z.any());
|
|
124
|
+
var AgentStatusSchema = import_zod.z.enum(AgentStatus);
|
|
125
|
+
var CapsuleServiceStatusSchema = import_zod.z.enum(CapsuleServiceStatus);
|
|
126
|
+
var HealthStatusSchema = import_zod.z.enum(HealthStatus);
|
|
127
|
+
var CommandStatusSchema = import_zod.z.enum(CommandStatus);
|
|
128
|
+
var DangerLevelSchema = import_zod.z.enum(DangerLevel).default("LOW");
|
|
129
|
+
var UserSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("usr_"), username: import_zod.z.string(), displayName: import_zod.z.string().nullable().optional(), createdAt: import_zod.z.string(), updatedAt: import_zod.z.string() });
|
|
130
|
+
var UserRole = import_zod.z.enum(["owner", "operator", "viewer"]);
|
|
131
|
+
var createUserRequestSchema = import_zod.z.object({ username: import_zod.z.string().min(1), password: import_zod.z.string().min(12), displayName: import_zod.z.string().optional(), role: UserRole.default("viewer") });
|
|
132
|
+
var updateUserRequestSchema = import_zod.z.object({ displayName: import_zod.z.string().optional(), role: UserRole.optional(), status: import_zod.z.enum(["ACTIVE", "DISABLED"]).optional() });
|
|
133
|
+
var resetUserPasswordRequestSchema = import_zod.z.object({ password: import_zod.z.string().min(12) });
|
|
134
|
+
var AdminLoginRequestSchema = import_zod.z.object({ username: import_zod.z.string().min(1), password: import_zod.z.string().min(1) });
|
|
135
|
+
var adminLoginRequestSchema = AdminLoginRequestSchema;
|
|
136
|
+
var AdminSessionSchema = import_zod.z.object({ user: UserSchema, csrfToken: import_zod.z.string(), expiresAt: import_zod.z.string() });
|
|
137
|
+
var AgentSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("agt_"), code: import_zod.z.string(), name: import_zod.z.string().nullable().optional(), mode: import_zod.z.enum(["embedded", "sidecar", "external"]), runtime: import_zod.z.string().nullable().optional(), status: AgentStatusSchema, lastHeartbeatAt: import_zod.z.string().nullable().optional(), createdAt: import_zod.z.string(), updatedAt: import_zod.z.string() });
|
|
138
|
+
var RegistrationTokenSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("tok_"), name: import_zod.z.string(), status: import_zod.z.enum(TokenStatus), expiresAt: import_zod.z.string().nullable().optional(), usedAt: import_zod.z.string().nullable().optional(), createdAt: import_zod.z.string() });
|
|
139
|
+
var CreateRegistrationTokenRequestSchema = import_zod.z.object({ name: import_zod.z.string().default("Default registration token").optional(), expiresInSeconds: import_zod.z.number().int().min(60).optional() });
|
|
140
|
+
var createRegistrationTokenRequestSchema = CreateRegistrationTokenRequestSchema;
|
|
141
|
+
var CreateRegistrationTokenResponseSchema = RegistrationTokenSchema.extend({ rawToken: import_zod.z.string().startsWith("opstage_reg_") });
|
|
142
|
+
var CapsuleManifestSchema = import_zod.z.object({ kind: import_zod.z.literal("CapsuleService"), schemaVersion: import_zod.z.string().default("1.0").optional(), code: import_zod.z.string().min(1), name: import_zod.z.string().min(1), description: import_zod.z.string().optional(), version: import_zod.z.string().min(1), runtime: import_zod.z.enum(["nodejs", "java", "python", "go", "other"]), agentMode: import_zod.z.enum(["embedded", "sidecar", "external"]), capabilities: import_zod.z.array(import_zod.z.string()).optional(), labels: import_zod.z.record(import_zod.z.string()).optional() }).passthrough();
|
|
143
|
+
var HealthReportInputSchema = import_zod.z.object({ status: HealthStatusSchema, message: import_zod.z.string().optional(), details: AnyJson.optional() });
|
|
144
|
+
var healthReportInputSchema = HealthReportInputSchema;
|
|
145
|
+
var ConfigItemInputSchema = import_zod.z.object({ key: import_zod.z.string(), label: import_zod.z.string().optional(), type: import_zod.z.string(), source: import_zod.z.string().optional(), editable: import_zod.z.boolean().optional(), sensitive: import_zod.z.boolean().optional(), valuePreview: import_zod.z.string().optional(), defaultValue: import_zod.z.string().optional(), secretRef: import_zod.z.string().optional() });
|
|
146
|
+
var configItemInputSchema = ConfigItemInputSchema;
|
|
147
|
+
var ActionDefinitionInputSchema = import_zod.z.object({ name: import_zod.z.string(), label: import_zod.z.string(), description: import_zod.z.string().optional(), dangerLevel: import_zod.z.enum(DangerLevel).default("LOW").optional(), requiresConfirmation: import_zod.z.boolean().optional(), category: import_zod.z.string().optional(), order: import_zod.z.number().int().optional(), inputSchema: AnyJson.optional(), outputSchema: AnyJson.optional(), timeoutSeconds: import_zod.z.number().int().positive().optional() });
|
|
148
|
+
var actionDefinitionInputSchema = ActionDefinitionInputSchema;
|
|
149
|
+
var ReportedServiceSchema = import_zod.z.object({ code: import_zod.z.string().min(1).max(80), name: import_zod.z.string().min(1).max(200), description: import_zod.z.string().max(2e3).optional(), version: import_zod.z.string().max(80).optional(), runtime: import_zod.z.string().optional(), manifest: AnyJson, health: HealthReportInputSchema.optional(), configs: import_zod.z.array(ConfigItemInputSchema).optional(), actions: import_zod.z.array(ActionDefinitionInputSchema).optional() });
|
|
150
|
+
var reportedServiceSchema = ReportedServiceSchema;
|
|
151
|
+
var ServiceReportRequestSchema = import_zod.z.object({ services: import_zod.z.array(ReportedServiceSchema).min(1) });
|
|
152
|
+
var serviceReportRequestSchema = ServiceReportRequestSchema;
|
|
153
|
+
var RegisterAgentRequestSchema = import_zod.z.object({ registrationToken: import_zod.z.string().startsWith("opstage_reg_"), agent: import_zod.z.object({ code: import_zod.z.string(), name: import_zod.z.string().optional(), mode: import_zod.z.literal("embedded"), runtime: import_zod.z.string().optional() }), service: ReportedServiceSchema.optional() });
|
|
154
|
+
var registerAgentRequestSchema = RegisterAgentRequestSchema;
|
|
155
|
+
var RegisterAgentResponseSchema = import_zod.z.object({ agentId: import_zod.z.string().startsWith("agt_"), agentToken: import_zod.z.string().startsWith("opstage_agent_"), heartbeatIntervalSeconds: import_zod.z.number().int(), commandPollIntervalSeconds: import_zod.z.number().int() });
|
|
156
|
+
var AgentHeartbeatResponseSchema = import_zod.z.object({ heartbeatIntervalSeconds: import_zod.z.number().int(), commandPollIntervalSeconds: import_zod.z.number().int() });
|
|
157
|
+
var AgentHeartbeatRequestSchema = import_zod.z.object({ serviceId: import_zod.z.string().startsWith("svc_").optional(), health: HealthReportInputSchema.optional() });
|
|
158
|
+
var agentHeartbeatRequestSchema = AgentHeartbeatRequestSchema;
|
|
159
|
+
var CapsuleServiceSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("svc_"), agentId: import_zod.z.string().startsWith("agt_").optional(), code: import_zod.z.string(), name: import_zod.z.string(), description: import_zod.z.string().nullable().optional(), version: import_zod.z.string().nullable().optional(), runtime: import_zod.z.string().nullable().optional(), status: CapsuleServiceStatusSchema, healthStatus: HealthStatusSchema.optional(), lastReportedAt: import_zod.z.string().nullable().optional(), lastHealthAt: import_zod.z.string().nullable().optional(), createdAt: import_zod.z.string(), updatedAt: import_zod.z.string() });
|
|
160
|
+
var HealthReportSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("hlr_"), serviceId: import_zod.z.string().startsWith("svc_"), agentId: import_zod.z.string().startsWith("agt_").optional(), status: HealthStatusSchema, message: import_zod.z.string().nullable().optional(), details: AnyJson.optional(), reportedAt: import_zod.z.string() });
|
|
161
|
+
var ConfigItemSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("cfg_"), serviceId: import_zod.z.string().startsWith("svc_"), key: import_zod.z.string(), label: import_zod.z.string().nullable().optional(), type: import_zod.z.string(), source: import_zod.z.string().nullable().optional(), editable: import_zod.z.boolean().default(false), sensitive: import_zod.z.boolean(), valuePreview: import_zod.z.string().nullable().optional(), defaultValue: import_zod.z.string().nullable().optional(), secretRef: import_zod.z.string().nullable().optional() });
|
|
162
|
+
var ActionDefinitionSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("act_"), serviceId: import_zod.z.string().startsWith("svc_"), name: import_zod.z.string(), label: import_zod.z.string(), description: import_zod.z.string().nullable().optional(), dangerLevel: import_zod.z.enum(DangerLevel), requiresConfirmation: import_zod.z.boolean(), category: import_zod.z.string().optional(), order: import_zod.z.number().int().optional(), inputSchema: AnyJson.optional(), outputSchema: AnyJson.optional(), timeoutSeconds: import_zod.z.number().int().optional() });
|
|
163
|
+
var CapsuleServiceDetailSchema = CapsuleServiceSchema.extend({ manifest: AnyJson.optional(), health: HealthReportSchema.nullable().optional(), configs: import_zod.z.array(ConfigItemSchema).optional(), actions: import_zod.z.array(ActionDefinitionSchema).optional() });
|
|
164
|
+
var CreateActionCommandRequestSchema = import_zod.z.object({ payload: AnyJson.optional(), confirmation: import_zod.z.boolean().optional() });
|
|
165
|
+
var createActionCommandRequestSchema = CreateActionCommandRequestSchema;
|
|
166
|
+
var CommandSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("cmd_"), agentId: import_zod.z.string().startsWith("agt_"), serviceId: import_zod.z.string().startsWith("svc_"), type: import_zod.z.enum(["ACTION_PREPARE", "ACTION_EXECUTE", "ACTION"]), actionName: import_zod.z.string(), status: CommandStatusSchema, payload: AnyJson.optional(), createdByUserId: import_zod.z.string().startsWith("usr_").nullable().optional(), createdAt: import_zod.z.string(), startedAt: import_zod.z.string().nullable().optional(), completedAt: import_zod.z.string().nullable().optional(), expiresAt: import_zod.z.string().nullable().optional() });
|
|
167
|
+
var ReportCommandResultRequestSchema = import_zod.z.object({ success: import_zod.z.boolean(), message: import_zod.z.string().optional(), data: AnyJson.optional(), error: AnyJson.optional(), startedAt: import_zod.z.string().optional(), finishedAt: import_zod.z.string().optional() });
|
|
168
|
+
var reportCommandResultRequestSchema = ReportCommandResultRequestSchema;
|
|
169
|
+
var CommandResultSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("crs_"), commandId: import_zod.z.string().startsWith("cmd_"), success: import_zod.z.boolean(), message: import_zod.z.string().nullable().optional(), data: AnyJson.optional(), error: AnyJson.optional(), reportedAt: import_zod.z.string() });
|
|
170
|
+
var CommandDetailSchema = CommandSchema.extend({ result: CommandResultSchema.nullable().optional() });
|
|
171
|
+
var AuditEventSchema = import_zod.z.object({ id: import_zod.z.string().startsWith("aud_"), actorType: import_zod.z.enum(AuditActorType), actorId: import_zod.z.string().nullable().optional(), action: import_zod.z.string(), targetType: import_zod.z.string().nullable().optional(), targetId: import_zod.z.string().nullable().optional(), result: import_zod.z.enum(AuditResult), message: import_zod.z.string().nullable().optional(), metadata: AnyJson.optional(), createdAt: import_zod.z.string() });
|
|
172
|
+
var DashboardSummarySchema = import_zod.z.object({ agentCounts: import_zod.z.record(import_zod.z.number().int()), serviceCounts: import_zod.z.record(import_zod.z.number().int()), commandCounts: import_zod.z.record(import_zod.z.number().int()), recentCommands: import_zod.z.array(CommandSchema).optional(), recentAuditEvents: import_zod.z.array(AuditEventSchema).optional() });
|
|
173
|
+
var SystemHealthSchema = import_zod.z.object({ status: import_zod.z.enum(["UP", "DEGRADED", "DOWN"]), timestamp: import_zod.z.string(), version: import_zod.z.string(), edition: import_zod.z.literal("ce"), database: import_zod.z.object({ status: import_zod.z.enum(["UP", "DEGRADED", "DOWN"]), kind: import_zod.z.enum(["sqlite", "postgres", "mysql"]).optional(), latencyMs: import_zod.z.number().int().optional() }), uptimeSeconds: import_zod.z.number().int().optional() });
|
|
174
|
+
var SystemVersionSchema = import_zod.z.object({ version: import_zod.z.string(), edition: import_zod.z.literal("ce"), commit: import_zod.z.string().optional(), buildTime: import_zod.z.string().optional() });
|
|
175
|
+
var ListQueryBase = import_zod.z.object({ page: import_zod.z.coerce.number().int().min(1).default(1), pageSize: import_zod.z.coerce.number().int().min(1).max(100).default(20), sort: import_zod.z.string().optional() });
|
|
176
|
+
var HttpError = class extends Error {
|
|
177
|
+
constructor(httpStatus, code, publicMessage, details) {
|
|
178
|
+
super(publicMessage);
|
|
179
|
+
this.httpStatus = httpStatus;
|
|
180
|
+
this.code = code;
|
|
181
|
+
this.publicMessage = publicMessage;
|
|
182
|
+
this.details = details;
|
|
183
|
+
}
|
|
184
|
+
httpStatus;
|
|
185
|
+
code;
|
|
186
|
+
publicMessage;
|
|
187
|
+
details;
|
|
188
|
+
};
|
|
189
|
+
function parseSort(value, allowed) {
|
|
190
|
+
if (!value) return [];
|
|
191
|
+
return value.split(",").filter(Boolean).map((raw) => {
|
|
192
|
+
const desc = raw.startsWith("-");
|
|
193
|
+
const field = desc ? raw.slice(1) : raw;
|
|
194
|
+
if (!allowed.includes(field)) throw new HttpError(422, "VALIDATION_FAILED", `Unknown sort field: ${field}`);
|
|
195
|
+
return { field, direction: desc ? "desc" : "asc" };
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function paginate(items, page, pageSize, total) {
|
|
199
|
+
return { data: items, pagination: { page, pageSize, total } };
|
|
200
|
+
}
|
|
201
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
202
|
+
0 && (module.exports = {
|
|
203
|
+
ActionDefinitionInputSchema,
|
|
204
|
+
ActionDefinitionSchema,
|
|
205
|
+
AdminLoginRequestSchema,
|
|
206
|
+
AdminSessionSchema,
|
|
207
|
+
AgentHeartbeatRequestSchema,
|
|
208
|
+
AgentHeartbeatResponseSchema,
|
|
209
|
+
AgentSchema,
|
|
210
|
+
AgentStatus,
|
|
211
|
+
AgentStatusSchema,
|
|
212
|
+
AnyJson,
|
|
213
|
+
AuditActorType,
|
|
214
|
+
AuditEventSchema,
|
|
215
|
+
AuditResult,
|
|
216
|
+
CapsuleManifestSchema,
|
|
217
|
+
CapsuleServiceDetailSchema,
|
|
218
|
+
CapsuleServiceSchema,
|
|
219
|
+
CapsuleServiceStatus,
|
|
220
|
+
CapsuleServiceStatusSchema,
|
|
221
|
+
CommandDetailSchema,
|
|
222
|
+
CommandResultSchema,
|
|
223
|
+
CommandSchema,
|
|
224
|
+
CommandStatus,
|
|
225
|
+
CommandStatusSchema,
|
|
226
|
+
ConfigItemInputSchema,
|
|
227
|
+
ConfigItemSchema,
|
|
228
|
+
CreateActionCommandRequestSchema,
|
|
229
|
+
CreateRegistrationTokenRequestSchema,
|
|
230
|
+
CreateRegistrationTokenResponseSchema,
|
|
231
|
+
DangerLevel,
|
|
232
|
+
DangerLevelSchema,
|
|
233
|
+
DashboardSummarySchema,
|
|
234
|
+
ErrorCode,
|
|
235
|
+
HealthReportInputSchema,
|
|
236
|
+
HealthReportSchema,
|
|
237
|
+
HealthStatus,
|
|
238
|
+
HealthStatusSchema,
|
|
239
|
+
HttpError,
|
|
240
|
+
ListQueryBase,
|
|
241
|
+
RegisterAgentRequestSchema,
|
|
242
|
+
RegisterAgentResponseSchema,
|
|
243
|
+
RegistrationTokenSchema,
|
|
244
|
+
ReportCommandResultRequestSchema,
|
|
245
|
+
ReportedServiceSchema,
|
|
246
|
+
ServiceReportRequestSchema,
|
|
247
|
+
SystemHealthSchema,
|
|
248
|
+
SystemVersionSchema,
|
|
249
|
+
TokenStatus,
|
|
250
|
+
UserRole,
|
|
251
|
+
UserSchema,
|
|
252
|
+
actionDefinitionInputSchema,
|
|
253
|
+
adminLoginRequestSchema,
|
|
254
|
+
agentHeartbeatRequestSchema,
|
|
255
|
+
configItemInputSchema,
|
|
256
|
+
createActionCommandRequestSchema,
|
|
257
|
+
createRegistrationTokenRequestSchema,
|
|
258
|
+
createUserRequestSchema,
|
|
259
|
+
healthReportInputSchema,
|
|
260
|
+
idPrefixes,
|
|
261
|
+
newId,
|
|
262
|
+
paginate,
|
|
263
|
+
parseSort,
|
|
264
|
+
registerAgentRequestSchema,
|
|
265
|
+
reportCommandResultRequestSchema,
|
|
266
|
+
reportedServiceSchema,
|
|
267
|
+
resetUserPasswordRequestSchema,
|
|
268
|
+
serviceReportRequestSchema,
|
|
269
|
+
updateUserRequestSchema,
|
|
270
|
+
z
|
|
271
|
+
});
|