@kici-dev/engine 0.1.15 → 0.1.16

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.
@@ -1,5 +1,6 @@
1
1
  import "../../chunk-gOLHoazu.js";
2
2
  import { ExecutionJobStatus, ExecutionStepStatus } from "./execution-status.js";
3
+ import { approverClauseSchema } from "../../approval/types.js";
3
4
  import { z } from "zod";
4
5
  //#region src/protocol/messages/orchestrator-agent.ts
5
6
  /**
@@ -554,6 +555,82 @@ const agentApiResponseSchema = z.object({
554
555
  /** Error description (present on failure). */
555
556
  error: z.string().optional()
556
557
  });
558
+ /** Orchestrator asks an agent for its log/diagnostic mini-bundle. */
559
+ const fleetLogsRequestSchema = z.object({
560
+ type: z.literal("fleet.logs.request"),
561
+ /** UUID correlating the chunked response. */
562
+ requestId: z.string(),
563
+ /** Hours of log history to include. */
564
+ logWindowHours: z.number(),
565
+ /** Per-node cap on raw log bytes. */
566
+ maxBytes: z.number()
567
+ });
568
+ /** One base64 frame of an agent's mini-bundle ZIP. */
569
+ const fleetBundleChunkSchema = z.object({
570
+ type: z.literal("fleet.bundle.chunk"),
571
+ requestId: z.string(),
572
+ seq: z.number().int().nonnegative(),
573
+ isLast: z.boolean(),
574
+ dataB64: z.string()
575
+ });
576
+ /** Agent failed to build/stream its mini-bundle. */
577
+ const fleetBundleErrorSchema = z.object({
578
+ type: z.literal("fleet.bundle.error"),
579
+ requestId: z.string(),
580
+ message: z.string()
581
+ });
582
+ /** Outcome of a step-level approval hold, sent back to the waiting agent. */
583
+ const StepApprovalOutcome = z.enum([
584
+ "approved",
585
+ "rejected",
586
+ "expired"
587
+ ]);
588
+ /**
589
+ * Agent -> Orchestrator: a step carrying `requireApproval` is about to run and
590
+ * the agent is blocking its step loop until the orchestrator resolves the
591
+ * approval. The orchestrator creates a step-scoped `held_runs` row from the
592
+ * normalized requirement and replies with `step.approval-resolved` once the
593
+ * hold is approved, rejected, or expired. The agent keeps heartbeats flowing
594
+ * during the wait so it is not reaped as stale.
595
+ *
596
+ * NOT fast-pathed — the `log.chunk` / `heartbeat` manual-validator invariant is
597
+ * untouched by this message.
598
+ */
599
+ const stepApprovalRequestSchema = z.object({
600
+ type: z.literal("step.approval-request"),
601
+ messageId: z.string(),
602
+ runId: z.string(),
603
+ jobId: z.string(),
604
+ stepIndex: z.number().int().nonnegative(),
605
+ stepName: z.string(),
606
+ /** AND-list of approver clauses (empty = any approval-capable member). */
607
+ clauses: z.array(approverClauseSchema),
608
+ /** Human label for the gate (from the SDK `requireApproval` reason). */
609
+ reason: z.string(),
610
+ /**
611
+ * Per-gate timeout override (seconds) from the SDK `requireApproval.timeout`.
612
+ * Absent ⇒ the orchestrator uses the org-default `approval_expiry_seconds`.
613
+ * The orchestrator owns the authoritative `expiresAt` computation.
614
+ */
615
+ timeoutSeconds: z.number().int().positive().optional()
616
+ });
617
+ /**
618
+ * Orchestrator -> Agent: resolution of a step-level approval hold. `requestId`
619
+ * correlates to the originating `step.approval-request.messageId`. On
620
+ * `approved` the agent runs the step with its live workspace intact; on
621
+ * `rejected`/`expired` it fails the job with a clear reason.
622
+ */
623
+ const stepApprovalResolvedSchema = z.object({
624
+ type: z.literal("step.approval-resolved"),
625
+ /** Correlates to the originating step.approval-request messageId. */
626
+ requestId: z.string(),
627
+ runId: z.string(),
628
+ jobId: z.string(),
629
+ stepIndex: z.number().int().nonnegative(),
630
+ outcome: StepApprovalOutcome,
631
+ /** Optional human reason (e.g. the reject reason). */
632
+ reason: z.string().optional()
633
+ });
557
634
  /** All messages that flow from Orchestrator to Agent. */
