@nylorun/core 0.10.0-beta → 0.12.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.
package/dist/contracts.js CHANGED
@@ -517,6 +517,9 @@ export const CredentialSelectionSchema = z
517
517
  const sandboxHostSchema = z.string().refine(isSandboxHostPattern, {
518
518
  message: "network.allow entries must be host names such as api.github.com or *.example.com",
519
519
  });
520
+ const sandboxDurationSchema = (name) => z.string().refine((value) => parseSandboxDuration(value) !== undefined, {
521
+ message: `${name} must be a duration such as 30s, 15m or 1h`,
522
+ });
520
523
  const sandboxResourcesSchema = z
521
524
  .object({
522
525
  cpus: z.number().int().min(1).max(64).optional(),
@@ -539,12 +542,223 @@ export const SandboxInlineRequestSchema = z
539
542
  resources: sandboxResourcesSchema.optional(),
540
543
  })
541
544
  .strict();
545
+ // --- sandboxes as a resource (Host feature `sandboxes`, blueprint D39) ----------------------
546
+ /**
547
+ * A sandbox id: 1–200 characters, one or more `/`-separated segments of letters, digits, `.`,
548
+ * `_` and `-`, each starting with a letter or digit (`user-42`, `team-a/proj-42`). Ids are
549
+ * hierarchical so an `sbx` grant can name a family of them (`team-a/*`).
550
+ */
551
+ const SANDBOX_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/;
552
+ export const SANDBOX_ID_MAX_LENGTH = 200;
553
+ export function isSandboxId(value) {
554
+ return (typeof value === "string" &&
555
+ value.length <= SANDBOX_ID_MAX_LENGTH &&
556
+ SANDBOX_ID_PATTERN.test(value));
557
+ }
558
+ /** An `sbx` entry: an exact sandbox id, or a prefix ending in `/*` (`team-a/*`). */
559
+ export function isSandboxGrant(value) {
560
+ if (typeof value !== "string")
561
+ return false;
562
+ return value.endsWith("/*") ? isSandboxId(value.slice(0, -2)) : isSandboxId(value);
563
+ }
542
564
  /**
543
- * `PutSessionRequest.sandbox`: `false` for none, `{ session }` to share another session's
544
- * sandbox, or an inline sandbox. Omitted means the Tenant's default.
565
+ * Whether `grants` (a subject token's `sbx`) reach sandbox `id`: an exact entry, or a prefix
566
+ * entry `p/*` for any id below `p/`. No grants reach no sandbox.
567
+ */
568
+ export function sandboxGranted(grants, id) {
569
+ for (const grant of grants ?? []) {
570
+ if (grant.endsWith("/*")) {
571
+ if (id.startsWith(grant.slice(0, -1)))
572
+ return true;
573
+ }
574
+ else if (grant === id)
575
+ return true;
576
+ }
577
+ return false;
578
+ }
579
+ export const SandboxIdSchema = z
580
+ .string()
581
+ .refine(isSandboxId, {
582
+ message: "A sandbox id is up to 200 characters: /-separated segments of letters, digits, '.', '_' and '-'",
583
+ })
584
+ .meta({ description: "A sandbox id, such as `user-42` or `team-a/proj-42`" });
585
+ export const SandboxGrantSchema = z.string().refine(isSandboxGrant, {
586
+ message: "A sandbox grant is a sandbox id, or a prefix ending in /* such as team-a/*",
587
+ });
588
+ /** `virtual`: a just-bash workspace, no cluster (F7.1). `pod`: an agent-sandbox pod (F7.2). */
589
+ export const SANDBOX_KINDS = ["virtual", "pod"];
590
+ const LABEL_KEY_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._/-]{0,61}[A-Za-z0-9])?$/;
591
+ const LABEL_VALUE_PATTERN = /^[\x20-\x7e]{0,256}$/;
592
+ export const SANDBOX_LABELS_MAX = 32;
593
+ /** The developer's own key-value pairs; the Runtime stores and filters them, never reads them. */
594
+ export const SandboxLabelsSchema = z
595
+ .record(z.string().regex(LABEL_KEY_PATTERN, {
596
+ message: "Label keys are 1-63 letters, digits, '.', '_', '/' and '-'",
597
+ }), z.string().regex(LABEL_VALUE_PATTERN, {
598
+ message: "Label values are up to 256 printable ASCII characters",
599
+ }))
600
+ .refine((labels) => Object.keys(labels).length <= SANDBOX_LABELS_MAX, {
601
+ message: `At most ${SANDBOX_LABELS_MAX} labels`,
602
+ });
603
+ /**
604
+ * `PUT /v1/sandboxes/{sandboxId}`: creates the sandbox, or finds the one with this id. The spec
605
+ * (`kind`, `image`, `network`, `resources`, `storage`) is checked against the Tenant's limits
606
+ * and fixed once the sandbox exists; `labels`, when sent, replace the sandbox's labels.
607
+ *
608
+ * Kind `pod` (Host feature `sandbox-pods`) is created at once on the Tenant's cluster. A `PUT`
609
+ * on an existing pod sandbox also starts it again when it was stopped, and one with a
610
+ * `lifecycle.ttl` other than its own sets a new expiry (counted from its creation), which
611
+ * revives an expired sandbox.
612
+ */
613
+ export const PutSandboxRequestSchema = z
614
+ .object({
615
+ requestId: RequestIdSchema.optional(),
616
+ /** Default `virtual`. `pod` needs sandbox pods (`nylorun sandbox enable`). */
617
+ kind: z.enum(SANDBOX_KINDS).optional(),
618
+ labels: SandboxLabelsSchema.optional(),
619
+ /** Pods only: the workload image (default the Tenant's, else `python:3.13-slim`). */
620
+ image: z.string().min(1).optional(),
621
+ /** Hosts the sandbox may reach; pods also take `*.suffix` patterns. */
622
+ network: z.object({ allow: z.array(sandboxHostSchema).optional() }).strict().optional(),
623
+ resources: sandboxResourcesSchema.optional(),
624
+ /** Pods only: the volume's size (default 5GiB), fixed once created. */
625
+ storage: z
626
+ .string()
627
+ .refine((value) => parseSandboxSize(value) !== undefined, {
628
+ message: "storage must be a size such as 5GiB",
629
+ })
630
+ .optional(),
631
+ /** Pods only. */
632
+ lifecycle: z
633
+ .object({
634
+ /** How long after its creation the sandbox expires; within the Tenant's `limits.ttl`. */
635
+ ttl: sandboxDurationSchema("lifecycle.ttl").optional(),
636
+ })
637
+ .strict()
638
+ .optional(),
639
+ })
640
+ .strict();
641
+ /** A session attached to a sandbox, as the sandbox's view lists it. */
642
+ export const SandboxSessionSchema = z
643
+ .object({ id: z.string(), activeTurnId: z.string().nullable() })
644
+ .strict();
645
+ /** What the Runtime wants of a pod sandbox (`desired`) and what it last saw (`observed`). */
646
+ export const SANDBOX_POD_DESIRED = ["running", "suspended", "deleted"];
647
+ export const SANDBOX_POD_OBSERVED = [
648
+ "creating",
649
+ "running",
650
+ "suspended",
651
+ "expired",
652
+ "lost",
653
+ "failed",
654
+ "deleting",
655
+ ];
656
+ export const SandboxPodViewSchema = z
657
+ .object({
658
+ desired: z.enum(SANDBOX_POD_DESIRED),
659
+ observed: z.enum(SANDBOX_POD_OBSERVED),
660
+ /** Bumped by every reset: each generation has its own volume. */
661
+ volumeGeneration: z.number().int().nonnegative(),
662
+ /** Bumped each time a pod joins; a host token of an older epoch is refused. */
663
+ hostEpoch: z.number().int().nonnegative(),
664
+ /** When it expires (its TTL), if it has one. */
665
+ expiresAt: z.string().optional(),
666
+ /** Why it failed, or was lost. */
667
+ reason: z.string().optional(),
668
+ })
669
+ .strict();
670
+ /** `PUT` and `GET /v1/sandboxes/{sandboxId}`. */
671
+ export const SandboxViewSchema = z
672
+ .object({
673
+ id: z.string(),
674
+ kind: z.enum(SANDBOX_KINDS),
675
+ labels: z.record(z.string(), z.string()),
676
+ /** The spec, resolved against the Tenant's limits when the sandbox was created. */
677
+ spec: z.record(z.string(), z.unknown()),
678
+ /**
679
+ * `ready` until a tool first runs in it, then the workspace's compute state. A virtual
680
+ * sandbox has nothing to stop: `stopped` means only that its turn queue is idle.
681
+ */
682
+ state: z.enum(["ready", "creating", "running", "stopped"]),
683
+ /** Kind `pod`: what the Runtime wants of the pod and what it last saw. */
684
+ pod: SandboxPodViewSchema.optional(),
685
+ /** Sessions attached to it (acting for a subject, only the subject's own). */
686
+ sessions: z.array(SandboxSessionSchema),
687
+ createdAt: z.string(),
688
+ updatedAt: z.string(),
689
+ })
690
+ .strict();
691
+ export const ListSandboxesResponseSchema = z
692
+ .object({ sandboxes: z.array(SandboxViewSchema) })
693
+ .strict();
694
+ export const DeleteSandboxResponseSchema = z
695
+ .object({ id: z.string(), deleted: z.boolean() })
696
+ .strict();
697
+ /** The schema id of a sandbox's lifecycle events (its stream in the record). */
698
+ export const SANDBOX_EVENT_SCHEMA = "nylorun.sandbox-event/1";
699
+ export const SANDBOX_EVENT_TYPES = [
700
+ "sandbox.created",
701
+ "sandbox.attached",
702
+ "sandbox.detached",
703
+ "sandbox.deleted",
704
+ // Kind `pod` (Host feature `sandbox-pods`).
705
+ "sandbox.running",
706
+ "sandbox.suspended",
707
+ "sandbox.expired",
708
+ "sandbox.relaunched",
709
+ "sandbox.lost",
710
+ "sandbox.reset",
711
+ "sandbox.failed",
712
+ ];
713
+ /** The payload of each sandbox lifecycle event. */
714
+ export const SANDBOX_EVENT_PAYLOADS = {
715
+ "sandbox.created": z
716
+ .object({ kind: z.enum(SANDBOX_KINDS), labels: z.record(z.string(), z.string()) })
717
+ .passthrough(),
718
+ "sandbox.attached": z.object({ sessionId: z.string() }).passthrough(),
719
+ "sandbox.detached": z
720
+ .object({ sessionId: z.string(), reason: z.enum(["reset"]) })
721
+ .passthrough(),
722
+ "sandbox.deleted": z.object({}).passthrough(),
723
+ /** A pod joined and serves the sandbox. */
724
+ "sandbox.running": z.object({ hostEpoch: z.number().int() }).passthrough(),
725
+ /** Stopped (`POST .../stop`, or idle): the volume is kept; the next turn starts it again. */
726
+ "sandbox.suspended": z.object({ reason: z.enum(["stop", "idle"]) }).passthrough(),
727
+ /** Its TTL passed: turns are refused until a `PUT` sets a longer TTL. */
728
+ "sandbox.expired": z.object({ onExpiry: z.enum(["retain", "delete"]) }).passthrough(),
729
+ /** Its pod was replaced (same volume): the old pod's host token no longer works. */
730
+ "sandbox.relaunched": z.object({ hostEpoch: z.number().int() }).passthrough(),
731
+ /** Its volume or node is gone: turns are refused until a reset. */
732
+ "sandbox.lost": z.object({ reason: z.string() }).passthrough(),
733
+ /** Reset: a new pod on a new, empty volume. */
734
+ "sandbox.reset": z.object({ volumeGeneration: z.number().int() }).passthrough(),
735
+ /** The pod did not become ready. */
736
+ "sandbox.failed": z.object({ reason: z.string() }).passthrough(),
737
+ };
738
+ /** One lifecycle event on a sandbox's stream, numbered from 0. */
739
+ export const SandboxEventSchema = z
740
+ .object({
741
+ schema: z.literal(SANDBOX_EVENT_SCHEMA),
742
+ eventId: z.string(),
743
+ tenantId: z.string(),
744
+ sandboxId: z.string(),
745
+ seq: z.number().int().nonnegative(),
746
+ time: z.string(),
747
+ type: z.enum(SANDBOX_EVENT_TYPES),
748
+ payload: z.record(z.string(), z.unknown()),
749
+ })
750
+ .strict();
751
+ export const ListSandboxEventsResponseSchema = z
752
+ .object({ events: z.array(SandboxEventSchema) })
753
+ .strict();
754
+ /**
755
+ * `PutSessionRequest.sandbox`: `false` for none, `{ id }` to attach a sandbox resource (Host
756
+ * feature `sandboxes`), `{ session }` to share another session's sandbox, or an inline sandbox.
757
+ * Omitted means the Tenant's default.
545
758
  */
