@kici-dev/engine 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -6
  3. package/dist/audit/access-log-policy.d.ts +97 -0
  4. package/dist/audit/access-log-policy.js +195 -0
  5. package/dist/audit/activity.d.ts +156 -0
  6. package/dist/audit/activity.js +175 -0
  7. package/dist/audit/retention-policy.d.ts +157 -0
  8. package/dist/audit/retention-policy.js +364 -0
  9. package/dist/bundler/index.d.ts +3 -0
  10. package/dist/bundler/index.js +3 -0
  11. package/dist/bundler/rolldown-config.d.ts +41 -0
  12. package/dist/bundler/rolldown-config.js +40 -0
  13. package/dist/chunk-gOLHoazu.js +4 -0
  14. package/dist/env/environment-allowlist.d.ts +45 -0
  15. package/dist/env/environment-allowlist.js +69 -0
  16. package/dist/environment/index.d.ts +3 -0
  17. package/dist/environment/index.js +3 -0
  18. package/dist/environment/scope-resolver.d.ts +35 -0
  19. package/dist/environment/scope-resolver.js +77 -0
  20. package/dist/environment/types.d.ts +98 -0
  21. package/dist/environment/types.js +2 -0
  22. package/dist/index.d.ts +54 -0
  23. package/dist/index.js +45 -0
  24. package/dist/labels.d.ts +106 -0
  25. package/dist/labels.js +162 -0
  26. package/dist/metrics/metric-catalog.generated.d.ts +400 -0
  27. package/dist/metrics/metric-catalog.generated.js +510 -0
  28. package/dist/protocol/dashboard-global-workflows.d.ts +9 -0
  29. package/dist/protocol/dashboard-global-workflows.js +3 -0
  30. package/dist/protocol/event-log-payload.d.ts +16 -0
  31. package/dist/protocol/event-log-payload.js +21 -0
  32. package/dist/protocol/messages/access-log.d.ts +545 -0
  33. package/dist/protocol/messages/access-log.js +175 -0
  34. package/dist/protocol/messages/actor.d.ts +100 -0
  35. package/dist/protocol/messages/actor.js +139 -0
  36. package/dist/protocol/messages/auth.d.ts +25 -0
  37. package/dist/protocol/messages/auth.js +36 -0
  38. package/dist/protocol/messages/browser.d.ts +369 -0
  39. package/dist/protocol/messages/browser.js +225 -0
  40. package/dist/protocol/messages/capabilities.d.ts +46 -0
  41. package/dist/protocol/messages/capabilities.js +42 -0
  42. package/dist/protocol/messages/common.d.ts +53 -0
  43. package/dist/protocol/messages/common.js +55 -0
  44. package/dist/protocol/messages/dashboard-global-workflows.d.ts +166 -0
  45. package/dist/protocol/messages/dashboard-global-workflows.js +80 -0
  46. package/dist/protocol/messages/dashboard.d.ts +4068 -0
  47. package/dist/protocol/messages/dashboard.js +1237 -0
  48. package/dist/protocol/messages/event-log.d.ts +49 -0
  49. package/dist/protocol/messages/event-log.js +45 -0
  50. package/dist/protocol/messages/execution-status.d.ts +164 -0
  51. package/dist/protocol/messages/execution-status.js +166 -0
  52. package/dist/protocol/messages/join.d.ts +18 -0
  53. package/dist/protocol/messages/join.js +28 -0
  54. package/dist/protocol/messages/log-pull.d.ts +27 -0
  55. package/dist/protocol/messages/log-pull.js +36 -0
  56. package/dist/protocol/messages/observe.d.ts +75 -0
  57. package/dist/protocol/messages/observe.js +70 -0
  58. package/dist/protocol/messages/orchestrator-agent.d.ts +606 -0
  59. package/dist/protocol/messages/orchestrator-agent.js +481 -0
  60. package/dist/protocol/messages/peer.d.ts +795 -0
  61. package/dist/protocol/messages/peer.js +372 -0
  62. package/dist/protocol/messages/platform-orchestrator.d.ts +1888 -0
  63. package/dist/protocol/messages/platform-orchestrator.js +379 -0
  64. package/dist/protocol/messages/run-events.d.ts +155 -0
  65. package/dist/protocol/messages/run-events.js +115 -0
  66. package/dist/protocol/messages/saas-orchestrator.d.ts +2179 -0
  67. package/dist/protocol/messages/source-registration.d.ts +103 -0
  68. package/dist/protocol/messages/source-registration.js +109 -0
  69. package/dist/protocol/messages/test-run.d.ts +59 -0
  70. package/dist/protocol/messages/test-run.js +52 -0
  71. package/dist/protocol/version.d.ts +12 -0
  72. package/dist/protocol/version.js +17 -0
  73. package/dist/provider/changed-files-fetcher.d.ts +24 -0
  74. package/dist/provider/changed-files-fetcher.js +2 -0
  75. package/dist/provider/check-run-conclusion.d.ts +15 -0
  76. package/dist/provider/check-run-conclusion.js +19 -0
  77. package/dist/provider/check-status-poster.d.ts +15 -0
  78. package/dist/provider/check-status-poster.js +2 -0
  79. package/dist/provider/clone-token-provider.d.ts +58 -0
  80. package/dist/provider/clone-token-provider.js +2 -0
  81. package/dist/provider/contributor-resolver.d.ts +22 -0
  82. package/dist/provider/contributor-resolver.js +2 -0
  83. package/dist/provider/index.d.ts +23 -0
  84. package/dist/provider/index.js +3 -0
  85. package/dist/provider/lock-file-fetcher.d.ts +24 -0
  86. package/dist/provider/lock-file-fetcher.js +2 -0
  87. package/dist/provider/repo-url-builder.d.ts +35 -0
  88. package/dist/provider/repo-url-builder.js +2 -0
  89. package/dist/provider/types.d.ts +9 -0
  90. package/dist/provider/types.js +2 -0
  91. package/dist/provider/webhook-normalizer.d.ts +163 -0
  92. package/dist/provider/webhook-normalizer.js +2 -0
  93. package/dist/registration/registerable-trigger-type.d.ts +52 -0
  94. package/dist/registration/registerable-trigger-type.js +56 -0
  95. package/dist/scaler/resource-types.d.ts +90 -0
  96. package/dist/scaler/resource-types.js +99 -0
  97. package/dist/scaler/scaler-backend-type.d.ts +16 -0
  98. package/dist/scaler/scaler-backend-type.js +20 -0
  99. package/dist/secrets/index.d.ts +7 -0
  100. package/dist/secrets/index.js +2 -0
  101. package/dist/secrets/types.d.ts +138 -0
  102. package/dist/secrets/types.js +2 -0
  103. package/dist/state-machine/index.d.ts +2 -0
  104. package/dist/state-machine/index.js +3 -0
  105. package/dist/state-machine/machine.d.ts +34 -0
  106. package/dist/state-machine/machine.js +103 -0
  107. package/dist/state-machine/types.d.ts +34 -0
  108. package/dist/state-machine/types.js +15 -0
  109. package/dist/trigger/decision-trace.d.ts +41 -0
  110. package/dist/trigger/decision-trace.js +30 -0
  111. package/dist/trigger/jsonpath-matcher.d.ts +27 -0
  112. package/dist/trigger/jsonpath-matcher.js +92 -0
  113. package/dist/trigger/matcher.d.ts +29 -0
  114. package/dist/trigger/matcher.js +704 -0
  115. package/dist/trigger/trigger-event-type.d.ts +14 -0
  116. package/dist/trigger/trigger-event-type.js +66 -0
  117. package/dist/trigger/types.d.ts +524 -0
  118. package/dist/trigger/types.js +48 -0
  119. package/dist/webhook/signature.d.ts +15 -0
  120. package/dist/webhook/signature.js +32 -0
  121. package/dist/ws/close-codes.d.ts +28 -0
  122. package/dist/ws/close-codes.js +33 -0
  123. package/dist/ws/rate-limiter.d.ts +86 -0
  124. package/dist/ws/rate-limiter.js +136 -0
  125. package/dist/ws/ws-like.d.ts +12 -0
  126. package/dist/ws/ws-like.js +2 -0
  127. package/package.json +54 -6
  128. package/sbom.spdx.json +202 -0
  129. package/index.js +0 -3
