@nylorun/core 0.21.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 (74) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/README.md +1 -1
  3. package/dist/compatibility.d.ts +37 -20
  4. package/dist/compatibility.js +38 -21
  5. package/dist/contracts.d.ts +531 -88
  6. package/dist/contracts.js +315 -204
  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 +54 -8
  17. package/dist/definition/http-tool.js +175 -10
  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/manifest-schemas.js +14 -2
  48. package/dist/schemas/agent-manifest.schema.json +14 -147
  49. package/dist/schemas/environment-manifest.schema.json +76 -16
  50. package/dist/types/manifest.d.ts +17 -18
  51. package/dist/types/model.d.ts +10 -5
  52. package/dist/utils/definition-files.d.ts +20 -6
  53. package/dist/utils/definition-files.js +31 -17
  54. package/dist/utils/file-systems.d.ts +20 -0
  55. package/dist/utils/file-systems.js +20 -0
  56. package/dist/utils/harness-id.d.ts +4 -1
  57. package/dist/utils/harness-id.js +4 -1
  58. package/dist/utils/media-types.d.ts +30 -0
  59. package/dist/utils/media-types.js +128 -0
  60. package/dist/utils/runtime-limits.d.ts +229 -0
  61. package/dist/utils/runtime-limits.js +482 -0
  62. package/dist/utils/runtime-tools.d.ts +8 -16
  63. package/dist/utils/runtime-tools.js +8 -27
  64. package/dist/utils/sandbox.d.ts +4 -1
  65. package/dist/utils/sandbox.js +4 -1
  66. package/package.json +1 -1
  67. package/dist/definition/deferred-tools.d.ts +0 -27
  68. package/dist/definition/deferred-tools.js +0 -82
  69. package/dist/definition/runtime-manifest.d.ts +0 -30
  70. package/dist/definition/runtime-manifest.js +0 -132
  71. package/dist/definition/sandbox-tools.d.ts +0 -5
  72. package/dist/definition/sandbox-tools.js +0 -109
  73. package/dist/definition/skill-tools.d.ts +0 -23
  74. 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, httpUrlIssue, } 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, {
@@ -143,13 +149,13 @@ const sandboxManifestSchema = z
143
149
  const httpToolTargetSchema = z
144
150
  .object({
145
151
  url: z.string().superRefine((url, ctx) => {
146
- const issue = httpUrlIssue(url);
152
+ const issue = httpUrlIssue(url) ?? httpUrlTemplateIssue(url);
147
153
  if (issue)
148
154
  ctx.addIssue({ code: "custom", message: issue });
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. */
@@ -188,6 +194,9 @@ const toolManifestSchema = z
188
194
  path: ["approval"],
189
195
  message: `Tool '${tool.name}' takes approval only as an HTTP tool`,
190
196
  });
197
+ const parameters = tool.http && httpInputIssue(tool.http, tool.inputSchema);
198
+ if (parameters)
199
+ ctx.addIssue({ code: "custom", path: ["http", "url"], message: `Tool '${tool.name}': ${parameters}` });
191
200
  });
192
201
  /** A manifest naming a removed field is refused with what replaces it. */
193
202
  const removedFieldError = (removedFields) => (issue) => {
@@ -196,14 +205,12 @@ const removedFieldError = (removedFields) => (issue) => {
196
205
  const removed = issue.keys?.find((key) => removedFields[key] !== undefined);
197
206
  return removed === undefined ? undefined : removedFields[removed];
198
207
  };
199
- /** What the Runtime adds to a session's agent; only the Runtime writes it. */
200
- const runtimeManifestSchema = z
201
- .object({
202
- sandbox: sandboxManifestSchema.optional(),
203
- tools: z.array(toolManifestSchema).optional(),
204
- instructions: z.array(z.string()).optional(),
205
- })
206
- .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_]*$/;
207
214
  /**
208
215
  * What an agent needs of the Environment its session opens on (protocol 14, D65), checked when a
209
216
  * session opens (`409 environment_unsuitable`). `sandbox`: `any` needs kind `virtual` or `pod`,
@@ -213,7 +220,8 @@ const runtimeManifestSchema = z
213
220
  const agentRequirementsSchema = z
214
221
  .object({
215
222
  sandbox: z.enum(["none", "any", "pod"]).optional(),
216
- 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(),
217
225
  })
218
226
  .strict();
219
227
  const agentManifestSchema = z
@@ -231,7 +239,6 @@ const agentManifestSchema = z
231
239
  skills: z.record(z.string(), skillManifestSchema).optional(),
232
240
  mcpServers: z.record(z.string(), mcpServerSchema).optional(),
233
241
  requires: agentRequirementsSchema.optional(),
234
- runtime: runtimeManifestSchema.optional(),
235
242
  // Reserved for Functions, which are deferred: developer code the Runtime will run from
236
243
  // uploaded definition files (a `functions/` folder). Any value is refused below.
237
244
  functions: z.unknown().optional().meta({ description: "Reserved: Functions are not available yet" }),
@@ -242,37 +249,17 @@ const agentManifestSchema = z
242
249
  delegationIssues(manifest, (message) => ctx.addIssue({ code: "custom", message }));
243
250
  const names = new Set();
244
251
  for (const tool of manifest.tools ?? []) {
245
- if (RUNTIME_TOOL_NAMES.has(tool.name))
246
- ctx.addIssue({
247
- code: "custom",
248
- message: `Tool '${tool.name}' takes the name of a tool the Runtime serves; rename it`,
249
- });
250
252
  if (tool.name.includes("__"))
251
253
  ctx.addIssue({
252
254
  code: "custom",
253
255
  message: `Tool '${tool.name}' must not contain '__', which names an MCP server's tools`,
254
256
  });
255
257
  }
256
- for (const tool of [...(manifest.tools ?? []), ...(manifest.runtime?.tools ?? [])]) {
258
+ for (const tool of manifest.tools ?? []) {
257
259
  if (names.has(tool.name))
258
260
  ctx.addIssue({ code: "custom", message: "Tool names must be unique" });
259
261
  names.add(tool.name);
260
262
  }
261
- for (const tool of manifest.runtime?.tools ?? [])
262
- if (!RUNTIME_TOOL_NAMES.has(tool.name))
263
- ctx.addIssue({
264
- code: "custom",
265
- message: `runtime.tools holds only the tools the Runtime serves, not '${tool.name}'`,
266
- });
267
- if (manifest.runtime?.sandbox !== undefined) {
268
- const pinned = new Set((manifest.runtime.tools ?? []).map((tool) => tool.name));
269
- for (const name of SANDBOX_TOOL_NAMES)
270
- if (!pinned.has(name))
271
- ctx.addIssue({
272
- code: "custom",
273
- message: `runtime.sandbox comes with the sandbox tools; runtime.tools has no '${name}'`,
274
- });
275
- }
276
263
  if (manifest.skills && Object.keys(manifest.skills).length === 0)
277
264
  ctx.addIssue({ code: "custom", message: "skills must be omitted when the agent has no skills" });
278
265
  for (const [key, skill] of Object.entries(manifest.skills ?? {}))
@@ -289,14 +276,8 @@ const agentManifestSchema = z
289
276
  * (`ManifestDrift`): the hand-written type keeps its read-only fields and its docs.
290
277
  */
291
278
  export const AgentManifestSchema = agentManifestSchema;
292
- /** Agents used as tools: one level deep, `{ task }` input, one shared sandbox spec. */
279
+ /** Agents used as tools: one level deep, `{ task }` input. */
293
280
  function delegationIssues(manifest, issue) {
294
- const sandboxes = new Set();
295
- const addSandbox = (agent) => {
296
- if (agent.runtime?.sandbox)
297
- sandboxes.add(canonical(agent.runtime.sandbox));
298
- };
299
- addSandbox(manifest);
300
281
  for (const tool of manifest.tools ?? []) {
301
282
  const child = tool.agent;
302
283
  if (!child)
@@ -309,18 +290,12 @@ function delegationIssues(manifest, issue) {
309
290
  issue(`Agent tool '${tool.name}' must take the standard { task } input`);
310
291
  if (tool.outputSchema !== undefined)
311
292
  issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
312
- if ("kind" in child) {
313
- // A flow agent runs in its own linked session; its leaves may delegate in turn.
314
- if (child.sandbox !== undefined && Object.keys(child.sandbox).length > 0)
315
- 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)
316
295
  continue;
317
- }
318
296
  if (child.tools?.some((item) => item.agent !== undefined))
319
297
  issue(`'${child.id}' delegates to another agent; nested delegation is not supported yet`);
320
- addSandbox(child);
321
298
  }
322
- if (sandboxes.size > 1)
323
- issue("An agent and the agents it uses as tools must declare identical sandboxes");
324
299
  }
325
300
  // Workflow manifest v3 (flow agents): `id` on any node, embedded agents, no functions.
326
301
  const workflowNodeOptions = { id: z.string().min(1).optional() };
@@ -350,6 +325,9 @@ const workflowLoopVerifySchema = z
350
325
  });
