@nylorun/core 0.22.0-beta → 0.23.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +1 -1
  3. package/dist/compatibility.d.ts +32 -16
  4. package/dist/compatibility.js +33 -17
  5. package/dist/contracts.d.ts +531 -88
  6. package/dist/contracts.js +297 -199
  7. package/dist/define.d.ts +8 -12
  8. package/dist/define.js +7 -11
  9. package/dist/definition/assemble.d.ts +1 -3
  10. package/dist/definition/assemble.js +4 -8
  11. package/dist/definition/bound.d.ts +1 -1
  12. package/dist/definition/delegate.d.ts +5 -0
  13. package/dist/definition/delegate.js +6 -1
  14. package/dist/definition/from.d.ts +4 -2
  15. package/dist/definition/from.js +11 -29
  16. package/dist/definition/http-tool.d.ts +5 -3
  17. package/dist/definition/http-tool.js +8 -5
  18. package/dist/definition/manifest.d.ts +7 -6
  19. package/dist/definition/manifest.js +7 -6
  20. package/dist/definition/mcp.d.ts +1 -1
  21. package/dist/definition/media-reference.d.ts +2 -11
  22. package/dist/definition/media-reference.js +0 -12
  23. package/dist/definition/model-failure.js +1 -0
  24. package/dist/definition/removed.js +1 -0
  25. package/dist/definition/trace.d.ts +0 -7
  26. package/dist/definition/trace.js +0 -34
  27. package/dist/definition/variant.d.ts +1 -1
  28. package/dist/definition/variant.js +1 -3
  29. package/dist/harness-api/artifacts.d.ts +84 -0
  30. package/dist/harness-api/artifacts.js +128 -0
  31. package/dist/harness-api/gates.d.ts +0 -4
  32. package/dist/harness-api/gates.js +0 -4
  33. package/dist/harness-api/harness-api.schema.json +2422 -924
  34. package/dist/harness-api/index.d.ts +9 -6
  35. package/dist/harness-api/index.js +9 -6
  36. package/dist/harness-api/json-schema.js +5 -2
  37. package/dist/harness-api/mcp.d.ts +77 -30
  38. package/dist/harness-api/mcp.js +42 -25
  39. package/dist/harness-api/messages.d.ts +45 -17
  40. package/dist/harness-api/messages.js +20 -5
  41. package/dist/harness-api/schema.d.ts +538 -198
  42. package/dist/harness-api/schema.js +298 -59
  43. package/dist/harness-api/transcript.d.ts +8 -10
  44. package/dist/harness-api/transcript.js +27 -11
  45. package/dist/harness-api/transport.d.ts +7 -1
  46. package/dist/harness-api/transport.js +10 -7
  47. package/dist/schemas/agent-manifest.schema.json +5 -146
  48. package/dist/schemas/environment-manifest.schema.json +56 -16
  49. package/dist/types/manifest.d.ts +3 -13
  50. package/dist/types/model.d.ts +10 -5
  51. package/dist/utils/definition-files.d.ts +20 -6
  52. package/dist/utils/definition-files.js +31 -17
  53. package/dist/utils/file-systems.d.ts +20 -0
  54. package/dist/utils/file-systems.js +20 -0
  55. package/dist/utils/harness-id.d.ts +4 -1
  56. package/dist/utils/harness-id.js +4 -1
  57. package/dist/utils/media-types.d.ts +30 -0
  58. package/dist/utils/media-types.js +128 -0
  59. package/dist/utils/runtime-limits.d.ts +229 -0
  60. package/dist/utils/runtime-limits.js +482 -0
  61. package/dist/utils/runtime-tools.d.ts +8 -16
  62. package/dist/utils/runtime-tools.js +8 -27
  63. package/dist/utils/sandbox.d.ts +4 -1
  64. package/dist/utils/sandbox.js +4 -1
  65. package/package.json +1 -1
  66. package/dist/definition/deferred-tools.d.ts +0 -27
  67. package/dist/definition/deferred-tools.js +0 -82
  68. package/dist/definition/runtime-manifest.d.ts +0 -30
  69. package/dist/definition/runtime-manifest.js +0 -132
  70. package/dist/definition/sandbox-tools.d.ts +0 -5
  71. package/dist/definition/sandbox-tools.js +0 -109
  72. package/dist/definition/skill-tools.d.ts +0 -23
  73. package/dist/definition/skill-tools.js +0 -76
package/dist/contracts.js CHANGED
@@ -1,19 +1,24 @@
1
1
  /** Public wire contracts only. Never import checkpoint or engine modules here. */
2
2
  import { z } from "zod";
3
- import { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
3
+ import { SANDBOX_NETWORK_PRESETS, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
4
4
  import { REMOVED_MANIFEST_FIELDS, manifestVersionIssue, workflowVersionIssue, } from "./definition/removed.js";
5
- import { RUNTIME_TOOL_NAMES } from "./utils/runtime-tools.js";
6
5
  import { DELEGATE_INPUT_SCHEMA, DELEGATE_NAME_PATTERN } from "./definition/delegate.js";
7
6
  import { stdioMcpRefusal } from "./definition/mcp.js";
8
- import { APPROVAL_MODES, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, httpInputIssue, httpUrlIssue, httpUrlTemplateIssue, httpVerifierIssue, } from "./definition/http-tool.js";
7
+ import { APPROVAL_MODES, HTTP_TOOL_METHODS, httpInputIssue, httpUrlIssue, httpUrlTemplateIssue, httpVerifierIssue, } from "./definition/http-tool.js";
9
8
  import { canonical } from "./utils/canonical.js";
9
+ import { FILE_NAME_MAX, FILE_PATH_MAX, LINK_TARGET_MAX } from "./utils/file-systems.js";
10
+ export { FILE_NAME_MAX, FILE_PATH_MAX } from "./utils/file-systems.js";
10
11
  import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, isHarnessId } from "./utils/harness-id.js";
11
12
  export { DEFAULT_HARNESS, HARNESS_ID_PATTERN, isHarnessId };
12
- import { DEFINITION_FILE_MAX_BYTES, isDefinitionFileHash, skillFilesIssue } from "./utils/definition-files.js";
13
+ import { isDefinitionFileHash, skillFilesIssue } from "./utils/definition-files.js";
13
14
  export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
14
- export { DEFINITION_FILE_MAX_BYTES, SKILL_FILES_MAX, definitionFilesOf, isDefinitionFileHash, } from "./utils/definition-files.js";
15
+ export { SKILL_TOTAL_BYTES_DEFAULT, definitionFilesOf, isDefinitionFileHash, skillsOf, } from "./utils/definition-files.js";
16
+ export { HARNESS_LIMIT_DEFAULTS, HarnessLimitsSchema, JS_STRING_MAX_LENGTH, RECORD_ENVELOPE_RESERVE_BYTES, RUNTIME_LIMIT_CEILINGS, RUNTIME_LIMIT_DEFAULTS, RuntimeLimitsSchema, S2_RECORD_MAX_BYTES, TIMER_MAX_MS, harnessLimitsOf, inlineBodyBytes, limitExceededMessage, runtimeLimitIssues, runtimeLimitsOf, } from "./utils/runtime-limits.js";
17
+ import { RuntimeLimitsSchema, TIMER_MAX_MS } from "./utils/runtime-limits.js";
18
+ export { DEFAULT_CONTENT_TYPE, MODEL_IMAGE_TYPES, contentTypeFor, essence, extensionFor, inputLabel, isModelImage, isOffice, isText, modelInputOf, normalizeContentType, } from "./utils/media-types.js";
15
19
  import { ERROR_CODES, isArtifactId } from "./compatibility.js";
16
20
  export const RequestIdSchema = z.string().min(1);
21
+ /** At most 256 characters: an identifier's grammar is the protocol's (it crosses the Runtime API, the Harness API and tokens, and means the same in every installation), so its length is a constant of protocol 15, not a setting. */
17
22
  export const IdempotencyKeySchema = z.string().min(1).max(256);
18
23
  const jsonObject = z.record(z.string(), z.unknown());
19
24
  /**
@@ -122,7 +127,8 @@ const sandboxManifestSchema = z
122
127
  .optional(),
123
128
  resources: z
124
129
  .object({
125
- cpus: z.number().int().min(1).max(64).optional(),
130
+ /** At most the Tenant's `limits.resources.cpus` (`environments.config`). */
131
+ cpus: z.number().int().min(1).optional(),
126
132
  memory: z
127
133
  .string()
128
134
  .refine((value) => parseSandboxSize(value) !== undefined, {
@@ -149,7 +155,7 @@ const httpToolTargetSchema = z
149
155
  }),
150
156
  method: z.enum(HTTP_TOOL_METHODS).optional(),
151
157
  credential: z.string().min(1).optional(),
152
- timeoutMs: z.number().int().positive().max(HTTP_TOOL_MAX_TIMEOUT_MS).optional(),
158
+ timeoutMs: z.number().int().positive().max(TIMER_MAX_MS).optional(),
153
159
  })
