@xtrape/capsule-contracts-node 0.4.0 → 0.5.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 +46 -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 +4 -3
- 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/dist/index.js
CHANGED
|
@@ -1,7 +1,104 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import { z as z2 } from "zod";
|
|
3
|
+
|
|
4
|
+
// src/ce.ts
|
|
2
5
|
import { z } from "zod";
|
|
6
|
+
var CE_CONTRACT_VERSION = 1;
|
|
7
|
+
var ServiceId = z.string().regex(/^[a-z0-9][a-z0-9-]*$/, "kebab-case service id");
|
|
8
|
+
var Json = z.record(z.any());
|
|
9
|
+
var ServiceInstanceHealth = ["HEALTHY", "DEGRADED", "UNREACHABLE"];
|
|
10
|
+
var ServiceInstanceHealthSchema = z.enum(ServiceInstanceHealth);
|
|
11
|
+
var ConversationTargetType = ["SERVICE", "TASK", "USER", "SYSTEM"];
|
|
12
|
+
var ConversationTargetTypeSchema = z.enum(ConversationTargetType);
|
|
13
|
+
var MessageSenderType = ["USER", "SERVICE", "SYSTEM"];
|
|
14
|
+
var MessageSenderTypeSchema = z.enum(MessageSenderType);
|
|
15
|
+
var MessageType = [
|
|
16
|
+
"TEXT",
|
|
17
|
+
"QUERY",
|
|
18
|
+
"COMMAND",
|
|
19
|
+
"SUMMARY",
|
|
20
|
+
"APPROVAL_REQUEST",
|
|
21
|
+
"APPROVAL_RESPONSE"
|
|
22
|
+
];
|
|
23
|
+
var MessageTypeSchema = z.enum(MessageType);
|
|
24
|
+
var ServiceManifestSchema = z.object({
|
|
25
|
+
contractVersion: z.literal(CE_CONTRACT_VERSION),
|
|
26
|
+
tenant: z.string().default("default"),
|
|
27
|
+
service: z.object({
|
|
28
|
+
id: ServiceId,
|
|
29
|
+
name: z.string().min(1),
|
|
30
|
+
version: z.string().min(1),
|
|
31
|
+
description: z.string().optional()
|
|
32
|
+
}),
|
|
33
|
+
owner: z.object({ organization: z.string().optional(), maintainer: z.string().optional() }).optional(),
|
|
34
|
+
runtime: z.object({
|
|
35
|
+
language: z.string().min(1),
|
|
36
|
+
agent: z.string().min(1),
|
|
37
|
+
// declared template; the real address is reported by the instance on register
|
|
38
|
+
endpoint: z.string().url().optional()
|
|
39
|
+
}),
|
|
40
|
+
// business-semantic capabilities (Capability), e.g. "status.query"
|
|
41
|
+
capabilities: z.array(z.string().min(1)).min(1),
|
|
42
|
+
// platform feature toggles (not business semantics)
|
|
43
|
+
features: z.record(z.boolean()).optional(),
|
|
44
|
+
message: z.object({ supportedTypes: z.array(MessageTypeSchema).min(1) }),
|
|
45
|
+
// structured triggers; kept loose for Phase 0
|
|
46
|
+
triggers: z.array(z.object({ type: z.string() }).passthrough()).optional()
|
|
47
|
+
}).passthrough();
|
|
48
|
+
var ServiceInstanceSchema = z.object({
|
|
49
|
+
contractVersion: z.literal(CE_CONTRACT_VERSION),
|
|
50
|
+
serviceId: ServiceId,
|
|
51
|
+
instanceId: z.string().min(1),
|
|
52
|
+
tenant: z.string().default("default"),
|
|
53
|
+
address: z.string().url(),
|
|
54
|
+
version: z.string().min(1),
|
|
55
|
+
health: ServiceInstanceHealthSchema,
|
|
56
|
+
startedAt: z.string().optional(),
|
|
57
|
+
lastHeartbeatAt: z.string().optional()
|
|
58
|
+
});
|
|
59
|
+
var ConversationMessageSchema = z.object({
|
|
60
|
+
contractVersion: z.literal(CE_CONTRACT_VERSION),
|
|
61
|
+
messageId: z.string().min(1),
|
|
62
|
+
conversationId: z.string().min(1),
|
|
63
|
+
tenant: z.string().default("default"),
|
|
64
|
+
targetType: ConversationTargetTypeSchema,
|
|
65
|
+
targetId: z.string().min(1),
|
|
66
|
+
senderType: MessageSenderTypeSchema,
|
|
67
|
+
senderId: z.string().min(1),
|
|
68
|
+
messageType: MessageTypeSchema,
|
|
69
|
+
content: z.string(),
|
|
70
|
+
payload: Json.optional(),
|
|
71
|
+
replyToMessageId: z.string().optional(),
|
|
72
|
+
idempotencyKey: z.string().optional(),
|
|
73
|
+
metadata: Json.optional()
|
|
74
|
+
});
|
|
75
|
+
var AgentHeartbeatSchema = z.object({
|
|
76
|
+
contractVersion: z.literal(CE_CONTRACT_VERSION),
|
|
77
|
+
serviceId: ServiceId,
|
|
78
|
+
instanceId: z.string().min(1),
|
|
79
|
+
tenant: z.string().default("default"),
|
|
80
|
+
ts: z.string(),
|
|
81
|
+
health: ServiceInstanceHealthSchema,
|
|
82
|
+
metricsSummary: Json.optional()
|
|
83
|
+
});
|
|
84
|
+
var CeErrorCode = {
|
|
85
|
+
CONTRACT_VERSION_MISMATCH: "CONTRACT_VERSION_MISMATCH",
|
|
86
|
+
UNKNOWN_INSTANCE: "UNKNOWN_INSTANCE",
|
|
87
|
+
NO_HEALTHY_INSTANCE: "NO_HEALTHY_INSTANCE",
|
|
88
|
+
TARGET_OFFLINE: "TARGET_OFFLINE",
|
|
89
|
+
VALIDATION_FAILED: "VALIDATION_FAILED",
|
|
90
|
+
INTERNAL_ERROR: "INTERNAL_ERROR"
|
|
91
|
+
};
|
|
92
|
+
var ErrorModelSchema = z.object({
|
|
93
|
+
code: z.string().min(1),
|
|
94
|
+
message: z.string(),
|
|
95
|
+
retryable: z.boolean()
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// src/index.ts
|
|
3
99
|
var AgentStatus = ["PENDING", "ONLINE", "OFFLINE", "DISABLED", "REVOKED"];
|
|
4
100
|
var CapsuleServiceStatus = ["UNKNOWN", "HEALTHY", "UNHEALTHY", "STALE", "OFFLINE"];
|
|
101
|
+
var WorkerStatus = CapsuleServiceStatus;
|
|
5
102
|
var HealthStatus = ["UP", "DEGRADED", "DOWN", "UNKNOWN"];
|
|
6
103
|
var CommandStatus = ["PENDING", "RUNNING", "SUCCEEDED", "FAILED", "EXPIRED", "CANCELLED"];
|
|
7
104
|
var DangerLevel = ["LOW", "MEDIUM", "HIGH"];
|
|
@@ -10,144 +107,163 @@ var AuditResult = ["SUCCESS", "FAILURE"];
|
|
|
10
107
|
var TokenStatus = ["ACTIVE", "REVOKED", "EXPIRED", "USED"];
|
|
11
108
|
var AgentMode = ["embedded", "ophub"];
|
|
12
109
|
var ServiceKind = ["business", "infrastructure", "system"];
|
|
13
|
-
var ServiceKindSchema =
|
|
14
|
-
var AnyJson =
|
|
15
|
-
var AgentStatusSchema =
|
|
16
|
-
var CapsuleServiceStatusSchema =
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
110
|
+
var ServiceKindSchema = z2.enum(ServiceKind);
|
|
111
|
+
var AnyJson = z2.record(z2.any());
|
|
112
|
+
var AgentStatusSchema = z2.enum(AgentStatus);
|
|
113
|
+
var CapsuleServiceStatusSchema = z2.enum(CapsuleServiceStatus);
|
|
114
|
+
var WorkerStatusSchema = CapsuleServiceStatusSchema;
|
|
115
|
+
var HealthStatusSchema = z2.enum(HealthStatus);
|
|
116
|
+
var CommandStatusSchema = z2.enum(CommandStatus);
|
|
117
|
+
var DangerLevelSchema = z2.enum(DangerLevel).default("LOW");
|
|
118
|
+
var AgentModeSchema = z2.enum(AgentMode);
|
|
119
|
+
var UserSchema = z2.object({ id: z2.string().startsWith("usr_"), username: z2.string(), displayName: z2.string().nullable().optional(), createdAt: z2.string(), updatedAt: z2.string() });
|
|
120
|
+
var UserRole = z2.enum(["owner", "operator", "viewer"]);
|
|
121
|
+
var createUserRequestSchema = z2.object({ username: z2.string().min(1), password: z2.string().min(12), displayName: z2.string().optional(), role: UserRole.default("viewer") });
|
|
122
|
+
var updateUserRequestSchema = z2.object({ displayName: z2.string().optional(), role: UserRole.optional(), status: z2.enum(["ACTIVE", "DISABLED"]).optional() });
|
|
123
|
+
var resetUserPasswordRequestSchema = z2.object({ password: z2.string().min(12) });
|
|
124
|
+
var AdminLoginRequestSchema = z2.object({ username: z2.string().min(1), password: z2.string().min(1) });
|
|
27
125
|
var adminLoginRequestSchema = AdminLoginRequestSchema;
|
|
28
|
-
var AdminSessionSchema =
|
|
29
|
-
var AgentSchema =
|
|
30
|
-
var RegistrationTokenSchema =
|
|
31
|
-
var CreateRegistrationTokenRequestSchema =
|
|
126
|
+
var AdminSessionSchema = z2.object({ user: UserSchema, csrfToken: z2.string(), expiresAt: z2.string() });
|
|
127
|
+
var AgentSchema = z2.object({ id: z2.string().startsWith("agt_"), code: z2.string(), name: z2.string().nullable().optional(), mode: AgentModeSchema, runtime: z2.string().nullable().optional(), status: AgentStatusSchema, lastHeartbeatAt: z2.string().nullable().optional(), createdAt: z2.string(), updatedAt: z2.string() });
|
|
128
|
+
var RegistrationTokenSchema = z2.object({ id: z2.string().startsWith("tok_"), name: z2.string(), status: z2.enum(TokenStatus), expiresAt: z2.string().nullable().optional(), usedAt: z2.string().nullable().optional(), createdAt: z2.string() });
|
|
129
|
+
var CreateRegistrationTokenRequestSchema = z2.object({ name: z2.string().default("Default registration token").optional(), expiresInSeconds: z2.number().int().min(60).optional() });
|
|
32
130
|
var createRegistrationTokenRequestSchema = CreateRegistrationTokenRequestSchema;
|
|
33
|
-
var CreateRegistrationTokenResponseSchema = RegistrationTokenSchema.extend({ rawToken:
|
|
34
|
-
var ServiceCapabilitySchema =
|
|
131
|
+
var CreateRegistrationTokenResponseSchema = RegistrationTokenSchema.extend({ rawToken: z2.string().startsWith("opstage_reg_") });
|
|
132
|
+
var ServiceCapabilitySchema = z2.object({ name: z2.string().min(1).max(120), label: z2.string().max(200).optional(), description: z2.string().max(2e3).optional(), metadata: AnyJson.optional() });
|
|
35
133
|
var serviceCapabilitySchema = ServiceCapabilitySchema;
|
|
36
|
-
var EventMetadataSchema =
|
|
134
|
+
var EventMetadataSchema = z2.object({ name: z2.string().min(1).max(160), direction: z2.enum(["publish", "subscribe"]).optional(), schema: AnyJson.optional(), designOnly: z2.boolean().default(true), metadata: AnyJson.optional() });
|
|
37
135
|
var eventMetadataSchema = EventMetadataSchema;
|
|
38
|
-
var CapsuleManifestSchema =
|
|
39
|
-
var
|
|
136
|
+
var CapsuleManifestSchema = z2.object({ kind: z2.literal("CapsuleService"), schemaVersion: z2.string().default("1.0").optional(), code: z2.string().min(1), name: z2.string().min(1), description: z2.string().optional(), version: z2.string().min(1), runtime: z2.enum(["nodejs", "java", "python", "go", "other"]), agentMode: AgentModeSchema, capabilities: z2.array(z2.union([z2.string(), ServiceCapabilitySchema])).optional(), events: z2.array(EventMetadataSchema).optional(), labels: z2.record(z2.string()).optional() }).passthrough();
|
|
137
|
+
var WorkerManifestSchema = CapsuleManifestSchema.extend({
|
|
138
|
+
kind: z2.enum(["Worker", "CapsuleService"]).default("Worker")
|
|
139
|
+
});
|
|
140
|
+
var workerManifestSchema = WorkerManifestSchema;
|
|
141
|
+
var HealthReportInputSchema = z2.object({ status: HealthStatusSchema, message: z2.string().optional(), details: AnyJson.optional() });
|
|
40
142
|
var healthReportInputSchema = HealthReportInputSchema;
|
|
41
|
-
var ConfigItemInputSchema =
|
|
143
|
+
var ConfigItemInputSchema = z2.object({ key: z2.string(), label: z2.string().optional(), type: z2.string(), source: z2.string().optional(), editable: z2.boolean().optional(), sensitive: z2.boolean().optional(), valuePreview: z2.string().optional(), defaultValue: z2.string().optional(), secretRef: z2.string().optional() });
|
|
42
144
|
var configItemInputSchema = ConfigItemInputSchema;
|
|
43
|
-
var ActionDefinitionInputSchema =
|
|
145
|
+
var ActionDefinitionInputSchema = z2.object({ name: z2.string(), label: z2.string(), description: z2.string().optional(), dangerLevel: z2.enum(DangerLevel).default("LOW").optional(), requiresConfirmation: z2.boolean().optional(), category: z2.string().optional(), order: z2.number().int().optional(), inputSchema: AnyJson.optional(), outputSchema: AnyJson.optional(), timeoutSeconds: z2.number().int().positive().optional() });
|
|
44
146
|
var actionDefinitionInputSchema = ActionDefinitionInputSchema;
|
|
45
|
-
var ReportedServiceSchema =
|
|
46
|
-
code:
|
|
47
|
-
name:
|
|
48
|
-
description:
|
|
49
|
-
version:
|
|
50
|
-
runtime:
|
|
147
|
+
var ReportedServiceSchema = z2.object({
|
|
148
|
+
code: z2.string().min(1).max(80),
|
|
149
|
+
name: z2.string().min(1).max(200),
|
|
150
|
+
description: z2.string().max(2e3).optional(),
|
|
151
|
+
version: z2.string().max(80).optional(),
|
|
152
|
+
runtime: z2.string().optional(),
|
|
51
153
|
manifest: AnyJson,
|
|
52
|
-
capabilities:
|
|
53
|
-
events:
|
|
154
|
+
capabilities: z2.array(ServiceCapabilitySchema).optional(),
|
|
155
|
+
events: z2.array(EventMetadataSchema).optional(),
|
|
54
156
|
health: HealthReportInputSchema.optional(),
|
|
55
|
-
configs:
|
|
56
|
-
actions:
|
|
157
|
+
configs: z2.array(ConfigItemInputSchema).optional(),
|
|
158
|
+
actions: z2.array(ActionDefinitionInputSchema).optional(),
|
|
57
159
|
serviceKind: ServiceKindSchema.optional()
|
|
58
160
|
});
|
|
59
161
|
var reportedServiceSchema = ReportedServiceSchema;
|
|
60
|
-
var
|
|
162
|
+
var ReportedWorkerSchema = ReportedServiceSchema;
|
|
163
|
+
var reportedWorkerSchema = ReportedWorkerSchema;
|
|
164
|
+
var WorkerRuntimeReportSchema = ReportedWorkerSchema;
|
|
165
|
+
var workerRuntimeReportSchema = WorkerRuntimeReportSchema;
|
|
166
|
+
var ServiceReportRequestSchema = z2.object({ services: z2.array(ReportedServiceSchema).min(1) });
|
|
61
167
|
var serviceReportRequestSchema = ServiceReportRequestSchema;
|
|
62
|
-
var
|
|
63
|
-
var
|
|
168
|
+
var WorkerReportRequestSchema = z2.object({ workers: z2.array(ReportedWorkerSchema).min(1) });
|
|
169
|
+
var workerReportRequestSchema = WorkerReportRequestSchema;
|
|
170
|
+
var RuntimeKindSchema = z2.enum(["nodejs", "java", "python", "go", "other"]);
|
|
171
|
+
var RegisterAgentRequestSchema = z2.object({ registrationToken: z2.string().startsWith("opstage_reg_"), agent: z2.object({ code: z2.string(), name: z2.string().optional(), mode: AgentModeSchema.default("embedded"), runtime: RuntimeKindSchema.or(z2.string()).optional() }), service: ReportedServiceSchema.optional() });
|
|
64
172
|
var registerAgentRequestSchema = RegisterAgentRequestSchema;
|
|
65
|
-
var RegisterAgentResponseSchema =
|
|
66
|
-
var AgentHeartbeatResponseSchema =
|
|
67
|
-
var AgentHeartbeatRequestSchema =
|
|
173
|
+
var RegisterAgentResponseSchema = z2.object({ agentId: z2.string().startsWith("agt_"), agentToken: z2.string().startsWith("opstage_agent_"), heartbeatIntervalSeconds: z2.number().int(), commandPollIntervalSeconds: z2.number().int() });
|
|
174
|
+
var AgentHeartbeatResponseSchema = z2.object({ heartbeatIntervalSeconds: z2.number().int(), commandPollIntervalSeconds: z2.number().int() });
|
|
175
|
+
var AgentHeartbeatRequestSchema = z2.object({ serviceId: z2.string().startsWith("svc_").optional(), health: HealthReportInputSchema.optional() });
|
|
68
176
|
var agentHeartbeatRequestSchema = AgentHeartbeatRequestSchema;
|
|
69
|
-
var CapsuleServiceSchema =
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
var
|
|
73
|
-
var
|
|
74
|
-
var
|
|
177
|
+
var CapsuleServiceSchema = z2.object({ id: z2.string().startsWith("svc_"), agentId: z2.string().startsWith("agt_").optional(), code: z2.string(), name: z2.string(), description: z2.string().nullable().optional(), version: z2.string().nullable().optional(), runtime: z2.string().nullable().optional(), status: CapsuleServiceStatusSchema, healthStatus: HealthStatusSchema.optional(), lastReportedAt: z2.string().nullable().optional(), lastHealthAt: z2.string().nullable().optional(), createdAt: z2.string(), updatedAt: z2.string() });
|
|
178
|
+
var WorkerSchema = CapsuleServiceSchema;
|
|
179
|
+
var workerSchema = WorkerSchema;
|
|
180
|
+
var WorkerInstanceSchema = CapsuleServiceSchema;
|
|
181
|
+
var workerInstanceSchema = WorkerInstanceSchema;
|
|
182
|
+
var HealthReportSchema = z2.object({ id: z2.string().startsWith("hlr_"), serviceId: z2.string().startsWith("svc_"), agentId: z2.string().startsWith("agt_").optional(), status: HealthStatusSchema, message: z2.string().nullable().optional(), details: AnyJson.optional(), reportedAt: z2.string() });
|
|
183
|
+
var ConfigItemSchema = z2.object({ id: z2.string().startsWith("cfg_"), serviceId: z2.string().startsWith("svc_"), key: z2.string(), label: z2.string().nullable().optional(), type: z2.string(), source: z2.string().nullable().optional(), editable: z2.boolean().default(false), sensitive: z2.boolean(), valuePreview: z2.string().nullable().optional(), defaultValue: z2.string().nullable().optional(), secretRef: z2.string().nullable().optional() });
|
|
184
|
+
var ActionDefinitionSchema = z2.object({ id: z2.string().startsWith("act_"), serviceId: z2.string().startsWith("svc_"), name: z2.string(), label: z2.string(), description: z2.string().nullable().optional(), dangerLevel: z2.enum(DangerLevel), requiresConfirmation: z2.boolean(), category: z2.string().optional(), order: z2.number().int().optional(), inputSchema: AnyJson.optional(), outputSchema: AnyJson.optional(), timeoutSeconds: z2.number().int().optional() });
|
|
185
|
+
var CapsuleServiceDetailSchema = CapsuleServiceSchema.extend({ manifest: AnyJson.optional(), health: HealthReportSchema.nullable().optional(), configs: z2.array(ConfigItemSchema).optional(), actions: z2.array(ActionDefinitionSchema).optional() });
|
|
186
|
+
var WorkerDetailSchema = CapsuleServiceDetailSchema;
|
|
187
|
+
var workerDetailSchema = WorkerDetailSchema;
|
|
188
|
+
var WorkerInstanceDetailSchema = CapsuleServiceDetailSchema;
|
|
189
|
+
var workerInstanceDetailSchema = WorkerInstanceDetailSchema;
|
|
190
|
+
var ActionPrepareResultSchema = z2.object({
|
|
75
191
|
action: AnyJson.optional(),
|
|
76
192
|
inputSchema: AnyJson.optional(),
|
|
77
193
|
initialPayload: AnyJson.optional(),
|
|
78
194
|
currentState: AnyJson.optional()
|
|
79
195
|
});
|
|
80
196
|
var actionPrepareResultSchema = ActionPrepareResultSchema;
|
|
81
|
-
var CapsuleBusExperimentalSchema =
|
|
197
|
+
var CapsuleBusExperimentalSchema = z2.literal("v0.4-experimental");
|
|
82
198
|
var BusRouteStatus = ["ENABLED", "DISABLED", "DRY_RUN"];
|
|
83
|
-
var BusRouteStatusSchema =
|
|
84
|
-
var BusEventEnvelopeSchema =
|
|
85
|
-
id:
|
|
199
|
+
var BusRouteStatusSchema = z2.enum(BusRouteStatus);
|
|
200
|
+
var BusEventEnvelopeSchema = z2.object({
|
|
201
|
+
id: z2.string().startsWith("bev_").optional(),
|
|
86
202
|
experimental: CapsuleBusExperimentalSchema.default("v0.4-experimental"),
|
|
87
|
-
eventType:
|
|
88
|
-
sourceServiceCode:
|
|
89
|
-
sourceServiceId:
|
|
90
|
-
occurredAt:
|
|
91
|
-
correlationId:
|
|
92
|
-
causationId:
|
|
203
|
+
eventType: z2.string().min(1).max(160),
|
|
204
|
+
sourceServiceCode: z2.string().min(1).max(80),
|
|
205
|
+
sourceServiceId: z2.string().startsWith("svc_").optional(),
|
|
206
|
+
occurredAt: z2.string().datetime().optional(),
|
|
207
|
+
correlationId: z2.string().min(1).max(160).optional(),
|
|
208
|
+
causationId: z2.string().min(1).max(160).optional(),
|
|
93
209
|
payload: AnyJson.default({}).optional(),
|
|
94
210
|
metadata: AnyJson.default({}).optional()
|
|
95
211
|
});
|
|
96
212
|
var PublishBusEventRequestSchema = BusEventEnvelopeSchema.omit({ id: true }).extend({
|
|
97
|
-
routePolicy:
|
|
213
|
+
routePolicy: z2.object({ dryRun: z2.boolean().optional() }).optional()
|
|
98
214
|
});
|
|
99
|
-
var BusRouteRuleSchema =
|
|
100
|
-
id:
|
|
101
|
-
name:
|
|
102
|
-
description:
|
|
215
|
+
var BusRouteRuleSchema = z2.object({
|
|
216
|
+
id: z2.string().startsWith("brt_").optional(),
|
|
217
|
+
name: z2.string().min(1).max(160),
|
|
218
|
+
description: z2.string().max(1e3).optional(),
|
|
103
219
|
status: BusRouteStatusSchema.optional().default("DISABLED"),
|
|
104
|
-
match:
|
|
105
|
-
eventType:
|
|
106
|
-
sourceServiceCode:
|
|
220
|
+
match: z2.object({
|
|
221
|
+
eventType: z2.string().min(1).max(160),
|
|
222
|
+
sourceServiceCode: z2.string().min(1).max(80).optional()
|
|
107
223
|
}),
|
|
108
|
-
target:
|
|
109
|
-
serviceCode:
|
|
110
|
-
actionName:
|
|
224
|
+
target: z2.object({
|
|
225
|
+
serviceCode: z2.string().min(1).max(80),
|
|
226
|
+
actionName: z2.string().min(1).max(128)
|
|
111
227
|
}),
|
|
112
228
|
inputMapping: AnyJson.default({}).optional(),
|
|
113
229
|
metadata: AnyJson.default({}).optional()
|
|
114
230
|
});
|
|
115
231
|
var CreateBusRouteRuleRequestSchema = BusRouteRuleSchema.omit({ id: true });
|
|
116
|
-
var BusCommandRequestSchema =
|
|
117
|
-
commandId:
|
|
118
|
-
commandType:
|
|
119
|
-
targetService:
|
|
120
|
-
actionName:
|
|
121
|
-
sourceEventId:
|
|
232
|
+
var BusCommandRequestSchema = z2.object({
|
|
233
|
+
commandId: z2.string().startsWith("cmd_").optional(),
|
|
234
|
+
commandType: z2.literal("ACTION_EXECUTE").default("ACTION_EXECUTE"),
|
|
235
|
+
targetService: z2.string().min(1).max(80),
|
|
236
|
+
actionName: z2.string().min(1).max(128),
|
|
237
|
+
sourceEventId: z2.string().startsWith("bev_").optional(),
|
|
122
238
|
payload: AnyJson.default({}).optional(),
|
|
123
|
-
metadata:
|
|
124
|
-
routingRuleId:
|
|
125
|
-
correlationId:
|
|
126
|
-
}).catchall(
|
|
239
|
+
metadata: z2.object({
|
|
240
|
+
routingRuleId: z2.string().startsWith("brt_").optional(),
|
|
241
|
+
correlationId: z2.string().min(1).max(160).optional()
|
|
242
|
+
}).catchall(z2.any()).optional()
|
|
127
243
|
});
|
|
128
244
|
var busCommandRequestSchema = BusCommandRequestSchema;
|
|
129
245
|
var BusRoutingRuleSchema = BusRouteRuleSchema;
|
|
130
246
|
var busRoutingRuleSchema = BusRoutingRuleSchema;
|
|
131
|
-
var BusRoutedCommandSchema =
|
|
132
|
-
routeId:
|
|
133
|
-
commandId:
|
|
134
|
-
dryRun:
|
|
135
|
-
targetServiceCode:
|
|
136
|
-
actionName:
|
|
137
|
-
status:
|
|
138
|
-
errorCode:
|
|
139
|
-
errorMessage:
|
|
247
|
+
var BusRoutedCommandSchema = z2.object({
|
|
248
|
+
routeId: z2.string().startsWith("brt_"),
|
|
249
|
+
commandId: z2.string().startsWith("cmd_").optional(),
|
|
250
|
+
dryRun: z2.boolean(),
|
|
251
|
+
targetServiceCode: z2.string(),
|
|
252
|
+
actionName: z2.string(),
|
|
253
|
+
status: z2.enum(["CREATED", "DRY_RUN", "SKIPPED", "FAILED"]),
|
|
254
|
+
errorCode: z2.string().optional(),
|
|
255
|
+
errorMessage: z2.string().optional()
|
|
140
256
|
});
|
|
141
|
-
var PublishBusEventResponseSchema =
|
|
142
|
-
eventId:
|
|
257
|
+
var PublishBusEventResponseSchema = z2.object({
|
|
258
|
+
eventId: z2.string().startsWith("bev_"),
|
|
143
259
|
experimental: CapsuleBusExperimentalSchema,
|
|
144
|
-
routedCommands:
|
|
260
|
+
routedCommands: z2.array(BusRoutedCommandSchema)
|
|
145
261
|
});
|
|
146
262
|
var BusEventRecordSchema = BusEventEnvelopeSchema.extend({
|
|
147
|
-
id:
|
|
148
|
-
agentId:
|
|
149
|
-
acceptedAt:
|
|
150
|
-
routeCount:
|
|
263
|
+
id: z2.string().startsWith("bev_"),
|
|
264
|
+
agentId: z2.string().startsWith("agt_"),
|
|
265
|
+
acceptedAt: z2.string(),
|
|
266
|
+
routeCount: z2.number().int()
|
|
151
267
|
});
|
|
152
268
|
var BusErrorCode = {
|
|
153
269
|
CAPSULE_BUS_DISABLED: "CAPSULE_BUS_DISABLED",
|
|
@@ -159,19 +275,19 @@ var publishBusEventResponseSchema = PublishBusEventResponseSchema;
|
|
|
159
275
|
var busEventEnvelopeSchema = BusEventEnvelopeSchema;
|
|
160
276
|
var busRouteRuleSchema = BusRouteRuleSchema;
|
|
161
277
|
var createBusRouteRuleRequestSchema = CreateBusRouteRuleRequestSchema;
|
|
162
|
-
var CreateActionCommandRequestSchema =
|
|
278
|
+
var CreateActionCommandRequestSchema = z2.object({ payload: AnyJson.optional(), confirmation: z2.boolean().optional() });
|
|
163
279
|
var createActionCommandRequestSchema = CreateActionCommandRequestSchema;
|
|
164
|
-
var CommandTypeSchema =
|
|
165
|
-
var CommandSchema =
|
|
166
|
-
var ReportCommandResultRequestSchema =
|
|
280
|
+
var CommandTypeSchema = z2.enum(["ACTION_PREPARE", "ACTION_EXECUTE"]);
|
|
281
|
+
var CommandSchema = z2.object({ id: z2.string().startsWith("cmd_"), agentId: z2.string().startsWith("agt_"), serviceId: z2.string().startsWith("svc_"), type: CommandTypeSchema, actionName: z2.string(), status: CommandStatusSchema, payload: AnyJson.optional(), createdByUserId: z2.string().startsWith("usr_").nullable().optional(), createdAt: z2.string(), startedAt: z2.string().nullable().optional(), completedAt: z2.string().nullable().optional(), expiresAt: z2.string().nullable().optional() });
|
|
282
|
+
var ReportCommandResultRequestSchema = z2.object({ success: z2.boolean(), message: z2.string().optional(), data: AnyJson.optional(), error: AnyJson.optional(), startedAt: z2.string().optional(), finishedAt: z2.string().optional() });
|
|
167
283
|
var reportCommandResultRequestSchema = ReportCommandResultRequestSchema;
|
|
168
|
-
var CommandResultSchema =
|
|
284
|
+
var CommandResultSchema = z2.object({ id: z2.string().startsWith("crs_"), commandId: z2.string().startsWith("cmd_"), success: z2.boolean(), message: z2.string().nullable().optional(), data: AnyJson.optional(), error: AnyJson.optional(), reportedAt: z2.string() });
|
|
169
285
|
var CommandDetailSchema = CommandSchema.extend({ result: CommandResultSchema.nullable().optional() });
|
|
170
|
-
var AuditEventSchema =
|
|
171
|
-
var DashboardSummarySchema =
|
|
172
|
-
var SystemHealthSchema =
|
|
173
|
-
var SystemVersionSchema =
|
|
174
|
-
var ListQueryBase =
|
|
286
|
+
var AuditEventSchema = z2.object({ id: z2.string().startsWith("aud_"), actorType: z2.enum(AuditActorType), actorId: z2.string().nullable().optional(), action: z2.string(), targetType: z2.string().nullable().optional(), targetId: z2.string().nullable().optional(), result: z2.enum(AuditResult), message: z2.string().nullable().optional(), metadata: AnyJson.optional(), createdAt: z2.string() });
|
|
287
|
+
var DashboardSummarySchema = z2.object({ agentCounts: z2.record(z2.number().int()), serviceCounts: z2.record(z2.number().int()), commandCounts: z2.record(z2.number().int()), recentCommands: z2.array(CommandSchema).optional(), recentAuditEvents: z2.array(AuditEventSchema).optional() });
|
|
288
|
+
var SystemHealthSchema = z2.object({ status: z2.enum(["UP", "DEGRADED", "DOWN"]), timestamp: z2.string(), version: z2.string(), edition: z2.literal("ce"), database: z2.object({ status: z2.enum(["UP", "DEGRADED", "DOWN"]), kind: z2.enum(["sqlite", "postgres", "mysql"]).optional(), latencyMs: z2.number().int().optional() }), uptimeSeconds: z2.number().int().optional() });
|
|
289
|
+
var SystemVersionSchema = z2.object({ version: z2.string(), edition: z2.literal("ce"), commit: z2.string().optional(), buildTime: z2.string().optional() });
|
|
290
|
+
var ListQueryBase = z2.object({ page: z2.coerce.number().int().min(1).default(1), pageSize: z2.coerce.number().int().min(1).max(100).default(20), sort: z2.string().optional() });
|
|
175
291
|
var HttpError = class extends Error {
|
|
176
292
|
constructor(httpStatus, code, publicMessage, details) {
|
|
177
293
|
super(publicMessage);
|
|
@@ -210,7 +326,8 @@ var ErrorCode = {
|
|
|
210
326
|
TOKEN_REVOKED: "TOKEN_REVOKED",
|
|
211
327
|
TOKEN_EXPIRED: "TOKEN_EXPIRED",
|
|
212
328
|
AGENT_REVOKED: "AGENT_REVOKED",
|
|
213
|
-
AGENT_DISABLED: "AGENT_DISABLED"
|
|
329
|
+
AGENT_DISABLED: "AGENT_DISABLED",
|
|
330
|
+
CAPSULE_SERVICE_CODE_TAKEN: "CAPSULE_SERVICE_CODE_TAKEN"
|
|
214
331
|
};
|
|
215
332
|
export {
|
|
216
333
|
ActionDefinitionInputSchema,
|
|
@@ -220,6 +337,7 @@ export {
|
|
|
220
337
|
AdminSessionSchema,
|
|
221
338
|
AgentHeartbeatRequestSchema,
|
|
222
339
|
AgentHeartbeatResponseSchema,
|
|
340
|
+
AgentHeartbeatSchema,
|
|
223
341
|
AgentMode,
|
|
224
342
|
AgentModeSchema,
|
|
225
343
|
AgentSchema,
|
|
@@ -238,12 +356,14 @@ export {
|
|
|
238
356
|
BusRouteStatusSchema,
|
|
239
357
|
BusRoutedCommandSchema,
|
|
240
358
|
BusRoutingRuleSchema,
|
|
359
|
+
CE_CONTRACT_VERSION,
|
|
241
360
|
CapsuleBusExperimentalSchema,
|
|
242
361
|
CapsuleManifestSchema,
|
|
243
362
|
CapsuleServiceDetailSchema,
|
|
244
363
|
CapsuleServiceSchema,
|
|
245
364
|
CapsuleServiceStatus,
|
|
246
365
|
CapsuleServiceStatusSchema,
|
|
366
|
+
CeErrorCode,
|
|
247
367
|
CommandDetailSchema,
|
|
248
368
|
CommandResultSchema,
|
|
249
369
|
CommandSchema,
|
|
@@ -252,6 +372,9 @@ export {
|
|
|
252
372
|
CommandTypeSchema,
|
|
253
373
|
ConfigItemInputSchema,
|
|
254
374
|
ConfigItemSchema,
|
|
375
|
+
ConversationMessageSchema,
|
|
376
|
+
ConversationTargetType,
|
|
377
|
+
ConversationTargetTypeSchema,
|
|
255
378
|
CreateActionCommandRequestSchema,
|
|
256
379
|
CreateBusRouteRuleRequestSchema,
|
|
257
380
|
CreateRegistrationTokenRequestSchema,
|
|
@@ -260,6 +383,7 @@ export {
|
|
|
260
383
|
DangerLevelSchema,
|
|
261
384
|
DashboardSummarySchema,
|
|
262
385
|
ErrorCode,
|
|
386
|
+
ErrorModelSchema,
|
|
263
387
|
EventMetadataSchema,
|
|
264
388
|
HealthReportInputSchema,
|
|
265
389
|
HealthReportSchema,
|
|
@@ -267,6 +391,10 @@ export {
|
|
|
267
391
|
HealthStatusSchema,
|
|
268
392
|
HttpError,
|
|
269
393
|
ListQueryBase,
|
|
394
|
+
MessageSenderType,
|
|
395
|
+
MessageSenderTypeSchema,
|
|
396
|
+
MessageType,
|
|
397
|
+
MessageTypeSchema,
|
|
270
398
|
PublishBusEventRequestSchema,
|
|
271
399
|
PublishBusEventResponseSchema,
|
|
272
400
|
RegisterAgentRequestSchema,
|
|
@@ -274,16 +402,30 @@ export {
|
|
|
274
402
|
RegistrationTokenSchema,
|
|
275
403
|
ReportCommandResultRequestSchema,
|
|
276
404
|
ReportedServiceSchema,
|
|
405
|
+
ReportedWorkerSchema,
|
|
277
406
|
RuntimeKindSchema,
|
|
278
407
|
ServiceCapabilitySchema,
|
|
408
|
+
ServiceInstanceHealth,
|
|
409
|
+
ServiceInstanceHealthSchema,
|
|
410
|
+
ServiceInstanceSchema,
|
|
279
411
|
ServiceKind,
|
|
280
412
|
ServiceKindSchema,
|
|
413
|
+
ServiceManifestSchema,
|
|
281
414
|
ServiceReportRequestSchema,
|
|
282
415
|
SystemHealthSchema,
|
|
283
416
|
SystemVersionSchema,
|
|
284
417
|
TokenStatus,
|
|
285
418
|
UserRole,
|
|
286
419
|
UserSchema,
|
|
420
|
+
WorkerDetailSchema,
|
|
421
|
+
WorkerInstanceDetailSchema,
|
|
422
|
+
WorkerInstanceSchema,
|
|
423
|
+
WorkerManifestSchema,
|
|
424
|
+
WorkerReportRequestSchema,
|
|
425
|
+
WorkerRuntimeReportSchema,
|
|
426
|
+
WorkerSchema,
|
|
427
|
+
WorkerStatus,
|
|
428
|
+
WorkerStatusSchema,
|
|
287
429
|
actionDefinitionInputSchema,
|
|
288
430
|
actionPrepareResultSchema,
|
|
289
431
|
adminLoginRequestSchema,
|
|
@@ -306,9 +448,17 @@ export {
|
|
|
306
448
|
registerAgentRequestSchema,
|
|
307
449
|
reportCommandResultRequestSchema,
|
|
308
450
|
reportedServiceSchema,
|
|
451
|
+
reportedWorkerSchema,
|
|
309
452
|
resetUserPasswordRequestSchema,
|
|
310
453
|
serviceCapabilitySchema,
|
|
311
454
|
serviceReportRequestSchema,
|
|
312
455
|
updateUserRequestSchema,
|
|
313
|
-
|
|
456
|
+
workerDetailSchema,
|
|
457
|
+
workerInstanceDetailSchema,
|
|
458
|
+
workerInstanceSchema,
|
|
459
|
+
workerManifestSchema,
|
|
460
|
+
workerReportRequestSchema,
|
|
461
|
+
workerRuntimeReportSchema,
|
|
462
|
+
workerSchema,
|
|
463
|
+
z2 as z
|
|
314
464
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xtrape/capsule-contracts-node",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "TypeScript contracts and Zod schemas for Xtrape
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "TypeScript contracts and Zod schemas for Xtrape Agent, Worker, and Panel wire protocols.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xtrape",
|
|
7
|
-
"
|
|
7
|
+
"worker",
|
|
8
|
+
"panel",
|
|
8
9
|
"opstage",
|
|
9
10
|
"contracts",
|
|
10
11
|
"zod",
|
package/spec/.source
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
xtrape-
|
|
1
|
+
xtrape-contracts-nodejs@local-authority
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"name": "service.reported",
|
|
100
100
|
"actorType": "AGENT",
|
|
101
101
|
"targetType": "CapsuleService",
|
|
102
|
-
"summary": "Agent reported
|
|
102
|
+
"summary": "Agent reported or updated a Worker Runtime Report; action name is retained for compatibility."
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
105
|
"name": "service.retired",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"name": "service.action.requested",
|
|
112
112
|
"actorType": "USER",
|
|
113
113
|
"targetType": "CapsuleService",
|
|
114
|
-
"summary": "Admin requested
|
|
114
|
+
"summary": "Admin requested a Worker Action; backend created a Command."
|
|
115
115
|
},
|
|
116
116
|
{
|
|
117
117
|
"name": "command.created",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
{ "prefix": "agt", "type": "Agent", "comment": "Agent identity." },
|
|
17
17
|
{ "prefix": "tok", "type": "RegistrationToken", "comment": "Registration token (the row; the raw token value is generated separately via newToken('reg'))." },
|
|
18
18
|
{ "prefix": "atk", "type": "AgentToken", "comment": "Agent token (the row; raw token via newToken('agt'))." },
|
|
19
|
-
{ "prefix": "svc", "type": "CapsuleService", "comment": "
|
|
19
|
+
{ "prefix": "svc", "type": "CapsuleService", "comment": "Worker Instance reported by an Agent; persisted type name retained for compatibility." },
|
|
20
20
|
{ "prefix": "act", "type": "ActionDefinition", "comment": "Action declared on a service manifest." },
|
|
21
21
|
{ "prefix": "cmd", "type": "Command", "comment": "Command for an Agent to execute." },
|
|
22
22
|
{ "prefix": "res", "type": "CommandResult", "comment": "Optional separate row for command results; CE v0.1 may inline into Command." },
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
]
|
|
22
22
|
},
|
|
23
23
|
"CapsuleServiceStatus": {
|
|
24
|
-
"description": "Effective lifecycle state of a
|
|
24
|
+
"description": "Effective lifecycle state of a Worker Instance. The schema name is retained for wire compatibility.",
|
|
25
25
|
"values": [
|
|
26
26
|
{ "value": "PENDING", "meaning": "Service was reported by an Agent but has not yet sent a health report." },
|
|
27
27
|
{ "value": "UP", "meaning": "Service has reported a healthy status within freshness threshold." },
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"AgentMode": {
|
|
120
120
|
"description": "Deployment mode of an Agent.",
|
|
121
121
|
"values": [
|
|
122
|
-
{ "value": "embedded", "meaning": "Agent runs in-process inside a
|
|
122
|
+
{ "value": "embedded", "meaning": "Agent runs in-process inside a Worker (CE v0.1 baseline)." },
|
|
123
123
|
{ "value": "sidecar", "meaning": "Agent runs as a separate process beside services. Reserved for EE.", "reservedFor": "EE" },
|
|
124
124
|
{ "value": "external", "meaning": "Agent runs as a separate fleet manager. Reserved for EE/Cloud.", "reservedFor": "EE" }
|
|
125
125
|
]
|
package/spec/errors.json
CHANGED
|
@@ -76,12 +76,12 @@
|
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
78
|
"name": "capsuleService",
|
|
79
|
-
"title": "
|
|
79
|
+
"title": "Worker compatibility codes",
|
|
80
80
|
"codes": [
|
|
81
81
|
{ "code": "CAPSULE_SERVICE_NOT_FOUND", "httpStatus": 404, "meaning": "serviceId does not exist." },
|
|
82
82
|
{ "code": "CAPSULE_SERVICE_NOT_OWNED", "httpStatus": 403, "meaning": "Service exists but does not belong to the calling Agent." },
|
|
83
83
|
{ "code": "CAPSULE_SERVICE_MANIFEST_INVALID", "httpStatus": 422, "meaning": "Manifest validation failed (missing required fields, etc.)." },
|
|
84
|
-
{ "code": "CAPSULE_SERVICE_CODE_TAKEN", "httpStatus": 409, "meaning": "
|
|
84
|
+
{ "code": "CAPSULE_SERVICE_CODE_TAKEN", "httpStatus": 409, "meaning": "Worker code is already owned in the workspace; code name is retained for compatibility." }
|
|
85
85
|
]
|
|
86
86
|
},
|
|
87
87
|
{
|
package/spec/errors.md
CHANGED