351
326
  else if (verify.http !== undefined && verify.id !== undefined)
352
327
  ctx.addIssue({ code: "custom", path: ["id"], message: "An HTTP verifier takes no id" });
328
+ const verifier = verify.http && httpVerifierIssue(verify.http);
329
+ if (verifier)
330
+ ctx.addIssue({ code: "custom", path: ["http"], message: verifier });
353
331
  })
354
332
  .meta({ id: "WorkflowLoopVerify" }); // the refinement picks one kind
355
333
  const workflowNodeKinds = z.lazy(() => z.union([
@@ -365,7 +343,12 @@ const workflowNodeKinds = z.lazy(() => z.union([
365
343
  /** An HTTP stage: the Runtime makes the request, as for an agent's HTTP tool. */
366
344
  http: httpToolTargetSchema.optional(),
367
345
  })
368
- .strict(),
346
+ .strict()
347
+ .superRefine((tool, ctx) => {
348
+ const parameters = tool.http && httpInputIssue(tool.http, tool.inputSchema);
349
+ if (parameters)
350
+ ctx.addIssue({ code: "custom", path: ["http", "url"], message: `Tool '${tool.name}': ${parameters}` });
351
+ }),
369
352
  ...workflowNodeOptions,
370
353
  })
371
354
  .strict(),
@@ -495,7 +478,8 @@ const durationSchema = (name) => z.string().refine((value) => parseSandboxDurati
495
478
  });
496
479
  const resourcesSchema = z
497
480
  .object({
498
- 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(),
499
483
  memory: z
500
484
  .string()
501
485
  .refine((value) => parseSandboxSize(value) !== undefined, {
@@ -511,6 +495,11 @@ const resourcesSchema = z
511
495
  * hierarchical so a grant can name a family of them (`users/alice/*`).
512
496
  */
513
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
+ */
514
503
  export const ENVIRONMENT_ID_MAX_LENGTH = 200;
515
504
  export function isEnvironmentId(value) {
516
505
  return (typeof value === "string" &&
@@ -553,19 +542,18 @@ export const EnvironmentGrantSchema = z.string().refine(isEnvironmentGrant, {
553
542
  * compute, only the vault, for agents whose tools are remote MCP servers and HTTP tools.
554
543
  */
555
544
  export const ENVIRONMENT_KINDS = ["virtual", "pod", "none"];
556
- const LABEL_KEY_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._/-]{0,61}[A-Za-z0-9])?$/;
557
- const LABEL_VALUE_PATTERN = /^[\x20-\x7e]{0,256}$/;
558
- export const ENVIRONMENT_LABELS_MAX = 32;
559
- /** The developer's own key-value pairs; the Runtime stores and filters them, never reads them. */
560
- export const EnvironmentLabelsSchema = z
561
- .record(z.string().regex(LABEL_KEY_PATTERN, {
562
- 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",
563
554
  }), z.string().regex(LABEL_VALUE_PATTERN, {
564
- message: "Label values are up to 256 printable ASCII characters",
565
- }))
566
- .refine((labels) => Object.keys(labels).length <= ENVIRONMENT_LABELS_MAX, {
567
- message: `At most ${ENVIRONMENT_LABELS_MAX} labels`,
568
- });
555
+ message: "Label values are printable ASCII characters",
556
+ }));
569
557
  /** A harness id (track R4): what a harness names itself in `hello`. */
570
558
  export const HarnessIdSchema = z.string().regex(HARNESS_ID_PATTERN, {
571
559
  message: "harness must be a harness id: lowercase letters, digits and dashes, starting with a letter",
@@ -582,14 +570,15 @@ export const EnvironmentLifecycleSchema = z
582
570
  deleteAfter: durationSchema("lifecycle.deleteAfter").optional(),
583
571
  })
584
572
  .strict();
585
- /** The most setup commands and input files an Environment's recipe holds (step 2). */
586
- export const ENVIRONMENT_SETUP_MAX = 16;
587
- /** A setup command's longest timeout (default 10m). */
588
- 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";
589
578
  const absoluteWorkspacePath = (name) => z
590
579
  .string()
591
580
  .min(1)
592
- .max(1024)
581
+ .max(FILE_PATH_MAX)
593
582
  .refine((value) => (value === "/workspace" || value.startsWith("/workspace/")) &&
594
583
  !value.split("/").some((segment) => segment === ".." || segment === "."), { message: `${name} must be /workspace or a path under it, without . or .. segments` });
595
584
  /**
@@ -599,15 +588,12 @@ const absoluteWorkspacePath = (name) => z
599
588
  */
600
589
  export const EnvironmentSetupCommandSchema = z
601
590
  .object({
602
- 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),
603
593
  /** Where it runs. Default `/workspace`. */
604
594
  cwd: absoluteWorkspacePath("cwd").optional(),
605
- /** Default 10m, at most 30m. */
606
- timeout: durationSchema("timeout")
607
- .refine((value) => (parseSandboxDuration(value) ?? 0) <= ENVIRONMENT_SETUP_TIMEOUT_MAX_MS, {
608
- message: "timeout is at most 30m",
609
- })
610
- .optional(),
595
+ /** Default 10m (`ENVIRONMENT_SETUP_TIMEOUT_DEFAULT`), at most the Tenant's `setupCommandMs`. */
596
+ timeout: durationSchema("timeout").optional(),
611
597
  })
612
598
  .strict();
613
599
  /**
@@ -615,18 +601,16 @@ export const EnvironmentSetupCommandSchema = z
615
601
  * is made or reset, before the setup commands. A file artifact is written at `path`; a folder
616
602
  * artifact is unpacked under it.
617
603
  */
618
- /** The most files one `files` entry by hash names (Q6). */
619
- export const ENVIRONMENT_FILES_MAX = 1000;
620
604
  /** A file's path inside a `files` entry by hash: relative, `/`-separated, without `.` or `..`. */
621
605
  const relativeFilePath = z
622
606
  .string()
623
607
  .min(1)
624
- .max(1024)
608
+ .max(FILE_PATH_MAX)
625
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" });
626
610
  /**
627
611
  * One input file entry (pods only): an artifact version copied to `path` (a file artifact, or a
628
612
  * folder's files under it), or (Q6) files by content hash, each `sha256:<hex>` of a definition
629
- * 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`
630
614
  * at its relative path. A manifest by hash moves to another Tenant with its files.
631
615
  */
632
616
  export const EnvironmentFileSchema = z.union([
@@ -642,15 +626,17 @@ export const EnvironmentFileSchema = z.union([
642
626
  path: absoluteWorkspacePath("path"),
643
627
  files: z
644
628
  .record(relativeFilePath, z.string().refine(isDefinitionFileHash, { message: "each file is sha256:<64 lowercase hex>" }))
645
- .refine((files) => Object.keys(files).length >= 1 && Object.keys(files).length <= ENVIRONMENT_FILES_MAX, {
646
- message: `files names 1 to ${ENVIRONMENT_FILES_MAX} files`,
647
- }),
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" }),
648
631
  })
649
632
  .strict(),
650
633
  ]);
651
634
  /**
652
635
  * An environment manifest's name (protocol 14, D63): 1–64 letters, digits, `.`, `_` and `-`,
653
- * 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.
654
640
  */
655
641
  const ENVIRONMENT_MANIFEST_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
656
642
  export function isEnvironmentManifestName(value) {
@@ -682,6 +668,42 @@ export const EnvironmentManifestRefSchema = z
682
668
  message: "manifest is an environment manifest's name, or name@version such as analyst-box@3",
683
669
  })
684
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();
685
707
  /**
686
708
  * `PUT /v1/environments/{environmentId}`: creates the Environment and its vault, or finds the
687
709
  * one with this id, so "get or create" is one call. An Environment is made from one version of an
@@ -721,9 +743,11 @@ export const PutEnvironmentRequestSchema = z
721
743
  /**
722
744
  * The harness that runs the Environment's sessions (track R4): `nylorun` (ours, the default)
723
745
  * or the id of a custom harness. A pod Environment whose harness is not ours runs its
724
- * `image` as the harness: the image's own entrypoint, with nothing copied in. Each session
725
- * pins the harness when it opens; a session whose Environment's harness changed later fails
726
- * its next turn with `harness_mismatch`.
746
+ * `image` as the harness: the image's own entrypoint, with nothing copied in. It is fixed
747
+ * for the Environment's life (protocol 14): to run another harness, fork onto a manifest
748
+ * version that names it. Each session pins the harness when it opens; a session whose
749
+ * Environment id was deleted and made again with another harness fails its next turn with
750
+ * `harness_mismatch`.
727
751
  */
728
752
  harness: HarnessIdSchema.optional(),
729
753
  /**
@@ -736,9 +760,14 @@ export const PutEnvironmentRequestSchema = z
736
760
  * Pods only (Host feature `environment-setup`): commands run when the disk is made or reset,
737
761
  * before any turn. A change applies at the next reset.
738
762
  */
739
- setup: z.array(EnvironmentSetupCommandSchema).max(ENVIRONMENT_SETUP_MAX).optional(),
763
+ setup: z.array(EnvironmentSetupCommandSchema).optional(),
740
764
  /** Pods only: artifact versions copied in when the disk is made or reset, before `setup`. */
741
- 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(),
742
771
  /**
743
772
  * The secrets an Environment of this kind needs, by name (D64): each slot's type, binding,
744
773
  * whether it is required and a description, never a value. With slots declared, a secret
@@ -772,6 +801,8 @@ export const EnvironmentRecipeSchema = z
772
801
  lifecycle: EnvironmentLifecycleSchema,
773
802
  setup: z.array(EnvironmentSetupCommandSchema).optional(),
774
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(),
775
806
  secrets: z.lazy(() => EnvironmentSecretSlotsSchema).optional(),
776
807
  })
777
808
  .strict();
@@ -828,6 +859,14 @@ export const EnvironmentViewSchema = z
828
859
  manifestVersion: z.number().int().positive().optional(),
829
860
  /** The hash of what it runs (`manifest`). */
830
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(),
831
870
  /**
832
871
  * The Environment it was forked from (`POST .../fork`, Q15), and the disk version it started
833
872
  * from (`null` for an empty disk).
@@ -1096,19 +1135,15 @@ export const TenantEnvironmentsConfigSchema = z
1096
1135
  /** Stop compute after this long without use; an Environment's `lifecycle.idle` is at most this. */
1097
1136
  idle: durationSchema("limits.idle").optional(),
1098
1137
  /** The most Environments the Tenant may hold. Default 100. */
1099
- environments: z.number().int().min(0).max(100_000).optional(),
1138
+ environments: z.number().int().min(0).optional(),
1100
1139
  })