546
759
  export const SandboxRequestSchema = z.union([
547
760
  z.literal(false),
761
+ z.object({ id: SandboxIdSchema }).strict(),
548
762
  z.object({ session: z.string().min(1) }).strict(),
549
763
  SandboxInlineRequestSchema,
550
764
  ]);
@@ -560,6 +774,8 @@ export const PutSessionRequestSchema = z
560
774
  sandbox: SandboxRequestSchema.optional(),
561
775
  })
562
776
  .strict();
777
+ /** The hosts a harness can run on (blueprint D38). */
778
+ export const SANDBOX_PLACEMENT_HOSTS = ["harness-container", "sandbox"];
563
779
  /**
564
780
  * A Tenant's sandbox configuration (Tenant setting `sandbox.config`): what a session gets when
565
781
  * it names no sandbox, and the limits every session's sandbox must fit.
@@ -585,9 +801,36 @@ export const TenantSandboxConfigSchema = z
585
801
  message: "idle must be a duration such as 30s, 15m or 1h",
586
802
  })
587
803
  .optional(),
804
+ /** The most sandbox resources (`PUT /v1/sandboxes/{id}`) the Tenant may hold. Default 100. */
805
+ sandboxes: z.number().int().min(0).max(100_000).optional(),
806
+ /** Pods: the longest `lifecycle.ttl` a sandbox may ask for. Default none (no limit). */
807
+ ttl: sandboxDurationSchema("limits.ttl").optional(),
588
808
  })