154
160
  .strict();
155
161
  /** A name kept for a later kind of `what` (tool, verifier), refused for now. */
@@ -199,14 +205,12 @@ const removedFieldError = (removedFields) => (issue) => {
199
205
  const removed = issue.keys?.find((key) => removedFields[key] !== undefined);
200
206
  return removed === undefined ? undefined : removedFields[removed];
201
207
  };
202
- /** What the Runtime adds to a session's agent; only the Runtime writes it. */
203
- const runtimeManifestSchema = z
204
- .object({
205
- sandbox: sandboxManifestSchema.optional(),
206
- tools: z.array(toolManifestSchema).optional(),
207
- instructions: z.array(z.string()).optional(),
208
- })
209
- .strict();
208
+ /**
209
+ * An environment variable name a shell secret or plain variable may take (R2c, D50): a POSIX
210
+ * name, of any length (POSIX and Linux set none; a request's body bounds it). Names the sandbox
211
+ * needs for itself (the proxy, the trust store, `PATH`, `HOME`) and `NYLORUN_*` are reserved.
212
+ */
213
+ export const ENVIRONMENT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
210
214
  /**
211
215
  * What an agent needs of the Environment its session opens on (protocol 14, D65), checked when a
212
216
  * session opens (`409 environment_unsuitable`). `sandbox`: `any` needs kind `virtual` or `pod`,
@@ -216,7 +220,8 @@ const runtimeManifestSchema = z
216
220
  const agentRequirementsSchema = z
217
221
  .object({
218
222
  sandbox: z.enum(["none", "any", "pod"]).optional(),
219
- secrets: z.array(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,127}$/, "A secret name in requires is an environment variable name")).max(64).optional(),
223
+ /** At most the Tenant's Runtime limit `environmentSecretSlots`, checked when the agent is deployed. */
224
+ secrets: z.array(z.string().regex(ENVIRONMENT_NAME_PATTERN, "A secret name in requires is an environment variable name")).optional(),
220
225
  })
221
226
  .strict();
222
227
  const agentManifestSchema = z
@@ -234,7 +239,6 @@ const agentManifestSchema = z
234
239
  skills: z.record(z.string(), skillManifestSchema).optional(),
235
240
  mcpServers: z.record(z.string(), mcpServerSchema).optional(),
236
241
  requires: agentRequirementsSchema.optional(),
237
- runtime: runtimeManifestSchema.optional(),
238
242
  // Reserved for Functions, which are deferred: developer code the Runtime will run from
239
243
  // uploaded definition files (a `functions/` folder). Any value is refused below.
240
244
  functions: z.unknown().optional().meta({ description: "Reserved: Functions are not available yet" }),
@@ -245,37 +249,17 @@ const agentManifestSchema = z
245
249
  delegationIssues(manifest, (message) => ctx.addIssue({ code: "custom", message }));
246
250
  const names = new Set();
247
251
  for (const tool of manifest.tools ?? []) {
248
- if (RUNTIME_TOOL_NAMES.has(tool.name))
249
- ctx.addIssue({
250
- code: "custom",
251
- message: `Tool '${tool.name}' takes the name of a tool the Runtime serves; rename it`,
252
- });
253
252
  if (tool.name.includes("__"))
254
253
  ctx.addIssue({
255
254
  code: "custom",
256
255
  message: `Tool '${tool.name}' must not contain '__', which names an MCP server's tools`,
257
256
  });
258
257
  }
