@nylorun/core 0.3.0-beta → 0.5.0-beta

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 (58) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/compatibility.d.ts +48 -1
  3. package/dist/compatibility.js +192 -1
  4. package/dist/contracts.d.ts +562 -19
  5. package/dist/contracts.js +442 -29
  6. package/dist/define.d.ts +9 -3
  7. package/dist/define.js +3 -0
  8. package/dist/definition/assemble.js +35 -0
  9. package/dist/definition/bind-tool.js +3 -0
  10. package/dist/definition/bound.d.ts +3 -0
  11. package/dist/definition/builder.d.ts +5 -5
  12. package/dist/definition/declaration.d.ts +2 -2
  13. package/dist/definition/declaration.js +13 -1
  14. package/dist/definition/delegate.d.ts +35 -0
  15. package/dist/definition/delegate.js +72 -0
  16. package/dist/definition/from.js +15 -2
  17. package/dist/definition/helpers.d.ts +1 -1
  18. package/dist/definition/helpers.js +8 -1
  19. package/dist/definition/manifest.js +3 -0
  20. package/dist/definition/variant.d.ts +7 -0
  21. package/dist/definition/variant.js +87 -0
  22. package/dist/definition/workflow/build.d.ts +38 -0
  23. package/dist/definition/workflow/build.js +62 -0
  24. package/dist/definition/workflow/chain.d.ts +49 -0
  25. package/dist/definition/workflow/chain.js +41 -0
  26. package/dist/definition/workflow/diagnostics.d.ts +14 -0
  27. package/dist/definition/workflow/diagnostics.js +38 -0
  28. package/dist/definition/workflow/index.d.ts +18 -0
  29. package/dist/definition/workflow/index.js +10 -0
  30. package/dist/definition/workflow/loop.d.ts +54 -0
  31. package/dist/definition/workflow/loop.js +102 -0
  32. package/dist/definition/workflow/map.d.ts +17 -0
  33. package/dist/definition/workflow/map.js +46 -0
  34. package/dist/definition/workflow/parallel.d.ts +19 -0
  35. package/dist/definition/workflow/parallel.js +37 -0
  36. package/dist/definition/workflow/patch.d.ts +11 -0
  37. package/dist/definition/workflow/patch.js +45 -0
  38. package/dist/definition/workflow/runnable.d.ts +40 -0
  39. package/dist/definition/workflow/runnable.js +251 -0
  40. package/dist/definition/workflow/slot.d.ts +23 -0
  41. package/dist/definition/workflow/slot.js +16 -0
  42. package/dist/definition/workflow/switch.d.ts +26 -0
  43. package/dist/definition/workflow/switch.js +66 -0
  44. package/dist/definition/workflow/types.d.ts +25 -0
  45. package/dist/definition/workflow/types.js +7 -0
  46. package/dist/definition/workflow/verdict.d.ts +20 -0
  47. package/dist/definition/workflow/verdict.js +25 -0
  48. package/dist/index.d.ts +1 -0
  49. package/dist/types/agent.d.ts +5 -0
  50. package/dist/types/manifest.d.ts +5 -0
  51. package/dist/types/middleware.d.ts +5 -0
  52. package/dist/types/observe.d.ts +87 -1
  53. package/dist/types/tool.d.ts +11 -0
  54. package/dist/types/workflow.d.ts +106 -0
  55. package/dist/types/workflow.js +1 -0
  56. package/dist/utils/hash.d.ts +3 -2
  57. package/dist/utils/hash.js +1 -1
  58. package/package.json +1 -1
package/dist/contracts.js CHANGED
@@ -2,10 +2,21 @@
2
2
  import { z } from "zod";