589
809
  .strict()
590
810
  .optional(),
811
+ /** Pods: what happens at expiry and how long a pod has to stop. Read at every timer. */
812
+ lifecycle: z
813
+ .object({
814
+ /** `retain` (default) keeps the volume after the TTL; `delete` deletes the sandbox. */
815
+ onExpiry: z.enum(["retain", "delete"]).optional(),
816
+ /** The pod's grace period to stop, at most 30s. Default 10s. */
817
+ stopGrace: sandboxDurationSchema("lifecycle.stopGrace")
818
+ .refine((value) => (parseSandboxDuration(value) ?? 0) <= 30_000, {
819
+ message: "lifecycle.stopGrace is at most 30s",
820
+ })
821
+ .optional(),
822
+ })
823
+ .strict()
824
+ .optional(),
825
+ /**
826
+ * Where each harness may run (blueprint D38), by harness id (`nylorun`, or `*` for the rest):
827
+ * `harness-container` (the Runtime's harness) and `sandbox` (the engine in a pod sandbox).
828
+ * Default `{ "*": { hosts: ["harness-container", "sandbox"] } }`. Checked when a session
829
+ * opens; a host left out is refused (`placement_refused`).
830
+ */
831
+ placement: z
832
+ .record(z.string().min(1), z.object({ hosts: z.array(z.enum(SANDBOX_PLACEMENT_HOSTS)).min(1) }).strict())
833
+ .optional(),
591
834
  })
592
835
  .strict();
593
836
  /** `PUT /v1/tenant/sandbox`: replaces the Tenant's sandbox configuration. */
@@ -751,7 +994,27 @@ const messageBase = {
751
994
  /** Optional turn manifest (Loop patch); validated as a variant of the pinned agent. */
752
995
  manifest: AgentManifestSchema.optional(),
753
996
  };
754
- /** Exactly one of `content` or `data`. Optional `manifest` for per-turn agent patches. */
997
+ /** The most parts one message may carry (protocol 6). */
998
+ export const MAX_MESSAGE_PARTS = 32;
999
+ /**
1000
+ * One part of a user message (protocol 6): text, or a file by artifact id. A file part without
1001
+ * `version` means the artifact's latest version when the message is accepted; the Runtime pins
1002
+ * it then. The model reads an image as an image, a text file as text, and refuses other files.
1003
+ */
1004
+ export const MessagePartSchema = z.discriminatedUnion("type", [
1005
+ z.object({ type: z.literal("text"), text: z.string().min(1) }).strict(),
1006
+ z
1007
+ .object({
1008
+ type: z.literal("file"),
1009
+ artifactId: z.string().min(1),
1010
+ version: z.number().int().positive().optional(),
1011
+ })
1012
+ .strict(),
1013
+ ]);
1014
+ /**
1015
+ * Exactly one of `content`, `data` or `parts` (protocol 6). Optional `manifest` for per-turn
1016
+ * agent patches.
1017
+ */
755
1018
  export const MessageEventBodySchema = z.union([
756
1019
  z
757
1020
  .object({
@@ -765,6 +1028,12 @@ export const MessageEventBodySchema = z.union([
765
1028
  data: jsonValue,
766
1029
  })
767
1030
  .strict(),
1031
+ z
1032
+ .object({
1033
+ ...messageBase,
1034
+ parts: z.array(MessagePartSchema).min(1).max(MAX_MESSAGE_PARTS),
1035
+ })
1036
+ .strict(),
768
1037
  ]);
769
1038
  export const ActionOutcomeSchema = z
770
1039
  .object({
@@ -1127,6 +1396,8 @@ export const CommandMessagePayloadSchema = z
1127
1396
  type: z.literal("message"),
1128
1397
  content: z.string().optional(),
1129
1398
  data: jsonValue.optional(),
1399
+ /** Text and file parts (protocol 6), as sent: a file part names an artifact, never bytes. */
1400
+ parts: z.array(MessagePartSchema).optional(),
1130
1401
  /** The turn manifest the message carried, if any. */
1131
1402
  manifest: z.unknown().optional(),
1132
1403
  })
@@ -1181,6 +1452,13 @@ export const SandboxStatePayloadSchema = z
1181
1452
  error: z.string().optional(),
1182
1453
  })
