@nylorun/core 0.11.0-beta → 0.13.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/CHANGELOG.md +92 -0
- package/dist/compatibility.d.ts +71 -34
- package/dist/compatibility.js +76 -46
- package/dist/contracts.d.ts +1078 -215
- package/dist/contracts.js +742 -181
- package/dist/define.d.ts +1 -1
- package/dist/define.js +1 -1
- package/dist/definition/sandbox-capability.d.ts +13 -0
- package/dist/definition/sandbox-capability.js +59 -0
- package/dist/harness-api/errors.d.ts +7 -0
- package/dist/harness-api/errors.js +9 -0
- package/dist/harness-api/hash.d.ts +12 -0
- package/dist/harness-api/hash.js +34 -0
- package/dist/harness-api/index.d.ts +10 -0
- package/dist/harness-api/index.js +10 -0
- package/dist/harness-api/messages.d.ts +394 -0
- package/dist/harness-api/messages.js +21 -0
- package/dist/harness-api/rpc.d.ts +78 -0
- package/dist/harness-api/rpc.js +240 -0
- package/dist/harness-api/schema.d.ts +155 -0
- package/dist/harness-api/schema.js +271 -0
- package/dist/harness-api/transcript.d.ts +29 -0
- package/dist/harness-api/transcript.js +74 -0
- package/package.json +6 -2
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
|
+
/** A sandbox grant: 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
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Whether `grants` (a token caller's sandbox grants) 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
|
+
});
|
|
542
603
|
/**
|
|
543
|
-
* `
|
|
544
|
-
*
|
|
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(),
|
|
808
|
+
})
|
|
809
|
+
.strict()
|
|
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(),
|
|
588
822
|
})
|
|
589
823
|
.strict()
|
|
590
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. */
|
|
@@ -621,14 +864,33 @@ const oauthRefreshSchema = z
|
|
|
621
864
|
tokenEndpointAuth: tokenEndpointAuthSchema,
|
|
622
865
|
})
|
|
623
866
|
.strict();
|
|
867
|
+
/** The owner of every installation vault (`scope: "installation"`); a reserved subject. */
|
|
868
|
+
export const INSTALLATION_OWNER = "installation";
|
|
624
869
|
export const CreateVaultRequestSchema = z
|
|
625
870
|
.object({
|
|
626
871
|
...vaultWriteBase,
|
|
627
872
|
name: z.string().min(1),
|
|
628
|
-
|
|
873
|
+
/**
|
|
874
|
+
* `user` (the default): one person's vault, owned by `ownerUserId`. `installation`: the
|
|
875
|
+
* installation's own vault, owned by `installation`, which any session may attach;
|
|
876
|
+
* application keys only.
|
|
877
|
+
*/
|
|
878
|
+
scope: z.enum(["user", "installation"]).optional(),
|
|
879
|
+
/** Required for a `user` vault; absent (or `installation`) for an installation vault. */
|
|
880
|
+
ownerUserId: z.string().min(1).optional(),
|
|
629
881
|
metadata: z.record(z.string(), z.string()).optional(),
|
|
630
882
|
})
|
|
631
|
-
.strict()
|
|
883
|
+
.strict()
|
|
884
|
+
.superRefine((value, ctx) => {
|
|
885
|
+
if ((value.scope ?? "user") === "user") {
|
|
886
|
+
if (value.ownerUserId === undefined)
|
|
887
|
+
ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "ownerUserId is required for a user vault" });
|
|
888
|
+
else if (value.ownerUserId === INSTALLATION_OWNER)
|
|
889
|
+
ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "installation is reserved for installation vaults" });
|
|
890
|
+
}
|
|
891
|
+
else if (value.ownerUserId !== undefined && value.ownerUserId !== INSTALLATION_OWNER)
|
|
892
|
+
ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "An installation vault is owned by installation" });
|
|
893
|
+
});
|
|
632
894
|
export const CreateCredentialRequestSchema = z
|
|
633
895
|
.object({
|
|
634
896
|
...vaultWriteBase,
|
|
@@ -751,7 +1013,27 @@ const messageBase = {
|
|
|
751
1013
|
/** Optional turn manifest (Loop patch); validated as a variant of the pinned agent. */
|
|
752
1014
|
manifest: AgentManifestSchema.optional(),
|
|
753
1015
|
};
|
|
754
|
-
/**
|
|
1016
|
+
/** The most parts one message may carry (protocol 6). */
|
|
1017
|
+
export const MAX_MESSAGE_PARTS = 32;
|
|
1018
|
+
/**
|
|
1019
|
+
* One part of a user message (protocol 6): text, or a file by artifact id. A file part without
|
|
1020
|
+
* `version` means the artifact's latest version when the message is accepted; the Runtime pins
|
|
1021
|
+
* it then. The model reads an image as an image, a text file as text, and refuses other files.
|
|
1022
|
+
*/
|
|
1023
|
+
export const MessagePartSchema = z.discriminatedUnion("type", [
|
|
1024
|
+
z.object({ type: z.literal("text"), text: z.string().min(1) }).strict(),
|
|
1025
|
+
z
|
|
1026
|
+
.object({
|
|
1027
|
+
type: z.literal("file"),
|
|
1028
|
+
artifactId: z.string().min(1),
|
|
1029
|
+
version: z.number().int().positive().optional(),
|
|
1030
|
+
})
|
|
1031
|
+
.strict(),
|
|
1032
|
+
]);
|
|
1033
|
+
/**
|
|
1034
|
+
* Exactly one of `content`, `data` or `parts` (protocol 6). Optional `manifest` for per-turn
|
|
1035
|
+
* agent patches.
|
|
1036
|
+
*/
|
|
755
1037
|
export const MessageEventBodySchema = z.union([
|
|
756
1038
|
z
|
|
757
1039
|
.object({
|
|
@@ -765,6 +1047,12 @@ export const MessageEventBodySchema = z.union([
|
|
|
765
1047
|
data: jsonValue,
|
|
766
1048
|
})
|
|
767
1049
|
.strict(),
|
|
1050
|
+
z
|
|
1051
|
+
.object({
|
|
1052
|
+
...messageBase,
|
|
1053
|
+
parts: z.array(MessagePartSchema).min(1).max(MAX_MESSAGE_PARTS),
|
|
1054
|
+
})
|
|
1055
|
+
.strict(),
|
|
768
1056
|
]);
|
|
769
1057
|
export const ActionOutcomeSchema = z
|
|
770
1058
|
.object({
|
|
@@ -1127,6 +1415,8 @@ export const CommandMessagePayloadSchema = z
|
|
|
1127
1415
|
type: z.literal("message"),
|
|
1128
1416
|
content: z.string().optional(),
|
|
1129
1417
|
data: jsonValue.optional(),
|
|
1418
|
+
/** Text and file parts (protocol 6), as sent: a file part names an artifact, never bytes. */
|
|
1419
|
+
parts: z.array(MessagePartSchema).optional(),
|
|
1130
1420
|
/** The turn manifest the message carried, if any. */
|
|
1131
1421
|
manifest: z.unknown().optional(),
|
|
1132
1422
|
})
|
|
@@ -1181,6 +1471,13 @@ export const SandboxStatePayloadSchema = z
|
|
|
1181
1471
|
error: z.string().optional(),
|
|
1182
1472
|
})
|
|
1183
1473
|
.passthrough();
|
|
1474
|
+
/**
|
|
1475
|
+
* `sandbox.attached`: the session was opened on a sandbox resource (`sandbox: { id }`). The
|
|
1476
|
+
* sandbox's own stream records the same attachment.
|
|
1477
|
+
*/
|
|
1478
|
+
export const SandboxAttachedPayloadSchema = z
|
|
1479
|
+
.object({ sandboxId: z.string() })
|
|
1480
|
+
.passthrough();
|
|
1184
1481
|
/** `sandbox.exec`: one sandbox tool call finished. */
|
|
1185
1482
|
export const SandboxExecPayloadSchema = z
|
|
1186
1483
|
.object({
|
|
@@ -1253,6 +1550,77 @@ export const TranscriptUpdatedPayloadSchema = z
|
|
|
1253
1550
|
length: z.number().int().nonnegative(),
|
|
1254
1551
|
})
|
|
1255
1552
|
.passthrough();
|
|
1553
|
+
/**
|
|
1554
|
+
* Where an artifact version's bytes came from: a client's upload, our engine's `save_artifact`,
|
|
1555
|
+
* or the turn-end export of a sandbox's outputs (F8.2), whose listing and bytes the harness
|
|
1556
|
+
* holding the workspace supplied.
|
|
1557
|
+
*/
|
|
1558
|
+
export const ArtifactSourceSchema = z.enum(["upload", "engine", "export"]);
|
|
1559
|
+
/**
|
|
1560
|
+
* What an artifact holds: one file, or a folder (F8.2), whose versions are manifests of paths to
|
|
1561
|
+
* content-addressed files.
|
|
1562
|
+
*/
|
|
1563
|
+
export const ArtifactKindSchema = z.enum(["file", "folder"]);
|
|
1564
|
+
/**
|
|
1565
|
+
* `artifact.created` and `artifact.version.created` (protocol 6): a file or folder artifact of the
|
|
1566
|
+
* session, or a new version of one, committed. Ids, sizes and hashes, never bytes. A folder's
|
|
1567
|
+
* `size` is the sum of its files' and its `sha256` is its manifest's.
|
|
1568
|
+
*/
|
|
1569
|
+
export const ArtifactVersionPayloadSchema = z
|
|
1570
|
+
.object({
|
|
1571
|
+
artifactId: z.string(),
|
|
1572
|
+
kind: ArtifactKindSchema,
|
|
1573
|
+
name: z.string(),
|
|
1574
|
+
contentType: z.string(),
|
|
1575
|
+
version: z.number().int().positive(),
|
|
1576
|
+
size: z.number().int().nonnegative(),
|
|
1577
|
+
sha256: z.string(),
|
|
1578
|
+
source: ArtifactSourceSchema,
|
|
1579
|
+
/** The tool call that saved it (`save_artifact`), when our engine did. */
|
|
1580
|
+
callId: z.string().optional(),
|
|
1581
|
+
/** A folder's number of files. */
|
|
1582
|
+
fileCount: z.number().int().nonnegative().optional(),
|
|
1583
|
+
/**
|
|
1584
|
+
* True when the listing and the bytes are the harness's claim (a turn-end export): the
|
|
1585
|
+
* Runtime stored what the harness holding the workspace supplied, without observing it.
|
|
1586
|
+
*/
|
|
1587
|
+
claimed: z.boolean().optional(),
|
|
1588
|
+
})
|
|
1589
|
+
.passthrough();
|
|
1590
|
+
/** `artifact.deleted`: the artifact and every version of it are gone. */
|
|
1591
|
+
export const ArtifactDeletedPayloadSchema = z
|
|
1592
|
+
.object({ artifactId: z.string(), name: z.string() })
|
|
1593
|
+
.passthrough();
|
|
1594
|
+
/** Why a turn-end export stored nothing although the sandbox had outputs (F8.2). */
|
|
1595
|
+
export const ArtifactExportSkipReasonSchema = z.enum([
|
|
1596
|
+
"too_many_files",
|
|
1597
|
+
"file_too_large",
|
|
1598
|
+
"too_large",
|
|
1599
|
+
"tenant_total",
|
|
1600
|
+
]);
|
|
1601
|
+
/**
|
|
1602
|
+
* `artifact.export.skipped`: the turn's outputs were past a limit, so no folder version was
|
|
1603
|
+
* written. The turn itself completed.
|
|
1604
|
+
*/
|
|
1605
|
+
export const ArtifactExportSkippedPayloadSchema = z
|
|
1606
|
+
.object({
|
|
1607
|
+
/** The folder artifact the export writes: `outputs`. */
|
|
1608
|
+
name: z.string(),
|
|
1609
|
+
reason: ArtifactExportSkipReasonSchema,
|
|
1610
|
+
message: z.string(),
|
|
1611
|
+
/** The limit passed: files, or bytes. */
|
|
1612
|
+
limit: z.number().int().nonnegative().optional(),
|
|
1613
|
+
/** The file past the per-file limit (`file_too_large`). */
|
|
1614
|
+
path: z.string().optional(),
|
|
1615
|
+
})
|
|
1616
|
+
.passthrough();
|
|
1617
|
+
/**
|
|
1618
|
+
* `artifact.export.failed`: the turn-end export could not finish (the sandbox or the Object store
|
|
1619
|
+
* failed). The turn itself completed; the next turn exports again.
|
|
1620
|
+
*/
|
|
1621
|
+
export const ArtifactExportFailedPayloadSchema = z
|
|
1622
|
+
.object({ name: z.string(), message: z.string() })
|
|
1623
|
+
.passthrough();
|
|
1256
1624
|
/**
|
|
1257
1625
|
* The event catalog (Durable Streams §9.5): every session event type, its payload schema, its
|
|
1258
1626
|
* payload schema version and who writes it. A type not listed here cannot be written. A type
|
|
@@ -1289,11 +1657,29 @@ export const EVENT_CATALOG = {
|
|
|
1289
1657
|
"delegation.completed": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
|
|
1290
1658
|
"sandbox.state": { payload: SandboxStatePayloadSchema, source: "loop", version: 1 },
|
|
1291
1659
|
"sandbox.exec": { payload: SandboxExecPayloadSchema, source: "loop", version: 1 },
|
|
1660
|
+
"sandbox.attached": { payload: SandboxAttachedPayloadSchema, source: "api", version: 1 },
|
|
1292
1661
|
"node.started": { payload: NodeStartedPayloadSchema, source: "loop", version: 1 },
|
|
1293
1662
|
"node.agent": { payload: NodeAgentPayloadSchema, source: "loop", version: 1 },
|
|
1294
1663
|
"loop.iteration": { payload: LoopIterationPayloadSchema, source: "loop", version: 1 },
|
|
1295
1664
|
"loop.verified": { payload: LoopVerifiedPayloadSchema, source: "api", version: 1 },
|
|
1296
1665
|
"loop.decided": { payload: LoopDecidedPayloadSchema, source: "api", version: 1 },
|
|
1666
|
+
"artifact.created": { payload: ArtifactVersionPayloadSchema, source: "api", version: 1 },
|
|
1667
|
+
"artifact.version.created": {
|
|
1668
|
+
payload: ArtifactVersionPayloadSchema,
|
|
1669
|
+
source: "api",
|
|
1670
|
+
version: 1,
|
|
1671
|
+
},
|
|
1672
|
+
"artifact.deleted": { payload: ArtifactDeletedPayloadSchema, source: "api", version: 1 },
|
|
1673
|
+
"artifact.export.skipped": {
|
|
1674
|
+
payload: ArtifactExportSkippedPayloadSchema,
|
|
1675
|
+
source: "api",
|
|
1676
|
+
version: 1,
|
|
1677
|
+
},
|
|
1678
|
+
"artifact.export.failed": {
|
|
1679
|
+
payload: ArtifactExportFailedPayloadSchema,
|
|
1680
|
+
source: "api",
|
|
1681
|
+
version: 1,
|
|
1682
|
+
},
|
|
1297
1683
|
"transcript.updated": {
|
|
1298
1684
|
payload: TranscriptUpdatedPayloadSchema,
|
|
1299
1685
|
source: "loop",
|
|
@@ -1433,6 +1819,18 @@ export const StreamRelayStatusSchema = z
|
|
|
1433
1819
|
lagBytes: z.number().nonnegative().optional(),
|
|
1434
1820
|
})
|
|
1435
1821
|
.strict();
|
|
1822
|
+
/**
|
|
1823
|
+
* The Tenant's harnesses (F6.2): `in-process` runs one in core's process; `remote` waits for
|
|
1824
|
+
* harnesses on the Harness API listener. `workspace` says one that serves the Tenant's
|
|
1825
|
+
* workspaces is connected.
|
|
1826
|
+
*/
|
|
1827
|
+
export const HarnessStatusSchema = z
|
|
1828
|
+
.object({
|
|
1829
|
+
mode: z.enum(["in-process", "remote"]),
|
|
1830
|
+
connected: z.number().int().nonnegative(),
|
|
1831
|
+
workspace: z.boolean(),
|
|
1832
|
+
})
|
|
1833
|
+
.strict();
|
|
1436
1834
|
export const HostAggregateSchema = z
|
|
1437
1835
|
.object({
|
|
1438
1836
|
runningSessions: z.number().int().nonnegative(),
|
|
@@ -1442,6 +1840,8 @@ export const HostAggregateSchema = z
|
|
|
1442
1840
|
uncertainEffects: z.number().int().nonnegative(),
|
|
1443
1841
|
/** This process's stream relay, when it runs one (a Host with S2). */
|
|
1444
1842
|
relay: StreamRelayStatusSchema.optional(),
|
|
1843
|
+
/** The open Tenant's harnesses. */
|
|
1844
|
+
harness: HarnessStatusSchema.optional(),
|
|
1445
1845
|
})
|
|
1446
1846
|
.strict();
|
|
1447
1847
|
export const AdminHostStatusSchema = z
|
|
@@ -1474,6 +1874,31 @@ export const AdminStatusSchema = z
|
|
|
1474
1874
|
.optional(),
|
|
1475
1875
|
})
|
|
1476
1876
|
.strict();
|
|
1877
|
+
/**
|
|
1878
|
+
* An operator key (Host feature `operator-keys`): a revocable application key of the Tenant,
|
|
1879
|
+
* named by its id (`APPLICATION_KEY_ID_PATTERN`). The Runtime keeps only its hash.
|
|
1880
|
+
*/
|
|
1881
|
+
export const OperatorKeySchema = z
|
|
1882
|
+
.object({
|
|
1883
|
+
id: z.string().min(1),
|
|
1884
|
+
role: z.string().min(1),
|
|
1885
|
+
/** When the current key was issued: created, or last rotated. */
|
|
1886
|
+
createdAt: z.string().min(1),
|
|
1887
|
+
})
|
|
1888
|
+
.strict();
|
|
1889
|
+
/** `GET /v1/admin/keys`: every key of the Tenant (Studio's and derived ones too), by id. */
|
|
1890
|
+
export const ListOperatorKeysResponseSchema = z
|
|
1891
|
+
.object({ keys: z.array(OperatorKeySchema) })
|
|
1892
|
+
.strict();
|
|
1893
|
+
/** `PUT /v1/admin/keys/{id}`: the new key, shown this once; `rotated` when it replaced one. */
|
|
1894
|
+
export const PutOperatorKeyResponseSchema = OperatorKeySchema.extend({
|
|
1895
|
+
key: z.string().regex(/^[0-9a-f]{64}$/),
|
|
1896
|
+
rotated: z.boolean(),
|
|
1897
|
+
}).strict();
|
|
1898
|
+
/** `DELETE /v1/admin/keys/{id}`: the key no longer authenticates. */
|
|
1899
|
+
export const DeleteOperatorKeyResponseSchema = z
|
|
1900
|
+
.object({ id: z.string().min(1), deleted: z.literal(true) })
|
|
1901
|
+
.strict();
|
|
1477
1902
|
/**
|
|
1478
1903
|
* `.nylorun/link.json`: the installation a Project uses. Format 3 names the local `tenant`
|
|
1479
1904
|
* that `nylorun start` created or attached; `tenantId` is information only, since nothing in a
|
|
@@ -1548,6 +1973,8 @@ export const TenantStatusSchema = z
|
|
|
1548
1973
|
retained: z.number().int().nonnegative(),
|
|
1549
1974
|
})
|
|
1550
1975
|
.strict(),
|
|
1976
|
+
/** The Tenant's harnesses (F6.2). */
|
|
1977
|
+
harness: HarnessStatusSchema.optional(),
|
|
1551
1978
|
/**
|
|
1552
1979
|
* Durable Session Execution invocations of this Tenant that need an operator: paused
|
|
1553
1980
|
* after exhausting retries, or backing off after failures. Absent when the execution
|
|
@@ -1633,20 +2060,30 @@ export const ResetTenantRequestSchema = z
|
|
|
1633
2060
|
.strict();
|
|
1634
2061
|
/**
|
|
1635
2062
|
* Acting for a subject (Host feature `subject-headers`): what an application principal may
|
|
1636
|
-
* narrow a request to. `sessions:own`
|
|
1637
|
-
*
|
|
2063
|
+
* narrow a request to. `sessions:own` reaches only the subject's own sessions; the others reach
|
|
2064
|
+
* Tenant-wide resources. `sandboxes:write` creates and deletes sandboxes (Host feature
|
|
2065
|
+
* `sandboxes`); a token caller's reach only the ids its sandbox grants name. Vaults are the
|
|
2066
|
+
* installation's, managed by application keys acting for no one (protocol 7).
|
|
1638
2067
|
*/
|
|
1639
2068
|
export const SUBJECT_SCOPES = [
|
|
1640
2069
|
"agents:read",
|
|
1641
2070
|
"agents:write",
|
|
1642
2071
|
"sessions:own",
|
|
1643
|
-
"vaults:own",
|
|
1644
2072
|
"tenant:settings",
|
|
2073
|
+
"sandboxes:write",
|
|
1645
2074
|
];
|
|
2075
|
+
/**
|
|
2076
|
+
* Scopes protocol 7 retired: `Nylorun-Scopes` may still name them (protocol 6 clients do), and
|
|
2077
|
+
* they grant nothing.
|
|
2078
|
+
*/
|
|
2079
|
+
const RETIRED_SUBJECT_SCOPES = ["vaults:own"];
|
|
1646
2080
|
/** 1–200 visible ASCII characters; spaces only inside. */
|
|
1647
2081
|
const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
|
|
1648
|
-
/**
|
|
1649
|
-
|
|
2082
|
+
/**
|
|
2083
|
+
* Owner ids the Runtime uses itself: the host model's vault is owned by `host`, installation
|
|
2084
|
+
* vaults by `installation`.
|
|
2085
|
+
*/
|
|
2086
|
+
const RESERVED_SUBJECTS = new Set(["host", INSTALLATION_OWNER]);
|
|
1650
2087
|
/** A valid subject: 1–200 visible ASCII characters, not reserved by the Runtime. */
|
|
1651
2088
|
export function isSubject(value) {
|
|
1652
2089
|
return (typeof value === "string" &&
|
|
@@ -1665,12 +2102,13 @@ export function parseSubjectHeaders(subject, scopes) {
|
|
|
1665
2102
|
};
|
|
1666
2103
|
if (RESERVED_SUBJECTS.has(subject))
|
|
1667
2104
|
return { ok: false, message: `Subject ${subject} is reserved` };
|
|
1668
|
-
const
|
|
1669
|
-
if (
|
|
2105
|
+
const named = (scopes ?? "").split(" ").filter(Boolean);
|
|
2106
|
+
if (named.length === 0)
|
|
1670
2107
|
return {
|
|
1671
2108
|
ok: false,
|
|
1672
2109
|
message: "Nylorun-Scopes is required with Nylorun-Subject",
|
|
1673
2110
|
};
|
|
2111
|
+
const names = named.filter((name) => !RETIRED_SUBJECT_SCOPES.includes(name));
|
|
1674
2112
|
const unknown = names.filter((name) => !SUBJECT_SCOPES.includes(name));
|
|
1675
2113
|
if (unknown.length > 0)
|
|
1676
2114
|
return { ok: false, message: `Unknown scope ${unknown.join(", ")}` };
|
|
@@ -1680,113 +2118,35 @@ export function parseSubjectHeaders(subject, scopes) {
|
|
|
1680
2118
|
scopes: new Set(names),
|
|
1681
2119
|
};
|
|
1682
2120
|
}
|
|
1683
|
-
// ---
|
|
1684
|
-
/**
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
export const
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
2121
|
+
// --- token callers (Host feature `trusted-issuers`) ------------------------------------------
|
|
2122
|
+
/**
|
|
2123
|
+
* Scopes a token caller (a trusted issuer's token) may carry: never `agents:write` or
|
|
2124
|
+
* `tenant:settings`.
|
|
2125
|
+
*/
|
|
2126
|
+
export const TOKEN_SCOPES = [
|
|
2127
|
+
"agents:read",
|
|
2128
|
+
"sessions:own",
|
|
2129
|
+
"sandboxes:write",
|
|
2130
|
+
];
|
|
2131
|
+
/** The most sandbox grants one token caller carries. */
|
|
2132
|
+
export const TOKEN_SANDBOX_GRANTS_MAX = 16;
|
|
2133
|
+
/**
|
|
2134
|
+
* The longest a token the Runtime signs itself lives, in seconds (delivery tokens, capability
|
|
2135
|
+
* links): rotating signing keys revokes the previous key once the longest token it may have
|
|
2136
|
+
* signed has expired.
|
|
2137
|
+
*/
|
|
2138
|
+
export const TOKEN_TTL_MAX_SECONDS = 900;
|
|
2139
|
+
/**
|
|
2140
|
+
* The `iss` of every token a Tenant's Runtime signs itself: delivery tokens, capability links,
|
|
2141
|
+
* run, host and egress tokens.
|
|
2142
|
+
*/
|
|
2143
|
+
export function tenantTokenIssuer(tenantId) {
|
|
1693
2144
|
return `urn:nylorun:tenant:${tenantId}`;
|
|
1694
2145
|
}
|
|
1695
|
-
/** Token lifetimes, in seconds. */
|
|
1696
|
-
export const TOKEN_TTL_MIN_SECONDS = 60;
|
|
1697
|
-
export const TOKEN_TTL_MAX_SECONDS = 900;
|
|
1698
|
-
export const TOKEN_TTL_DEFAULT_SECONDS = 600;
|
|
1699
|
-
/** A role's name in the access policy; `anon` is reserved for publishable keys. */
|
|
1700
|
-
export const ROLE_NAME_PATTERN = /^[a-z][a-z0-9_-]{0,31}$/;
|
|
1701
2146
|
const AgentAllowlistSchema = z.union([
|
|
1702
2147
|
z.literal("*"),
|
|
1703
2148
|
z.array(z.string().min(1)),
|
|
1704
2149
|
]);
|
|
1705
|
-
export const RoleLimitsSchema = z
|
|
1706
|
-
.object({
|
|
1707
|
-
turnsPerHour: z.number().int().min(1).max(100_000).optional(),
|
|
1708
|
-
concurrentTurns: z.number().int().min(1).max(1000).optional(),
|
|
1709
|
-
})
|
|
1710
|
-
.strict();
|
|
1711
|
-
export const AccessRoleSchema = z
|
|
1712
|
-
.object({
|
|
1713
|
-
scopes: z.array(TokenScopeSchema).min(1),
|
|
1714
|
-
agents: AgentAllowlistSchema,
|
|
1715
|
-
limits: RoleLimitsSchema.optional(),
|
|
1716
|
-
})
|
|
1717
|
-
.strict();
|
|
1718
|
-
/**
|
|
1719
|
-
* The Tenant's access policy: what each role may do with a subject token, what a publishable
|
|
1720
|
-
* key grants alone (`anon`), and how long tokens live. Without roles nothing can be minted.
|
|
1721
|
-
*/
|
|
1722
|
-
export const AccessPolicySchema = z
|
|
1723
|
-
.object({
|
|
1724
|
-
version: z.literal(1),
|
|
1725
|
-
roles: z
|
|
1726
|
-
.record(z.string(), AccessRoleSchema)
|
|
1727
|
-
.superRefine((roles, issue) => {
|
|
1728
|
-
for (const name of Object.keys(roles))
|
|
1729
|
-
if (!ROLE_NAME_PATTERN.test(name) || name === "anon")
|
|
1730
|
-
issue.addIssue({
|
|
1731
|
-
code: "custom",
|
|
1732
|
-
message: `Role name ${name} is invalid or reserved`,
|
|
1733
|
-
path: [name],
|
|
1734
|
-
});
|
|
1735
|
-
}),
|
|
1736
|
-
anon: z
|
|
1737
|
-
.object({
|
|
1738
|
-
scopes: z.array(z.literal("agents:read")),
|
|
1739
|
-
agents: AgentAllowlistSchema,
|
|
1740
|
-
})
|
|
1741
|
-
.strict(),
|
|
1742
|
-
tokens: z
|
|
1743
|
-
.object({
|
|
1744
|
-
maxTtlSeconds: z
|
|
1745
|
-
.number()
|
|
1746
|
-
.int()
|
|
1747
|
-
.min(TOKEN_TTL_MIN_SECONDS)
|
|
1748
|
-
.max(TOKEN_TTL_MAX_SECONDS),
|
|
1749
|
-
})
|
|
1750
|
-
.strict(),
|
|
1751
|
-
})
|
|
1752
|
-
.strict();
|
|
1753
|
-
/** The policy of a Tenant that never set one: no roles, nothing for `anon`. */
|
|
1754
|
-
export const DEFAULT_ACCESS_POLICY = Object.freeze({
|
|
1755
|
-
version: 1,
|
|
1756
|
-
roles: {},
|
|
1757
|
-
anon: { scopes: [], agents: [] },
|
|
1758
|
-
tokens: { maxTtlSeconds: TOKEN_TTL_DEFAULT_SECONDS },
|
|
1759
|
-
});
|
|
1760
|
-
export const PutAccessPolicyRequestSchema = z
|
|
1761
|
-
.object({ requestId: RequestIdSchema, policy: AccessPolicySchema })
|
|
1762
|
-
.strict();
|
|
1763
|
-
export const CreateTokenRequestSchema = z
|
|
1764
|
-
.object({
|
|
1765
|
-
requestId: RequestIdSchema,
|
|
1766
|
-
subject: z.string().refine(isSubject, "subject must be 1-200 visible ASCII characters and not reserved"),
|
|
1767
|
-
role: z.string().regex(ROLE_NAME_PATTERN),
|
|
1768
|
-
scopes: z.array(TokenScopeSchema).min(1).optional(),
|
|
1769
|
-
agents: z.array(z.string().min(1)).optional(),
|
|
1770
|
-
ttlSeconds: z
|
|
1771
|
-
.number()
|
|
1772
|
-
.int()
|
|
1773
|
-
.min(TOKEN_TTL_MIN_SECONDS)
|
|
1774
|
-
.max(TOKEN_TTL_MAX_SECONDS)
|
|
1775
|
-
.optional(),
|
|
1776
|
-
})
|
|
1777
|
-
.strict();
|
|
1778
|
-
export const CreateTokenResponseSchema = z
|
|
1779
|
-
.object({
|
|
1780
|
-
token: z.string().min(1),
|
|
1781
|
-
/** ISO time the token stops being accepted. */
|
|
1782
|
-
expiresAt: z.string().min(1),
|
|
1783
|
-
subject: z.string(),
|
|
1784
|
-
role: z.string(),
|
|
1785
|
-
scopes: z.array(TokenScopeSchema),
|
|
1786
|
-
agents: AgentAllowlistSchema,
|
|
1787
|
-
keyId: z.string(),
|
|
1788
|
-
})
|
|
1789
|
-
.strict();
|
|
1790
2150
|
export const SIGNING_KEY_STATES = ["standby", "current", "previous", "revoked"];
|
|
1791
2151
|
/** A public JSON Web Key as the JWKS publishes it. */
|
|
1792
2152
|
export const PublicJwkSchema = z
|
|
@@ -1822,18 +2182,47 @@ export const RotateSigningKeysRequestSchema = z
|
|
|
1822
2182
|
export const RevokeSigningKeyRequestSchema = z
|
|
1823
2183
|
.object({ requestId: RequestIdSchema })
|
|
1824
2184
|
.strict();
|
|
1825
|
-
|
|
2185
|
+
// --- trusted issuers (Host feature `trusted-issuers`) --------------------------------------
|
|
2186
|
+
/**
|
|
2187
|
+
* Scopes a trusted issuer's tokens may carry (`allowedScopes` in the identity file): the
|
|
2188
|
+
* token scopes, and `studio`, an operator scope no Runtime route requires (Studio
|
|
2189
|
+
* admits a person who holds it, Tenant-wide).
|
|
2190
|
+
*/
|
|
2191
|
+
export const ISSUER_SCOPES = [...TOKEN_SCOPES, "studio"];
|
|
2192
|
+
/** Every scope a caller can hold: the subject scopes, and an issuer token's `studio`. */
|
|
2193
|
+
export const CALLER_SCOPES = [...SUBJECT_SCOPES, "studio"];
|
|
2194
|
+
/**
|
|
2195
|
+
* `GET /v1/me`: who the Runtime takes the caller to be, for any credential.
|
|
2196
|
+
*
|
|
2197
|
+
* - `via` is how the caller authenticated: `application:<principalId>` (an application key,
|
|
2198
|
+
* acting as itself), `subject` (an application key acting for `Nylorun-Subject`) or
|
|
2199
|
+
* `issuer:<name>` (a token from the identity file's issuer `name`).
|
|
2200
|
+
* - `subject` is the person the request acts for; absent for an application key alone.
|
|
2201
|
+
* - `scopes`: what the caller holds. An application key alone holds every subject scope.
|
|
2202
|
+
* - `agents`: the agents it may reach, `*` for all.
|
|
2203
|
+
* - `sandboxes`: the sandbox grants of a token caller (empty reaches none); absent for an
|
|
2204
|
+
* application key, alone or acting for a subject, which no grant limits.
|
|
2205
|
+
*/
|
|
2206
|
+
export const MeResponseSchema = z
|
|
1826
2207
|
.object({
|
|
1827
|
-
|
|
1828
|
-
|
|
2208
|
+
subject: z
|
|
2209
|
+
.string()
|
|
2210
|
+
.optional()
|
|
2211
|
+
.meta({ description: "The person the request acts for; absent for an application key alone" }),
|
|
2212
|
+
scopes: z.array(z.enum(CALLER_SCOPES)),
|
|
2213
|
+
agents: AgentAllowlistSchema,
|
|
2214
|
+
sandboxes: z
|
|
2215
|
+
.array(z.string())
|
|
2216
|
+
.optional()
|
|
2217
|
+
.meta({
|
|
2218
|
+
description: "A token caller's sandbox grants (empty reaches none); absent when no grant limits the caller",
|
|
2219
|
+
}),
|
|
2220
|
+
via: z.string().meta({
|
|
2221
|
+
description: "How the caller authenticated: `application:<principalId>`, `subject` or `issuer:<name>`",
|
|
2222
|
+
}),
|
|
1829
2223
|
})
|
|
1830
2224
|
.strict();
|
|
1831
|
-
|
|
1832
|
-
.object({ subject: z.string(), epoch: z.number().int().nonnegative() })
|
|
1833
|
-
.strict();
|
|
1834
|
-
// --- publishable keys (Host feature `browser-access`) --------------------------------------
|
|
1835
|
-
/** Loopback origins with any port, for development: `http://localhost:*`, `http://127.0.0.1:*`. */
|
|
1836
|
-
export const LOOPBACK_ORIGIN_WILDCARDS = ["http://localhost:*", "http://127.0.0.1:*"];
|
|
2225
|
+
// --- origins ---------------------------------------------------------------------------------
|
|
1837
2226
|
/** True for a serialized web origin: `scheme://host[:port]`, lowercase, no path. */
|
|
1838
2227
|
export function isSerializedOrigin(value) {
|
|
1839
2228
|
let url;
|
|
@@ -1848,50 +2237,6 @@ export function isSerializedOrigin(value) {
|
|
|
1848
2237
|
// Host names only: no wildcards or other characters URL parsing lets through.
|
|
1849
2238
|
/^(?:[a-z0-9-]+(?:\.[a-z0-9-]+)*|\[[0-9a-f:.]+\])$/.test(url.hostname));
|
|
1850
2239
|
}
|
|
1851
|
-
/** An origin allowlist entry: an exact origin or a loopback wildcard. */
|
|
1852
|
-
export const OriginEntrySchema = z
|
|
1853
|
-
.string()
|
|
1854
|
-
.refine((value) => LOOPBACK_ORIGIN_WILDCARDS.includes(value) ||
|
|
1855
|
-
isSerializedOrigin(value), "must be an origin such as https://app.example.com, or http://localhost:*");
|
|
1856
|
-
/** True when `origin` (a request's `Origin`) is allowed by `origins`. */
|
|
1857
|
-
export function originAllowed(origins, origin) {
|
|
1858
|
-
if (!isSerializedOrigin(origin))
|
|
1859
|
-
return false;
|
|
1860
|
-
for (const entry of origins) {
|
|
1861
|
-
if (entry === origin)
|
|
1862
|
-
return true;
|
|
1863
|
-
if (entry.endsWith(":*")) {
|
|
1864
|
-
const prefix = entry.slice(0, -1);
|
|
1865
|
-
if (origin.startsWith(prefix) && /^\d{1,5}$/.test(origin.slice(prefix.length)))
|
|
1866
|
-
return true;
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
return false;
|
|
1870
|
-
}
|
|
1871
|
-
export const PublishableKeySchema = z
|
|
1872
|
-
.object({
|
|
1873
|
-
id: z.string(),
|
|
1874
|
-
name: z.string(),
|
|
1875
|
-
key: z.string(),
|
|
1876
|
-
origins: z.array(z.string()),
|
|
1877
|
-
createdAt: z.string(),
|
|
1878
|
-
revokedAt: z.string().nullable(),
|
|
1879
|
-
})
|
|
1880
|
-
.strict();
|
|
1881
|
-
export const CreatePublishableKeyRequestSchema = z
|
|
1882
|
-
.object({
|
|
1883
|
-
requestId: RequestIdSchema,
|
|
1884
|
-
name: z.string().min(1).max(100),
|
|
1885
|
-
/** `[]` allows native apps only (no `Origin`). */
|
|
1886
|
-
origins: z.array(OriginEntrySchema).max(100),
|
|
1887
|
-
})
|
|
1888
|
-
.strict();
|
|
1889
|
-
export const UpdatePublishableKeyRequestSchema = z
|
|
1890
|
-
.object({
|
|
1891
|
-
requestId: RequestIdSchema,
|
|
1892
|
-
origins: z.array(OriginEntrySchema).max(100),
|
|
1893
|
-
})
|
|
1894
|
-
.strict();
|
|
1895
2240
|
// Successful answers of the Tenant and Admin APIs that had no schema of their own. With the
|
|
1896
2241
|
// request schemas above they describe every body the Runtime sends (its OpenAPI document).
|
|
1897
2242
|
/** `GET /v1/agents` with an application key: every definition, manifest included. */
|
|
@@ -1906,7 +2251,7 @@ export const AgentDefinitionViewSchema = z
|
|
|
1906
2251
|
export const ListAgentsResponseSchema = z
|
|
1907
2252
|
.object({ agents: z.array(AgentDefinitionViewSchema) })
|
|
1908
2253
|
.strict();
|
|
1909
|
-
/** `GET /v1/agents` with a
|
|
2254
|
+
/** `GET /v1/agents` with a token caller's credential: the allowed agents' names only. */
|
|
1910
2255
|
export const PublicAgentSchema = z
|
|
1911
2256
|
.object({
|
|
1912
2257
|
agentId: z.string(),
|
|
@@ -1959,11 +2304,16 @@ export const SessionViewSchema = z
|
|
|
1959
2304
|
activeTurnId: z.string().nullable(),
|
|
1960
2305
|
vaultIds: z.array(z.string()),
|
|
1961
2306
|
credentialSelections: z.array(CredentialSelectionSchema),
|
|
1962
|
-
/**
|
|
2307
|
+
/**
|
|
2308
|
+
* The session whose sandbox this one shares; `null` when it owns its own. Deprecated: share
|
|
2309
|
+
* a sandbox resource with `sandbox: { id }` (the client's `sandboxes.forSession()`).
|
|
2310
|
+
*/
|
|
1963
2311
|
sandboxOwnerId: z.string().nullable(),
|
|
2312
|
+
/** The sandbox resource the session is attached to (`sandbox: { id }`), if any. */
|
|
2313
|
+
sandboxId: z.string().optional(),
|
|
1964
2314
|
/** The sandbox pinned when the session was opened, or `null`. */
|
|
1965
2315
|
sandbox: z.record(z.string(), z.unknown()).nullable(),
|
|
1966
|
-
sandboxSource: z.enum(["default", "inline", "shared"]).optional(),
|
|
2316
|
+
sandboxSource: z.enum(["default", "inline", "shared", "sandbox"]).optional(),
|
|
1967
2317
|
mcpSnapshot: z.record(z.string(), z.unknown()).nullable(),
|
|
1968
2318
|
mcpDiagnostics: z.array(z.record(z.string(), z.unknown())),
|
|
1969
2319
|
/** What the session waits on: interactions, approvals, timers. */
|
|
@@ -2029,11 +2379,24 @@ export const EffectiveSandboxConfigSchema = z
|
|
|
2029
2379
|
resources: SandboxResourcesLimitSchema,
|
|
2030
2380
|
defaultResources: SandboxResourcesLimitSchema,
|
|
2031
2381
|
idle: z.string(),
|
|
2382
|
+
/** The most sandbox resources the Tenant may hold. */
|
|
2383
|
+
sandboxes: z.number().int().nonnegative().optional(),
|
|
2384
|
+
/** Pods: the longest `lifecycle.ttl`, when the Tenant sets one. */
|
|
2385
|
+
ttl: z.string().optional(),
|
|
2032
2386
|
})
|
|
2033
2387
|
.strict(),
|
|
2388
|
+
/** Pods (Host feature `sandbox-pods`): what happens at expiry, and the pod's stop grace. */
|
|
2389
|
+
lifecycle: z
|
|
2390
|
+
.object({ onExpiry: z.enum(["retain", "delete"]), stopGrace: z.string() })
|
|
2391
|
+
.strict()
|
|
2392
|
+
.optional(),
|
|
2393
|
+
/** Where each harness may run (D38). */
|
|
2394
|
+
placement: z
|
|
2395
|
+
.record(z.string(), z.object({ hosts: z.array(z.enum(SANDBOX_PLACEMENT_HOSTS)) }).strict())
|
|
2396
|
+
.optional(),
|
|
2034
2397
|
})
|
|
2035
2398
|
.strict();
|
|
2036
|
-
const SandboxBackendNameSchema = z.enum(["virtual"]);
|
|
2399
|
+
const SandboxBackendNameSchema = z.enum(["virtual", "local"]);
|
|
2037
2400
|
const SandboxIsolationSchema = z.enum(["process", "container"]);
|
|
2038
2401
|
/** `GET` and `PUT /v1/tenant/sandbox`: the backend chosen, and the configuration in force. */
|
|
2039
2402
|
export const TenantSandboxViewSchema = z
|
|
@@ -2053,6 +2416,20 @@ export const TenantSandboxViewSchema = z
|
|
|
2053
2416
|
.strict()),
|
|
2054
2417
|
defaultImage: z.string(),
|
|
2055
2418
|
config: EffectiveSandboxConfigSchema,
|
|
2419
|
+
/**
|
|
2420
|
+
* The Tenant's cluster for pod sandboxes (`nylorun sandbox enable`), as the sandboxes
|
|
2421
|
+
* service reports it; null without one, or when the service does not answer.
|
|
2422
|
+
*/
|
|
2423
|
+
cluster: z
|
|
2424
|
+
.object({
|
|
2425
|
+
namespace: z.string(),
|
|
2426
|
+
context: z.string(),
|
|
2427
|
+
ready: z.boolean(),
|
|
2428
|
+
controllerVersion: z.string().optional(),
|
|
2429
|
+
networkPolicy: z.object({ enforced: z.boolean(), probedAt: z.string().optional() }).optional(),
|
|
2430
|
+
})
|
|
2431
|
+
.nullable()
|
|
2432
|
+
.optional(),
|
|
2056
2433
|
})
|
|
2057
2434
|
.strict();
|
|
2058
2435
|
/** What a usage total or a budget covers: the whole Tenant, one agent, or one turn. */
|
|
@@ -2128,18 +2505,34 @@ export const ListVaultsResponseSchema = z.object({ vaults: z.array(VaultInfoSche
|
|
|
2128
2505
|
export const ListCredentialsResponseSchema = z
|
|
2129
2506
|
.object({ credentials: z.array(CredentialInfoSchema) })
|
|
2130
2507
|
.strict();
|
|
2508
|
+
/**
|
|
2509
|
+
* `POST /v1/vaults/{vaultId}/oauth/start` (F9 C2): sign the installation in to the remote MCP
|
|
2510
|
+
* server at `url`, declared as `server`, and store its OAuth credential in the installation vault.
|
|
2511
|
+
* `clientId` names a client registered with the authorization server; without one the Runtime
|
|
2512
|
+
* registers itself (RFC 7591) when the server allows it.
|
|
2513
|
+
*/
|
|
2514
|
+
export const StartOAuthRequestSchema = z
|
|
2515
|
+
.object({
|
|
2516
|
+
url: z.string().min(1).max(2048),
|
|
2517
|
+
server: z.string().min(1).max(128),
|
|
2518
|
+
clientId: z.string().min(1).max(512).optional(),
|
|
2519
|
+
})
|
|
2520
|
+
.strict();
|
|
2521
|
+
/** Where to send the browser, and until when the sign-in can finish. */
|
|
2522
|
+
export const StartOAuthResponseSchema = z
|
|
2523
|
+
.object({ authorizeUrl: z.string(), expiresAt: z.string() })
|
|
2524
|
+
.strict();
|
|
2131
2525
|
/** A deleted vault or credential. */
|
|
2132
2526
|
export const DeletedResponseSchema = z.object({ id: z.string() }).strict();
|
|
2133
|
-
export const AccessPolicyResponseSchema = z.object({ policy: AccessPolicySchema }).strict();
|
|
2134
|
-
export const ListPublishableKeysResponseSchema = z
|
|
2135
|
-
.object({ keys: z.array(PublishableKeySchema) })
|
|
2136
|
-
.strict();
|
|
2137
2527
|
export const HostShutdownResponseSchema = z
|
|
2138
2528
|
.object({ status: z.literal("shutting_down") })
|
|
2139
2529
|
.strict();
|
|
2140
|
-
/**
|
|
2530
|
+
/**
|
|
2531
|
+
* The last frame of a session stream the Runtime ends: `event: nylorun.closed`, when the
|
|
2532
|
+
* token caller's token expires.
|
|
2533
|
+
*/
|
|
2141
2534
|
export const StreamClosedFrameSchema = z
|
|
2142
|
-
.object({ reason: z.enum(["token_expired"
|
|
2535
|
+
.object({ reason: z.enum(["token_expired"]) })
|
|
2143
2536
|
.strict();
|
|
2144
2537
|
/**
|
|
2145
2538
|
* The `code` of an AG-UI `RUN_ERROR` the Runtime sends: a rejection's code, or `session_busy`
|
|
@@ -2153,10 +2546,7 @@ export const AgUiRunErrorCodeSchema = z.enum([
|
|
|
2153
2546
|
// --- Action endpoints: the Runtime delivers Actions over HTTP ------------------------------
|
|
2154
2547
|
/** The JWT `typ` of a delivery token (RFC 8725 explicit typing). */
|
|
2155
2548
|
export const DELIVERY_TOKEN_TYPE = "nylorun-delivery+jwt";
|
|
2156
|
-
/**
|
|
2157
|
-
* A delivery token lives no longer than a subject token: rotating signing keys revokes the
|
|
2158
|
-
* previous key once the longest token it may have signed has expired.
|
|
2159
|
-
*/
|
|
2549
|
+
/** A delivery token lives no longer than any token the Runtime signs (`TOKEN_TTL_MAX_SECONDS`). */
|
|
2160
2550
|
export const DELIVERY_TOKEN_MAX_TTL_SECONDS = TOKEN_TTL_MAX_SECONDS;
|
|
2161
2551
|
/** Inline delivery timeouts, in milliseconds. The maximum keeps a token within its lifetime. */
|
|
2162
2552
|
export const ENDPOINT_TIMEOUT_DEFAULT_MS = 60_000;
|
|
@@ -2357,7 +2747,8 @@ export const StudioEmbedMessageSchema = z.discriminatedUnion("kind", [
|
|
|
2357
2747
|
embed("token.expiring", { expiresAt: z.string().nullable() }),
|
|
2358
2748
|
embed("route.changed", { route: z.string() }),
|
|
2359
2749
|
embed("open.external", { url: EXTERNAL_URL }),
|
|
2360
|
-
|
|
2750
|
+
/** Asks the embedding app to open this session in its own UI. */
|
|
2751
|
+
embed("open.session", { sessionId: z.string().min(1) }),
|
|
2361
2752
|
embed("error", { code: z.string().min(1), message: z.string() }),
|
|
2362
2753
|
]);
|
|
2363
2754
|
/** Schemes that never name an embedder. */
|
|
@@ -2394,3 +2785,173 @@ export function parseFrameAncestors(value) {
|
|
|
2394
2785
|
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.`);
|
|
2395
2786
|
return [...new Set(entries)];
|
|
2396
2787
|
}
|
|
2788
|
+
// --- File artifacts (protocol 6, blueprint D35, F8.1) ----------------------------------------
|
|
2789
|
+
/** The JWT `typ` of a capability link's token (RFC 8725 explicit typing). */
|
|
2790
|
+
export const ARTIFACT_LINK_TOKEN_TYPE = "nylorun-artifact+jwt";
|
|
2791
|
+
/** A capability link lives no longer than any token the Runtime signs (`TOKEN_TTL_MAX_SECONDS`). */
|
|
2792
|
+
export const ARTIFACT_LINK_MAX_TTL_SECONDS = TOKEN_TTL_MAX_SECONDS;
|
|
2793
|
+
export const ARTIFACT_LINK_DEFAULT_TTL_SECONDS = 300;
|
|
2794
|
+
/** A Tenant's limits when it sets none: 100 MiB per file, 10 GiB in all. */
|
|
2795
|
+
export const ARTIFACT_FILE_BYTES_DEFAULT = 100 * 1024 * 1024;
|
|
2796
|
+
export const ARTIFACT_TOTAL_BYTES_DEFAULT = 10 * 1024 * 1024 * 1024;
|
|
2797
|
+
/** The longest artifact name, in characters. */
|
|
2798
|
+
export const ARTIFACT_NAME_MAX = 255;
|
|
2799
|
+
/** The longest path of a file in a folder artifact, in characters. */
|
|
2800
|
+
export const ARTIFACT_PATH_MAX = 1024;
|
|
2801
|
+
/** Labels: up to 32, keys 1–63 characters, values up to 256. */
|
|
2802
|
+
export const ArtifactLabelsSchema = z
|
|
2803
|
+
.record(z.string().min(1).max(63), z.string().max(256))
|
|
2804
|
+
.refine((labels) => Object.keys(labels).length <= 32, { message: "At most 32 labels" });
|
|
2805
|
+
/**
|
|
2806
|
+
* One version of an artifact: immutable once it exists. A folder version's `size` is the sum of
|
|
2807
|
+
* its files' sizes and its `sha256` is its manifest's.
|
|
2808
|
+
*/
|
|
2809
|
+
export const ArtifactVersionViewSchema = z
|
|
2810
|
+
.object({
|
|
2811
|
+
version: z.number().int().positive(),
|
|
2812
|
+
size: z.number().int().nonnegative(),
|
|
2813
|
+
sha256: z.string().meta({ description: "SHA-256 of the bytes (a folder: of its manifest), lowercase hex" }),
|
|
2814
|
+
contentType: z.string(),
|
|
2815
|
+
source: ArtifactSourceSchema,
|
|
2816
|
+
createdAt: z.string(),
|
|
2817
|
+
})
|
|
2818
|
+
.strict();
|
|
2819
|
+
/**
|
|
2820
|
+
* An artifact: an id, a name and numbered versions, its bytes in the Object store. A file's
|
|
2821
|
+
* version is its bytes; a folder's (F8.2) is a manifest of paths to content-addressed files.
|
|
2822
|
+
*/
|
|
2823
|
+
export const ArtifactViewSchema = z
|
|
2824
|
+
.object({
|
|
2825
|
+
artifactId: z.string(),
|
|
2826
|
+
kind: ArtifactKindSchema,
|
|
2827
|
+
name: z.string(),
|
|
2828
|
+
contentType: z.string().meta({ description: "The latest version's media type" }),
|
|
2829
|
+
/** The session it belongs to; absent for a Tenant-wide artifact an application made. */
|
|
2830
|
+
sessionId: z.string().optional(),
|
|
2831
|
+
latestVersion: z.number().int().positive(),
|
|
2832
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
2833
|
+
createdAt: z.string(),
|
|
2834
|
+
updatedAt: z.string(),
|
|
2835
|
+
/** Every version, oldest first (`GET /v1/artifacts/{id}` only). */
|
|
2836
|
+
versions: z.array(ArtifactVersionViewSchema).optional(),
|
|
2837
|
+
})
|
|
2838
|
+
.strict();
|
|
2839
|
+
export const ListArtifactsResponseSchema = z
|
|
2840
|
+
.object({ artifacts: z.array(ArtifactViewSchema) })
|
|
2841
|
+
.strict();
|
|
2842
|
+
/** What an upload answers: the artifact, and the version the upload created. */
|
|
2843
|
+
export const UploadArtifactResponseSchema = z
|
|
2844
|
+
.object({ artifact: ArtifactViewSchema, version: ArtifactVersionViewSchema })
|
|
2845
|
+
.strict();
|
|
2846
|
+
export const DeleteArtifactResponseSchema = z
|
|
2847
|
+
.object({ artifactId: z.string(), deleted: z.boolean() })
|
|
2848
|
+
.strict();
|
|
2849
|
+
/** `POST /v1/artifacts/{id}/links`: a capability link to one version. */
|
|
2850
|
+
export const CreateArtifactLinkRequestSchema = z
|
|
2851
|
+
.object({
|
|
2852
|
+
requestId: RequestIdSchema.optional(),
|
|
2853
|
+
/** The version to open. Default: the latest. */
|
|
2854
|
+
version: z.number().int().positive().optional(),
|
|
2855
|
+
/** Seconds until the link stops working. Default 300, at most 900. */
|
|
2856
|
+
expiresIn: z.number().int().min(1).max(ARTIFACT_LINK_MAX_TTL_SECONDS).optional(),
|
|
2857
|
+
/**
|
|
2858
|
+
* A folder's file, by its path in the folder: the link opens that one file. Without it, a
|
|
2859
|
+
* folder's link opens its zip.
|
|
2860
|
+
*/
|
|
2861
|
+
file: z.string().min(1).max(ARTIFACT_PATH_MAX).optional(),
|
|
2862
|
+
})
|
|
2863
|
+
.strict();
|
|
2864
|
+
/** A capability link: `GET` its path on the Runtime with no credential, until it expires. */
|
|
2865
|
+
export const ArtifactLinkSchema = z
|
|
2866
|
+
.object({
|
|
2867
|
+
/** `/v1/artifact-links/<token>`, on the Runtime that minted it. */
|
|
2868
|
+
path: z.string(),
|
|
2869
|
+
artifactId: z.string(),
|
|
2870
|
+
version: z.number().int().positive(),
|
|
2871
|
+
/** The folder's file the link opens; absent for a file artifact, or a folder's zip. */
|
|
2872
|
+
file: z.string().optional(),
|
|
2873
|
+
expiresAt: z.string(),
|
|
2874
|
+
})
|
|
2875
|
+
.strict();
|
|
2876
|
+
// --- Folder artifacts (protocol 6, F8.2) -------------------------------------------------------
|
|
2877
|
+
/** The media type of a folder artifact and of its manifests. */
|
|
2878
|
+
export const FOLDER_CONTENT_TYPE = "application/vnd.nylorun.folder+json";
|
|
2879
|
+
/** The manifest format a folder version is stored as. */
|
|
2880
|
+
export const FOLDER_MANIFEST_FORMAT = "nylorun.folder.v1";
|
|
2881
|
+
/** The folder artifact a session's turn-end export writes, one per session. */
|
|
2882
|
+
export const OUTPUTS_ARTIFACT_NAME = "outputs";
|
|
2883
|
+
/** The most files one turn-end export stores; past it the export is skipped. */
|
|
2884
|
+
export const EXPORT_MAX_FILES = 10_000;
|
|
2885
|
+
/** The most bytes one turn-end export stores (before dedupe); past it the export is skipped. */
|
|
2886
|
+
export const EXPORT_MAX_BYTES = 1024 * 1024 * 1024;
|
|
2887
|
+
/** One file of a folder: its path in the folder (`/`-separated, relative), size, hash and type. */
|
|
2888
|
+
export const FolderEntrySchema = z
|
|
2889
|
+
.object({
|
|
2890
|
+
path: z.string().min(1).max(ARTIFACT_PATH_MAX),
|
|
2891
|
+
size: z.number().int().nonnegative(),
|
|
2892
|
+
sha256: z.string().meta({ description: "SHA-256 of the file's bytes, lowercase hex" }),
|
|
2893
|
+
contentType: z.string(),
|
|
2894
|
+
})
|
|
2895
|
+
.strict();
|
|
2896
|
+
/**
|
|
2897
|
+
* A folder version as stored: the files, sorted by path, each naming its content-addressed
|
|
2898
|
+
* bytes by SHA-256. The one manifest format for folders, reused by P5's snapshots.
|
|
2899
|
+
*/
|
|
2900
|
+
export const FolderManifestSchema = z
|
|
2901
|
+
.object({
|
|
2902
|
+
format: z.literal(FOLDER_MANIFEST_FORMAT),
|
|
2903
|
+
entries: z.array(FolderEntrySchema),
|
|
2904
|
+
})
|
|
2905
|
+
.strict();
|
|
2906
|
+
/** `GET /v1/artifacts/{id}/versions/{n|latest}/tree`: a folder version's files. */
|
|
2907
|
+
export const ArtifactTreeSchema = z
|
|
2908
|
+
.object({
|
|
2909
|
+
artifactId: z.string(),
|
|
2910
|
+
version: z.number().int().positive(),
|
|
2911
|
+
/** Every file, sorted by path. */
|
|
2912
|
+
entries: z.array(FolderEntrySchema),
|
|
2913
|
+
})
|
|
2914
|
+
.strict();
|
|
2915
|
+
/** `GET /v1/artifacts/{id}/versions/{n|latest}/diff?from=m`: what changed between two versions. */
|
|
2916
|
+
export const ArtifactDiffSchema = z
|
|
2917
|
+
.object({
|
|
2918
|
+
artifactId: z.string(),
|
|
2919
|
+
/** The version compared against; absent when there is none (version 1, no `from`). */
|
|
2920
|
+
from: z.number().int().positive().optional(),
|
|
2921
|
+
to: z.number().int().positive(),
|
|
2922
|
+
/** Files only in `to`, sorted by path. */
|
|
2923
|
+
added: z.array(FolderEntrySchema),
|
|
2924
|
+
/** Files only in `from`. */
|
|
2925
|
+
removed: z.array(FolderEntrySchema),
|
|
2926
|
+
/** Files in both whose bytes or media type differ. */
|
|
2927
|
+
changed: z.array(z.object({ path: z.string(), from: FolderEntrySchema, to: FolderEntrySchema }).strict()),
|
|
2928
|
+
})
|
|
2929
|
+
.strict();
|
|
2930
|
+
/** A Tenant's artifact limits, stored as Tenant setting `artifacts.config`. */
|
|
2931
|
+
export const TenantArtifactsConfigSchema = z
|
|
2932
|
+
.object({
|
|
2933
|
+
limits: z
|
|
2934
|
+
.object({
|
|
2935
|
+
/** The largest file one upload may store, in bytes. Default 100 MiB. */
|
|
2936
|
+
fileBytes: z.number().int().positive().optional(),
|
|
2937
|
+
/** The most bytes every artifact version together may hold. Default 10 GiB. */
|
|
2938
|
+
totalBytes: z.number().int().positive().optional(),
|
|
2939
|
+
})
|
|
2940
|
+
.strict()
|
|
2941
|
+
.optional(),
|
|
2942
|
+
})
|
|
2943
|
+
.strict();
|
|
2944
|
+
/** `PUT /v1/tenant/artifacts`: replaces the Tenant's artifact configuration. */
|
|
2945
|
+
export const PutTenantArtifactsRequestSchema = TenantArtifactsConfigSchema.extend({
|
|
2946
|
+
requestId: RequestIdSchema.optional(),
|
|
2947
|
+
}).strict();
|
|
2948
|
+
export const TenantArtifactsViewSchema = z
|
|
2949
|
+
.object({
|
|
2950
|
+
limits: z.object({ fileBytes: z.number().int(), totalBytes: z.number().int() }).strict(),
|
|
2951
|
+
/**
|
|
2952
|
+
* Bytes the artifacts store now: every file version, plus each distinct file of the folders
|
|
2953
|
+
* once (folders share content-addressed files).
|
|
2954
|
+
*/
|
|
2955
|
+
usedBytes: z.number().int().nonnegative(),
|
|
2956
|
+
})
|
|
2957
|
+
.strict();
|