@nylorun/core 0.19.0-beta → 0.21.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 (98) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/README.md +2 -2
  3. package/dist/compatibility.d.ts +148 -32
  4. package/dist/compatibility.js +154 -33
  5. package/dist/contracts.d.ts +2714 -495
  6. package/dist/contracts.js +1395 -493
  7. package/dist/define.d.ts +15 -12
  8. package/dist/define.js +11 -7
  9. package/dist/definition/approval.d.ts +16 -0
  10. package/dist/definition/approval.js +33 -0
  11. package/dist/definition/assemble.d.ts +6 -10
  12. package/dist/definition/assemble.js +48 -105
  13. package/dist/definition/bind-agent.d.ts +3 -4
  14. package/dist/definition/bind-agent.js +12 -30
  15. package/dist/definition/binding.d.ts +2 -2
  16. package/dist/definition/bound.d.ts +10 -10
  17. package/dist/definition/builder.d.ts +16 -20
  18. package/dist/definition/builder.js +29 -81
  19. package/dist/definition/code-tools.d.ts +4 -4
  20. package/dist/definition/code-tools.js +7 -22
  21. package/dist/definition/declaration.d.ts +4 -7
  22. package/dist/definition/declaration.js +29 -99
  23. package/dist/definition/{tools-capability.d.ts → deferred-tools.d.ts} +3 -13
  24. package/dist/definition/{tools-capability.js → deferred-tools.js} +2 -18
  25. package/dist/definition/delegate.d.ts +2 -4
  26. package/dist/definition/delegate.js +8 -10
  27. package/dist/definition/flow/compile.js +0 -2
  28. package/dist/definition/from.d.ts +7 -4
  29. package/dist/definition/from.js +72 -117
  30. package/dist/definition/helpers.d.ts +0 -7
  31. package/dist/definition/helpers.js +0 -5
  32. package/dist/definition/http-tool.d.ts +7 -4
  33. package/dist/definition/http-tool.js +6 -10
  34. package/dist/definition/implementations.d.ts +6 -8
  35. package/dist/definition/manifest.d.ts +11 -5
  36. package/dist/definition/manifest.js +27 -26
  37. package/dist/definition/mcp.d.ts +1 -52
  38. package/dist/definition/mcp.js +11 -60
  39. package/dist/definition/media-reference.d.ts +23 -0
  40. package/dist/definition/media-reference.js +26 -0
  41. package/dist/definition/removed.d.ts +3 -10
  42. package/dist/definition/removed.js +10 -17
  43. package/dist/definition/runtime-manifest.d.ts +30 -0
  44. package/dist/definition/runtime-manifest.js +132 -0
  45. package/dist/definition/sandbox-tools.d.ts +1 -1
  46. package/dist/definition/sandbox-tools.js +1 -1
  47. package/dist/definition/skill-tools.d.ts +13 -7
  48. package/dist/definition/skill-tools.js +23 -10
  49. package/dist/definition/trace.d.ts +18 -0
  50. package/dist/definition/trace.js +42 -0
  51. package/dist/definition/variant.d.ts +5 -4
  52. package/dist/definition/variant.js +23 -55
  53. package/dist/definition/workflow/runnable.js +1 -1
  54. package/dist/errors.d.ts +1 -1
  55. package/dist/harness-api/entries.d.ts +242 -0
  56. package/dist/harness-api/entries.js +118 -0
  57. package/dist/harness-api/gates.d.ts +167 -0
  58. package/dist/harness-api/gates.js +117 -0
  59. package/dist/harness-api/harness-api.schema.json +4975 -0
  60. package/dist/harness-api/index.d.ts +19 -3
  61. package/dist/harness-api/index.js +16 -3
  62. package/dist/harness-api/json-schema.d.ts +12 -0
  63. package/dist/harness-api/json-schema.js +61 -0
  64. package/dist/harness-api/mcp.d.ts +57 -0
  65. package/dist/harness-api/mcp.js +39 -0
  66. package/dist/harness-api/messages.d.ts +11 -5
  67. package/dist/harness-api/messages.js +5 -3
  68. package/dist/harness-api/schema.d.ts +346 -36
  69. package/dist/harness-api/schema.js +143 -22
  70. package/dist/harness-api/transport.d.ts +55 -0
  71. package/dist/harness-api/transport.js +61 -0
  72. package/dist/index.d.ts +1 -1
  73. package/dist/manifest-schemas.d.ts +6 -0
  74. package/dist/manifest-schemas.js +34 -0
  75. package/dist/schemas/agent-manifest.schema.json +897 -0
  76. package/dist/schemas/environment-manifest.schema.json +329 -0
  77. package/dist/types/agent.d.ts +1 -1
  78. package/dist/types/manifest.d.ts +48 -28
  79. package/dist/types/model.d.ts +2 -2
  80. package/dist/types/observe.d.ts +8 -20
  81. package/dist/types/part.d.ts +25 -0
  82. package/dist/types/tool.d.ts +1 -1
  83. package/dist/types/transcript.d.ts +5 -0
  84. package/dist/utils/definition-files.d.ts +11 -6
  85. package/dist/utils/definition-files.js +19 -9
  86. package/dist/utils/harness-id.d.ts +9 -0
  87. package/dist/utils/harness-id.js +11 -0
  88. package/dist/utils/runtime-tools.d.ts +19 -0
  89. package/dist/utils/runtime-tools.js +30 -0
  90. package/dist/utils/sandbox.d.ts +1 -1
  91. package/dist/utils/sandbox.js +1 -1
  92. package/package.json +11 -4
  93. package/dist/definition/capability.d.ts +0 -43
  94. package/dist/definition/capability.js +0 -82
  95. package/dist/definition/sandbox-capability.d.ts +0 -44
  96. package/dist/definition/sandbox-capability.js +0 -139
  97. package/dist/types/middleware.d.ts +0 -94
  98. /package/dist/types/{middleware.js → part.js} +0 -0
package/dist/contracts.js CHANGED
@@ -1,15 +1,18 @@
1
1
  /** Public wire contracts only. Never import checkpoint or engine modules here. */
2
2
  import { z } from "zod";
3
3
  import { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
4
- import { REMOVED_CAPABILITY_FIELDS, REMOVED_MANIFEST_FIELDS, manifestVersionIssue, workflowVersionIssue, } from "./definition/removed.js";
4
+ import { REMOVED_MANIFEST_FIELDS, manifestVersionIssue, workflowVersionIssue, } from "./definition/removed.js";
5
+ import { RUNTIME_TOOL_NAMES } from "./utils/runtime-tools.js";
5
6
  import { DELEGATE_INPUT_SCHEMA, DELEGATE_NAME_PATTERN } from "./definition/delegate.js";
6
- import { mcpToolSettingsVersionIssue, stdioMcpRefusal, usesMcpToolSettings, } from "./definition/mcp.js";
7
+ import { stdioMcpRefusal } from "./definition/mcp.js";
7
8
  import { APPROVAL_MODES, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, httpUrlIssue, } from "./definition/http-tool.js";
8
9
  import { canonical } from "./utils/canonical.js";
9
- import { DEFINITION_FILE_MAX_BYTES, skillFilesIssue } from "./utils/definition-files.js";
10
+ import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, isHarnessId } from "./utils/harness-id.js";
11
+ export { DEFAULT_HARNESS, HARNESS_ID_PATTERN, isHarnessId };
12
+ import { DEFINITION_FILE_MAX_BYTES, isDefinitionFileHash, skillFilesIssue } from "./utils/definition-files.js";
10
13
  export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
11
14
  export { DEFINITION_FILE_MAX_BYTES, SKILL_FILES_MAX, definitionFilesOf, isDefinitionFileHash, } from "./utils/definition-files.js";
12
- import { ERROR_CODES } from "./compatibility.js";
15
+ import { ERROR_CODES, isArtifactId } from "./compatibility.js";
13
16
  export const RequestIdSchema = z.string().min(1);
14
17
  export const IdempotencyKeySchema = z.string().min(1).max(256);
15
18
  const jsonObject = z.record(z.string(), z.unknown());
@@ -37,7 +40,12 @@ const jsonValue = z
37
40
  const modelFacingName = (what) => z.string().regex(DELEGATE_NAME_PATTERN, {
38
41
  error: (issue) => `${what} name '${String(issue.input)}' may use only letters, digits, _ and -, up to 64 characters, so that every model provider accepts it`,
39
42
  });
40
- /** One tool's settings on an MCP server (manifest v6, R2b C9). */
43
+ /** Which Agent Plugin brought a skill or an MCP server. */
44
+ const pluginLabelSchema = z
45
+ .object({ name: z.string().min(1), version: z.string().min(1).optional() })
46
+ .strict()
47
+ .meta({ id: "PluginLabel" });
48
+ /** One tool's settings on an MCP server (R2b C9). */
41
49
  const mcpToolSettingsSchema = z
42
50
  .object({
43
51
  enabled: z.boolean().optional(),
@@ -46,10 +54,11 @@ const mcpToolSettingsSchema = z
46
54
  })
47
55
  .strict()
48
56
  .meta({ id: "McpToolSettings" });
49
- /** Manifest v6 (R2b C9, C10): per-tool settings keyed by the server's tool names, `"*"` for the rest. */
57
+ /** Per-tool settings keyed by the server's tool names, `"*"` for the rest (R2b C9, C10). */
50
58
  const mcpServerSettings = {
51
59
  deferred: z.boolean().optional(),
52
60
  tools: z.record(z.string().min(1), mcpToolSettingsSchema).optional(),
61
+ plugin: pluginLabelSchema.optional(),
53
62
  };
54
63
  const mcpServerSchema = z.discriminatedUnion("type", [
55
64
  z
@@ -89,6 +98,7 @@ const skillManifestSchema = z
89
98
  name: z.string().min(1),
90
99
  description: z.string().min(1),
91
100
  files: z.record(z.string(), z.string()),
101
+ plugin: pluginLabelSchema.optional(),
92
102
  })
93
103
  .strict()
94
104
  .superRefine((skill, ctx) => {
@@ -179,17 +189,36 @@ const toolManifestSchema = z
179
189
  message: `Tool '${tool.name}' takes approval only as an HTTP tool`,
180
190
  });
181
191
  });
182
- /** A manifest or capability naming a removed field is refused with what replaces it. */
192
+ /** A manifest naming a removed field is refused with what replaces it. */
183
193
  const removedFieldError = (removedFields) => (issue) => {
184
194
  if (issue.code !== "unrecognized_keys")
185
195
  return undefined;
186
196
  const removed = issue.keys?.find((key) => removedFields[key] !== undefined);
187
197
  return removed === undefined ? undefined : removedFields[removed];
188
198
  };
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();
207
+ /**
208
+ * What an agent needs of the Environment its session opens on (protocol 14, D65), checked when a
209
+ * session opens (`409 environment_unsuitable`). `sandbox`: `any` needs kind `virtual` or `pod`,
210
+ * `pod` needs kind `pod`, `none` needs nothing. `secrets`: names its skills' scripts read, which
211
+ * the Environment's vault must hold. The agent names no Environment: the app still maps.
212
+ */
213
+ const agentRequirementsSchema = z
214
+ .object({
215
+ 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(),
217
+ })
218
+ .strict();
189
219
  const agentManifestSchema = z
190
220
  .strictObject({
191
- // 6 adds an MCP server's `tools` and `deferred` (R2b C9); 5 is accepted unchanged.
192
- manifestSchemaVersion: z.union([z.literal(5), z.literal(6)], {
221
+ manifestSchemaVersion: z.literal(7, {
193
222
  error: (issue) => manifestVersionIssue(issue.input),
194
223
  }),
195
224
  id: z.string().min(1),
@@ -197,19 +226,12 @@ const agentManifestSchema = z
197
226
  description: z.string().optional(),
198
227
  metadata: definitionJson.optional(),
199
228
  outputSchema: definitionJson.optional(),
200
- capabilities: z.array(z.strictObject({
201
- id: z.string().min(1),
202
- type: z.enum(["agent", "agent-plugin"]),
203
- name: z.string().min(1).optional(),
204
- description: z.string().optional(),
205
- metadata: definitionJson.optional(),
206
- instructions: z.array(z.string()).optional(),
207
- skills: z.record(z.string(), skillManifestSchema).optional(),
208
- tools: z.array(toolManifestSchema).optional(),
209
- mcpServers: z.record(z.string(), mcpServerSchema).optional(),
210
- sandbox: sandboxManifestSchema.optional(),
211
- }, { error: removedFieldError(REMOVED_CAPABILITY_FIELDS) })),
212
- runtime: z.object({}).strict().optional(),
229
+ instructions: z.array(z.string()).optional(),
230
+ tools: z.array(toolManifestSchema).optional(),
231
+ skills: z.record(z.string(), skillManifestSchema).optional(),
232
+ mcpServers: z.record(z.string(), mcpServerSchema).optional(),
233
+ requires: agentRequirementsSchema.optional(),
234
+ runtime: runtimeManifestSchema.optional(),
213
235
  // Reserved for Functions, which are deferred: developer code the Runtime will run from
214
236
  // uploaded definition files (a `functions/` folder). Any value is refused below.
215
237
  functions: z.unknown().optional().meta({ description: "Reserved: Functions are not available yet" }),
@@ -218,124 +240,85 @@ const agentManifestSchema = z
218
240
  if (manifest.functions !== undefined)
219
241
  ctx.addIssue({ code: "custom", path: ["functions"], message: "Functions are not available yet" });
220
242
  delegationIssues(manifest, (message) => ctx.addIssue({ code: "custom", message }));
221
- const ids = new Set();
222
243
  const names = new Set();
223
- const servers = new Set();
224
- const skills = new Set();
225
- let sandboxes = 0;
226
- for (const capability of manifest.capabilities) {
227
- if (capability.sandbox) {
228
- sandboxes += 1;
229
- if (sandboxes > 1)
230
- ctx.addIssue({
231
- code: "custom",
232
- message: "At most one capability may declare a sandbox",
233
- });
234
- const declared = new Set((capability.tools ?? []).map((tool) => tool.name));
235
- for (const name of SANDBOX_TOOL_NAMES)
236
- if (!declared.has(name))
237
- ctx.addIssue({
238
- code: "custom",
239
- message: `Sandbox capability '${capability.id}' must declare the built-in '${name}' tool`,
240
- });
241
- }
242
- if (ids.has(capability.id))
243
- ctx.addIssue({ code: "custom", message: "Duplicate capability id" });
244
- ids.add(capability.id);
245
- for (const tool of capability.tools ?? []) {
246
- if (names.has(tool.name))
247
- ctx.addIssue({
248
- code: "custom",
249
- message: "Tool names must be unique",
250
- });
251
- names.add(tool.name);
252
- }
253
- if (capability.skills && Object.keys(capability.skills).length === 0)
244
+ for (const tool of manifest.tools ?? []) {
245
+ if (RUNTIME_TOOL_NAMES.has(tool.name))
254
246
  ctx.addIssue({
255
247
  code: "custom",
256
- message: "skills must be omitted when a capability declares no skills",
248
+ message: `Tool '${tool.name}' takes the name of a tool the Runtime serves; rename it`,
257
249
  });
258
- for (const [key, skill] of Object.entries(capability.skills ?? {})) {
259
- if (key !== skill.name)
260
- ctx.addIssue({
261
- code: "custom",
262
- message: `skills key '${key}' must equal the skill name`,
263
- });
264
- if (skills.has(skill.name))
265
- ctx.addIssue({
266
- code: "custom",
267
- message: `Duplicate skill '${skill.name}'`,
268
- });
269
- skills.add(skill.name);
270
- }
271
- if (capability.mcpServers && Object.keys(capability.mcpServers).length === 0)
250
+ if (tool.name.includes("__"))
272
251
  ctx.addIssue({
273
252
  code: "custom",
274
- message: "mcpServers must be omitted when a capability declares no servers",
253
+ message: `Tool '${tool.name}' must not contain '__', which names an MCP server's tools`,
275
254
  });
276
- for (const [key, server] of Object.entries(capability.mcpServers ?? {})) {
277
- if (key !== server.name)
278
- ctx.addIssue({
279
- code: "custom",
280
- message: `mcpServers key '${key}' must equal the server name`,
281
- });
282
- if (servers.has(server.name))
255
+ }
256
+ for (const tool of [...(manifest.tools ?? []), ...(manifest.runtime?.tools ?? [])]) {
257
+ if (names.has(tool.name))
258
+ ctx.addIssue({ code: "custom", message: "Tool names must be unique" });
259
+ names.add(tool.name);
260
+ }
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))
283
271
  ctx.addIssue({
284
272
  code: "custom",
285
- message: `Duplicate MCP server '${server.name}'`,
273
+ message: `runtime.sandbox comes with the sandbox tools; runtime.tools has no '${name}'`,
286
274
  });
287
- servers.add(server.name);
288
- if (manifest.manifestSchemaVersion === 5 && usesMcpToolSettings(server))
289
- ctx.addIssue({ code: "custom", message: mcpToolSettingsVersionIssue(server.name) });
290
- }
291
275
  }
276
+ if (manifest.skills && Object.keys(manifest.skills).length === 0)
277
+ ctx.addIssue({ code: "custom", message: "skills must be omitted when the agent has no skills" });
278
+ for (const [key, skill] of Object.entries(manifest.skills ?? {}))
279
+ if (key !== skill.name)
280
+ ctx.addIssue({ code: "custom", message: `skills key '${key}' must equal the skill name` });
281
+ if (manifest.mcpServers && Object.keys(manifest.mcpServers).length === 0)
282
+ ctx.addIssue({ code: "custom", message: "mcpServers must be omitted when the agent has no servers" });
283
+ for (const [key, server] of Object.entries(manifest.mcpServers ?? {}))
284
+ if (key !== server.name)
285
+ ctx.addIssue({ code: "custom", message: `mcpServers key '${key}' must equal the server name` });
292
286
  });