1183
1454
  .passthrough();
1455
+ /**
1456
+ * `sandbox.attached`: the session was opened on a sandbox resource (`sandbox: { id }`). The
1457
+ * sandbox's own stream records the same attachment.
1458
+ */
1459
+ export const SandboxAttachedPayloadSchema = z
1460
+ .object({ sandboxId: z.string() })
1461
+ .passthrough();
1184
1462
  /** `sandbox.exec`: one sandbox tool call finished. */
1185
1463
  export const SandboxExecPayloadSchema = z
1186
1464
  .object({
@@ -1253,6 +1531,77 @@ export const TranscriptUpdatedPayloadSchema = z
1253
1531
  length: z.number().int().nonnegative(),
1254
1532
  })
1255
1533
  .passthrough();
1534
+ /**
1535
+ * Where an artifact version's bytes came from: a client's upload, our engine's `save_artifact`,
1536
+ * or the turn-end export of a sandbox's outputs (F8.2), whose listing and bytes the harness
1537
+ * holding the workspace supplied.
1538
+ */
1539
+ export const ArtifactSourceSchema = z.enum(["upload", "engine", "export"]);
1540
+ /**
1541
+ * What an artifact holds: one file, or a folder (F8.2), whose versions are manifests of paths to
1542
+ * content-addressed files.
1543
+ */
1544
+ export const ArtifactKindSchema = z.enum(["file", "folder"]);
1545
+ /**
1546
+ * `artifact.created` and `artifact.version.created` (protocol 6): a file or folder artifact of the
1547
+ * session, or a new version of one, committed. Ids, sizes and hashes, never bytes. A folder's
1548
+ * `size` is the sum of its files' and its `sha256` is its manifest's.
1549
+ */
1550
+ export const ArtifactVersionPayloadSchema = z
1551
+ .object({
1552
+ artifactId: z.string(),
1553
+ kind: ArtifactKindSchema,
1554
+ name: z.string(),
1555
+ contentType: z.string(),
1556
+ version: z.number().int().positive(),
1557
+ size: z.number().int().nonnegative(),
1558
+ sha256: z.string(),
1559
+ source: ArtifactSourceSchema,
1560
+ /** The tool call that saved it (`save_artifact`), when our engine did. */
1561
+ callId: z.string().optional(),
1562
+ /** A folder's number of files. */
1563
+ fileCount: z.number().int().nonnegative().optional(),
1564
+ /**
1565
+ * True when the listing and the bytes are the harness's claim (a turn-end export): the
1566
+ * Runtime stored what the harness holding the workspace supplied, without observing it.
1567
+ */
1568
+ claimed: z.boolean().optional(),
1569
+ })
1570
+ .passthrough();
1571
+ /** `artifact.deleted`: the artifact and every version of it are gone. */
1572
+ export const ArtifactDeletedPayloadSchema = z
1573
+ .object({ artifactId: z.string(), name: z.string() })
1574
+ .passthrough();
1575
+ /** Why a turn-end export stored nothing although the sandbox had outputs (F8.2). */
1576
+ export const ArtifactExportSkipReasonSchema = z.enum([
1577
+ "too_many_files",
1578
+ "file_too_large",
1579
+ "too_large",
1580
+ "tenant_total",
1581
+ ]);
1582
+ /**
1583
+ * `artifact.export.skipped`: the turn's outputs were past a limit, so no folder version was
1584
+ * written. The turn itself completed.
1585
+ */
1586
+ export const ArtifactExportSkippedPayloadSchema = z
1587
+ .object({
1588
+ /** The folder artifact the export writes: `outputs`. */
1589
+ name: z.string(),
1590
+ reason: ArtifactExportSkipReasonSchema,
1591
+ message: z.string(),
1592
+ /** The limit passed: files, or bytes. */
1593
+ limit: z.number().int().nonnegative().optional(),
1594
+ /** The file past the per-file limit (`file_too_large`). */
1595
+ path: z.string().optional(),
1596
+ })
1597
+ .passthrough();
1598
+ /**
1599
+ * `artifact.export.failed`: the turn-end export could not finish (the sandbox or the Object store
1600
+ * failed). The turn itself completed; the next turn exports again.
1601
+ */
1602
+ export const ArtifactExportFailedPayloadSchema = z
1603
+ .object({ name: z.string(), message: z.string() })
1604
+ .passthrough();
1256
1605
  /**
1257
1606
  * The event catalog (Durable Streams §9.5): every session event type, its payload schema, its
1258
1607
  * payload schema version and who writes it. A type not listed here cannot be written. A type
@@ -1289,11 +1638,29 @@ export const EVENT_CATALOG = {
1289
1638
  "delegation.completed": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
1290
1639
  "sandbox.state": { payload: SandboxStatePayloadSchema, source: "loop", version: 1 },
1291
1640
  "sandbox.exec": { payload: SandboxExecPayloadSchema, source: "loop", version: 1 },
1641
+ "sandbox.attached": { payload: SandboxAttachedPayloadSchema, source: "api", version: 1 },
1292
1642
  "node.started": { payload: NodeStartedPayloadSchema, source: "loop", version: 1 },
1293
1643
  "node.agent": { payload: NodeAgentPayloadSchema, source: "loop", version: 1 },
1294
1644
  "loop.iteration": { payload: LoopIterationPayloadSchema, source: "loop", version: 1 },
1295
1645
  "loop.verified": { payload: LoopVerifiedPayloadSchema, source: "api", version: 1 },
1296
1646
  "loop.decided": { payload: LoopDecidedPayloadSchema, source: "api", version: 1 },
1647
+ "artifact.created": { payload: ArtifactVersionPayloadSchema, source: "api", version: 1 },
1648
+ "artifact.version.created": {
1649
+ payload: ArtifactVersionPayloadSchema,
1650
+ source: "api",
1651
+ version: 1,
1652
+ },
1653
+ "artifact.deleted": { payload: ArtifactDeletedPayloadSchema, source: "api", version: 1 },
1654
+ "artifact.export.skipped": {
1655
+ payload: ArtifactExportSkippedPayloadSchema,
1656
+ source: "api",
1657
+ version: 1,
1658
+ },
1659
+ "artifact.export.failed": {
1660
+ payload: ArtifactExportFailedPayloadSchema,
1661
+ source: "api",
1662
+ version: 1,
1663
+ },
1297
1664
  "transcript.updated": {
1298
1665
  payload: TranscriptUpdatedPayloadSchema,
1299
1666
  source: "loop",
@@ -1433,6 +1800,18 @@ export const StreamRelayStatusSchema = z
1433
1800
  lagBytes: z.number().nonnegative().optional(),
1434
1801
  })
1435
1802
  .strict();
1803
+ /**
1804
+ * The Tenant's harnesses (F6.2): `in-process` runs one in core's process; `remote` waits for
1805
+ * harnesses on the Harness API listener. `workspace` says one that serves the Tenant's
1806
+ * workspaces is connected.
1807
+ */
1808
+ export const HarnessStatusSchema = z
1809
+ .object({
1810
+ mode: z.enum(["in-process", "remote"]),
1811
+ connected: z.number().int().nonnegative(),
1812
+ workspace: z.boolean(),
1813
+ })
1814
+ .strict();
1436
1815
  export const HostAggregateSchema = z
