@nylorun/core 0.16.0-beta → 0.18.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 (39) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +10 -0
  3. package/dist/compatibility.d.ts +18 -11
  4. package/dist/compatibility.js +18 -11
  5. package/dist/contracts.d.ts +176 -50
  6. package/dist/contracts.js +289 -85
  7. package/dist/define.d.ts +6 -5
  8. package/dist/define.js +3 -2
  9. package/dist/definition/assemble.d.ts +3 -1
  10. package/dist/definition/assemble.js +3 -0
  11. package/dist/definition/code-tools.d.ts +4 -4
  12. package/dist/definition/code-tools.js +3 -2
  13. package/dist/definition/from.d.ts +5 -0
  14. package/dist/definition/from.js +31 -188
  15. package/dist/definition/manifest.d.ts +3 -1
  16. package/dist/definition/manifest.js +4 -1
  17. package/dist/definition/mcp.d.ts +45 -1
  18. package/dist/definition/mcp.js +85 -2
  19. package/dist/definition/removed.d.ts +8 -3
  20. package/dist/definition/removed.js +13 -4
  21. package/dist/definition/sandbox-capability.d.ts +21 -4
  22. package/dist/definition/sandbox-capability.js +56 -19
  23. package/dist/definition/tools-capability.d.ts +37 -0
  24. package/dist/definition/tools-capability.js +98 -0
  25. package/dist/definition/variant.d.ts +2 -1
  26. package/dist/definition/variant.js +40 -4
  27. package/dist/harness-api/messages.d.ts +30 -352
  28. package/dist/harness-api/messages.js +2 -6
  29. package/dist/harness-api/schema.d.ts +701 -13
  30. package/dist/harness-api/schema.js +129 -53
  31. package/dist/harness-api/transcript.d.ts +8 -6
  32. package/dist/harness-api/transcript.js +4 -5
  33. package/dist/project.d.ts +67 -0
  34. package/dist/project.js +210 -0
  35. package/dist/transport.d.ts +52 -0
  36. package/dist/transport.js +73 -0
  37. package/dist/types/manifest.d.ts +42 -14
  38. package/dist/types/tool.d.ts +22 -0
  39. package/package.json +9 -1
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Tools that would run the developer's code (track R2 M6): an agent tool with no `http` and no
3
3
  * `agent` that is not one of the Runtime's built-ins (sandbox tools, skill tools,
4
- * `save_artifact`), and a flow agent's `tool` stage without `http`. The Runtime runs no code
5
- * of yours during a session, so `PUT /v1/agents/:id` refuses a definition with one, and the
6
- * SDK refuses it before sending. The local engine (`@nylorun/harness/run`) still runs
7
- * `tool({ run })`.
4
+ * `save_artifact`, `read_artifact`), and a flow agent's `tool` stage without `http`. The
5
+ * Runtime runs no code of yours during a session, so `PUT /v1/agents/:id` refuses a definition
6
+ * with one, and the SDK refuses it before sending. The local engine (`@nylorun/harness/run`)
7
+ * still runs `tool({ run })`.
8
8
  */
9
9
  import type { AgentManifest } from "../types/manifest.js";
10
10
  import type { WorkflowManifest } from "../types/workflow.js";
@@ -1,6 +1,6 @@
1
1
  import { isSandboxToolName } from "../utils/sandbox.js";
2
2
  import { forEachFlowNode } from "./flow/paths.js";
3
- import { ARTIFACTS_CAPABILITY_ID, SAVE_ARTIFACT_TOOL } from "./sandbox-capability.js";
3
+ import { ARTIFACTS_CAPABILITY_ID, READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL, } from "./sandbox-capability.js";
4
4
  import { isSkillTool } from "./skill-tools.js";
5
5
  /** Every code tool of a definition document, the agents it embeds or uses as tools included. */