259
- for (const tool of [...(manifest.tools ?? []), ...(manifest.runtime?.tools ?? [])]) {
258
+ for (const tool of manifest.tools ?? []) {
260
259
  if (names.has(tool.name))
261
260
  ctx.addIssue({ code: "custom", message: "Tool names must be unique" });
262
261
  names.add(tool.name);
263
262
  }
264
- for (const tool of manifest.runtime?.tools ?? [])
265
- if (!RUNTIME_TOOL_NAMES.has(tool.name))
266
- ctx.addIssue({
267
- code: "custom",
268
- message: `runtime.tools holds only the tools the Runtime serves, not '${tool.name}'`,
269
- });
270
- if (manifest.runtime?.sandbox !== undefined) {
271
- const pinned = new Set((manifest.runtime.tools ?? []).map((tool) => tool.name));
272
- for (const name of SANDBOX_TOOL_NAMES)
273
- if (!pinned.has(name))
274
- ctx.addIssue({
275
- code: "custom",
276
- message: `runtime.sandbox comes with the sandbox tools; runtime.tools has no '${name}'`,
277
- });
278
- }
279
263
  if (manifest.skills && Object.keys(manifest.skills).length === 0)
280
264
  ctx.addIssue({ code: "custom", message: "skills must be omitted when the agent has no skills" });
281
265
  for (const [key, skill] of Object.entries(manifest.skills ?? {}))
@@ -292,14 +276,8 @@ const agentManifestSchema = z
292
276
  * (`ManifestDrift`): the hand-written type keeps its read-only fields and its docs.
293
277
  */
294
278
  export const AgentManifestSchema = agentManifestSchema;
295
- /** Agents used as tools: one level deep, `{ task }` input, one shared sandbox spec. */
279
+ /** Agents used as tools: one level deep, `{ task }` input. */
296
280
  function delegationIssues(manifest, issue) {
297
- const sandboxes = new Set();
298
- const addSandbox = (agent) => {
299
- if (agent.runtime?.sandbox)
300
- sandboxes.add(canonical(agent.runtime.sandbox));
301
- };
302
- addSandbox(manifest);
303
281
  for (const tool of manifest.tools ?? []) {
304
282
  const child = tool.agent;
305
283
  if (!child)
@@ -312,18 +290,12 @@ function delegationIssues(manifest, issue) {
312
290
  issue(`Agent tool '${tool.name}' must take the standard { task } input`);
313
291
  if (tool.outputSchema !== undefined)
314
292
  issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
315
- if ("kind" in child) {
316
- // A flow agent runs in its own linked session; its leaves may delegate in turn.
317
- if (child.sandbox !== undefined && Object.keys(child.sandbox).length > 0)
318
- sandboxes.add(canonical(child.sandbox));
293
+ // A flow agent runs in its own linked session; its leaves may delegate in turn.
294
+ if ("kind" in child)
319
295
  continue;
320
- }
321
296
  if (child.tools?.some((item) => item.agent !== undefined))
322
297
  issue(`'${child.id}' delegates to another agent; nested delegation is not supported yet`);
323
- addSandbox(child);
324
298
  }
325
- if (sandboxes.size > 1)
326
- issue("An agent and the agents it uses as tools must declare identical sandboxes");
327
299
  }
328
300
  // Workflow manifest v3 (flow agents): `id` on any node, embedded agents, no functions.
329
301
  const workflowNodeOptions = { id: z.string().min(1).optional() };
@@ -506,7 +478,8 @@ const durationSchema = (name) => z.string().refine((value) => parseSandboxDurati
506
478
  });
507
479
  const resourcesSchema = z
508
480
  .object({
509
- cpus: z.number().int().min(1).max(64).optional(),
481
+ /** At most the Tenant's `limits.resources.cpus` (`environments.config`), which it sets. */
482
+ cpus: z.number().int().min(1).optional(),
510
483
  memory: z
511
484
  .string()
512
485
  .refine((value) => parseSandboxSize(value) !== undefined, {
@@ -522,6 +495,11 @@ const resourcesSchema = z
522
495
  * hierarchical so a grant can name a family of them (`users/alice/*`).
523
496
  */
524
497
  const ENVIRONMENT_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/;
498
+ /**
499
+ * An identifier's grammar is the protocol's (B15): it crosses the Runtime API, tokens and grants
500
+ * and means the same in every installation, so its length is a constant of protocol 15, not a
501
+ * setting.
502
+ */
525
503
  export const ENVIRONMENT_ID_MAX_LENGTH = 200;
526
504
  export function isEnvironmentId(value) {
527
505
  return (typeof value === "string" &&
@@ -564,19 +542,18 @@ export const EnvironmentGrantSchema = z.string().refine(isEnvironmentGrant, {
564
542
  * compute, only the vault, for agents whose tools are remote MCP servers and HTTP tools.
565
543
  */
566
544
  export const ENVIRONMENT_KINDS = ["virtual", "pod", "none"];
567
- const LABEL_KEY_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._/-]{0,61}[A-Za-z0-9])?$/;
568
- const LABEL_VALUE_PATTERN = /^[\x20-\x7e]{0,256}$/;
569
- export const ENVIRONMENT_LABELS_MAX = 32;
570
- /** The developer's own key-value pairs; the Runtime stores and filters them, never reads them. */
571
- export const EnvironmentLabelsSchema = z
572
- .record(z.string().regex(LABEL_KEY_PATTERN, {
573
- message: "Label keys are 1-63 letters, digits, '.', '_', '/' and '-'",
545
+ const LABEL_KEY_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._/-]*[A-Za-z0-9])?$/;
546
+ const LABEL_VALUE_PATTERN = /^[\x20-\x7e]*$/;
547
+ /**
548
+ * The developer's own key-value pairs; the Runtime stores and filters them, never reads them. How
549
+ * many, and how long a key and a value may be, are the Tenant's Runtime limits
550
+ * `environmentLabels`, `labelKeyChars` and `labelValueChars`, checked when they are set.
551
+ */
552
+ export const EnvironmentLabelsSchema = z.record(z.string().regex(LABEL_KEY_PATTERN, {
553
+ message: "Label keys are letters, digits, '.', '_', '/' and '-', and start and end with a letter or digit",
574
554
  }), z.string().regex(LABEL_VALUE_PATTERN, {
575
- message: "Label values are up to 256 printable ASCII characters",
576
- }))
577
- .refine((labels) => Object.keys(labels).length <= ENVIRONMENT_LABELS_MAX, {
578
- message: `At most ${ENVIRONMENT_LABELS_MAX} labels`,
579
- });
555
+ message: "Label values are printable ASCII characters",
556
+ }));
580
557
  /** A harness id (track R4): what a harness names itself in `hello`. */
581
558
  export const HarnessIdSchema = z.string().regex(HARNESS_ID_PATTERN, {
582
559
  message: "harness must be a harness id: lowercase letters, digits and dashes, starting with a letter",
@@ -593,14 +570,15 @@ export const EnvironmentLifecycleSchema = z
593
570
  deleteAfter: durationSchema("lifecycle.deleteAfter").optional(),
594
571
  })
595
572
  .strict();
596
- /** The most setup commands and input files an Environment's recipe holds (step 2). */
597
- export const ENVIRONMENT_SETUP_MAX = 16;
598
- /** A setup command's longest timeout (default 10m). */
599
- export const ENVIRONMENT_SETUP_TIMEOUT_MAX_MS = 30 * 60_000;
573
+ /**
574
+ * The default of a setup command's `timeout` setting. The longest one may ask for is the Tenant's
575
+ * Runtime limit `setupCommandMs`.
576
+ */
577
+ export const ENVIRONMENT_SETUP_TIMEOUT_DEFAULT = "10m";
600
578
  const absoluteWorkspacePath = (name) => z
601
579
  .string()
602
580
  .min(1)
603
- .max(1024)
581
+ .max(FILE_PATH_MAX)
604
582
  .refine((value) => (value === "/workspace" || value.startsWith("/workspace/")) &&
605
583
  !value.split("/").some((segment) => segment === ".." || segment === "."), { message: `${name} must be /workspace or a path under it, without . or .. segments` });
606
584
  /**
@@ -610,15 +588,12 @@ const absoluteWorkspacePath = (name) => z
610
588
  */
611
589
  export const EnvironmentSetupCommandSchema = z
612
590
  .object({
613
- command: z.string().min(1).max(4096),
591
+ /** At most the Tenant's Runtime limit `setupCommandChars`, checked when the manifest is put. */
592
+ command: z.string().min(1),
614
593
  /** Where it runs. Default `/workspace`. */
615
594
  cwd: absoluteWorkspacePath("cwd").optional(),
616
- /** Default 10m, at most 30m. */
617
- timeout: durationSchema("timeout")
618
- .refine((value) => (parseSandboxDuration(value) ?? 0) <= ENVIRONMENT_SETUP_TIMEOUT_MAX_MS, {
619
- message: "timeout is at most 30m",
620
- })
621
- .optional(),
595
+ /** Default 10m (`ENVIRONMENT_SETUP_TIMEOUT_DEFAULT`), at most the Tenant's `setupCommandMs`. */
596
+ timeout: durationSchema("timeout").optional(),
622
597
  })
623
598
  .strict();
624
599
  /**
@@ -626,18 +601,16 @@ export const EnvironmentSetupCommandSchema = z
626
601
  * is made or reset, before the setup commands. A file artifact is written at `path`; a folder
627
602
  * artifact is unpacked under it.
628
603
  */
629
- /** The most files one `files` entry by hash names (Q6). */
630
- export const ENVIRONMENT_FILES_MAX = 1000;
631
604
  /** A file's path inside a `files` entry by hash: relative, `/`-separated, without `.` or `..`. */
632
605
  const relativeFilePath = z
633
606
  .string()
634
607
  .min(1)
635
- .max(1024)
608
+ .max(FILE_PATH_MAX)
636
609
  .refine((value) => !value.startsWith("/") && !value.includes("\0") && value.split("/").every((segment) => segment !== "" && segment !== "." && segment !== ".."), { message: "a file's path is relative, without empty, . or .. segments" });
637
610
  /**
638
611
  * One input file entry (pods only): an artifact version copied to `path` (a file artifact, or a
639
612
  * folder's files under it), or (Q6) files by content hash, each `sha256:<hex>` of a definition
640
- * file the Tenant holds (`PUT /v1/files/sha256:<hex>`, at most 10 MiB each), copied under `path`
613
+ * file the Tenant holds (`PUT /v1/files/sha256:<hex>`, at most 2 GiB each), copied under `path`
641
614
  * at its relative path. A manifest by hash moves to another Tenant with its files.
642
615
  */
643
616
  export const EnvironmentFileSchema = z.union([
@@ -653,15 +626,17 @@ export const EnvironmentFileSchema = z.union([
653
626
  path: absoluteWorkspacePath("path"),
654
627
  files: z
655
628
  .record(relativeFilePath, z.string().refine(isDefinitionFileHash, { message: "each file is sha256:<64 lowercase hex>" }))
656
- .refine((files) => Object.keys(files).length >= 1 && Object.keys(files).length <= ENVIRONMENT_FILES_MAX, {
657
- message: `files names 1 to ${ENVIRONMENT_FILES_MAX} files`,
658
- }),
629
+ // At most the Tenant's Runtime limit `environmentFilesPerEntry`, checked when made (Q6).
630
+ .refine((files) => Object.keys(files).length >= 1, { message: "files names at least one file" }),
659
631
  })
660
632
  .strict(),
661
633
  ]);
662
634
  /**
663
635
  * An environment manifest's name (protocol 14, D63): 1–64 letters, digits, `.`, `_` and `-`,
664
- * starting with a letter or digit, such as `analyst-box`.
636
+ * starting with a letter or digit, such as `analyst-box`; a version is at most 9 digits.
637
+ * An identifier's grammar is the protocol's (B15): it crosses the Runtime API, tokens and grants
638
+ * and means the same in every installation, so its length is a constant of protocol 15, not a
639
+ * setting.
665
640
  */
666
641
  const ENVIRONMENT_MANIFEST_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
667
642
  export function isEnvironmentManifestName(value) {
@@ -693,6 +668,42 @@ export const EnvironmentManifestRefSchema = z
693
668
  message: "manifest is an environment manifest's name, or name@version such as analyst-box@3",
694
669
  })
695
670
  .meta({ description: "`name` (the latest version when the Environment is created) or `name@n`" });
671
+ /**
672
+ * What an Environment's artifacts, its sessions' skills and its disk versions may hold: part of
673
+ * its manifest, fixed for its life. Each limit left out is the Tenant's (`/v1/tenant/artifacts`,
674
+ * `/v1/tenant/skills`, `/v1/tenant/limits`) as it is when the limit is checked, and none may be
675
+ * above the Tenant's.
676
+ */
677
+ export const EnvironmentLimitsSchema = z
678
+ .object({
679
+ artifacts: z
680
+ .object({
681
+ /** The largest file one artifact upload, save or export may store. */
682
+ fileBytes: z.number().int().positive().optional(),
683
+ /** The most bytes the artifacts of its sessions and its disk versions may hold together. */
684
+ totalBytes: z.number().int().positive().optional(),
685
+ })
686
+ .strict()
687
+ .optional(),
688
+ skills: z
689
+ .object({
690
+ /** The most bytes one skill's files may hold together, for a session to open in it. */
691
+ totalBytes: z.number().int().positive().optional(),
692
+ })
693
+ .strict()
694
+ .optional(),
695
+ /** Its disk versions, within the Tenant's Runtime limits `diskVersion*` (`/v1/tenant/limits`). */
696
+ disk: z
697
+ .object({
698
+ /** The most bytes of files one version of its disk holds. */
699
+ versionBytes: z.number().int().positive().optional(),
700
+ /** The most entries (files, links, empty directories) one version holds. */
701
+ versionEntries: z.number().int().positive().optional(),
702
+ })
703
+ .strict()
704
+ .optional(),
705
+ })
706
+ .strict();
696
707
  /**
697
708
  * `PUT /v1/environments/{environmentId}`: creates the Environment and its vault, or finds the
698
709
  * one with this id, so "get or create" is one call. An Environment is made from one version of an
@@ -749,9 +760,14 @@ export const PutEnvironmentRequestSchema = z
749
760
  * Pods only (Host feature `environment-setup`): commands run when the disk is made or reset,
750
761
  * before any turn. A change applies at the next reset.
751
762
  */
752
- setup: z.array(EnvironmentSetupCommandSchema).max(ENVIRONMENT_SETUP_MAX).optional(),
763
+ setup: z.array(EnvironmentSetupCommandSchema).optional(),
753
764
  /** Pods only: artifact versions copied in when the disk is made or reset, before `setup`. */
754
- files: z.array(EnvironmentFileSchema).max(ENVIRONMENT_SETUP_MAX).optional(),
765
+ files: z.array(EnvironmentFileSchema).optional(),
766
+ /**
767
+ * What its artifacts and its sessions' skills may hold, at most the Tenant's limits; a limit
768
+ * left out is the Tenant's. Fixed.
769
+ */
770
+ limits: EnvironmentLimitsSchema.optional(),
755
771
  /**
756
772
  * The secrets an Environment of this kind needs, by name (D64): each slot's type, binding,
757
773
  * whether it is required and a description, never a value. With slots declared, a secret
@@ -785,6 +801,8 @@ export const EnvironmentRecipeSchema = z
785
801
  lifecycle: EnvironmentLifecycleSchema,
786
802
  setup: z.array(EnvironmentSetupCommandSchema).optional(),
787
803
  files: z.array(EnvironmentFileSchema).optional(),
804
+ /** As the manifest set them: a limit left out is the Tenant's when it is checked. */
805
+ limits: EnvironmentLimitsSchema.optional(),
788
806
  secrets: z.lazy(() => EnvironmentSecretSlotsSchema).optional(),
789
807
  })
790
808
  .strict();
@@ -841,6 +859,14 @@ export const EnvironmentViewSchema = z
841
859
  manifestVersion: z.number().int().positive().optional(),
842
860
  /** The hash of what it runs (`manifest`). */
843
861
  manifestHash: z.string().optional(),
862
+ /** The limits in force now: its manifest's, else the Tenant's, never above the Tenant's. */
863
+ limits: z
864
+ .object({
865
+ artifacts: z.object({ fileBytes: z.number().int(), totalBytes: z.number().int() }).strict(),
866
+ skills: z.object({ totalBytes: z.number().int() }).strict(),
867
+ disk: z.object({ versionBytes: z.number().int(), versionEntries: z.number().int() }).strict(),
868
+ })
869
+ .strict(),
844
870
  /**
845
871
  * The Environment it was forked from (`POST .../fork`, Q15), and the disk version it started
846
872
  * from (`null` for an empty disk).
@@ -1109,19 +1135,15 @@ export const TenantEnvironmentsConfigSchema = z
1109
1135
  /** Stop compute after this long without use; an Environment's `lifecycle.idle` is at most this. */
1110
1136
  idle: durationSchema("limits.idle").optional(),
1111
1137
  /** The most Environments the Tenant may hold. Default 100. */
1112
- environments: z.number().int().min(0).max(100_000).optional(),
1138
+ environments: z.number().int().min(0).optional(),
1113
1139
  })