1437
1816
  .object({
1438
1817
  runningSessions: z.number().int().nonnegative(),
@@ -1442,6 +1821,8 @@ export const HostAggregateSchema = z
1442
1821
  uncertainEffects: z.number().int().nonnegative(),
1443
1822
  /** This process's stream relay, when it runs one (a Host with S2). */
1444
1823
  relay: StreamRelayStatusSchema.optional(),
1824
+ /** The open Tenant's harnesses. */
1825
+ harness: HarnessStatusSchema.optional(),
1445
1826
  })
1446
1827
  .strict();
1447
1828
  export const AdminHostStatusSchema = z
@@ -1475,16 +1856,18 @@ export const AdminStatusSchema = z
1475
1856
  })
1476
1857
  .strict();
1477
1858
  /**
1478
- * `.nylorun/link.json`: the installation a Project uses. Format 2 (one Tenant per
1479
- * installation) names the local `stack` that `nylorun start` created or attached; `tenantId`
1480
- * is information only, since nothing in a request selects a Tenant. Formats 0 and 1 named a
1481
- * Tenant on a multi-Tenant Host of an older Runtime.
1859
+ * `.nylorun/link.json`: the installation a Project uses. Format 3 names the local `tenant`
1860
+ * that `nylorun start` created or attached; `tenantId` is information only, since nothing in a
1861
+ * request selects a Tenant. Formats 0–2 are from older releases; they parse so readers can say
1862
+ * why they refuse them.
1482
1863
  */
1483
1864
  export const ProjectLinkFileSchema = z
1484
1865
  .object({
1485
- format: z.union([z.literal(0), z.literal(1), z.literal(2)]).default(0),
1486
- /** The local stack's name (format 2); absent for an installation that is not a stack. */
1487
- stack: z.string().min(1).optional(),
1866
+ format: z
1867
+ .union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)])
1868
+ .default(0),
1869
+ /** The local Tenant's name (format 3); absent for an installation that is not local. */
1870
+ tenant: z.string().min(1).optional(),
1488
1871
  hostUrl: z.string().min(1),
1489
1872
  hostId: z.string().min(1),
1490
1873
  tenantId: z.string().min(1).optional(),
@@ -1546,6 +1929,8 @@ export const TenantStatusSchema = z
1546
1929
  retained: z.number().int().nonnegative(),
1547
1930
  })
1548
1931
  .strict(),
1932
+ /** The Tenant's harnesses (F6.2). */
1933
+ harness: HarnessStatusSchema.optional(),
1549
1934
  /**
1550
1935
  * Durable Session Execution invocations of this Tenant that need an operator: paused
1551
1936
  * after exhausting retries, or backing off after failures. Absent when the execution
@@ -1610,7 +1995,7 @@ export const SeedTenantConfigRequestSchema = z
1610
1995
  model: seedModelSchema.optional(),
1611
1996
  /**
1612
1997
  * The Tenant's model calls use the Runtime's deterministic fixture model instead of its
1613
- * host model, e.g. for the stack Tenant a smoke check resets (scripts/lib/stack-tenant.mjs). Stored
1998
+ * host model, e.g. for the Tenant a smoke check resets (scripts/lib/stack-tenant.mjs). Stored
1614
1999
  * as Tenant setting `model.fixture`. Host feature `tenant-fixture-model`.
1615
2000
  */
1616
2001
  fixtureModel: z.literal(true).optional(),
