@nylorun/core 0.20.0-beta → 0.22.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 (90) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +2 -2
  3. package/dist/compatibility.d.ts +88 -13
  4. package/dist/compatibility.js +88 -13
  5. package/dist/contracts.d.ts +1328 -110
  6. package/dist/contracts.js +563 -163
  7. package/dist/define.d.ts +15 -13
  8. package/dist/define.js +11 -8
  9. package/dist/definition/approval.js +12 -14
  10. package/dist/definition/assemble.d.ts +6 -10
  11. package/dist/definition/assemble.js +48 -105
  12. package/dist/definition/bind-agent.d.ts +3 -4
  13. package/dist/definition/bind-agent.js +12 -30
  14. package/dist/definition/binding.d.ts +2 -2
  15. package/dist/definition/bound.d.ts +10 -10
  16. package/dist/definition/builder.d.ts +16 -20
  17. package/dist/definition/builder.js +29 -81
  18. package/dist/definition/code-tools.d.ts +3 -3
  19. package/dist/definition/code-tools.js +6 -21
  20. package/dist/definition/declaration.d.ts +4 -7
  21. package/dist/definition/declaration.js +29 -99
  22. package/dist/definition/{tools-capability.d.ts → deferred-tools.d.ts} +3 -13
  23. package/dist/definition/{tools-capability.js → deferred-tools.js} +2 -18
  24. package/dist/definition/delegate.d.ts +2 -4
  25. package/dist/definition/delegate.js +8 -10
  26. package/dist/definition/from.d.ts +7 -4
  27. package/dist/definition/from.js +72 -117
  28. package/dist/definition/helpers.d.ts +0 -7
  29. package/dist/definition/helpers.js +0 -5
  30. package/dist/definition/http-tool.d.ts +49 -5
  31. package/dist/definition/http-tool.js +167 -5
  32. package/dist/definition/implementations.d.ts +6 -8
  33. package/dist/definition/manifest.d.ts +11 -5
  34. package/dist/definition/manifest.js +26 -26
  35. package/dist/definition/mcp.d.ts +1 -52
  36. package/dist/definition/mcp.js +0 -52
  37. package/dist/definition/media-reference.d.ts +23 -0
  38. package/dist/definition/media-reference.js +26 -0
  39. package/dist/definition/removed.d.ts +3 -10
  40. package/dist/definition/removed.js +10 -17
  41. package/dist/definition/runtime-manifest.d.ts +30 -0
  42. package/dist/definition/runtime-manifest.js +132 -0
  43. package/dist/definition/sandbox-tools.d.ts +1 -1
  44. package/dist/definition/sandbox-tools.js +1 -1
  45. package/dist/definition/skill-tools.d.ts +13 -7
  46. package/dist/definition/skill-tools.js +23 -10
  47. package/dist/definition/trace.d.ts +18 -0
  48. package/dist/definition/trace.js +42 -0
  49. package/dist/definition/variant.d.ts +5 -4
  50. package/dist/definition/variant.js +18 -51
  51. package/dist/definition/workflow/runnable.js +1 -1
  52. package/dist/errors.d.ts +1 -1
  53. package/dist/harness-api/entries.d.ts +1 -0
  54. package/dist/harness-api/entries.js +1 -0
  55. package/dist/harness-api/gates.d.ts +1 -6
  56. package/dist/harness-api/gates.js +1 -3
  57. package/dist/harness-api/harness-api.schema.json +11 -92
  58. package/dist/harness-api/index.d.ts +2 -2
  59. package/dist/harness-api/index.js +2 -2
  60. package/dist/harness-api/mcp.d.ts +0 -4
  61. package/dist/harness-api/mcp.js +0 -2
  62. package/dist/harness-api/messages.d.ts +1 -3
  63. package/dist/harness-api/messages.js +1 -3
  64. package/dist/harness-api/schema.d.ts +5 -17
  65. package/dist/harness-api/schema.js +9 -6
  66. package/dist/index.d.ts +1 -1
  67. package/dist/manifest-schemas.d.ts +6 -0
  68. package/dist/manifest-schemas.js +46 -0
  69. package/dist/schemas/agent-manifest.schema.json +905 -0
  70. package/dist/schemas/environment-manifest.schema.json +349 -0
  71. package/dist/types/agent.d.ts +1 -1
  72. package/dist/types/manifest.d.ts +47 -24
  73. package/dist/types/model.d.ts +2 -2
  74. package/dist/types/observe.d.ts +5 -18
  75. package/dist/types/part.d.ts +25 -0
  76. package/dist/types/tool.d.ts +1 -1
  77. package/dist/types/transcript.d.ts +5 -0
  78. package/dist/utils/definition-files.d.ts +11 -6
  79. package/dist/utils/definition-files.js +19 -9
  80. package/dist/utils/runtime-tools.d.ts +19 -0
  81. package/dist/utils/runtime-tools.js +30 -0
  82. package/dist/utils/sandbox.d.ts +1 -1
  83. package/dist/utils/sandbox.js +1 -1
  84. package/package.json +9 -3
  85. package/dist/definition/capability.d.ts +0 -43
  86. package/dist/definition/capability.js +0 -82
  87. package/dist/definition/sandbox-capability.d.ts +0 -44
  88. package/dist/definition/sandbox-capability.js +0 -139
  89. package/dist/types/middleware.d.ts +0 -94
  90. /package/dist/types/{middleware.js → part.js} +0 -0
package/dist/contracts.js CHANGED
@@ -1,14 +1,15 @@
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 { APPROVAL_MODES, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, httpUrlIssue, } from "./definition/http-tool.js";
7
+ import { stdioMcpRefusal } from "./definition/mcp.js";
8
+ import { APPROVAL_MODES, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, httpInputIssue, httpUrlIssue, httpUrlTemplateIssue, httpVerifierIssue, } from "./definition/http-tool.js";
8
9
  import { canonical } from "./utils/canonical.js";
9
10
  import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, isHarnessId } from "./utils/harness-id.js";
10
11
  export { DEFAULT_HARNESS, HARNESS_ID_PATTERN, isHarnessId };
11
- import { DEFINITION_FILE_MAX_BYTES, skillFilesIssue } from "./utils/definition-files.js";
12
+ import { DEFINITION_FILE_MAX_BYTES, isDefinitionFileHash, skillFilesIssue } from "./utils/definition-files.js";
12
13
  export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
13
14
  export { DEFINITION_FILE_MAX_BYTES, SKILL_FILES_MAX, definitionFilesOf, isDefinitionFileHash, } from "./utils/definition-files.js";
14
15
  import { ERROR_CODES, isArtifactId } from "./compatibility.js";