1114
1140
  .strict()
1115
1141
  .optional(),
1116
1142
  /** Pods: how long a pod has to stop. Read at every timer. */
1117
1143
  lifecycle: z
1118
1144
  .object({
1119
- /** The pod's grace period to stop, at most 30s. Default 10s. */
1120
- stopGrace: durationSchema("lifecycle.stopGrace")
1121
- .refine((value) => (parseSandboxDuration(value) ?? 0) <= 30_000, {
1122
- message: "lifecycle.stopGrace is at most 30s",
1123
- })
1124
- .optional(),
1145
+ /** The pod's grace period to stop (its `terminationGracePeriodSeconds`). Default 10s. */
1146
+ stopGrace: durationSchema("lifecycle.stopGrace").optional(),
1125
1147
  })
1126
1148
  .strict()
1127
1149
  .optional(),
@@ -1202,12 +1224,6 @@ const credentialRoutingChange = {
1202
1224
  via: CredentialViaSchema.nullable().optional(),
1203
1225
  identity: CredentialIdentitySchema.nullable().optional(),
1204
1226
  };
1205
- /**
1206
- * An environment variable name a shell secret or plain variable may take (R2c, D50): a POSIX
1207
- * name. Names the sandbox needs for itself (the proxy, the trust store, `PATH`, `HOME`) and
1208
- * `NYLORUN_*` are reserved.
1209
- */
1210
- export const ENVIRONMENT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
1211
1227
  export const RESERVED_ENVIRONMENT_NAMES = new Set([
1212
1228
  "PATH",
1213
1229
  "HOME",
@@ -1234,8 +1250,12 @@ const EnvironmentNameSchema = z
1234
1250
  .string()
1235
1251
  .regex(ENVIRONMENT_NAME_PATTERN, "An environment variable name is a letter or _ followed by letters, digits or _")
1236
1252
  .refine((name) => !isReservedEnvironmentName(name), "That environment variable name is reserved");
1237
- /** The value a sandbox sees for every `environment_secret` (R2c, D50): never the secret. */
1238
- export const ENVIRONMENT_SECRET_SENTINEL = "nylorun-managed";
1253
+ /**
1254
+ * The value a sandbox sees for every `environment_secret` (R2c, D50): never the secret. Word
1255
+ * characters only, so CLIs that check a token's format before sending it (the Vercel CLI
1256
+ * refuses anything matching `\W`) still send the request egress-gate sets the header on.
1257
+ */
1258
+ export const ENVIRONMENT_SECRET_SENTINEL = "nylorun_managed";
1239
1259
  /**
1240
1260
  * How egress-gate writes an `environment_secret` into a request (R2c, D50): one header, set on
1241
1261
  * every request to a bound host. `format` is text with `{value}` once, optionally inside a
@@ -1276,14 +1296,18 @@ const AllowedHostsSchema = z
1276
1296
  .toLowerCase()
1277
1297
  .refine((host) => /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/.test(host) && !/^\d+(\.\d+){3}$/.test(host), "allowedHosts takes exact host names such as api.github.com: no wildcard, port or IP address"))
1278
1298
  .min(1)
1279
- .max(32)
1280
1299
  .refine((hosts) => new Set(hosts).size === hosts.length, "allowedHosts lists each host once");
1300
+ /** At most the Tenant's Runtime limit `secretValueChars`, checked when it is written. */
1281
1301
  const EnvironmentValueSchema = z
1282
1302
  .string()
1283
1303
  .min(1)
1284
- .max(8192)
1285
1304
  .refine((value) => !/[\r\n\0]/.test(value), "A value has no CR, LF or NUL");
1286
- /** The name of a credential for a tool (`bearer` or `headers`): a label of 1–64 characters. */
1305
+ /**
1306
+ * The name of a credential for a tool (`bearer` or `headers`): a label of 1–64 characters.
1307
+ * An identifier's grammar is the protocol's (B15): it crosses the Runtime API, tokens and grants
1308
+ * and means the same in every installation, so its length is a constant of protocol 15, not a
1309
+ * setting.
1310
+ */
1287
1311
  export const TOOL_SECRET_NAME_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
1288
1312
  /**
1289
1313
  * `PUT /v1/environments/{environmentId}/secrets/{name}` (D56): creates or replaces one credential
@@ -1337,7 +1361,7 @@ export const PutEnvironmentSecretRequestSchema = z.discriminatedUnion("type", [
1337
1361
  export const PutEnvironmentSecretValueRequestSchema = z
1338
1362
  .object({
1339
1363
  requestId: RequestIdSchema.optional(),
1340
- value: z.string().min(1).max(8192).optional(),
1364
+ value: z.string().min(1).optional(),
1341
1365
  headers: CredentialHeadersSchema.optional(),
1342
1366
  })
1343
1367
  .strict()
@@ -1361,7 +1385,8 @@ export function environmentSecretNameError(type, name) {
1361
1385
  const slotBase = {
1362
1386
  /** Whether a session whose agent needs it may open without it. Default false. */
1363
1387
  required: z.boolean().optional(),
1364
- description: z.string().max(500).optional(),
1388
+ /** At most the Tenant's Runtime limit `secretDescriptionChars`, checked when the manifest is put. */
1389
+ description: z.string().optional(),
1365
1390
  };
1366
1391
  /**
1367
1392
  * One secret an Environment of a kind needs (D64): its type and binding, never its value. The
@@ -1381,15 +1406,11 @@ export const EnvironmentSecretSlotSchema = z.discriminatedUnion("type", [
1381
1406
  z.object({ type: z.literal("bearer"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1382
1407
  z.object({ type: z.literal("headers"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1383
1408
  ]);
1384
- /** The most secret slots one manifest declares. */
1385
- export const ENVIRONMENT_SECRET_SLOTS_MAX = 64;
1409
+ /** A manifest's secret slots: at most the Tenant's Runtime limit `environmentSecretSlots`. */
1386
1410
  export const EnvironmentSecretSlotsSchema = z
1387
1411
  .record(z.string(), EnvironmentSecretSlotSchema)
1388
1412
  .superRefine((slots, ctx) => {
1389
- const names = Object.keys(slots);
1390
- if (names.length > ENVIRONMENT_SECRET_SLOTS_MAX)
1391
- ctx.addIssue({ code: "custom", message: `At most ${ENVIRONMENT_SECRET_SLOTS_MAX} secrets` });
1392
- for (const name of names) {
1413
+ for (const name of Object.keys(slots)) {
1393
1414
  const error = environmentSecretNameError(slots[name].type, name);
1394
1415
  if (error)
1395
1416
  ctx.addIssue({ code: "custom", path: [name], message: error });
@@ -1410,7 +1431,8 @@ export const EnvironmentManifestSchema = z
1410
1431
  error: (issue) => `manifestSchemaVersion ${JSON.stringify(issue.input)} is not one this Runtime reads: use ${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`,
1411
1432
  }),
1412
1433
  name: EnvironmentManifestNameSchema,
1413
- description: z.string().max(1024).optional(),
1434
+ /** At most the Tenant's Runtime limit `manifestDescriptionChars`, checked when it is saved. */
1435
+ description: z.string().optional(),
1414
1436
  kind: environmentFields.kind,
1415
1437
  image: environmentFields.image,
1416
1438
  resources: environmentFields.resources,
@@ -1420,6 +1442,7 @@ export const EnvironmentManifestSchema = z
1420
1442
  lifecycle: environmentFields.lifecycle,
1421
1443
  setup: environmentFields.setup,
1422
1444
  files: environmentFields.files,
1445
+ limits: environmentFields.limits,
1423
1446
  secrets: EnvironmentSecretSlotsSchema.optional(),
1424
1447
  })
1425
1448
  .strict();
@@ -1560,15 +1583,21 @@ export const ForkEnvironmentResponseSchema = z.union([
1560
1583
  */
1561
1584
  export const MODEL_INPUTS = ["text", "image", "pdf", "office", "audio", "video"];
1562
1585
  export const ModelInputSchema = z.enum(MODEL_INPUTS);
1586
+ /**
1587
+ * The defaults of a custom endpoint's `contextWindow` and `maxTokens` settings (and the window
1588
+ * assumed for a model the Runtime knows nothing of): small, since an early compaction beats a
1589
+ * failed call.
1590
+ */
1591
+ export const CUSTOM_MODEL_SETTING_DEFAULTS = Object.freeze({ contextWindow: 32_768, maxTokens: 8_192 });
1563
1592
  /**
1564
1593
  * What the Runtime cannot learn from a custom OpenAI-compatible endpoint (Model Calls §7):
1565
- * its context window and output limit, whether it reasons, what it reads (`inputs`; default text
1566
- * only) and pi-ai `compat` settings (`thinkingFormat`, `thinkingTokenBudgetField`,
1567
- * `chatTemplateKwargs`, …).
1594
+ * its context window and output limit (default `CUSTOM_MODEL_SETTING_DEFAULTS`), whether it
1595
+ * reasons, what it reads (`inputs`; default text only) and pi-ai `compat` settings
1596
+ * (`thinkingFormat`, `thinkingTokenBudgetField`, `chatTemplateKwargs`, …).
1568
1597
  */
1569
1598
  export const CustomModelSettingsSchema = z
1570
1599
  .object({
1571
- contextWindow: z.number().int().min(1024).optional(),
1600
+ contextWindow: z.number().int().min(1).optional(),
1572
1601
  maxTokens: z.number().int().min(1).optional(),
1573
1602
  reasoning: z.boolean().optional(),
1574
1603
  inputs: z.array(ModelInputSchema).optional(),
@@ -1683,8 +1712,9 @@ export const McpPreviewToolSchema = z
1683
1712
  /** The server's own name for the tool. */
1684
1713
  serverToolName: z.string(),
1685
1714
  /**
1686
- * What the model would call it (R2b C6); absent when the Runtime leaves the tool out (its
1687
- * input schema is not one the Runtime can use).
1715
+ * What the model would call it as Nylorun's engine names MCP tools (R2b C6); absent when the
1716
+ * engine leaves the tool out (its input schema is not one it can use). A harness of your own
1717
+ * names tools itself.
1688
1718
  */
1689
1719
  modelName: z.string().optional(),
1690
1720
  description: z.string().optional(),
@@ -1709,10 +1739,10 @@ export const McpPreviewSchema = z
1709
1739
  credentialSent: z.boolean(),
1710
1740
  /** The server's `initialize` answer: its name, version and title. */
1711
1741
  serverInfo: z.record(z.string(), z.unknown()).optional(),
1712
- /** The server's instructions from `initialize`, cut to 2,000 characters. */
1742
+ /** The server's instructions from `initialize`. */
1713
1743
  instructions: z.string().optional(),
1714
1744
  tools: z.array(McpPreviewToolSchema),
1715
- /** Tools the model knows by another name than `server__tool` (R2b C6). */
1745
+ /** Tools Nylorun's engine names otherwise than `server__tool` (R2b C6). */
1716
1746
  renamed: z.array(z.object({ serverToolName: z.string(), name: z.string() }).strict()),
1717
1747
  authRequired: z
1718
1748
  .object({
@@ -1799,8 +1829,6 @@ const messageBase = {
1799
1829
  /** Optional turn manifest (Loop patch); validated as a variant of the pinned agent. */
1800
1830
  manifest: AgentManifestSchema.optional(),
1801
1831
  };
1802
- /** The most parts one message may carry (protocol 6). */
1803
- export const MAX_MESSAGE_PARTS = 32;
1804
1832
  /**
1805
1833
  * One part of a user message (protocol 6): text, or a file by artifact id. A file part without
1806
1834
  * `version` means the artifact's latest version when the message is accepted; the Runtime pins
@@ -1836,7 +1864,8 @@ export const MessageEventBodySchema = z.union([
1836
1864
  z
1837
1865
  .object({
1838
1866
  ...messageBase,
1839
- parts: z.array(MessagePartSchema).min(1).max(MAX_MESSAGE_PARTS),
1867
+ /** At most the Tenant's Runtime limit `messageParts`, checked when the message is accepted. */
1868
+ parts: z.array(MessagePartSchema).min(1),
1840
1869
  })
1841
1870
  .strict(),
1842
1871
  ]);
@@ -2088,9 +2117,10 @@ export const ModelFailedPayloadSchema = z
2088
2117
  })
2089
2118
  .passthrough();
2090
2119
  /**
2091
- * `context.compacted`: the engine summarized older history to fit the model's window
2092
- * (Model Calls §8). Token counts are estimates. `partial: true`: one summary call of several,
2093
- * in the log for its timing; only the last one (without `partial`) replaced the history.
2120
+ * `context.compacted`: the harness summarized older history to fit the model's window
2121
+ * (Model Calls §8), and said so with the transcript edit that replaced it (`kind: "compaction"`,
2122
+ * protocol 15). Token counts are the harness's estimates; `invocationId` and the model facts are
2123
+ * the last summary call's. Written once per compaction, when the segment's edit is recorded.
2094
2124
  */
2095
2125
  export const ContextCompactedPayloadSchema = z
2096
2126
  .object({
@@ -2098,20 +2128,18 @@ export const ContextCompactedPayloadSchema = z
2098
2128
  trigger: z.enum(["threshold", "overflow"]),
2099
2129
  tokensBefore: z.number().int().nonnegative(),
2100
2130
  tokensAfter: z.number().int().nonnegative(),
2101
- partial: z.literal(true).optional(),
2102
2131
  ...modelOutcomeFacts,
2103
2132
  ...eventAgent,
2104
2133
  })
2105
2134
  .passthrough();
2106
2135
  /** How a tool call ended (R5.1): the tool answered, the Runtime ended it, or a cancel did. */
2107
2136
  export const TOOL_CALL_STATUSES = ["completed", "failed", "cancelled"];
2108
- /** Where a tool call ran (R5.1): a remote MCP server, an HTTP tool, the sandbox, or core. */
2109
2137
  /**
2110
- * Where a tool call runs: an MCP server, an HTTP tool's URL, the session's sandbox, the Runtime
2111
- * itself (`platform`: the artifact, skill and deferred-tool tools), or the harness that runs the
2112
- * turn (`harness`: a tool it declared in `hello.features.tools`).
2138
+ * Where a tool call ran (R5.1), its effect's target kind (protocol 15): an MCP server, an HTTP
2139
+ * tool's URL, the session's sandbox, or the harness that runs the turn (`harness`: a tool it runs
2140
+ * in its own process, such as our engine's skill, artifact and `tool_search` tools).
2113
2141
  */
2114
- export const TOOL_CALL_KINDS = ["mcp", "http", "sandbox", "platform", "harness"];
2142
+ export const TOOL_CALL_KINDS = ["mcp", "http", "sandbox", "harness"];
2115
2143
  /**
2116
2144
  * What the Tenant's tool policy did with a tool call (R5 step 2), when it did more than allow
2117
2145
  * it: `deny` refused it unsent; `ask` held it for a person, who approved it (`approvedBy`, when
@@ -2137,11 +2165,17 @@ export const ToolCompletedPayloadSchema = z
2137
2165
  ...toolIds,
2138
2166
  /** The tool call's effect id (R7.1). */
2139
2167
  effectId: z.string().min(1).optional(),
2168
+ /** The name the model called the tool by, as its harness named it: for display. */
2140
2169
  toolName: z.string().min(1),
2141
2170
  status: z.enum(TOOL_CALL_STATUSES).optional(),
2142
2171
  kind: z.enum(TOOL_CALL_KINDS).optional(),
2143
2172
  /** The MCP server, or the HTTP tool's URL host. */
2144
2173
  server: z.string().min(1).optional(),
2174
+ /**
2175
+ * The tool's identity (protocol 15): an MCP tool's own name on `server`, or the HTTP tool's
2176
+ * declared name. Tool policy and approval key on it.
2177
+ */
2178
+ tool: z.string().min(1).optional(),
2145
2179
  /**
2146
2180
  * The skill the call ran: `load_skill` and `read_skill_resource` name it, and a sandbox tool
2147
2181
  * whose input names its folder, `/skills/<name>@<hash>/`, ran its files.
@@ -2403,9 +2437,10 @@ export const TranscriptUpdatedPayloadSchema = z
2403
2437
  })
2404
2438
  .passthrough();
2405
2439
  /**
2406
- * Where an artifact version's bytes came from: a client's upload, our engine's `save_artifact`,
2407
- * or the turn-end export of a sandbox's outputs (F8.2), whose listing and bytes the harness
2408
- * holding the workspace supplied.
2440
+ * Where an artifact version's bytes came from: a client's upload, a harness over the artifact
2441
+ * seam (our engine's `save_artifact`, its tool results and its outputs folder), an Environment's
2442
+ * disk version (`snapshot`), or core's turn-end export of a sandbox's outputs, which versions
2443
+ * before protocol 15 name (`export`).
2409
2444
  */
2410
2445
  export const ArtifactSourceSchema = z.enum(["upload", "engine", "export", "snapshot"]);
2411
2446
  /**
@@ -2443,12 +2478,17 @@ export const ArtifactVersionPayloadSchema = z
2443
2478
  export const ArtifactDeletedPayloadSchema = z
2444
2479
  .object({ artifactId: z.string(), name: z.string() })
2445
2480
  .passthrough();
2446
- /** Why a turn-end export stored nothing although the sandbox had outputs (F8.2). */
2481
+ /**
2482
+ * Why the turn-end save of a session's outputs folder stored nothing although the sandbox had
2483
+ * outputs: our engine's claim (protocol 15), with the limit it met.
2484
+ */
2447
2485
  export const ArtifactExportSkipReasonSchema = z.enum([
2448
2486
  "too_many_files",
2449
2487
  "file_too_large",
2450
2488
  "too_large",
2451
2489
  "tenant_total",
2490
+ /** Past the session's Environment's own total (its manifest's `limits.artifacts.totalBytes`). */
2491
+ "environment_total",
2452
2492
  ]);
2453
2493
  /**
2454
2494
  * `artifact.export.skipped`: the turn's outputs were past a limit, so no folder version was
@@ -2467,8 +2507,9 @@ export const ArtifactExportSkippedPayloadSchema = z
2467
2507
  })
2468
2508
  .passthrough();
2469
2509
  /**
2470
- * `artifact.export.failed`: the turn-end export could not finish (the sandbox or the Object store
2471
- * failed). The turn itself completed; the next turn exports again.
2510
+ * `artifact.export.failed`: the turn-end save of the outputs folder could not finish (the sandbox
2511
+ * or the artifact seam failed), as our engine claims it. The turn itself completed; the next turn
2512
+ * saves again.
2472
2513
  */
2473
2514
  export const ArtifactExportFailedPayloadSchema = z
2474
2515
  .object({ name: z.string(), message: z.string() })
@@ -2484,13 +2525,8 @@ export const McpServerOutcomeSchema = z
2484
2525
  /** `refused`: the vault has no usable credential for it; `failed`: it could not be reached or listed. */
2485
2526
  outcome: z.enum(["connected", "refused", "failed"]),
2486
2527
  message: z.string(),
2487
- /** The tools it added to the session; 0 unless connected. */
2528
+ /** The tools it added to the session that its `tools` settings leave enabled; 0 unless connected. */
2488
2529
  tools: z.number().int().nonnegative(),
2489
- /**
2490
- * Of those, the tools out of the model's tool list, which it finds with `tool_search` and runs
2491
- * with `tool_call` (R2b C10); absent when none is.
2492
- */
2493
- deferred: z.number().int().positive().optional(),
2494
2530
  /** Listed tools the server's `tools` settings disable (R2b C9); absent when none. */
2495
2531
  disabled: z.number().int().positive().optional(),
2496
2532
  /**
@@ -2500,14 +2536,6 @@ export const McpServerOutcomeSchema = z
2500
2536
  unknownTools: z.array(z.string()).optional(),
2501
2537
  /** The credentials a refusal names. */
2502
2538
  credentialIds: z.array(z.string()).optional(),
2503
- /**
2504
- * Tools the model knows by another name (R2b C6): `server__tool` with characters outside
2505
- * `[A-Za-z0-9_-]` replaced by `_`, and shortened to 64 with a hash, or suffixed with the hash
2506
- * when that collides. The server is still called by `serverToolName`.
2507
- */
2508
- renamed: z
2509
- .array(z.object({ serverToolName: z.string(), name: z.string() }).passthrough())
2510
- .optional(),
2511
2539
  })