3
3
  import { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
4
4
  import { hookListIssue } from "./definition/hooks.js";
5
- export const PROTOCOL_VERSION = 1;
5
+ import { DELEGATE_INPUT_SCHEMA } from "./definition/delegate.js";
6
+ import { canonical } from "./utils/canonical.js";
7
+ export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
8
+ import { ERROR_CODES } from "./compatibility.js";
6
9
  export const RequestIdSchema = z.string().min(1);
7
10
  export const IdempotencyKeySchema = z.string().min(1).max(256);
8
11
  const jsonObject = z.record(z.string(), z.unknown());
12
+ const jsonValue = z.lazy(() => z.union([
13
+ z.string(),
14
+ z.number(),
15
+ z.boolean(),
16
+ z.null(),
17
+ z.array(jsonValue),
18
+ z.record(z.string(), jsonValue),
19
+ ]));
9
20
  const mcpServerSchema = z.discriminatedUnion("type", [
10
21
  z
11
22
  .object({
@@ -80,6 +91,7 @@ const toolManifestSchema = z
80
91
  description: z.string().optional(),
81
92
  inputSchema: jsonObject,
82
93
  outputSchema: jsonObject.optional(),
94
+ agent: z.lazy(() => AgentManifestSchema).optional(),
83
95
  })
84
96
  .strict();
85
97
  const hookPointSchema = z
@@ -122,6 +134,7 @@ export const AgentManifestSchema = z
122
134
  })
123
135
  .strict()
124
136
  .superRefine((manifest, ctx) => {
137
+ delegationIssues(manifest, (message) => ctx.addIssue({ code: "custom", message }));
125
138
  const ids = new Set();
126
139
  const names = new Set();
127
140
  const servers = new Set();
@@ -192,11 +205,153 @@ export const AgentManifestSchema = z
192
205
  }
193
206
  }
194
207
  });
208
+ /** Agents used as tools: one level deep, `{ task }` input, one shared sandbox spec. */
209
+ function delegationIssues(manifest, issue) {
210
+ const sandboxes = new Set();
211
+ const addSandboxes = (agent) => {
212
+ for (const capability of agent.capabilities)
213
+ if (capability.sandbox)
214
+ sandboxes.add(canonical(capability.sandbox));
215
+ };
216
+ addSandboxes(manifest);
217
+ for (const capability of manifest.capabilities)
218
+ for (const tool of capability.tools ?? []) {
219
+ const child = tool.agent;
220
+ if (!child)
221
+ continue;
222
+ if (tool.name !== child.id)
223
+ issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
224
+ if (!child.description?.trim() || tool.description !== child.description)
225
+ issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
226
+ if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
227
+ issue(`Agent tool '${tool.name}' must take the standard { task } input`);
228
+ if (tool.outputSchema !== undefined)
229
+ issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
230
+ for (const inner of child.capabilities)
231
+ if (inner.tools?.some((item) => item.agent !== undefined))
232
+ issue(`'${child.id}' delegates to another agent; nested delegation is not supported yet`);
233
+ addSandboxes(child);
234
+ }
235
+ if (sandboxes.size > 1)
236
+ issue("An agent and the agents it uses as tools must declare identical sandboxes");
237
+ }
195
238
  const absolutePath = z.string().min(1).refine((value) => value.startsWith("/") || /^[A-Za-z]:[\\/]/.test(value), { message: "plugin root must be an absolute path" });
239
+ const workflowFnRefSchema = z.object({ fn: z.literal(true) }).strict();
240
+ const workflowNodeSchema = z.lazy(() => z.union([
241
+ z.object({ agent: z.string().min(1) }).strict(),
242
+ z
243
+ .object({
244
+ tool: z
245
+ .object({
246
+ name: z.string().min(1),
247
+ description: z.string().optional(),
248
+ inputSchema: jsonObject.optional(),
249
+ outputSchema: jsonObject.optional(),
250
+ })
251
+ .strict(),
252
+ })
253
+ .strict(),
254
+ z
255
+ .object({
256
+ chain: z
257
+ .object({
258
+ id: z.string().min(1),
259
+ steps: z.array(workflowNodeSchema).min(1),
260
+ })
261
+ .strict(),
262
+ })
263
+ .strict(),
264
+ z
265
+ .object({
266
+ switch: z
267
+ .object({
268
+ id: z.string().min(1),
269
+ on: workflowFnRefSchema,
270
+ cases: z.record(z.string(), workflowNodeSchema),
271
+ default: workflowNodeSchema.optional(),
272
+ })
273
+ .strict(),
274
+ })
275
+ .strict(),
276
+ z
277
+ .object({
278
+ parallel: z
279
+ .object({
280
+ id: z.string().min(1),
281
+ branches: z.record(z.string(), workflowNodeSchema),
282
+ })
283
+ .strict(),
284
+ })
285
+ .strict(),
286
+ z
287
+ .object({
288
+ map: z
289
+ .object({
290
+ id: z.string().min(1),
291
+ over: workflowFnRefSchema,
292
+ each: workflowNodeSchema,
293
+ })
294
+ .strict(),
295
+ })
296
+ .strict(),
297
+ z
298
+ .object({
299
+ loop: z
300
+ .object({
301
+ id: z.string().min(1),
302
+ run: workflowNodeSchema,
303
+ verify: z.union([
304
+ workflowFnRefSchema,
305
+ z.object({ agent: z.string().min(1) }).strict(),
306
+ z
307
+ .object({
308
+ slot: z
309
+ .object({
310
+ id: z.string().min(1).optional(),
311
+ input: workflowFnRefSchema.optional(),
312
+ run: workflowNodeSchema,
313
+ })
314
+ .strict(),
315
+ })
316
+ .strict(),
317
+ ]),
318
+ decide: workflowFnRefSchema,
319
+ })
320
+ .strict(),
321
+ })
322
+ .strict(),
323
+ z
324
+ .object({
325
+ slot: z
326
+ .object({
327
+ id: z.string().min(1).optional(),
328
+ input: workflowFnRefSchema.optional(),
329
+ run: workflowNodeSchema,
330
+ })
331
+ .strict(),
332
+ })
333
+ .strict(),
334
+ ]));
335
+ /** Workflow definition document. `kind: "workflow"`; a missing `kind` is never a workflow. */
336
+ export const WorkflowManifestSchema = z
337
+ .object({
338
+ kind: z.literal("workflow"),
339
+ workflowSchemaVersion: z.literal(1),
340
+ id: z.string().min(1),
341
+ root: workflowNodeSchema,
342
+ sandbox: sandboxManifestSchema.optional(),
343
+ })
344
+ .strict();
345
+ /** Registry document: agent (no `kind`, or legacy) or workflow (`kind: "workflow"`). */
346
+ export const DefinitionDocumentSchema = z.union([
347
+ AgentManifestSchema,
348
+ WorkflowManifestSchema,
349
+ ]);
196
350
  export const PutAgentRequestSchema = z