1101
1140
  .strict()
1102
1141
  .optional(),
1103
1142
  /** Pods: how long a pod has to stop. Read at every timer. */
1104
1143
  lifecycle: z
1105
1144
  .object({
1106
- /** The pod's grace period to stop, at most 30s. Default 10s. */
1107
- stopGrace: durationSchema("lifecycle.stopGrace")
1108
- .refine((value) => (parseSandboxDuration(value) ?? 0) <= 30_000, {
1109
- message: "lifecycle.stopGrace is at most 30s",
1110
- })
1111
- .optional(),
1145
+ /** The pod's grace period to stop (its `terminationGracePeriodSeconds`). Default 10s. */
1146
+ stopGrace: durationSchema("lifecycle.stopGrace").optional(),
1112
1147
  })
1113
1148
  .strict()
1114
1149
  .optional(),
@@ -1189,12 +1224,6 @@ const credentialRoutingChange = {
1189
1224
  via: CredentialViaSchema.nullable().optional(),
1190
1225
  identity: CredentialIdentitySchema.nullable().optional(),
1191
1226
  };
1192
- /**
1193
- * An environment variable name a shell secret or plain variable may take (R2c, D50): a POSIX
1194
- * name. Names the sandbox needs for itself (the proxy, the trust store, `PATH`, `HOME`) and
1195
- * `NYLORUN_*` are reserved.
1196
- */
1197
- export const ENVIRONMENT_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
1198
1227
  export const RESERVED_ENVIRONMENT_NAMES = new Set([
1199
1228
  "PATH",
1200
1229
  "HOME",
@@ -1221,8 +1250,12 @@ const EnvironmentNameSchema = z
1221
1250
  .string()
1222
1251
  .regex(ENVIRONMENT_NAME_PATTERN, "An environment variable name is a letter or _ followed by letters, digits or _")
1223
1252
  .refine((name) => !isReservedEnvironmentName(name), "That environment variable name is reserved");
1224
- /** The value a sandbox sees for every `environment_secret` (R2c, D50): never the secret. */
1225
- 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";
1226
1259
  /**
1227
1260
  * How egress-gate writes an `environment_secret` into a request (R2c, D50): one header, set on
1228
1261
  * every request to a bound host. `format` is text with `{value}` once, optionally inside a
@@ -1263,14 +1296,18 @@ const AllowedHostsSchema = z
1263
1296
  .toLowerCase()
1264
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"))
1265
1298
  .min(1)
1266
- .max(32)
1267
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. */
1268
1301
  const EnvironmentValueSchema = z
1269
1302
  .string()
1270
1303
  .min(1)
1271
- .max(8192)
1272
1304
  .refine((value) => !/[\r\n\0]/.test(value), "A value has no CR, LF or NUL");
1273
- /** 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
+ */
1274
1311
  export const TOOL_SECRET_NAME_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
1275
1312
  /**
1276
1313
  * `PUT /v1/environments/{environmentId}/secrets/{name}` (D56): creates or replaces one credential
@@ -1324,7 +1361,7 @@ export const PutEnvironmentSecretRequestSchema = z.discriminatedUnion("type", [
1324
1361
  export const PutEnvironmentSecretValueRequestSchema = z
1325
1362
  .object({
1326
1363
  requestId: RequestIdSchema.optional(),
1327
- value: z.string().min(1).max(8192).optional(),
1364
+ value: z.string().min(1).optional(),
1328
1365
  headers: CredentialHeadersSchema.optional(),
1329
1366
  })
1330
1367
  .strict()
@@ -1348,7 +1385,8 @@ export function environmentSecretNameError(type, name) {
1348
1385
  const slotBase = {
1349
1386
  /** Whether a session whose agent needs it may open without it. Default false. */
1350
1387
  required: z.boolean().optional(),
1351
- 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(),
1352
1390
  };
1353
1391
  /**
1354
1392
  * One secret an Environment of a kind needs (D64): its type and binding, never its value. The
@@ -1368,15 +1406,11 @@ export const EnvironmentSecretSlotSchema = z.discriminatedUnion("type", [
1368
1406
  z.object({ type: z.literal("bearer"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1369
1407
  z.object({ type: z.literal("headers"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1370
1408
  ]);
1371
- /** The most secret slots one manifest declares. */
1372
- export const ENVIRONMENT_SECRET_SLOTS_MAX = 64;
1409
+ /** A manifest's secret slots: at most the Tenant's Runtime limit `environmentSecretSlots`. */
1373
1410
  export const EnvironmentSecretSlotsSchema = z
1374
1411
  .record(z.string(), EnvironmentSecretSlotSchema)
1375
1412
  .superRefine((slots, ctx) => {
1376
- const names = Object.keys(slots);
1377
- if (names.length > ENVIRONMENT_SECRET_SLOTS_MAX)
1378
- ctx.addIssue({ code: "custom", message: `At most ${ENVIRONMENT_SECRET_SLOTS_MAX} secrets` });
1379
- for (const name of names) {
1413
+ for (const name of Object.keys(slots)) {
1380
1414
  const error = environmentSecretNameError(slots[name].type, name);
1381
1415
  if (error)
1382
1416
  ctx.addIssue({ code: "custom", path: [name], message: error });
@@ -1397,7 +1431,8 @@ export const EnvironmentManifestSchema = z
1397
1431
  error: (issue) => `manifestSchemaVersion ${JSON.stringify(issue.input)} is not one this Runtime reads: use ${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`,
1398
1432
  }),
1399
1433
  name: EnvironmentManifestNameSchema,
1400
- 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(),
1401
1436
  kind: environmentFields.kind,
1402
1437
  image: environmentFields.image,
1403
1438
  resources: environmentFields.resources,
@@ -1407,6 +1442,7 @@ export const EnvironmentManifestSchema = z
1407
1442
  lifecycle: environmentFields.lifecycle,
1408
1443
  setup: environmentFields.setup,
1409
1444
  files: environmentFields.files,
1445
+ limits: environmentFields.limits,
1410
1446
  secrets: EnvironmentSecretSlotsSchema.optional(),
1411
1447
  })
1412
1448
  .strict();
@@ -1547,15 +1583,21 @@ export const ForkEnvironmentResponseSchema = z.union([
1547
1583
  */
1548
1584
  export const MODEL_INPUTS = ["text", "image", "pdf", "office", "audio", "video"];
1549
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 });
1550
1592
  /**
1551
1593
  * What the Runtime cannot learn from a custom OpenAI-compatible endpoint (Model Calls §7):
1552
- * its context window and output limit, whether it reasons, what it reads (`inputs`; default text
1553
- * only) and pi-ai `compat` settings (`thinkingFormat`, `thinkingTokenBudgetField`,
1554
- * `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`, …).
1555
1597
  */
1556
1598
  export const CustomModelSettingsSchema = z
1557
1599
  .object({
1558
- contextWindow: z.number().int().min(1024).optional(),
1600
+ contextWindow: z.number().int().min(1).optional(),
1559
1601
  maxTokens: z.number().int().min(1).optional(),
1560
1602
  reasoning: z.boolean().optional(),
1561
1603
  inputs: z.array(ModelInputSchema).optional(),
@@ -1670,8 +1712,9 @@ export const McpPreviewToolSchema = z
1670
1712
  /** The server's own name for the tool. */
1671
1713
  serverToolName: z.string(),
1672
1714
  /**
1673
- * What the model would call it (R2b C6); absent when the Runtime leaves the tool out (its
1674
- * 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.
1675
1718
  */
1676
1719
  modelName: z.string().optional(),
1677
1720
  description: z.string().optional(),
@@ -1696,10 +1739,10 @@ export const McpPreviewSchema = z
1696
1739
  credentialSent: z.boolean(),
1697
1740
  /** The server's `initialize` answer: its name, version and title. */
1698
1741
  serverInfo: z.record(z.string(), z.unknown()).optional(),
1699
- /** The server's instructions from `initialize`, cut to 2,000 characters. */
1742
+ /** The server's instructions from `initialize`. */
1700
1743
  instructions: z.string().optional(),
1701
1744
  tools: z.array(McpPreviewToolSchema),
1702
- /** Tools the model knows by another name than `server__tool` (R2b C6). */
1745
+ /** Tools Nylorun's engine names otherwise than `server__tool` (R2b C6). */
1703
1746
  renamed: z.array(z.object({ serverToolName: z.string(), name: z.string() }).strict()),
1704
1747
  authRequired: z
1705
1748
  .object({
@@ -1786,8 +1829,6 @@ const messageBase = {
1786
1829
  /** Optional turn manifest (Loop patch); validated as a variant of the pinned agent. */
1787
1830
  manifest: AgentManifestSchema.optional(),
1788
1831
  };
1789
- /** The most parts one message may carry (protocol 6). */
1790
- export const MAX_MESSAGE_PARTS = 32;
1791
1832
  /**
1792
1833
  * One part of a user message (protocol 6): text, or a file by artifact id. A file part without
1793
1834
  * `version` means the artifact's latest version when the message is accepted; the Runtime pins
@@ -1823,7 +1864,8 @@ export const MessageEventBodySchema = z.union([
1823
1864
  z
1824
1865
  .object({
1825
1866
  ...messageBase,
1826
- 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),
1827
1869
  })
1828
1870
  .strict(),
1829
1871
  ]);
@@ -2075,9 +2117,10 @@ export const ModelFailedPayloadSchema = z
2075
2117
  })
2076
2118
  .passthrough();
2077
2119
  /**
2078
- * `context.compacted`: the engine summarized older history to fit the model's window
2079
- * (Model Calls §8). Token counts are estimates. `partial: true`: one summary call of several,
2080
- * 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.
2081
2124
  */
2082
2125
  export const ContextCompactedPayloadSchema = z
2083
2126
  .object({
@@ -2085,20 +2128,18 @@ export const ContextCompactedPayloadSchema = z
2085
2128
  trigger: z.enum(["threshold", "overflow"]),
2086
2129
  tokensBefore: z.number().int().nonnegative(),
2087
2130
  tokensAfter: z.number().int().nonnegative(),
2088
- partial: z.literal(true).optional(),
2089
2131
  ...modelOutcomeFacts,
2090
2132
  ...eventAgent,
2091
2133
  })
2092
2134
  .passthrough();
2093
2135
  /** How a tool call ended (R5.1): the tool answered, the Runtime ended it, or a cancel did. */
2094
2136
  export const TOOL_CALL_STATUSES = ["completed", "failed", "cancelled"];
2095
- /** Where a tool call ran (R5.1): a remote MCP server, an HTTP tool, the sandbox, or core. */
2096
2137
  /**
2097
- * Where a tool call runs: an MCP server, an HTTP tool's URL, the session's sandbox, the Runtime
2098
- * itself (`platform`: the artifact, skill and deferred-tool tools), or the harness that runs the
2099
- * 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).
2100
2141
  */
2101
- export const TOOL_CALL_KINDS = ["mcp", "http", "sandbox", "platform", "harness"];
2142
+ export const TOOL_CALL_KINDS = ["mcp", "http", "sandbox", "harness"];
2102
2143
  /**
2103
2144
  * What the Tenant's tool policy did with a tool call (R5 step 2), when it did more than allow
2104
2145
  * it: `deny` refused it unsent; `ask` held it for a person, who approved it (`approvedBy`, when
@@ -2124,11 +2165,17 @@ export const ToolCompletedPayloadSchema = z
2124
2165
  ...toolIds,
2125
2166
  /** The tool call's effect id (R7.1). */
2126
2167
  effectId: z.string().min(1).optional(),
2168
+ /** The name the model called the tool by, as its harness named it: for display. */
2127
2169
  toolName: z.string().min(1),
2128
2170
  status: z.enum(TOOL_CALL_STATUSES).optional(),
2129
2171
  kind: z.enum(TOOL_CALL_KINDS).optional(),
2130
2172
  /** The MCP server, or the HTTP tool's URL host. */
2131
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(),
2132
2179
  /**
2133
2180
  * The skill the call ran: `load_skill` and `read_skill_resource` name it, and a sandbox tool
2134
2181
  * whose input names its folder, `/skills/<name>@<hash>/`, ran its files.
@@ -2390,9 +2437,10 @@ export const TranscriptUpdatedPayloadSchema = z
2390
2437
  })
2391
2438
  .passthrough();
2392
2439
  /**
2393
- * Where an artifact version's bytes came from: a client's upload, our engine's `save_artifact`,
2394
- * or the turn-end export of a sandbox's outputs (F8.2), whose listing and bytes the harness
2395
- * 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`).
2396
2444
  */
2397
2445
  export const ArtifactSourceSchema = z.enum(["upload", "engine", "export", "snapshot"]);
2398
2446
  /**
@@ -2430,12 +2478,17 @@ export const ArtifactVersionPayloadSchema = z
2430
2478
  export const ArtifactDeletedPayloadSchema = z
2431
2479
  .object({ artifactId: z.string(), name: z.string() })
2432
2480
  .passthrough();
2433
- /** 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
+ */
2434
2485
  export const ArtifactExportSkipReasonSchema = z.enum([
2435
2486
  "too_many_files",
2436
2487
  "file_too_large",
2437
2488
  "too_large",
2438
2489
  "tenant_total",
2490
+ /** Past the session's Environment's own total (its manifest's `limits.artifacts.totalBytes`). */
2491
+ "environment_total",
2439
2492
  ]);
2440
2493
  /**
2441
2494
  * `artifact.export.skipped`: the turn's outputs were past a limit, so no folder version was
@@ -2454,8 +2507,9 @@ export const ArtifactExportSkippedPayloadSchema = z
2454
2507
  })
2455
2508
  .passthrough();
2456
2509
  /**
2457
- * `artifact.export.failed`: the turn-end export could not finish (the sandbox or the Object store
2458
- * 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.
2459
2513
  */
2460
2514
  export const ArtifactExportFailedPayloadSchema = z
2461
2515
  .object({ name: z.string(), message: z.string() })
@@ -2471,13 +2525,8 @@ export const McpServerOutcomeSchema = z
2471
2525
  /** `refused`: the vault has no usable credential for it; `failed`: it could not be reached or listed. */
2472
2526
  outcome: z.enum(["connected", "refused", "failed"]),
2473
2527
  message: z.string(),
2474
- /** 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. */
2475
2529
  tools: z.number().int().nonnegative(),
2476
- /**
2477
- * Of those, the tools out of the model's tool list, which it finds with `tool_search` and runs
2478
- * with `tool_call` (R2b C10); absent when none is.
2479
- */
2480
- deferred: z.number().int().positive().optional(),
2481
2530
  /** Listed tools the server's `tools` settings disable (R2b C9); absent when none. */
2482
2531
  disabled: z.number().int().positive().optional(),
2483
2532
  /**
@@ -2487,14 +2536,6 @@ export const McpServerOutcomeSchema = z
2487
2536
  unknownTools: z.array(z.string()).optional(),
2488
2537
  /** The credentials a refusal names. */
2489
2538
  credentialIds: z.array(z.string()).optional(),
2490
- /**
2491
- * Tools the model knows by another name (R2b C6): `server__tool` with characters outside
2492
- * `[A-Za-z0-9_-]` replaced by `_`, and shortened to 64 with a hash, or suffixed with the hash
2493
- * when that collides. The server is still called by `serverToolName`.
2494
- */
2495
- renamed: z
2496
- .array(z.object({ serverToolName: z.string(), name: z.string() }).passthrough())
2497
- .optional(),
2498
2539
  })
2499
2540
  .passthrough();
2500
2541
  /**
@@ -2912,7 +2953,12 @@ export const SUBJECT_SCOPES = [
2912
2953
  * settings moved to the Management API, which no subject reaches.
2913
2954
  */
2914
2955
  const RETIRED_SUBJECT_SCOPES = ["vaults:own", "tenant:settings"];
2915
- /** 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
+ */
2916
2962
  const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
2917
2963
  /**
2918
2964
  * The owner of a session opened for no person: an MCP server's or HTTP tool's identity header
@@ -2969,13 +3015,6 @@ export const TOKEN_SCOPES = [
2969
3015
  "sessions:own",
2970
3016
  "environments:write",
2971
3017
  ];
2972
- /** The most Environment grants one token caller carries. */
2973
- export const TOKEN_ENVIRONMENT_GRANTS_MAX = 16;
2974
- /**
2975
- * The longest a token the Runtime signs itself lives, in seconds (capability links): rotating
2976
- * signing keys revokes the previous key once the longest token it may have signed has expired.
2977
- */
2978
- export const TOKEN_TTL_MAX_SECONDS = 900;
2979
3018
  /**
2980
3019
  * The `iss` of every token a Tenant's Runtime signs itself: capability links, run, host and
2981
3020
  * egress tokens.
@@ -3142,10 +3181,9 @@ export const SessionViewSchema = z
3142
3181
  ownerUserId: z.string(),
3143
3182
  manifestHash: z.string(),
3144
3183
  /**
3145
- * The hash of the definition the session was opened from (R2b C11). `manifestHash` differs
3146
- * from it when the Runtime pinned its `runtime` block on the definition: a sandbox's tools,
3147
- * the artifact tools and the skill tools. Compare this one with the registered
3148
- * 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.
3149
3187
  */
3150
3188
  definitionHash: z.string().optional(),
3151
3189
  implementationVersion: z.string(),
@@ -3370,7 +3408,8 @@ export const ModelBudgetSchema = z
3370
3408
  export const PutModelBudgetsRequestSchema = z
3371
3409
  .object({
3372
3410
  requestId: RequestIdSchema.optional(),
3373
- 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),
3374
3413
  })
3375
3414
  .strict()
3376
3415
  .superRefine((request, ctx) => {
@@ -3394,8 +3433,11 @@ export const ToolInputConditionSchema = z
3394
3433
  gte: z.number().optional(),
3395
3434
  lt: z.number().optional(),
3396
3435
  lte: z.number().optional(),
3397
- /** A regular expression the field's string value must match. */
3398
- 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(),
3399
3441
  })
3400
3442
  .strict()
3401
3443
  .superRefine((condition, ctx) => {
@@ -3412,27 +3454,45 @@ export const ToolInputConditionSchema = z
3412
3454
  /**
3413
3455
  * One rule of the Tenant's tool policy (R5 step 2), applied at the Tool Gate to every MCP and
3414
3456
  * HTTP tool call of every harness. A rule matches a call when every selector it sets matches:
3415
- * `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
3416
3459
  * server's name), `kind`, `agent` (the agent that calls it) and `when` (fields of the input, by
3417
3460
  * dotted path). The strictest matching rule decides: `deny` refuses the call before it is sent,
3418
3461
  * `ask` holds it until a person approves it on the session (`approve`), `allow` runs it. A call no
3419
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`.
3420
3466
  */
3421
3467
  export const ToolRuleSchema = z
3422
3468
  .object({
3423
3469
  effect: z.enum(TOOL_POLICY_EFFECTS),
3424
- tool: z.string().min(1).max(200).optional(),
3425
- 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(),
3426
3474
  kind: z.enum(["mcp", "http"]).optional(),
3427
- agent: z.string().min(1).max(200).optional(),
3428
- 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(),
3429
3477
  /** Why the rule exists: shown with a held or denied call. */
3430
- reason: z.string().min(1).max(500).optional(),
3478
+ reason: z.string().min(1).optional(),
3431
3479
  })
3432
- .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
+ });
3433
3489
  /** `PUT /v1/tenant/tool-policy`: replaces every rule. An empty list allows every call. */
3434
3490
  export const PutToolPolicyRequestSchema = z
3435
- .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
+ })
3436
3496
  .strict();
