@agent-vm/gateway-control-contracts 0.0.114 → 0.0.115

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/dist/index.js CHANGED
@@ -1,5 +1,403 @@
1
+ import { GatewayRuntimeFrameworkIdentitySchema, GatewayRuntimeFrameworkKindSchema, GatewayRuntimeTrustedInvocationContextSchema, GatewayRuntimeTrustedInvocationCorrelationSchema, GatewayRuntimeTrustedInvocationPrincipalSchema, GatewayRuntimeTrustedInvocationPrincipalSchema as GatewayRuntimeTrustedInvocationPrincipalSchema$1, GatewayRuntimeTrustedInvocationRequesterSchema, GatewayStablePrincipalDigestSchema, ManagedAgentProjectionSchema, ManagedAgentProjectionSchema as ManagedAgentProjectionSchema$1 } from "@agent-vm/agent-portal-sdk/contracts";
1
2
  import { CONTROL_PROTOCOL_VERSION, ControlCorrelationSchema, ControlRpcErrorSchema, ControlRpcResultBaseSchema, ControlSessionStateSchema, KnownControlDomainSchema } from "@agent-vm/control-protocol-contracts";
2
3
  import { z } from "zod/v4";
4
+ import { Buffer } from "node:buffer";
5
+ import { createHash } from "node:crypto";
6
+ import { jsonObjectSchema, mcpConfigSchema, toolPortalBackendKindSchema, toolPortalConfigSchema } from "@agent-vm/config-contracts";
7
+ //#region src/gateway-control-principal.ts
8
+ function lengthPrefixedUtf8(value) {
9
+ return `${Buffer.byteLength(value, "utf8")}:${value}`;
10
+ }
11
+ function canonicalStablePrincipalMaterial(principal) {
12
+ const frameworkIdentityValue = principal.frameworkIdentity.kind === "openclaw" ? principal.frameworkIdentity.agentId : principal.frameworkIdentity.profileName;
13
+ return [
14
+ principal.agentId,
15
+ principal.frameworkIdentity.kind,
16
+ frameworkIdentityValue,
17
+ principal.toolPortalProfileId,
18
+ principal.profileAssignmentRevision
19
+ ].map(lengthPrefixedUtf8).join("");
20
+ }
21
+ function deriveGatewayControlStablePrincipal(options) {
22
+ return GatewayStablePrincipalDigestSchema.parse(createHash("sha256").update("agent-vm-gateway-stable-principal-v4", "utf8").update("\0").update(canonicalStablePrincipalMaterial(options.principal), "utf8").digest("hex"));
23
+ }
24
+ //#endregion
25
+ //#region src/gateway-runtime-portal-context.ts
26
+ const GatewayRuntimePortalSurfaceClassSchema = z.enum(["mcp", "protected_uds"]);
27
+ const GatewayRuntimePortalSemanticSnapshotSchema = z.object({
28
+ activeRevision: z.string().min(1),
29
+ agentProjections: z.record(z.string().min(1), ManagedAgentProjectionSchema$1),
30
+ bindingRevision: z.string().min(1),
31
+ catalogRevision: z.string().min(1),
32
+ desiredRevision: z.string().min(1),
33
+ profilePolicyRevision: z.string().min(1),
34
+ projectionCohortDigest: z.string().regex(/^projection-cohort:[a-f0-9]{64}$/u),
35
+ providerRevision: z.string().min(1),
36
+ schemaRevision: z.string().min(1),
37
+ schemaVersion: z.literal(1),
38
+ surfaceEligibilityByProfile: z.record(z.string().min(1), z.record(z.string().min(1), z.array(GatewayRuntimePortalSurfaceClassSchema).min(1)))
39
+ }).strict();
40
+ //#endregion
41
+ //#region src/gateway-runtime-approval.ts
42
+ const GATEWAY_RUNTIME_APPROVAL_AUDIENCE = "agent-vm-controller-approval";
43
+ const GatewayRuntimeApprovalFingerprintSchema = z.string().regex(/^sha256:[a-f0-9]{64}$/u);
44
+ function canonicalApprovalJson(value) {
45
+ if (value === null || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
46
+ if (typeof value === "number") {
47
+ if (!Number.isFinite(value)) throw new TypeError("Approval fingerprint values must be finite.");
48
+ return JSON.stringify(value);
49
+ }
50
+ if (Array.isArray(value)) return `[${value.map((item) => canonicalApprovalJson(item)).join(",")}]`;
51
+ if (typeof value === "object") return `{${Object.entries(value).filter(([, fieldValue]) => fieldValue !== void 0).toSorted(([leftName], [rightName]) => leftName.localeCompare(rightName)).map(([fieldName, fieldValue]) => `${JSON.stringify(fieldName)}:${canonicalApprovalJson(fieldValue)}`).join(",")}}`;
52
+ throw new TypeError("Approval fingerprint values must be JSON-compatible.");
53
+ }
54
+ const GatewayRuntimeApprovalAuthorityContextSchema = z.object({
55
+ controllerEpoch: z.string().min(1),
56
+ frameworkEpoch: z.string().min(1),
57
+ gatewayEpoch: z.string().min(1),
58
+ runtimeEpoch: z.string().min(1),
59
+ zoneId: z.string().min(1)
60
+ }).strict();
61
+ const GatewayRuntimeApprovalSemanticRevisionCohortSchema = z.object({
62
+ activeRevision: z.string().min(1),
63
+ bindingRevision: z.string().min(1),
64
+ catalogRevision: z.string().min(1),
65
+ profilePolicyRevision: z.string().min(1),
66
+ providerRevision: z.string().min(1),
67
+ schemaRevision: z.string().min(1)
68
+ }).strict();
69
+ const GatewayRuntimeApprovalCallSchema = z.object({
70
+ arguments: jsonObjectSchema,
71
+ id: z.string().min(1),
72
+ name: z.string().min(1),
73
+ namespace: z.string().min(1)
74
+ }).strict();
75
+ const GatewayRuntimeApprovalChallengeIntentSchema = z.object({
76
+ backendKind: toolPortalBackendKindSchema,
77
+ call: GatewayRuntimeApprovalCallSchema,
78
+ operationId: z.string().uuid(),
79
+ semanticRevisions: GatewayRuntimeApprovalSemanticRevisionCohortSchema,
80
+ surfaceClass: GatewayRuntimePortalSurfaceClassSchema,
81
+ trustedContext: GatewayRuntimeTrustedInvocationContextSchema
82
+ }).strict();
83
+ const GatewayRuntimeApprovalChallengeSchema = z.object({
84
+ approvalId: z.string().uuid(),
85
+ createdAt: z.string().datetime(),
86
+ expiresAt: z.string().datetime(),
87
+ fingerprint: GatewayRuntimeApprovalFingerprintSchema,
88
+ intent: GatewayRuntimeApprovalChallengeIntentSchema
89
+ }).strict();
90
+ const approvalDispatchAuthorityShape = {
91
+ approvalId: z.string().uuid(),
92
+ authorityContext: GatewayRuntimeApprovalAuthorityContextSchema,
93
+ expiresAt: z.string().datetime(),
94
+ fingerprint: GatewayRuntimeApprovalFingerprintSchema,
95
+ operationId: z.string().uuid(),
96
+ stablePrincipal: GatewayStablePrincipalDigestSchema
97
+ };
98
+ const GatewayRuntimeMcpProviderDispatchReservationSchema = z.object({
99
+ ...approvalDispatchAuthorityShape,
100
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.mcp_provider),
101
+ reservationId: z.string().uuid()
102
+ }).strict();
103
+ const GatewayRuntimeControllerHostActionDispatchReservationSchema = z.object({
104
+ ...approvalDispatchAuthorityShape,
105
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.controller_host_action),
106
+ reservationId: z.string().uuid()
107
+ }).strict();
108
+ const GatewayRuntimeToolVmRunnerDispatchReservationSchema = z.object({
109
+ ...approvalDispatchAuthorityShape,
110
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.tool_vm_runner),
111
+ reservationId: z.string().uuid()
112
+ }).strict();
113
+ const GatewayRuntimeApprovalDispatchReservationSchema = z.discriminatedUnion("backendKind", [
114
+ GatewayRuntimeMcpProviderDispatchReservationSchema,
115
+ GatewayRuntimeControllerHostActionDispatchReservationSchema,
116
+ GatewayRuntimeToolVmRunnerDispatchReservationSchema
117
+ ]);
118
+ const GatewayRuntimeGatewayDispatchReservationSchema = z.discriminatedUnion("backendKind", [GatewayRuntimeMcpProviderDispatchReservationSchema, GatewayRuntimeToolVmRunnerDispatchReservationSchema]);
119
+ const GatewayRuntimeMcpProviderDispatchGrantSchema = z.object({
120
+ ...approvalDispatchAuthorityShape,
121
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.mcp_provider),
122
+ grantId: z.string().uuid()
123
+ }).strict();
124
+ const GatewayRuntimeToolVmRunnerDispatchGrantSchema = z.object({
125
+ ...approvalDispatchAuthorityShape,
126
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.tool_vm_runner),
127
+ grantId: z.string().uuid()
128
+ }).strict();
129
+ const GatewayRuntimeApprovalDispatchGrantSchema = z.discriminatedUnion("backendKind", [GatewayRuntimeMcpProviderDispatchGrantSchema, GatewayRuntimeToolVmRunnerDispatchGrantSchema]);
130
+ const directDispatchAuthorityShape = {
131
+ fingerprint: GatewayRuntimeApprovalFingerprintSchema,
132
+ kind: z.literal("without-approval"),
133
+ operationId: z.string().uuid()
134
+ };
135
+ const GatewayRuntimeMcpProviderDirectDispatchAuthoritySchema = z.object({
136
+ ...directDispatchAuthorityShape,
137
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.mcp_provider)
138
+ }).strict();
139
+ const GatewayRuntimeToolVmRunnerDirectDispatchAuthoritySchema = z.object({
140
+ ...directDispatchAuthorityShape,
141
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.tool_vm_runner)
142
+ }).strict();
143
+ const GatewayRuntimeControllerHostActionDirectDispatchAuthoritySchema = z.object({
144
+ ...directDispatchAuthorityShape,
145
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.controller_host_action)
146
+ }).strict();
147
+ const GatewayRuntimeMcpProviderApprovalGrantDispatchAuthoritySchema = z.object({
148
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.mcp_provider),
149
+ grant: GatewayRuntimeMcpProviderDispatchGrantSchema,
150
+ kind: z.literal("approval-grant")
151
+ }).strict();
152
+ const GatewayRuntimeToolVmRunnerApprovalGrantDispatchAuthoritySchema = z.object({
153
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.tool_vm_runner),
154
+ grant: GatewayRuntimeToolVmRunnerDispatchGrantSchema,
155
+ kind: z.literal("approval-grant")
156
+ }).strict();
157
+ const GatewayRuntimeControllerHostActionApprovalReservationDispatchAuthoritySchema = z.object({
158
+ backendKind: z.literal(toolPortalBackendKindSchema.enum.controller_host_action),
159
+ kind: z.literal("controller-approval-reservation"),
160
+ reservation: GatewayRuntimeControllerHostActionDispatchReservationSchema
161
+ }).strict();
162
+ const GatewayRuntimeToolPortalDispatchAuthoritySchema = z.union([
163
+ GatewayRuntimeMcpProviderDirectDispatchAuthoritySchema,
164
+ GatewayRuntimeToolVmRunnerDirectDispatchAuthoritySchema,
165
+ GatewayRuntimeControllerHostActionDirectDispatchAuthoritySchema,
166
+ GatewayRuntimeMcpProviderApprovalGrantDispatchAuthoritySchema,
167
+ GatewayRuntimeToolVmRunnerApprovalGrantDispatchAuthoritySchema,
168
+ GatewayRuntimeControllerHostActionApprovalReservationDispatchAuthoritySchema
169
+ ]);
170
+ const GatewayRuntimeApprovalNotDispatchedReasonSchema = z.enum([
171
+ "consumed-without-dispatch",
172
+ "denied",
173
+ "expired",
174
+ "revoked",
175
+ "stale-authority",
176
+ "stale-fingerprint"
177
+ ]);
178
+ const GatewayRuntimeApprovalAmbiguousReasonSchema = z.literal("dispatch-armed");
179
+ const GatewayRuntimeApprovalAdmissionResultSchema = z.discriminatedUnion("kind", [
180
+ z.object({
181
+ challenge: GatewayRuntimeApprovalChallengeSchema,
182
+ kind: z.literal("approval-required")
183
+ }).strict(),
184
+ z.object({
185
+ kind: z.literal("dispatch-reserved"),
186
+ reservation: GatewayRuntimeApprovalDispatchReservationSchema
187
+ }).strict(),
188
+ z.object({
189
+ kind: z.literal("not-dispatched"),
190
+ operationId: z.string().uuid(),
191
+ reason: GatewayRuntimeApprovalNotDispatchedReasonSchema
192
+ }).strict(),
193
+ z.object({
194
+ kind: z.literal("ambiguous"),
195
+ operationId: z.string().uuid(),
196
+ reason: GatewayRuntimeApprovalAmbiguousReasonSchema
197
+ }).strict()
198
+ ]);
199
+ const GatewayRuntimeApprovalArmDispatchCommandSchema = z.object({ reservation: GatewayRuntimeGatewayDispatchReservationSchema }).strict();
200
+ const GatewayRuntimeApprovalArmDispatchResultSchema = z.discriminatedUnion("kind", [
201
+ z.object({
202
+ grant: GatewayRuntimeApprovalDispatchGrantSchema,
203
+ kind: z.literal("dispatch-armed")
204
+ }).strict(),
205
+ z.object({
206
+ kind: z.literal("not-dispatched"),
207
+ operationId: z.string().uuid(),
208
+ reason: GatewayRuntimeApprovalNotDispatchedReasonSchema
209
+ }).strict(),
210
+ z.object({
211
+ kind: z.literal("ambiguous"),
212
+ operationId: z.string().uuid(),
213
+ reason: GatewayRuntimeApprovalAmbiguousReasonSchema
214
+ }).strict()
215
+ ]);
216
+ const GatewayRuntimeApprovalDecisionCommandSchema = z.object({
217
+ approvalId: z.string().uuid(),
218
+ decision: z.enum(["approve", "deny"])
219
+ }).strict();
220
+ const GatewayRuntimeApprovalRevokeCommandSchema = z.object({ approvalId: z.string().uuid() }).strict();
221
+ function deriveGatewayRuntimeApprovalFingerprint(props) {
222
+ return `sha256:${createHash("sha256").update(canonicalApprovalJson(props), "utf8").digest("hex")}`;
223
+ }
224
+ function deriveGatewayRuntimeApprovalId(fingerprint) {
225
+ const hexadecimal = fingerprint.slice(7, 39).split("");
226
+ hexadecimal[12] = "5";
227
+ hexadecimal[16] = (Number.parseInt(hexadecimal[16] ?? "0", 16) & 3 | 8).toString(16);
228
+ const value = hexadecimal.join("");
229
+ return `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
230
+ }
231
+ //#endregion
232
+ //#region src/gateway-runtime-readiness-snapshot.ts
233
+ const GATEWAY_RUNTIME_READINESS_SNAPSHOT_VERSION = 1;
234
+ const GATEWAY_RUNTIME_ATTACHMENT_SNAPSHOT_VERSION = 1;
235
+ const BoundedIdentitySchema = z.string().min(1).max(256);
236
+ const PositiveSafeIntegerSchema = z.number().int().positive().max(Number.MAX_SAFE_INTEGER);
237
+ const NonNegativeSafeIntegerSchema = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
238
+ const GatewayRuntimeManagedPluginClientKindSchema = z.enum(["openclaw-managed-plugin", "hermes-managed-plugin"]);
239
+ const GatewayRuntimeExpectedAttachmentIdentitySchema = z.object({
240
+ attachmentGeneration: PositiveSafeIntegerSchema,
241
+ clientKind: GatewayRuntimeManagedPluginClientKindSchema,
242
+ configuredAgentIds: z.array(BoundedIdentitySchema).min(1).max(128).readonly(),
243
+ frameworkEpoch: BoundedIdentitySchema,
244
+ gatewayEpoch: BoundedIdentitySchema,
245
+ protocolVersion: PositiveSafeIntegerSchema,
246
+ projectionCohortDigest: z.string().regex(/^projection-cohort:[a-f0-9]{64}$/u),
247
+ runtimeEpoch: BoundedIdentitySchema,
248
+ schemaVersion: PositiveSafeIntegerSchema
249
+ }).strict().superRefine((identity, context) => {
250
+ if (new Set(identity.configuredAgentIds).size !== identity.configuredAgentIds.length) context.addIssue({
251
+ code: "custom",
252
+ message: "Gateway runtime configured agent ids must be unique.",
253
+ path: ["configuredAgentIds"]
254
+ });
255
+ }).readonly();
256
+ const GatewayRuntimeAttachmentSnapshotSchema = z.object({
257
+ connectionId: z.string().uuid().optional(),
258
+ expected: GatewayRuntimeExpectedAttachmentIdentitySchema,
259
+ observationSequence: NonNegativeSafeIntegerSchema,
260
+ snapshotVersion: z.literal(1),
261
+ status: z.enum([
262
+ "awaiting-attachment",
263
+ "attached",
264
+ "attachment-lost",
265
+ "retired"
266
+ ])
267
+ }).strict().superRefine((snapshot, context) => {
268
+ const requiresConnectionIdentity = snapshot.status === "attached" || snapshot.status === "attachment-lost";
269
+ if (requiresConnectionIdentity && snapshot.connectionId === void 0) context.addIssue({
270
+ code: "custom",
271
+ message: "Accepted and lost attachment snapshots require a connection identity.",
272
+ path: ["connectionId"]
273
+ });
274
+ if (!requiresConnectionIdentity && snapshot.connectionId !== void 0) context.addIssue({
275
+ code: "custom",
276
+ message: "Awaiting and retired attachment snapshots cannot claim a connection identity.",
277
+ path: ["connectionId"]
278
+ });
279
+ }).readonly();
280
+ const GatewayRuntimeUdsPublicationSnapshotSchema = z.object({
281
+ identity: z.literal("managed-plugin-private-uds"),
282
+ protocolVersion: PositiveSafeIntegerSchema,
283
+ schemaVersion: PositiveSafeIntegerSchema,
284
+ socketPath: z.string().min(1).max(256).startsWith("/"),
285
+ status: z.enum(["published", "retired"])
286
+ }).strict().readonly();
287
+ const GatewayRuntimeRequiredBackendKindSchema = z.enum([
288
+ "controller_host_action",
289
+ "mcp_provider",
290
+ "tool_vm_runner"
291
+ ]);
292
+ const GatewayRuntimeRequiredBackendsReadinessSchema = z.object({
293
+ readyBackendKinds: z.array(GatewayRuntimeRequiredBackendKindSchema).max(3).readonly(),
294
+ revision: BoundedIdentitySchema,
295
+ status: z.literal("ready")
296
+ }).strict().superRefine((readiness, context) => {
297
+ if (new Set(readiness.readyBackendKinds).size !== readiness.readyBackendKinds.length) context.addIssue({
298
+ code: "custom",
299
+ message: "Gateway runtime ready backend kinds must be unique.",
300
+ path: ["readyBackendKinds"]
301
+ });
302
+ }).readonly();
303
+ const GatewayRuntimeFatalEvidenceSchema = z.object({
304
+ failureCode: BoundedIdentitySchema,
305
+ kind: z.literal("fatal"),
306
+ observedGatewayEpoch: BoundedIdentitySchema,
307
+ processEpoch: BoundedIdentitySchema,
308
+ role: z.enum(["framework-service", "tool-portal-service"]),
309
+ schemaVersion: z.literal(1),
310
+ serviceId: BoundedIdentitySchema
311
+ }).strict().readonly();
312
+ /**
313
+ * Role-local Tool Portal evidence. The controller must join this with framework,
314
+ * backend, ingress, and control-session evidence before admitting the Gateway.
315
+ */
316
+ const GatewayRuntimeReadinessSnapshotSchema = z.object({
317
+ controlEndpoint: z.object({
318
+ identity: z.object({
319
+ bootId: BoundedIdentitySchema,
320
+ controllerEpoch: BoundedIdentitySchema,
321
+ generationId: BoundedIdentitySchema,
322
+ peerId: BoundedIdentitySchema,
323
+ processEpoch: BoundedIdentitySchema,
324
+ zoneId: BoundedIdentitySchema
325
+ }).strict().readonly(),
326
+ listener: z.object({
327
+ host: z.string().min(1).max(253),
328
+ port: z.number().int().min(1).max(65535),
329
+ readyPath: z.string().min(1).max(256).startsWith("/"),
330
+ socketPath: z.string().min(1).max(256).startsWith("/")
331
+ }).strict().readonly()
332
+ }).strict().readonly(),
333
+ kind: z.literal("tool-portal-role-readiness"),
334
+ providerRevision: BoundedIdentitySchema,
335
+ requiredBackends: GatewayRuntimeRequiredBackendsReadinessSchema,
336
+ semanticRevision: BoundedIdentitySchema,
337
+ serviceIdentity: z.object({
338
+ processEpoch: BoundedIdentitySchema,
339
+ role: z.literal("tool-portal"),
340
+ serviceId: BoundedIdentitySchema
341
+ }).strict().readonly(),
342
+ snapshotVersion: z.literal(1),
343
+ uds: z.object({
344
+ attachment: GatewayRuntimeAttachmentSnapshotSchema,
345
+ publication: GatewayRuntimeUdsPublicationSnapshotSchema
346
+ }).strict().readonly()
347
+ }).strict().superRefine((snapshot, context) => {
348
+ if (snapshot.controlEndpoint.identity.processEpoch !== snapshot.serviceIdentity.processEpoch) context.addIssue({
349
+ code: "custom",
350
+ message: "Gateway runtime service and control endpoint process epochs must match.",
351
+ path: [
352
+ "controlEndpoint",
353
+ "identity",
354
+ "processEpoch"
355
+ ]
356
+ });
357
+ if (snapshot.uds.publication.status === "retired" && snapshot.uds.attachment.status !== "retired") context.addIssue({
358
+ code: "custom",
359
+ message: "A retired UDS publication requires a retired attachment lifecycle.",
360
+ path: [
361
+ "uds",
362
+ "attachment",
363
+ "status"
364
+ ]
365
+ });
366
+ }).readonly();
367
+ function freezeExpectedAttachmentIdentity(identity) {
368
+ return Object.freeze({
369
+ ...identity,
370
+ configuredAgentIds: Object.freeze([...identity.configuredAgentIds].toSorted())
371
+ });
372
+ }
373
+ function createGatewayRuntimeAttachmentSnapshot(input) {
374
+ const parsed = GatewayRuntimeAttachmentSnapshotSchema.parse(input);
375
+ return Object.freeze({
376
+ ...parsed,
377
+ expected: freezeExpectedAttachmentIdentity(parsed.expected)
378
+ });
379
+ }
380
+ function createGatewayRuntimeReadinessSnapshot(input) {
381
+ const parsed = GatewayRuntimeReadinessSnapshotSchema.parse(input);
382
+ const attachment = createGatewayRuntimeAttachmentSnapshot(parsed.uds.attachment);
383
+ return Object.freeze({
384
+ ...parsed,
385
+ controlEndpoint: Object.freeze({
386
+ identity: Object.freeze({ ...parsed.controlEndpoint.identity }),
387
+ listener: Object.freeze({ ...parsed.controlEndpoint.listener })
388
+ }),
389
+ serviceIdentity: Object.freeze({ ...parsed.serviceIdentity }),
390
+ requiredBackends: Object.freeze({
391
+ ...parsed.requiredBackends,
392
+ readyBackendKinds: Object.freeze([...parsed.requiredBackends.readyBackendKinds].toSorted())
393
+ }),
394
+ uds: Object.freeze({
395
+ attachment,
396
+ publication: Object.freeze({ ...parsed.uds.publication })
397
+ })
398
+ });
399
+ }
400
+ //#endregion
3
401
  //#region src/gateway-control-admission.ts
4
402
  const GATEWAY_CONTROL_ADMISSION_LIMITS = {
5
403
  authority: {
@@ -669,6 +1067,11 @@ function classifyGatewayControlAdmission(options) {
669
1067
  status: "fence"
670
1068
  };
671
1069
  switch (message.operation) {
1070
+ case "gateway_runtime_readiness": return {
1071
+ coalesceKey: "gateway-runtime-readiness",
1072
+ messageClass: "liveness",
1073
+ status: "classified"
1074
+ };
672
1075
  case "runtime_status": return {
673
1076
  coalesceKey: `runtime-status:${message.payload.statusKind}`,
674
1077
  messageClass: "liveness",
@@ -687,6 +1090,20 @@ function classifyGatewayControlAdmission(options) {
687
1090
  status: "classified"
688
1091
  };
689
1092
  if (options.direction === "controller_to_gateway") switch (message.operation) {
1093
+ case "tool_vm_binding_publish": {
1094
+ if (message.kind !== "command") return {
1095
+ reason: "direction_violation",
1096
+ status: "fence"
1097
+ };
1098
+ const stablePrincipal = message.payload.binding.stablePrincipal;
1099
+ return {
1100
+ authoritySchedulingKey: stablePrincipal,
1101
+ coalesceKey: `tool-vm-binding:${stablePrincipal}`,
1102
+ messageClass: "authority",
1103
+ stablePrincipal,
1104
+ status: "classified"
1105
+ };
1106
+ }
690
1107
  case "operation_cancel": return options.controllerSafetyOperation === true && message.payload.initiatedBy === "controller" ? {
691
1108
  messageClass: "safety",
692
1109
  status: "classified"
@@ -711,7 +1128,10 @@ function classifyGatewayControlAdmission(options) {
711
1128
  case "lease_use_start":
712
1129
  case "lease_use_heartbeat":
713
1130
  case "lease_use_end":
714
- case "tool_portal_controller_host_action": return {
1131
+ case "tool_portal_controller_host_action":
1132
+ case "tool_portal_admission_reserve":
1133
+ case "tool_portal_dispatch_arm":
1134
+ case "tool_vm_binding_request": return {
715
1135
  reason: "direction_violation",
716
1136
  status: "fence"
717
1137
  };
@@ -745,6 +1165,10 @@ function classifyGatewayControlAdmission(options) {
745
1165
  reason: "direction_violation",
746
1166
  status: "fence"
747
1167
  };
1168
+ case "tool_vm_binding_publish": return {
1169
+ reason: "direction_violation",
1170
+ status: "fence"
1171
+ };
748
1172
  case "lease_create":
749
1173
  case "lease_get":
750
1174
  case "lease_peek":
@@ -752,7 +1176,10 @@ function classifyGatewayControlAdmission(options) {
752
1176
  case "lease_release":
753
1177
  case "lease_use_start":
754
1178
  case "lease_use_end":
755
- case "tool_portal_controller_host_action": return authorityClassification(options.stablePrincipal);
1179
+ case "tool_portal_controller_host_action":
1180
+ case "tool_portal_admission_reserve":
1181
+ case "tool_portal_dispatch_arm":
1182
+ case "tool_vm_binding_request": return authorityClassification(options.stablePrincipal);
756
1183
  }
757
1184
  return {
758
1185
  reason: "direction_violation",
@@ -760,6 +1187,221 @@ function classifyGatewayControlAdmission(options) {
760
1187
  };
761
1188
  }
762
1189
  //#endregion
1190
+ //#region src/gateway-runtime-control-endpoint.ts
1191
+ const GATEWAY_RUNTIME_TOOL_PORTAL_CONTROL_LISTEN_HOST = "127.0.0.1";
1192
+ const GATEWAY_RUNTIME_TOOL_PORTAL_CONTROL_GUEST_PORT = 18790;
1193
+ const GatewayRuntimeToolPortalProductionControlEndpointSchema = z.object({
1194
+ host: z.literal(GATEWAY_RUNTIME_TOOL_PORTAL_CONTROL_LISTEN_HOST),
1195
+ port: z.literal(GATEWAY_RUNTIME_TOOL_PORTAL_CONTROL_GUEST_PORT)
1196
+ }).strict().readonly();
1197
+ const GATEWAY_RUNTIME_TOOL_PORTAL_PRODUCTION_CONTROL_ENDPOINT = GatewayRuntimeToolPortalProductionControlEndpointSchema.parse({
1198
+ host: GATEWAY_RUNTIME_TOOL_PORTAL_CONTROL_LISTEN_HOST,
1199
+ port: GATEWAY_RUNTIME_TOOL_PORTAL_CONTROL_GUEST_PORT
1200
+ });
1201
+ //#endregion
1202
+ //#region src/gateway-runtime-portal-admission.ts
1203
+ const GATEWAY_RUNTIME_PORTAL_ADMISSION_FILE_NAME = "gateway-runtime-portal-admission.json";
1204
+ const GatewayRuntimeManagedToolPortalConfigSchema = toolPortalConfigSchema.transform((config, context) => {
1205
+ if (config.mode !== "managed") {
1206
+ context.addIssue({
1207
+ code: "custom",
1208
+ message: "Gateway runtime admission requires managed Tool Portal configuration.",
1209
+ path: ["mode"]
1210
+ });
1211
+ return z.NEVER;
1212
+ }
1213
+ return config;
1214
+ });
1215
+ const GatewayRuntimePortalAdmissionMaterialSchema = z.object({
1216
+ effectiveMcpConfig: mcpConfigSchema,
1217
+ effectiveToolPortalConfig: GatewayRuntimeManagedToolPortalConfigSchema,
1218
+ semanticSnapshot: GatewayRuntimePortalSemanticSnapshotSchema
1219
+ }).strict();
1220
+ //#endregion
1221
+ //#region src/gateway-runtime-portal-semantic-revision.ts
1222
+ function sortedStrings(values) {
1223
+ return [...values].toSorted();
1224
+ }
1225
+ function normalizedToolSelector(selector) {
1226
+ return {
1227
+ allow: selector.allow === "*" ? "*" : sortedStrings(selector.allow),
1228
+ deny: sortedStrings(selector.deny)
1229
+ };
1230
+ }
1231
+ function normalizedMcpProviders(providers) {
1232
+ return Object.fromEntries(Object.entries(providers).map(([providerId, provider]) => {
1233
+ const secretPolicies = Object.fromEntries(Object.entries(provider.secretPolicies).map(([secretName, policy]) => [secretName, {
1234
+ hosts: sortedStrings(policy.hosts),
1235
+ injection: policy.injection
1236
+ }]));
1237
+ const transport = provider.transport.kind === "stdio" ? {
1238
+ args: provider.transport.args,
1239
+ command: provider.transport.command,
1240
+ ...provider.transport.connectionTimeoutMs === void 0 ? {} : { connectionTimeoutMs: provider.transport.connectionTimeoutMs },
1241
+ ...provider.transport.cwd === void 0 ? {} : { cwd: provider.transport.cwd },
1242
+ env: provider.transport.env,
1243
+ kind: provider.transport.kind,
1244
+ ...provider.transport.networkAccess === void 0 ? {} : { networkAccess: provider.transport.networkAccess },
1245
+ requiredEgressHosts: sortedStrings(provider.transport.requiredEgressHosts)
1246
+ } : {
1247
+ ...provider.transport.connectionTimeoutMs === void 0 ? {} : { connectionTimeoutMs: provider.transport.connectionTimeoutMs },
1248
+ headers: provider.transport.headers,
1249
+ kind: provider.transport.kind,
1250
+ requiredEgressHosts: sortedStrings(provider.transport.requiredEgressHosts),
1251
+ url: provider.transport.url
1252
+ };
1253
+ return [providerId, {
1254
+ discovery: provider.discovery,
1255
+ kind: provider.kind,
1256
+ namespace: provider.namespace,
1257
+ secretPolicies,
1258
+ transport
1259
+ }];
1260
+ }));
1261
+ }
1262
+ function normalizedSurfaceEligibility(surfaceEligibilityByProfile) {
1263
+ return Object.fromEntries(Object.entries(surfaceEligibilityByProfile).map(([profileId, capabilities]) => [profileId, Object.fromEntries(Object.entries(capabilities).map(([capabilityId, surfaceClasses]) => [capabilityId, sortedStrings(surfaceClasses)]))]));
1264
+ }
1265
+ function normalizedCatalogInputs(props) {
1266
+ return {
1267
+ profiles: Object.fromEntries(Object.entries(props.toolPortalConfig.profiles).map(([profileId, profile]) => [profileId, Object.fromEntries(Object.entries(profile.namespaces).map(([namespaceId, namespacePolicy]) => [namespaceId, {
1268
+ ...namespacePolicy.backend.kind === "tool_vm_runner" ? { operations: Object.fromEntries(Object.entries(namespacePolicy.backend.operations).map(([operationName, operation]) => [operationName, {
1269
+ description: operation.description,
1270
+ kind: operation.kind
1271
+ }])) } : {},
1272
+ tools: normalizedToolSelector(namespacePolicy.tools)
1273
+ }]))])),
1274
+ providers: normalizedMcpProviders(props.mcpConfig.providers)
1275
+ };
1276
+ }
1277
+ function normalizedProfilePolicyInputs(props) {
1278
+ return {
1279
+ profiles: Object.fromEntries(Object.entries(props.toolPortalConfig.profiles).map(([profileId, profile]) => [profileId, Object.fromEntries(Object.entries(profile.namespaces).map(([namespaceId, namespacePolicy]) => [namespaceId, {
1280
+ calls: {
1281
+ requiresApproval: normalizedToolSelector(namespacePolicy.calls.requiresApproval),
1282
+ withoutApproval: normalizedToolSelector(namespacePolicy.calls.withoutApproval)
1283
+ },
1284
+ tools: normalizedToolSelector(namespacePolicy.tools)
1285
+ }]))])),
1286
+ surfaceEligibilityByProfile: normalizedSurfaceEligibility(props.surfaceEligibilityByProfile)
1287
+ };
1288
+ }
1289
+ function normalizedBindingInputs(config) {
1290
+ return Object.fromEntries(Object.entries(config.profiles).map(([profileId, profile]) => [profileId, Object.fromEntries(Object.entries(profile.namespaces).map(([namespaceId, namespacePolicy]) => [namespaceId, namespacePolicy.backend.kind === "tool_vm_runner" ? {
1291
+ kind: namespacePolicy.backend.kind,
1292
+ operations: Object.fromEntries(Object.entries(namespacePolicy.backend.operations).map(([operationName, operation]) => [operationName, operation.kind === "command.fixed" ? {
1293
+ executable: operation.executable,
1294
+ kind: operation.kind,
1295
+ mandatoryArgvPrefix: operation.mandatoryArgvPrefix,
1296
+ workingDirectory: operation.workingDirectory
1297
+ } : operation.kind === "process.start" ? {
1298
+ executable: operation.executable,
1299
+ kind: operation.kind,
1300
+ mandatoryArgvPrefix: operation.mandatoryArgvPrefix,
1301
+ maxRuntimeMs: operation.maxRuntimeMs,
1302
+ retainOutputBytes: operation.retainOutputBytes,
1303
+ workingDirectory: operation.workingDirectory
1304
+ } : operation.kind === "process.wait" ? {
1305
+ kind: operation.kind,
1306
+ timeoutMs: operation.timeoutMs
1307
+ } : { kind: operation.kind }])),
1308
+ profile: namespacePolicy.backend.profile
1309
+ } : { kind: namespacePolicy.backend.kind }]))]));
1310
+ }
1311
+ function canonicalJson(value) {
1312
+ return JSON.stringify(value, (_key, nestedValue) => {
1313
+ if (typeof nestedValue !== "object" || nestedValue === null || Array.isArray(nestedValue)) return nestedValue;
1314
+ return Object.fromEntries(Object.entries(nestedValue).toSorted(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey)));
1315
+ });
1316
+ }
1317
+ function revision(domain, material) {
1318
+ return `${domain}:${createHash("sha256").update(`${domain}\0`, "utf8").update(canonicalJson(material), "utf8").digest("hex")}`;
1319
+ }
1320
+ function frameworkIdentityKey(identity) {
1321
+ return identity.kind === "openclaw" ? `openclaw:${identity.agentId}` : `hermes:${identity.profileName}`;
1322
+ }
1323
+ function assertExactManagedAgentProjectionInputs(props) {
1324
+ const projectionAgentIds = props.agentProjections.map((projection) => projection.agentId);
1325
+ if (new Set(projectionAgentIds).size !== projectionAgentIds.length) throw new Error("Managed Agent Projection agent ids must be unique.");
1326
+ const configuredAgentIds = sortedStrings(Object.keys(props.configuredAgents));
1327
+ const sortedProjectionAgentIds = sortedStrings(projectionAgentIds);
1328
+ if (configuredAgentIds.length !== sortedProjectionAgentIds.length || configuredAgentIds.some((agentId, index) => agentId !== sortedProjectionAgentIds[index])) throw new Error("Managed Agent Projection agent ids must exactly match configured Tool Portal agent ids.");
1329
+ if (new Set(props.agentProjections.map((projection) => projection.frameworkIdentity.kind)).size !== 1) throw new Error("Managed Agent Projections must share one framework kind.");
1330
+ const frameworkIdentityKeys = props.agentProjections.map((projection) => frameworkIdentityKey(projection.frameworkIdentity));
1331
+ if (new Set(frameworkIdentityKeys).size !== frameworkIdentityKeys.length) throw new Error("Managed Agent Projection framework identities must be unique.");
1332
+ for (const projection of props.agentProjections) {
1333
+ if (projection.frameworkIdentity.kind === "openclaw" && projection.frameworkIdentity.agentId !== projection.agentId) throw new Error(`OpenClaw projection identity must match agent '${projection.agentId}'.`);
1334
+ if (props.configuredAgents[projection.agentId]?.profile !== projection.toolPortalProfileId) throw new Error(`Managed Agent Projection Tool Portal profile does not match for agent '${projection.agentId}'.`);
1335
+ }
1336
+ }
1337
+ function deriveManagedAgentProjection(input) {
1338
+ return ManagedAgentProjectionSchema.parse({
1339
+ ...input,
1340
+ profileAssignmentRevision: revision("profile-assignment", input)
1341
+ });
1342
+ }
1343
+ function deriveManagedAgentProjectionCohortDigest(agentProjections) {
1344
+ return revision("projection-cohort", { agentProjections: [...agentProjections].toSorted((leftProjection, rightProjection) => leftProjection.agentId.localeCompare(rightProjection.agentId)) });
1345
+ }
1346
+ function deriveGatewayRuntimePortalSemanticSnapshot(props) {
1347
+ assertExactManagedAgentProjectionInputs({
1348
+ agentProjections: props.agentProjections,
1349
+ configuredAgents: props.toolPortalConfig.agents
1350
+ });
1351
+ const projections = props.agentProjections.map((projection) => deriveManagedAgentProjection(projection)).toSorted((leftProjection, rightProjection) => leftProjection.agentId.localeCompare(rightProjection.agentId));
1352
+ const agentProjections = Object.fromEntries(projections.map((projection) => [projection.agentId, projection]));
1353
+ const projectionCohortDigest = deriveManagedAgentProjectionCohortDigest(projections);
1354
+ const providerRevision = revision("provider", normalizedMcpProviders(props.mcpConfig.providers));
1355
+ const catalogRevision = revision("catalog", normalizedCatalogInputs({
1356
+ mcpConfig: props.mcpConfig,
1357
+ toolPortalConfig: props.toolPortalConfig
1358
+ }));
1359
+ const profilePolicyRevision = revision("profile-policy", normalizedProfilePolicyInputs({
1360
+ surfaceEligibilityByProfile: props.surfaceEligibilityByProfile,
1361
+ toolPortalConfig: props.toolPortalConfig
1362
+ }));
1363
+ const bindingRevision = revision("binding", normalizedBindingInputs(props.toolPortalConfig));
1364
+ const schemaRevision = revision("schema", {
1365
+ mcpConfigSchemaVersion: props.mcpConfig.schemaVersion,
1366
+ toolPortalConfigSchemaVersion: props.toolPortalConfig.schemaVersion
1367
+ });
1368
+ const desiredRevision = revision("portal-admission", {
1369
+ agentProjections,
1370
+ bindingRevision,
1371
+ catalogRevision,
1372
+ profilePolicyRevision,
1373
+ projectionCohortDigest,
1374
+ providerRevision,
1375
+ schemaRevision,
1376
+ surfaceEligibilityByProfile: normalizedSurfaceEligibility(props.surfaceEligibilityByProfile)
1377
+ });
1378
+ return GatewayRuntimePortalSemanticSnapshotSchema.parse({
1379
+ activeRevision: desiredRevision,
1380
+ agentProjections,
1381
+ bindingRevision,
1382
+ catalogRevision,
1383
+ desiredRevision,
1384
+ profilePolicyRevision,
1385
+ projectionCohortDigest,
1386
+ providerRevision,
1387
+ schemaRevision,
1388
+ schemaVersion: 1,
1389
+ surfaceEligibilityByProfile: normalizedSurfaceEligibility(props.surfaceEligibilityByProfile)
1390
+ });
1391
+ }
1392
+ function assertGatewayRuntimePortalSemanticSnapshotMatchesInputs(props) {
1393
+ if (canonicalJson(deriveGatewayRuntimePortalSemanticSnapshot({
1394
+ agentProjections: Object.values(props.semanticSnapshot.agentProjections).map((projection) => ({
1395
+ agentId: projection.agentId,
1396
+ frameworkIdentity: projection.frameworkIdentity,
1397
+ toolPortalProfileId: projection.toolPortalProfileId
1398
+ })),
1399
+ mcpConfig: props.mcpConfig,
1400
+ surfaceEligibilityByProfile: props.semanticSnapshot.surfaceEligibilityByProfile,
1401
+ toolPortalConfig: props.toolPortalConfig
1402
+ })) !== canonicalJson(props.semanticSnapshot)) throw new Error("Gateway runtime semantic snapshot does not match the protected Tool Portal and MCP inputs.");
1403
+ }
1404
+ //#endregion
763
1405
  //#region src/index.ts
764
1406
  const GatewayControlDomainSchema = z.literal("gateway_control");
765
1407
  const GatewayControlHelloSchema = z.object({
@@ -785,6 +1427,7 @@ const GatewayControlHelloResponseSchema = z.object({
785
1427
  }).strict();
786
1428
  const GatewayControlRpcOperationSchema = z.enum([
787
1429
  "control_ping",
1430
+ "gateway_runtime_readiness",
788
1431
  "caller_context_register",
789
1432
  "lease_create",
790
1433
  "lease_get",
@@ -797,7 +1440,11 @@ const GatewayControlRpcOperationSchema = z.enum([
797
1440
  "lease_use_end",
798
1441
  "health_event",
799
1442
  "runtime_status",
1443
+ "tool_vm_binding_publish",
1444
+ "tool_vm_binding_request",
800
1445
  "tool_portal_controller_host_action",
1446
+ "tool_portal_admission_reserve",
1447
+ "tool_portal_dispatch_arm",
801
1448
  "operation_cancel",
802
1449
  "recovery_command"
803
1450
  ]);
@@ -833,21 +1480,8 @@ const GatewayControlCapabilityRefSchema = z.object({
833
1480
  }).strict();
834
1481
  const GatewayControlToolCallCorrelationSchema = ControlCorrelationSchema.extend({ capability: GatewayControlCapabilityRefSchema.optional() }).strict();
835
1482
  const GatewayControlTrustedCallerContextIdSchema = z.string().uuid();
836
- const GatewayControlAdmissionPrincipalSchema = z.string().regex(/^[a-f0-9]{64}$/u);
837
- const GatewayControlTrustedLeaseContextSchema = z.object({
838
- agentId: z.string().min(1),
839
- agentWorkspaceDir: z.string().min(1),
840
- approvalScopeId: z.string().min(1).optional(),
841
- callerContextId: GatewayControlTrustedCallerContextIdSchema,
842
- custodyScopeId: z.string().min(1).optional(),
843
- hostWorkMountDir: z.string().min(1),
844
- profileId: z.string().min(1),
845
- sessionKeyDigest: z.string().min(32),
846
- workMountDir: z.string().min(1),
847
- zoneId: z.string().min(1)
848
- }).strict();
849
1483
  const GatewayControlCallerContextRefSchema = z.object({ callerContextId: GatewayControlTrustedCallerContextIdSchema }).strict();
850
- const GatewayControlRegisteredCallerContextRefSchema = GatewayControlCallerContextRefSchema.extend({ admissionPrincipal: GatewayControlAdmissionPrincipalSchema }).strict();
1484
+ const GatewayControlRegisteredCallerContextRefSchema = GatewayControlCallerContextRefSchema.extend({ admissionPrincipal: GatewayStablePrincipalDigestSchema }).strict();
851
1485
  const GatewayControlCallerContextProofAlgorithmSchema = z.literal("hmac-sha256");
852
1486
  const GatewayControlCallerContextProofSchema = z.object({
853
1487
  algorithm: GatewayControlCallerContextProofAlgorithmSchema,
@@ -861,36 +1495,27 @@ const GatewayControlCallerContextAgentAuthoritySchema = z.object({
861
1495
  function buildGatewayControlCallerContextProofPayload(input) {
862
1496
  const purpose = input.purpose ?? "tool_vm_lease";
863
1497
  return [
864
- "gateway-control-caller-context-v1",
1498
+ "gateway-control-caller-context-v4",
865
1499
  input.zoneId,
866
- input.agentId,
867
- input.agentWorkspaceDir,
868
- input.workMountDir,
869
- input.sessionKey,
1500
+ deriveGatewayControlStablePrincipal({ principal: input.principal }),
870
1501
  purpose
871
1502
  ].join("\0");
872
1503
  }
873
1504
  function buildGatewayControlCallerContextAgentAuthorityPayload(input) {
874
1505
  const purpose = input.purpose ?? "tool_vm_lease";
875
1506
  return [
876
- "gateway-control-agent-authority-v1",
1507
+ "gateway-control-agent-authority-v4",
877
1508
  input.zoneId,
878
- input.agentId,
879
- input.agentWorkspaceDir,
880
- input.workMountDir,
881
- input.sessionKey,
1509
+ deriveGatewayControlStablePrincipal({ principal: input.principal }),
882
1510
  purpose
883
1511
  ].join("\0");
884
1512
  }
885
1513
  const GatewayControlCallerContextRegisterPayloadSchema = z.object({
886
1514
  adapterEvidence: z.object({
887
1515
  agentAuthority: GatewayControlCallerContextAgentAuthoritySchema,
888
- agentId: z.string().min(1),
889
- agentWorkspaceDir: z.string().min(1),
1516
+ principal: GatewayRuntimeTrustedInvocationPrincipalSchema$1,
890
1517
  proof: GatewayControlCallerContextProofSchema,
891
1518
  purpose: z.enum(["tool_vm_lease", "tool_portal_controller_host_action"]).optional(),
892
- sessionKey: z.string().min(1),
893
- workMountDir: z.string().min(1),
894
1519
  zoneId: z.string().min(1)
895
1520
  }).strict(),
896
1521
  correlation: GatewayControlToolCallCorrelationSchema.optional()
@@ -898,7 +1523,11 @@ const GatewayControlCallerContextRegisterPayloadSchema = z.object({
898
1523
  const GatewayControlLeaseCreateIntentPayloadSchema = z.object({
899
1524
  callerContext: GatewayControlCallerContextRefSchema,
900
1525
  correlation: GatewayControlToolCallCorrelationSchema.optional(),
901
- gatewayWorkspaceDir: z.string().min(1).optional(),
1526
+ idleTtlHintMs: z.number().int().positive().optional()
1527
+ }).strict();
1528
+ const GatewayControlToolVmBindingRequestPayloadSchema = z.object({
1529
+ callerContext: GatewayControlCallerContextRefSchema,
1530
+ correlation: GatewayControlToolCallCorrelationSchema.optional(),
902
1531
  idleTtlHintMs: z.number().int().positive().optional()
903
1532
  }).strict();
904
1533
  const GatewayControlLeaseIdPayloadSchema = z.object({
@@ -1013,7 +1642,7 @@ const GatewayControlToolVmLeaseCallerContextStateSchema = z.enum([
1013
1642
  "not_applicable"
1014
1643
  ]);
1015
1644
  const GatewayControlControllerRequestHealthOperationSchema = z.enum([
1016
- "zone-git-push",
1645
+ "workspace-git-push",
1017
1646
  "lease-create",
1018
1647
  "lease-get",
1019
1648
  "lease-peek",
@@ -1116,41 +1745,44 @@ const GatewayControlRuntimeStatusPayloadSchema = z.object({
1116
1745
  ]).optional(),
1117
1746
  statusKind: z.string().min(1)
1118
1747
  }).strict();
1119
- const GatewayControlZoneGitPushControllerHostActionPayloadSchema = z.object({
1120
- actionId: z.literal("zone_git_push"),
1748
+ const GatewayControlGitObjectIdSchema = z.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u, "expected an exact lowercase SHA-1 or SHA-256 object id");
1749
+ const GatewayControlWorkspaceGitPushControllerHostActionPayloadSchema = z.object({
1750
+ actionId: z.literal("workspace_git_push"),
1751
+ approvalReservation: GatewayRuntimeControllerHostActionDispatchReservationSchema.optional(),
1121
1752
  callerContext: GatewayControlCallerContextRefSchema,
1122
1753
  correlation: GatewayControlToolCallCorrelationSchema,
1123
- expectedHead: z.string().min(1)
1754
+ expectedHead: GatewayControlGitObjectIdSchema
1124
1755
  }).strict();
1125
1756
  const GatewayControlControllerHostProbePayloadSchema = z.object({
1126
1757
  actionId: z.literal("controller_host_probe"),
1758
+ approvalReservation: GatewayRuntimeControllerHostActionDispatchReservationSchema.optional(),
1127
1759
  callerContext: GatewayControlCallerContextRefSchema,
1128
1760
  correlation: GatewayControlToolCallCorrelationSchema
1129
1761
  }).strict();
1130
- const GatewayControlToolPortalControllerHostActionPayloadSchema = z.discriminatedUnion("actionId", [GatewayControlZoneGitPushControllerHostActionPayloadSchema, GatewayControlControllerHostProbePayloadSchema]);
1131
- const GatewayControlZoneGitCommitSummarySchema = z.object({
1132
- sha: z.string().min(1),
1762
+ const GatewayControlToolPortalControllerHostActionPayloadSchema = z.discriminatedUnion("actionId", [GatewayControlWorkspaceGitPushControllerHostActionPayloadSchema, GatewayControlControllerHostProbePayloadSchema]);
1763
+ const GatewayControlWorkspaceGitCommitSummarySchema = z.object({
1764
+ sha: GatewayControlGitObjectIdSchema,
1133
1765
  subject: z.string()
1134
1766
  }).strict();
1135
- const GatewayControlZoneGitPushResultSchema = z.object({
1767
+ const GatewayControlWorkspaceGitPushResultSchema = z.object({
1136
1768
  branch: z.string().min(1),
1137
- localHead: z.string().min(1),
1138
- pushedCommits: z.array(GatewayControlZoneGitCommitSummarySchema),
1139
- remoteHead: z.string().min(1)
1769
+ localHead: GatewayControlGitObjectIdSchema,
1770
+ pushedCommits: z.array(GatewayControlWorkspaceGitCommitSummarySchema),
1771
+ remoteHead: GatewayControlGitObjectIdSchema
1140
1772
  }).strict();
1141
1773
  const GatewayControlControllerHostProbeResultSchema = z.object({
1142
1774
  entryNames: z.array(z.string().min(1)).max(64),
1143
1775
  probeKind: z.literal("controller_cache_dir_listing")
1144
1776
  }).strict();
1145
- const GatewayControlZoneGitPushControllerHostActionResultSchema = z.object({
1146
- actionId: z.literal("zone_git_push"),
1147
- result: GatewayControlZoneGitPushResultSchema
1777
+ const GatewayControlWorkspaceGitPushControllerHostActionResultSchema = z.object({
1778
+ actionId: z.literal("workspace_git_push"),
1779
+ result: GatewayControlWorkspaceGitPushResultSchema
1148
1780
  }).strict();
1149
1781
  const GatewayControlControllerHostProbeActionResultSchema = z.object({
1150
1782
  actionId: z.literal("controller_host_probe"),
1151
1783
  result: GatewayControlControllerHostProbeResultSchema
1152
1784
  }).strict();
1153
- const GatewayControlToolPortalControllerHostActionResultSchema = z.discriminatedUnion("actionId", [GatewayControlZoneGitPushControllerHostActionResultSchema, GatewayControlControllerHostProbeActionResultSchema]);
1785
+ const GatewayControlToolPortalControllerHostActionResultSchema = z.discriminatedUnion("actionId", [GatewayControlWorkspaceGitPushControllerHostActionResultSchema, GatewayControlControllerHostProbeActionResultSchema]);
1154
1786
  const GatewayControlActiveOperationIdSchema = z.string().uuid();
1155
1787
  const GatewayInitiatedOperationCancelPayloadSchema = z.object({
1156
1788
  activeOperationId: GatewayControlActiveOperationIdSchema,
@@ -1180,6 +1812,8 @@ const GatewayControlRecoveryCommandPayloadSchema = z.discriminatedUnion("action"
1180
1812
  }).strict()
1181
1813
  ]);
1182
1814
  const GatewayControlPingPayloadSchema = z.object({}).strict();
1815
+ const GatewayControlToolPortalAdmissionReservePayloadSchema = z.object({ intent: GatewayRuntimeApprovalChallengeIntentSchema }).strict();
1816
+ const GatewayControlToolPortalDispatchArmPayloadSchema = z.object({ reservation: GatewayRuntimeGatewayDispatchReservationSchema }).strict();
1183
1817
  const GatewayControlHeartbeatPayloadSchema = z.object({
1184
1818
  elapsedMs: z.number().int().nonnegative().optional(),
1185
1819
  observedAtMs: z.number().int().positive()
@@ -1188,12 +1822,69 @@ const GatewayControlRpcErrorSchema = ControlRpcErrorSchema;
1188
1822
  const GatewayControlSessionStateSchema = ControlSessionStateSchema;
1189
1823
  const GatewayControlToolVmSshAccessSchema = z.object({
1190
1824
  host: z.string().min(1),
1191
- identityPem: z.string().min(1).optional(),
1192
- knownHostsLine: z.string().min(1).optional(),
1193
1825
  port: z.number().int().positive(),
1194
1826
  user: z.string().min(1)
1195
1827
  }).strict();
1196
- const GatewayControlLeaseSnapshotSchema = z.object({
1828
+ const GatewayControlPrivateToolVmSshAccessSchema = GatewayControlToolVmSshAccessSchema.extend({
1829
+ identityPem: z.string().min(1),
1830
+ knownHostsLine: z.string().min(1)
1831
+ }).strict();
1832
+ const GatewayControlToolVmBindingPublicationAuthoritySchema = z.object({
1833
+ attachmentGeneration: z.number().int().positive(),
1834
+ connectionId: z.string().uuid(),
1835
+ controllerEpoch: z.string().min(1),
1836
+ gatewayEpoch: z.string().min(1),
1837
+ processEpoch: z.string().min(1),
1838
+ sessionId: z.string().uuid(),
1839
+ zoneId: z.string().min(1)
1840
+ }).strict();
1841
+ const GatewayControlToolVmBindingAccessGrantSchema = z.object({
1842
+ agentId: z.string().min(1),
1843
+ idleTtlMs: z.number().int().positive(),
1844
+ leafGeneration: z.string().min(1),
1845
+ leaseId: z.string().min(1),
1846
+ profileAssignmentRevision: z.string().min(1),
1847
+ ssh: GatewayControlPrivateToolVmSshAccessSchema,
1848
+ sshBindingId: z.string().min(1),
1849
+ stablePrincipal: GatewayStablePrincipalDigestSchema,
1850
+ tcpSlot: z.number().int().nonnegative(),
1851
+ transport: z.literal("ssh-sandbox"),
1852
+ workdir: z.string().min(1),
1853
+ zoneId: z.string().min(1)
1854
+ }).strict();
1855
+ const GatewayControlToolVmBindingIdentitySchema = GatewayControlToolVmBindingAccessGrantSchema.pick({
1856
+ agentId: true,
1857
+ leafGeneration: true,
1858
+ leaseId: true,
1859
+ profileAssignmentRevision: true,
1860
+ sshBindingId: true,
1861
+ stablePrincipal: true,
1862
+ zoneId: true
1863
+ }).strict();
1864
+ const GatewayControlToolVmBindingPublicationSchema = z.discriminatedUnion("kind", [z.object({
1865
+ authority: GatewayControlToolVmBindingPublicationAuthoritySchema,
1866
+ binding: GatewayControlToolVmBindingAccessGrantSchema,
1867
+ kind: z.literal("current"),
1868
+ observedAtMs: z.number().int().positive()
1869
+ }).strict(), z.object({
1870
+ authority: GatewayControlToolVmBindingPublicationAuthoritySchema,
1871
+ binding: GatewayControlToolVmBindingIdentitySchema,
1872
+ kind: z.literal("retired"),
1873
+ observedAtMs: z.number().int().positive(),
1874
+ reason: z.enum([
1875
+ "dead",
1876
+ "expired",
1877
+ "released",
1878
+ "replaced",
1879
+ "session_retired"
1880
+ ])
1881
+ }).strict()]);
1882
+ const GatewayControlToolVmBindingRequestResultSchema = z.object({
1883
+ agentId: z.string().min(1),
1884
+ stablePrincipal: GatewayStablePrincipalDigestSchema,
1885
+ status: z.literal("publication_pending")
1886
+ }).strict();
1887
+ const GatewayControlLeaseSnapshotBaseSchema = z.object({
1197
1888
  agentId: z.string().min(1),
1198
1889
  activeUseId: z.string().uuid().optional(),
1199
1890
  expiresAtMs: z.number().int().positive().optional(),
@@ -1211,6 +1902,13 @@ const GatewayControlLeaseSnapshotSchema = z.object({
1211
1902
  workdir: z.string().min(1),
1212
1903
  zoneId: z.string().min(1)
1213
1904
  }).strict();
1905
+ const GatewayControlPublicLeaseSnapshotSchema = GatewayControlLeaseSnapshotBaseSchema;
1906
+ const GatewayControlPrivateLeaseSnapshotSchema = GatewayControlLeaseSnapshotBaseSchema.extend({
1907
+ leafGeneration: z.string().min(1),
1908
+ ssh: GatewayControlPrivateToolVmSshAccessSchema,
1909
+ sshBindingId: z.string().min(1)
1910
+ }).strict();
1911
+ const GatewayControlLeaseSnapshotSchema = z.union([GatewayControlPrivateLeaseSnapshotSchema, GatewayControlPublicLeaseSnapshotSchema]);
1214
1912
  const GatewayControlLeaseUseSnapshotSchema = z.object({
1215
1913
  expiresAt: z.number().int().positive().optional(),
1216
1914
  heartbeatAfterMs: z.number().int().positive().optional(),
@@ -1225,8 +1923,11 @@ const GatewayControlLeaseUseSnapshotSchema = z.object({
1225
1923
  const GatewayControlRpcDomainCorrelationSchema = ControlCorrelationSchema;
1226
1924
  const GatewayControlRpcForbiddenResponseFieldsSchema = {
1227
1925
  activeOperationId: z.never().optional(),
1926
+ approvalAdmission: z.never().optional(),
1927
+ approvalDispatch: z.never().optional(),
1228
1928
  approvalRequired: z.never().optional(),
1229
1929
  callerContext: z.never().optional(),
1930
+ bindingRequest: z.never().optional(),
1230
1931
  controllerHostAction: z.never().optional(),
1231
1932
  error: z.never().optional(),
1232
1933
  lease: z.never().optional(),
@@ -1265,32 +1966,53 @@ const GatewayControlRpcCallerContextResponsePayloadSchema = z.discriminatedUnion
1265
1966
  error: GatewayControlRpcErrorSchema,
1266
1967
  result: GatewayControlRpcErrorResponseResultSchema
1267
1968
  }).strict()]);
1268
- const GatewayControlRpcLeaseResponsePayloadSchema = z.discriminatedUnion("result", [
1969
+ const GatewayControlRpcToolVmBindingRequestResponsePayloadSchema = z.discriminatedUnion("result", [GatewayControlRpcResponseCorrelationSchema.extend({
1970
+ ...GatewayControlRpcForbiddenResponseFieldsSchema,
1971
+ bindingRequest: GatewayControlToolVmBindingRequestResultSchema,
1972
+ result: z.literal("ok")
1973
+ }).strict(), GatewayControlRpcResponseCorrelationSchema.extend({
1974
+ ...GatewayControlRpcForbiddenResponseFieldsSchema,
1975
+ error: GatewayControlRpcErrorSchema,
1976
+ result: GatewayControlRpcErrorResponseResultSchema
1977
+ }).strict()]);
1978
+ const GatewayControlRpcLeaseRejectedResponsePayloadSchema = GatewayControlRpcResponseCorrelationSchema.extend({
1979
+ ...GatewayControlRpcForbiddenResponseFieldsSchema,
1980
+ error: GatewayControlRpcErrorSchema.optional(),
1981
+ leaseRejectionReason: GatewayControlLeaseRejectionReasonSchema,
1982
+ result: z.literal("rejected")
1983
+ }).strict();
1984
+ const GatewayControlRpcLeaseFailedResponsePayloadSchema = GatewayControlRpcResponseCorrelationSchema.extend({
1985
+ ...GatewayControlRpcForbiddenResponseFieldsSchema,
1986
+ error: GatewayControlRpcErrorSchema,
1987
+ leaseRejectionReason: GatewayControlLeaseRejectionReasonSchema.optional(),
1988
+ result: z.enum([
1989
+ "failed",
1990
+ "timeout",
1991
+ "cancelled",
1992
+ "stale_generation",
1993
+ "approval_required",
1994
+ "approval_stale"
1995
+ ])
1996
+ }).strict();
1997
+ const GatewayControlRpcPrivateLeaseResponsePayloadSchema = z.discriminatedUnion("result", [
1269
1998
  GatewayControlRpcResponseCorrelationSchema.extend({
1270
1999
  ...GatewayControlRpcForbiddenResponseFieldsSchema,
1271
- lease: GatewayControlLeaseSnapshotSchema,
2000
+ lease: GatewayControlPrivateLeaseSnapshotSchema,
1272
2001
  result: z.literal("ok")
1273
2002
  }).strict(),
2003
+ GatewayControlRpcLeaseRejectedResponsePayloadSchema,
2004
+ GatewayControlRpcLeaseFailedResponsePayloadSchema
2005
+ ]);
2006
+ const GatewayControlRpcPublicLeaseResponsePayloadSchema = z.discriminatedUnion("result", [
1274
2007
  GatewayControlRpcResponseCorrelationSchema.extend({
1275
2008
  ...GatewayControlRpcForbiddenResponseFieldsSchema,
1276
- error: GatewayControlRpcErrorSchema.optional(),
1277
- leaseRejectionReason: GatewayControlLeaseRejectionReasonSchema,
1278
- result: z.literal("rejected")
2009
+ lease: GatewayControlPublicLeaseSnapshotSchema,
2010
+ result: z.literal("ok")
1279
2011
  }).strict(),
1280
- GatewayControlRpcResponseCorrelationSchema.extend({
1281
- ...GatewayControlRpcForbiddenResponseFieldsSchema,
1282
- error: GatewayControlRpcErrorSchema,
1283
- leaseRejectionReason: GatewayControlLeaseRejectionReasonSchema.optional(),
1284
- result: z.enum([
1285
- "failed",
1286
- "timeout",
1287
- "cancelled",
1288
- "stale_generation",
1289
- "approval_required",
1290
- "approval_stale"
1291
- ])
1292
- }).strict()
2012
+ GatewayControlRpcLeaseRejectedResponsePayloadSchema,
2013
+ GatewayControlRpcLeaseFailedResponsePayloadSchema
1293
2014
  ]);
2015
+ const GatewayControlRpcLeaseResponsePayloadSchema = z.union([GatewayControlRpcPrivateLeaseResponsePayloadSchema, GatewayControlRpcPublicLeaseResponsePayloadSchema]);
1294
2016
  const GatewayControlRpcLeaseUseResponsePayloadSchema = z.discriminatedUnion("result", [
1295
2017
  GatewayControlRpcResponseCorrelationSchema.extend({
1296
2018
  ...GatewayControlRpcForbiddenResponseFieldsSchema,
@@ -1336,13 +2058,34 @@ const GatewayControlRpcOperationCancelResponsePayloadSchema = z.discriminatedUni
1336
2058
  error: GatewayControlRpcErrorSchema,
1337
2059
  result: GatewayControlRpcErrorResponseResultSchema
1338
2060
  }).strict()]);
2061
+ const GatewayControlRpcApprovalAdmissionResponsePayloadSchema = z.discriminatedUnion("result", [GatewayControlRpcResponseCorrelationSchema.extend({
2062
+ ...GatewayControlRpcForbiddenResponseFieldsSchema,
2063
+ approvalAdmission: GatewayRuntimeApprovalAdmissionResultSchema,
2064
+ result: z.literal("ok")
2065
+ }).strict(), GatewayControlRpcResponseCorrelationSchema.extend({
2066
+ ...GatewayControlRpcForbiddenResponseFieldsSchema,
2067
+ error: GatewayControlRpcErrorSchema,
2068
+ result: GatewayControlRpcErrorResponseResultSchema
2069
+ }).strict()]);
2070
+ const GatewayControlRpcApprovalDispatchResponsePayloadSchema = z.discriminatedUnion("result", [GatewayControlRpcResponseCorrelationSchema.extend({
2071
+ ...GatewayControlRpcForbiddenResponseFieldsSchema,
2072
+ approvalDispatch: GatewayRuntimeApprovalArmDispatchResultSchema,
2073
+ result: z.literal("ok")
2074
+ }).strict(), GatewayControlRpcResponseCorrelationSchema.extend({
2075
+ ...GatewayControlRpcForbiddenResponseFieldsSchema,
2076
+ error: GatewayControlRpcErrorSchema,
2077
+ result: GatewayControlRpcErrorResponseResultSchema
2078
+ }).strict()]);
1339
2079
  const GatewayControlRpcResponsePayloadSchema = z.union([
1340
2080
  GatewayControlRpcBareResponsePayloadSchema,
1341
2081
  GatewayControlRpcCallerContextResponsePayloadSchema,
2082
+ GatewayControlRpcToolVmBindingRequestResponsePayloadSchema,
1342
2083
  GatewayControlRpcLeaseResponsePayloadSchema,
1343
2084
  GatewayControlRpcLeaseUseResponsePayloadSchema,
1344
2085
  GatewayControlRpcControllerHostActionResponsePayloadSchema,
1345
- GatewayControlRpcOperationCancelResponsePayloadSchema
2086
+ GatewayControlRpcOperationCancelResponsePayloadSchema,
2087
+ GatewayControlRpcApprovalAdmissionResponsePayloadSchema,
2088
+ GatewayControlRpcApprovalDispatchResponsePayloadSchema
1346
2089
  ]);
1347
2090
  const GatewayControlRpcControlPingCommandResultMessageSchema = GatewayControlRpcDomainCorrelationSchema.extend({
1348
2091
  kind: z.literal("command_result"),
@@ -1354,17 +2097,20 @@ const GatewayControlRpcCallerContextRegisterCommandResultMessageSchema = Gateway
1354
2097
  operation: z.literal("caller_context_register"),
1355
2098
  payload: GatewayControlRpcCallerContextResponsePayloadSchema
1356
2099
  }).strict();
1357
- const GatewayControlRpcLeaseCommandResultMessageSchema = GatewayControlRpcDomainCorrelationSchema.extend({
2100
+ const GatewayControlRpcPrivateLeaseCommandResultMessageSchema = GatewayControlRpcDomainCorrelationSchema.extend({
1358
2101
  kind: z.literal("command_result"),
1359
2102
  operation: z.enum([
1360
2103
  "lease_create",
1361
2104
  "lease_get",
1362
- "lease_peek",
1363
2105
  "lease_reacquire",
1364
- "lease_renew",
1365
- "lease_release"
2106
+ "lease_renew"
1366
2107
  ]),
1367
- payload: GatewayControlRpcLeaseResponsePayloadSchema
2108
+ payload: GatewayControlRpcPrivateLeaseResponsePayloadSchema
2109
+ }).strict();
2110
+ const GatewayControlRpcPublicLeaseCommandResultMessageSchema = GatewayControlRpcDomainCorrelationSchema.extend({
2111
+ kind: z.literal("command_result"),
2112
+ operation: z.enum(["lease_peek", "lease_release"]),
2113
+ payload: GatewayControlRpcPublicLeaseResponsePayloadSchema
1368
2114
  }).strict();
1369
2115
  const GatewayControlRpcLeaseUseCommandResultMessageSchema = GatewayControlRpcDomainCorrelationSchema.extend({
1370
2116
  kind: z.literal("command_result"),
@@ -1390,6 +2136,26 @@ const GatewayControlRpcRecoveryCommandResultMessageSchema = GatewayControlRpcDom
1390
2136
  operation: z.literal("recovery_command"),
1391
2137
  payload: GatewayControlRpcBareResponsePayloadSchema
1392
2138
  }).strict();
2139
+ const GatewayControlRpcApprovalAdmissionCommandResultMessageSchema = GatewayControlRpcDomainCorrelationSchema.extend({
2140
+ kind: z.literal("command_result"),
2141
+ operation: z.literal("tool_portal_admission_reserve"),
2142
+ payload: GatewayControlRpcApprovalAdmissionResponsePayloadSchema
2143
+ }).strict();
2144
+ const GatewayControlRpcApprovalDispatchCommandResultMessageSchema = GatewayControlRpcDomainCorrelationSchema.extend({
2145
+ kind: z.literal("command_result"),
2146
+ operation: z.literal("tool_portal_dispatch_arm"),
2147
+ payload: GatewayControlRpcApprovalDispatchResponsePayloadSchema
2148
+ }).strict();
2149
+ const GatewayControlRpcToolVmBindingRequestCommandResultMessageSchema = GatewayControlRpcDomainCorrelationSchema.extend({
2150
+ kind: z.literal("command_result"),
2151
+ operation: z.literal("tool_vm_binding_request"),
2152
+ payload: GatewayControlRpcToolVmBindingRequestResponsePayloadSchema
2153
+ }).strict();
2154
+ const GatewayControlRpcToolVmBindingPublishCommandResultMessageSchema = GatewayControlRpcDomainCorrelationSchema.extend({
2155
+ kind: z.literal("command_result"),
2156
+ operation: z.literal("tool_vm_binding_publish"),
2157
+ payload: GatewayControlRpcBareResponsePayloadSchema
2158
+ }).strict();
1393
2159
  const GatewayControlHeartbeatMessageSchema = z.object({
1394
2160
  kind: z.literal("heartbeat"),
1395
2161
  operation: z.never().optional(),
@@ -1398,13 +2164,28 @@ const GatewayControlHeartbeatMessageSchema = z.object({
1398
2164
  const GatewayControlRpcCommandResultMessageSchema = z.discriminatedUnion("operation", [
1399
2165
  GatewayControlRpcControlPingCommandResultMessageSchema,
1400
2166
  GatewayControlRpcCallerContextRegisterCommandResultMessageSchema,
1401
- GatewayControlRpcLeaseCommandResultMessageSchema,
2167
+ GatewayControlRpcPrivateLeaseCommandResultMessageSchema,
2168
+ GatewayControlRpcPublicLeaseCommandResultMessageSchema,
1402
2169
  GatewayControlRpcLeaseUseCommandResultMessageSchema,
1403
2170
  GatewayControlRpcControllerHostActionCommandResultMessageSchema,
1404
2171
  GatewayControlRpcOperationCancelCommandResultMessageSchema,
1405
- GatewayControlRpcRecoveryCommandResultMessageSchema
2172
+ GatewayControlRpcRecoveryCommandResultMessageSchema,
2173
+ GatewayControlRpcApprovalAdmissionCommandResultMessageSchema,
2174
+ GatewayControlRpcApprovalDispatchCommandResultMessageSchema,
2175
+ GatewayControlRpcToolVmBindingRequestCommandResultMessageSchema,
2176
+ GatewayControlRpcToolVmBindingPublishCommandResultMessageSchema
1406
2177
  ]);
1407
2178
  const GatewayControlRpcCommandMessageSchema = z.discriminatedUnion("operation", [
2179
+ GatewayControlRpcDomainCorrelationSchema.extend({
2180
+ kind: z.literal("command"),
2181
+ operation: z.literal("tool_vm_binding_request"),
2182
+ payload: GatewayControlToolVmBindingRequestPayloadSchema
2183
+ }).strict(),
2184
+ GatewayControlRpcDomainCorrelationSchema.extend({
2185
+ kind: z.literal("command"),
2186
+ operation: z.literal("tool_vm_binding_publish"),
2187
+ payload: GatewayControlToolVmBindingPublicationSchema
2188
+ }).strict(),
1408
2189
  GatewayControlRpcDomainCorrelationSchema.extend({
1409
2190
  kind: z.literal("command"),
1410
2191
  operation: z.literal("control_ping"),
@@ -1465,6 +2246,16 @@ const GatewayControlRpcCommandMessageSchema = z.discriminatedUnion("operation",
1465
2246
  operation: z.literal("tool_portal_controller_host_action"),
1466
2247
  payload: GatewayControlToolPortalControllerHostActionPayloadSchema
1467
2248
  }).strict(),
2249
+ GatewayControlRpcDomainCorrelationSchema.extend({
2250
+ kind: z.literal("command"),
2251
+ operation: z.literal("tool_portal_admission_reserve"),
2252
+ payload: GatewayControlToolPortalAdmissionReservePayloadSchema
2253
+ }).strict(),
2254
+ GatewayControlRpcDomainCorrelationSchema.extend({
2255
+ kind: z.literal("command"),
2256
+ operation: z.literal("tool_portal_dispatch_arm"),
2257
+ payload: GatewayControlToolPortalDispatchArmPayloadSchema
2258
+ }).strict(),
1468
2259
  GatewayControlRpcDomainCorrelationSchema.extend({
1469
2260
  kind: z.literal("command"),
1470
2261
  operation: z.literal("operation_cancel"),
@@ -1476,16 +2267,28 @@ const GatewayControlRpcCommandMessageSchema = z.discriminatedUnion("operation",
1476
2267
  payload: GatewayControlRecoveryCommandPayloadSchema
1477
2268
  }).strict()
1478
2269
  ]);
1479
- const GatewayControlRpcEventMessageSchema = z.discriminatedUnion("operation", [GatewayControlRpcDomainCorrelationSchema.extend({
1480
- kind: z.literal("event"),
1481
- operation: z.literal("health_event"),
1482
- payload: GatewayControlHealthEventPayloadSchema
1483
- }).strict(), GatewayControlRpcDomainCorrelationSchema.extend({
1484
- kind: z.literal("event"),
1485
- operation: z.literal("runtime_status"),
1486
- payload: GatewayControlRuntimeStatusPayloadSchema
1487
- }).strict()]);
1488
- const GatewayControlEventOnlyOperationSchema = z.enum(["health_event", "runtime_status"]);
2270
+ const GatewayControlRpcEventMessageSchema = z.discriminatedUnion("operation", [
2271
+ GatewayControlRpcDomainCorrelationSchema.extend({
2272
+ kind: z.literal("event"),
2273
+ operation: z.literal("gateway_runtime_readiness"),
2274
+ payload: GatewayRuntimeReadinessSnapshotSchema
2275
+ }).strict(),
2276
+ GatewayControlRpcDomainCorrelationSchema.extend({
2277
+ kind: z.literal("event"),
2278
+ operation: z.literal("health_event"),
2279
+ payload: GatewayControlHealthEventPayloadSchema
2280
+ }).strict(),
2281
+ GatewayControlRpcDomainCorrelationSchema.extend({
2282
+ kind: z.literal("event"),
2283
+ operation: z.literal("runtime_status"),
2284
+ payload: GatewayControlRuntimeStatusPayloadSchema
2285
+ }).strict()
2286
+ ]);
2287
+ const GatewayControlEventOnlyOperationSchema = z.enum([
2288
+ "gateway_runtime_readiness",
2289
+ "health_event",
2290
+ "runtime_status"
2291
+ ]);
1489
2292
  const GatewayControlRpcCommandResultOperationSchema = GatewayControlRpcOperationSchema.exclude(GatewayControlEventOnlyOperationSchema.options);
1490
2293
  const GatewayControlRpcMessageSchema = z.union([
1491
2294
  GatewayControlHeartbeatMessageSchema,
@@ -1497,6 +2300,7 @@ const gatewayControlDeliveryPolicyByKind = { heartbeat: "critical_idempotent" };
1497
2300
  const gatewayControlDeliveryPolicyByOperation = {
1498
2301
  caller_context_register: "critical_idempotent",
1499
2302
  control_ping: "acked_idempotent",
2303
+ gateway_runtime_readiness: "latest_wins",
1500
2304
  health_event: "append_only_observation",
1501
2305
  lease_create: "critical_idempotent",
1502
2306
  lease_get: "acked_idempotent",
@@ -1510,7 +2314,11 @@ const gatewayControlDeliveryPolicyByOperation = {
1510
2314
  operation_cancel: "acked_idempotent",
1511
2315
  recovery_command: "critical_idempotent",
1512
2316
  runtime_status: "latest_wins",
1513
- tool_portal_controller_host_action: "single_use_critical"
2317
+ tool_vm_binding_publish: "critical_idempotent",
2318
+ tool_vm_binding_request: "critical_idempotent",
2319
+ tool_portal_controller_host_action: "single_use_critical",
2320
+ tool_portal_admission_reserve: "single_use_critical",
2321
+ tool_portal_dispatch_arm: "single_use_critical"
1514
2322
  };
1515
2323
  function deriveGatewayControlDeliveryPolicy(envelope) {
1516
2324
  if (envelope.operation === "lease_create" && envelope.idempotencyKey === void 0) return "single_use_critical";
@@ -1530,6 +2338,7 @@ function assertGatewayControlEnvelopeDeliveryPolicy(envelope) {
1530
2338
  const gatewayControlCommandExecutionTimeoutMsByOperation = {
1531
2339
  caller_context_register: 5e3,
1532
2340
  control_ping: 5e3,
2341
+ gateway_runtime_readiness: 5e3,
1533
2342
  health_event: 5e3,
1534
2343
  lease_create: 18e4,
1535
2344
  lease_get: 5e3,
@@ -1543,7 +2352,11 @@ const gatewayControlCommandExecutionTimeoutMsByOperation = {
1543
2352
  operation_cancel: 5e3,
1544
2353
  recovery_command: 1e4,
1545
2354
  runtime_status: 5e3,
1546
- tool_portal_controller_host_action: 12e4
2355
+ tool_vm_binding_publish: 1e4,
2356
+ tool_vm_binding_request: 18e4,
2357
+ tool_portal_controller_host_action: 12e4,
2358
+ tool_portal_admission_reserve: 1e4,
2359
+ tool_portal_dispatch_arm: 1e4
1547
2360
  };
1548
2361
  function buildGatewayControlJsonSchemas() {
1549
2362
  return {
@@ -1573,6 +2386,6 @@ function assertGatewayControlDomainRegistered() {
1573
2386
  return KnownControlDomainSchema.extract(["gateway_control"]).parse("gateway_control");
1574
2387
  }
1575
2388
  //#endregion
1576
- export { ControllerInitiatedGatewayOperationCancelPayloadSchema, GATEWAY_CONTROL_ADMISSION_EXECUTION_LIMITS, GATEWAY_CONTROL_ADMISSION_LIMITS, GATEWAY_CONTROL_PROCESS_ADMISSION_LIMITS, GatewayControlActiveOperationIdSchema, GatewayControlAdmissionPrincipalSchema, GatewayControlCallerContextAgentAuthoritySchema, GatewayControlCallerContextProofAlgorithmSchema, GatewayControlCallerContextProofSchema, GatewayControlCallerContextRefSchema, GatewayControlCallerContextRegisterPayloadSchema, GatewayControlCapabilityRefSchema, GatewayControlControllerHostProbeActionResultSchema, GatewayControlControllerHostProbePayloadSchema, GatewayControlControllerHostProbeResultSchema, GatewayControlControllerRequestHealthOperationSchema, GatewayControlDomainSchema, GatewayControlEventOnlyOperationSchema, GatewayControlForbiddenPayloadFieldSchema, GatewayControlHealthEventPayloadSchema, GatewayControlHealthEventResultSchema, GatewayControlHeartbeatPayloadSchema, GatewayControlHelloResponseSchema, GatewayControlHelloSchema, GatewayControlLeaseCreateIntentPayloadSchema, GatewayControlLeaseIdPayloadSchema, GatewayControlLeaseReacquireIntentPayloadSchema, GatewayControlLeaseRejectionReasonSchema, GatewayControlLeaseSnapshotSchema, GatewayControlLeaseStaleEvidenceSchema, GatewayControlLeaseUseEndPayloadSchema, GatewayControlLeaseUseHeartbeatPayloadSchema, GatewayControlLeaseUseSnapshotSchema, GatewayControlLeaseUseStartPayloadSchema, GatewayControlOperationCancelPayloadSchema, GatewayControlPingPayloadSchema, GatewayControlProviderRuntimeHealthSchema, GatewayControlRecoveryCommandPayloadSchema, GatewayControlRegisteredCallerContextRefSchema, GatewayControlRpcBareResponsePayloadSchema, GatewayControlRpcCallerContextResponsePayloadSchema, GatewayControlRpcCommandMessageSchema, GatewayControlRpcCommandResultMessageSchema, GatewayControlRpcCommandResultOperationSchema, GatewayControlRpcControllerHostActionResponsePayloadSchema, GatewayControlRpcDomainCorrelationSchema, GatewayControlRpcErrorSchema, GatewayControlRpcEventMessageSchema, GatewayControlRpcLeaseResponsePayloadSchema, GatewayControlRpcLeaseUseResponsePayloadSchema, GatewayControlRpcMessageSchema, GatewayControlRpcOperationCancelResponsePayloadSchema, GatewayControlRpcOperationSchema, GatewayControlRpcResponseBasePayloadSchema, GatewayControlRpcResponsePayloadSchema, GatewayControlRpcResultSchema, GatewayControlRuntimeFindingSchema, GatewayControlRuntimeStatusPayloadSchema, GatewayControlSessionHealthOperationSchema, GatewayControlSessionStateSchema, GatewayControlToolCallCorrelationSchema, GatewayControlToolPortalControllerHostActionPayloadSchema, GatewayControlToolPortalControllerHostActionResultSchema, GatewayControlToolVmLeaseCallerContextStateSchema, GatewayControlToolVmLeaseLifecycleEventRoleSchema, GatewayControlToolVmLeaseLifecycleTransitionSchema, GatewayControlToolVmSshAccessSchema, GatewayControlToolVmSshHealthOperationSchema, GatewayControlTrustedCallerContextIdSchema, GatewayControlTrustedLeaseContextSchema, GatewayControlZoneGitCommitSummarySchema, GatewayControlZoneGitPushControllerHostActionPayloadSchema, GatewayControlZoneGitPushControllerHostActionResultSchema, GatewayControlZoneGitPushResultSchema, GatewayInitiatedOperationCancelPayloadSchema, assertGatewayControlDomainRegistered, assertGatewayControlEnvelopeDeliveryPolicy, buildGatewayControlCallerContextAgentAuthorityPayload, buildGatewayControlCallerContextProofPayload, buildGatewayControlJsonSchemas, classifyGatewayControlAdmission, createGatewayControlAdmissionExecutor, createGatewayControlAdmissionScheduler, createGatewayControlProcessAdmission, deriveGatewayControlDeliveryPolicy, gatewayControlCommandExecutionTimeoutMsByOperation, gatewayControlDeliveryPolicyByKind, gatewayControlDeliveryPolicyByOperation };
2389
+ export { ControllerInitiatedGatewayOperationCancelPayloadSchema, GATEWAY_CONTROL_ADMISSION_EXECUTION_LIMITS, GATEWAY_CONTROL_ADMISSION_LIMITS, GATEWAY_CONTROL_PROCESS_ADMISSION_LIMITS, GATEWAY_RUNTIME_APPROVAL_AUDIENCE, GATEWAY_RUNTIME_ATTACHMENT_SNAPSHOT_VERSION, GATEWAY_RUNTIME_PORTAL_ADMISSION_FILE_NAME, GATEWAY_RUNTIME_READINESS_SNAPSHOT_VERSION, GATEWAY_RUNTIME_TOOL_PORTAL_CONTROL_GUEST_PORT, GATEWAY_RUNTIME_TOOL_PORTAL_CONTROL_LISTEN_HOST, GATEWAY_RUNTIME_TOOL_PORTAL_PRODUCTION_CONTROL_ENDPOINT, GatewayControlActiveOperationIdSchema, GatewayControlCallerContextAgentAuthoritySchema, GatewayControlCallerContextProofAlgorithmSchema, GatewayControlCallerContextProofSchema, GatewayControlCallerContextRefSchema, GatewayControlCallerContextRegisterPayloadSchema, GatewayControlCapabilityRefSchema, GatewayControlControllerHostProbeActionResultSchema, GatewayControlControllerHostProbePayloadSchema, GatewayControlControllerHostProbeResultSchema, GatewayControlControllerRequestHealthOperationSchema, GatewayControlDomainSchema, GatewayControlEventOnlyOperationSchema, GatewayControlForbiddenPayloadFieldSchema, GatewayControlHealthEventPayloadSchema, GatewayControlHealthEventResultSchema, GatewayControlHeartbeatPayloadSchema, GatewayControlHelloResponseSchema, GatewayControlHelloSchema, GatewayControlLeaseCreateIntentPayloadSchema, GatewayControlLeaseIdPayloadSchema, GatewayControlLeaseReacquireIntentPayloadSchema, GatewayControlLeaseRejectionReasonSchema, GatewayControlLeaseSnapshotSchema, GatewayControlLeaseStaleEvidenceSchema, GatewayControlLeaseUseEndPayloadSchema, GatewayControlLeaseUseHeartbeatPayloadSchema, GatewayControlLeaseUseSnapshotSchema, GatewayControlLeaseUseStartPayloadSchema, GatewayControlOperationCancelPayloadSchema, GatewayControlPingPayloadSchema, GatewayControlPrivateLeaseSnapshotSchema, GatewayControlPrivateToolVmSshAccessSchema, GatewayControlProviderRuntimeHealthSchema, GatewayControlPublicLeaseSnapshotSchema, GatewayControlRecoveryCommandPayloadSchema, GatewayControlRegisteredCallerContextRefSchema, GatewayControlRpcApprovalAdmissionResponsePayloadSchema, GatewayControlRpcApprovalDispatchResponsePayloadSchema, GatewayControlRpcBareResponsePayloadSchema, GatewayControlRpcCallerContextResponsePayloadSchema, GatewayControlRpcCommandMessageSchema, GatewayControlRpcCommandResultMessageSchema, GatewayControlRpcCommandResultOperationSchema, GatewayControlRpcControllerHostActionResponsePayloadSchema, GatewayControlRpcDomainCorrelationSchema, GatewayControlRpcErrorSchema, GatewayControlRpcEventMessageSchema, GatewayControlRpcLeaseResponsePayloadSchema, GatewayControlRpcLeaseUseResponsePayloadSchema, GatewayControlRpcMessageSchema, GatewayControlRpcOperationCancelResponsePayloadSchema, GatewayControlRpcOperationSchema, GatewayControlRpcPrivateLeaseResponsePayloadSchema, GatewayControlRpcPublicLeaseResponsePayloadSchema, GatewayControlRpcResponseBasePayloadSchema, GatewayControlRpcResponsePayloadSchema, GatewayControlRpcResultSchema, GatewayControlRpcToolVmBindingRequestResponsePayloadSchema, GatewayControlRuntimeFindingSchema, GatewayControlRuntimeStatusPayloadSchema, GatewayControlSessionHealthOperationSchema, GatewayControlSessionStateSchema, GatewayControlToolCallCorrelationSchema, GatewayControlToolPortalAdmissionReservePayloadSchema, GatewayControlToolPortalControllerHostActionPayloadSchema, GatewayControlToolPortalControllerHostActionResultSchema, GatewayControlToolPortalDispatchArmPayloadSchema, GatewayControlToolVmBindingAccessGrantSchema, GatewayControlToolVmBindingIdentitySchema, GatewayControlToolVmBindingPublicationAuthoritySchema, GatewayControlToolVmBindingPublicationSchema, GatewayControlToolVmBindingRequestPayloadSchema, GatewayControlToolVmBindingRequestResultSchema, GatewayControlToolVmLeaseCallerContextStateSchema, GatewayControlToolVmLeaseLifecycleEventRoleSchema, GatewayControlToolVmLeaseLifecycleTransitionSchema, GatewayControlToolVmSshAccessSchema, GatewayControlToolVmSshHealthOperationSchema, GatewayControlTrustedCallerContextIdSchema, GatewayControlWorkspaceGitCommitSummarySchema, GatewayControlWorkspaceGitPushControllerHostActionPayloadSchema, GatewayControlWorkspaceGitPushControllerHostActionResultSchema, GatewayControlWorkspaceGitPushResultSchema, GatewayInitiatedOperationCancelPayloadSchema, GatewayRuntimeApprovalAdmissionResultSchema, GatewayRuntimeApprovalAmbiguousReasonSchema, GatewayRuntimeApprovalArmDispatchCommandSchema, GatewayRuntimeApprovalArmDispatchResultSchema, GatewayRuntimeApprovalAuthorityContextSchema, GatewayRuntimeApprovalCallSchema, GatewayRuntimeApprovalChallengeIntentSchema, GatewayRuntimeApprovalChallengeSchema, GatewayRuntimeApprovalDecisionCommandSchema, GatewayRuntimeApprovalDispatchGrantSchema, GatewayRuntimeApprovalDispatchReservationSchema, GatewayRuntimeApprovalFingerprintSchema, GatewayRuntimeApprovalNotDispatchedReasonSchema, GatewayRuntimeApprovalRevokeCommandSchema, GatewayRuntimeApprovalSemanticRevisionCohortSchema, GatewayRuntimeAttachmentSnapshotSchema, GatewayRuntimeControllerHostActionApprovalReservationDispatchAuthoritySchema, GatewayRuntimeControllerHostActionDirectDispatchAuthoritySchema, GatewayRuntimeControllerHostActionDispatchReservationSchema, GatewayRuntimeExpectedAttachmentIdentitySchema, GatewayRuntimeFatalEvidenceSchema, GatewayRuntimeFrameworkIdentitySchema, GatewayRuntimeFrameworkKindSchema, GatewayRuntimeGatewayDispatchReservationSchema, GatewayRuntimeManagedPluginClientKindSchema, GatewayRuntimeMcpProviderApprovalGrantDispatchAuthoritySchema, GatewayRuntimeMcpProviderDirectDispatchAuthoritySchema, GatewayRuntimeMcpProviderDispatchGrantSchema, GatewayRuntimeMcpProviderDispatchReservationSchema, GatewayRuntimePortalAdmissionMaterialSchema, GatewayRuntimePortalSemanticSnapshotSchema, GatewayRuntimePortalSurfaceClassSchema, GatewayRuntimeReadinessSnapshotSchema, GatewayRuntimeRequiredBackendKindSchema, GatewayRuntimeRequiredBackendsReadinessSchema, GatewayRuntimeToolPortalDispatchAuthoritySchema, GatewayRuntimeToolPortalProductionControlEndpointSchema, GatewayRuntimeToolVmRunnerApprovalGrantDispatchAuthoritySchema, GatewayRuntimeToolVmRunnerDirectDispatchAuthoritySchema, GatewayRuntimeToolVmRunnerDispatchGrantSchema, GatewayRuntimeToolVmRunnerDispatchReservationSchema, GatewayRuntimeTrustedInvocationContextSchema, GatewayRuntimeTrustedInvocationCorrelationSchema, GatewayRuntimeTrustedInvocationPrincipalSchema, GatewayRuntimeTrustedInvocationRequesterSchema, GatewayRuntimeUdsPublicationSnapshotSchema, ManagedAgentProjectionSchema, assertGatewayControlDomainRegistered, assertGatewayControlEnvelopeDeliveryPolicy, assertGatewayRuntimePortalSemanticSnapshotMatchesInputs, buildGatewayControlCallerContextAgentAuthorityPayload, buildGatewayControlCallerContextProofPayload, buildGatewayControlJsonSchemas, classifyGatewayControlAdmission, createGatewayControlAdmissionExecutor, createGatewayControlAdmissionScheduler, createGatewayControlProcessAdmission, createGatewayRuntimeAttachmentSnapshot, createGatewayRuntimeReadinessSnapshot, deriveGatewayControlDeliveryPolicy, deriveGatewayControlStablePrincipal, deriveGatewayRuntimeApprovalFingerprint, deriveGatewayRuntimeApprovalId, deriveGatewayRuntimePortalSemanticSnapshot, deriveManagedAgentProjection, gatewayControlCommandExecutionTimeoutMsByOperation, gatewayControlDeliveryPolicyByKind, gatewayControlDeliveryPolicyByOperation };
1577
2390
 
1578
2391
  //# sourceMappingURL=index.js.map