6
6
  export function codeToolsOf(manifest, into = []) {
@@ -29,7 +29,8 @@ function runsWithoutCode(capability, tool) {
29
29
  return true;
30
30
  if (capability.sandbox !== undefined && isSandboxToolName(tool.name))
31
31
  return true;
32
- if (capability.id === ARTIFACTS_CAPABILITY_ID && tool.name === SAVE_ARTIFACT_TOOL)
32
+ if (capability.id === ARTIFACTS_CAPABILITY_ID &&
33
+ (tool.name === SAVE_ARTIFACT_TOOL || tool.name === READ_ARTIFACT_TOOL))
33
34
  return true;
34
35
  return isSkillTool(capability, tool.name);
35
36
  }
@@ -6,6 +6,11 @@ import type { Implementations } from "./implementations.js";
6
6
  export interface SessionToolRef {
7
7
  readonly capabilityId: string;
8
8
  readonly name: string;
9
+ /**
10
+ * Text the model reads with the capability's instructions while the tool is advertised, such
11
+ * as `tool_search`'s note of the servers whose tools are deferred (R2b C10). Not hashed.
12
+ */
13
+ readonly instructions?: readonly string[];
9
14
  }
10
15
  /** Rebuild an agent from manifest JSON + in-process implementations (T28). */
11
16
  export declare function agentFrom<Info = unknown>(json: AgentManifest | JsonObject, implementations: Implementations<Info>, options?: {
@@ -1,13 +1,11 @@
1
1
  import { HarnessError } from "../errors.js";
2
2
  import { assembleAgent } from "./assemble.js";
3
3
  import { schemaFromJSON } from "./schema-json.js";
4
- import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
5
- import { REMOVED_CAPABILITY_FIELDS, manifestVersionIssue } from "./removed.js";
4
+ import { assertJson, deepFreeze } from "../utils/immutable.js";
6
5
  import { delegateFromManifest, delegateOf } from "./delegate.js";
7
- import { stdioMcpRefusal } from "./mcp.js";
8
6
  import { SKILL_TOOL_NAMES } from "./skill-tools.js";
9
- import { skillFilesIssue } from "../utils/definition-files.js";
10
7
  import { httpToolFromManifest, httpToolOf } from "./http-tool.js";
8
+ import { AgentManifestSchema } from "../contracts.js";
11
9
  /** Tools the engine or the Runtime runs, which need no implementation: agents and HTTP tools. */
12
10
  const declarative = (tool) => delegateOf(tool) !== undefined || httpToolOf(tool) !== undefined;
13
11
  /** Rebuild an agent from manifest JSON + in-process implementations (T28). */
@@ -20,8 +18,12 @@ export function agentFrom(json, implementations, options) {
20
18
  for (const capability of manifest.capabilities) {
21
19
  const impl = implementations[capability.id] ?? {};
22
20
  const tools = resolveTools(capability, impl.tools);
23
- const session = sessionTools
24
- .filter((item) => item.capabilityId === capability.id)
21
+ const owned = sessionTools.filter((item) => item.capabilityId === capability.id);
22
+ const instructions = [
23
+ ...(capability.instructions ?? []),
24
+ ...owned.flatMap((item) => item.instructions ?? []),
25
+ ];
26
+ const session = owned
25
27
  .map((item) => {
26
28
  const live = impl.tools?.[item.name];
27
29
  if (!live)
@@ -35,8 +37,8 @@ export function agentFrom(json, implementations, options) {
35
37
  request.configuration.tools.set(capability.id, advertised.map((tool) => (declarative(tool)
36
38
  ? tool
37
39
  : implementations[capability.id]?.tools?.[tool.name]) ?? tool));
38
- if (capability.instructions)
39
- request.configuration.instructions.set(capability.id, capability.instructions);
40
+ if (instructions.length > 0)
41
+ request.configuration.instructions.set(capability.id, instructions);
40
42
  return next();
41
43
  });
42
44
  entries.push(Object.freeze({
@@ -97,6 +99,7 @@ export function agentFrom(json, implementations, options) {
97
99
  metadata: manifest.metadata,
98
100
  outputSchema,
99
101
  runtime: manifest.runtime,
102
+ manifestSchemaVersion: manifest.manifestSchemaVersion,
100
103
  }, dynamics);
101
104
  if (!result.ok)
102
105
  throw new HarnessError("agent.build-failed", result.diagnostics.map((item) => item.message).join("; "));
@@ -144,187 +147,27 @@ function resolveTools(capability, tools) {
144
147
  throw new HarnessError("agent.build-failed", `Missing tool implementation '${declared.name}' for capability '${capability.id}'`);
145
148
  });
146
149
  }
150
+ /**
151
+ * The manifest as `AgentManifestSchema` accepts it (the Runtime's own check), as a frozen copy.
152
+ * A refusal is `agent.build-failed` with the schema's messages.
153
+ */
147
154
  function normalizeManifest(json) {
148
155
  if (!json || typeof json !== "object" || Array.isArray(json))
149
156
  throw new HarnessError("agent.build-failed", "Agent.from requires a manifest object");
150
- const value = json;
151
- if (typeof value.id !== "string" || !value.id)
152
- throw new HarnessError("agent.build-failed", "Manifest id must be a non-empty string");
153
- if ("name" in value && value.name !== undefined) {
154
- if (typeof value.name !== "string" || !value.name)
155
- throw new HarnessError("agent.build-failed", "Manifest name must be a non-empty string");
156
- }
157
- if (!Array.isArray(value.capabilities))
158
- throw new HarnessError("agent.build-failed", "Manifest capabilities must be an array");
159
- if ("schemaVersion" in value && value.schemaVersion !== undefined)
160
- throw new HarnessError("agent.build-failed", "Manifest field schemaVersion was renamed to manifestSchemaVersion");
161
- const versionIssue = manifestVersionIssue(value.manifestSchemaVersion);
162
- if (versionIssue)
163
- throw new HarnessError("agent.build-failed", versionIssue);
164
- if ("functions" in value && value.functions !== undefined)
165
- throw new HarnessError("agent.build-failed", "Functions are not available yet");
166
- // Reject top-level model (Runtime-owned).
167
- if ("model" in value && value.model !== undefined)
168
- throw new HarnessError("agent.build-failed", "Manifest must not include top-level model; Runtime owns model resolution");
169
- if ("description" in value && value.description !== undefined) {
170
- if (typeof value.description !== "string")
171
- throw new HarnessError("agent.build-failed", "Manifest description must be a string");
172
- }
173
- const metadata = "metadata" in value && value.metadata !== undefined
174
- ? copyJsonObject(value.metadata, "metadata")
175
- : undefined;
176
- const runtime = normalizeRuntime(value.runtime);
177
- const capabilities = value.capabilities.map(normalizeCapability);
178
- const servers = new Set();
179
- for (const capability of capabilities)
180
- for (const name of Object.keys(capability.mcpServers ?? {})) {
181
- if (servers.has(name))
182
- throw new HarnessError("agent.build-failed", `Duplicate MCP server '${name}'`);
183
- servers.add(name);
184
- }
185
- return deepFreeze({
186
- manifestSchemaVersion: 5,
187
- id: value.id,
188
- ...(typeof value.name === "string" && value.name ? { name: value.name } : {}),
189
- ...(typeof value.description === "string"
190
- ? { description: value.description }
191
- : {}),
192
- ...(metadata === undefined ? {} : { metadata }),
193
- ...(value.outputSchema && typeof value.outputSchema === "object"
194
- ? { outputSchema: value.outputSchema }
195
- : {}),
196
- capabilities,
197
- ...(runtime === undefined ? {} : { runtime }),
198
- });
199
- }
200
- function normalizeRuntime(value) {
201
- if (value === undefined)
202
- return undefined;
203
- if (!value ||
204
- typeof value !== "object" ||
205
- Array.isArray(value) ||
206
- Object.keys(value).length > 0)
207
- throw new HarnessError("agent.build-failed", "runtime must be an empty object when present");
208
- return {};
209
- }
210
- function normalizeCapability(capability) {
211
- const raw = capability;
212
- if ("name" in raw && raw.name !== undefined) {
213
- if (typeof raw.name !== "string" || !raw.name)
214
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' name must be a non-empty string`);
215
- }
216
- if ("description" in raw && raw.description !== undefined) {
217
- if (typeof raw.description !== "string")
218
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' description must be a string`);
219
- }
220
- if ("model" in raw && raw.model !== undefined)
221
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' must not include model; Runtime owns model resolution`);
222
- if (capability.type !== "agent" && capability.type !== "agent-plugin")
223
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}' type must be agent or agent-plugin`);
224
- for (const [field, message] of Object.entries(REMOVED_CAPABILITY_FIELDS))
225
- if (field in raw)
226
- throw new HarnessError("agent.build-failed", `Capability '${capability.id}': ${message}`);
227
- const metadata = capability.metadata === undefined
228
- ? undefined
229
- : copyJsonObject(capability.metadata, "metadata");
230
- const mcpServers = normalizeMcpServers(capability.id, capability.mcpServers);
231
- const skills = normalizeSkills(capability.id, capability.skills);
232
- return Object.freeze({
233
- id: capability.id,
234
- type: capability.type,
235
- ...(typeof raw.name === "string" && raw.name ? { name: raw.name } : {}),
236
- ...(typeof raw.description === "string"
237
- ? { description: raw.description }
238
- : {}),
239
- ...(metadata === undefined ? {} : { metadata }),
240
- ...(capability.instructions
241
- ? { instructions: Object.freeze([...capability.instructions]) }
242
- : {}),
243
- ...(capability.tools
244
- ? { tools: Object.freeze(capability.tools.map(normalizeTool)) }
245
- : {}),
246
- ...(skills === undefined ? {} : { skills }),
247
- ...(mcpServers === undefined ? {} : { mcpServers }),
248
- ...(capability.sandbox === undefined
249
- ? {}
250
- : {
251
- sandbox: deepFreeze(copyJsonObject(capability.sandbox, "sandbox")),
252
- }),
253
- });
254
- }
255
- function normalizeSkills(capabilityId, skills) {
256
- if (skills === undefined)
257
- return undefined;
258
- if (!skills ||
259
- typeof skills !== "object" ||
260
- Array.isArray(skills) ||
261
- Object.keys(skills).length === 0)
262
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skills must be a non-empty map or omitted`);
263
- const normalized = {};
264
- for (const [key, skill] of Object.entries(skills)) {
265
- if (!skill ||
266
- typeof skill !== "object" ||
267
- skill.name !== key ||
268
- typeof skill.description !== "string" ||
269
- skill.description.length === 0)
270
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skills key '${key}' must equal the skill name`);
271
- const issue = skillFilesIssue(skill.files);
272
- if (issue)
273
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' skill '${key}' ${issue}`);
274
- normalized[key] = Object.freeze({
275
- name: skill.name,
276
- description: skill.description,
277
- files: Object.freeze({ ...skill.files }),
278
- });
279
- }
280
- return Object.freeze(normalized);
281
- }
282
- function normalizeMcpServers(capabilityId, servers) {
283
- if (servers === undefined)
284
- return undefined;
285
- if (!servers ||
286
- typeof servers !== "object" ||
287
- Array.isArray(servers) ||
288
- Object.keys(servers).length === 0)
289
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers must be a non-empty map or omitted`);
290
- const normalized = {};
291
- for (const [key, server] of Object.entries(servers)) {
292
- if (server.type === "stdio")
293
- throw new HarnessError("agent.build-failed", stdioMcpRefusal(key));
294
- if (!isMcpServer(server) || server.name !== key)
295
- throw new HarnessError("agent.build-failed", `Capability '${capabilityId}' mcpServers key '${key}' must equal the server name`);
296
- normalized[key] = server;
297
- }
298
- return Object.freeze(normalized);
299
- }
300
- function isMcpServer(value) {
301
- if (!value || typeof value !== "object" || Array.isArray(value))
302
- return false;
303
- const server = value;
304
- if (typeof server.name !== "string" || !server.name)
305
- return false;
306
- if (server.type === "streamable-http" || server.type === "sse")
307
- return typeof server.url === "string" && server.url.length > 0;
308
- return false;
309
- }
310
- function normalizeTool(tool) {
311
- return Object.freeze({
312
- name: tool.name,
313
- ...(tool.description === undefined
314
- ? {}
315
- : { description: tool.description }),
316
- inputSchema: tool.inputSchema,
317
- ...(tool.outputSchema === undefined
318
- ? {}
319
- : { outputSchema: tool.outputSchema }),
320
- ...(tool.agent === undefined
321
- ? {}
322
- : {
323
- agent: "kind" in tool.agent
324
- ? deepFreeze(JSON.parse(JSON.stringify(tool.agent)))
325
- : normalizeManifest(tool.agent),
326
- }),
327
- ...(tool.http === undefined ? {} : { http: Object.freeze({ ...tool.http }) }),
328
- ...(tool.approval === undefined ? {} : { approval: tool.approval }),
329
- });
157
+ const parsed = AgentManifestSchema.safeParse(json);
158
+ if (!parsed.success)
159
+ throw new HarnessError("agent.build-failed", parsed.error.issues
160
+ .map((issue) => issue.path.length === 0
161
+ ? issue.message
162
+ : `${issue.path.join(".")}: ${issue.message}`)
163
+ .join("; "));
164
+ // The schema checks no value of a JSON object; metadata must be JSON data, as before.
165
+ const manifest = parsed.data;
166
+ for (const metadata of [
167
+ manifest.metadata,
168
+ ...manifest.capabilities.map((capability) => capability.metadata),
169
+ ])
170
+ if (metadata !== undefined)
171
+ assertJson(metadata, "metadata");
172
+ return deepFreeze(JSON.parse(JSON.stringify(manifest)));
330
173
  }
@@ -1,5 +1,5 @@
1
1
  import type { BoundMiddleware } from "./bound.js";
2
- import type { AgentManifest, RuntimeManifest } from "../types/manifest.js";
2
+ import type { AgentManifest, ManifestSchemaVersion, RuntimeManifest } from "../types/manifest.js";
3
3
  import type { JsonObject } from "../types/shared.js";
4
4
  import type { ToolSchemaSource } from "../types/tool.js";
5
5
  export declare function createManifest(input: {
@@ -10,4 +10,6 @@ export declare function createManifest(input: {
10
10
  outputSchema?: ToolSchemaSource;
11
11
  runtime?: RuntimeManifest;
12
12
  middleware: readonly BoundMiddleware[];
13
+ /** The version a manifest rebuilt from JSON had; it never goes below what the capabilities need. */
14
+ manifestSchemaVersion?: ManifestSchemaVersion;
13
15
  }): AgentManifest;
@@ -2,11 +2,14 @@ import { bindOutputContract } from "./output-contract.js";
2
2
  import { normalizedSchemasFor } from "./schema.js";
3
3
  import { delegateOf } from "./delegate.js";
4
4
  import { httpToolOf } from "./http-tool.js";
5
+ import { manifestVersionFor } from "./mcp.js";
5
6
  import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
6
7
  export function createManifest(input) {
7
8
  const capabilities = input.middleware.map((item) => projectCapability(item));
9
+ // 6 only when an MCP server sets `tools` or `deferred` (R2b C9), so other hashes stay.
10
+ const needed = manifestVersionFor(capabilities);
8
11
  return deepFreeze({
9
- manifestSchemaVersion: 5,
12
+ manifestSchemaVersion: Math.max(needed, input.manifestSchemaVersion ?? needed),
10
13
  id: input.id,
11
14
  ...(input.name === undefined ? {} : { name: input.name }),
12
15
  ...(input.description === undefined
@@ -1,5 +1,5 @@
1
1
  import type { CapabilityDeclaration } from "../types/middleware.js";
2
- import type { McpServerManifest } from "../types/manifest.js";
2
+ import type { ApprovalMode, ManifestSchemaVersion, McpServerManifest } from "../types/manifest.js";
3
3
  type WithOptionalName<T> = T extends {
4
4
  readonly name: string;
5
5
  } ? Omit<T, "name"> & {
@@ -30,10 +30,54 @@ export declare class McpError extends Error {
30
30
  * github: { type: "streamable-http", url: "https://mcp.example.com/github" },
31
31
  * })
32
32
  * ```
33
+ *
34
+ * `tools` sets tools by the server's own names, with `"*"` for the rest: an allowlist, approval
35
+ * per tool, deferral per tool (R2b C9, C10). `deferred` defers every tool of the server. Either
36
+ * makes the manifest v6.
37
+ *
38
+ * ```ts
39
+ * Agent({ id: "assistant" }).mcp({
40
+ * github: {
41
+ * type: "streamable-http",
42
+ * url: "https://api.githubcopilot.com/mcp/",
43
+ * tools: {
44
+ * "*": { enabled: false },
45
+ * search_issues: { enabled: true },
46
+ * create_issue: { enabled: true, approval: "always" },
47
+ * },
48
+ * },
49
+ * })
50
+ * ```
33
51
  */
34
52
  export declare function mcp(servers: Readonly<Record<string, McpServerSpec>>, options?: McpOptions): McpCapability;
35
53
  /** Why a `stdio` MCP server is refused: the one message the builder, plugins and manifests give. */
36
54
  export declare function stdioMcpRefusal(name: string): string;
37
55
  /** Validate a map of MCP servers and fill each `name` from its key. */
38
56
  export declare function normalizeMcpServers(servers: Readonly<Record<string, McpServerSpec>>, caller?: string): Readonly<Record<string, McpServerManifest>>;
57
+ /** The key of an MCP server's `tools` map that sets every tool without an entry (R2b C9). */
58
+ export declare const MCP_TOOL_DEFAULTS = "*";
59
+ /** A tool's settings once resolved (R2b C9): its entry, then `"*"`, then the server, then the default. */
60
+ export interface ResolvedMcpToolSettings {
61
+ readonly enabled: boolean;
62
+ readonly approval: ApprovalMode;
63
+ /** Undefined: nothing sets it, and the Runtime decides (R2b C10, automatic deferral). */
64
+ readonly deferred?: boolean;
65
+ }
66
+ /**
67
+ * The settings of the server's tool named `serverToolName` (its own name, before C6 renaming):
68
+ * from the tool's entry in `tools`, then the `"*"` entry, then the server, then the default
69
+ * (enabled, approval `never`, deferral automatic).
70
+ */
71
+ export declare function mcpToolSettings(server: McpServerManifest, serverToolName: string): ResolvedMcpToolSettings;
72
+ /** True when the server sets `tools` or `deferred`, which need manifest v6 (R2b C9, Q19). */
73
+ export declare function usesMcpToolSettings(server: McpServerManifest): boolean;
74
+ /** Why a manifest v5 with this server is refused (R2b C9, Q19). */
75
+ export declare function mcpToolSettingsVersionIssue(serverName: string): string;
76
+ /**
77
+ * The manifest version a definition with these capabilities needs: 6 when an MCP server sets
78
+ * `tools` or `deferred`, else 5, so a manifest that uses neither keeps its hash (Q19).
79
+ */
80
+ export declare function manifestVersionFor(capabilities: readonly {
81
+ readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
82
+ }[]): ManifestSchemaVersion;
39
83
  export {};
@@ -19,6 +19,24 @@ export class McpError extends Error {
19
19
  * github: { type: "streamable-http", url: "https://mcp.example.com/github" },
20
20
  * })
21
21
  * ```
22
+ *
23
+ * `tools` sets tools by the server's own names, with `"*"` for the rest: an allowlist, approval
24
+ * per tool, deferral per tool (R2b C9, C10). `deferred` defers every tool of the server. Either
25
+ * makes the manifest v6.
26
+ *
27
+ * ```ts
28
+ * Agent({ id: "assistant" }).mcp({
29
+ * github: {
30
+ * type: "streamable-http",
31
+ * url: "https://api.githubcopilot.com/mcp/",
32
+ * tools: {
33
+ * "*": { enabled: false },
34
+ * search_issues: { enabled: true },
35
+ * create_issue: { enabled: true, approval: "always" },
36
+ * },
37
+ * },
38
+ * })
39
+ * ```
22
40
  */
23
41
  export function mcp(servers, options = {}) {
24
42
  const id = options.id ?? "mcp";
@@ -43,7 +61,10 @@ export function normalizeMcpServers(servers, caller = "mcp()") {
43
61
  if (isRecord(server) && server.type === "stdio")
44
62
  throw new McpError("mcp.stdio", stdioMcpRefusal(key));
45
63
  if (!isMcpServer(server)) {
46
- throw new McpError("mcp.invalid-server", `MCP server '${key}' is not a valid streamable-http or sse declaration`);
64
+ throw new McpError("mcp.invalid-server", `MCP server '${key}' is not a valid streamable-http or sse declaration` +
65
+ (isRecord(server) && (server.tools !== undefined || server.deferred !== undefined)
66
+ ? ": deferred is a boolean, and tools maps tool names to { enabled?, approval?, deferred? }"
67
+ : ""));
47
68
  }
48
69
  if (server.name !== key) {
49
70
  throw new McpError("mcp.name-mismatch", `MCP server key '${key}' must equal the server name '${server.name}'`);
@@ -52,6 +73,42 @@ export function normalizeMcpServers(servers, caller = "mcp()") {
52
73
  }
53
74
  return Object.freeze(mcpServers);
54
75
  }
76
+ /** The key of an MCP server's `tools` map that sets every tool without an entry (R2b C9). */
77
+ export const MCP_TOOL_DEFAULTS = "*";
78
+ /**
79
+ * The settings of the server's tool named `serverToolName` (its own name, before C6 renaming):
80
+ * from the tool's entry in `tools`, then the `"*"` entry, then the server, then the default
81
+ * (enabled, approval `never`, deferral automatic).
82
+ */
83
+ export function mcpToolSettings(server, serverToolName) {
84
+ const own = Object.hasOwn(server.tools ?? {}, serverToolName)
85
+ ? server.tools[serverToolName]
86
+ : undefined;
87
+ const defaults = server.tools?.[MCP_TOOL_DEFAULTS];
88
+ const deferred = own?.deferred ?? defaults?.deferred ?? server.deferred;
89
+ return {
90
+ enabled: own?.enabled ?? defaults?.enabled ?? true,
91
+ approval: own?.approval ?? defaults?.approval ?? server.approval ?? "never",
92
+ ...(deferred === undefined ? {} : { deferred }),
93
+ };
94
+ }
95
+ /** True when the server sets `tools` or `deferred`, which need manifest v6 (R2b C9, Q19). */
96
+ export function usesMcpToolSettings(server) {
97
+ return server.tools !== undefined || server.deferred !== undefined;
98
+ }
99
+ /** Why a manifest v5 with this server is refused (R2b C9, Q19). */
100
+ export function mcpToolSettingsVersionIssue(serverName) {
101
+ return `MCP server '${serverName}' sets tools or deferred, which need manifestSchemaVersion 6. Rebuild the agent with the current SDK`;
102
+ }
103
+ /**
104
+ * The manifest version a definition with these capabilities needs: 6 when an MCP server sets
105
+ * `tools` or `deferred`, else 5, so a manifest that uses neither keeps its hash (Q19).
106
+ */
107
+ export function manifestVersionFor(capabilities) {
108
+ return capabilities.some((capability) => Object.values(capability.mcpServers ?? {}).some(usesMcpToolSettings))
109
+ ? 6
110
+ : 5;
111
+ }
55
112
  function freezeServer(server) {
56
113
  return Object.freeze({
57
114
  name: server.name,
@@ -61,6 +118,19 @@ function freezeServer(server) {
61
118
  ? {}
62
119
  : { headers: Object.freeze({ ...server.headers }) }),
63
120
  ...(server.approval === undefined ? {} : { approval: server.approval }),
121
+ ...(server.deferred === undefined ? {} : { deferred: server.deferred }),
122
+ ...(server.tools === undefined
123
+ ? {}
124
+ : {
125
+ tools: Object.freeze(Object.fromEntries(Object.entries(server.tools).map(([name, settings]) => [
126
+ name,
127
+ Object.freeze({
128
+ ...(settings.enabled === undefined ? {} : { enabled: settings.enabled }),
129
+ ...(settings.approval === undefined ? {} : { approval: settings.approval }),
130
+ ...(settings.deferred === undefined ? {} : { deferred: settings.deferred }),
131
+ }),
132
+ ]))),
133
+ }),
64
134
  });
65
135
  }
66
136
  function isMcpServer(value) {
@@ -69,9 +139,22 @@ function isMcpServer(value) {
69
139
  if (value.type === "streamable-http" || value.type === "sse")
70
140
  return (typeof value.url === "string" &&
71
141
  value.url.length > 0 &&
72
- (value.approval === undefined || APPROVAL_MODES.includes(value.approval)));
142
+ (value.approval === undefined || isApprovalMode(value.approval)) &&
143
+ (value.deferred === undefined || typeof value.deferred === "boolean") &&
144
+ (value.tools === undefined || isToolSettingsMap(value.tools)));
73
145
  return false;
74
146
  }
147
+ const isApprovalMode = (value) => APPROVAL_MODES.includes(value);
148
+ function isToolSettingsMap(value) {
149
+ if (!isRecord(value))
150
+ return false;
151
+ return Object.entries(value).every(([name, settings]) => name.length > 0 &&
152
+ isRecord(settings) &&
153
+ Object.keys(settings).every((key) => key === "enabled" || key === "approval" || key === "deferred") &&
154
+ (settings.enabled === undefined || typeof settings.enabled === "boolean") &&
155
+ (settings.approval === undefined || isApprovalMode(settings.approval)) &&
156
+ (settings.deferred === undefined || typeof settings.deferred === "boolean"));
157
+ }
75
158
  function isRecord(value) {
76
159
  return !!value && typeof value === "object" && !Array.isArray(value);
77
160
  }
@@ -1,10 +1,15 @@
1
1
  /**
2
- * Manifest fields that manifest v5 removed, and what replaces each. Manifest v5 (with workflow
2
+ * Capability fields that manifest v5 removed, and what replaces each. Manifest v5 (with workflow
3
3
  * manifest v3 for flow agents) is the first where the Runtime never calls the developer's code
4
- * during a session (see MIGRATION.md).
4
+ * during a session (see MIGRATION.md). `model` went earlier: the Runtime owns the model.
5
5
  */
6
6
  export declare const REMOVED_CAPABILITY_FIELDS: Readonly<Record<string, string>>;
7
- /** Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5. */
7
+ /** Manifest fields an older SDK wrote, and why each is refused. */
8
+ export declare const REMOVED_MANIFEST_FIELDS: Readonly<Record<string, string>>;
9
+ /**
10
+ * Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5 and
11
+ * version 6 (R2b C9: an MCP server's `tools` and `deferred`; v5 is accepted unchanged).
12
+ */
8
13
  export declare function manifestVersionIssue(version: unknown): string | undefined;
9
14
  /** Why a workflow manifest with this `workflowSchemaVersion` is refused, or undefined for version 3. */
10
15
  export declare function workflowVersionIssue(version: unknown): string | undefined;
@@ -1,16 +1,25 @@
1
1
  /**
2
- * Manifest fields that manifest v5 removed, and what replaces each. Manifest v5 (with workflow
2
+ * Capability fields that manifest v5 removed, and what replaces each. Manifest v5 (with workflow
3
3
  * manifest v3 for flow agents) is the first where the Runtime never calls the developer's code
4
- * during a session (see MIGRATION.md).
4
+ * during a session (see MIGRATION.md). `model` went earlier: the Runtime owns the model.
5
5
  */
6
6
  export const REMOVED_CAPABILITY_FIELDS = Object.freeze({
7
7
  hooks: "hooks were removed: the Runtime no longer calls your code during a session. Use an HTTP tool, approval on a tool, or a loop verifier instead (see MIGRATION.md)",
8
8
  beforeModelCall: "beforeModelCall was removed with hooks (see MIGRATION.md)",
9
9
  afterModelCall: "afterModelCall was removed with hooks (see MIGRATION.md)",
10
+ model: "A capability must not include model; the Runtime owns model resolution",
10
11
  });
11
- /** Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5. */
12
+ /** Manifest fields an older SDK wrote, and why each is refused. */
13
+ export const REMOVED_MANIFEST_FIELDS = Object.freeze({
14
+ schemaVersion: "Manifest field schemaVersion was renamed to manifestSchemaVersion",
15
+ model: "Manifest must not include top-level model; Runtime owns model resolution",
16
+ });
17
+ /**
18
+ * Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5 and
19
+ * version 6 (R2b C9: an MCP server's `tools` and `deferred`; v5 is accepted unchanged).
20
+ */
12
21
  export function manifestVersionIssue(version) {
13
- if (version === 5)
22
+ if (version === 5 || version === 6)
14
23
  return undefined;
15
24
  if (version === 4 || version === 3)
16
25
  return `manifestSchemaVersion ${version} is no longer supported: manifest v5 removed hooks. Rebuild the agent with the current SDK (see MIGRATION.md)`;
@@ -9,11 +9,28 @@ export declare const SANDBOX_CAPABILITY_ID = "nylorun.sandbox";
9
9
  export declare const ARTIFACTS_CAPABILITY_ID = "nylorun.artifacts";
10
10
  export declare const SAVE_ARTIFACT_TOOL = "save_artifact";
11
11
  /**
12
- * The capability manifest that gives a session `save_artifact`: one tool that stores a sandbox
13
- * file, or inline text, as a file artifact of the session. Its schema is part of the hashed
14
- * manifest; change it deliberately.
12
+ * The tool that reads an artifact of the session in pages (R2b C11, Q24): how the model reads a
13
+ * tool result the Runtime stored because it was too large to show. With or without a sandbox.
15
14
  */
16
- export declare function artifactsCapabilityManifest(): CapabilityManifest;
15
+ export declare const READ_ARTIFACT_TOOL = "read_artifact";
16
+ /** The most `read_artifact` returns per call (R2b C11): 32 KiB, the inline cap of a tool result. */
17
+ export declare const READ_ARTIFACT_MAX_BYTES: number;
18
+ /** What the `nylorun.artifacts` capability gives a session. */
19
+ export interface ArtifactsCapabilityOptions {
20
+ /** `save_artifact`, which comes with a sandbox. Default true. */
21
+ readonly save?: boolean;
22
+ /**
23
+ * `read_artifact` (R2b C11), for an agent whose MCP or HTTP tool results the Runtime may store
24
+ * as artifacts. Default false.
25
+ */
26
+ readonly read?: boolean;
27
+ }
28
+ /**
29
+ * The capability manifest that gives a session `save_artifact`, which stores a sandbox file, or
30
+ * inline text, as a file artifact of the session, and `read_artifact`, which reads one in pages.
31
+ * Its schemas are part of the hashed manifest; change them deliberately.
32
+ */
33
+ export declare function artifactsCapabilityManifest(options?: ArtifactsCapabilityOptions): CapabilityManifest;
17
34
  /**
18
35
  * The capability manifest that gives a session its sandbox: the six built-in tools, the sandbox
19
36
  * instructions and the resolved spec. The Runtime adds it to a session's pinned manifest. Its