3437
3497
  /** The Tenant's tool policy; `updatedAt` is null until one is set. */
3438
3498
  export const ToolPolicySchema = z
@@ -3457,7 +3517,12 @@ export const AgUiRunErrorCodeSchema = z.enum([
3457
3517
  "runtime_error",
3458
3518
  ]);
3459
3519
  // --- Studio embedding (Studio design §8) ---------------------------------------------------
3460
- /** 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
+ */
3461
3526
  const STUDIO_TENANT_ID = /^[A-Za-z0-9_-]{1,128}$/;
3462
3527
  /** `POST /_studio/login-tokens` body. No `tenant` mints a Host-wide token (the CLI's `{}`). */
3463
3528
  export const StudioLoginTokenRequestSchema = z
@@ -3500,7 +3565,6 @@ export const StudioThemeSchema = z.object({
3500
3565
  });
3501
3566
  const EMBED_ROUTE = z
3502
3567
  .string()
3503
- .max(2048)
3504
3568
  .regex(/^\/tenants\/[^/?#\s]+(?:\/[^?#\s]*)?$/, "must be a Studio route under /tenants/");
3505
3569
  const EXTERNAL_URL = z.string().refine((value) => {
3506
3570
  try {
@@ -3582,20 +3646,31 @@ export function parseFrameAncestors(value) {
3582
3646
  // --- File artifacts (protocol 6, blueprint D35, F8.1) ----------------------------------------
3583
3647
  /** The JWT `typ` of a capability link's token (RFC 8725 explicit typing). */
3584
3648
  export const ARTIFACT_LINK_TOKEN_TYPE = "nylorun-artifact+jwt";
3585
- /** A capability link lives no longer than any token the Runtime signs (`TOKEN_TTL_MAX_SECONDS`). */
3586
- 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
+ */
3587
3654
  export const ARTIFACT_LINK_DEFAULT_TTL_SECONDS = 300;
3588
3655
  /** A Tenant's limits when it sets none: 100 MiB per file, 10 GiB in all. */
3589
3656
  export const ARTIFACT_FILE_BYTES_DEFAULT = 100 * 1024 * 1024;
3590
3657
  export const ARTIFACT_TOTAL_BYTES_DEFAULT = 10 * 1024 * 1024 * 1024;
3591
- /** The longest artifact name, in characters. */
3592
- export const ARTIFACT_NAME_MAX = 255;
3593
- /** The longest path of a file in a folder artifact, in characters. */
3594
- export const ARTIFACT_PATH_MAX = 1024;
3595
- /** Labels: up to 32, keys 1–63 characters, values up to 256. */
3596
- export const ArtifactLabelsSchema = z
3597
- .record(z.string().min(1).max(63), z.string().max(256))
3598
- .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());
3599
3674
  /**
3600
3675
  * One version of an artifact: immutable once it exists. A folder version's `size` is the sum of
3601
3676
  * its files' sizes and its `sha256` is its manifest's.
@@ -3654,7 +3729,7 @@ export const UploadArtifactResponseSchema = z
3654
3729
  export const DefinitionFileViewSchema = z
3655
3730
  .object({
3656
3731
  sha256: z.string().regex(/^sha256:[0-9a-f]{64}$/),
3657
- size: z.number().int().nonnegative().max(DEFINITION_FILE_MAX_BYTES),
3732
+ size: z.number().int().nonnegative(),
3658
3733
  })
3659
3734
  .strict();
3660
3735
  export const DeleteArtifactResponseSchema = z
@@ -3666,8 +3741,8 @@ export const CreateArtifactLinkRequestSchema = z
3666
3741
  requestId: RequestIdSchema.optional(),
3667
3742
  /** The version to open. Default: the latest. */
3668
3743
  version: z.number().int().positive().optional(),
3669
- /** Seconds until the link stops working. Default 300, at most 900. */
3670
- 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(),
3671
3746
  /**
3672
3747
  * A folder's file, by its path in the folder: the link opens that one file. Without it, a
3673
3748
  * folder's link opens its zip.
@@ -3697,12 +3772,8 @@ export const FOLDER_MANIFEST_FORMAT = "nylorun.folder.v1";
3697
3772
  * modes and modification times, symbolic links and empty directories. Readers accept both.
3698
3773
  */
3699
3774
  export const FOLDER_MANIFEST_FORMAT_V2 = "nylorun.folder.v2";
3700
- /** 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. */
3701
3776
  export const OUTPUTS_ARTIFACT_NAME = "outputs";
3702
- /** The most files one turn-end export stores; past it the export is skipped. */
3703
- export const EXPORT_MAX_FILES = 10_000;
3704
- /** The most bytes one turn-end export stores (before dedupe); past it the export is skipped. */
3705
- export const EXPORT_MAX_BYTES = 1024 * 1024 * 1024;
3706
3777
  /**
3707
3778
  * One file of a folder: its path in the folder (`/`-separated, relative), size, hash and type.
3708
3779
  * In a v2 manifest an entry may also be a symbolic link (`type: "link"`, its `target`) or an
@@ -3722,7 +3793,7 @@ export const FolderEntrySchema = z
3722
3793
  /** v2: the modification time, ms since the epoch. */
3723
3794
  mtimeMs: z.number().nonnegative().optional(),
3724
3795
  /** v2: a link's target, as stored on the disk. */
3725
- target: z.string().max(4096).optional(),
3796
+ target: z.string().max(LINK_TARGET_MAX).optional(),
3726
3797
  })
3727
3798
  .strict();
3728
3799
  /**
@@ -3787,6 +3858,43 @@ export const TenantArtifactsViewSchema = z
3787
3858
  usedBytes: z.number().int().nonnegative(),
3788
3859
  })
3789
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();
3790
3898
  /** Opt-in session reads (Host feature `session-reads`). */
3791
3899
  export const SessionListItemSchema = SessionSummarySchema.extend({
3792
3900
  lastTurnId: z.string().nullable(),
@@ -3876,9 +3984,12 @@ export const ToolCallSchema = z
3876
3984
  effectId: z.string(),
3877
3985
  turnId: z.string(),
3878
3986
  callId: z.string().nullable(),
3987
+ /** The name the model called it by: for display. */
3879
3988
  toolName: z.string().nullable(),
3880
3989
  kind: z.enum(TOOL_CALL_KINDS).nullable(),
3881
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(),
3882
3993
  /** The skill the call ran (see `tool.completed`). */
3883
3994
  skill: z.string().nullable(),
3884
3995
  /** The Agent Plugin that brought its MCP server or skill. */