558
635
  const orchestratorToAgentMessageSchema = z.discriminatedUnion("type", [
559
636
  jobDispatchSchema,
@@ -566,7 +643,9 @@ const orchestratorToAgentMessageSchema = z.discriminatedUnion("type", [
566
643
  eventEmitResponseSchema,
567
644
  agentApiResponseSchema,
568
645
  agentAuthSuccessSchema,
569
- agentAuthFailureSchema
646
+ agentAuthFailureSchema,
647
+ fleetLogsRequestSchema,
648
+ stepApprovalResolvedSchema
570
649
  ]);
571
650
  /** All messages that flow from Agent to Orchestrator. */
572
651
  const agentToOrchestratorMessageSchema = z.discriminatedUnion("type", [
@@ -589,9 +668,12 @@ const agentToOrchestratorMessageSchema = z.discriminatedUnion("type", [
589
668
  eventEmitSchema,
590
669
  agentApiRequestSchema,
591
670
  agentMetricsSchema,
592
- agentAuthRequestSchema
671
+ agentAuthRequestSchema,
672
+ fleetBundleChunkSchema,
673
+ fleetBundleErrorSchema,
674
+ stepApprovalRequestSchema
593
675
  ]);
594
676
  //#endregion
595
- export { CacheRefScope, JobRejectReason, agentApiRequestSchema, agentApiResponseSchema, agentAuthFailureSchema, agentAuthRequestSchema, agentAuthSuccessSchema, agentLogChunkSchema, agentMetricsSchema, agentRegisterSchema, agentStatusSchema, agentStepStatusSchema, agentToOrchestratorMessageSchema, cacheUserRestoreRequestSchema, cacheUserRestoreResponseSchema, cacheUserSaveCompleteSchema, cacheUserSaveRequestSchema, cacheUserSaveResponseSchema, configAckSchema, eventEmitResponseSchema, eventEmitSchema, gitAuthSchema, jobAckSchema, jobCancelSchema, jobConcurrencyAckSchema, jobConcurrencyReportSchema, jobDispatchSchema, jobRejectSchema, jobStatusSchema, orchestratorToAgentMessageSchema, registerAckSchema };
677
+ export { CacheRefScope, JobRejectReason, StepApprovalOutcome, agentApiRequestSchema, agentApiResponseSchema, agentAuthFailureSchema, agentAuthRequestSchema, agentAuthSuccessSchema, agentLogChunkSchema, agentMetricsSchema, agentRegisterSchema, agentStatusSchema, agentStepStatusSchema, agentToOrchestratorMessageSchema, cacheUserRestoreRequestSchema, cacheUserRestoreResponseSchema, cacheUserSaveCompleteSchema, cacheUserSaveRequestSchema, cacheUserSaveResponseSchema, configAckSchema, eventEmitResponseSchema, eventEmitSchema, fleetBundleChunkSchema, fleetBundleErrorSchema, fleetLogsRequestSchema, gitAuthSchema, jobAckSchema, jobCancelSchema, jobConcurrencyAckSchema, jobConcurrencyReportSchema, jobDispatchSchema, jobRejectSchema, jobStatusSchema, orchestratorToAgentMessageSchema, registerAckSchema, stepApprovalRequestSchema, stepApprovalResolvedSchema };
596
678
 
597
679
  //# sourceMappingURL=orchestrator-agent.js.map
@@ -302,6 +302,38 @@ export declare const peerConfigReloadResponseSchema: z.ZodObject<{
302
302
  restartRequired: z.ZodOptional<z.ZodArray<z.ZodString>>;
303
303
  fieldsChanged: z.ZodOptional<z.ZodArray<z.ZodString>>;
304
304
  }, z.core.$strip>;
305
+ /** Which of THIS peer's downstream nodes to gather. all=true ignores the id lists. */
306
+ export declare const fleetSelectionSchema: z.ZodObject<{
307
+ all: z.ZodBoolean;
308
+ agentIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
309
+ workerInstanceIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
310
+ }, z.core.$strip>;
311
+ /** Ask a peer to assemble and stream back its subtree bundle. */
312
+ export declare const peerLogsCollectRequestSchema: z.ZodObject<{
313
+ type: z.ZodLiteral<"peer.logs.collect.request">;
314
+ messageId: z.ZodString;
315
+ logWindowHours: z.ZodNumber;
316
+ includeCoordinatorMesh: z.ZodBoolean;
317
+ selection: z.ZodObject<{
318
+ all: z.ZodBoolean;
319
+ agentIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
320
+ workerInstanceIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
321
+ }, z.core.$strip>;
322
+ }, z.core.$strip>;
323
+ /** One base64 frame of a peer's subtree ZIP. */
324
+ export declare const peerLogsCollectChunkSchema: z.ZodObject<{
325
+ type: z.ZodLiteral<"peer.logs.collect.chunk">;
326
+ messageId: z.ZodString;
327
+ seq: z.ZodNumber;
328
+ isLast: z.ZodBoolean;
329
+ dataB64: z.ZodString;
330
+ }, z.core.$strip>;
331
+ /** Peer failed to assemble/stream its subtree. */
332
+ export declare const peerLogsCollectErrorSchema: z.ZodObject<{
333
+ type: z.ZodLiteral<"peer.logs.collect.error">;
334
+ messageId: z.ZodString;
335
+ message: z.ZodString;
336
+ }, z.core.$strip>;
305
337
  /** Graceful shutdown announcement. Peers remove sender from registry immediately. */
306
338
  export declare const peerLeavingSchema: z.ZodObject<{
307
339
  type: z.ZodLiteral<"peer.leaving">;
@@ -568,6 +600,26 @@ export declare const peerToPeerMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObje
568
600
  errors: z.ZodOptional<z.ZodArray<z.ZodString>>;
569
601
  restartRequired: z.ZodOptional<z.ZodArray<z.ZodString>>;
570
602
  fieldsChanged: z.ZodOptional<z.ZodArray<z.ZodString>>;
603
+ }, z.core.$strip>, z.ZodObject<{
604
+ type: z.ZodLiteral<"peer.logs.collect.request">;
605
+ messageId: z.ZodString;
606
+ logWindowHours: z.ZodNumber;
607
+ includeCoordinatorMesh: z.ZodBoolean;
608
+ selection: z.ZodObject<{
609
+ all: z.ZodBoolean;
610
+ agentIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
611
+ workerInstanceIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
612
+ }, z.core.$strip>;
613
+ }, z.core.$strip>, z.ZodObject<{
614
+ type: z.ZodLiteral<"peer.logs.collect.chunk">;
615
+ messageId: z.ZodString;
616
+ seq: z.ZodNumber;
617
+ isLast: z.ZodBoolean;
618
+ dataB64: z.ZodString;
619
+ }, z.core.$strip>, z.ZodObject<{
620
+ type: z.ZodLiteral<"peer.logs.collect.error">;
621
+ messageId: z.ZodString;
622
+ message: z.ZodString;
571
623
  }, z.core.$strip>, z.ZodObject<{
572
624
  type: z.ZodLiteral<"peer.leaving">;
573
625
  instanceId: z.ZodString;
@@ -816,6 +868,26 @@ export declare const peerFromPeerMessageSchema: z.ZodDiscriminatedUnion<[z.ZodOb
816
868
  errors: z.ZodOptional<z.ZodArray<z.ZodString>>;
817
869
  restartRequired: z.ZodOptional<z.ZodArray<z.ZodString>>;
818
870
  fieldsChanged: z.ZodOptional<z.ZodArray<z.ZodString>>;
871
+ }, z.core.$strip>, z.ZodObject<{
872
+ type: z.ZodLiteral<"peer.logs.collect.request">;
873
+ messageId: z.ZodString;
874
+ logWindowHours: z.ZodNumber;
875
+ includeCoordinatorMesh: z.ZodBoolean;
876
+ selection: z.ZodObject<{
877
+ all: z.ZodBoolean;
878
+ agentIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
879
+ workerInstanceIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
880
+ }, z.core.$strip>;
881
+ }, z.core.$strip>, z.ZodObject<{
882
+ type: z.ZodLiteral<"peer.logs.collect.chunk">;
883
+ messageId: z.ZodString;
884
+ seq: z.ZodNumber;
885
+ isLast: z.ZodBoolean;
886
+ dataB64: z.ZodString;
887
+ }, z.core.$strip>, z.ZodObject<{
888
+ type: z.ZodLiteral<"peer.logs.collect.error">;
889
+ messageId: z.ZodString;
890
+ message: z.ZodString;
819
891
  }, z.core.$strip>, z.ZodObject<{
820
892
  type: z.ZodLiteral<"peer.leaving">;
821
893
  instanceId: z.ZodString;
@@ -856,6 +928,10 @@ export type PeerConfigReload = z.infer<typeof peerConfigReloadSchema>;
856
928
  export type PeerConfigReloadResponse = z.infer<typeof peerConfigReloadResponseSchema>;
857
929
  export type PeerLeaving = z.infer<typeof peerLeavingSchema>;
858
930
  export type PeerAgentTokenRevoke = z.infer<typeof peerAgentTokenRevokeSchema>;
931
+ export type FleetSelection = z.infer<typeof fleetSelectionSchema>;
932
+ export type PeerLogsCollectRequest = z.infer<typeof peerLogsCollectRequestSchema>;
933
+ export type PeerLogsCollectChunk = z.infer<typeof peerLogsCollectChunkSchema>;
934
+ export type PeerLogsCollectError = z.infer<typeof peerLogsCollectErrorSchema>;
859
935
  export type PeerToPeerMessage = z.infer<typeof peerToPeerMessageSchema>;
860
936
  export {};
861
937
  //# sourceMappingURL=peer.d.ts.map
@@ -316,6 +316,35 @@ const peerConfigReloadResponseSchema = z.object({
316
316
  restartRequired: z.array(z.string()).optional(),
317
317
  fieldsChanged: z.array(z.string()).optional()
318
318
  });
319
+ /** Which of THIS peer's downstream nodes to gather. all=true ignores the id lists. */
320
+ const fleetSelectionSchema = z.object({
321
+ all: z.boolean(),
322
+ agentIds: z.array(z.string()).default([]),
323
+ workerInstanceIds: z.array(z.string()).default([])
324
+ });
325
+ /** Ask a peer to assemble and stream back its subtree bundle. */
326
+ const peerLogsCollectRequestSchema = z.object({
327
+ type: z.literal("peer.logs.collect.request"),
328
+ messageId: z.string(),
329
+ logWindowHours: z.number(),
330
+ /** Loop guard: false on every downstream request so the coordinator mesh never echoes. */
331
+ includeCoordinatorMesh: z.boolean(),
332
+ selection: fleetSelectionSchema
333
+ });
334
+ /** One base64 frame of a peer's subtree ZIP. */
335
+ const peerLogsCollectChunkSchema = z.object({
336
+ type: z.literal("peer.logs.collect.chunk"),
337
+ messageId: z.string(),
338
+ seq: z.number().int().nonnegative(),
339
+ isLast: z.boolean(),
340
+ dataB64: z.string()
341
+ });
342
+ /** Peer failed to assemble/stream its subtree. */
343
+ const peerLogsCollectErrorSchema = z.object({
344
+ type: z.literal("peer.logs.collect.error"),
345
+ messageId: z.string(),
346
+ message: z.string()
347
+ });
319
348
  /** Graceful shutdown announcement. Peers remove sender from registry immediately. */
320
349
  const peerLeavingSchema = z.object({
321
350
  type: z.literal("peer.leaving"),
@@ -377,6 +406,9 @@ const peerToPeerMessageSchema = z.discriminatedUnion("type", [
377
406
  peerCacheUploadResponseSchema,
378
407
  peerConfigReloadSchema,
379
408
  peerConfigReloadResponseSchema,
409
+ peerLogsCollectRequestSchema,
410
+ peerLogsCollectChunkSchema,
411
+ peerLogsCollectErrorSchema,
380
412
  peerLeavingSchema,
381
413
  peerAgentTokenRevokeSchema,
382
414
  peerScalerEventSchema
@@ -400,11 +432,14 @@ const peerFromPeerMessageSchema = z.discriminatedUnion("type", [
400
432
  peerCacheUploadResponseSchema,
401
433
  peerConfigReloadSchema,
402
434
  peerConfigReloadResponseSchema,
435
+ peerLogsCollectRequestSchema,
436
+ peerLogsCollectChunkSchema,
437
+ peerLogsCollectErrorSchema,
403
438
  peerLeavingSchema,
404
439
  peerAgentTokenRevokeSchema,
405
440
  peerScalerEventSchema
406
441
  ]);
407
442
  //#endregion
408
- export { jobProgressSchema, jobRerouteAckSchema, jobRerouteSchema, peerAgentTokenRevokeSchema, peerAuthRequestSchema, peerAuthResponseSchema, peerCapabilitiesSchema, peerConfigReloadResponseSchema, peerConfigReloadSchema, peerFromPeerMessageSchema, peerHeartbeatSchema, peerHelloResponseSchema, peerHelloSchema, peerJobCancelSchema, peerLeavingSchema, peerScalerEventSchema, peerToPeerMessageSchema, raftAppendEntriesSchema, raftVoteRequestSchema, raftVoteResponseSchema };
443
+ export { fleetSelectionSchema, jobProgressSchema, jobRerouteAckSchema, jobRerouteSchema, peerAgentTokenRevokeSchema, peerAuthRequestSchema, peerAuthResponseSchema, peerCapabilitiesSchema, peerConfigReloadResponseSchema, peerConfigReloadSchema, peerFromPeerMessageSchema, peerHeartbeatSchema, peerHelloResponseSchema, peerHelloSchema, peerJobCancelSchema, peerLeavingSchema, peerLogsCollectChunkSchema, peerLogsCollectErrorSchema, peerLogsCollectRequestSchema, peerScalerEventSchema, peerToPeerMessageSchema, raftAppendEntriesSchema, raftVoteRequestSchema, raftVoteResponseSchema };
409
444
 
410
445
  //# sourceMappingURL=peer.js.map
@@ -5,17 +5,17 @@ export declare const trustPolicyUpdateSchema: z.ZodObject<{
5
5
  orgId: z.ZodString;
6
6
  policy: z.ZodObject<{
7
7
  forkPolicy: z.ZodEnum<{
8
- hold: "hold";
9
8
  reject: "reject";
9
+ hold: "hold";
10
10
  allow: "allow";
11
11
  }>;
12
12
  unknownContributorPolicy: z.ZodEnum<{
13
- hold: "hold";
14
13
  reject: "reject";
14
+ hold: "hold";
15
15
  }>;
16
16
  workflowChangePolicy: z.ZodEnum<{
17
- hold: "hold";
18
17
  reject: "reject";
18
+ hold: "hold";
19
19
  allow: "allow";
20
20
  }>;
21
21
  approvalExpiryHours: z.ZodNumber;
@@ -32,6 +32,10 @@ export declare const trustPolicyUpdateSchema: z.ZodObject<{
32
32
  write: "write";
33
33
  admin: "admin";
34
34
  }>>;
35
+ teamMemberships: z.ZodDefault<z.ZodArray<z.ZodObject<{
36
+ teamName: z.ZodString;
37
+ memberUserIds: z.ZodArray<z.ZodString>;
38
+ }, z.core.$strip>>>;
35
39
  }, z.core.$strip>;
36
40
  export type TrustPolicyUpdate = z.infer<typeof trustPolicyUpdateSchema>;
37
41
  /**
@@ -350,17 +354,17 @@ export declare const platformToOrchestratorMessageSchema: z.ZodDiscriminatedUnio
350
354
  orgId: z.ZodString;
351
355
  policy: z.ZodObject<{
352
356
  forkPolicy: z.ZodEnum<{
353
- hold: "hold";
354
357
  reject: "reject";
358
+ hold: "hold";
355
359
  allow: "allow";
356
360
  }>;
357
361
  unknownContributorPolicy: z.ZodEnum<{
358
- hold: "hold";
359
362
  reject: "reject";
363
+ hold: "hold";
360
364
  }>;
361
365
  workflowChangePolicy: z.ZodEnum<{
362
- hold: "hold";
363
366
  reject: "reject";
367
+ hold: "hold";
364
368
  allow: "allow";
365
369
  }>;
366
370
  approvalExpiryHours: z.ZodNumber;
@@ -377,6 +381,10 @@ export declare const platformToOrchestratorMessageSchema: z.ZodDiscriminatedUnio
377
381
  write: "write";
378
382
  admin: "admin";
379
383
  }>>;
384
+ teamMemberships: z.ZodDefault<z.ZodArray<z.ZodObject<{
385
+ teamName: z.ZodString;
386
+ memberUserIds: z.ZodArray<z.ZodString>;
387
+ }, z.core.$strip>>>;
380
388
  }, z.core.$strip>, z.ZodObject<{
381
389
  type: z.ZodLiteral<"source.register.ack">;
382
390
  messageId: z.ZodString;
@@ -1853,6 +1861,8 @@ export declare const platformToOrchestratorMessageSchema: z.ZodDiscriminatedUnio
1853
1861
  "held_run.list.read": "held_run.list.read";
1854
1862
  "held_run.approve": "held_run.approve";
1855
1863
  "held_run.reject": "held_run.reject";
1864
+ "held_run.request": "held_run.request";
1865
+ "held_run.expire": "held_run.expire";
1856
1866
  "registration.list.read": "registration.list.read";
1857
1867
  "diagnostics.read": "diagnostics.read";
1858
1868
  "scaler.capacity.read": "scaler.capacity.read";
@@ -44,7 +44,18 @@ const trustPolicyUpdateSchema = z.object({
44
44
  "read",
45
45
  "write",
46
46
  "admin"
47
- ]))
47
+ ])),
48
+ /**
49
+ * Operator-defined teams and their member user ids. The orchestrator has no
50
+ * identity store, so team membership is delivered here (next to
51
+ * `identityLinks`) and cached in-memory. The approval resolver matches a
52
+ * `{team}` clause by looking up the team's members in this list.
53
+ * `.default([])` keeps an older Platform that doesn't send it valid.
54
+ */
55
+ teamMemberships: z.array(z.object({
56
+ teamName: z.string(),
57
+ memberUserIds: z.array(z.string())
58
+ })).default([])
48
59
  });
49
60
  /**
50
61
  * Internal shape of a fully-reassembled, HMAC-verified webhook relay handed