@@ -39,7 +40,12 @@ const jsonValue = z
39
40
  const modelFacingName = (what) => z.string().regex(DELEGATE_NAME_PATTERN, {
40
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`,
41
42
  });
42
- /** 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). */
43
49
  const mcpToolSettingsSchema = z
44
50
  .object({
45
51
  enabled: z.boolean().optional(),
@@ -48,10 +54,11 @@ const mcpToolSettingsSchema = z
48
54
  })
49
55
  .strict()
50
56
  .meta({ id: "McpToolSettings" });
51
- /** 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). */
52
58
  const mcpServerSettings = {
53
59
  deferred: z.boolean().optional(),
54
60
  tools: z.record(z.string().min(1), mcpToolSettingsSchema).optional(),
61
+ plugin: pluginLabelSchema.optional(),
55
62
  };
56
63
  const mcpServerSchema = z.discriminatedUnion("type", [
57
64
  z
@@ -91,6 +98,7 @@ const skillManifestSchema = z
91
98
  name: z.string().min(1),
92
99
  description: z.string().min(1),
93
100
  files: z.record(z.string(), z.string()),
101
+ plugin: pluginLabelSchema.optional(),
94
102
  })
95
103
  .strict()
96
104
  .superRefine((skill, ctx) => {
@@ -135,7 +143,7 @@ const sandboxManifestSchema = z
135
143
  const httpToolTargetSchema = z
136
144
  .object({
137
145
  url: z.string().superRefine((url, ctx) => {
138
- const issue = httpUrlIssue(url);
146
+ const issue = httpUrlIssue(url) ?? httpUrlTemplateIssue(url);
139
147
  if (issue)
140
148
  ctx.addIssue({ code: "custom", message: issue });
141
149
  }),
@@ -180,18 +188,40 @@ const toolManifestSchema = z
180
188
  path: ["approval"],
181
189
  message: `Tool '${tool.name}' takes approval only as an HTTP tool`,
182
190
  });
191
+ const parameters = tool.http && httpInputIssue(tool.http, tool.inputSchema);
192
+ if (parameters)
193
+ ctx.addIssue({ code: "custom", path: ["http", "url"], message: `Tool '${tool.name}': ${parameters}` });
183
194
  });
184
- /** A manifest or capability naming a removed field is refused with what replaces it. */
195
+ /** A manifest naming a removed field is refused with what replaces it. */
185
196
  const removedFieldError = (removedFields) => (issue) => {
186
197
  if (issue.code !== "unrecognized_keys")
187
198
  return undefined;
188
199
  const removed = issue.keys?.find((key) => removedFields[key] !== undefined);
189
200
  return removed === undefined ? undefined : removedFields[removed];
190
201
  };
202
+ /** What the Runtime adds to a session's agent; only the Runtime writes it. */
203
+ const runtimeManifestSchema = z
204
+ .object({
205
+ sandbox: sandboxManifestSchema.optional(),
206
+ tools: z.array(toolManifestSchema).optional(),
207
+ instructions: z.array(z.string()).optional(),
208
+ })
209
+ .strict();
210
+ /**
211
+ * What an agent needs of the Environment its session opens on (protocol 14, D65), checked when a
212
+ * session opens (`409 environment_unsuitable`). `sandbox`: `any` needs kind `virtual` or `pod`,
213
+ * `pod` needs kind `pod`, `none` needs nothing. `secrets`: names its skills' scripts read, which
214
+ * the Environment's vault must hold. The agent names no Environment: the app still maps.
215
+ */
216
+ const agentRequirementsSchema = z
217
+ .object({
218
+ sandbox: z.enum(["none", "any", "pod"]).optional(),
219
+ secrets: z.array(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,127}$/, "A secret name in requires is an environment variable name")).max(64).optional(),
220
+ })
221
+ .strict();
191
222
  const agentManifestSchema = z
192
223
  .strictObject({
193
- // 6 adds an MCP server's `tools` and `deferred` (R2b C9); 5 is accepted unchanged.
194
- manifestSchemaVersion: z.union([z.literal(5), z.literal(6)], {
224
+ manifestSchemaVersion: z.literal(7, {
195
225
  error: (issue) => manifestVersionIssue(issue.input),
196
226
  }),
197
227
  id: z.string().min(1),
@@ -199,19 +229,12 @@ const agentManifestSchema = z
199
229
  description: z.string().optional(),
200
230
  metadata: definitionJson.optional(),
201
231
  outputSchema: definitionJson.optional(),
202
- capabilities: z.array(z.strictObject({
203
- id: z.string().min(1),
204
- type: z.enum(["agent", "agent-plugin"]),
205
- name: z.string().min(1).optional(),
206
- description: z.string().optional(),
207
- metadata: definitionJson.optional(),
208
- instructions: z.array(z.string()).optional(),
209
- skills: z.record(z.string(), skillManifestSchema).optional(),
210
- tools: z.array(toolManifestSchema).optional(),
211
- mcpServers: z.record(z.string(), mcpServerSchema).optional(),
212
- sandbox: sandboxManifestSchema.optional(),
213
- }, { error: removedFieldError(REMOVED_CAPABILITY_FIELDS) })),
214
- runtime: z.object({}).strict().optional(),
232
+ instructions: z.array(z.string()).optional(),
233
+ tools: z.array(toolManifestSchema).optional(),
234
+ skills: z.record(z.string(), skillManifestSchema).optional(),
235
+ mcpServers: z.record(z.string(), mcpServerSchema).optional(),
236
+ requires: agentRequirementsSchema.optional(),
237
+ runtime: runtimeManifestSchema.optional(),
215
238
  // Reserved for Functions, which are deferred: developer code the Runtime will run from
216
239
  // uploaded definition files (a `functions/` folder). Any value is refused below.
217
240
  functions: z.unknown().optional().meta({ description: "Reserved: Functions are not available yet" }),
@@ -220,124 +243,85 @@ const agentManifestSchema = z
220
243
  if (manifest.functions !== undefined)
221
244
  ctx.addIssue({ code: "custom", path: ["functions"], message: "Functions are not available yet" });
222
245
  delegationIssues(manifest, (message) => ctx.addIssue({ code: "custom", message }));
223
- const ids = new Set();
224
246
  const names = new Set();
225
- const servers = new Set();
226
- const skills = new Set();
227
- let sandboxes = 0;
228
- for (const capability of manifest.capabilities) {
229
- if (capability.sandbox) {
230
- sandboxes += 1;
231
- if (sandboxes > 1)
232
- ctx.addIssue({
233
- code: "custom",
234
- message: "At most one capability may declare a sandbox",
235
- });
236
- const declared = new Set((capability.tools ?? []).map((tool) => tool.name));
237
- for (const name of SANDBOX_TOOL_NAMES)
238
- if (!declared.has(name))
239
- ctx.addIssue({
240
- code: "custom",
241
- message: `Sandbox capability '${capability.id}' must declare the built-in '${name}' tool`,
242
- });
243
- }
244
- if (ids.has(capability.id))
245
- ctx.addIssue({ code: "custom", message: "Duplicate capability id" });
246
- ids.add(capability.id);
247
- for (const tool of capability.tools ?? []) {
248
- if (names.has(tool.name))
249
- ctx.addIssue({
250
- code: "custom",
251
- message: "Tool names must be unique",
252
- });
253
- names.add(tool.name);
254
- }
255
- if (capability.skills && Object.keys(capability.skills).length === 0)
247
+ for (const tool of manifest.tools ?? []) {
248
+ if (RUNTIME_TOOL_NAMES.has(tool.name))
256
249
  ctx.addIssue({
257
250
  code: "custom",
258
- message: "skills must be omitted when a capability declares no skills",
251
+ message: `Tool '${tool.name}' takes the name of a tool the Runtime serves; rename it`,
259
252
  });
260
- for (const [key, skill] of Object.entries(capability.skills ?? {})) {
261
- if (key !== skill.name)
262
- ctx.addIssue({
263
- code: "custom",
264
- message: `skills key '${key}' must equal the skill name`,
265
- });
266
- if (skills.has(skill.name))
267
- ctx.addIssue({
268
- code: "custom",
269
- message: `Duplicate skill '${skill.name}'`,
270
- });
271
- skills.add(skill.name);
272
- }
273
- if (capability.mcpServers && Object.keys(capability.mcpServers).length === 0)
253
+ if (tool.name.includes("__"))
274
254
  ctx.addIssue({
275
255
  code: "custom",
276
- message: "mcpServers must be omitted when a capability declares no servers",
256
+ message: `Tool '${tool.name}' must not contain '__', which names an MCP server's tools`,
277
257
  });