2512
2540
  .passthrough();
2513
2541
  /**
@@ -2925,7 +2953,12 @@ export const SUBJECT_SCOPES = [
2925
2953
  * settings moved to the Management API, which no subject reaches.
2926
2954
  */
2927
2955
  const RETIRED_SUBJECT_SCOPES = ["vaults:own", "tenant:settings"];
2928
- /** 1–200 visible ASCII characters; spaces only inside. */
2956
+ /**
2957
+ * 1–200 visible ASCII characters; spaces only inside.
2958
+ * An identifier's grammar is the protocol's (B15): it crosses the Runtime API, tokens and grants
2959
+ * and means the same in every installation, so its length is a constant of protocol 15, not a
2960
+ * setting.
2961
+ */
2929
2962
  const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
2930
2963
  /**
2931
2964
  * The owner of a session opened for no person: an MCP server's or HTTP tool's identity header
@@ -2982,13 +3015,6 @@ export const TOKEN_SCOPES = [
2982
3015
  "sessions:own",
2983
3016
  "environments:write",
2984
3017
  ];
2985
- /** The most Environment grants one token caller carries. */
2986
- export const TOKEN_ENVIRONMENT_GRANTS_MAX = 16;
2987
- /**
2988
- * The longest a token the Runtime signs itself lives, in seconds (capability links): rotating
2989
- * signing keys revokes the previous key once the longest token it may have signed has expired.
2990
- */
2991
- export const TOKEN_TTL_MAX_SECONDS = 900;
2992
3018
  /**
2993
3019
  * The `iss` of every token a Tenant's Runtime signs itself: capability links, run, host and
2994
3020
  * egress tokens.
@@ -3155,10 +3181,9 @@ export const SessionViewSchema = z
3155
3181
  ownerUserId: z.string(),
3156
3182
  manifestHash: z.string(),
3157
3183
  /**
3158
- * The hash of the definition the session was opened from (R2b C11). `manifestHash` differs
3159
- * from it when the Runtime pinned its `runtime` block on the definition: a sandbox's tools,
3160
- * the artifact tools and the skill tools. Compare this one with the registered
3161
- * definition's hash. Absent for a session opened before this release.
3184
+ * The hash of the definition the session was opened from (R2b C11). Since protocol 15 the
3185
+ * session pins its definition as registered, so it equals `manifestHash`. Absent for a
3186
+ * session opened before R2b C11.
3162
3187
  */