@@ -1632,7 +2017,8 @@ export const ResetTenantRequestSchema = z
1632
2017
  /**
1633
2018
  * Acting for a subject (Host feature `subject-headers`): what an application principal may
1634
2019
  * narrow a request to. `sessions:own` and `vaults:own` reach only the subject's own sessions
1635
- * and vaults; the others reach Tenant-wide resources.
2020
+ * and vaults; the others reach Tenant-wide resources. `sandboxes:write` creates and deletes
2021
+ * sandboxes (Host feature `sandboxes`); a subject token's reach only the ids its `sbx` grants.
1636
2022
  */
1637
2023
  export const SUBJECT_SCOPES = [
1638
2024
  "agents:read",
@@ -1640,6 +2026,7 @@ export const SUBJECT_SCOPES = [
1640
2026
  "sessions:own",
1641
2027
  "vaults:own",
1642
2028
  "tenant:settings",
2029
+ "sandboxes:write",
1643
2030
  ];
1644
2031
  /** 1–200 visible ASCII characters; spaces only inside. */
1645
2032
  const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
@@ -1680,7 +2067,14 @@ export function parseSubjectHeaders(subject, scopes) {
1680
2067
  }
1681
2068
  // --- subject tokens and the access policy (Host feature `subject-tokens`) ------------------
1682
2069
  /** Scopes a subject token may carry: never `agents:write` or `tenant:settings`. */
1683
- export const TOKEN_SCOPES = ["agents:read", "sessions:own", "vaults:own"];
2070
+ export const TOKEN_SCOPES = [
2071
+ "agents:read",
2072
+ "sessions:own",
2073
+ "vaults:own",
2074
+ "sandboxes:write",
2075
+ ];
2076
+ /** The most `sandboxes` grants one subject token carries (it is capped at 4 KiB). */
2077
+ export const TOKEN_SANDBOX_GRANTS_MAX = 16;
1684
2078
  const TokenScopeSchema = z.enum(TOKEN_SCOPES);
1685
2079
  /** The JWT `typ` of a subject token (RFC 8725 explicit typing). */
1686
2080
  export const SUBJECT_TOKEN_TYPE = "nylorun-subject+jwt";
@@ -1765,6 +2159,11 @@ export const CreateTokenRequestSchema = z
1765
2159
  role: z.string().regex(ROLE_NAME_PATTERN),
1766
2160
  scopes: z.array(TokenScopeSchema).min(1).optional(),
1767
2161
  agents: z.array(z.string().min(1)).optional(),
2162
+ /**
2163
+ * The sandboxes the token reaches (its `sbx` claim): exact ids, or prefixes ending in `/*`.
2164
+ * Absent or empty: none (Host feature `sandboxes`).
2165
+ */
2166
+ sandboxes: z.array(SandboxGrantSchema).max(TOKEN_SANDBOX_GRANTS_MAX).optional(),
1768
2167
  ttlSeconds: z
1769
2168
  .number()
1770
2169
  .int()
@@ -1782,6 +2181,8 @@ export const CreateTokenResponseSchema = z
1782
2181
  role: z.string(),
1783
2182
  scopes: z.array(TokenScopeSchema),
1784
2183
  agents: AgentAllowlistSchema,
2184
+ /** The token's `sbx` grants, when it has any. */
2185
+ sandboxes: z.array(z.string()).optional(),
1785
2186
  keyId: z.string(),
1786
2187
  })
1787
2188
  .strict();
@@ -1957,11 +2358,16 @@ export const SessionViewSchema = z
1957
2358
  activeTurnId: z.string().nullable(),
1958
2359
  vaultIds: z.array(z.string()),
1959
2360
  credentialSelections: z.array(CredentialSelectionSchema),
1960
- /** The session whose sandbox this one shares; `null` when it owns its own. */
2361
+ /**
2362
+ * The session whose sandbox this one shares; `null` when it owns its own. Deprecated: share
2363
+ * a sandbox resource with `sandbox: { id }` (the client's `sandboxes.forSession()`).
2364
+ */
1961
2365
  sandboxOwnerId: z.string().nullable(),
2366
+ /** The sandbox resource the session is attached to (`sandbox: { id }`), if any. */
2367
+ sandboxId: z.string().optional(),
1962
2368
  /** The sandbox pinned when the session was opened, or `null`. */
1963
2369
  sandbox: z.record(z.string(), z.unknown()).nullable(),
1964
- sandboxSource: z.enum(["default", "inline", "shared"]).optional(),
2370
+ sandboxSource: z.enum(["default", "inline", "shared", "sandbox"]).optional(),
1965
2371
  mcpSnapshot: z.record(z.string(), z.unknown()).nullable(),
1966
2372
  mcpDiagnostics: z.array(z.record(z.string(), z.unknown())),
1967
2373
  /** What the session waits on: interactions, approvals, timers. */
@@ -2027,11 +2433,24 @@ export const EffectiveSandboxConfigSchema = z
2027
2433
  resources: SandboxResourcesLimitSchema,
2028
2434
  defaultResources: SandboxResourcesLimitSchema,
2029
2435
  idle: z.string(),
2436
+ /** The most sandbox resources the Tenant may hold. */
2437
+ sandboxes: z.number().int().nonnegative().optional(),
2438
+ /** Pods: the longest `lifecycle.ttl`, when the Tenant sets one. */
2439
+ ttl: z.string().optional(),
2030
2440
  })
2031
2441
  .strict(),
2442
+ /** Pods (Host feature `sandbox-pods`): what happens at expiry, and the pod's stop grace. */
2443
+ lifecycle: z
2444
+ .object({ onExpiry: z.enum(["retain", "delete"]), stopGrace: z.string() })
2445
+ .strict()
2446
+ .optional(),
2447
+ /** Where each harness may run (D38). */
2448
+ placement: z
2449
+ .record(z.string(), z.object({ hosts: z.array(z.enum(SANDBOX_PLACEMENT_HOSTS)) }).strict())
2450
+ .optional(),
2032
2451
  })