278
- for (const [key, server] of Object.entries(capability.mcpServers ?? {})) {
279
- if (key !== server.name)
280
- ctx.addIssue({
281
- code: "custom",
282
- message: `mcpServers key '${key}' must equal the server name`,
283
- });
284
- if (servers.has(server.name))
258
+ }
259
+ for (const tool of [...(manifest.tools ?? []), ...(manifest.runtime?.tools ?? [])]) {
260
+ if (names.has(tool.name))
261
+ ctx.addIssue({ code: "custom", message: "Tool names must be unique" });
262
+ names.add(tool.name);
263
+ }
264
+ for (const tool of manifest.runtime?.tools ?? [])
265
+ if (!RUNTIME_TOOL_NAMES.has(tool.name))
266
+ ctx.addIssue({
267
+ code: "custom",
268
+ message: `runtime.tools holds only the tools the Runtime serves, not '${tool.name}'`,
269
+ });
270
+ if (manifest.runtime?.sandbox !== undefined) {
271
+ const pinned = new Set((manifest.runtime.tools ?? []).map((tool) => tool.name));
272
+ for (const name of SANDBOX_TOOL_NAMES)
273
+ if (!pinned.has(name))
285
274
  ctx.addIssue({
286
275
  code: "custom",
287
- message: `Duplicate MCP server '${server.name}'`,
276
+ message: `runtime.sandbox comes with the sandbox tools; runtime.tools has no '${name}'`,
288
277
  });
289
- servers.add(server.name);
290
- if (manifest.manifestSchemaVersion === 5 && usesMcpToolSettings(server))
291
- ctx.addIssue({ code: "custom", message: mcpToolSettingsVersionIssue(server.name) });
292
- }
293
278
  }
279
+ if (manifest.skills && Object.keys(manifest.skills).length === 0)
280
+ ctx.addIssue({ code: "custom", message: "skills must be omitted when the agent has no skills" });
281
+ for (const [key, skill] of Object.entries(manifest.skills ?? {}))
282
+ if (key !== skill.name)
283
+ ctx.addIssue({ code: "custom", message: `skills key '${key}' must equal the skill name` });
284
+ if (manifest.mcpServers && Object.keys(manifest.mcpServers).length === 0)
285
+ ctx.addIssue({ code: "custom", message: "mcpServers must be omitted when the agent has no servers" });
286
+ for (const [key, server] of Object.entries(manifest.mcpServers ?? {}))
287
+ if (key !== server.name)
288
+ ctx.addIssue({ code: "custom", message: `mcpServers key '${key}' must equal the server name` });
294
289
  });
295
290
  /**
296
- * An agent's manifest (manifest v5 and v6). Its output is checked against `AgentManifest` here and
297
- * below (`ManifestDrift`): the hand-written type keeps its read-only fields and its docs.
291
+ * An agent's manifest (manifest v7). Its output is checked against `AgentManifest` here and below
292
+ * (`ManifestDrift`): the hand-written type keeps its read-only fields and its docs.
298
293
  */
299
294
  export const AgentManifestSchema = agentManifestSchema;
300
295
  /** Agents used as tools: one level deep, `{ task }` input, one shared sandbox spec. */
301
296
  function delegationIssues(manifest, issue) {
302
297
  const sandboxes = new Set();
303
- const addSandboxes = (agent) => {
304
- for (const capability of agent.capabilities)
305
- if (capability.sandbox)
306
- sandboxes.add(canonical(capability.sandbox));
298
+ const addSandbox = (agent) => {
299
+ if (agent.runtime?.sandbox)
300
+ sandboxes.add(canonical(agent.runtime.sandbox));
307
301
  };
308
- addSandboxes(manifest);
309
- for (const capability of manifest.capabilities)
310
- for (const tool of capability.tools ?? []) {
311
- const child = tool.agent;
312
- if (!child)
313
- continue;
314
- if ("kind" in child) {
315
- // A flow agent runs in its own linked session; its leaves may delegate in turn.
316
- if (tool.name !== child.id)
317
- issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
318
- if (!child.description?.trim() || tool.description !== child.description)
319
- issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
320
- if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
321
- issue(`Agent tool '${tool.name}' must take the standard { task } input`);
322
- if (tool.outputSchema !== undefined)
323
- issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
324
- if (child.sandbox !== undefined && Object.keys(child.sandbox).length > 0)
325
- sandboxes.add(canonical(child.sandbox));
326
- continue;
327
- }
328
- if (tool.name !== child.id)
329
- issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
330
- if (!child.description?.trim() || tool.description !== child.description)
331
- issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
332
- if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
333
- issue(`Agent tool '${tool.name}' must take the standard { task } input`);
334
- if (tool.outputSchema !== undefined)
335
- issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
336
- for (const inner of child.capabilities)
337
- if (inner.tools?.some((item) => item.agent !== undefined))
338
- issue(`'${child.id}' delegates to another agent; nested delegation is not supported yet`);
339
- addSandboxes(child);
302
+ addSandbox(manifest);
303
+ for (const tool of manifest.tools ?? []) {
304
+ const child = tool.agent;
305
+ if (!child)
306
+ continue;
307
+ if (tool.name !== child.id)
308
+ issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
309
+ if (!child.description?.trim() || tool.description !== child.description)
310
+ issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
311
+ if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
312
+ issue(`Agent tool '${tool.name}' must take the standard { task } input`);
313
+ if (tool.outputSchema !== undefined)
314
+ issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
315
+ if ("kind" in child) {
316
+ // A flow agent runs in its own linked session; its leaves may delegate in turn.
317
+ if (child.sandbox !== undefined && Object.keys(child.sandbox).length > 0)
318
+ sandboxes.add(canonical(child.sandbox));
319
+ continue;
340
320
  }
321
+ if (child.tools?.some((item) => item.agent !== undefined))
322
+ issue(`'${child.id}' delegates to another agent; nested delegation is not supported yet`);
323
+ addSandbox(child);
324
+ }
341
325
  if (sandboxes.size > 1)
342
326
  issue("An agent and the agents it uses as tools must declare identical sandboxes");
343
327
  }
@@ -369,6 +353,9 @@ const workflowLoopVerifySchema = z
369
353
  });
370
354
  else if (verify.http !== undefined && verify.id !== undefined)
371
355
  ctx.addIssue({ code: "custom", path: ["id"], message: "An HTTP verifier takes no id" });
356
+ const verifier = verify.http && httpVerifierIssue(verify.http);
357
+ if (verifier)
358
+ ctx.addIssue({ code: "custom", path: ["http"], message: verifier });
372
359
  })
373
360
  .meta({ id: "WorkflowLoopVerify" }); // the refinement picks one kind