3163
3188
  definitionHash: z.string().optional(),
3164
3189
  implementationVersion: z.string(),
@@ -3383,7 +3408,8 @@ export const ModelBudgetSchema = z
3383
3408
  export const PutModelBudgetsRequestSchema = z
3384
3409
  .object({
3385
3410
  requestId: RequestIdSchema.optional(),
3386
- budgets: z.array(ModelBudgetSchema).max(100),
3411
+ /** At most the Tenant's Runtime limit `modelBudgets`, checked when they are put. */
3412
+ budgets: z.array(ModelBudgetSchema),
3387
3413
  })
3388
3414
  .strict()
3389
3415
  .superRefine((request, ctx) => {
@@ -3407,8 +3433,11 @@ export const ToolInputConditionSchema = z
3407
3433
  gte: z.number().optional(),
3408
3434
  lt: z.number().optional(),
3409
3435
  lte: z.number().optional(),
3410
- /** A regular expression the field's string value must match. */
3411
- matches: z.string().min(1).max(500).optional(),
3436
+ /**
3437
+ * A regular expression the field's string value must match: at most the Tenant's Runtime
3438
+ * limit `toolRuleTextChars`, checked when the policy is put.
3439
+ */
3440
+ matches: z.string().min(1).optional(),
3412
3441
  })