2033
2452
  .strict();
2034
- const SandboxBackendNameSchema = z.enum(["virtual"]);
2453
+ const SandboxBackendNameSchema = z.enum(["virtual", "local"]);
2035
2454
  const SandboxIsolationSchema = z.enum(["process", "container"]);
2036
2455
  /** `GET` and `PUT /v1/tenant/sandbox`: the backend chosen, and the configuration in force. */
2037
2456
  export const TenantSandboxViewSchema = z
@@ -2051,6 +2470,20 @@ export const TenantSandboxViewSchema = z
2051
2470
  .strict()),
2052
2471
  defaultImage: z.string(),
2053
2472
  config: EffectiveSandboxConfigSchema,
2473
+ /**
2474
+ * The Tenant's cluster for pod sandboxes (`nylorun sandbox enable`), as the sandboxes
2475
+ * service reports it; null without one, or when the service does not answer.
2476
+ */
2477
+ cluster: z
2478
+ .object({
2479
+ namespace: z.string(),
2480
+ context: z.string(),
2481
+ ready: z.boolean(),
2482
+ controllerVersion: z.string().optional(),
2483
+ networkPolicy: z.object({ enforced: z.boolean(), probedAt: z.string().optional() }).optional(),
2484
+ })
2485
+ .nullable()
2486
+ .optional(),
2054
2487
  })
2055
2488
  .strict();
2056
2489
  /** What a usage total or a budget covers: the whole Tenant, one agent, or one turn. */
@@ -2392,3 +2825,176 @@ export function parseFrameAncestors(value) {
2392
2825
  throw new Error(`${entry} is not an exact origin. Use origins such as nylorun://localhost or https://app.example.com, with no wildcards or paths.`);
2393
2826
  return [...new Set(entries)];
2394
2827
  }