293
287
  /**
294
- * An agent's manifest (manifest v5 and v6). Its output is checked against `AgentManifest` here and
295
- * below (`ManifestDrift`): the hand-written type keeps its read-only fields and its docs.
288
+ * An agent's manifest (manifest v7). Its output is checked against `AgentManifest` here and below
289
+ * (`ManifestDrift`): the hand-written type keeps its read-only fields and its docs.
296
290
  */
297
291
  export const AgentManifestSchema = agentManifestSchema;
298
292
  /** Agents used as tools: one level deep, `{ task }` input, one shared sandbox spec. */
299
293
  function delegationIssues(manifest, issue) {
300
294
  const sandboxes = new Set();
301
- const addSandboxes = (agent) => {
302
- for (const capability of agent.capabilities)
303
- if (capability.sandbox)
304
- sandboxes.add(canonical(capability.sandbox));
295
+ const addSandbox = (agent) => {
296
+ if (agent.runtime?.sandbox)
297
+ sandboxes.add(canonical(agent.runtime.sandbox));
305
298
  };
306
- addSandboxes(manifest);
307
- for (const capability of manifest.capabilities)
308
- for (const tool of capability.tools ?? []) {
309
- const child = tool.agent;
310
- if (!child)
311
- continue;
312
- if ("kind" in child) {
313
- // A flow agent runs in its own linked session; its leaves may delegate in turn.
314
- if (tool.name !== child.id)
315
- issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
316
- if (!child.description?.trim() || tool.description !== child.description)
317
- issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
318
- if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
319
- issue(`Agent tool '${tool.name}' must take the standard { task } input`);
320
- if (tool.outputSchema !== undefined)
321
- issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
322
- if (child.sandbox !== undefined && Object.keys(child.sandbox).length > 0)
323
- sandboxes.add(canonical(child.sandbox));
324
- continue;
325
- }
326
- if (tool.name !== child.id)
327
- issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
328
- if (!child.description?.trim() || tool.description !== child.description)
329
- issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
330
- if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
331
- issue(`Agent tool '${tool.name}' must take the standard { task } input`);
332
- if (tool.outputSchema !== undefined)
333
- issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
334
- for (const inner of child.capabilities)
335
- if (inner.tools?.some((item) => item.agent !== undefined))
336
- issue(`'${child.id}' delegates to another agent; nested delegation is not supported yet`);
337
- addSandboxes(child);
299
+ addSandbox(manifest);
300
+ for (const tool of manifest.tools ?? []) {
301
+ const child = tool.agent;
302
+ if (!child)
303
+ continue;
304
+ if (tool.name !== child.id)
305
+ issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
306
+ if (!child.description?.trim() || tool.description !== child.description)
307
+ issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
308
+ if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
309
+ issue(`Agent tool '${tool.name}' must take the standard { task } input`);
310
+ if (tool.outputSchema !== undefined)
311
+ 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));
316
+ continue;
338
317
  }
318
+ if (child.tools?.some((item) => item.agent !== undefined))
319
+ issue(`'${child.id}' delegates to another agent; nested delegation is not supported yet`);
320
+ addSandbox(child);
321
+ }
339
322
  if (sandboxes.size > 1)
340
323
  issue("An agent and the agents it uses as tools must declare identical sandboxes");
341
324
  }
@@ -504,19 +487,13 @@ export const PutAgentRequestSchema = z
504
487
  implementationVersion: z.string().min(1),
505
488
  })
506
489
  .strict();