@@ -0,0 +1,379 @@
1
+ import "../../chunk-gOLHoazu.js";
2
+ import { heartbeatSchema } from "./common.js";
3
+ import { authFailureSchema, authRequestSchema, authSuccessSchema } from "./auth.js";
4
+ import { executionStatusSchema, jobStatusForwardSchema, stateReplaySchema, stepStatusForwardSchema } from "./execution-status.js";
5
+ import { sourceDeregisterAckSchema, sourceDeregisterSchema, sourceRegistrationAckSchema, sourceRegistrationSchema } from "./source-registration.js";
6
+ import { dashboardAccessLogListRequestSchema } from "./access-log.js";
7
+ import { dashboardOrchLogsRequestSchema, jobContextMessageSchema, runEventMessageSchema } from "./run-events.js";
8
+ import { globalWorkflowsGetRequestSchema, globalWorkflowsUpdateRequestSchema } from "./dashboard-global-workflows.js";
9
+ import { backendGetRequestSchema, backendSyncRequestSchema, backendTestRequestSchema, backendsListRequestSchema, backendsSyncAllRequestSchema, dashboardDiagnosticsRequestSchema, dashboardEventLogDetailRequestSchema, dashboardEventLogListRequestSchema, dashboardEventLogPayloadStreamRequestSchema, dashboardPayloadRequestSchema, dashboardRunDetailRequestSchema, dashboardScalerAgentsRequestSchema, dashboardScalerCapacityRequestSchema, dashboardStepLogsRequestSchema, envBindingsListRequestSchema, envBindingsSetRequestSchema, envCreateRequestSchema, envDeleteRequestSchema, envGetRequestSchema, envHistoryRequestSchema, envListRequestSchema, envSecretDeleteRequestSchema, envSecretScopeCreateRequestSchema, envSecretScopeDeleteRequestSchema, envSecretScopeRenameRequestSchema, envSecretSetRequestSchema, envSecretsListRequestSchema, envSourceOverrideDeleteRequestSchema, envSourceOverrideSetRequestSchema, envSourceOverridesListRequestSchema, envUpdateRequestSchema, envVarDeleteRequestSchema, envVarSetRequestSchema, envVarsListRequestSchema, heldRunApproveRequestSchema, heldRunRejectRequestSchema, heldRunsListRequestSchema, manualScheduleRequestSchema, registrationDeleteRequestSchema, registrationDisableRequestSchema, registrationsListRequestSchema, runCancelRequestSchema, runRerunRequestSchema } from "./dashboard.js";
10
+ import { z } from "zod";
11
+ //#region src/protocol/messages/platform-orchestrator.ts
12
+ /** Trust policy update pushed from Platform to orchestrator when policy or identity links change. */
13
+ const trustPolicyUpdateSchema = z.object({
14
+ type: z.literal("trust_policy.update"),
15
+ orgId: z.string(),
16
+ policy: z.object({
17
+ forkPolicy: z.enum([
18
+ "hold",
19
+ "reject",
20
+ "allow"
21
+ ]),
22
+ unknownContributorPolicy: z.enum(["hold", "reject"]),
23
+ workflowChangePolicy: z.enum([
24
+ "hold",
25
+ "reject",
26
+ "allow"
27
+ ]),
28
+ approvalExpiryHours: z.number()
29
+ }),
30
+ identityLinks: z.array(z.object({
31
+ userId: z.string(),
32
+ provider: z.string(),
33
+ providerUsername: z.string(),
34
+ /**
35
+ * Immutable IDP-side numeric id (e.g. GitHub's `id`).
36
+ * Nullable during the backfill window for legacy rows that
37
+ * predate the column. Trust resolver prefers this over
38
+ * `providerUsername` and (in the strict end-state) refuses
39
+ * trust when both sides have it null.
40
+ */
41
+ providerUserId: z.string().nullish()
42
+ })),
43
+ memberCiTrustLevels: z.record(z.string(), z.enum([
44
+ "none",
45
+ "read",
46
+ "write",
47
+ "admin"
48
+ ]))
49
+ });
50
+ /**
51
+ * Internal shape of a fully-reassembled, HMAC-verified webhook relay handed
52
+ * to the orchestrator's `onWebhookRelay` callback.
53
+ *
54
+ * NOT a wire-parseable schema: this shape is intentionally absent from the
55
+ * `platformToOrchestratorMessageSchema` discriminated union so that a rogue
56
+ * or compromised Platform process (A10) cannot fabricate one and bypass the
57
+ * on-orchestrator HMAC verification gate. The only legitimate construction
58
+ * site is `completeChunkedRelay` in `packages/orchestrator/src/ws/platform-client.ts`,
59
+ * which synthesizes this shape AFTER `onVerifyInbound` returns `'accepted'`.
60
+ *
61
+ * Migration `packages/platform/src/db/migrations/012_drop_webhook_secret_columns.ts`
62
+ * makes the orch-side `verifyInboundWebhook` (called from `onVerifyInbound` on
63
+ * the chunked relay path `webhook.relay.start` / `webhook.relay.chunk`) the
64
+ * sole trust boundary against a malicious Platform; keeping this schema OUT
65
+ * of the wire union enforces that invariant statically.
66
+ */
67
+ const webhookRelaySchema = z.object({
68
+ type: z.literal("webhook.relay"),
69
+ messageId: z.string(),
70
+ routingKey: z.string(),
71
+ deliveryId: z.string(),
72
+ event: z.string(),
73
+ action: z.string().nullish(),
74
+ payload: z.unknown(),
75
+ /** Trace ID propagated across tiers for distributed tracing. */
76
+ requestId: z.string().optional()
77
+ });
78
+ /**
79
+ * HMAC verification + processing result returned by orchestrator in webhook.ack.
80
+ *
81
+ * Used in the chunked relay protocol where the orchestrator (not Platform)
82
+ * verifies the inbound HMAC signature against its locally-stored secret.
83
+ *
84
+ * - `accepted`: signature verified (or method is `none`/IP allowlist OK), webhook
85
+ * handed to the existing webhook processing pipeline.
86
+ * - `rejected_signature`: signature did not match any rotation secret. Maps to HTTP 401.
87
+ * - `rejected_unknown_source`: the routing key is not registered on this orchestrator
88
+ * (or the provider is not yet implemented). Maps to HTTP 404 + Platform negative cache.
89
+ * - `rejected_misconfigured`: the orchestrator has the source but its verification config
90
+ * is malformed (e.g. invalid JSON in generic_webhook_sources.verification_config) or
91
+ * the chunked stream itself was malformed (out-of-order, oversize, base64 decode fail,
92
+ * missing chunks at finalization, TTL expiry). Maps to HTTP 500.
93
+ */
94
+ const WebhookRelayResult = z.enum([
95
+ "accepted",
96
+ "rejected_signature",
97
+ "rejected_unknown_source",
98
+ "rejected_misconfigured"
99
+ ]);
100
+ /**
101
+ * Maximum total body size accepted by the chunked webhook relay protocol.
102
+ * 25 MiB matches GitHub's own webhook payload cap. Senders that need higher must
103
+ * connect their orchestrator directly (bypassing Platform).
104
+ */
105
+ const WEBHOOK_RELAY_MAX_BODY_BYTES = 25 * 1024 * 1024;
106
+ /**
107
+ * Recommended raw chunk size for the chunked relay protocol. 64 KiB raw becomes
108
+ * ~85 KiB base64 in JSON; permessage-deflate compresses it well. Sender (Platform)
109
+ * picks the actual size; receiver (orchestrator) just enforces totalSize and chunkCount.
110
+ */
111
+ const WEBHOOK_RELAY_CHUNK_SIZE = 64 * 1024;
112
+ /**
113
+ * Start frame of the chunked webhook relay protocol (Platform -> orchestrator).
114
+ * Carries metadata + signature inputs only; body bytes follow in subsequent
115
+ * webhook.relay.chunk frames correlated by messageId.
116
+ *
117
+ * The orchestrator allocates a per-messageId reassembly buffer on receipt.
118
+ * No webhook.ack is sent until the final chunk completes the stream.
119
+ */
120
+ const webhookRelayStartSchema = z.object({
121
+ type: z.literal("webhook.relay.start"),
122
+ messageId: z.string(),
123
+ routingKey: z.string(),
124
+ deliveryId: z.string(),
125
+ event: z.string(),
126
+ action: z.string().nullish(),
127
+ /** Inbound HTTP signature header NAME (lowercased, e.g. `x-hub-signature-256`). */
128
+ signatureHeaderName: z.string().nullish(),
129
+ /** Inbound HTTP signature header VALUE (the claimed HMAC, e.g. `sha256=abc...`). */
130
+ signatureHeader: z.string().nullish(),
131
+ /** Inbound HTTP request client IP for IP-allowlist verification (generic webhooks). */
132
+ clientIp: z.string().nullish(),
133
+ /**
134
+ * Selected inbound headers the orchestrator may need (lowercased keys). Senders
135
+ * SHOULD include only headers the verification path uses (signature alt-name,
136
+ * x-hub-signature, etc.) and route metadata; bulk header forwarding is an
137
+ * anti-pattern.
138
+ */
139
+ headers: z.record(z.string(), z.string()),
140
+ /**
141
+ * Total body size in bytes. Sum of decoded chunk sizes MUST equal this value;
142
+ * mismatch yields rejected_misconfigured. Capped at WEBHOOK_RELAY_MAX_BODY_BYTES.
143
+ */
144
+ totalSize: z.number().int().min(0).max(WEBHOOK_RELAY_MAX_BODY_BYTES),
145
+ /** Number of chunk frames the orchestrator should expect (>= 1). */
146
+ chunkCount: z.number().int().min(1),
147
+ /** Trace ID propagated across tiers for distributed tracing. */
148
+ requestId: z.string().optional()
149
+ });
150
+ /**
151
+ * One chunk of the body. Sequence is 0-indexed and MUST arrive strictly in order;
152
+ * the final=true chunk completes the stream and triggers verify+process on the
153
+ * orchestrator. Decoded chunk bytes (sum across the stream) MUST equal totalSize
154
+ * declared in webhook.relay.start.
155
+ */
156
+ const webhookRelayChunkSchema = z.object({
157
+ type: z.literal("webhook.relay.chunk"),
158
+ messageId: z.string(),
159
+ /** 0-indexed chunk number; must match the orchestrator's expected next sequence. */
160
+ sequence: z.number().int().min(0),
161
+ /** Base64-encoded chunk bytes. */
162
+ data: z.string(),
163
+ /** True on the last chunk in the stream. Triggers verify+process on the orchestrator. */
164
+ final: z.boolean()
165
+ });
166
+ /** Peer discovery notification sent by Platform when another orchestrator shares routing keys. */
167
+ const peerDiscoverSchema = z.object({
168
+ type: z.literal("peer.discover"),
169
+ peer: z.object({
170
+ connectionId: z.string(),
171
+ /** The peer's self-reported cluster instance ID (from source.register). */
172
+ instanceId: z.string().optional(),
173
+ address: z.string().nullable(),
174
+ routingKeys: z.array(z.string())
175
+ })
176
+ });
177
+ /** Full peer list update pushed by Platform to all pool members when membership changes. Replaces peer.discover. */
178
+ const peerUpdateSchema = z.object({
179
+ type: z.literal("peer.update"),
180
+ peers: z.array(z.object({
181
+ connectionId: z.string(),
182
+ instanceId: z.string().optional(),
183
+ address: z.string().nullable(),
184
+ routingKeys: z.array(z.string()),
185
+ orchRole: z.enum(["coordinator", "worker"]).optional()
186
+ }))
187
+ });
188
+ /**
189
+ * Stale check run cleanup request sent by Platform when a replacement orchestrator
190
+ * reconnects after the previous one died. Contains metadata for runs that were
191
+ * marked timed_out_stale by Platform, so the orchestrator can update stuck GitHub
192
+ * check runs that the dead orchestrator left as "in_progress".
193
+ */
194
+ const staleCheckrunCleanupSchema = z.object({
195
+ type: z.literal("stale.checkrun.cleanup"),
196
+ runs: z.array(z.object({
197
+ runId: z.string(),
198
+ provider: z.string(),
199
+ routingKey: z.string(),
200
+ repoIdentifier: z.string(),
201
+ sha: z.string(),
202
+ workflowName: z.string(),
203
+ jobNames: z.array(z.string())
204
+ }))
205
+ });
206
+ /** Periodic OTel metrics push from orchestrator to Platform for centralized observability. */
207
+ const orchMetricsSchema = z.object({
208
+ type: z.literal("orch.metrics"),
209
+ messageId: z.string(),
210
+ metrics: z.array(z.object({
211
+ name: z.string(),
212
+ type: z.enum([
213
+ "counter",
214
+ "histogram",
215
+ "gauge",
216
+ "upDownCounter"
217
+ ]),
218
+ value: z.number().optional(),
219
+ labels: z.record(z.string(), z.string()).optional(),
220
+ buckets: z.array(z.object({
221
+ le: z.number(),
222
+ count: z.number()
223
+ })).optional(),
224
+ count: z.number().optional(),
225
+ sum: z.number().optional()
226
+ })),
227
+ timestamp: z.number()
228
+ });
229
+ /**
230
+ * Acknowledgment that a webhook was received and processing started.
231
+ *
232
+ * Under the chunked relay protocol the orchestrator also reports the HMAC
233
+ * verification outcome here via `result`, and may include a non-secret-bearing
234
+ * diagnostic in `reason` when result is a rejection. Both fields are optional
235
+ * for backward compatibility during the rollout: pre-cutover senders omit them.
236
+ */
237
+ const webhookAckSchema = z.object({
238
+ type: z.literal("webhook.ack"),
239
+ messageId: z.string(),
240
+ deliveryId: z.string(),
241
+ /**
242
+ * Verification + processing outcome. Required from the chunked relay path
243
+ * (commit 3 onwards on the orch side); pre-chunked acks omit this.
244
+ */
245
+ result: WebhookRelayResult.optional(),
246
+ /**
247
+ * Optional non-secret-bearing diagnostic for rejection cases. MUST NOT
248
+ * include any secret material (HMAC keys, bearer tokens, computed signatures).
249
+ */
250
+ reason: z.string().nullish()
251
+ });
252
+ /** Execution lifecycle event reported back to Platform. */
253
+ const executionEventSchema = z.object({
254
+ type: z.literal("execution.event"),
255
+ messageId: z.string(),
256
+ runId: z.string(),
257
+ event: z.enum([
258
+ "started",
259
+ "job_dispatched",
260
+ "job_completed",
261
+ "finished"
262
+ ]),
263
+ data: z.record(z.string(), z.unknown()),
264
+ timestamp: z.number()
265
+ });
266
+ /** Streaming log chunk from job execution. */
267
+ const logChunkSchema = z.object({
268
+ type: z.literal("log.chunk"),
269
+ messageId: z.string(),
270
+ runId: z.string(),
271
+ jobId: z.string(),
272
+ stepIndex: z.number(),
273
+ lines: z.array(z.string()),
274
+ timestamp: z.number()
275
+ });
276
+ /** Cache lookup statistics forwarded from orchestrator to Platform for centralized metrics. */
277
+ const cacheStatsSchema = z.object({
278
+ type: z.literal("cache.stats"),
279
+ cacheType: z.enum(["source", "dep"]),
280
+ hit: z.boolean()
281
+ });
282
+ /** All messages that flow from Platform to Orchestrator.
283
+ *
284
+ * The single-frame `webhookRelaySchema` is intentionally NOT a member of this
285
+ * union: that shape carries an attacker-controlled `payload` and pre-existed
286
+ * the chunked relay's on-orch HMAC verification, so accepting it on the wire
287
+ * would let a compromised Platform (A10) fabricate webhook deliveries that
288
+ * bypass the only trust boundary against a malicious Platform (see the
289
+ * docblock on `webhookRelaySchema` above and migration
290
+ * `packages/platform/src/db/migrations/012_drop_webhook_secret_columns.ts`).
291
+ * The chunked path `webhook.relay.start` + `webhook.relay.chunk` is the sole
292
+ * legitimate route from Platform to `onWebhookRelay`. */
293
+ const platformToOrchestratorMessageSchema = z.discriminatedUnion("type", [
294
+ webhookRelayStartSchema,
295
+ webhookRelayChunkSchema,
296
+ trustPolicyUpdateSchema,
297
+ sourceRegistrationAckSchema,
298
+ sourceDeregisterAckSchema,
299
+ authSuccessSchema,
300
+ authFailureSchema,
301
+ peerDiscoverSchema,
302
+ peerUpdateSchema,
303
+ staleCheckrunCleanupSchema,
304
+ dashboardRunDetailRequestSchema,
305
+ dashboardStepLogsRequestSchema,
306
+ runRerunRequestSchema,
307
+ manualScheduleRequestSchema,
308
+ runCancelRequestSchema,
309
+ dashboardPayloadRequestSchema,
310
+ dashboardOrchLogsRequestSchema,
311
+ envListRequestSchema,
312
+ envGetRequestSchema,
313
+ envCreateRequestSchema,
314
+ envUpdateRequestSchema,
315
+ envDeleteRequestSchema,
316
+ envVarsListRequestSchema,
317
+ envVarSetRequestSchema,
318
+ envVarDeleteRequestSchema,
319
+ envSourceOverridesListRequestSchema,
320
+ envSourceOverrideSetRequestSchema,
321
+ envSourceOverrideDeleteRequestSchema,
322
+ envBindingsListRequestSchema,
323
+ envBindingsSetRequestSchema,
324
+ envSecretsListRequestSchema,
325
+ envSecretSetRequestSchema,
326
+ envSecretDeleteRequestSchema,
327
+ envSecretScopeCreateRequestSchema,
328
+ envSecretScopeRenameRequestSchema,
329
+ envSecretScopeDeleteRequestSchema,
330
+ envHistoryRequestSchema,
331
+ heldRunsListRequestSchema,
332
+ heldRunApproveRequestSchema,
333
+ heldRunRejectRequestSchema,
334
+ registrationsListRequestSchema,
335
+ registrationDisableRequestSchema,
336
+ registrationDeleteRequestSchema,
337
+ dashboardDiagnosticsRequestSchema,
338
+ dashboardScalerCapacityRequestSchema,
339
+ dashboardScalerAgentsRequestSchema,
340
+ backendsListRequestSchema,
341
+ backendGetRequestSchema,
342
+ backendsSyncAllRequestSchema,
343
+ backendSyncRequestSchema,
344
+ backendTestRequestSchema,
345
+ dashboardEventLogListRequestSchema,
346
+ dashboardEventLogDetailRequestSchema,
347
+ dashboardEventLogPayloadStreamRequestSchema,
348
+ globalWorkflowsGetRequestSchema,
349
+ globalWorkflowsUpdateRequestSchema,
350
+ dashboardAccessLogListRequestSchema
351
+ ]);
352
+ /** All messages that flow from Orchestrator to Platform.
353
+ *
354
+ * Note: Dashboard response messages (dashboard.run.detail.response,
355
+ * dashboard.step.logs.response, dashboard.orch.logs.response) are intentionally
356
+ * excluded here. They are parsed separately via dashboardOrchToPlatformSchema so
357
+ * the Platform WS handler can route them to the DashboardProxy for request
358
+ * correlation. */
359
+ const orchestratorToPlatformMessageSchema = z.discriminatedUnion("type", [
360
+ webhookAckSchema,
361
+ executionEventSchema,
362
+ logChunkSchema,
363
+ executionStatusSchema,
364
+ stepStatusForwardSchema,
365
+ jobStatusForwardSchema,
366
+ stateReplaySchema,
367
+ sourceRegistrationSchema,
368
+ sourceDeregisterSchema,
369
+ cacheStatsSchema,
370
+ authRequestSchema,
371
+ heartbeatSchema,
372
+ runEventMessageSchema,
373
+ jobContextMessageSchema,
374
+ orchMetricsSchema
375
+ ]);
376
+ //#endregion
377
+ export { WEBHOOK_RELAY_CHUNK_SIZE, WEBHOOK_RELAY_MAX_BODY_BYTES, WebhookRelayResult, cacheStatsSchema, executionEventSchema, logChunkSchema, orchMetricsSchema, orchestratorToPlatformMessageSchema, peerDiscoverSchema, peerUpdateSchema, platformToOrchestratorMessageSchema, staleCheckrunCleanupSchema, trustPolicyUpdateSchema, webhookAckSchema, webhookRelayChunkSchema, webhookRelaySchema, webhookRelayStartSchema };
378
+
379
+ //# sourceMappingURL=platform-orchestrator.js.map
@@ -0,0 +1,155 @@
1
+ import { z } from 'zod';
2
+ /** Infrastructure event emitted by orchestrator or agent during run lifecycle.
3
+ *
4
+ * SECURITY INVARIANT: This schema MUST NOT carry an `orgId` (or any tenant
5
+ * identifier). Orchestrator WS connections are single-tenant — `authState.orgId`
6
+ * is fixed for the connection's lifetime, derived from a DB-backed API-key hash.
7
+ * The Platform always uses `authState.orgId` for tenant attribution; trusting a
8
+ * wire-supplied field would be a cross-tenant injection primitive (see
9
+ * `docs/architecture/security/ws-tenant-isolation.md`).
10
+ */
11
+ export declare const runEventMessageSchema: z.ZodObject<{
12
+ type: z.ZodLiteral<"run.event">;
13
+ runId: z.ZodString;
14
+ eventType: z.ZodString;
15
+ timestampMs: z.ZodNumber;
16
+ sourceService: z.ZodEnum<{
17
+ platform: "platform";
18
+ orchestrator: "orchestrator";
19
+ agent: "agent";
20
+ }>;
21
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
22
+ traceId: z.ZodOptional<z.ZodString>;
23
+ spanId: z.ZodOptional<z.ZodString>;
24
+ parentSpanId: z.ZodOptional<z.ZodString>;
25
+ durationMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
26
+ jobId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
27
+ stepIndex: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
28
+ }, z.core.$strip>;
29
+ /** Execution context sent by agent at job start for the Summary tab.
30
+ *
31
+ * SECURITY INVARIANT: see `runEventMessageSchema` above — no tenant identifier
32
+ * may appear on this wire schema. All tenant attribution comes from
33
+ * `authState.orgId` on the receiving Platform side.
34
+ */
35
+ export declare const jobContextMessageSchema: z.ZodObject<{
36
+ type: z.ZodLiteral<"job.context">;
37
+ runId: z.ZodString;
38
+ jobId: z.ZodString;
39
+ context: z.ZodObject<{
40
+ envVars: z.ZodOptional<z.ZodArray<z.ZodObject<{
41
+ name: z.ZodString;
42
+ value: z.ZodString;
43
+ category: z.ZodEnum<{
44
+ user: "user";
45
+ system: "system";
46
+ inherited: "inherited";
47
+ secret: "secret";
48
+ }>;
49
+ }, z.core.$strip>>>;
50
+ runtime: z.ZodOptional<z.ZodObject<{
51
+ nodeVersion: z.ZodOptional<z.ZodString>;
52
+ os: z.ZodOptional<z.ZodString>;
53
+ arch: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strip>>;
55
+ sandboxType: z.ZodOptional<z.ZodString>;
56
+ labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
57
+ workingDirectory: z.ZodOptional<z.ZodString>;
58
+ gitRef: z.ZodOptional<z.ZodString>;
59
+ lockFileVersion: z.ZodOptional<z.ZodString>;
60
+ sdkVersion: z.ZodOptional<z.ZodString>;
61
+ depCacheStatus: z.ZodOptional<z.ZodString>;
62
+ networkIsolation: z.ZodOptional<z.ZodString>;
63
+ scalerContext: z.ZodOptional<z.ZodObject<{
64
+ backendType: z.ZodString;
65
+ scalerName: z.ZodString;
66
+ }, z.core.$loose>>;
67
+ }, z.core.$strip>;
68
+ }, z.core.$strip>;
69
+ /** Run event forwarded to browser for live timeline updates.
70
+ *
71
+ * NOTE: `runId` is already present in this schema (and always populated by the
72
+ * Platform WS fan-out in `browser-fan-out.ts::onRunEvent`). The dashboard uses it
73
+ * to group events by their originating run in the rerun chain. Do not remove.
74
+ */
75
+ export declare const browserRunEventSchema: z.ZodObject<{
76
+ type: z.ZodLiteral<"run.event">;
77
+ runId: z.ZodString;
78
+ eventType: z.ZodString;
79
+ timestampMs: z.ZodNumber;
80
+ sourceService: z.ZodString;
81
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
82
+ durationMs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
83
+ jobId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
84
+ stepIndex: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
85
+ }, z.core.$strip>;
86
+ /** Job context forwarded to browser for Summary tab. */
87
+ export declare const browserJobContextSchema: z.ZodObject<{
88
+ type: z.ZodLiteral<"job.context">;
89
+ runId: z.ZodString;
90
+ jobId: z.ZodString;
91
+ context: z.ZodObject<{
92
+ envVars: z.ZodOptional<z.ZodArray<z.ZodObject<{
93
+ name: z.ZodString;
94
+ value: z.ZodString;
95
+ category: z.ZodEnum<{
96
+ user: "user";
97
+ system: "system";
98
+ inherited: "inherited";
99
+ secret: "secret";
100
+ }>;
101
+ }, z.core.$strip>>>;
102
+ runtime: z.ZodOptional<z.ZodObject<{
103
+ nodeVersion: z.ZodOptional<z.ZodString>;
104
+ os: z.ZodOptional<z.ZodString>;
105
+ arch: z.ZodOptional<z.ZodString>;
106
+ }, z.core.$strip>>;
107
+ sandboxType: z.ZodOptional<z.ZodString>;
108
+ labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
109
+ workingDirectory: z.ZodOptional<z.ZodString>;
110
+ gitRef: z.ZodOptional<z.ZodString>;
111
+ lockFileVersion: z.ZodOptional<z.ZodString>;
112
+ sdkVersion: z.ZodOptional<z.ZodString>;
113
+ depCacheStatus: z.ZodOptional<z.ZodString>;
114
+ networkIsolation: z.ZodOptional<z.ZodString>;
115
+ scalerContext: z.ZodOptional<z.ZodObject<{
116
+ backendType: z.ZodString;
117
+ scalerName: z.ZodString;
118
+ }, z.core.$loose>>;
119
+ }, z.core.$strip>;
120
+ }, z.core.$strip>;
121
+ /** Request orchestration logs for a job via Platform-orchestrator proxy. */
122
+ export declare const dashboardOrchLogsRequestSchema: z.ZodObject<{
123
+ type: z.ZodLiteral<"dashboard.orch.logs">;
124
+ requestId: z.ZodString;
125
+ actor: z.ZodDiscriminatedUnion<[z.ZodObject<{
126
+ type: z.ZodLiteral<"user">;
127
+ sub: z.ZodString;
128
+ }, z.core.$strip>, z.ZodObject<{
129
+ type: z.ZodLiteral<"api_key">;
130
+ keyId: z.ZodString;
131
+ ownerSub: z.ZodString;
132
+ }, z.core.$strip>, z.ZodObject<{
133
+ type: z.ZodLiteral<"service_account">;
134
+ id: z.ZodString;
135
+ }, z.core.$strip>, z.ZodObject<{
136
+ type: z.ZodLiteral<"platform_operator">;
137
+ sub: z.ZodString;
138
+ reason: z.ZodString;
139
+ }, z.core.$strip>, z.ZodObject<{
140
+ type: z.ZodLiteral<"system">;
141
+ component: z.ZodString;
142
+ }, z.core.$strip>], "type">;
143
+ runId: z.ZodString;
144
+ jobId: z.ZodString;
145
+ }, z.core.$strip>;
146
+ /** Response with orchestration logs for a job. */
147
+ export declare const dashboardOrchLogsResponseSchema: z.ZodObject<{
148
+ type: z.ZodLiteral<"dashboard.orch.logs.response">;
149
+ requestId: z.ZodString;
150
+ lines: z.ZodArray<z.ZodString>;
151
+ totalLines: z.ZodNumber;
152
+ error: z.ZodOptional<z.ZodString>;
153
+ }, z.core.$strip>;
154
+ export type DashboardOrchLogsRequest = z.infer<typeof dashboardOrchLogsRequestSchema>;
155
+ //# sourceMappingURL=run-events.d.ts.map
@@ -0,0 +1,115 @@
1
+ import "../../chunk-gOLHoazu.js";
2
+ import { actorPrincipalSchema } from "./actor.js";
3
+ import { z } from "zod";
4
+ //#region src/protocol/messages/run-events.ts
5
+ /** Infrastructure event emitted by orchestrator or agent during run lifecycle.
6
+ *
7
+ * SECURITY INVARIANT: This schema MUST NOT carry an `orgId` (or any tenant
8
+ * identifier). Orchestrator WS connections are single-tenant — `authState.orgId`
9
+ * is fixed for the connection's lifetime, derived from a DB-backed API-key hash.
10
+ * The Platform always uses `authState.orgId` for tenant attribution; trusting a
11
+ * wire-supplied field would be a cross-tenant injection primitive (see
12
+ * `docs/architecture/security/ws-tenant-isolation.md`).
13
+ */
14
+ const runEventMessageSchema = z.object({
15
+ type: z.literal("run.event"),
16
+ runId: z.string(),
17
+ eventType: z.string(),
18
+ timestampMs: z.number(),
19
+ sourceService: z.enum([
20
+ "platform",
21
+ "orchestrator",
22
+ "agent"
23
+ ]),
24
+ metadata: z.record(z.string(), z.unknown()).optional(),
25
+ traceId: z.string().optional(),
26
+ spanId: z.string().optional(),
27
+ parentSpanId: z.string().optional(),
28
+ durationMs: z.number().nullable().optional(),
29
+ jobId: z.string().nullable().optional(),
30
+ stepIndex: z.number().nullable().optional()
31
+ });
32
+ /** Execution context sent by agent at job start for the Summary tab.
33
+ *
34
+ * SECURITY INVARIANT: see `runEventMessageSchema` above — no tenant identifier
35
+ * may appear on this wire schema. All tenant attribution comes from
36
+ * `authState.orgId` on the receiving Platform side.
37
+ */
38
+ const jobContextMessageSchema = z.object({
39
+ type: z.literal("job.context"),
40
+ runId: z.string(),
41
+ jobId: z.string(),
42
+ context: z.object({
43
+ envVars: z.array(z.object({
44
+ name: z.string(),
45
+ value: z.string(),
46
+ category: z.enum([
47
+ "system",
48
+ "user",
49
+ "inherited",
50
+ "secret"
51
+ ])
52
+ })).optional(),
53
+ runtime: z.object({
54
+ nodeVersion: z.string().optional(),
55
+ os: z.string().optional(),
56
+ arch: z.string().optional()
57
+ }).optional(),
58
+ sandboxType: z.string().optional(),
59
+ labels: z.array(z.string()).optional(),
60
+ workingDirectory: z.string().optional(),
61
+ gitRef: z.string().optional(),
62
+ lockFileVersion: z.string().optional(),
63
+ sdkVersion: z.string().optional(),
64
+ depCacheStatus: z.string().optional(),
65
+ networkIsolation: z.string().optional(),
66
+ scalerContext: z.object({
67
+ backendType: z.string(),
68
+ scalerName: z.string()
69
+ }).passthrough().optional()
70
+ })
71
+ });
72
+ /** Run event forwarded to browser for live timeline updates.
73
+ *
74
+ * NOTE: `runId` is already present in this schema (and always populated by the
75
+ * Platform WS fan-out in `browser-fan-out.ts::onRunEvent`). The dashboard uses it
76
+ * to group events by their originating run in the rerun chain. Do not remove.
77
+ */
78
+ const browserRunEventSchema = z.object({
79
+ type: z.literal("run.event"),
80
+ runId: z.string(),
81
+ eventType: z.string(),
82
+ timestampMs: z.number(),
83
+ sourceService: z.string(),
84
+ metadata: z.record(z.string(), z.unknown()).optional(),
85
+ durationMs: z.number().nullable().optional(),
86
+ jobId: z.string().nullable().optional(),
87
+ stepIndex: z.number().nullable().optional()
88
+ });
89
+ /** Job context forwarded to browser for Summary tab. */
90
+ const browserJobContextSchema = z.object({
91
+ type: z.literal("job.context"),
92
+ runId: z.string(),
93
+ jobId: z.string(),
94
+ context: jobContextMessageSchema.shape.context
95
+ });
96
+ /** Request orchestration logs for a job via Platform-orchestrator proxy. */
97
+ const dashboardOrchLogsRequestSchema = z.object({
98
+ type: z.literal("dashboard.orch.logs"),
99
+ requestId: z.string(),
100
+ actor: actorPrincipalSchema,
101
+ runId: z.string(),
102
+ jobId: z.string()
103
+ });
104
+ /** Response with orchestration logs for a job. */
105
+ const dashboardOrchLogsResponseSchema = z.object({
106
+ type: z.literal("dashboard.orch.logs.response"),
107
+ requestId: z.string(),
108
+ lines: z.array(z.string()),
109
+ totalLines: z.number(),
110
+ error: z.string().optional()
111
+ });
112
+ //#endregion
113
+ export { browserJobContextSchema, browserRunEventSchema, dashboardOrchLogsRequestSchema, dashboardOrchLogsResponseSchema, jobContextMessageSchema, runEventMessageSchema };
114
+
115
+ //# sourceMappingURL=run-events.js.map