197
351
  .object({
198
352
  requestId: RequestIdSchema,
199
- manifest: AgentManifestSchema,
353
+ /** Agent or workflow document. Registry `kind` is carried on the document. */
354
+ manifest: DefinitionDocumentSchema,
200
355
  implementationVersion: z.string().min(1),
201
356
  pluginRoots: z.record(z.string(), absolutePath).optional(),
202
357
  })
@@ -215,6 +370,8 @@ export const PutSessionRequestSchema = z
215
370
  info: jsonObject.optional(),
216
371
  vaultIds: z.array(z.string().min(1)).optional(),
217
372
  credentialSelections: z.array(CredentialSelectionSchema).optional(),
373
+ /** Share another session's sandbox (same owner, Tenant, and identical specs). */
374
+ sandbox: z.object({ session: z.string().min(1) }).strict().optional(),
218
375
  })
219
376
  .strict();
220
377
  const vaultWriteBase = {
@@ -333,13 +490,27 @@ const commandBase = {
333
490
  requestId: RequestIdSchema,
334
491
  idempotencyKey: IdempotencyKeySchema,
335
492
  };
336
- export const MessageEventBodySchema = z
337
- .object({
493
+ const messageBase = {
338
494
  ...commandBase,
339
495
  type: z.literal("message"),
340
- content: z.string().min(1),
341
- })
342
- .strict();
496
+ /** Optional turn manifest (Loop patch); validated as a variant of the pinned agent. */
497
+ manifest: AgentManifestSchema.optional(),
498
+ };
499
+ /** Exactly one of `content` or `data`. Optional `manifest` for per-turn agent patches. */
500
+ export const MessageEventBodySchema = z.union([
501
+ z
502
+ .object({
503
+ ...messageBase,
504
+ content: z.string().min(1),
505
+ })
506
+ .strict(),
507
+ z
508
+ .object({
509
+ ...messageBase,
510
+ data: jsonValue,
511
+ })
512
+ .strict(),
513
+ ]);
343
514
  export const ActionOutcomeSchema = z
344
515
  .object({
345
516
  value: z.unknown(),
@@ -356,7 +527,7 @@ export const ActionResultCommandSchema = z
356
527
  outcome: ActionOutcomeSchema,
357
528
  })
358
529
  .strict();
359
- export const SessionCommandSchema = z.discriminatedUnion("type", [
530
+ export const SessionCommandSchema = z.union([
360
531
  MessageEventBodySchema,
361
532
  z
362
533
  .object({
@@ -388,6 +559,7 @@ export const LiveEventSchema = z
388
559
  .object({
389
560
  eventId: z.string(),
390
561
  sessionId: z.string(),
562
+ tenantId: z.string().min(1),
391
563
  turnId: z.string().nullable(),
392
564
  cursor: z.string(),
393
565
  createdAt: z.string(),
@@ -407,11 +579,20 @@ export const AcceptedResponseSchema = z.object({
407
579
  });
408
580
  export const RejectedResponseSchema = z.object({
409
581
  status: z.literal("rejected"),
410
- code: z.string(),
582
+ code: z.enum(ERROR_CODES),
411
583
  message: z.string(),
584
+ details: z.unknown().optional(),
412
585
  activeTurnId: z.string().optional(),
413
586
  requestId: z.string().optional(),
414
587
  });
588
+ /** The agent a call belongs to. Set on work for an agent used as a tool; absent for the root. */
589
+ export const AgentRefSchema = z
590
+ .object({
591
+ id: z.string().min(1),
592
+ path: z.string().min(1),
593
+ delegationId: z.string().min(1).optional(),
594
+ })
595
+ .strict();
415
596
  const actionBase = {
416
597
  actionId: z.string(),
417
598
  sessionId: z.string(),
@@ -425,6 +606,7 @@ const actionBase = {
425
606
  generation: z.number().int().nonnegative(),
426
607
  claimId: z.string().nullable(),
427
608
  leaseExpiresAt: z.string().nullable(),
609
+ agent: AgentRefSchema.optional(),
428
610
  };
429
611
  /** The hook point an action runs, and the capabilities that registered it (manifest order). */
430
612
  export const ActionHookSchema = z
@@ -434,20 +616,56 @@ export const ActionHookSchema = z
434
616
  capabilityIds: z.array(z.string().min(1)).min(1),
435
617
  })
436
618
  .strict();
437
- export const ActionSchema = z.discriminatedUnion("kind", [
438
- z.object({
439
- ...actionBase,
440
- kind: z.literal("tool"),
441
- capabilityId: z.string(),
442
- toolName: z.string(),
443
- inputSchema: jsonObject.optional(),
444
- outputSchema: jsonObject.optional(),
445
- }),
446
- z.object({
447
- ...actionBase,
448
- kind: z.literal("hook"),
449
- hook: ActionHookSchema,
450
- }),
619
+ const agentToolActionSchema = z
620
+ .object({
621
+ ...actionBase,
622
+ kind: z.literal("tool"),
623
+ capabilityId: z.string(),
624
+ toolName: z.string(),
625
+ inputSchema: jsonObject.optional(),
626
+ outputSchema: jsonObject.optional(),
627
+ })
628
+ .strict();
629
+ /** Tool node on a workflow: routed by path + key instead of capabilityId. */
630
+ const workflowToolActionSchema = z
631
+ .object({
632
+ ...actionBase,
633
+ kind: z.literal("tool"),
634
+ path: z.string().min(1),
635
+ key: z.string().min(1),
636
+ inputSchema: jsonObject.optional(),
637
+ outputSchema: jsonObject.optional(),
638
+ })
639
+ .strict();
640
+ const hookActionSchema = z
641
+ .object({
642
+ ...actionBase,
643
+ kind: z.literal("hook"),
644
+ hook: ActionHookSchema,
645
+ })
646
+ .strict();
647
+ const fnActionSchema = z
648
+ .object({
649
+ ...actionBase,
650
+ kind: z.literal("fn"),
651
+ path: z.string().min(1),
652
+ key: z.string().min(1),
653
+ })
654
+ .strict();
655
+ const verifyActionSchema = z
656
+ .object({
657
+ ...actionBase,
658
+ kind: z.literal("verify"),
659
+ path: z.string().min(1),
660
+ key: z.string().min(1),
661
+ })
662
+ .strict();
663
+ export const ActionSchema = z.union([
664
+ agentToolActionSchema,
665
+ workflowToolActionSchema,
666
+ hookActionSchema,
667
+ fnActionSchema,
668
+ verifyActionSchema,
451
669
  ]);
452
670
  export const ActionClaimRequestSchema = z
453
671
  .object({
@@ -489,6 +707,7 @@ export const RegisterExecutorsResponseSchema = z.object({
489
707
  agentId: z.string(),
490
708
  implementationVersion: z.string(),
491
709
  rotated: z.boolean(),
710
+ replacedBy: z.literal("different-credential").optional(),
492
711
  })),
493
712
  });
494
713
  export const ExecutorSummarySchema = z.object({
@@ -501,16 +720,210 @@ export const ExecutorSummarySchema = z.object({
501
720
  export const ListExecutorsResponseSchema = z.object({
502
721
  executors: z.array(ExecutorSummarySchema),
503
722
  });
504
- // Health fields added after the beta stay optional so a new client can parse an older Runtime.
505
- export const HealthResponseSchema = z.object({
723
+ export const ProtocolRangeSchema = z
724
+ .object({
725
+ min: z.number().int(),
726
+ max: z.number().int(),
727
+ features: z.array(z.string()),
728
+ })
729
+ .strict();
730
+ export const HealthResponseSchema = z
731
+ .object({
506
732
  status: z.literal("ok"),
507
733
  service: z.string(),
508
- version: z.string().optional(),
509
- scopeId: z.string().optional(),
510
- pid: z.number().int().positive().optional(),
511
- });
734
+ version: z.string(),
735
+ protocol: ProtocolRangeSchema,
736
+ coreVersion: z.string(),
737
+ hostId: z.string(),
738
+ pid: z.number().int(),
739
+ })
740
+ .strict();
512
741
  export const ReadyResponseSchema = z.object({
513
742
  status: z.enum(["ready", "not_ready"]),
514
743
  service: z.string(),
515
744
  checks: z.record(z.string(), z.boolean()),
516
745
  });
746
+ export const ProtocolRejectedResponseSchema = z
747
+ .object({
748
+ status: z.literal("rejected"),
749
+ code: z.literal("protocol_unsupported"),
750
+ protocol: ProtocolRangeSchema,
751
+ })
752
+ .strict();
753
+ export const TenantEnvelopeSchema = z
754
+ .object({
755
+ id: z.string().min(1),
756
+ name: z.string().min(1),
757
+ createdAt: z.string().min(1),
758
+ updatedAt: z.string().min(1),
759
+ schemaVersion: z.number().int(),
760
+ })
761
+ .strict();
762
+ export const CreateTenantRequestSchema = z
763
+ .object({
764
+ tenantId: z.string().min(1),
765
+ name: z.string().min(1),
766
+ principalId: z.string().min(1),
767
+ credentialHash: z.string().regex(/^[0-9a-f]{64}$/),
768
+ idempotencyKey: IdempotencyKeySchema,
769
+ })
770
+ .strict();
771
+ export const AdminTenantSchema = z
772
+ .object({
773
+ id: z.string().min(1),
774
+ name: z.string().nullable(),
775
+ state: z.enum(["open", "quarantined"]),
776
+ envelope: TenantEnvelopeSchema.nullable(),
777
+ })
778
+ .strict();
779
+ export const QuarantineSchema = z
780
+ .object({
781
+ code: z.enum([
782
+ "locked",
783
+ "kek-missing",
784
+ "corrupt",
785
+ "schema-too-new",
786
+ "migration-failed",
787
+ "envelope-invalid",
788
+ "open-timeout",
789
+ "open-failed",
790
+ ]),
791
+ message: z.string(),
792
+ repair: z.string(),
793
+ lockPath: z.string().optional(),
794
+ lockPid: z.number().int().optional(),
795
+ })
796
+ .strict();
797
+ export const AdminTenantStatusSchema = AdminTenantSchema.extend({
798
+ quarantine: QuarantineSchema.optional(),
799
+ });
800
+ export const HostAggregateSchema = z
801
+ .object({
802
+ runningSessions: z.number().int().nonnegative(),
803
+ connectedExecutors: z.number().int().nonnegative(),
804
+ pendingActions: z.number().int().nonnegative(),
805
+ uncertainEffects: z.number().int().nonnegative(),
806
+ })
807
+ .strict();
808
+ export const AdminHostStatusSchema = z
809
+ .object({
810
+ hostId: z.string().min(1),
811
+ url: z.string().min(1),
812
+ pid: z.number().int(),
813
+ version: z.string().min(1),
814
+ protocol: ProtocolRangeSchema,
815
+ tenants: z.array(AdminTenantSchema),
816
+ aggregate: HostAggregateSchema,
817
+ })
818
+ .strict();
819
+ /** Shared Admin API status (D§4.1). OSS fills `host`; Cloud omits it. */
820
+ export const AdminStatusSchema = z
821
+ .object({
822
+ service: z.string().min(1),
823
+ version: z.string().min(1),
824
+ protocol: ProtocolRangeSchema,
825
+ tenants: z.array(AdminTenantSchema),
826
+ aggregate: HostAggregateSchema,
827
+ host: z
828
+ .object({
829
+ hostId: z.string().min(1),
830
+ url: z.string().min(1),
831
+ pid: z.number().int(),
832
+ })
833
+ .strict()
834
+ .optional(),
835
+ })
836
+ .strict();
837
+ export const ProjectLinkFileSchema = z
838
+ .object({
839
+ format: z.union([z.literal(0), z.literal(1)]).default(0),
840
+ hostUrl: z.string().min(1),
841
+ hostId: z.string().min(1),
842
+ tenantId: z.string().min(1),
843
+ })
844
+ .passthrough();
845
+ export const ProjectCredentialsFileSchema = z
846
+ .object({
847
+ format: z.union([z.literal(0), z.literal(1)]).default(0),
848
+ applicationKey: z.string().regex(/^[0-9a-f]{64}$/),
849
+ principalId: z.string().min(1),
850
+ })
851
+ .passthrough();
852
+ export const HostModelViewSchema = z.union([
853
+ z.object({ configured: z.literal(false) }).strict(),
854
+ z
855
+ .object({
856
+ configured: z.literal(true),
857
+ provider: z.string(),
858
+ model: z.string(),
859
+ authType: z.enum(["api_key", "oauth"]),
860
+ baseUrl: z.string().optional(),
861
+ })
862
+ .strict(),
863
+ ]);
864
+ export const TenantStatusSchema = z
865
+ .object({
866
+ tenant: TenantEnvelopeSchema,
867
+ path: z.string().min(1),
868
+ checks: z
869
+ .object({
870
+ sqlite: z.boolean(),
871
+ scheduler: z.boolean(),
872
+ model: z.boolean(),
873
+ executors: z.boolean(),
874
+ schema: z.boolean(),
875
+ })
876
+ .strict(),
877
+ model: HostModelViewSchema,
878
+ agents: z.array(z
879
+ .object({
880
+ agentId: z.string(),
881
+ registered: z.boolean(),
882
+ connected: z.boolean(),
883
+ })
884
+ .strict()),
885
+ counts: z
886
+ .object({
887
+ sessions: z.number().int().nonnegative(),
888
+ runningSessions: z.number().int().nonnegative(),
889
+ pendingActions: z.number().int().nonnegative(),
890
+ uncertainEffects: z.number().int().nonnegative(),
891
+ })
892
+ .strict(),
893
+ sandbox: z
894
+ .object({
895
+ backend: z.string().nullable(),
896
+ retained: z.number().int().nonnegative(),
897
+ })
898
+ .strict(),
899
+ })
900
+ .strict();
901
+ const seedModelSchema = PutHostModelRequestSchema.omit({
902
+ requestId: true,
903
+ idempotencyKey: true,
904
+ });
905
+ export const SeedTenantConfigRequestSchema = z
906
+ .object({
907
+ requestId: RequestIdSchema,
908
+ sandbox: z
909
+ .object({
910
+ backend: z.enum(["auto", "microsandbox", "virtual"]),
911
+ })
912
+ .strict()
913
+ .optional(),
914
+ model: seedModelSchema.optional(),
915
+ })
916
+ .strict();
917
+ export const SeedTenantConfigResponseSchema = z
918
+ .object({
919
+ applied: z.array(z.string()),
920
+ kept: z.array(z.string()),
921
+ })
922
+ .strict();
923
+ export const ResetTenantRequestSchema = z
924
+ .object({
925
+ requestId: RequestIdSchema,
926
+ scope: z.enum(["sessions", "sandboxes", "all"]),
927
+ activeWork: z.enum(["drain", "cancel"]),
928
+ })
929
+ .strict();
package/dist/define.d.ts CHANGED
@@ -2,7 +2,9 @@ export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./de
2
2
  export type { AgentOptions } from "./definition/builder.js";
3
3
  export { HarnessError, isHarnessError } from "./errors.js";
4
4
  export type { HarnessErrorCode, HarnessErrorDetails, HarnessErrorOptions, } from "./errors.js";
5
- export type { BuiltAgent } from "./types/agent.js";
5
+ export type { AgentTool, BuiltAgent } from "./types/agent.js";
6
+ export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
7
+ export type { Delegate } from "./definition/delegate.js";
6
8
  export { capability, middleware, model, tool } from "./definition/helpers.js";
7
9
  export { ToolError, isToolError } from "./definition/tool-error.js";
8
10
  export { defineSchema } from "./definition/schema.js";
@@ -12,17 +14,21 @@ export { SANDBOX_DEFERRED_FIELDS, SANDBOX_FIELDS, SANDBOX_NETWORK_PRESETS, SANDB
12
14
  export type { SandboxToolName } from "./utils/sandbox.js";
13
15
  export type { Implementations } from "./definition/implementations.js";
14
16
  export type { AgentManifest, CapabilityManifest, McpServerManifest, RuntimeManifest, SandboxManifest, SandboxNetworkPreset, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
15
- export type { CapabilityDeclaration, CapabilityItems, MiddlewareContributions, SkillRecord, StepMiddleware, StepRequest, StepResponse, } from "./types/middleware.js";
17
+ export type { CapabilityDeclaration, CapabilityInput, CapabilityItems, MiddlewareContributions, SkillRecord, StepMiddleware, StepRequest, StepResponse, } from "./types/middleware.js";
16
18
  export type { Patch, Decision, TurnDecision, HookAt, HookScope, HookManifest, HookState, HookToolCall, BeforeHook, AfterHook, BeforeHooks, AfterHooks, BeforeTurnArgs, BeforeStepArgs, AfterStepArgs, AfterTurnArgs, } from "./types/dynamics.js";
17
19
  export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
18
20
  export type { ModelCandidate, ModelControls, ModelDirective, ModelEvidence, ModelFinishReason, ModelAdapter, ModelAdapterContext, ModelPreparedCall, ContextContributor, ContextMutationOptions, ContextSnapshot, ModelCall, ModelCallTool, ModelOutputBlock, PromptContentPart, PromptItem, ModelConfigurationContributor, ModelConfigurationInstruction, ModelConfigurationMutationOptions, ModelConfigurationSnapshot, ModelConfigurationTool, ModelRequest, ModelToolCall, ModelUsage, } from "./types/model.js";
19
21
  export type { BuildDiagnostic, ContextItem, DeferredOutcome, JsonObject, JsonPrimitive, JsonValue, Tripwire, } from "./types/shared.js";
20
22
  export type { ObserveEvent, ObserveModelConfigurationSnapshot, ObserveModelRequested, ObserveSealedCall, ObserveToolSnapshot, Observer, } from "./types/observe.js";
21
23
  export type { InputEvent, MessageInput, InteractionReply, TranscriptEntry, UserContentPart, } from "./types/transcript.js";
22
- export type { Interaction, RequiredInteraction, ToolContent, ToolDefinition, ToolDescriptor, ToolExecutionContext, ToolExecutionResume, ToolInputSchema, ToolOutputSchema, ToolSchema, ToolSchemaSource, StandardToolSchema, StandardSchemaIssue, SchemaIssue, SchemaValidation, SchemaOutput, ToolOwner, ToolOutcome, ToolResult, ToolValidationFailureDetails, ToolEffects, ToolApproval, ToolRunResult, SessionStateBag, } from "./types/tool.js";
24
+ export type { Interaction, RequiredInteraction, ToolContent, ToolDefinition, ToolDescriptor, ToolExecutionContext, AgentRef, ToolExecutionResume, ToolInputSchema, ToolOutputSchema, ToolSchema, ToolSchemaSource, StandardToolSchema, StandardSchemaIssue, SchemaIssue, SchemaValidation, SchemaOutput, ToolOwner, ToolOutcome, ToolResult, ToolValidationFailureDetails, ToolEffects, ToolApproval, ToolRunResult, SessionStateBag, } from "./types/tool.js";
23
25
  export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
24
26
  export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
25
27
  export type { AgentBinding } from "./definition/binding.js";
28
+ export { Loop, Chain, Switch, Parallel, Map, VerdictSchema, isVerdict, withInstructions, withoutTools, WorkflowBuildError, isSlot, isBuiltWorkflow, } from "./definition/workflow/index.js";
29
+ export type { BuiltWorkflow, OutputOf, InputOf, LoopOptions, LoopRunnable, LoopVerify, LoopVerifyFn, LoopDecideFn, LoopVerifyArgs, LoopDecideArgs, LoopDecision, ChainOptions, ChainStep, ChainResults, ChainSlot, SwitchOptions, SwitchCases, ParallelOptions, ParallelBranches, MapOptions, MapOver, Slot, SlotInputArgs, WorkflowRunnable, } from "./definition/workflow/index.js";
30
+ export { isVariantOf } from "./definition/variant.js";
31
+ export type { Verdict, WorkflowBinding, WorkflowManifest } from "./types/workflow.js";
26
32
  export type { BoundMiddleware, BoundToolDefinition, } from "./definition/bound.js";
27
33
  export { bindTool } from "./definition/bind-tool.js";
28
34
  export { bindOutputContract } from "./definition/output-contract.js";
package/dist/define.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./definition/builder.js";
2
2
  export { HarnessError, isHarnessError } from "./errors.js";
3
+ export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
3
4
  export { capability, middleware, model, tool } from "./definition/helpers.js";
4
5
  export { ToolError, isToolError } from "./definition/tool-error.js";
5
6
  export { defineSchema } from "./definition/schema.js";
@@ -9,6 +10,8 @@ export { SANDBOX_DEFERRED_FIELDS, SANDBOX_FIELDS, SANDBOX_NETWORK_PRESETS, SANDB
9
10
  export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
10
11
  export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
11
12
  export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
13
+ export { Loop, Chain, Switch, Parallel, Map, VerdictSchema, isVerdict, withInstructions, withoutTools, WorkflowBuildError, isSlot, isBuiltWorkflow, } from "./definition/workflow/index.js";
14
+ export { isVariantOf } from "./definition/variant.js";
12
15
  export { bindTool } from "./definition/bind-tool.js";
13
16
  export { bindOutputContract } from "./definition/output-contract.js";
14
17
  export { agentFrom } from "./definition/from.js";
@@ -1,6 +1,8 @@
1
1
  import { bindAgent } from "./bind-agent.js";
2
2
  import { createManifest } from "./manifest.js";
3
3
  import { createSkillTools } from "./skill-tools.js";
4
+ import { DELEGATE_NAME_PATTERN, delegateOf, delegatesOf } from "./delegate.js";
5
+ import { canonical } from "../utils/canonical.js";
4
6
  const diagnostic = (code, message, extra = {}) => Object.freeze({ code, message, ...extra });
5
7
  export function assembleAgent(middleware, identity, dynamics = new Map()) {
6
8
  const diagnostics = [];
@@ -72,6 +74,7 @@ export function assembleAgent(middleware, identity, dynamics = new Map()) {
72
74
  else
73
75
  toolOwners.set(entry.name, item.id);
74
76
  }
77
+ diagnostics.push(...delegationDiagnostics(skilled.items));
75
78
  if (diagnostics.length)
76
79
  return Object.freeze({
77
80
  ok: false,
@@ -90,6 +93,38 @@ export function assembleAgent(middleware, identity, dynamics = new Map()) {
90
93
  const agent = bindAgent(frozenMiddleware, manifest, identity, dynamics);
91
94
  return Object.freeze({ ok: true, agent, manifest });
92
95
  }
96
+ /** v1 delegation is one level deep and non-interactive; anything else fails the build by name. */
97
+ function delegationDiagnostics(items) {
98
+ const found = [];
99
+ const sandboxes = new Set();
100
+ for (const item of items)
101
+ if (item.sandbox)
102
+ sandboxes.add(canonical(item.sandbox));
103
+ for (const item of items)
104
+ for (const tool of item.tools ?? []) {
105
+ const delegate = delegateOf(tool);
106
+ if (!delegate)
107
+ continue;
108
+ const child = delegate.manifest;
109
+ const extra = { toolName: tool.name };
110
+ if (!DELEGATE_NAME_PATTERN.test(child.id))
111
+ found.push(diagnostic("delegation.invalid-name", `Agent '${child.id}' is used as a tool, so its id must be 1-64 letters, digits, '_' or '-'`, extra));
112
+ if (!child.description?.trim())
113
+ found.push(diagnostic("delegation.description-required", `Agent '${child.id}' is used as a tool by capability '${item.id}' and needs a description: the parent's model reads it to decide when to delegate`, extra));
114
+ const nested = delegatesOf(child)[0];
115
+ if (nested)
116
+ found.push(diagnostic("delegation.nested", `'${child.id}' delegates to '${nested.manifest.id}'; nested delegation is not supported yet`, extra));
117
+ for (const childTool of delegate.agent?.getBinding().tools ?? [])
118
+ if (childTool.approval)
119
+ found.push(diagnostic("delegation.approval-unsupported", `'${childTool.name}' in '${child.id}' needs approval; agents used as tools can't ask for it yet, so keep it on the parent`, extra));
120
+ for (const capability of child.capabilities)
121
+ if (capability.sandbox)
122
+ sandboxes.add(canonical(capability.sandbox));
123
+ }
124
+ if (sandboxes.size > 1)
125
+ found.push(diagnostic("sandbox.mismatch", "An agent and the agents it uses as tools share one sandbox, so every sandbox they declare must be identical"));
126
+ return found;
127
+ }
93
128
  const SKILL_TOOL_NAMES = new Set(["load_skill", "read_skill_resource"]);
94
129
  function attachSkillTools(items) {
95
130
  const skills = new Map();