507
- export const CredentialSelectionSchema = z
508
- .object({
509
- serverName: z.string().min(1),
510
- credentialId: z.string().min(1),
511
- })
512
- .strict();
513
- const sandboxHostSchema = z.string().refine(isSandboxHostPattern, {
514
- message: "network.allow entries must be host names such as api.github.com or *.example.com",
490
+ const hostPatternSchema = z.string().refine(isSandboxHostPattern, {
491
+ message: "network.allowedHosts entries must be host names such as api.github.com or *.example.com",
515
492
  });
516
- const sandboxDurationSchema = (name) => z.string().refine((value) => parseSandboxDuration(value) !== undefined, {
493
+ const durationSchema = (name) => z.string().refine((value) => parseSandboxDuration(value) !== undefined, {
517
494
  message: `${name} must be a duration such as 30s, 15m or 1h`,
518
495
  });
519
- const sandboxResourcesSchema = z
496
+ const resourcesSchema = z
520
497
  .object({
521
498
  cpus: z.number().int().min(1).max(64).optional(),
522
499
  memory: z
@@ -527,41 +504,30 @@ const sandboxResourcesSchema = z
527
504
  .optional(),
528
505
  })
529
506
  .strict();
507
+ // --- Environments (protocol 11, R2d, blueprint D55 and D56) --------------------------------
530
508
  /**
531
- * A sandbox defined when a session is opened. No `network.allow` means no egress. The Runtime
532
- * checks it against the Tenant's limits and pins the result on the session.
509
+ * An Environment id: 1–200 characters, one or more `/`-separated segments of letters, digits,
510
+ * `.`, `_` and `-`, each starting with a letter or digit (`user-42`, `users/alice/web`). Ids are
511
+ * hierarchical so a grant can name a family of them (`users/alice/*`).
533
512
  */
534
- export const SandboxInlineRequestSchema = z
535
- .object({
536
- image: z.string().min(1).optional(),
537
- network: z.object({ allow: z.array(sandboxHostSchema).optional() }).strict().optional(),
538
- resources: sandboxResourcesSchema.optional(),
539
- })
540
- .strict();
541
- // --- sandboxes as a resource (Host feature `sandboxes`, blueprint D39) ----------------------
542
- /**
543
- * A sandbox id: 1–200 characters, one or more `/`-separated segments of letters, digits, `.`,
544
- * `_` and `-`, each starting with a letter or digit (`user-42`, `team-a/proj-42`). Ids are
545
- * hierarchical so an `sbx` grant can name a family of them (`team-a/*`).
546
- */
547
- const SANDBOX_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/;
548
- export const SANDBOX_ID_MAX_LENGTH = 200;
549
- export function isSandboxId(value) {
513
+ const ENVIRONMENT_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/;
514
+ export const ENVIRONMENT_ID_MAX_LENGTH = 200;
515
+ export function isEnvironmentId(value) {
550
516
  return (typeof value === "string" &&
551
- value.length <= SANDBOX_ID_MAX_LENGTH &&
552
- SANDBOX_ID_PATTERN.test(value));
517
+ value.length <= ENVIRONMENT_ID_MAX_LENGTH &&
518
+ ENVIRONMENT_ID_PATTERN.test(value));
553
519
  }
554
- /** A sandbox grant: an exact sandbox id, or a prefix ending in `/*` (`team-a/*`). */
555
- export function isSandboxGrant(value) {
520
+ /** An Environment grant: an exact Environment id, or a prefix ending in `/*` (`team-a/*`). */
521
+ export function isEnvironmentGrant(value) {
556
522
  if (typeof value !== "string")
557
523
  return false;
558
- return value.endsWith("/*") ? isSandboxId(value.slice(0, -2)) : isSandboxId(value);
524
+ return value.endsWith("/*") ? isEnvironmentId(value.slice(0, -2)) : isEnvironmentId(value);
559
525
  }
560
526
  /**
561
- * Whether `grants` (a token caller's sandbox grants) reach sandbox `id`: an exact entry, or a prefix
562
- * entry `p/*` for any id below `p/`. No grants reach no sandbox.
527
+ * Whether `grants` (a token caller's Environment grants) reach Environment `id`: an exact entry,
528
+ * or a prefix entry `p/*` for any id below `p/`. No grants reach no Environment.
563
529
  */
564
- export function sandboxGranted(grants, id) {
530
+ export function environmentGranted(grants, id) {
565
531
  for (const grant of grants ?? []) {
566
532
  if (grant.endsWith("/*")) {
567
533
  if (id.startsWith(grant.slice(0, -1)))
@@ -572,245 +538,573 @@ export function sandboxGranted(grants, id) {
572
538
  }
573
539
  return false;
574
540
  }
575
- export const SandboxIdSchema = z
541
+ export const EnvironmentIdSchema = z
576
542
  .string()
577
- .refine(isSandboxId, {
578
- message: "A sandbox id is up to 200 characters: /-separated segments of letters, digits, '.', '_' and '-'",
543
+ .refine(isEnvironmentId, {
544
+ message: "An Environment id is up to 200 characters: /-separated segments of letters, digits, '.', '_' and '-'",
579
545
  })
580
- .meta({ description: "A sandbox id, such as `user-42` or `team-a/proj-42`" });
581
- export const SandboxGrantSchema = z.string().refine(isSandboxGrant, {
582
- message: "A sandbox grant is a sandbox id, or a prefix ending in /* such as team-a/*",
546
+ .meta({ description: "An Environment id, such as `user-42` or `users/alice/web`" });
547
+ export const EnvironmentGrantSchema = z.string().refine(isEnvironmentGrant, {
548
+ message: "An Environment grant is an Environment id, or a prefix ending in /* such as team-a/*",
583
549
  });
584
- /** `virtual`: a just-bash workspace, no cluster (F7.1). `pod`: an agent-sandbox pod (F7.2). */
585
- export const SANDBOX_KINDS = ["virtual", "pod"];
550
+ /**
551
+ * `virtual`: a just-bash workspace in the harness container, no cluster (a local convenience).
552
+ * `pod`: an agent-sandbox pod with its own volume (Host feature `sandbox-pods`). `none`: no
553
+ * compute, only the vault, for agents whose tools are remote MCP servers and HTTP tools.
554
+ */
555
+ export const ENVIRONMENT_KINDS = ["virtual", "pod", "none"];
586
556
  const LABEL_KEY_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._/-]{0,61}[A-Za-z0-9])?$/;
587
557
  const LABEL_VALUE_PATTERN = /^[\x20-\x7e]{0,256}$/;
588
- export const SANDBOX_LABELS_MAX = 32;
558
+ export const ENVIRONMENT_LABELS_MAX = 32;
589
559
  /** The developer's own key-value pairs; the Runtime stores and filters them, never reads them. */
590
- export const SandboxLabelsSchema = z
560
+ export const EnvironmentLabelsSchema = z
591
561
  .record(z.string().regex(LABEL_KEY_PATTERN, {
592
562
  message: "Label keys are 1-63 letters, digits, '.', '_', '/' and '-'",
593
563
  }), z.string().regex(LABEL_VALUE_PATTERN, {
594
564
  message: "Label values are up to 256 printable ASCII characters",
595
565
  }))
596
- .refine((labels) => Object.keys(labels).length <= SANDBOX_LABELS_MAX, {
597
- message: `At most ${SANDBOX_LABELS_MAX} labels`,
566
+ .refine((labels) => Object.keys(labels).length <= ENVIRONMENT_LABELS_MAX, {
567
+ message: `At most ${ENVIRONMENT_LABELS_MAX} labels`,
568
+ });
569
+ /** A harness id (track R4): what a harness names itself in `hello`. */
570
+ export const HarnessIdSchema = z.string().regex(HARNESS_ID_PATTERN, {
571
+ message: "harness must be a harness id: lowercase letters, digits and dashes, starting with a letter",
598
572
  });
599
573
  /**
600
- * `PUT /v1/sandboxes/{sandboxId}`: creates the sandbox, or finds the one with this id. The spec
601
- * (`kind`, `image`, `network`, `resources`, `storage`) is checked against the Tenant's limits
602
- * and fixed once the sandbox exists; `labels`, when sent, replace the sandbox's labels.
603
- *
604
- * Kind `pod` (Host feature `sandbox-pods`) is created at once on the Tenant's cluster. A `PUT`
605
- * on an existing pod sandbox also starts it again when it was stopped, and one with a
606
- * `lifecycle.ttl` other than its own sets a new expiry (counted from its creation), which
607
- * revives an expired sandbox.
574
+ * An Environment's lifecycle. `idle`: stop compute after this long without a turn, at most the
575
+ * Tenant's `limits.idle` (default the Tenant's). `deleteAfter`: delete the Environment, its vault
576
+ * and its disk once it has gone this long unused (no turn, recipe change, secret write, stop or
577
+ * reset); default never.
578
+ */
579
+ export const EnvironmentLifecycleSchema = z
580
+ .object({
581
+ idle: durationSchema("lifecycle.idle").optional(),
582
+ deleteAfter: durationSchema("lifecycle.deleteAfter").optional(),
583
+ })
584
+ .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;
589
+ const absoluteWorkspacePath = (name) => z
590
+ .string()
591
+ .min(1)
592
+ .max(1024)
593
+ .refine((value) => (value === "/workspace" || value.startsWith("/workspace/")) &&
594
+ !value.split("/").some((segment) => segment === ".." || segment === "."), { message: `${name} must be /workspace or a path under it, without . or .. segments` });
595
+ /**
596
+ * One setup command (pods only): run with `/bin/sh -c` when the pod's disk is made or reset,
597
+ * before the engine takes a turn, with the Environment's variables, secrets (as the sentinel)
598
+ * and egress, as a turn's commands are.
599
+ */
600
+ export const EnvironmentSetupCommandSchema = z
601
+ .object({
602
+ command: z.string().min(1).max(4096),
603
+ /** Where it runs. Default `/workspace`. */
604
+ 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(),
611
+ })
612
+ .strict();
613
+ /**
614
+ * One input file (pods only): a version of a Tenant-wide artifact, copied in when the pod's disk
615
+ * is made or reset, before the setup commands. A file artifact is written at `path`; a folder
616
+ * artifact is unpacked under it.
617
+ */
618
+ /** The most files one `files` entry by hash names (Q6). */
619
+ export const ENVIRONMENT_FILES_MAX = 1000;
620
+ /** A file's path inside a `files` entry by hash: relative, `/`-separated, without `.` or `..`. */
621
+ const relativeFilePath = z
622
+ .string()
623
+ .min(1)
624
+ .max(1024)
625
+ .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
+ /**
627
+ * One input file entry (pods only): an artifact version copied to `path` (a file artifact, or a
628
+ * 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`
630
+ * at its relative path. A manifest by hash moves to another Tenant with its files.
631
+ */
632
+ export const EnvironmentFileSchema = z.union([
633
+ z
634
+ .object({
635
+ artifactId: z.string().refine(isArtifactId, { message: "artifactId must be an artifact id" }),
636
+ version: z.number().int().positive(),
637
+ path: absoluteWorkspacePath("path"),
638
+ })
639
+ .strict(),
640
+ z
641
+ .object({
642
+ path: absoluteWorkspacePath("path"),
643
+ files: z
644
+ .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
+ }),
648
+ })
649
+ .strict(),
650
+ ]);
651
+ /**
652
+ * An environment manifest's name (protocol 14, D63): 1–64 letters, digits, `.`, `_` and `-`,
653
+ * starting with a letter or digit, such as `analyst-box`.
654
+ */
655
+ const ENVIRONMENT_MANIFEST_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
656
+ export function isEnvironmentManifestName(value) {
657
+ return typeof value === "string" && ENVIRONMENT_MANIFEST_NAME_PATTERN.test(value);
658
+ }
659
+ export const EnvironmentManifestNameSchema = z
660
+ .string()
661
+ .refine(isEnvironmentManifestName, {
662
+ message: "An environment manifest's name is 1-64 letters, digits, '.', '_' and '-', starting with a letter or digit",
663
+ })
664
+ .meta({ description: "An environment manifest's name, such as `analyst-box`" });
665
+ /**
666
+ * Which manifest an Environment is made from: `name` (its latest version when the Environment is
667
+ * created) or `name@n` (version `n`). Either way the Environment keeps that version for life.
608
668
  */
609
- export const PutSandboxRequestSchema = z
669
+ export function parseEnvironmentManifestRef(ref) {
670
+ const at = ref.lastIndexOf("@");
671
+ const name = at < 0 ? ref : ref.slice(0, at);
672
+ if (!isEnvironmentManifestName(name))
673
+ return undefined;
674
+ if (at < 0)
675
+ return { name };
676
+ const version = ref.slice(at + 1);
677
+ return /^[1-9][0-9]{0,8}$/.test(version) ? { name, version: Number(version) } : undefined;
678
+ }
679
+ export const EnvironmentManifestRefSchema = z
680
+ .string()
681
+ .refine((value) => parseEnvironmentManifestRef(value) !== undefined, {
682
+ message: "manifest is an environment manifest's name, or name@version such as analyst-box@3",
683
+ })
684
+ .meta({ description: "`name` (the latest version when the Environment is created) or `name@n`" });
685
+ /**
686
+ * `PUT /v1/environments/{environmentId}`: creates the Environment and its vault, or finds the
687
+ * one with this id, so "get or create" is one call. An Environment is made from one version of an
688
+ * environment manifest (`manifest`) or from the inline manifest these fields make, and never
689
+ * changes what it runs after that (protocol 14, D63): on an existing one, `labels` replace its
690
+ * labels and `ownerUserId` sets or clears its owner guard, a field that matches what it runs is
691
+ * accepted, and anything else is `409 environment_immutable`, naming the fork that makes a new
692
+ * Environment instead.
693
+ */
694
+ export const PutEnvironmentRequestSchema = z
610
695
  .object({
611
696
  requestId: RequestIdSchema.optional(),
612
- /** Default `virtual`. `pod` needs sandbox pods (`nylorun sandbox enable`). */
613
- kind: z.enum(SANDBOX_KINDS).optional(),
614
- labels: SandboxLabelsSchema.optional(),
697
+ /**
698
+ * The environment manifest to make the Environment from (Host feature
699
+ * `environment-manifests`): `name` or `name@n`. With it, none of the inline fields below is
700
+ * sent; `labels`, `ownerUserId` and `from` still are.
701
+ */
702
+ manifest: EnvironmentManifestRefSchema.optional(),
703
+ /** Default `virtual`. `pod` needs sandbox pods (`nylorun local sandbox enable`). Fixed. */
704
+ kind: z.enum(ENVIRONMENT_KINDS).optional(),
705
+ labels: EnvironmentLabelsSchema.optional(),
615
706
  /** Pods only: the workload image (default the Tenant's, else `python:3.13-slim`). */
616
707
  image: z.string().min(1).optional(),
617
- /** Hosts the sandbox may reach; pods also take `*.suffix` patterns. */
618
- network: z.object({ allow: z.array(sandboxHostSchema).optional() }).strict().optional(),
619
- resources: sandboxResourcesSchema.optional(),
620
- /** Pods only: the volume's size (default 5GiB), fixed once created. */
708
+ resources: resourcesSchema.optional(),
709
+ /** Pods only: the volume's size (default 5GiB). Fixed. */
621
710
  storage: z
622
711
  .string()
623
712
  .refine((value) => parseSandboxSize(value) !== undefined, {
624
713
  message: "storage must be a size such as 5GiB",
625
714
  })
626
715
  .optional(),
627
- /** Pods only. */
628
- lifecycle: z
716
+ /** Hosts the sandbox may reach; pods also take `*.suffix` patterns. */
717
+ network: z
718
+ .object({ allowedHosts: z.array(hostPatternSchema).optional() })
719
+ .strict()
720
+ .optional(),
721
+ /**
722
+ * The harness that runs the Environment's sessions (track R4): `nylorun` (ours, the default)
723
+ * 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`.
727
+ */
728
+ harness: HarnessIdSchema.optional(),
729
+ /**
730
+ * The owner guard: when set, only sessions of this owner may name the Environment (checked
731
+ * when a session opens and at every turn start). `null` clears it.
732
+ */
733
+ ownerUserId: z.string().min(1).nullable().optional(),
734
+ lifecycle: EnvironmentLifecycleSchema.optional(),
735
+ /**
736
+ * Pods only (Host feature `environment-setup`): commands run when the disk is made or reset,
737
+ * before any turn. A change applies at the next reset.
738
+ */
739
+ setup: z.array(EnvironmentSetupCommandSchema).max(ENVIRONMENT_SETUP_MAX).optional(),
740
+ /** 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(),
742
+ /**
743
+ * The secrets an Environment of this kind needs, by name (D64): each slot's type, binding,
744
+ * whether it is required and a description, never a value. With slots declared, a secret
745
+ * write sends only the value and a name not declared is `409 secret_not_in_manifest`.
746
+ */
747
+ secrets: z.lazy(() => EnvironmentSecretSlotsSchema).optional(),
748
+ /**
749
+ * Only when the `PUT` creates the Environment (Host feature `environment-disk-versions`): its
750
+ * disk starts from this version of another Environment's disk. Its vault starts empty.
751
+ */
752
+ from: z
629
753
  .object({
630
- /** How long after its creation the sandbox expires; within the Tenant's `limits.ttl`. */
631
- ttl: sandboxDurationSchema("lifecycle.ttl").optional(),
754
+ environment: EnvironmentIdSchema,
755
+ version: z.union([z.number().int().positive(), z.literal("latest")]),
632
756
  })
633
757
  .strict()
634
758
  .optional(),
635
759
  })
636
760
  .strict();
637
- /** A session attached to a sandbox, as the sandbox's view lists it. */
638
- export const SandboxSessionSchema = z
761
+ /**
762
+ * What an Environment runs (its inline manifest, called the recipe before protocol 14), resolved
763
+ * against the Tenant's limits when it was made. It never changes after that.
764
+ */
765
+ export const EnvironmentRecipeSchema = z
766
+ .object({
767
+ image: z.string().optional(),
768
+ resources: z.object({ cpus: z.number().int(), memory: z.string() }).strict().optional(),
769
+ storage: z.string().optional(),
770
+ network: z.object({ allowedHosts: z.array(z.string()) }).strict().optional(),
771
+ harness: z.string(),
772
+ lifecycle: EnvironmentLifecycleSchema,
773
+ setup: z.array(EnvironmentSetupCommandSchema).optional(),
774
+ files: z.array(EnvironmentFileSchema).optional(),
775
+ secrets: z.lazy(() => EnvironmentSecretSlotsSchema).optional(),
776
+ })
777
+ .strict();
778
+ /** A session that names an Environment, as the Environment's view lists it. */
779
+ export const EnvironmentSessionSchema = z
639
780
  .object({ id: z.string(), activeTurnId: z.string().nullable() })
640
781
  .strict();
641
- /** What the Runtime wants of a pod sandbox (`desired`) and what it last saw (`observed`). */
642
- export const SANDBOX_POD_DESIRED = ["running", "suspended", "deleted"];
643
- export const SANDBOX_POD_OBSERVED = [
782
+ /** What the Runtime wants of a pod (`desired`) and what it last saw (`observed`). */
783
+ export const POD_DESIRED = ["running", "suspended", "deleted"];
784
+ export const POD_OBSERVED = [
644
785
  "creating",
645
786
  "running",
646
787
  "suspended",
647
- "expired",
648
788
  "lost",
649
789
  "failed",
650
790
  "deleting",
651
791
  ];
652
- export const SandboxPodViewSchema = z
792
+ export const EnvironmentPodViewSchema = z
653
793
  .object({
654
- desired: z.enum(SANDBOX_POD_DESIRED),
655
- observed: z.enum(SANDBOX_POD_OBSERVED),
794
+ desired: z.enum(POD_DESIRED),
795
+ observed: z.enum(POD_OBSERVED),
656
796
  /** Bumped by every reset: each generation has its own volume. */
657
797
  volumeGeneration: z.number().int().nonnegative(),
658
798
  /** Bumped each time a pod joins; a host token of an older epoch is refused. */
659
799
  hostEpoch: z.number().int().nonnegative(),
660
- /** When it expires (its TTL), if it has one. */
661
- expiresAt: z.string().optional(),
662
800
  /** Why it failed, or was lost. */
663
801
  reason: z.string().optional(),
802
+ /**
803
+ * The workload image by digest (`repo@sha256:…`), pinned the first time a pod was ready
804
+ * (Q14): every later pod runs it. Absent before then, or for an image with no repository.
805
+ */
806
+ imageDigest: z.string().optional(),
664
807
  })
665
808
  .strict();
666
- /** `PUT` and `GET /v1/sandboxes/{sandboxId}`. */
667
- export const SandboxViewSchema = z
809
+ /**
810
+ * The compute states an Environment reports today: `ready` until a tool first runs in a virtual
811
+ * one, then `creating`, `running` or `stopped`. An open set: clients must accept values they do
812
+ * not know (a later release may add one, such as `cold`).
813
+ */
814
+ export const ENVIRONMENT_STATES = ["ready", "creating", "running", "stopped"];
815
+ /** `PUT` and `GET /v1/environments/{environmentId}`. */
816
+ export const EnvironmentViewSchema = z
668
817
  .object({
669
818
  id: z.string(),
670
- kind: z.enum(SANDBOX_KINDS),
819
+ kind: z.enum(ENVIRONMENT_KINDS),
671
820
  labels: z.record(z.string(), z.string()),
672
- /** The spec, resolved against the Tenant's limits when the sandbox was created. */
673
- spec: z.record(z.string(), z.unknown()),
674
821
  /**
675
- * `ready` until a tool first runs in it, then the workspace's compute state. A virtual
676
- * sandbox has nothing to stop: `stopped` means only that its turn queue is idle.
822
+ * What it runs, fixed when it was made (protocol 14): its manifest's fields, or the inline
823
+ * ones, resolved against the Tenant's limits.
677
824
  */
678
- state: z.enum(["ready", "creating", "running", "stopped"]),
825
+ manifest: EnvironmentRecipeSchema,
826
+ /** The environment manifest it was made from and its version, when it was made from one. */
827
+ manifestName: z.string().optional(),
828
+ manifestVersion: z.number().int().positive().optional(),
829
+ /** The hash of what it runs (`manifest`). */
830
+ manifestHash: z.string().optional(),
831
+ /**
832
+ * The Environment it was forked from (`POST .../fork`, Q15), and the disk version it started
833
+ * from (`null` for an empty disk).
834
+ */
835
+ forkedFrom: z
836
+ .object({ environment: z.string(), disk: z.number().int().positive().nullable() })
837
+ .strict()
838
+ .optional(),
839
+ /** Each secret slot its manifest declares, and whether its vault holds a value for it. */
840
+ slots: z
841
+ .array(z
842
+ .object({
843
+ name: z.string(),
844
+ type: z.string(),
845
+ required: z.boolean(),
846
+ set: z.boolean(),
847
+ })
848
+ .strict())
849
+ .optional(),
850
+ /** Always 1 since protocol 14: an Environment never changes what it runs. */
851
+ version: z.number().int().positive(),
852
+ /** Always `version`. */
853
+ appliedVersion: z.number().int().positive(),
854
+ /** The owner guard, or `null`. */
855
+ ownerUserId: z.string().nullable(),
856
+ /** See `ENVIRONMENT_STATES`: an open set. */
857
+ state: z.string().meta({ description: "ready, creating, running or stopped; an open set" }),
679
858
  /** Kind `pod`: what the Runtime wants of the pod and what it last saw. */
680
- pod: SandboxPodViewSchema.optional(),
681
- /** Sessions attached to it (acting for a subject, only the subject's own). */
682
- sessions: z.array(SandboxSessionSchema),
859
+ pod: EnvironmentPodViewSchema.optional(),
860
+ /** When it was last used: a turn, a recipe change, a secret write, a stop or a reset. */
861
+ lastUsedAt: z.string(),
862
+ /**
863
+ * Its disk versions (Host feature `environment-disk-versions`): the latest, and the copy
864
+ * that holds the disk now, if one does. Absent for kind `none`.
865
+ */
866
+ disk: z
867
+ .object({
868
+ latestVersion: z.number().int().positive().nullable(),
869
+ operation: z
870
+ .object({
871
+ kind: z.enum(["snapshot", "restore", "seed"]),
872
+ version: z.number().int().positive().optional(),
873
+ startedAt: z.string(),
874
+ })
875
+ .strict()
876
+ .optional(),
877
+ })
878
+ .strict()
879
+ .optional(),
880
+ /** Sessions that name it (acting for a subject, only the subject's own). */
881
+ sessions: z.array(EnvironmentSessionSchema),
683
882
  createdAt: z.string(),
684
883
  updatedAt: z.string(),
685
884
  })
686
885
  .strict();
687
- export const ListSandboxesResponseSchema = z
688
- .object({ sandboxes: z.array(SandboxViewSchema) })
886
+ /** `POST /v1/environments/{id}/snapshot`: a new version of the Environment's disk. */
887
+ export const EnvironmentSnapshotSchema = z
888
+ .object({
889
+ environmentId: z.string(),
890
+ artifactId: z.string(),
891
+ version: z.number().int().positive(),
892
+ format: z.string(),
893
+ /** Entries in the version: files, links and empty directories. */
894
+ files: z.number().int().nonnegative(),
895
+ /** The files' bytes. */
896
+ bytes: z.number().int().nonnegative(),
897
+ /** Of those, the bytes stored now (the rest were stored already). */
898
+ storedBytes: z.number().int().nonnegative(),
899
+ durationMs: z.number().int().nonnegative(),
900
+ /** True when the disk had not changed: `version` is the latest, and nothing was stored. */
901
+ unchanged: z.boolean(),
902
+ createdAt: z.string(),
903
+ })
689
904
  .strict();
690
- export const DeleteSandboxResponseSchema = z
905
+ /** `POST /v1/environments/{id}/restore`: which version of its disk to put back. */
906
+ export const RestoreEnvironmentRequestSchema = z
907
+ .object({
908
+ requestId: RequestIdSchema.optional(),
909
+ version: z.union([z.number().int().positive(), z.literal("latest")]),
910
+ })
911
+ .strict();
912
+ export const EnvironmentRestoreSchema = z
913
+ .object({
914
+ environmentId: z.string(),
915
+ restored: z.number().int().positive(),
916
+ /**
917
+ * `done` once the version is back (a virtual Environment); `pending` while a pod's new volume
918
+ * is seeded (`disk.operation` in the view until it ends; turns wait for it).
919
+ */
920
+ status: z.enum(["done", "pending"]),
921
+ volumeGeneration: z.number().int().nonnegative().optional(),
922
+ })
923
+ .strict();
924
+ /** `GET /v1/environments/{id}/versions`: its disk versions, newest first. */
925
+ export const EnvironmentVersionsSchema = z
926
+ .object({
927
+ environmentId: z.string(),
928
+ /** The folder artifact that holds them (read trees, files and diffs through `/v1/artifacts`). */
929
+ artifactId: z.string().nullable(),
930
+ latest: z.number().int().positive().nullable(),
931
+ versions: z.array(z
932
+ .object({
933
+ version: z.number().int().positive(),
934
+ bytes: z.number().int().nonnegative(),
935
+ createdAt: z.string(),
936
+ })
937
+ .strict()),
938
+ })
939
+ .strict();
940
+ export const ListEnvironmentsResponseSchema = z
941
+ .object({ environments: z.array(EnvironmentViewSchema) })
942
+ .strict();
943
+ export const DeleteEnvironmentResponseSchema = z
691
944
  .object({ id: z.string(), deleted: z.boolean() })
692
945
  .strict();
693
- /** The schema id of a sandbox's lifecycle events (its stream in the record). */
694
- export const SANDBOX_EVENT_SCHEMA = "nylorun.sandbox-event/1";
695
- export const SANDBOX_EVENT_TYPES = [
696
- "sandbox.created",
697
- "sandbox.attached",
698
- "sandbox.detached",
699
- "sandbox.deleted",
946
+ /** A turn that was running on an Environment when one of its connections opened (D67). */
947
+ export const EgressRunningTurnSchema = z
948
+ .object({ sessionId: z.string(), turnId: z.string() })
949
+ .strict();
950
+ /**
951
+ * One connection a pod Environment opened through egress-gate (track R7, Q6): written when it
952
+ * closes, or at once when the gate refused it, to the Environment's own stream as
953
+ * `environment.egress` (D67). The connection is the Environment's: its egress token names the pod,
954
+ * and the Environment's sessions run turns in parallel (D66). `runningTurns` lists the turns
955
+ * active on it as the connection opened, at most 16, as context and never as the owner.
956
+ *
957
+ * `startedAt` is the gate's clock at CONNECT and `durationMs` runs from there to the close, so
958
+ * the span is the gate's own measurement. `bytesUp` is what the sandbox sent, `bytesDown` what it
959
+ * got. `mode: "credential"` is a host an `environment_secret` is bound to (R2c): the gate read
960
+ * each request (`requests`) and set a credential on it (`credentialIds`, ids only). It never
961
+ * carries a header value, a URL path or a body.
962
+ */
963
+ export const EgressConnectionPayloadSchema = z
964
+ .object({
965
+ environmentId: z.string(),
966
+ host: z.string(),
967
+ port: z.number().int(),
968
+ outcome: z.enum(["allowed", "refused"]),
969
+ /** Why the gate refused it, as in its `egress_refused` log line (`host_not_allowed`, …). */
970
+ reason: z.string().optional(),
971
+ /** The HTTP status a refusal answered the CONNECT with. */
972
+ status: z.number().int().optional(),
973
+ mode: z.enum(["tunnel", "credential"]),
974
+ credentialBound: z.boolean(),
975
+ credentialIds: z.array(z.string()).optional(),
976
+ requests: z.number().int().nonnegative().optional(),
977
+ bytesUp: z.number().int().nonnegative(),
978
+ bytesDown: z.number().int().nonnegative(),
979
+ durationMs: z.number().nonnegative(),
980
+ startedAt: z.string(),
981
+ runningTurns: z.array(EgressRunningTurnSchema).max(16),
982
+ })
983
+ .passthrough();
984
+ /** The schema id of an Environment's lifecycle events (its stream in the record). */
985
+ export const ENVIRONMENT_EVENT_SCHEMA = "nylorun.environment-event/1";
986
+ export const ENVIRONMENT_EVENT_TYPES = [
987
+ "environment.created",
988
+ "environment.attached",
989
+ "environment.detached",
990
+ "environment.deleted",
700
991
  // Kind `pod` (Host feature `sandbox-pods`).
701
- "sandbox.running",
702
- "sandbox.suspended",
703
- "sandbox.expired",
704
- "sandbox.relaunched",
705
- "sandbox.lost",
706
- "sandbox.reset",
707
- "sandbox.failed",
992
+ "environment.running",
993
+ "environment.suspended",
994
+ "environment.relaunched",
995
+ "environment.lost",
996
+ "environment.reset",
997
+ "environment.failed",
998
+ // Forked into a new Environment (Q15).
999
+ "environment.forked",
1000
+ // egress-gate: every connection the Environment opens (R7, D67).
1001
+ "environment.egress",
708
1002
  ];
709
- /** The payload of each sandbox lifecycle event. */
710
- export const SANDBOX_EVENT_PAYLOADS = {
711
- "sandbox.created": z
712
- .object({ kind: z.enum(SANDBOX_KINDS), labels: z.record(z.string(), z.string()) })
1003
+ /** The payload of each Environment lifecycle event. */
1004
+ export const ENVIRONMENT_EVENT_PAYLOADS = {
1005
+ "environment.created": z
1006
+ .object({
1007
+ kind: z.enum(ENVIRONMENT_KINDS),
1008
+ labels: z.record(z.string(), z.string()),
1009
+ /** The environment manifest and version it was made from (protocol 14, D63). */
1010
+ manifest: z.object({ name: z.string(), version: z.number().int().positive() }).strict().optional(),
1011
+ /** The Environment it was forked from, and the disk version it started from (Q15). */
1012
+ forkedFrom: z
1013
+ .object({ environment: z.string(), disk: z.number().int().positive().nullable() })
1014
+ .strict()
1015
+ .optional(),
1016
+ })
713
1017
  .passthrough(),
714
- "sandbox.attached": z.object({ sessionId: z.string() }).passthrough(),
715
- "sandbox.detached": z
1018
+ "environment.attached": z.object({ sessionId: z.string() }).passthrough(),
1019
+ "environment.detached": z
716
1020
  .object({ sessionId: z.string(), reason: z.enum(["reset"]) })
717
1021
  .passthrough(),
718
- "sandbox.deleted": z.object({}).passthrough(),
719
- /** A pod joined and serves the sandbox. */
720
- "sandbox.running": z.object({ hostEpoch: z.number().int() }).passthrough(),
1022
+ /** Deleted by a `DELETE`, or by the sweep once `lifecycle.deleteAfter` passed (`reason`). */
1023
+ "environment.deleted": z
1024
+ .object({ reason: z.enum(["delete", "deleteAfter"]).optional() })
1025
+ .passthrough(),
1026
+ /** A pod joined and serves the Environment. */
1027
+ "environment.running": z.object({ hostEpoch: z.number().int() }).passthrough(),
721
1028
  /** Stopped (`POST .../stop`, or idle): the volume is kept; the next turn starts it again. */
722
- "sandbox.suspended": z.object({ reason: z.enum(["stop", "idle"]) }).passthrough(),
723
- /** Its TTL passed: turns are refused until a `PUT` sets a longer TTL. */
724
- "sandbox.expired": z.object({ onExpiry: z.enum(["retain", "delete"]) }).passthrough(),
1029
+ "environment.suspended": z.object({ reason: z.enum(["stop", "idle"]) }).passthrough(),
725
1030
  /** Its pod was replaced (same volume): the old pod's host token no longer works. */
726
- "sandbox.relaunched": z.object({ hostEpoch: z.number().int() }).passthrough(),
1031
+ "environment.relaunched": z.object({ hostEpoch: z.number().int() }).passthrough(),
727
1032
  /** Its volume or node is gone: turns are refused until a reset. */
728
- "sandbox.lost": z.object({ reason: z.string() }).passthrough(),
1033
+ "environment.lost": z.object({ reason: z.string() }).passthrough(),
729
1034
  /** Reset: a new pod on a new, empty volume. */
730
- "sandbox.reset": z.object({ volumeGeneration: z.number().int() }).passthrough(),
1035
+ "environment.reset": z.object({ volumeGeneration: z.number().int() }).passthrough(),
731
1036
  /** The pod did not become ready. */
732
- "sandbox.failed": z.object({ reason: z.string() }).passthrough(),
1037
+ "environment.failed": z.object({ reason: z.string() }).passthrough(),
1038
+ /** Forked into Environment `to`: its disk started from version `disk`, `secrets` were copied. */
1039
+ "environment.forked": z
1040
+ .object({
1041
+ to: z.string(),
1042
+ disk: z.number().int().positive().nullable(),
1043
+ manifest: z.object({ name: z.string(), version: z.number().int().positive() }).strict().optional(),
1044
+ secrets: z.number().int().nonnegative(),
1045
+ })
1046
+ .passthrough(),
1047
+ /** A connection through egress-gate, with the turns running as it opened (D67). */
1048
+ "environment.egress": EgressConnectionPayloadSchema,
733
1049
  };
734
- /** One lifecycle event on a sandbox's stream, numbered from 0. */
735
- export const SandboxEventSchema = z
1050
+ /** One lifecycle event on an Environment's stream, numbered from 0. */
1051
+ export const EnvironmentEventSchema = z
736
1052
  .object({
737
- schema: z.literal(SANDBOX_EVENT_SCHEMA),
1053
+ schema: z.literal(ENVIRONMENT_EVENT_SCHEMA),
738
1054
  eventId: z.string(),
739
1055
  tenantId: z.string(),
740
- sandboxId: z.string(),
1056
+ environmentId: z.string(),
741
1057
  seq: z.number().int().nonnegative(),
742
1058
  time: z.string(),
743
- type: z.enum(SANDBOX_EVENT_TYPES),
1059
+ type: z.enum(ENVIRONMENT_EVENT_TYPES),
744
1060
  payload: z.record(z.string(), z.unknown()),
745
1061
  })
746
1062
  .strict();
747
- export const ListSandboxEventsResponseSchema = z
748
- .object({ events: z.array(SandboxEventSchema) })
1063
+ export const ListEnvironmentEventsResponseSchema = z
1064
+ .object({ events: z.array(EnvironmentEventSchema) })
749
1065
  .strict();
750
- /**
751
- * `PutSessionRequest.sandbox`: `false` for none, `{ id }` to attach a sandbox resource (Host
752
- * feature `sandboxes`), `{ session }` to share another session's sandbox, or an inline sandbox.
753
- * Omitted means the Tenant's default.
754
- */
755
- export const SandboxRequestSchema = z.union([
756
- z.literal(false),
757
- z.object({ id: SandboxIdSchema }).strict(),
758
- z.object({ session: z.string().min(1) }).strict(),
759
- SandboxInlineRequestSchema,
760
- ]);
761
1066
  export const PutSessionRequestSchema = z
762
1067
  .object({
763
1068
  requestId: RequestIdSchema,
764
1069
  agentId: z.string().min(1),
765
1070
  ownerUserId: z.string().min(1),
766
1071
  info: jsonObject.optional(),
767
- vaultIds: z.array(z.string().min(1)).optional(),
768
- credentialSelections: z.array(CredentialSelectionSchema).optional(),
769
- /** The session's sandbox; see `SandboxRequestSchema`. Fixed once the session exists. */
770
- sandbox: SandboxRequestSchema.optional(),
1072
+ /**
1073
+ * The Environment the session runs in: its sandbox, and its vault's credentials for the
1074
+ * session's shell, MCP servers and HTTP tools. Omitted: no sandbox and no credentials.
1075
+ * Fixed once the session exists.
1076
+ */
1077
+ environment: EnvironmentIdSchema.optional(),
771
1078
  })
772
1079
  .strict();
773
1080
  /** The hosts a harness can run on (blueprint D38). */
774
- export const SANDBOX_PLACEMENT_HOSTS = ["harness-container", "sandbox"];
1081
+ export const PLACEMENT_HOSTS = ["harness-container", "sandbox"];
775
1082
  /**
776
- * A Tenant's sandbox configuration (Tenant setting `sandbox.config`): what a session gets when
777
- * it names no sandbox, and the limits every session's sandbox must fit.
1083
+ * A Tenant's Environment settings (Tenant setting `environments.config`): the limits every
1084
+ * Environment's recipe must fit, the pods' stop grace, and where harnesses may run.
778
1085
  */
779
- export const TenantSandboxConfigSchema = z
1086
+ export const TenantEnvironmentsConfigSchema = z
780
1087
  .object({
781
- /** `none` (the default when unset), `virtual`, or an inline sandbox. */
782
- default: z
783
- .union([z.literal("none"), z.literal("virtual"), SandboxInlineRequestSchema])
784
- .optional(),
785
1088
  limits: z
786
1089
  .object({
787
- /** Hosts a sandbox may allow. Default: package registries and code hosts. */
788
- network: z.array(sandboxHostSchema).optional(),
789
- /** The most a session may ask for. */
790
- resources: sandboxResourcesSchema.optional(),
791
- /** What a session gets when it asks for nothing. */
792
- defaultResources: sandboxResourcesSchema.optional(),
793
- /** Stop compute after this long without use. */
794
- idle: z
795
- .string()
796
- .refine((value) => parseSandboxDuration(value) !== undefined, {
797
- message: "idle must be a duration such as 30s, 15m or 1h",
798
- })
799
- .optional(),
800
- /** The most sandbox resources (`PUT /v1/sandboxes/{id}`) the Tenant may hold. Default 100. */
801
- sandboxes: z.number().int().min(0).max(100_000).optional(),
802
- /** Pods: the longest `lifecycle.ttl` a sandbox may ask for. Default none (no limit). */
803
- ttl: sandboxDurationSchema("limits.ttl").optional(),
1090
+ /** Hosts an Environment may allow. Default: package registries and code hosts. */
1091
+ network: z.array(hostPatternSchema).optional(),
1092
+ /** The most an Environment may ask for. */
1093
+ resources: resourcesSchema.optional(),
1094
+ /** What an Environment gets when it asks for nothing. */
1095
+ defaultResources: resourcesSchema.optional(),
1096
+ /** Stop compute after this long without use; an Environment's `lifecycle.idle` is at most this. */
1097
+ idle: durationSchema("limits.idle").optional(),
1098
+ /** The most Environments the Tenant may hold. Default 100. */
1099
+ environments: z.number().int().min(0).max(100_000).optional(),
804
1100
  })
805
1101
  .strict()
806
1102
  .optional(),
807
- /** Pods: what happens at expiry and how long a pod has to stop. Read at every timer. */
1103
+ /** Pods: how long a pod has to stop. Read at every timer. */
808
1104
  lifecycle: z
809
1105
  .object({
810
- /** `retain` (default) keeps the volume after the TTL; `delete` deletes the sandbox. */
811
- onExpiry: z.enum(["retain", "delete"]).optional(),
812
1106
  /** The pod's grace period to stop, at most 30s. Default 10s. */
813
- stopGrace: sandboxDurationSchema("lifecycle.stopGrace")
1107
+ stopGrace: durationSchema("lifecycle.stopGrace")
814
1108
  .refine((value) => (parseSandboxDuration(value) ?? 0) <= 30_000, {
815
1109
  message: "lifecycle.stopGrace is at most 30s",
816
1110
  })
@@ -820,50 +1114,24 @@ export const TenantSandboxConfigSchema = z
820
1114
  .optional(),
821
1115
  /**
822
1116
  * Where each harness may run (blueprint D38), by harness id (`nylorun`, or `*` for the rest):
823
- * `harness-container` (the Runtime's harness) and `sandbox` (the engine in a pod sandbox).
1117
+ * `harness-container` (the Runtime's harness) and `sandbox` (the engine in a pod).
824
1118
  * Default `{ "*": { hosts: ["harness-container", "sandbox"] } }`. Checked when a session
825
- * opens; a host left out is refused (`placement_refused`).
1119
+ * opens; a host left out is refused (`placement_refused`). `"*": { hosts: [] }` refuses every
1120
+ * harness the map does not name.
826
1121
  */
827
1122
  placement: z
828
- .record(z.string().min(1), z.object({ hosts: z.array(z.enum(SANDBOX_PLACEMENT_HOSTS)).min(1) }).strict())
1123
+ .record(z.string().min(1), z.object({ hosts: z.array(z.enum(PLACEMENT_HOSTS)) }).strict())
829
1124
  .optional(),
830
1125
  })
831
1126
  .strict();
832
- /** `PUT /v1/tenant/sandbox`: replaces the Tenant's sandbox configuration. */
833
- export const PutTenantSandboxRequestSchema = TenantSandboxConfigSchema.extend({
1127
+ /** `PUT /v1/tenant/sandbox`: replaces the Tenant's Environment settings (`environments.config`). */
1128
+ export const PutTenantEnvironmentsRequestSchema = TenantEnvironmentsConfigSchema.extend({
834
1129
  requestId: RequestIdSchema.optional(),
835
1130
  }).strict();
836
1131
  const vaultWriteBase = {
837
1132
  requestId: RequestIdSchema,
838
1133
  idempotencyKey: IdempotencyKeySchema,
839
1134
  };
840
- /** The owner of every installation vault (`scope: "installation"`); a reserved subject. */
841
- export const INSTALLATION_OWNER = "installation";
842
- export const CreateVaultRequestSchema = z
843
- .object({
844
- ...vaultWriteBase,
845
- name: z.string().min(1),
846
- /**
847
- * `user` (the default): one person's vault, owned by `ownerUserId`. `installation`: the
848
- * installation's own vault, owned by `installation`, which any session may attach;
849
- * management keys only (the Management API).
850
- */
851
- scope: z.enum(["user", "installation"]).optional(),
852
- /** Required for a `user` vault; absent (or `installation`) for an installation vault. */
853
- ownerUserId: z.string().min(1).optional(),
854
- metadata: z.record(z.string(), z.string()).optional(),
855
- })
856
- .strict()
857
- .superRefine((value, ctx) => {
858
- if ((value.scope ?? "user") === "user") {
859
- if (value.ownerUserId === undefined)
860
- ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "ownerUserId is required for a user vault" });
861
- else if (value.ownerUserId === INSTALLATION_OWNER)
862
- ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "installation is reserved for installation vaults" });
863
- }
864
- else if (value.ownerUserId !== undefined && value.ownerUserId !== INSTALLATION_OWNER)
865
- ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "An installation vault is owned by installation" });
866
- });
867
1135
  /** An RFC 9110 field name. */
868
1136
  export const HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
869
1137
  const CredentialHeaderNameSchema = z
@@ -1002,88 +1270,295 @@ const EnvironmentValueSchema = z
1002
1270
  .min(1)
1003
1271
  .max(8192)
1004
1272
  .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. */
1274
+ export const TOOL_SECRET_NAME_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
1005
1275
  /**
1006
- * A credential for the server at `url` (the URL a manifest names): `bearer` sends
1007
- * `Authorization: Bearer <token>`, `headers` its header map (R2b C2). The header names may not be
1008
- * the MCP transport's headers or `Nylorun-*`.
1276
+ * `PUT /v1/environments/{environmentId}/secrets/{name}` (D56): creates or replaces one credential
1277
+ * in the Environment's vault. For `environment_secret` and `environment_variable` the name is
1278
+ * the variable's name (a POSIX name, not reserved); for `bearer` and `headers` it is a label.
1279
+ * The same name and type keeps the credential and re-seals its value and binding; another type
1280
+ * replaces it. Values are write-only: no route reads them back. Two `environment_secret`
1281
+ * credentials bound to one host, or two `bearer`/`headers` credentials for one URL, are
1282
+ * `409 credential_conflict`.
1009
1283
  */
1010
- export const CreateCredentialRequestSchema = z
1284
+ export const PutEnvironmentSecretRequestSchema = z.discriminatedUnion("type", [
1285
+ z
1286
+ .object({
1287
+ requestId: RequestIdSchema.optional(),
1288
+ type: z.literal("environment_secret"),
1289
+ value: EnvironmentValueSchema,
1290
+ allowedHosts: AllowedHostsSchema,
1291
+ inject: EnvironmentSecretInjectSchema.optional(),
1292
+ })
1293
+ .strict(),
1294
+ z
1295
+ .object({
1296
+ requestId: RequestIdSchema.optional(),
1297
+ type: z.literal("environment_variable"),
1298
+ value: EnvironmentValueSchema,
1299
+ })
1300
+ .strict(),
1301
+ z
1302
+ .object({
1303
+ requestId: RequestIdSchema.optional(),
1304
+ type: z.literal("bearer"),
1305
+ url: z.string().min(1),
1306
+ value: z.string().min(1),
1307
+ ...credentialRouting,
1308
+ })
1309
+ .strict(),
1310
+ z
1311
+ .object({
1312
+ requestId: RequestIdSchema.optional(),
1313
+ type: z.literal("headers"),
1314
+ url: z.string().min(1),
1315
+ headers: CredentialHeadersSchema,
1316
+ ...credentialRouting,
1317
+ })
1318
+ .strict(),
1319
+ ]);
1320
+ /**
1321
+ * A secret write on an Environment whose manifest declares the secret's slot (D64): only the
1322
+ * value, `value` (or `headers` for a `headers` slot). Its type and binding come from the slot.
1323
+ */
1324
+ export const PutEnvironmentSecretValueRequestSchema = z
1011
1325
  .object({
1012
- ...vaultWriteBase,
1013
- name: z.string().min(1),
1014
- auth: z.discriminatedUnion("type", [
1015
- z
1016
- .object({
1017
- type: z.literal("bearer"),
1018
- url: z.string().min(1),
1019
- token: z.string().min(1),
1020
- ...credentialRouting,
1021
- })
1022
- .strict(),
1023
- z
1024
- .object({
1025
- type: z.literal("headers"),
1026
- url: z.string().min(1),
1027
- headers: CredentialHeadersSchema,
1028
- ...credentialRouting,
1029
- })
1030
- .strict(),
1031
- z
1032
- .object({
1033
- type: z.literal("environment_secret"),
1034
- secretName: EnvironmentNameSchema,
1035
- secretValue: EnvironmentValueSchema,
1036
- allowedHosts: AllowedHostsSchema,
1037
- inject: EnvironmentSecretInjectSchema.optional(),
1038
- })
1039
- .strict(),
1040
- z
1041
- .object({
1042
- type: z.literal("environment_variable"),
1043
- variableName: EnvironmentNameSchema,
1044
- variableValue: EnvironmentValueSchema,
1045
- })
1046
- .strict(),
1047
- ]),
1326
+ requestId: RequestIdSchema.optional(),
1327
+ value: z.string().min(1).max(8192).optional(),
1328
+ headers: CredentialHeadersSchema.optional(),
1329
+ })
1330
+ .strict()
1331
+ .refine((body) => (body.value === undefined) !== (body.headers === undefined), {
1332
+ message: "Send value, or headers for a headers secret",
1333
+ });
1334
+ /** Whether `name` may name a secret of `type` (`PUT .../secrets/{name}`); a message when not. */
1335
+ export function environmentSecretNameError(type, name) {
1336
+ if (type === "environment_secret" || type === "environment_variable") {
1337
+ if (!ENVIRONMENT_NAME_PATTERN.test(name))
1338
+ return "An environment variable name is a letter or _ followed by letters, digits or _";
1339
+ if (isReservedEnvironmentName(name))
1340
+ return `${name} is a reserved environment variable name`;
1341
+ return undefined;
1342
+ }
1343
+ return TOOL_SECRET_NAME_PATTERN.test(name)
1344
+ ? undefined
1345
+ : "A credential name is 1-64 letters, digits, '.', '_' and '-'";
1346
+ }
1347
+ // --- Environment manifests (protocol 14, D63 to D65) -----------------------------------------
1348
+ const slotBase = {
1349
+ /** Whether a session whose agent needs it may open without it. Default false. */
1350
+ required: z.boolean().optional(),
1351
+ description: z.string().max(500).optional(),
1352
+ };
1353
+ /**
1354
+ * One secret an Environment of a kind needs (D64): its type and binding, never its value. The
1355
+ * value is written into each Environment's vault (`PUT /v1/environments/{id}/secrets/{name}`
1356
+ * with `{ value }`, or `{ headers }` for `headers`), and the binding comes from here.
1357
+ */
1358
+ export const EnvironmentSecretSlotSchema = z.discriminatedUnion("type", [
1359
+ z
1360
+ .object({
1361
+ type: z.literal("environment_secret"),
1362
+ allowedHosts: AllowedHostsSchema,
1363
+ inject: EnvironmentSecretInjectSchema.optional(),
1364
+ ...slotBase,
1365
+ })
1366
+ .strict(),
1367
+ z.object({ type: z.literal("environment_variable"), ...slotBase }).strict(),
1368
+ z.object({ type: z.literal("bearer"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1369
+ z.object({ type: z.literal("headers"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1370
+ ]);
1371
+ /** The most secret slots one manifest declares. */
1372
+ export const ENVIRONMENT_SECRET_SLOTS_MAX = 64;
1373
+ export const EnvironmentSecretSlotsSchema = z
1374
+ .record(z.string(), EnvironmentSecretSlotSchema)
1375
+ .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) {
1380
+ const error = environmentSecretNameError(slots[name].type, name);
1381
+ if (error)
1382
+ ctx.addIssue({ code: "custom", path: [name], message: error });
1383
+ }
1384
+ });
1385
+ /** The schema version of an environment manifest; the Runtime refuses one it does not know. */
1386
+ export const ENVIRONMENT_MANIFEST_SCHEMA_VERSION = 1;
1387
+ const environmentFields = PutEnvironmentRequestSchema.shape;
1388
+ /**
1389
+ * An environment manifest (protocol 14, D63): a named, versioned definition of a kind of
1390
+ * Environment, saved like an agent (`PUT /v1/environment-manifests/{name}`). It holds what every
1391
+ * Environment made from it shares; an Environment's id, labels, owner guard, disk and secret
1392
+ * values are its own. Written as a JSON file with `$schema`, which clients drop before saving.
1393
+ */
1394
+ export const EnvironmentManifestSchema = z
1395
+ .object({
1396
+ manifestSchemaVersion: z.literal(ENVIRONMENT_MANIFEST_SCHEMA_VERSION, {
1397
+ error: (issue) => `manifestSchemaVersion ${JSON.stringify(issue.input)} is not one this Runtime reads: use ${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`,
1398
+ }),
1399
+ name: EnvironmentManifestNameSchema,
1400
+ description: z.string().max(1024).optional(),
1401
+ kind: environmentFields.kind,
1402
+ image: environmentFields.image,
1403
+ resources: environmentFields.resources,
1404
+ storage: environmentFields.storage,
1405
+ network: environmentFields.network,
1406
+ harness: environmentFields.harness,
1407
+ lifecycle: environmentFields.lifecycle,
1408
+ setup: environmentFields.setup,
1409
+ files: environmentFields.files,
1410
+ secrets: EnvironmentSecretSlotsSchema.optional(),
1411
+ })
1412
+ .strict();
1413
+ /** `PUT /v1/environment-manifests/{name}`: the manifest, whose `name` is the path's. */
1414
+ export const PutEnvironmentManifestRequestSchema = EnvironmentManifestSchema.extend({
1415
+ requestId: RequestIdSchema.optional(),
1416
+ }).strict();
1417
+ /** Who saved a version: the subject a request acted for, else `application`. */
1418
+ export const EnvironmentManifestSavedBySchema = z.object({ actor: z.string() }).strict();
1419
+ /** One version of an environment manifest. */
1420
+ export const EnvironmentManifestViewSchema = z
1421
+ .object({
1422
+ name: z.string(),
1423
+ version: z.number().int().positive(),
1424
+ /** The hash of `manifest`: equal manifests have equal hashes. */
1425
+ hash: z.string(),
1426
+ manifest: EnvironmentManifestSchema,
1427
+ savedBy: EnvironmentManifestSavedBySchema,
1428
+ createdAt: z.string(),
1429
+ /** How many Environments were made from this version. */
1430
+ environments: z.number().int().nonnegative(),
1048
1431
  })
1049
1432
  .strict();
1433
+ /** `GET /v1/environment-manifests`: each manifest's latest version, by name. */
1434
+ export const ListEnvironmentManifestsResponseSchema = z
1435
+ .object({ manifests: z.array(EnvironmentManifestViewSchema) })
1436
+ .strict();
1437
+ /** `GET /v1/environment-manifests/{name}/versions`: every version, newest first. */
1438
+ export const EnvironmentManifestVersionsSchema = z
1439
+ .object({
1440
+ name: z.string(),
1441
+ latest: z.number().int().positive(),
1442
+ versions: z.array(z
1443
+ .object({
1444
+ version: z.number().int().positive(),
1445
+ hash: z.string(),
1446
+ savedBy: EnvironmentManifestSavedBySchema,
1447
+ createdAt: z.string(),
1448
+ environments: z.number().int().nonnegative(),
1449
+ })
1450
+ .strict()),
1451
+ })
1452
+ .strict();
1453
+ /** Something a save would do that the saver should know: never a refusal. */
1454
+ export const EnvironmentManifestWarningSchema = z
1455
+ .object({ code: z.string(), message: z.string() })
1456
+ .strict();
1050
1457
  /**
1051
- * Replaces a credential's secret; its type and URL stay. `via` and `identity` are kept unless
1052
- * given (`null` removes one).
1458
+ * `PUT /v1/environment-manifests/{name}?dryRun=true`: what saving it would do, with nothing
1459
+ * saved. `errors` lists every reason the Runtime would refuse it (the Tenant's limits, for one);
1460
+ * a save with errors is `400`. `behind` counts the Environments made from an older version than
1461
+ * the one it would save. No Environment changes when a version is saved (D63).
1053
1462
  */
1054
- export const RotateCredentialRequestSchema = z
1463
+ export const EnvironmentManifestPlanSchema = z
1055
1464
  .object({
1056
- ...vaultWriteBase,
1057
- auth: z.discriminatedUnion("type", [
1058
- z
1059
- .object({
1060
- type: z.literal("bearer"),
1061
- token: z.string().min(1),
1062
- ...credentialRoutingChange,
1063
- })
1064
- .strict(),
1065
- z
1066
- .object({
1067
- type: z.literal("headers"),
1068
- headers: CredentialHeadersSchema,
1069
- ...credentialRoutingChange,
1070
- })
1071
- .strict(),
1072
- z.object({ type: z.literal("environment_secret"), secretValue: EnvironmentValueSchema }).strict(),
1073
- z.object({ type: z.literal("environment_variable"), variableValue: EnvironmentValueSchema }).strict(),
1074
- ]),
1465
+ name: z.string(),
1466
+ /** The latest version now, or `null` for a new manifest. */
1467
+ from: z.number().int().positive().nullable(),
1468
+ /** The version a save would answer: `from` when nothing changed. */
1469
+ to: z.number().int().positive(),
1470
+ unchanged: z.boolean(),
1471
+ changes: z.array(z.object({ path: z.string(), from: z.unknown().optional(), to: z.unknown().optional() }).strict()),
1472
+ warnings: z.array(EnvironmentManifestWarningSchema),
1473
+ errors: z.array(z.string()),
1474
+ behind: z.number().int().nonnegative(),
1475
+ })
1476
+ .strict();
1477
+ /** `PUT /v1/environment-manifests/{name}`: the version saved (or the latest, unchanged). */
1478
+ export const SaveEnvironmentManifestResponseSchema = z
1479
+ .object({
1480
+ manifest: EnvironmentManifestViewSchema,
1481
+ unchanged: z.boolean(),
1482
+ warnings: z.array(EnvironmentManifestWarningSchema),
1483
+ })
1484
+ .strict();
1485
+ export const DeleteEnvironmentManifestResponseSchema = z
1486
+ .object({ name: z.string(), deleted: z.boolean() })
1487
+ .strict();
1488
+ /**
1489
+ * `POST /v1/environments/{id}/fork` (Q15): how an Environment gets a new manifest version. The
1490
+ * fork is a new Environment, made from the version, its disk started from a version of the
1491
+ * source's disk and its secrets copied inside the Runtime. The source keeps what it runs, its
1492
+ * disk and its sessions.
1493
+ */
1494
+ export const ForkEnvironmentRequestSchema = z
1495
+ .object({
1496
+ requestId: RequestIdSchema.optional(),
1497
+ /** The new Environment's id. */
1498
+ id: EnvironmentIdSchema,
1499
+ /** `name` or `name@n`; default the source's manifest at its latest version. */
1500
+ manifest: EnvironmentManifestRefSchema.optional(),
1501
+ /** Where its disk starts: `latest` (a snapshot taken first; the default), a version, or `empty`. */
1502
+ disk: z.union([z.literal("latest"), z.literal("empty"), z.number().int().positive()]).optional(),
1503
+ /** `copy` (the default): the source's secrets the new manifest declares (all, without slots). */
1504
+ secrets: z.enum(["copy", "none"]).optional(),
1505
+ labels: EnvironmentLabelsSchema.optional(),
1506
+ ownerUserId: z.string().min(1).nullable().optional(),
1507
+ /** Answer the plan and make nothing. */
1508
+ dryRun: z.boolean().optional(),
1509
+ })
1510
+ .strict();
1511
+ /** What a fork does (or, with `dryRun`, would do). */
1512
+ export const EnvironmentForkPlanSchema = z
1513
+ .object({
1514
+ source: z.string(),
1515
+ id: z.string(),
1516
+ kind: z.enum(ENVIRONMENT_KINDS),
1517
+ /** The manifest version it is made from, or `null` for the source's inline fields. */
1518
+ manifest: z.object({ name: z.string(), version: z.number().int().positive() }).strict().nullable(),
1519
+ /** The disk version it starts from: `latest` in a dry run (the snapshot is taken at the fork); `null` for an empty disk. */
1520
+ disk: z.union([z.number().int().positive(), z.literal("latest")]).nullable(),
1521
+ /** Whether the new manifest's setup runs on the copied disk: it differs from what the source runs. */
1522
+ setup: z.boolean(),
1523
+ secrets: z
1524
+ .object({
1525
+ /** Copied, by name. */
1526
+ copied: z.array(z.string()),
1527
+ /** The source's secrets the new manifest does not declare: left behind. */
1528
+ dropped: z.array(z.string()),
1529
+ /** Required slots of the new manifest no copied secret fills. */
1530
+ missing: z.array(z.string()),
1531
+ })
1532
+ .strict(),
1533
+ /** How what it runs differs from what the source runs. */
1534
+ changes: z.array(z.object({ path: z.string(), from: z.unknown().optional(), to: z.unknown().optional() }).strict()),
1535
+ /** The source's sessions: they stay on it. */
1536
+ sessions: z.number().int().nonnegative(),
1075
1537
  })
1076
1538
  .strict();
1539
+ /** `POST /v1/environments/{id}/fork`: the new Environment and the plan it ran, or with `dryRun` the plan only. */
1540
+ export const ForkEnvironmentResponseSchema = z.union([
1541
+ z.object({ dryRun: z.literal(true), plan: EnvironmentForkPlanSchema }).strict(),
1542
+ z.object({ environment: EnvironmentViewSchema, plan: EnvironmentForkPlanSchema }).strict(),
1543
+ ]);
1544
+ /**
1545
+ * What a model may read (protocol 12): `text` always; `image`, `pdf`, `office` (Word, Excel,
1546
+ * PowerPoint), `audio` and `video` when its catalog entry or the operator says so. In this order.
1547
+ */
1548
+ export const MODEL_INPUTS = ["text", "image", "pdf", "office", "audio", "video"];
1549
+ export const ModelInputSchema = z.enum(MODEL_INPUTS);
1077
1550
  /**
1078
1551
  * What the Runtime cannot learn from a custom OpenAI-compatible endpoint (Model Calls §7):
1079
- * its context window and output limit, whether it reasons, and pi-ai `compat` settings
1080
- * (`thinkingFormat`, `thinkingTokenBudgetField`, `chatTemplateKwargs`, …).
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`, …).
1081
1555
  */
1082
1556
  export const CustomModelSettingsSchema = z
1083
1557
  .object({
1084
1558
  contextWindow: z.number().int().min(1024).optional(),
1085
1559
  maxTokens: z.number().int().min(1).optional(),
1086
1560
  reasoning: z.boolean().optional(),
1561
+ inputs: z.array(ModelInputSchema).optional(),
1087
1562
  compat: z.record(z.string(), z.unknown()).optional(),
1088
1563
  })
1089
1564
  .strict();
@@ -1121,34 +1596,25 @@ export const SelectHostModelRequestSchema = z
1121
1596
  baseUrl: z.string().min(1).optional(),
1122
1597
  })
1123
1598
  .strict();
1124
- export const VaultInfoSchema = z
1125
- .object({
1126
- id: z.string(),
1127
- name: z.string(),
1128
- ownerUserId: z.string(),
1129
- metadata: z.record(z.string(), z.string()).optional(),
1130
- createdAt: z.string(),
1131
- })
1132
- .strict();
1133
- export const CredentialInfoSchema = z
1599
+ export const ENVIRONMENT_SECRET_TYPES = [
1600
+ "bearer",
1601
+ "headers",
1602
+ "environment_secret",
1603
+ "environment_variable",
1604
+ ];
1605
+ /**
1606
+ * One credential of an Environment's vault, never its value: what it is bound to (the server
1607
+ * `url` for `bearer` and `headers`; the hosts and header for `environment_secret`).
1608
+ */
1609
+ export const EnvironmentSecretViewSchema = z
1134
1610
  .object({
1135
- id: z.string(),
1136
- vaultId: z.string(),
1137
1611
  name: z.string(),
1138
- type: z.enum(["bearer", "headers", "environment_secret", "environment_variable"]),
1139
- /**
1140
- * What the credential is bound to: the server `url` for `bearer` and `headers`; the variable
1141
- * name and hosts for `environment_secret` (R2c); the name and its plain value for
1142
- * `environment_variable`, which is not a secret. A secret's value is never shown.
1143
- */
1612
+ type: z.enum(ENVIRONMENT_SECRET_TYPES),
1144
1613
  binding: z
1145
1614
  .object({
1146
1615
  url: z.string().optional(),
1147
- secretName: z.string().optional(),
1148
1616
  allowedHosts: z.array(z.string()).optional(),
1149
1617
  inject: EnvironmentSecretInjectSchema.optional(),
1150
- variableName: z.string().optional(),
1151
- variableValue: z.string().optional(),
1152
1618
  })
1153
1619
  .strict(),
1154
1620
  /** A `headers` credential's header names (lower case), never their values. */
@@ -1159,13 +1625,15 @@ export const CredentialInfoSchema = z
1159
1625
  rotatedAt: z.string().optional(),
1160
1626
  })
1161
1627
  .strict();
1628
+ export const ListEnvironmentSecretsResponseSchema = z
1629
+ .object({ secrets: z.array(EnvironmentSecretViewSchema) })
1630
+ .strict();
1162
1631
  /** The MCP transports a preview speaks: a manifest's remote server types. */
1163
1632
  export const MCP_PREVIEW_TYPES = ["streamable-http", "sse"];
1164
1633
  /**
1165
1634
  * `POST /v1/tenant/mcp/preview` (R2b C12): what a remote MCP server offers, before an agent
1166
- * names it. The Runtime connects with the installation vault's credential for `url` (one
1167
- * credential across the installation vaults, or the one in `vaultId`), lists the tools and
1168
- * closes the connection; it never calls a tool.
1635
+ * names it. The Runtime connects with the credential for `url` in the vault of `environmentId`
1636
+ * (none without one), lists the tools and closes the connection; it never calls a tool.
1169
1637
  */
1170
1638
  export const McpPreviewRequestSchema = z
1171
1639
  .object({
@@ -1192,8 +1660,8 @@ export const McpPreviewRequestSchema = z
1192
1660
  * host's name before its top-level domain (`linear` for `mcp.linear.app`).
1193
1661
  */
1194
1662
  name: modelFacingName("MCP server").optional(),
1195
- /** The installation vault whose credential to send. Default: every installation vault. */
1196
- vaultId: z.string().min(1).optional(),
1663
+ /** The Environment whose vault's credential for `url` to send. Default: none is sent. */
1664
+ environmentId: EnvironmentIdSchema.optional(),
1197
1665
  })
1198
1666
  .strict();
1199
1667
  /** One tool a preview found. */
@@ -1216,7 +1684,7 @@ export const McpPreviewToolSchema = z
1216
1684
  /**
1217
1685
  * A preview (R2b C12). A server that answered `401` is `authRequired`, with its RFC 9728
1218
1686
  * protected-resource metadata when it publishes any: it needs a person's sign-in or a key the
1219
- * installation vaults do not hold, so reach it with a key or through a gateway (`via`).
1687
+ * Environment's vault does not hold, so reach it with a key or through a gateway (`via`).
1220
1688
  */
1221
1689
  export const McpPreviewSchema = z
1222
1690
  .object({
@@ -1224,7 +1692,7 @@ export const McpPreviewSchema = z
1224
1692
  name: z.string(),
1225
1693
  url: z.string(),
1226
1694
  type: z.enum(MCP_PREVIEW_TYPES),
1227
- /** True when an installation vault's credential was sent. */
1695
+ /** True when a credential of the Environment's vault was sent. */
1228
1696
  credentialSent: z.boolean(),
1229
1697
  /** The server's `initialize` answer: its name, version and title. */
1230
1698
  serverInfo: z.record(z.string(), z.unknown()).optional(),
@@ -1244,6 +1712,70 @@ export const McpPreviewSchema = z
1244
1712
  .optional(),
1245
1713
  })
1246
1714
  .strict();
1715
+ /**
1716
+ * `POST /v1/tenant/credential-coverage`: which credential each of a saved agent's remote MCP
1717
+ * servers and HTTP tools would get in a session that names `environmentId`, decided as the
1718
+ * session's tool calls decide it (by URL). It reads no secret and calls no server.
1719
+ */
1720
+ export const CredentialCoverageRequestSchema = z
1721
+ .object({
1722
+ requestId: RequestIdSchema.optional(),
1723
+ /** A saved agent or flow agent. */
1724
+ agentId: z.string().min(1),
1725
+ /** The Environment the session would name. Default: none (every entry is `missing`). */
1726
+ environmentId: EnvironmentIdSchema.optional(),
1727
+ })
1728
+ .strict();
1729
+ /** A credential coverage names: where it is, never its value. */
1730
+ export const CoverageCredentialSchema = z
1731
+ .object({
1732
+ environmentId: z.string(),
1733
+ /** The secret's name in the Environment's vault. */
1734
+ name: z.string(),
1735
+ /** Where the credential sends the requests instead of the URL (a gateway). */
1736
+ via: z.string().optional(),
1737
+ })
1738
+ .strict();
1739
+ /**
1740
+ * What a session would send for one URL an agent declares:
1741
+ * - `covered`: the Environment's vault holds a credential for it (`credential`);
1742
+ * - `missing`: it holds none: an MCP server is called without a credential (a public server
1743
+ * needs none), an HTTP tool fails with `http.credential`.
1744
+ */
1745
+ export const COVERAGE_STATUSES = ["covered", "missing"];
1746
+ /** One remote MCP server or HTTP tool credential an agent declares. */
1747
+ export const CredentialCoverageEntrySchema = z
1748
+ .object({
1749
+ kind: z.enum(["mcp", "http"]),
1750
+ /** The agent that declares it: absent for the agent itself, else a subagent or a flow's agent. */
1751
+ agentId: z.string().optional(),
1752
+ /** A flow's HTTP stage or HTTP verifier: its stage key. */
1753
+ stage: z.string().optional(),
1754
+ /** The MCP server's name, or the HTTP tool's (or stage's) name. */
1755
+ name: z.string(),
1756
+ /** The server's name, or the HTTP tool's `credential`. */
1757
+ serverName: z.string(),
1758
+ /** The URL a credential must be bound to, as the vault compares it. */
1759
+ url: z.string(),
1760
+ /** True when the call fails without a credential (an HTTP tool's `credential`). */
1761
+ required: z.boolean(),
1762
+ status: z.enum(COVERAGE_STATUSES),
1763
+ /** The credential the session would send, when `covered`. */
1764
+ credential: CoverageCredentialSchema.optional(),
1765
+ /** What the session would do, in a sentence. */
1766
+ message: z.string(),
1767
+ })
1768
+ .strict();
1769
+ export const CredentialCoverageSchema = z
1770
+ .object({
1771
+ agentId: z.string(),
1772
+ environmentId: z.string().nullable(),
1773
+ /** True when every entry is `covered`. */
1774
+ complete: z.boolean(),
1775
+ /** One per declared MCP server and HTTP tool credential: the agent's, then its agents'. */
1776
+ entries: z.array(CredentialCoverageEntrySchema),
1777
+ })
1778
+ .strict();
1247
1779
  const commandBase = {
1248
1780
  requestId: RequestIdSchema,
1249
1781
  idempotencyKey: IdempotencyKeySchema,
@@ -1331,8 +1863,16 @@ export const SessionCommandSchema = z.union([
1331
1863
  export const SessionEventBodySchema = SessionCommandSchema;
1332
1864
  /** The envelope every session event carries (`nylorun.event/2`, Durable Streams §9.5). */
1333
1865
  export const EVENT_SCHEMA = "nylorun.event/2";
1334
- /** Who wrote an event. v1 writes `loop` (the engine) and `api` (commands and results). */
1866
+ /**
1867
+ * Who wrote an event (track R4, R4.9): the writer says so, not the event's type. `client` is a
1868
+ * command over the Runtime API (its `principal` says who sent it), `core` is core's own logic
1869
+ * (settle, sweeps, the flow host, exports, the tools core serves), `harness` is what a harness
1870
+ * reported (`source.id` is its harness id, `runId` its run), and the gates are themselves.
1871
+ * `loop` and `api` are what events written before R4 say.
1872
+ */
1335
1873
  export const EventSourceKindSchema = z.enum([
1874
+ "client",
1875
+ "core",
1336
1876
  "model-gate",
1337
1877
  "tool-gate",
1338
1878
  "egress-gate",
@@ -1348,7 +1888,12 @@ export const EventSourceKindSchema = z.enum([
1348
1888
  "human",
1349
1889
  "api",
1350
1890
  ]);
1351
- /** How far an event can be trusted, by who could forge it. v1 writes `observed` only. */
1891
+ /**
1892
+ * How far an event can be trusted, by who could forge it. `observed`: the Runtime saw it itself
1893
+ * (commands, the tools core serves, gate records, core's settle). `claimed`: a harness reported
1894
+ * it (an assistant message, a tool result it ran, its turn's end), so it is the harness's claim;
1895
+ * the Model Gate's usage row is the measured record of the same model call.
1896
+ */
1352
1897
  export const EvidenceClassSchema = z.enum([
1353
1898
  "observed",
1354
1899
  "measured",
@@ -1356,6 +1901,13 @@ export const EvidenceClassSchema = z.enum([
1356
1901
  "claimed",
1357
1902
  "asserted",
1358
1903
  ]);
1904
+ /** A command's sender (R4.9): from the request's credential, never from its body. */
1905
+ export const EventPrincipalSchema = z
1906
+ .object({
1907
+ kind: z.enum(["application", "subject", "flow-host", "core"]),
1908
+ id: z.string(),
1909
+ })
1910
+ .strict();
1359
1911
  /**
1360
1912
  * The envelope fields. Not strict: a client strips fields it does not know, so the envelope
1361
1913
  * can grow without a protocol bump.
@@ -1382,6 +1934,8 @@ const eventEnvelope = {
1382
1934
  schemaVersion: z.number().int().positive(),
1383
1935
  source: z.object({ kind: EventSourceKindSchema, id: z.string() }),
1384
1936
  evidence: EvidenceClassSchema,
1937
+ /** Who sent a command (`command.*`, a cancel's `turn.cancelled`), from its credential (R4.9). */
1938
+ principal: EventPrincipalSchema.optional(),
1385
1939
  trace: z
1386
1940
  .object({
1387
1941
  traceId: z.string(),
@@ -1436,9 +1990,49 @@ const toolIds = {
1436
1990
  /** The harness invocation of the call; interactions refer to it. */
1437
1991
  invocationId: z.string().min(1),
1438
1992
  };
1993
+ /**
1994
+ * When a gate served a call (R7.1): its own start and end, as it measured them. Absent when no
1995
+ * gate measured the call (a fixture model, a sandbox or core-served tool, a call refused before
1996
+ * it was sent).
1997
+ */
1998
+ export const GateTimesSchema = z
1999
+ .object({ startedAt: z.string(), endedAt: z.string() })
2000
+ .passthrough();
2001
+ /**
2002
+ * What the Model Gate's meter recorded for a model call (R7.1), from the usage ledger: the
2003
+ * tokens and cost the Runtime counts, beside the `usage` the harness reported. `cachedTokens`
2004
+ * and `costUsd` are absent when zero.
2005
+ */
2006
+ export const MeteredUsageSchema = z
2007
+ .object({
2008
+ inputTokens: z.number().int().nonnegative(),
2009
+ outputTokens: z.number().int().nonnegative(),
2010
+ totalTokens: z.number().int().nonnegative(),
2011
+ cachedTokens: z.number().int().nonnegative().optional(),
2012
+ costUsd: z.number().nonnegative().optional(),
2013
+ })
2014
+ .passthrough();
2015
+ /**
2016
+ * The timing of a model call's outcome (R7.1), on `message.assistant`, `model.failed` and
2017
+ * `context.compacted`. `durationMs` is the journal's window, from the intent to the outcome;
2018
+ * `gate`, `firstTokenMs` and `meteredUsage` are the meter's, absent when no gate metered the
2019
+ * call.
2020
+ */
2021
+ const modelOutcomeFacts = {
2022
+ /** The model call's effect id. */
2023
+ effectId: z.string().min(1).optional(),
2024
+ /** From the intent to the outcome, as the journal saw them. */
2025
+ durationMs: z.number().int().nonnegative().optional(),
2026
+ gate: GateTimesSchema.optional(),
2027
+ /** From the gate's start of the call to the provider's first stream event. */
2028
+ firstTokenMs: z.number().int().nonnegative().optional(),
2029
+ meteredUsage: MeteredUsageSchema.optional(),
2030
+ };
1439
2031
  /**
1440
2032
  * `message.assistant`: one completed model step. `invocationId` is the model call's.
1441
- * `model`, `finishReason` and `usage` are present when the provider reported them.
2033
+ * `model`, `finishReason` and `usage` are present when the provider reported them. A step that
2034
+ * said nothing (no text, no tool calls, as a structured answer) has `text: ""` and no tool
2035
+ * calls: it is in the log for its timing, and is never a message (`isEmptyAssistantMessage`).
1442
2036
  */
1443
2037
  export const AssistantMessagePayloadSchema = z
1444
2038
  .object({
@@ -1457,9 +2051,15 @@ export const AssistantMessagePayloadSchema = z
1457
2051
  input: z.unknown(),
1458
2052
  })
1459
2053
  .passthrough()),
2054
+ ...modelOutcomeFacts,
1460
2055
  ...eventAgent,
1461
2056
  })
1462
2057
  .passthrough();
2058
+ /** True when a `message.assistant` said nothing: no text and no tool calls (R7.1). */
2059
+ export function isEmptyAssistantMessage(payload) {
2060
+ return ((typeof payload.text !== "string" || payload.text === "") &&
2061
+ (payload.toolCalls?.length ?? 0) === 0);
2062
+ }
1463
2063
  /**
1464
2064
  * `model.failed`: a model call that failed in a known way (Model Calls §6.4). The turn
1465
2065
  * then fails with `model.<code>`, or recovers.
@@ -1470,12 +2070,14 @@ export const ModelFailedPayloadSchema = z
1470
2070
  code: z.string().min(1),
1471
2071
  message: z.string(),
1472
2072
  retryable: z.boolean(),
2073
+ ...modelOutcomeFacts,
1473
2074
  ...eventAgent,
1474
2075
  })
1475
2076
  .passthrough();
1476
2077
  /**
1477
2078
  * `context.compacted`: the engine summarized older history to fit the model's window
1478
- * (Model Calls §8). Token counts are estimates.
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.
1479
2081
  */
1480
2082
  export const ContextCompactedPayloadSchema = z
1481
2083
  .object({
@@ -1483,15 +2085,67 @@ export const ContextCompactedPayloadSchema = z
1483
2085
  trigger: z.enum(["threshold", "overflow"]),
1484
2086
  tokensBefore: z.number().int().nonnegative(),
1485
2087
  tokensAfter: z.number().int().nonnegative(),
2088
+ partial: z.literal(true).optional(),
2089
+ ...modelOutcomeFacts,
1486
2090
  ...eventAgent,
1487
2091
  })
1488
2092
  .passthrough();
1489
- /** `tool.completed`: a tool the Runtime ran (HTTP, MCP, sandbox, built-in). `error` for a tool error. */
2093
+ /** How a tool call ended (R5.1): the tool answered, the Runtime ended it, or a cancel did. */
2094
+ 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
+ /**
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`).
2100
+ */
2101
+ export const TOOL_CALL_KINDS = ["mcp", "http", "sandbox", "platform", "harness"];
2102
+ /**
2103
+ * What the Tenant's tool policy did with a tool call (R5 step 2), when it did more than allow
2104
+ * it: `deny` refused it unsent; `ask` held it for a person, who approved it (`approvedBy`, when
2105
+ * known) or denied it.
2106
+ */
2107
+ export const ToolPolicyFactSchema = z
2108
+ .object({
2109
+ decision: z.enum(["ask", "deny"]),
2110
+ reason: z.string(),
2111
+ approvedBy: z.string().optional(),
2112
+ })
2113
+ .passthrough();
2114
+ /**
2115
+ * `tool.completed`: how one tool call ended, written once per call (R5.1). `status`
2116
+ * `completed`: the tool answered, with its output or the tool error it reported (`error`).
2117
+ * `failed`: the Runtime ended the call (`tool.disabled`, `tool.unavailable`, `tool.denied`, or
2118
+ * `tool.interrupted` for a call a crash interrupted, which may have run). `cancelled`: the turn
2119
+ * was cancelled while the call ran; it may have run. `attempts` above 1: the call was sent again
2120
+ * after a crash, with the same key.
2121
+ */
1490
2122
  export const ToolCompletedPayloadSchema = z
1491
2123
  .object({
1492
2124
  ...toolIds,
1493
- capabilityId: z.string().min(1),
2125
+ /** The tool call's effect id (R7.1). */
2126
+ effectId: z.string().min(1).optional(),
1494
2127
  toolName: z.string().min(1),
2128
+ status: z.enum(TOOL_CALL_STATUSES).optional(),
2129
+ kind: z.enum(TOOL_CALL_KINDS).optional(),
2130
+ /** The MCP server, or the HTTP tool's URL host. */
2131
+ server: z.string().min(1).optional(),
2132
+ /**
2133
+ * The skill the call ran: `load_skill` and `read_skill_resource` name it, and a sandbox tool
2134
+ * whose input names its folder, `/skills/<name>@<hash>/`, ran its files.
2135
+ */
2136
+ skill: z.string().min(1).optional(),
2137
+ /** The Agent Plugin that brought the call's MCP server or skill. */
2138
+ plugin: pluginLabelSchema.optional(),
2139
+ /** How many times the call was sent: 0 when the Runtime refused it, above 1 after a crash re-sent it. */
2140
+ attempts: z.number().int().nonnegative().optional(),
2141
+ /** From the first send to the outcome; absent when the call never ran. */
2142
+ durationMs: z.number().int().nonnegative().optional(),
2143
+ /**
2144
+ * The Tool Gate's own start and end of the call's last send (R7.1): an MCP or HTTP tool
2145
+ * through the gateway. Absent for a sandbox or core-served tool.
2146
+ */
2147
+ gate: GateTimesSchema.optional(),
2148
+ policy: ToolPolicyFactSchema.optional(),
1495
2149
  output: z.unknown().optional(),
1496
2150
  error: z
1497
2151
  .object({
@@ -1502,8 +2156,6 @@ export const ToolCompletedPayloadSchema = z
1502
2156
  * whose server answered `401`.
1503
2157
  */
1504
2158
  server: z.string().optional(),
1505
- /** With `credential_rejected`: the scope of the vault whose credential was sent; absent when none was. */
1506
- vault: z.enum(["installation", "user"]).optional(),
1507
2159
  /** An MCP tool error (R2b C7): true when calling again may work, as for `mcp.unreachable`. */
1508
2160
  retryable: z.boolean().optional(),
1509
2161
  })
@@ -1520,8 +2172,29 @@ export const ToolCompletedPayloadSchema = z
1520
2172
  export const EffectUncertainPayloadSchema = z
1521
2173
  .object({ effectId: z.string().min(1), message: z.string().optional() })
1522
2174
  .passthrough();
2175
+ /**
2176
+ * How a turn that ended went (R7.1), on `turn.completed`, `turn.failed` and `turn.cancelled`:
2177
+ * `durationMs` from the turn's start to its end, waits for a person included, so the turn's span
2178
+ * holds every crossing in it; `pausedMs`, how much of that it waited paused; `totals` from the
2179
+ * usage ledger (`steps`: the model calls the gate metered). Absent on a turn
2180
+ * that started before the Runtime recorded them.
2181
+ */
2182
+ const turnEndFacts = {
2183
+ durationMs: z.number().int().nonnegative().optional(),
2184
+ pausedMs: z.number().int().nonnegative().optional(),
2185
+ /** The session's agent. */
2186
+ agentId: z.string().optional(),
2187
+ totals: z
2188
+ .object({
2189
+ steps: z.number().int().nonnegative(),
2190
+ tokens: z.number().int().nonnegative(),
2191
+ costUsd: z.number().nonnegative(),
2192
+ })
2193
+ .passthrough()
2194
+ .optional(),
2195
+ };
1523
2196
  export const TurnCompletedPayloadSchema = z
1524
- .object({ output: z.unknown() })
2197
+ .object({ output: z.unknown(), ...turnEndFacts })
1525
2198
  .passthrough();
1526
2199
  export const TurnPausedPayloadSchema = z
1527
2200
  .object({
@@ -1546,10 +2219,11 @@ export const TurnFailedPayloadSchema = z
1546
2219
  .passthrough()
1547
2220
  .optional(),
1548
2221
  message: z.string().optional(),
2222
+ ...turnEndFacts,
1549
2223
  })
1550
2224
  .passthrough();
1551
2225
  export const TurnCancelledPayloadSchema = z
1552
- .object({ reason: z.string().optional() })
2226
+ .object({ reason: z.string().optional(), ...turnEndFacts })
1553
2227
  .passthrough();
1554
2228
  /** Lifecycle of an agent used as a tool. `agent.delegationId` is the parent call's invocation. */
1555
2229
  export const DelegationPayloadSchema = z
@@ -1583,6 +2257,14 @@ export const CommandMessagePayloadSchema = z
1583
2257
  parts: z.array(MessagePartSchema).optional(),
1584
2258
  /** The turn manifest the message carried, if any. */
1585
2259
  manifest: z.unknown().optional(),
2260
+ /**
2261
+ * The W3C trace context the message was sent with (R7.4): the turn's trace is the caller's,
2262
+ * and its root span the child of the caller's span.
2263
+ */
2264
+ trace: z
2265
+ .object({ traceparent: z.string(), tracestate: z.string().optional() })
2266
+ .passthrough()
2267
+ .optional(),
1586
2268
  })
1587
2269
  .passthrough();
1588
2270
  /** `command.approve`: an answer to an approval interaction. */
@@ -1603,8 +2285,8 @@ export const CommandRespondPayloadSchema = z
1603
2285
  value: z.unknown(),
1604
2286
  })
1605
2287
  .passthrough();
1606
- /** `sandbox.state`: the session's sandbox changed state. */
1607
- export const SandboxStatePayloadSchema = z
2288
+ /** `environment.state`: the session's sandbox changed state. */
2289
+ export const EnvironmentStatePayloadSchema = z
1608
2290
  .object({
1609
2291
  state: z.enum(["creating", "running", "stopped"]),
1610
2292
  backend: z.string(),
@@ -1618,14 +2300,14 @@ export const SandboxStatePayloadSchema = z
1618
2300
  })
1619
2301
  .passthrough();
1620
2302
  /**
1621
- * `sandbox.attached`: the session was opened on a sandbox resource (`sandbox: { id }`). The
1622
- * sandbox's own stream records the same attachment.
2303
+ * `environment.attached`: the session was opened on an Environment (`environment`). The
2304
+ * Environment's own stream records the same attachment.
1623
2305
  */
1624
- export const SandboxAttachedPayloadSchema = z
1625
- .object({ sandboxId: z.string() })
2306
+ export const EnvironmentAttachedPayloadSchema = z
2307
+ .object({ environmentId: z.string() })
1626
2308
  .passthrough();
1627
- /** `sandbox.exec`: one sandbox tool call finished. */
1628
- export const SandboxExecPayloadSchema = z
2309
+ /** `environment.exec`: one sandbox tool call finished. */
2310
+ export const EnvironmentExecPayloadSchema = z
1629
2311
  .object({
1630
2312
  tool: z.string(),
1631
2313
  command: z.string().optional(),
@@ -1643,6 +2325,26 @@ export const NodeStartedPayloadSchema = z
1643
2325
  iterations: z.string().optional(),
1644
2326
  })
1645
2327
  .passthrough();
2328
+ /**
2329
+ * `node.completed`: a flow's HTTP stage or HTTP verifier ended, or a tool stage the Runtime
2330
+ * refused to run (R7.1), named as its `node.started` names it. `status` reads as
2331
+ * `tool.completed`'s: `completed` when the stage's server answered (an error answer included),
2332
+ * `failed` when the Runtime ended it, `cancelled` when a cancel did. `gate` is the Tool Gate's
2333
+ * own start and end of its last send.
2334
+ */
2335
+ export const NodeCompletedPayloadSchema = z
2336
+ .object({
2337
+ path: z.string(),
2338
+ kind: z.string(),
2339
+ key: z.string(),
2340
+ iterations: z.string().optional(),
2341
+ effectId: z.string().min(1),
2342
+ status: z.enum(TOOL_CALL_STATUSES),
2343
+ /** From the first send to the outcome; absent when the stage never ran. */
2344
+ durationMs: z.number().int().nonnegative().optional(),
2345
+ gate: GateTimesSchema.optional(),
2346
+ })
2347
+ .passthrough();
1646
2348
  /** `node.agent`: a workflow node runs as a linked agent session. */
1647
2349
  export const NodeAgentPayloadSchema = z
1648
2350
  .object({
@@ -1692,7 +2394,7 @@ export const TranscriptUpdatedPayloadSchema = z
1692
2394
  * or the turn-end export of a sandbox's outputs (F8.2), whose listing and bytes the harness
1693
2395
  * holding the workspace supplied.
1694
2396
  */
1695
- export const ArtifactSourceSchema = z.enum(["upload", "engine", "export"]);
2397
+ export const ArtifactSourceSchema = z.enum(["upload", "engine", "export", "snapshot"]);
1696
2398
  /**
1697
2399
  * What an artifact holds: one file, or a folder (F8.2), whose versions are manifests of paths to
1698
2400
  * content-addressed files.
@@ -1763,8 +2465,9 @@ export const McpServerOutcomeSchema = z
1763
2465
  .object({
1764
2466
  /** The agent used as a tool that declares the server; absent for the session's root agent. */
1765
2467
  agentId: z.string().optional(),
1766
- capabilityId: z.string(),
1767
2468
  serverName: z.string(),
2469
+ /** The Agent Plugin that brought the server. */
2470
+ plugin: pluginLabelSchema.optional(),
1768
2471
  /** `refused`: the vault has no usable credential for it; `failed`: it could not be reached or listed. */
1769
2472
  outcome: z.enum(["connected", "refused", "failed"]),
1770
2473
  message: z.string(),
@@ -1828,10 +2531,11 @@ export const EVENT_CATALOG = {
1828
2531
  "delegation.started": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
1829
2532
  "delegation.completed": { payload: DelegationPayloadSchema, source: "loop", version: 1 },
1830
2533
  "mcp.discovered": { payload: McpDiscoveredPayloadSchema, source: "loop", version: 1 },
1831
- "sandbox.state": { payload: SandboxStatePayloadSchema, source: "loop", version: 1 },
1832
- "sandbox.exec": { payload: SandboxExecPayloadSchema, source: "loop", version: 1 },
1833
- "sandbox.attached": { payload: SandboxAttachedPayloadSchema, source: "api", version: 1 },
2534
+ "environment.state": { payload: EnvironmentStatePayloadSchema, source: "loop", version: 1 },
2535
+ "environment.exec": { payload: EnvironmentExecPayloadSchema, source: "loop", version: 1 },
2536
+ "environment.attached": { payload: EnvironmentAttachedPayloadSchema, source: "api", version: 1 },
1834
2537
  "node.started": { payload: NodeStartedPayloadSchema, source: "loop", version: 1 },
2538
+ "node.completed": { payload: NodeCompletedPayloadSchema, source: "loop", version: 1 },
1835
2539
  "node.agent": { payload: NodeAgentPayloadSchema, source: "loop", version: 1 },
1836
2540
  "loop.iteration": { payload: LoopIterationPayloadSchema, source: "loop", version: 1 },
1837
2541
  "loop.verified": { payload: LoopVerifiedPayloadSchema, source: "api", version: 1 },
@@ -2162,8 +2866,8 @@ export const SeedTenantConfigRequestSchema = z
2162
2866
  sandbox: z
2163
2867
  .object({
2164
2868
  backend: z.enum(["auto", "virtual"]).optional(),
2165
- /** Seeds Tenant setting `sandbox.config` when it is absent. */
2166
- config: TenantSandboxConfigSchema.optional(),
2869
+ /** Seeds Tenant setting `environments.config` when it is absent. */
2870
+ config: TenantEnvironmentsConfigSchema.optional(),
2167
2871
  })
2168
2872
  .strict()
2169
2873
  .optional(),
@@ -2185,22 +2889,22 @@ export const SeedTenantConfigResponseSchema = z
2185
2889
  export const ResetTenantRequestSchema = z
2186
2890
  .object({
2187
2891
  requestId: RequestIdSchema,
2188
- scope: z.enum(["sessions", "sandboxes", "all"]),
2892
+ scope: z.enum(["sessions", "environments", "all"]),
2189
2893
  activeWork: z.enum(["drain", "cancel"]),
2190
2894
  })
2191
2895
  .strict();
2192
2896
  /**
2193
2897
  * Acting for a subject (Host feature `subject-headers`): what an application principal may
2194
2898
  * narrow a request to. `sessions:own` reaches only the subject's own sessions; the others reach
2195
- * Tenant-wide resources. `sandboxes:write` creates and deletes sandboxes (Host feature
2196
- * `sandboxes`); a token caller's reach only the ids its sandbox grants name. Vaults are the
2197
- * installation's, managed with management keys on the Management API (protocol 8).
2899
+ * Tenant-wide resources. `environments:write` creates, changes and deletes Environments and
2900
+ * writes their secrets (protocol 11); a token caller's reach only the ids its Environment
2901
+ * grants name.
2198
2902
  */
2199
2903
  export const SUBJECT_SCOPES = [
2200
2904
  "agents:read",
2201
2905
  "agents:write",
2202
2906
  "sessions:own",
2203
- "sandboxes:write",
2907
+ "environments:write",
2204
2908
  ];
2205
2909
  /**
2206
2910
  * Retired scopes: `Nylorun-Scopes` may still name them (older clients do), and they grant
@@ -2211,9 +2915,11 @@ const RETIRED_SUBJECT_SCOPES = ["vaults:own", "tenant:settings"];
2211
2915
  /** 1–200 visible ASCII characters; spaces only inside. */
2212
2916
  const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
2213
2917
  /**
2214
- * Owner ids the Runtime uses itself: the host model's vault is owned by `host`, installation
2215
- * vaults by `installation`.
2918
+ * The owner of a session opened for no person: an MCP server's or HTTP tool's identity header
2919
+ * (R2b C2) names nobody for it. A reserved subject.
2216
2920
  */
2921
+ export const INSTALLATION_OWNER = "installation";
2922
+ /** Owner ids the Runtime uses itself: `host` (the model vault's) and `installation`. */
2217
2923
  const RESERVED_SUBJECTS = new Set(["host", INSTALLATION_OWNER]);
2218
2924
  /** A valid subject: 1–200 visible ASCII characters, not reserved by the Runtime. */
2219
2925
  export function isSubject(value) {
@@ -2240,6 +2946,11 @@ export function parseSubjectHeaders(subject, scopes) {
2240
2946
  message: "Nylorun-Scopes is required with Nylorun-Subject",
2241
2947
  };
2242
2948
  const names = named.filter((name) => !RETIRED_SUBJECT_SCOPES.includes(name));
2949
+ if (names.includes("sandboxes:write"))
2950
+ return {
2951
+ ok: false,
2952
+ message: "sandboxes:write was renamed environments:write in protocol 11",
2953
+ };
2243
2954
  const unknown = names.filter((name) => !SUBJECT_SCOPES.includes(name));
2244
2955
  if (unknown.length > 0)
2245
2956
  return { ok: false, message: `Unknown scope ${unknown.join(", ")}` };
@@ -2256,10 +2967,10 @@ export function parseSubjectHeaders(subject, scopes) {
2256
2967
  export const TOKEN_SCOPES = [
2257
2968
  "agents:read",
2258
2969
  "sessions:own",
2259
- "sandboxes:write",
2970
+ "environments:write",
2260
2971
  ];
2261
- /** The most sandbox grants one token caller carries. */
2262
- export const TOKEN_SANDBOX_GRANTS_MAX = 16;
2972
+ /** The most Environment grants one token caller carries. */
2973
+ export const TOKEN_ENVIRONMENT_GRANTS_MAX = 16;
2263
2974
  /**
2264
2975
  * The longest a token the Runtime signs itself lives, in seconds (capability links): rotating
2265
2976
  * signing keys revokes the previous key once the longest token it may have signed has expired.
@@ -2329,8 +3040,8 @@ export const CALLER_SCOPES = [...SUBJECT_SCOPES, "studio"];
2329
3040
  * - `subject` is the person the request acts for; absent for an application key alone.
2330
3041
  * - `scopes`: what the caller holds. An application key alone holds every subject scope.
2331
3042
  * - `agents`: the agents it may reach, `*` for all.
2332
- * - `sandboxes`: the sandbox grants of a token caller (empty reaches none); absent for an
2333
- * application key, alone or acting for a subject, which no grant limits.
3043
+ * - `environments`: the Environment grants of a token caller (empty reaches none); absent for
3044
+ * an application key, alone or acting for a subject, which no grant limits.
2334
3045
  */
2335
3046
  export const MeResponseSchema = z
2336
3047
  .object({
@@ -2340,11 +3051,11 @@ export const MeResponseSchema = z
2340
3051
  .meta({ description: "The person the request acts for; absent for an application key alone" }),
2341
3052
  scopes: z.array(z.enum(CALLER_SCOPES)),
2342
3053
  agents: AgentAllowlistSchema,
2343
- sandboxes: z
3054
+ environments: z
2344
3055
  .array(z.string())
2345
3056
  .optional()
2346
3057
  .meta({
2347
- description: "A token caller's sandbox grants (empty reaches none); absent when no grant limits the caller",
3058
+ description: "A token caller's Environment grants (empty reaches none); absent when no grant limits the caller",
2348
3059
  }),
2349
3060
  via: z.string().meta({
2350
3061
  description: "How the caller authenticated: `application:<principalId>`, `management:<principalId>`, `subject` or `issuer:<name>`",
@@ -2396,6 +3107,8 @@ export const PutAgentResponseSchema = z
2396
3107
  agentId: z.string(),
2397
3108
  manifestHash: z.string(),
2398
3109
  implementationVersion: z.string(),
3110
+ /** True for `?dryRun=true` (protocol 14): every check ran, and nothing was saved. */
3111
+ dryRun: z.boolean().optional(),
2399
3112
  })
2400
3113
  .strict();
2401
3114
  export const SESSION_STATUSES = [
@@ -2430,26 +3143,33 @@ export const SessionViewSchema = z
2430
3143
  manifestHash: z.string(),
2431
3144
  /**
2432
3145
  * The hash of the definition the session was opened from (R2b C11). `manifestHash` differs
2433
- * from it when the Runtime pinned its own capabilities beside the definition: a sandbox's
2434
- * tools and `save_artifact`, or `read_artifact`. Compare this one with the registered
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
2435
3148
  * definition's hash. Absent for a session opened before this release.
2436
3149
  */
2437
3150
  definitionHash: z.string().optional(),
2438
3151
  implementationVersion: z.string(),
2439
3152
  status: z.enum(SESSION_STATUSES),
2440
3153
  activeTurnId: z.string().nullable(),
2441
- vaultIds: z.array(z.string()),
2442
- credentialSelections: z.array(CredentialSelectionSchema),
2443
3154
  /**
2444
- * The session whose sandbox this one shares; `null` when it owns its own. Deprecated: share
2445
- * a sandbox resource with `sandbox: { id }` (the client's `sandboxes.forSession()`).
3155
+ * The Environment the session names, and its recipe version when the session opened (for
3156
+ * reading only); `null` without one.
3157
+ */
3158
+ environment: z
3159
+ .object({ id: z.string(), version: z.number().int().positive() })
3160
+ .strict()
3161
+ .nullable(),
3162
+ /**
3163
+ * The harness that runs the session's turns, pinned when it opened (track R4): its
3164
+ * Environment's harness, else `nylorun`.
2446
3165
  */
2447
- sandboxOwnerId: z.string().nullable(),
2448
- /** The sandbox resource the session is attached to (`sandbox: { id }`), if any. */
2449
- sandboxId: z.string().optional(),
2450
- /** The sandbox pinned when the session was opened, or `null`. */
2451
- sandbox: z.record(z.string(), z.unknown()).nullable(),
2452
- sandboxSource: z.enum(["default", "inline", "shared", "sandbox"]).optional(),
3166
+ harness: z.string(),
3167
+ /**
3168
+ * Why the session takes no new turn, when it is closed: `protocol_13` for a session opened
3169
+ * before protocol 13, `protocol_11` for one opened before protocol 11 (a new turn is
3170
+ * `409 session_closed`; its history stays readable).
3171
+ */
3172
+ closedReason: z.string().optional(),
2453
3173
  mcpSnapshot: z.record(z.string(), z.unknown()).nullable(),
2454
3174
  mcpDiagnostics: z.array(z.record(z.string(), z.unknown())),
2455
3175
  /** What the session waits on: interactions, approvals, timers. */
@@ -2473,14 +3193,25 @@ export const SandboxToolOutcomeSchema = z.discriminatedUnion("kind", [
2473
3193
  .strict(),
2474
3194
  ]);
2475
3195
  export const ResetTenantResponseSchema = z.object({ ok: z.literal(true) }).strict();
2476
- /** `GET /v1/tenant/models`: public provider and model names, no credentials. */
3196
+ /**
3197
+ * `GET /v1/tenant/models`: public provider and model names, no credentials. Each model says what
3198
+ * it reads (`inputs`: its catalog's list and the operator's additions) and what the operator may
3199
+ * add (`addableInputs`, protocol 12).
3200
+ */
2477
3201
  export const HostModelCatalogSchema = z
2478
3202
  .object({
2479
3203
  providers: z.array(z
2480
3204
  .object({
2481
3205
  id: z.string(),
2482
3206
  name: z.string(),
2483
- models: z.array(z.object({ id: z.string(), name: z.string() }).strict()),
3207
+ models: z.array(z
3208
+ .object({
3209
+ id: z.string(),
3210
+ name: z.string(),
3211
+ inputs: z.array(ModelInputSchema),
3212
+ addableInputs: z.array(ModelInputSchema),
3213
+ })
3214
+ .strict()),
2484
3215
  })
2485
3216
  .strict()),
2486
3217
  })
@@ -2493,40 +3224,57 @@ export const HostModelProviderInfoSchema = z
2493
3224
  authType: z.enum(["api_key", "oauth"]),
2494
3225
  baseUrl: z.string().optional(),
2495
3226
  settings: CustomModelSettingsSchema.optional(),
3227
+ /** What the provider's selected model reads (protocol 12); absent for a model unknown here. */
3228
+ inputs: z.array(ModelInputSchema).optional(),
2496
3229
  lastUpdated: z.string(),
2497
3230
  active: z.boolean(),
2498
3231
  })
2499
3232
  .strict();
3233
+ /**
3234
+ * `PUT /v1/tenant/models/inputs`: the inputs one catalog model reads (protocol 12), replacing
3235
+ * what the operator added before. Its catalog's own inputs always stay; an empty list removes
3236
+ * the additions. A custom endpoint sets `settings.inputs` on `PUT /v1/tenant/model` instead.
3237
+ */
3238
+ export const PutModelInputsRequestSchema = z
3239
+ .object({
3240
+ requestId: RequestIdSchema.optional(),
3241
+ provider: z.string().min(1),
3242
+ model: z.string().min(1),
3243
+ inputs: z.array(ModelInputSchema),
3244
+ })
3245
+ .strict();
3246
+ /** What one catalog model reads now: its catalog's inputs and the operator's additions. */
3247
+ export const ModelInputsViewSchema = z
3248
+ .object({
3249
+ provider: z.string(),
3250
+ model: z.string(),
3251
+ inputs: z.array(ModelInputSchema),
3252
+ })
3253
+ .strict();
2500
3254
  export const ListProvidersResponseSchema = z
2501
3255
  .object({ providers: z.array(HostModelProviderInfoSchema) })
2502
3256
  .strict();
2503
3257
  const SandboxResourcesLimitSchema = z
2504
3258
  .object({ cpus: z.number(), memoryMiB: z.number() })
2505
3259
  .strict();
2506
- /** A Tenant's sandbox configuration with every default applied (sizes in MiB). */
3260
+ /** A Tenant's Environment settings with every default applied (sizes in MiB). */
2507
3261
  export const EffectiveSandboxConfigSchema = z
2508
3262
  .object({
2509
- default: z.union([z.literal("none"), z.literal("virtual"), SandboxInlineRequestSchema]),
2510
3263
  limits: z
2511
3264
  .object({
2512
3265
  network: z.array(z.string()),
2513
3266
  resources: SandboxResourcesLimitSchema,
2514
3267
  defaultResources: SandboxResourcesLimitSchema,
2515
3268
  idle: z.string(),
2516
- /** The most sandbox resources the Tenant may hold. */
2517
- sandboxes: z.number().int().nonnegative().optional(),
2518
- /** Pods: the longest `lifecycle.ttl`, when the Tenant sets one. */
2519
- ttl: z.string().optional(),
3269
+ /** The most Environments the Tenant may hold. */
3270
+ environments: z.number().int().nonnegative().optional(),
2520
3271
  })
2521
3272
  .strict(),
2522
- /** Pods (Host feature `sandbox-pods`): what happens at expiry, and the pod's stop grace. */
2523
- lifecycle: z
2524
- .object({ onExpiry: z.enum(["retain", "delete"]), stopGrace: z.string() })
2525
- .strict()
2526
- .optional(),
3273
+ /** Pods (Host feature `sandbox-pods`): the pod's stop grace. */
3274
+ lifecycle: z.object({ stopGrace: z.string() }).strict().optional(),
2527
3275
  /** Where each harness may run (D38). */
2528
3276
  placement: z
2529
- .record(z.string(), z.object({ hosts: z.array(z.enum(SANDBOX_PLACEMENT_HOSTS)) }).strict())
3277
+ .record(z.string(), z.object({ hosts: z.array(z.enum(PLACEMENT_HOSTS)) }).strict())
2530
3278
  .optional(),
2531
3279
  })
2532
3280
  .strict();
@@ -2551,7 +3299,7 @@ export const TenantSandboxViewSchema = z
2551
3299
  defaultImage: z.string(),
2552
3300
  config: EffectiveSandboxConfigSchema,
2553
3301
  /**
2554
- * The Tenant's cluster for pod sandboxes (`nylorun sandbox enable`), as the sandboxes
3302
+ * The Tenant's cluster for pod sandboxes (`nylorun local sandbox enable`), as the sandboxes
2555
3303
  * service reports it; null without one, or when the service does not answer.
2556
3304
  */
2557
3305
  cluster: z
@@ -2635,11 +3383,62 @@ export const PutModelBudgetsRequestSchema = z
2635
3383
  }
2636
3384
  });
2637
3385
  export const ModelBudgetsSchema = z.object({ budgets: z.array(ModelBudgetSchema) }).strict();
2638
- export const ListVaultsResponseSchema = z.object({ vaults: z.array(VaultInfoSchema) }).strict();
2639
- export const ListCredentialsResponseSchema = z
2640
- .object({ credentials: z.array(CredentialInfoSchema) })
3386
+ /** What a tool policy rule does to a call it matches (R5 step 2). */
3387
+ export const TOOL_POLICY_EFFECTS = ["allow", "ask", "deny"];
3388
+ /** A test of one field of a tool call's input; every test it sets must hold. */
3389
+ export const ToolInputConditionSchema = z
3390
+ .object({
3391
+ equals: jsonValue.optional(),
3392
+ in: z.array(jsonValue).min(1).optional(),
3393
+ gt: z.number().optional(),
3394
+ gte: z.number().optional(),
3395
+ lt: z.number().optional(),
3396
+ lte: z.number().optional(),
3397
+ /** A regular expression the field's string value must match. */
3398
+ matches: z.string().min(1).max(500).optional(),
3399
+ })
3400
+ .strict()
3401
+ .superRefine((condition, ctx) => {
3402
+ if (Object.keys(condition).length === 0)
3403
+ ctx.addIssue({ code: "custom", message: "A condition sets at least one of equals, in, gt, gte, lt, lte or matches" });
3404
+ if (condition.matches !== undefined)
3405
+ try {
3406
+ new RegExp(condition.matches);
3407
+ }
3408
+ catch {
3409
+ ctx.addIssue({ code: "custom", path: ["matches"], message: `matches is not a regular expression: ${condition.matches}` });
3410
+ }
3411
+ });
3412
+ /**
3413
+ * One rule of the Tenant's tool policy (R5 step 2), applied at the Tool Gate to every MCP and
3414
+ * 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
3416
+ * server's name), `kind`, `agent` (the agent that calls it) and `when` (fields of the input, by
3417
+ * dotted path). The strictest matching rule decides: `deny` refuses the call before it is sent,
3418
+ * `ask` holds it until a person approves it on the session (`approve`), `allow` runs it. A call no
3419
+ * rule matches runs. Sandbox tools never cross the gate; their network side is egress policy.
3420
+ */
3421
+ export const ToolRuleSchema = z
3422
+ .object({
3423
+ effect: z.enum(TOOL_POLICY_EFFECTS),
3424
+ tool: z.string().min(1).max(200).optional(),
3425
+ server: z.string().min(1).max(200).optional(),
3426
+ 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(),
3429
+ /** Why the rule exists: shown with a held or denied call. */
3430
+ reason: z.string().min(1).max(500).optional(),
3431
+ })
2641
3432
  .strict();
2642
- /** A deleted vault or credential. */
3433
+ /** `PUT /v1/tenant/tool-policy`: replaces every rule. An empty list allows every call. */
3434
+ export const PutToolPolicyRequestSchema = z
3435
+ .object({ requestId: RequestIdSchema.optional(), rules: z.array(ToolRuleSchema).max(200) })
3436
+ .strict();
3437
+ /** The Tenant's tool policy; `updatedAt` is null until one is set. */
3438
+ export const ToolPolicySchema = z
3439
+ .object({ rules: z.array(ToolRuleSchema), updatedAt: z.string().nullable() })
3440
+ .strict();
3441
+ /** A deleted resource. */
2643
3442
  export const DeletedResponseSchema = z.object({ id: z.string() }).strict();
2644
3443
  /**
2645
3444
  * The last frame of a session stream the Runtime ends: `event: nylorun.closed`, when the
@@ -2823,6 +3622,11 @@ export const ArtifactViewSchema = z
2823
3622
  contentType: z.string().meta({ description: "The latest version's media type" }),
2824
3623
  /** The session it belongs to; absent for a Tenant-wide artifact an application made. */
2825
3624
  sessionId: z.string().optional(),
3625
+ /**
3626
+ * The Environment whose disk versions it holds (R2d step 3); absent otherwise. Such an
3627
+ * artifact changes only through `/v1/environments/{id}/snapshot` and its versions routes.
3628
+ */
3629
+ environmentId: z.string().optional(),
2826
3630
  latestVersion: z.number().int().positive(),
2827
3631
  labels: z.record(z.string(), z.string()).optional(),
2828
3632
  createdAt: z.string(),
@@ -2834,6 +3638,11 @@ export const ArtifactViewSchema = z
2834
3638
  export const ListArtifactsResponseSchema = z
2835
3639
  .object({ artifacts: z.array(ArtifactViewSchema) })
2836
3640
  .strict();
3641
+ /** Paged metadata only; read the artifact separately for its version history and bytes. */
3642
+ export const ArtifactListItemSchema = ArtifactViewSchema.omit({ versions: true });
3643
+ export const ArtifactPageSchema = z
3644
+ .object({ artifacts: z.array(ArtifactListItemSchema), nextCursor: z.string().nullable() })
3645
+ .strict();
2837
3646
  /** What an upload answers: the artifact, and the version the upload created. */
2838
3647
  export const UploadArtifactResponseSchema = z
2839
3648
  .object({ artifact: ArtifactViewSchema, version: ArtifactVersionViewSchema })
@@ -2883,19 +3692,37 @@ export const ArtifactLinkSchema = z
2883
3692
  export const FOLDER_CONTENT_TYPE = "application/vnd.nylorun.folder+json";
2884
3693
  /** The manifest format a folder version is stored as. */
2885
3694
  export const FOLDER_MANIFEST_FORMAT = "nylorun.folder.v1";
3695
+ /**
3696
+ * The manifest format of an Environment's disk versions (R2d step 3): v1's entries, plus file
3697
+ * modes and modification times, symbolic links and empty directories. Readers accept both.
3698
+ */
3699
+ export const FOLDER_MANIFEST_FORMAT_V2 = "nylorun.folder.v2";
2886
3700
  /** The folder artifact a session's turn-end export writes, one per session. */
2887
3701
  export const OUTPUTS_ARTIFACT_NAME = "outputs";
2888
3702
  /** The most files one turn-end export stores; past it the export is skipped. */
2889
3703
  export const EXPORT_MAX_FILES = 10_000;
2890
3704
  /** The most bytes one turn-end export stores (before dedupe); past it the export is skipped. */
2891
3705
  export const EXPORT_MAX_BYTES = 1024 * 1024 * 1024;
2892
- /** One file of a folder: its path in the folder (`/`-separated, relative), size, hash and type. */
3706
+ /**
3707
+ * One file of a folder: its path in the folder (`/`-separated, relative), size, hash and type.
3708
+ * In a v2 manifest an entry may also be a symbolic link (`type: "link"`, its `target`) or an
3709
+ * empty directory (`type: "dir"`), with no bytes (`size` 0, `sha256` and `contentType` empty),
3710
+ * and any entry may carry its `mode` and `mtimeMs`.
3711
+ */
2893
3712
  export const FolderEntrySchema = z
2894
3713
  .object({
2895
3714
  path: z.string().min(1).max(ARTIFACT_PATH_MAX),
2896
3715
  size: z.number().int().nonnegative(),
2897
3716
  sha256: z.string().meta({ description: "SHA-256 of the file's bytes, lowercase hex" }),
2898
3717
  contentType: z.string(),
3718
+ /** v2: absent for a file. */
3719
+ type: z.enum(["link", "dir"]).optional(),
3720
+ /** v2: the permission bits (`0o755` is 493). */
3721
+ mode: z.number().int().nonnegative().max(0o7777).optional(),
3722
+ /** v2: the modification time, ms since the epoch. */
3723
+ mtimeMs: z.number().nonnegative().optional(),
3724
+ /** v2: a link's target, as stored on the disk. */
3725
+ target: z.string().max(4096).optional(),
2899
3726
  })
2900
3727
  .strict();
2901
3728
  /**
@@ -2904,7 +3731,7 @@ export const FolderEntrySchema = z
2904
3731
  */
2905
3732
  export const FolderManifestSchema = z
2906
3733
  .object({
2907
- format: z.literal(FOLDER_MANIFEST_FORMAT),
3734
+ format: z.enum([FOLDER_MANIFEST_FORMAT, FOLDER_MANIFEST_FORMAT_V2]),
2908
3735
  entries: z.array(FolderEntrySchema),
2909
3736
  })
2910
3737
  .strict();
@@ -2963,7 +3790,7 @@ export const TenantArtifactsViewSchema = z
2963
3790
  /** Opt-in session reads (Host feature `session-reads`). */
2964
3791
  export const SessionListItemSchema = SessionSummarySchema.extend({
2965
3792
  lastTurnId: z.string().nullable(),
2966
- sandboxId: z.string().nullable(),
3793
+ environmentId: z.string().nullable(),
2967
3794
  createdAt: z.string().nullable(),
2968
3795
  lastEventAt: z.string().nullable(),
2969
3796
  }).strict();
@@ -3005,6 +3832,11 @@ export const SessionUsageTotalsSchema = z
3005
3832
  export const ModelCallSchema = z
3006
3833
  .object({
3007
3834
  id: z.string(),
3835
+ /**
3836
+ * The model effect the call served: the effect id its harness sent as `Idempotency-Key`
3837
+ * (track R4), so a call is joined to the journal.
3838
+ */
3839
+ effectId: z.string(),
3008
3840
  sessionId: z.string(),
3009
3841
  turnId: z.string(),
3010
3842
  agentId: z.string(),
@@ -3034,6 +3866,76 @@ export const ModelCallExportPageSchema = z
3034
3866
  asOf: z.string(),
3035
3867
  })
3036
3868
  .strict();
3037
- export const SandboxPageSchema = z
3038
- .object({ sandboxes: z.array(SandboxViewSchema), nextCursor: z.string().nullable() })
3869
+ /**
3870
+ * One tool call of a session (R5.2), read from the effect journal: what ran, with what input,
3871
+ * how many sends, and how it ended. `invoking` while it runs. `uncertain` only for a call
3872
+ * recorded before R5. The output is in the session's log (`tool.completed`).
3873
+ */
3874
+ export const ToolCallSchema = z
3875
+ .object({
3876
+ effectId: z.string(),
3877
+ turnId: z.string(),
3878
+ callId: z.string().nullable(),
3879
+ toolName: z.string().nullable(),
3880
+ kind: z.enum(TOOL_CALL_KINDS).nullable(),
3881
+ server: z.string().nullable(),
3882
+ /** The skill the call ran (see `tool.completed`). */
3883
+ skill: z.string().nullable(),
3884
+ /** The Agent Plugin that brought its MCP server or skill. */
3885
+ plugin: pluginLabelSchema.nullable(),
3886
+ /** `held`: the Tool Gate holds it for a person's approval (R5 step 2). */
3887
+ status: z.enum(["invoking", "held", ...TOOL_CALL_STATUSES, "uncertain"]),
3888
+ attempts: z.number().int().nonnegative(),
3889
+ input: z.unknown(),
3890
+ error: z.object({ code: z.string(), message: z.string() }).strict().nullable(),
3891
+ startedAt: z.string().nullable(),
3892
+ settledAt: z.string().nullable(),
3893
+ durationMs: z.number().int().nonnegative().nullable(),
3894
+ })
3895
+ .strict();
3896
+ export const ToolCallsPageSchema = z
3897
+ .object({ calls: z.array(ToolCallSchema), nextCursor: z.string().nullable(), asOf: z.string() })
3898
+ .strict();
3899
+ /** One OTLP attribute (R7.5): a key and an `AnyValue` (`stringValue`, `intValue`, …). */
3900
+ export const OtlpKeyValueSchema = z
3901
+ .object({ key: z.string(), value: z.record(z.string(), z.unknown()) })
3902
+ .passthrough();
3903
+ /**
3904
+ * One span as OTLP/HTTP JSON encodes it (R7.5): hex ids, times in nanoseconds as decimal strings,
3905
+ * `kind` (1 internal, 3 client) and `status.code` (0 unset, 1 ok, 2 error) as numbers.
3906
+ */
3907
+ export const OtlpSpanSchema = z
3908
+ .object({
3909
+ traceId: z.string(),
3910
+ spanId: z.string(),
3911
+ parentSpanId: z.string().optional(),
3912
+ name: z.string(),
3913
+ kind: z.number().int(),
3914
+ startTimeUnixNano: z.string(),
3915
+ endTimeUnixNano: z.string(),
3916
+ attributes: z.array(OtlpKeyValueSchema),
3917
+ status: z.object({ code: z.number().int(), message: z.string().optional() }).passthrough(),
3918
+ })
3919
+ .passthrough();
3920
+ /**
3921
+ * A turn's trace (R7.5, feature `traces`): the OTLP `ExportTraceServiceRequest` JSON the Runtime
3922
+ * posts to a collector, built from the turn's log rows. One resource, one scope.
3923
+ */
3924
+ export const TurnTraceSchema = z
3925
+ .object({
3926
+ resourceSpans: z.array(z
3927
+ .object({
3928
+ resource: z.object({ attributes: z.array(OtlpKeyValueSchema) }).passthrough(),
3929
+ scopeSpans: z.array(z
3930
+ .object({
3931
+ scope: z.object({ name: z.string(), version: z.string().optional() }).passthrough(),
3932
+ spans: z.array(OtlpSpanSchema),
3933
+ })
3934
+ .passthrough()),
3935
+ })
3936
+ .passthrough()),
3937
+ })
3938
+ .passthrough();
3939
+ export const EnvironmentPageSchema = z
3940
+ .object({ environments: z.array(EnvironmentViewSchema), nextCursor: z.string().nullable() })
3039
3941
  .strict();