3413
3442
  .strict()
3414
3443
  .superRefine((condition, ctx) => {
@@ -3425,27 +3454,45 @@ export const ToolInputConditionSchema = z
3425
3454
  /**
3426
3455
  * One rule of the Tenant's tool policy (R5 step 2), applied at the Tool Gate to every MCP and
3427
3456
  * HTTP tool call of every harness. A rule matches a call when every selector it sets matches:
3428
- * `tool` (the name the model calls it by, `*` for any run of characters), `server` (an MCP
3457
+ * `tool` (the tool's identity: an MCP tool's own name on its server, or an HTTP tool's declared
3458
+ * name; never the name a harness gave the model; `*` for any run of characters), `server` (an MCP
3429
3459
  * server's name), `kind`, `agent` (the agent that calls it) and `when` (fields of the input, by
3430
3460
  * dotted path). The strictest matching rule decides: `deny` refuses the call before it is sent,
3431
3461
  * `ask` holds it until a person approves it on the session (`approve`), `allow` runs it. A call no
3432
3462
  * rule matches runs. Sandbox tools never cross the gate; their network side is egress policy.
3463
+ *
3464
+ * A `tool` with `__` in it is refused (protocol 15): no declared tool's name has one, so it can
3465
+ * only be an MCP tool's model-facing `server__tool` name. Name an MCP tool by `server` and `tool`.
3433
3466
  */
3434
3467
  export const ToolRuleSchema = z
3435
3468
  .object({
3436
3469
  effect: z.enum(TOOL_POLICY_EFFECTS),
3437
- tool: z.string().min(1).max(200).optional(),
3438
- server: z.string().min(1).max(200).optional(),
3470
+ // The selectors, and `when`'s paths, are at most the Tenant's Runtime limit
3471
+ // `toolRuleFieldChars` long; `reason` at most `toolRuleTextChars` (checked when put).
3472
+ tool: z.string().min(1).optional(),
3473
+ server: z.string().min(1).optional(),
3439
3474
  kind: z.enum(["mcp", "http"]).optional(),
3440
- agent: z.string().min(1).max(200).optional(),
3441
- when: z.record(z.string().min(1).max(200), ToolInputConditionSchema).optional(),
3475
+ agent: z.string().min(1).optional(),
3476
+ when: z.record(z.string().min(1), ToolInputConditionSchema).optional(),
3442
3477
  /** Why the rule exists: shown with a held or denied call. */
3443
- reason: z.string().min(1).max(500).optional(),
3478
+ reason: z.string().min(1).optional(),
3444
3479
  })
3445
- .strict();
3480
+ .strict()
3481
+ .superRefine((rule, ctx) => {
3482
+ if (rule.tool !== undefined && rule.tool.includes("__"))
3483
+ ctx.addIssue({
3484
+ code: "custom",
3485
+ path: ["tool"],
3486
+ message: `Name an MCP tool by \`server\` and \`tool\` (its own name on the server), not by a model-facing name such as '${rule.tool}'`,
3487
+ });
3488
+ });
3446
3489
  /** `PUT /v1/tenant/tool-policy`: replaces every rule. An empty list allows every call. */
3447
3490
  export const PutToolPolicyRequestSchema = z
3448
- .object({ requestId: RequestIdSchema.optional(), rules: z.array(ToolRuleSchema).max(200) })
3491
+ .object({
3492
+ requestId: RequestIdSchema.optional(),
3493
+ /** At most the Tenant's Runtime limit `toolRules`, checked when they are put. */
3494
+ rules: z.array(ToolRuleSchema),
3495
+ })
3449
3496
  .strict();
3450
3497
  /** The Tenant's tool policy; `updatedAt` is null until one is set. */
3451
3498
  export const ToolPolicySchema = z
@@ -3470,7 +3517,12 @@ export const AgUiRunErrorCodeSchema = z.enum([
3470
3517
  "runtime_error",
3471
3518
  ]);
3472
3519
  // --- Studio embedding (Studio design §8) ---------------------------------------------------
3473
- /** A Tenant id as Studio's routes accept it. */
3520
+ /**
3521
+ * A Tenant id as Studio's routes accept it.
3522
+ * An identifier's grammar is the protocol's (B15): it crosses the Runtime API, tokens and grants
3523
+ * and means the same in every installation, so its length is a constant of protocol 15, not a
3524
+ * setting.
3525
+ */
3474
3526
  const STUDIO_TENANT_ID = /^[A-Za-z0-9_-]{1,128}$/;
3475
3527
  /** `POST /_studio/login-tokens` body. No `tenant` mints a Host-wide token (the CLI's `{}`). */
3476
3528
  export const StudioLoginTokenRequestSchema = z
@@ -3513,7 +3565,6 @@ export const StudioThemeSchema = z.object({
3513
3565
  });
3514
3566
  const EMBED_ROUTE = z
3515
3567
  .string()
3516
- .max(2048)
3517
3568
  .regex(/^\/tenants\/[^/?#\s]+(?:\/[^?#\s]*)?$/, "must be a Studio route under /tenants/");
3518
3569
  const EXTERNAL_URL = z.string().refine((value) => {
3519
3570
  try {
@@ -3595,20 +3646,31 @@ export function parseFrameAncestors(value) {
3595
3646
  // --- File artifacts (protocol 6, blueprint D35, F8.1) ----------------------------------------
3596
3647
  /** The JWT `typ` of a capability link's token (RFC 8725 explicit typing). */
3597
3648
  export const ARTIFACT_LINK_TOKEN_TYPE = "nylorun-artifact+jwt";
3598
- /** A capability link lives no longer than any token the Runtime signs (`TOKEN_TTL_MAX_SECONDS`). */
3599
- export const ARTIFACT_LINK_MAX_TTL_SECONDS = TOKEN_TTL_MAX_SECONDS;
3649
+ /**
3650
+ * How long a capability link lives when its request names no `expiresIn`: the request field's
3651
+ * default. A link lives no longer than any token the Runtime signs (the Host tuning's
3652
+ * `keys.tokenTtlMaxSeconds`, 900 s by default); a longer ask gets that.
3653
+ */
3600
3654
  export const ARTIFACT_LINK_DEFAULT_TTL_SECONDS = 300;
3601
3655
  /** A Tenant's limits when it sets none: 100 MiB per file, 10 GiB in all. */
3602
3656
  export const ARTIFACT_FILE_BYTES_DEFAULT = 100 * 1024 * 1024;
3603
3657
  export const ARTIFACT_TOTAL_BYTES_DEFAULT = 10 * 1024 * 1024 * 1024;
3604
- /** The longest artifact name, in characters. */
3605
- export const ARTIFACT_NAME_MAX = 255;
3606
- /** The longest path of a file in a folder artifact, in characters. */
3607
- export const ARTIFACT_PATH_MAX = 1024;
3608
- /** Labels: up to 32, keys 1–63 characters, values up to 256. */
3609
- export const ArtifactLabelsSchema = z
3610
- .record(z.string().min(1).max(63), z.string().max(256))
3611
- .refine((labels) => Object.keys(labels).length <= 32, { message: "At most 32 labels" });
3658
+ /**
3659
+ * The longest artifact name, in characters: the longest file name a workspace's file system takes
3660
+ * (`NAME_MAX`), since a name becomes one when the artifact is copied into a sandbox or downloaded.
3661
+ * A standard's constant, not a limit (B15).
3662
+ */
3663
+ export const ARTIFACT_NAME_MAX = FILE_NAME_MAX;
3664
+ /**
3665
+ * The longest path of a file in a folder artifact, in characters: the longest path a workspace's
3666
+ * file system takes (`PATH_MAX`), since the folder is unpacked there. A standard's constant.
3667
+ */
3668
+ export const ARTIFACT_PATH_MAX = FILE_PATH_MAX;
3669
+ /**
3670
+ * An artifact's labels. How many, and how long a key and a value may be, are the Tenant's Runtime
3671
+ * limits `artifactLabels`, `labelKeyChars` and `labelValueChars`, checked when they are set.
3672
+ */
3673
+ export const ArtifactLabelsSchema = z.record(z.string().min(1), z.string());
3612
3674
  /**
3613
3675
  * One version of an artifact: immutable once it exists. A folder version's `size` is the sum of
3614
3676
  * its files' sizes and its `sha256` is its manifest's.
@@ -3667,7 +3729,7 @@ export const UploadArtifactResponseSchema = z
3667
3729
  export const DefinitionFileViewSchema = z
3668
3730
  .object({
3669
3731
  sha256: z.string().regex(/^sha256:[0-9a-f]{64}$/),
3670
- size: z.number().int().nonnegative().max(DEFINITION_FILE_MAX_BYTES),
3732
+ size: z.number().int().nonnegative(),
3671
3733
  })
3672
3734
  .strict();
3673
3735
  export const DeleteArtifactResponseSchema = z
@@ -3679,8 +3741,8 @@ export const CreateArtifactLinkRequestSchema = z
3679
3741
  requestId: RequestIdSchema.optional(),
3680
3742
  /** The version to open. Default: the latest. */
3681
3743
  version: z.number().int().positive().optional(),
3682
- /** Seconds until the link stops working. Default 300, at most 900. */
3683
- expiresIn: z.number().int().min(1).max(ARTIFACT_LINK_MAX_TTL_SECONDS).optional(),
3744
+ /** Seconds until the link stops working. Default 300; a link lives at most the Host's `keys.tokenTtlMaxSeconds` (900 s by default). */
3745
+ expiresIn: z.number().int().min(1).optional(),
3684
3746
  /**
3685
3747
  * A folder's file, by its path in the folder: the link opens that one file. Without it, a
3686
3748
  * folder's link opens its zip.
@@ -3710,12 +3772,8 @@ export const FOLDER_MANIFEST_FORMAT = "nylorun.folder.v1";
3710
3772
  * modes and modification times, symbolic links and empty directories. Readers accept both.
3711
3773
  */
3712
3774
  export const FOLDER_MANIFEST_FORMAT_V2 = "nylorun.folder.v2";
3713
- /** The folder artifact a session's turn-end export writes, one per session. */
3775
+ /** The folder artifact our engine saves a session's outputs to at each turn's end, one per session. */
3714
3776
  export const OUTPUTS_ARTIFACT_NAME = "outputs";
3715
- /** The most files one turn-end export stores; past it the export is skipped. */
3716
- export const EXPORT_MAX_FILES = 10_000;
3717
- /** The most bytes one turn-end export stores (before dedupe); past it the export is skipped. */
3718
- export const EXPORT_MAX_BYTES = 1024 * 1024 * 1024;
3719
3777
  /**
3720
3778
  * One file of a folder: its path in the folder (`/`-separated, relative), size, hash and type.
3721
3779
  * In a v2 manifest an entry may also be a symbolic link (`type: "link"`, its `target`) or an
@@ -3735,7 +3793,7 @@ export const FolderEntrySchema = z
3735
3793
  /** v2: the modification time, ms since the epoch. */
3736
3794
  mtimeMs: z.number().nonnegative().optional(),
3737
3795
  /** v2: a link's target, as stored on the disk. */
3738
- target: z.string().max(4096).optional(),
3796
+ target: z.string().max(LINK_TARGET_MAX).optional(),
3739
3797
  })
3740
3798
  .strict();
3741
3799
  /**
@@ -3800,6 +3858,43 @@ export const TenantArtifactsViewSchema = z
3800
3858
  usedBytes: z.number().int().nonnegative(),
3801
3859
  })
3802
3860
  .strict();
3861
+ /**
3862
+ * A Tenant's skill limits, stored as Tenant setting `skills.config`: the most bytes one skill's
3863
+ * files may hold together. Unset, it is `SKILL_TOTAL_BYTES_DEFAULT` (2 GiB).
3864
+ */
3865
+ export const TenantSkillsConfigSchema = z
3866
+ .object({
3867
+ limits: z
3868
+ .object({
3869
+ /** The most bytes one skill's files may hold together. Default 2 GiB. */
3870
+ totalBytes: z.number().int().positive().optional(),
3871
+ })
3872
+ .strict()
3873
+ .optional(),
3874
+ })
3875
+ .strict();
3876
+ /** `PUT /v1/tenant/skills`: replaces the Tenant's skill configuration. */
3877
+ export const PutTenantSkillsRequestSchema = TenantSkillsConfigSchema.extend({
3878
+ requestId: RequestIdSchema.optional(),
3879
+ }).strict();
3880
+ export const TenantSkillsViewSchema = z
3881
+ .object({ limits: z.object({ totalBytes: z.number().int() }).strict() })
3882
+ .strict();
3883
+ /**
3884
+ * A Tenant's Runtime limits (harness boundary S0), stored as Tenant setting `limits.config`: what
3885
+ * one record entry, model call, model file, tool answer, harness state and Harness API chunk may
3886
+ * hold. Each limit left out is its default (`RUNTIME_LIMIT_DEFAULTS`); none may pass its ceiling
3887
+ * (`RUNTIME_LIMIT_CEILINGS`, a `400` naming it).
3888
+ */
3889
+ export const TenantLimitsConfigSchema = z
3890
+ .object({ limits: RuntimeLimitsSchema.partial().strict().optional() })
3891
+ .strict();
3892
+ /** `PUT /v1/tenant/limits`: replaces the Tenant's Runtime limits. */
3893
+ export const PutTenantLimitsRequestSchema = TenantLimitsConfigSchema.extend({
3894
+ requestId: RequestIdSchema.optional(),
3895
+ }).strict();
3896
+ /** The Runtime limits in force: the Tenant's, with the default for each it leaves out. */
3897
+ export const TenantLimitsViewSchema = z.object({ limits: RuntimeLimitsSchema }).strict();
3803
3898
  /** Opt-in session reads (Host feature `session-reads`). */
3804
3899
  export const SessionListItemSchema = SessionSummarySchema.extend({
3805
3900
  lastTurnId: z.string().nullable(),
@@ -3889,9 +3984,12 @@ export const ToolCallSchema = z
3889
3984
  effectId: z.string(),
3890
3985
  turnId: z.string(),
3891
3986
  callId: z.string().nullable(),
3987
+ /** The name the model called it by: for display. */
3892
3988
  toolName: z.string().nullable(),
3893
3989
  kind: z.enum(TOOL_CALL_KINDS).nullable(),
3894
3990
  server: z.string().nullable(),
3991
+ /** Its identity (see `tool.completed`): an MCP tool's name on `server`, an HTTP tool's declared name. */
3992
+ tool: z.string().nullable(),
3895
3993
  /** The skill the call ran (see `tool.completed`). */
3896
3994
  skill: z.string().nullable(),
3897
3995
  /** The Agent Plugin that brought its MCP server or skill. */