2828
+ // --- File artifacts (protocol 6, blueprint D35, F8.1) ----------------------------------------
2829
+ /** The JWT `typ` of a capability link's token (RFC 8725 explicit typing). */
2830
+ export const ARTIFACT_LINK_TOKEN_TYPE = "nylorun-artifact+jwt";
2831
+ /**
2832
+ * A capability link lives no longer than a subject token: rotating signing keys revokes the
2833
+ * previous key once the longest token it may have signed has expired.
2834
+ */
2835
+ export const ARTIFACT_LINK_MAX_TTL_SECONDS = TOKEN_TTL_MAX_SECONDS;
2836
+ export const ARTIFACT_LINK_DEFAULT_TTL_SECONDS = 300;
2837
+ /** A Tenant's limits when it sets none: 100 MiB per file, 10 GiB in all. */
2838
+ export const ARTIFACT_FILE_BYTES_DEFAULT = 100 * 1024 * 1024;
2839
+ export const ARTIFACT_TOTAL_BYTES_DEFAULT = 10 * 1024 * 1024 * 1024;
2840
+ /** The longest artifact name, in characters. */
2841
+ export const ARTIFACT_NAME_MAX = 255;
2842
+ /** The longest path of a file in a folder artifact, in characters. */
2843
+ export const ARTIFACT_PATH_MAX = 1024;
2844
+ /** Labels: up to 32, keys 1–63 characters, values up to 256. */
2845
+ export const ArtifactLabelsSchema = z
2846
+ .record(z.string().min(1).max(63), z.string().max(256))
2847
+ .refine((labels) => Object.keys(labels).length <= 32, { message: "At most 32 labels" });
2848
+ /**
2849
+ * One version of an artifact: immutable once it exists. A folder version's `size` is the sum of
2850
+ * its files' sizes and its `sha256` is its manifest's.
2851
+ */
2852
+ export const ArtifactVersionViewSchema = z
2853
+ .object({
2854
+ version: z.number().int().positive(),
2855
+ size: z.number().int().nonnegative(),
2856
+ sha256: z.string().meta({ description: "SHA-256 of the bytes (a folder: of its manifest), lowercase hex" }),
2857
+ contentType: z.string(),
2858
+ source: ArtifactSourceSchema,
2859
+ createdAt: z.string(),
2860
+ })
2861
+ .strict();
2862
+ /**
2863
+ * An artifact: an id, a name and numbered versions, its bytes in the Object store. A file's
2864
+ * version is its bytes; a folder's (F8.2) is a manifest of paths to content-addressed files.
2865
+ */
2866
+ export const ArtifactViewSchema = z
2867
+ .object({
2868
+ artifactId: z.string(),
2869
+ kind: ArtifactKindSchema,
2870
+ name: z.string(),
2871
+ contentType: z.string().meta({ description: "The latest version's media type" }),
2872
+ /** The session it belongs to; absent for a Tenant-wide artifact an application made. */
2873
+ sessionId: z.string().optional(),
2874
+ latestVersion: z.number().int().positive(),
2875
+ labels: z.record(z.string(), z.string()).optional(),
2876
+ createdAt: z.string(),
2877
+ updatedAt: z.string(),
2878
+ /** Every version, oldest first (`GET /v1/artifacts/{id}` only). */
2879
+ versions: z.array(ArtifactVersionViewSchema).optional(),
2880
+ })
2881
+ .strict();
2882
+ export const ListArtifactsResponseSchema = z
2883
+ .object({ artifacts: z.array(ArtifactViewSchema) })
2884
+ .strict();
2885
+ /** What an upload answers: the artifact, and the version the upload created. */
2886
+ export const UploadArtifactResponseSchema = z
2887
+ .object({ artifact: ArtifactViewSchema, version: ArtifactVersionViewSchema })
2888
+ .strict();
2889
+ export const DeleteArtifactResponseSchema = z
2890
+ .object({ artifactId: z.string(), deleted: z.boolean() })
2891
+ .strict();
2892
+ /** `POST /v1/artifacts/{id}/links`: a capability link to one version. */
2893
+ export const CreateArtifactLinkRequestSchema = z
2894
+ .object({
2895
+ requestId: RequestIdSchema.optional(),
2896
+ /** The version to open. Default: the latest. */
2897
+ version: z.number().int().positive().optional(),
2898
+ /** Seconds until the link stops working. Default 300, at most 900. */
2899
+ expiresIn: z.number().int().min(1).max(ARTIFACT_LINK_MAX_TTL_SECONDS).optional(),
2900
+ /**
2901
+ * A folder's file, by its path in the folder: the link opens that one file. Without it, a
2902
+ * folder's link opens its zip.
2903
+ */
2904
+ file: z.string().min(1).max(ARTIFACT_PATH_MAX).optional(),
2905
+ })
2906
+ .strict();
2907
+ /** A capability link: `GET` its path on the Runtime with no credential, until it expires. */
2908
+ export const ArtifactLinkSchema = z
2909
+ .object({
2910
+ /** `/v1/artifact-links/<token>`, on the Runtime that minted it. */
2911
+ path: z.string(),
2912
+ artifactId: z.string(),
2913
+ version: z.number().int().positive(),
2914
+ /** The folder's file the link opens; absent for a file artifact, or a folder's zip. */
2915
+ file: z.string().optional(),
2916
+ expiresAt: z.string(),
2917
+ })
2918
+ .strict();
2919
+ // --- Folder artifacts (protocol 6, F8.2) -------------------------------------------------------
2920
+ /** The media type of a folder artifact and of its manifests. */
2921
+ export const FOLDER_CONTENT_TYPE = "application/vnd.nylorun.folder+json";
2922
+ /** The manifest format a folder version is stored as. */
2923
+ export const FOLDER_MANIFEST_FORMAT = "nylorun.folder.v1";
2924
+ /** The folder artifact a session's turn-end export writes, one per session. */
2925
+ export const OUTPUTS_ARTIFACT_NAME = "outputs";
2926
+ /** The most files one turn-end export stores; past it the export is skipped. */
2927
+ export const EXPORT_MAX_FILES = 10_000;
2928
+ /** The most bytes one turn-end export stores (before dedupe); past it the export is skipped. */
2929
+ export const EXPORT_MAX_BYTES = 1024 * 1024 * 1024;
2930
+ /** One file of a folder: its path in the folder (`/`-separated, relative), size, hash and type. */
2931
+ export const FolderEntrySchema = z
2932
+ .object({
2933
+ path: z.string().min(1).max(ARTIFACT_PATH_MAX),
2934
+ size: z.number().int().nonnegative(),
2935
+ sha256: z.string().meta({ description: "SHA-256 of the file's bytes, lowercase hex" }),
2936
+ contentType: z.string(),
2937
+ })
2938
+ .strict();
2939
+ /**
2940
+ * A folder version as stored: the files, sorted by path, each naming its content-addressed
2941
+ * bytes by SHA-256. The one manifest format for folders, reused by P5's snapshots.
2942
+ */
2943
+ export const FolderManifestSchema = z
2944
+ .object({
2945
+ format: z.literal(FOLDER_MANIFEST_FORMAT),
2946
+ entries: z.array(FolderEntrySchema),
2947
+ })
2948
+ .strict();
2949
+ /** `GET /v1/artifacts/{id}/versions/{n|latest}/tree`: a folder version's files. */
2950
+ export const ArtifactTreeSchema = z
2951
+ .object({
2952
+ artifactId: z.string(),
2953
+ version: z.number().int().positive(),
2954
+ /** Every file, sorted by path. */
2955
+ entries: z.array(FolderEntrySchema),
2956
+ })
2957
+ .strict();
2958
+ /** `GET /v1/artifacts/{id}/versions/{n|latest}/diff?from=m`: what changed between two versions. */
2959
+ export const ArtifactDiffSchema = z
2960
+ .object({
2961
+ artifactId: z.string(),
2962
+ /** The version compared against; absent when there is none (version 1, no `from`). */
2963
+ from: z.number().int().positive().optional(),
2964
+ to: z.number().int().positive(),
2965
+ /** Files only in `to`, sorted by path. */
2966
+ added: z.array(FolderEntrySchema),
2967
+ /** Files only in `from`. */
2968
+ removed: z.array(FolderEntrySchema),
2969
+ /** Files in both whose bytes or media type differ. */
2970
+ changed: z.array(z.object({ path: z.string(), from: FolderEntrySchema, to: FolderEntrySchema }).strict()),
2971
+ })
2972
+ .strict();
2973
+ /** A Tenant's artifact limits, stored as Tenant setting `artifacts.config`. */
2974
+ export const TenantArtifactsConfigSchema = z
2975
+ .object({
2976
+ limits: z
2977
+ .object({
2978
+ /** The largest file one upload may store, in bytes. Default 100 MiB. */
2979
+ fileBytes: z.number().int().positive().optional(),
2980
+ /** The most bytes every artifact version together may hold. Default 10 GiB. */
2981
+ totalBytes: z.number().int().positive().optional(),
2982
+ })
2983
+ .strict()
2984
+ .optional(),
2985
+ })
2986
+ .strict();
2987
+ /** `PUT /v1/tenant/artifacts`: replaces the Tenant's artifact configuration. */
2988
+ export const PutTenantArtifactsRequestSchema = TenantArtifactsConfigSchema.extend({
2989
+ requestId: RequestIdSchema.optional(),
2990
+ }).strict();
2991
+ export const TenantArtifactsViewSchema = z
2992
+ .object({
2993
+ limits: z.object({ fileBytes: z.number().int(), totalBytes: z.number().int() }).strict(),
2994
+ /**
2995
+ * Bytes the artifacts store now: every file version, plus each distinct file of the folders
2996
+ * once (folders share content-addressed files).
2997
+ */
2998
+ usedBytes: z.number().int().nonnegative(),
2999
+ })
3000
+ .strict();