374
361
  const workflowNodeKinds = z.lazy(() => z.union([
@@ -384,7 +371,12 @@ const workflowNodeKinds = z.lazy(() => z.union([
384
371
  /** An HTTP stage: the Runtime makes the request, as for an agent's HTTP tool. */
385
372
  http: httpToolTargetSchema.optional(),
386
373
  })
387
- .strict(),
374
+ .strict()
375
+ .superRefine((tool, ctx) => {
376
+ const parameters = tool.http && httpInputIssue(tool.http, tool.inputSchema);
377
+ if (parameters)
378
+ ctx.addIssue({ code: "custom", path: ["http", "url"], message: `Tool '${tool.name}': ${parameters}` });
379
+ }),
388
380
  ...workflowNodeOptions,
389
381
  })
390
382
  .strict(),
@@ -634,25 +626,92 @@ export const EnvironmentSetupCommandSchema = z
634
626
  * is made or reset, before the setup commands. A file artifact is written at `path`; a folder
635
627
  * artifact is unpacked under it.
636
628
  */
637
- export const EnvironmentFileSchema = z
638
- .object({
639
- artifactId: z.string().refine(isArtifactId, { message: "artifactId must be an artifact id" }),
640
- version: z.number().int().positive(),
641
- path: absoluteWorkspacePath("path"),
629
+ /** The most files one `files` entry by hash names (Q6). */
630
+ export const ENVIRONMENT_FILES_MAX = 1000;
631
+ /** A file's path inside a `files` entry by hash: relative, `/`-separated, without `.` or `..`. */
632
+ const relativeFilePath = z
633
+ .string()
634
+ .min(1)
635
+ .max(1024)
636
+ .refine((value) => !value.startsWith("/") && !value.includes("\0") && value.split("/").every((segment) => segment !== "" && segment !== "." && segment !== ".."), { message: "a file's path is relative, without empty, . or .. segments" });
637
+ /**
638
+ * One input file entry (pods only): an artifact version copied to `path` (a file artifact, or a
639
+ * folder's files under it), or (Q6) files by content hash, each `sha256:<hex>` of a definition
640
+ * file the Tenant holds (`PUT /v1/files/sha256:<hex>`, at most 10 MiB each), copied under `path`
641
+ * at its relative path. A manifest by hash moves to another Tenant with its files.
642
+ */
643
+ export const EnvironmentFileSchema = z.union([
644
+ z
645
+ .object({
646
+ artifactId: z.string().refine(isArtifactId, { message: "artifactId must be an artifact id" }),
647
+ version: z.number().int().positive(),
648
+ path: absoluteWorkspacePath("path"),
649
+ })
650
+ .strict(),
651
+ z
652
+ .object({
653
+ path: absoluteWorkspacePath("path"),
654
+ files: z
655
+ .record(relativeFilePath, z.string().refine(isDefinitionFileHash, { message: "each file is sha256:<64 lowercase hex>" }))
656
+ .refine((files) => Object.keys(files).length >= 1 && Object.keys(files).length <= ENVIRONMENT_FILES_MAX, {
657
+ message: `files names 1 to ${ENVIRONMENT_FILES_MAX} files`,
658
+ }),
659
+ })
660
+ .strict(),
661
+ ]);
662
+ /**
663
+ * An environment manifest's name (protocol 14, D63): 1–64 letters, digits, `.`, `_` and `-`,
664
+ * starting with a letter or digit, such as `analyst-box`.
665
+ */
666
+ const ENVIRONMENT_MANIFEST_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
667
+ export function isEnvironmentManifestName(value) {
668
+ return typeof value === "string" && ENVIRONMENT_MANIFEST_NAME_PATTERN.test(value);
669
+ }
670
+ export const EnvironmentManifestNameSchema = z
671
+ .string()
672
+ .refine(isEnvironmentManifestName, {
673
+ message: "An environment manifest's name is 1-64 letters, digits, '.', '_' and '-', starting with a letter or digit",
642
674
  })
643
- .strict();
675
+ .meta({ description: "An environment manifest's name, such as `analyst-box`" });
676
+ /**
677
+ * Which manifest an Environment is made from: `name` (its latest version when the Environment is
678
+ * created) or `name@n` (version `n`). Either way the Environment keeps that version for life.
679
+ */
680
+ export function parseEnvironmentManifestRef(ref) {
681
+ const at = ref.lastIndexOf("@");
682
+ const name = at < 0 ? ref : ref.slice(0, at);
683
+ if (!isEnvironmentManifestName(name))
684
+ return undefined;
685
+ if (at < 0)
686
+ return { name };
687
+ const version = ref.slice(at + 1);
688
+ return /^[1-9][0-9]{0,8}$/.test(version) ? { name, version: Number(version) } : undefined;
689
+ }
690
+ export const EnvironmentManifestRefSchema = z
691
+ .string()
692
+ .refine((value) => parseEnvironmentManifestRef(value) !== undefined, {
693
+ message: "manifest is an environment manifest's name, or name@version such as analyst-box@3",
694
+ })
695
+ .meta({ description: "`name` (the latest version when the Environment is created) or `name@n`" });
644
696
  /**
645
697
  * `PUT /v1/environments/{environmentId}`: creates the Environment and its vault, or finds the
646
- * one with this id, so "get or create" is one call. On an existing one the fields sent are
647
- * compared: `kind` and `storage` are fixed (a difference is `409`), `labels` replace its labels,
648
- * and any other difference changes its recipe and bumps its `version`. Image and resources
649
- * reach a pod when it next starts from stopped; `network.allowedHosts` applies within seconds.
650
- * A `PUT` that changes nothing answers the view unchanged.
698
+ * one with this id, so "get or create" is one call. An Environment is made from one version of an
699
+ * environment manifest (`manifest`) or from the inline manifest these fields make, and never
700
+ * changes what it runs after that (protocol 14, D63): on an existing one, `labels` replace its
701
+ * labels and `ownerUserId` sets or clears its owner guard, a field that matches what it runs is
702
+ * accepted, and anything else is `409 environment_immutable`, naming the fork that makes a new
703
+ * Environment instead.
651
704
  */
652
705
  export const PutEnvironmentRequestSchema = z
653
706
  .object({
654
707
  requestId: RequestIdSchema.optional(),
655
- /** Default `virtual`. `pod` needs sandbox pods (`nylorun sandbox enable`). Fixed. */
708
+ /**
709
+ * The environment manifest to make the Environment from (Host feature
710
+ * `environment-manifests`): `name` or `name@n`. With it, none of the inline fields below is
711
+ * sent; `labels`, `ownerUserId` and `from` still are.
712
+ */
713
+ manifest: EnvironmentManifestRefSchema.optional(),
714
+ /** Default `virtual`. `pod` needs sandbox pods (`nylorun local sandbox enable`). Fixed. */
656
715
  kind: z.enum(ENVIRONMENT_KINDS).optional(),
657
716
  labels: EnvironmentLabelsSchema.optional(),
658
717
  /** Pods only: the workload image (default the Tenant's, else `python:3.13-slim`). */
@@ -673,9 +732,11 @@ export const PutEnvironmentRequestSchema = z
673
732
  /**
674
733
  * The harness that runs the Environment's sessions (track R4): `nylorun` (ours, the default)
675
734
  * or the id of a custom harness. A pod Environment whose harness is not ours runs its
676
- * `image` as the harness: the image's own entrypoint, with nothing copied in. Each session
677
- * pins the harness when it opens; a session whose Environment's harness changed later fails
678
- * its next turn with `harness_mismatch`.
735
+ * `image` as the harness: the image's own entrypoint, with nothing copied in. It is fixed
736
+ * for the Environment's life (protocol 14): to run another harness, fork onto a manifest
737
+ * version that names it. Each session pins the harness when it opens; a session whose
738
+ * Environment id was deleted and made again with another harness fails its next turn with
739
+ * `harness_mismatch`.
679
740
  */
680
741
  harness: HarnessIdSchema.optional(),
681
742
  /**
@@ -691,6 +752,12 @@ export const PutEnvironmentRequestSchema = z
691
752
  setup: z.array(EnvironmentSetupCommandSchema).max(ENVIRONMENT_SETUP_MAX).optional(),
692
753
  /** Pods only: artifact versions copied in when the disk is made or reset, before `setup`. */
693
754
  files: z.array(EnvironmentFileSchema).max(ENVIRONMENT_SETUP_MAX).optional(),
755
+ /**
756
+ * The secrets an Environment of this kind needs, by name (D64): each slot's type, binding,
757
+ * whether it is required and a description, never a value. With slots declared, a secret
758
+ * write sends only the value and a name not declared is `409 secret_not_in_manifest`.
759
+ */
760
+ secrets: z.lazy(() => EnvironmentSecretSlotsSchema).optional(),
694
761
  /**
695
762
  * Only when the `PUT` creates the Environment (Host feature `environment-disk-versions`): its
696
763
  * disk starts from this version of another Environment's disk. Its vault starts empty.
@@ -704,7 +771,10 @@ export const PutEnvironmentRequestSchema = z
704
771
  .optional(),
705
772
  })
706
773
  .strict();
707
- /** An Environment's recipe, resolved against the Tenant's limits. */
774
+ /**
775
+ * What an Environment runs (its inline manifest, called the recipe before protocol 14), resolved
776
+ * against the Tenant's limits when it was made. It never changes after that.
777
+ */
708
778
  export const EnvironmentRecipeSchema = z
709
779
  .object({
710
780
  image: z.string().optional(),
@@ -715,6 +785,7 @@ export const EnvironmentRecipeSchema = z
715
785
  lifecycle: EnvironmentLifecycleSchema,
716
786
  setup: z.array(EnvironmentSetupCommandSchema).optional(),
717
787
  files: z.array(EnvironmentFileSchema).optional(),
788
+ secrets: z.lazy(() => EnvironmentSecretSlotsSchema).optional(),
718
789
  })
719
790
  .strict();
720
791
  /** A session that names an Environment, as the Environment's view lists it. */
@@ -741,6 +812,11 @@ export const EnvironmentPodViewSchema = z
741
812
  hostEpoch: z.number().int().nonnegative(),
742
813
  /** Why it failed, or was lost. */
743
814
  reason: z.string().optional(),
815
+ /**
816
+ * The workload image by digest (`repo@sha256:…`), pinned the first time a pod was ready
817
+ * (Q14): every later pod runs it. Absent before then, or for an image with no repository.
818
+ */
819
+ imageDigest: z.string().optional(),
744
820
  })
745
821
  .strict();
746
822
  /**
@@ -755,11 +831,38 @@ export const EnvironmentViewSchema = z
755
831
  id: z.string(),
756
832
  kind: z.enum(ENVIRONMENT_KINDS),
757
833
  labels: z.record(z.string(), z.string()),
758
- /** What the app asked for, resolved against the Tenant's limits. */
759
- recipe: EnvironmentRecipeSchema,
760
- /** Bumped by every recipe change. */
834
+ /**
835
+ * What it runs, fixed when it was made (protocol 14): its manifest's fields, or the inline
836
+ * ones, resolved against the Tenant's limits.
837
+ */
838
+ manifest: EnvironmentRecipeSchema,
839
+ /** The environment manifest it was made from and its version, when it was made from one. */
840
+ manifestName: z.string().optional(),
841
+ manifestVersion: z.number().int().positive().optional(),
842
+ /** The hash of what it runs (`manifest`). */
843
+ manifestHash: z.string().optional(),
844
+ /**
845
+ * The Environment it was forked from (`POST .../fork`, Q15), and the disk version it started
846
+ * from (`null` for an empty disk).
847
+ */
848
+ forkedFrom: z
849
+ .object({ environment: z.string(), disk: z.number().int().positive().nullable() })
850
+ .strict()
851
+ .optional(),
852
+ /** Each secret slot its manifest declares, and whether its vault holds a value for it. */
853
+ slots: z
854
+ .array(z
855
+ .object({
856
+ name: z.string(),
857
+ type: z.string(),
858
+ required: z.boolean(),
859
+ set: z.boolean(),
860
+ })
861
+ .strict())
862
+ .optional(),
863
+ /** Always 1 since protocol 14: an Environment never changes what it runs. */
761
864
  version: z.number().int().positive(),
762
- /** The recipe version the current pod (or virtual workspace) runs. */
865
+ /** Always `version`. */
763
866
  appliedVersion: z.number().int().positive(),
764
867
  /** The owner guard, or `null`. */
765
868
  ownerUserId: z.string().nullable(),
@@ -853,11 +956,16 @@ export const ListEnvironmentsResponseSchema = z
853
956
  export const DeleteEnvironmentResponseSchema = z
854
957
  .object({ id: z.string(), deleted: z.boolean() })
855
958
  .strict();
959
+ /** A turn that was running on an Environment when one of its connections opened (D67). */
960
+ export const EgressRunningTurnSchema = z
961
+ .object({ sessionId: z.string(), turnId: z.string() })
962
+ .strict();
856
963
  /**
857
964
  * One connection a pod Environment opened through egress-gate (track R7, Q6): written when it
858
- * closes, or at once when the gate refused it. The session log of the turn holding the
859
- * Environment when it opened gets it as `egress.connection`; with no turn holding it, the
860
- * Environment's own stream gets it as `environment.egress` (Q7).
965
+ * closes, or at once when the gate refused it, to the Environment's own stream as
966
+ * `environment.egress` (D67). The connection is the Environment's: its egress token names the pod,
967
+ * and the Environment's sessions run turns in parallel (D66). `runningTurns` lists the turns
968
+ * active on it as the connection opened, at most 16, as context and never as the owner.
861
969
  *
862
970
  * `startedAt` is the gate's clock at CONNECT and `durationMs` runs from there to the close, so
863
971
  * the span is the gate's own measurement. `bytesUp` is what the sandbox sent, `bytesDown` what it
@@ -883,6 +991,7 @@ export const EgressConnectionPayloadSchema = z
883
991
  bytesDown: z.number().int().nonnegative(),
884
992
  durationMs: z.number().nonnegative(),
885
993
  startedAt: z.string(),
994
+ runningTurns: z.array(EgressRunningTurnSchema).max(16),
886
995
  })
887
996
  .passthrough();
888
997
  /** The schema id of an Environment's lifecycle events (its stream in the record). */
@@ -899,13 +1008,25 @@ export const ENVIRONMENT_EVENT_TYPES = [
899
1008
  "environment.lost",
900
1009
  "environment.reset",
901
1010
  "environment.failed",
902
- // egress-gate, while no turn holds the Environment (R7, Q7).
1011
+ // Forked into a new Environment (Q15).
1012
+ "environment.forked",
1013
+ // egress-gate: every connection the Environment opens (R7, D67).
903
1014
  "environment.egress",
904
1015
  ];
905
1016
  /** The payload of each Environment lifecycle event. */
906
1017
  export const ENVIRONMENT_EVENT_PAYLOADS = {
907
1018
  "environment.created": z
908
- .object({ kind: z.enum(ENVIRONMENT_KINDS), labels: z.record(z.string(), z.string()) })
1019
+ .object({
1020
+ kind: z.enum(ENVIRONMENT_KINDS),
1021
+ labels: z.record(z.string(), z.string()),
1022
+ /** The environment manifest and version it was made from (protocol 14, D63). */
1023
+ manifest: z.object({ name: z.string(), version: z.number().int().positive() }).strict().optional(),
1024
+ /** The Environment it was forked from, and the disk version it started from (Q15). */
1025
+ forkedFrom: z
1026
+ .object({ environment: z.string(), disk: z.number().int().positive().nullable() })
1027
+ .strict()
1028
+ .optional(),
1029
+ })
909
1030
  .passthrough(),
910
1031
  "environment.attached": z.object({ sessionId: z.string() }).passthrough(),
911
1032
  "environment.detached": z
@@ -927,7 +1048,16 @@ export const ENVIRONMENT_EVENT_PAYLOADS = {
927
1048
  "environment.reset": z.object({ volumeGeneration: z.number().int() }).passthrough(),
928
1049
  /** The pod did not become ready. */
929
1050
  "environment.failed": z.object({ reason: z.string() }).passthrough(),
930
- /** A connection through egress-gate while no turn held the Environment (`egress.connection`'s payload). */
1051
+ /** Forked into Environment `to`: its disk started from version `disk`, `secrets` were copied. */
1052
+ "environment.forked": z
1053
+ .object({
1054
+ to: z.string(),
1055
+ disk: z.number().int().positive().nullable(),
1056
+ manifest: z.object({ name: z.string(), version: z.number().int().positive() }).strict().optional(),
1057
+ secrets: z.number().int().nonnegative(),
1058
+ })
1059
+ .passthrough(),
1060
+ /** A connection through egress-gate, with the turns running as it opened (D67). */
931
1061
  "environment.egress": EgressConnectionPayloadSchema,
932
1062
  };
933
1063
  /** One lifecycle event on an Environment's stream, numbered from 0. */
@@ -1200,6 +1330,20 @@ export const PutEnvironmentSecretRequestSchema = z.discriminatedUnion("type", [
1200
1330
  })
1201
1331
  .strict(),
1202
1332
  ]);
1333
+ /**
1334
+ * A secret write on an Environment whose manifest declares the secret's slot (D64): only the
1335
+ * value, `value` (or `headers` for a `headers` slot). Its type and binding come from the slot.
1336
+ */
1337
+ export const PutEnvironmentSecretValueRequestSchema = z
1338
+ .object({
1339
+ requestId: RequestIdSchema.optional(),
1340
+ value: z.string().min(1).max(8192).optional(),
1341
+ headers: CredentialHeadersSchema.optional(),
1342
+ })
1343
+ .strict()
1344
+ .refine((body) => (body.value === undefined) !== (body.headers === undefined), {
1345
+ message: "Send value, or headers for a headers secret",
1346
+ });
1203
1347
  /** Whether `name` may name a secret of `type` (`PUT .../secrets/{name}`); a message when not. */
1204
1348
  export function environmentSecretNameError(type, name) {
1205
1349
  if (type === "environment_secret" || type === "environment_variable") {
@@ -1213,16 +1357,221 @@ export function environmentSecretNameError(type, name) {
1213
1357
  ? undefined
1214
1358
  : "A credential name is 1-64 letters, digits, '.', '_' and '-'";
1215
1359
  }
1360
+ // --- Environment manifests (protocol 14, D63 to D65) -----------------------------------------
1361
+ const slotBase = {
1362
+ /** Whether a session whose agent needs it may open without it. Default false. */
1363
+ required: z.boolean().optional(),
1364
+ description: z.string().max(500).optional(),
1365
+ };
1366
+ /**
1367
+ * One secret an Environment of a kind needs (D64): its type and binding, never its value. The
1368
+ * value is written into each Environment's vault (`PUT /v1/environments/{id}/secrets/{name}`
1369
+ * with `{ value }`, or `{ headers }` for `headers`), and the binding comes from here.
1370
+ */
1371
+ export const EnvironmentSecretSlotSchema = z.discriminatedUnion("type", [
1372
+ z
1373
+ .object({
1374
+ type: z.literal("environment_secret"),
1375
+ allowedHosts: AllowedHostsSchema,
1376
+ inject: EnvironmentSecretInjectSchema.optional(),
1377
+ ...slotBase,
1378
+ })
1379
+ .strict(),
1380
+ z.object({ type: z.literal("environment_variable"), ...slotBase }).strict(),
1381
+ z.object({ type: z.literal("bearer"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1382
+ z.object({ type: z.literal("headers"), url: z.string().min(1), ...credentialRouting, ...slotBase }).strict(),
1383
+ ]);
1384
+ /** The most secret slots one manifest declares. */
1385
+ export const ENVIRONMENT_SECRET_SLOTS_MAX = 64;
1386
+ export const EnvironmentSecretSlotsSchema = z
1387
+ .record(z.string(), EnvironmentSecretSlotSchema)
1388
+ .superRefine((slots, ctx) => {
1389
+ const names = Object.keys(slots);
1390
+ if (names.length > ENVIRONMENT_SECRET_SLOTS_MAX)
1391
+ ctx.addIssue({ code: "custom", message: `At most ${ENVIRONMENT_SECRET_SLOTS_MAX} secrets` });
1392
+ for (const name of names) {
1393
+ const error = environmentSecretNameError(slots[name].type, name);
1394
+ if (error)
1395
+ ctx.addIssue({ code: "custom", path: [name], message: error });
1396
+ }
1397
+ });
1398
+ /** The schema version of an environment manifest; the Runtime refuses one it does not know. */
1399
+ export const ENVIRONMENT_MANIFEST_SCHEMA_VERSION = 1;
1400
+ const environmentFields = PutEnvironmentRequestSchema.shape;
1401
+ /**
1402
+ * An environment manifest (protocol 14, D63): a named, versioned definition of a kind of
1403
+ * Environment, saved like an agent (`PUT /v1/environment-manifests/{name}`). It holds what every
1404
+ * Environment made from it shares; an Environment's id, labels, owner guard, disk and secret
1405
+ * values are its own. Written as a JSON file with `$schema`, which clients drop before saving.
1406
+ */
1407
+ export const EnvironmentManifestSchema = z
1408
+ .object({
1409
+ manifestSchemaVersion: z.literal(ENVIRONMENT_MANIFEST_SCHEMA_VERSION, {
1410
+ error: (issue) => `manifestSchemaVersion ${JSON.stringify(issue.input)} is not one this Runtime reads: use ${ENVIRONMENT_MANIFEST_SCHEMA_VERSION}`,
1411
+ }),
1412
+ name: EnvironmentManifestNameSchema,
1413
+ description: z.string().max(1024).optional(),
1414
+ kind: environmentFields.kind,
1415
+ image: environmentFields.image,
1416
+ resources: environmentFields.resources,
1417
+ storage: environmentFields.storage,
1418
+ network: environmentFields.network,
1419
+ harness: environmentFields.harness,
1420
+ lifecycle: environmentFields.lifecycle,
1421
+ setup: environmentFields.setup,
1422
+ files: environmentFields.files,
1423
+ secrets: EnvironmentSecretSlotsSchema.optional(),
1424
+ })
1425
+ .strict();
1426
+ /** `PUT /v1/environment-manifests/{name}`: the manifest, whose `name` is the path's. */
1427
+ export const PutEnvironmentManifestRequestSchema = EnvironmentManifestSchema.extend({
1428
+ requestId: RequestIdSchema.optional(),
1429
+ }).strict();
1430
+ /** Who saved a version: the subject a request acted for, else `application`. */
1431
+ export const EnvironmentManifestSavedBySchema = z.object({ actor: z.string() }).strict();
1432
+ /** One version of an environment manifest. */
1433
+ export const EnvironmentManifestViewSchema = z
1434
+ .object({
1435
+ name: z.string(),
1436
+ version: z.number().int().positive(),
1437
+ /** The hash of `manifest`: equal manifests have equal hashes. */
1438
+ hash: z.string(),
1439
+ manifest: EnvironmentManifestSchema,
1440
+ savedBy: EnvironmentManifestSavedBySchema,
1441
+ createdAt: z.string(),
1442
+ /** How many Environments were made from this version. */
1443
+ environments: z.number().int().nonnegative(),
1444
+ })
1445
+ .strict();
1446
+ /** `GET /v1/environment-manifests`: each manifest's latest version, by name. */
1447
+ export const ListEnvironmentManifestsResponseSchema = z
1448
+ .object({ manifests: z.array(EnvironmentManifestViewSchema) })
1449
+ .strict();
1450
+ /** `GET /v1/environment-manifests/{name}/versions`: every version, newest first. */
1451
+ export const EnvironmentManifestVersionsSchema = z
1452
+ .object({
1453
+ name: z.string(),
1454
+ latest: z.number().int().positive(),
1455
+ versions: z.array(z
1456
+ .object({
1457
+ version: z.number().int().positive(),
1458
+ hash: z.string(),
1459
+ savedBy: EnvironmentManifestSavedBySchema,
1460
+ createdAt: z.string(),
1461
+ environments: z.number().int().nonnegative(),
1462
+ })
1463
+ .strict()),
1464
+ })
1465
+ .strict();
1466
+ /** Something a save would do that the saver should know: never a refusal. */
1467
+ export const EnvironmentManifestWarningSchema = z
1468
+ .object({ code: z.string(), message: z.string() })
1469
+ .strict();
1470
+ /**
1471
+ * `PUT /v1/environment-manifests/{name}?dryRun=true`: what saving it would do, with nothing
1472
+ * saved. `errors` lists every reason the Runtime would refuse it (the Tenant's limits, for one);
1473
+ * a save with errors is `400`. `behind` counts the Environments made from an older version than
1474
+ * the one it would save. No Environment changes when a version is saved (D63).
1475
+ */
1476
+ export const EnvironmentManifestPlanSchema = z
1477
+ .object({
1478
+ name: z.string(),
1479
+ /** The latest version now, or `null` for a new manifest. */
1480
+ from: z.number().int().positive().nullable(),
1481
+ /** The version a save would answer: `from` when nothing changed. */
1482
+ to: z.number().int().positive(),
1483
+ unchanged: z.boolean(),
1484
+ changes: z.array(z.object({ path: z.string(), from: z.unknown().optional(), to: z.unknown().optional() }).strict()),
1485
+ warnings: z.array(EnvironmentManifestWarningSchema),
1486
+ errors: z.array(z.string()),
1487
+ behind: z.number().int().nonnegative(),
1488
+ })
1489
+ .strict();
1490
+ /** `PUT /v1/environment-manifests/{name}`: the version saved (or the latest, unchanged). */
1491
+ export const SaveEnvironmentManifestResponseSchema = z
1492
+ .object({
1493
+ manifest: EnvironmentManifestViewSchema,
1494
+ unchanged: z.boolean(),
1495
+ warnings: z.array(EnvironmentManifestWarningSchema),
1496
+ })
1497
+ .strict();
1498
+ export const DeleteEnvironmentManifestResponseSchema = z
1499
+ .object({ name: z.string(), deleted: z.boolean() })
1500
+ .strict();
1501
+ /**
1502
+ * `POST /v1/environments/{id}/fork` (Q15): how an Environment gets a new manifest version. The
1503
+ * fork is a new Environment, made from the version, its disk started from a version of the
1504
+ * source's disk and its secrets copied inside the Runtime. The source keeps what it runs, its
1505
+ * disk and its sessions.
1506
+ */
1507
+ export const ForkEnvironmentRequestSchema = z
1508
+ .object({
1509
+ requestId: RequestIdSchema.optional(),
1510
+ /** The new Environment's id. */
1511
+ id: EnvironmentIdSchema,
1512
+ /** `name` or `name@n`; default the source's manifest at its latest version. */
1513
+ manifest: EnvironmentManifestRefSchema.optional(),
1514
+ /** Where its disk starts: `latest` (a snapshot taken first; the default), a version, or `empty`. */
1515
+ disk: z.union([z.literal("latest"), z.literal("empty"), z.number().int().positive()]).optional(),
1516
+ /** `copy` (the default): the source's secrets the new manifest declares (all, without slots). */
1517
+ secrets: z.enum(["copy", "none"]).optional(),
1518
+ labels: EnvironmentLabelsSchema.optional(),
1519
+ ownerUserId: z.string().min(1).nullable().optional(),
1520
+ /** Answer the plan and make nothing. */
1521
+ dryRun: z.boolean().optional(),
1522
+ })
1523
+ .strict();
1524
+ /** What a fork does (or, with `dryRun`, would do). */
1525
+ export const EnvironmentForkPlanSchema = z
1526
+ .object({
1527
+ source: z.string(),
1528
+ id: z.string(),
1529
+ kind: z.enum(ENVIRONMENT_KINDS),
1530
+ /** The manifest version it is made from, or `null` for the source's inline fields. */
1531
+ manifest: z.object({ name: z.string(), version: z.number().int().positive() }).strict().nullable(),
1532
+ /** The disk version it starts from: `latest` in a dry run (the snapshot is taken at the fork); `null` for an empty disk. */
1533
+ disk: z.union([z.number().int().positive(), z.literal("latest")]).nullable(),
1534
+ /** Whether the new manifest's setup runs on the copied disk: it differs from what the source runs. */
1535
+ setup: z.boolean(),
1536
+ secrets: z
1537
+ .object({
1538
+ /** Copied, by name. */
1539
+ copied: z.array(z.string()),
1540
+ /** The source's secrets the new manifest does not declare: left behind. */
1541
+ dropped: z.array(z.string()),
1542
+ /** Required slots of the new manifest no copied secret fills. */
1543
+ missing: z.array(z.string()),
1544
+ })
1545
+ .strict(),
1546
+ /** How what it runs differs from what the source runs. */
1547
+ changes: z.array(z.object({ path: z.string(), from: z.unknown().optional(), to: z.unknown().optional() }).strict()),
1548
+ /** The source's sessions: they stay on it. */
1549
+ sessions: z.number().int().nonnegative(),
1550
+ })
1551
+ .strict();
1552
+ /** `POST /v1/environments/{id}/fork`: the new Environment and the plan it ran, or with `dryRun` the plan only. */
1553
+ export const ForkEnvironmentResponseSchema = z.union([
1554
+ z.object({ dryRun: z.literal(true), plan: EnvironmentForkPlanSchema }).strict(),
1555
+ z.object({ environment: EnvironmentViewSchema, plan: EnvironmentForkPlanSchema }).strict(),
1556
+ ]);
1557
+ /**
1558
+ * What a model may read (protocol 12): `text` always; `image`, `pdf`, `office` (Word, Excel,
1559
+ * PowerPoint), `audio` and `video` when its catalog entry or the operator says so. In this order.
1560
+ */
1561
+ export const MODEL_INPUTS = ["text", "image", "pdf", "office", "audio", "video"];
1562
+ export const ModelInputSchema = z.enum(MODEL_INPUTS);
1216
1563
  /**
1217
1564
  * What the Runtime cannot learn from a custom OpenAI-compatible endpoint (Model Calls §7):
1218
- * its context window and output limit, whether it reasons, and pi-ai `compat` settings
1219
- * (`thinkingFormat`, `thinkingTokenBudgetField`, `chatTemplateKwargs`, …).
1565
+ * its context window and output limit, whether it reasons, what it reads (`inputs`; default text
1566
+ * only) and pi-ai `compat` settings (`thinkingFormat`, `thinkingTokenBudgetField`,
1567
+ * `chatTemplateKwargs`, …).
1220
1568
  */
1221
1569
  export const CustomModelSettingsSchema = z
1222
1570
  .object({
1223
1571
  contextWindow: z.number().int().min(1024).optional(),
1224
1572
  maxTokens: z.number().int().min(1).optional(),
1225
1573
  reasoning: z.boolean().optional(),
1574
+ inputs: z.array(ModelInputSchema).optional(),
1226
1575
  compat: z.record(z.string(), z.unknown()).optional(),
1227
1576
  })
1228
1577
  .strict();
@@ -1757,7 +2106,12 @@ export const ContextCompactedPayloadSchema = z
1757
2106
  /** How a tool call ended (R5.1): the tool answered, the Runtime ended it, or a cancel did. */
1758
2107
  export const TOOL_CALL_STATUSES = ["completed", "failed", "cancelled"];
1759
2108
  /** Where a tool call ran (R5.1): a remote MCP server, an HTTP tool, the sandbox, or core. */
1760
- export const TOOL_CALL_KINDS = ["mcp", "http", "sandbox", "platform"];
2109
+ /**
2110
+ * Where a tool call runs: an MCP server, an HTTP tool's URL, the session's sandbox, the Runtime
2111
+ * itself (`platform`: the artifact, skill and deferred-tool tools), or the harness that runs the
2112
+ * turn (`harness`: a tool it declared in `hello.features.tools`).
2113
+ */
2114
+ export const TOOL_CALL_KINDS = ["mcp", "http", "sandbox", "platform", "harness"];
1761
2115
  /**
1762
2116
  * What the Tenant's tool policy did with a tool call (R5 step 2), when it did more than allow
1763
2117
  * it: `deny` refused it unsent; `ask` held it for a person, who approved it (`approvedBy`, when
@@ -1783,12 +2137,18 @@ export const ToolCompletedPayloadSchema = z
1783
2137
  ...toolIds,
1784
2138
  /** The tool call's effect id (R7.1). */
1785
2139
  effectId: z.string().min(1).optional(),
1786
- capabilityId: z.string().min(1),
1787
2140
  toolName: z.string().min(1),
1788
2141
  status: z.enum(TOOL_CALL_STATUSES).optional(),
1789
2142
  kind: z.enum(TOOL_CALL_KINDS).optional(),
1790
- /** The MCP server, or the HTTP tool's capability. */
2143
+ /** The MCP server, or the HTTP tool's URL host. */
1791
2144
  server: z.string().min(1).optional(),
2145
+ /**
2146
+ * The skill the call ran: `load_skill` and `read_skill_resource` name it, and a sandbox tool
2147
+ * whose input names its folder, `/skills/<name>@<hash>/`, ran its files.
2148
+ */
2149
+ skill: z.string().min(1).optional(),
2150
+ /** The Agent Plugin that brought the call's MCP server or skill. */
2151
+ plugin: pluginLabelSchema.optional(),
1792
2152
  /** How many times the call was sent: 0 when the Runtime refused it, above 1 after a crash re-sent it. */
1793
2153
  attempts: z.number().int().nonnegative().optional(),
1794
2154
  /** From the first send to the outcome; absent when the call never ran. */
@@ -2118,8 +2478,9 @@ export const McpServerOutcomeSchema = z
2118
2478
  .object({
2119
2479
  /** The agent used as a tool that declares the server; absent for the session's root agent. */
2120
2480
  agentId: z.string().optional(),
2121
- capabilityId: z.string(),
2122
2481
  serverName: z.string(),
2482
+ /** The Agent Plugin that brought the server. */
2483
+ plugin: pluginLabelSchema.optional(),
2123
2484
  /** `refused`: the vault has no usable credential for it; `failed`: it could not be reached or listed. */
2124
2485
  outcome: z.enum(["connected", "refused", "failed"]),
2125
2486
  message: z.string(),
@@ -2186,7 +2547,6 @@ export const EVENT_CATALOG = {
2186
2547
  "environment.state": { payload: EnvironmentStatePayloadSchema, source: "loop", version: 1 },
2187
2548
  "environment.exec": { payload: EnvironmentExecPayloadSchema, source: "loop", version: 1 },
2188
2549
  "environment.attached": { payload: EnvironmentAttachedPayloadSchema, source: "api", version: 1 },
2189
- "egress.connection": { payload: EgressConnectionPayloadSchema, source: "egress-gate", version: 1 },
2190
2550
  "node.started": { payload: NodeStartedPayloadSchema, source: "loop", version: 1 },
2191
2551
  "node.completed": { payload: NodeCompletedPayloadSchema, source: "loop", version: 1 },
2192
2552
  "node.agent": { payload: NodeAgentPayloadSchema, source: "loop", version: 1 },
@@ -2760,6 +3120,8 @@ export const PutAgentResponseSchema = z
2760
3120
  agentId: z.string(),
2761
3121
  manifestHash: z.string(),
2762
3122
  implementationVersion: z.string(),
3123
+ /** True for `?dryRun=true` (protocol 14): every check ran, and nothing was saved. */
3124
+ dryRun: z.boolean().optional(),
2763
3125
  })
2764
3126
  .strict();
2765
3127
  export const SESSION_STATUSES = [
@@ -2794,8 +3156,8 @@ export const SessionViewSchema = z
2794
3156
  manifestHash: z.string(),
2795
3157
  /**
2796
3158
  * The hash of the definition the session was opened from (R2b C11). `manifestHash` differs
2797
- * from it when the Runtime pinned its own capabilities beside the definition: a sandbox's
2798
- * tools and `save_artifact`, or `read_artifact`. Compare this one with the registered
3159
+ * from it when the Runtime pinned its `runtime` block on the definition: a sandbox's tools,
3160
+ * the artifact tools and the skill tools. Compare this one with the registered
2799
3161
  * definition's hash. Absent for a session opened before this release.
2800
3162
  */
2801
3163
  definitionHash: z.string().optional(),
@@ -2816,8 +3178,9 @@ export const SessionViewSchema = z
2816
3178
  */
2817
3179
  harness: z.string(),
2818
3180
  /**
2819
- * Why the session takes no new turn, when it is closed: `protocol_11` for a session opened
2820
- * before protocol 11 (a new turn is `409 session_closed`; its history stays readable).
3181
+ * Why the session takes no new turn, when it is closed: `protocol_13` for a session opened
3182
+ * before protocol 13, `protocol_11` for one opened before protocol 11 (a new turn is
3183
+ * `409 session_closed`; its history stays readable).
2821
3184
  */
2822
3185
  closedReason: z.string().optional(),
2823
3186
  mcpSnapshot: z.record(z.string(), z.unknown()).nullable(),
@@ -2843,14 +3206,25 @@ export const SandboxToolOutcomeSchema = z.discriminatedUnion("kind", [
2843
3206
  .strict(),
2844
3207
  ]);
2845
3208
  export const ResetTenantResponseSchema = z.object({ ok: z.literal(true) }).strict();
2846
- /** `GET /v1/tenant/models`: public provider and model names, no credentials. */
3209
+ /**
3210
+ * `GET /v1/tenant/models`: public provider and model names, no credentials. Each model says what
3211
+ * it reads (`inputs`: its catalog's list and the operator's additions) and what the operator may
3212
+ * add (`addableInputs`, protocol 12).
3213
+ */
2847
3214
  export const HostModelCatalogSchema = z
2848
3215
  .object({
2849
3216
  providers: z.array(z
2850
3217
  .object({
2851
3218
  id: z.string(),
2852
3219
  name: z.string(),
2853
- models: z.array(z.object({ id: z.string(), name: z.string() }).strict()),
3220
+ models: z.array(z
3221
+ .object({
3222
+ id: z.string(),
3223
+ name: z.string(),
3224
+ inputs: z.array(ModelInputSchema),
3225
+ addableInputs: z.array(ModelInputSchema),
3226
+ })
3227
+ .strict()),
2854
3228
  })
2855
3229
  .strict()),
2856
3230
  })
@@ -2863,10 +3237,33 @@ export const HostModelProviderInfoSchema = z
2863
3237
  authType: z.enum(["api_key", "oauth"]),
2864
3238
  baseUrl: z.string().optional(),
2865
3239
  settings: CustomModelSettingsSchema.optional(),
3240
+ /** What the provider's selected model reads (protocol 12); absent for a model unknown here. */
3241
+ inputs: z.array(ModelInputSchema).optional(),
2866
3242
  lastUpdated: z.string(),
2867
3243
  active: z.boolean(),
2868
3244
  })
2869
3245
  .strict();
3246
+ /**
3247
+ * `PUT /v1/tenant/models/inputs`: the inputs one catalog model reads (protocol 12), replacing
3248
+ * what the operator added before. Its catalog's own inputs always stay; an empty list removes
3249
+ * the additions. A custom endpoint sets `settings.inputs` on `PUT /v1/tenant/model` instead.
3250
+ */
3251
+ export const PutModelInputsRequestSchema = z
3252
+ .object({
3253
+ requestId: RequestIdSchema.optional(),
3254
+ provider: z.string().min(1),
3255
+ model: z.string().min(1),
3256
+ inputs: z.array(ModelInputSchema),
3257
+ })
3258
+ .strict();
3259
+ /** What one catalog model reads now: its catalog's inputs and the operator's additions. */
3260
+ export const ModelInputsViewSchema = z
3261
+ .object({
3262
+ provider: z.string(),
3263
+ model: z.string(),
3264
+ inputs: z.array(ModelInputSchema),
3265
+ })
3266
+ .strict();
2870
3267
  export const ListProvidersResponseSchema = z
2871
3268
  .object({ providers: z.array(HostModelProviderInfoSchema) })
2872
3269
  .strict();
@@ -2915,7 +3312,7 @@ export const TenantSandboxViewSchema = z
2915
3312
  defaultImage: z.string(),
2916
3313
  config: EffectiveSandboxConfigSchema,
2917
3314
  /**
2918
- * The Tenant's cluster for pod sandboxes (`nylorun sandbox enable`), as the sandboxes
3315
+ * The Tenant's cluster for pod sandboxes (`nylorun local sandbox enable`), as the sandboxes
2919
3316
  * service reports it; null without one, or when the service does not answer.
2920
3317
  */
2921
3318
  cluster: z
@@ -3492,10 +3889,13 @@ export const ToolCallSchema = z
3492
3889
  effectId: z.string(),
3493
3890
  turnId: z.string(),
3494
3891
  callId: z.string().nullable(),
3495
- capabilityId: z.string().nullable(),
3496
3892
  toolName: z.string().nullable(),
3497
3893
  kind: z.enum(TOOL_CALL_KINDS).nullable(),
3498
3894
  server: z.string().nullable(),
3895
+ /** The skill the call ran (see `tool.completed`). */
3896
+ skill: z.string().nullable(),
3897
+ /** The Agent Plugin that brought its MCP server or skill. */
3898
+ plugin: pluginLabelSchema.nullable(),
3499
3899
  /** `held`: the Tool Gate holds it for a person's approval (R5 step 2). */
3500
3900
  status: z.enum(["invoking", "held", ...TOOL_CALL_STATUSES, "uncertain"]),
3501
3901
  attempts: z.number().int().nonnegative(),