@nylorun/core 0.15.0-beta → 0.17.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.
package/dist/contracts.js CHANGED
@@ -2,8 +2,8 @@
2
2
  import { z } from "zod";
3
3
  import { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, isSandboxHostPattern, parseSandboxDuration, parseSandboxSize, } from "./utils/sandbox.js";
4
4
  import { REMOVED_CAPABILITY_FIELDS, manifestVersionIssue, workflowVersionIssue, } from "./definition/removed.js";
5
- import { DELEGATE_INPUT_SCHEMA } from "./definition/delegate.js";
6
- import { stdioMcpRefusal } from "./definition/mcp.js";
5
+ import { DELEGATE_INPUT_SCHEMA, DELEGATE_NAME_PATTERN } from "./definition/delegate.js";
6
+ import { mcpToolSettingsVersionIssue, stdioMcpRefusal, usesMcpToolSettings, } from "./definition/mcp.js";
7
7
  import { APPROVAL_MODES, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, httpUrlIssue, } from "./definition/http-tool.js";
8
8
  import { canonical } from "./utils/canonical.js";
9
9
  import { DEFINITION_FILE_MAX_BYTES, skillFilesIssue } from "./utils/definition-files.js";
@@ -25,23 +25,46 @@ const jsonValue = z
25
25
  z.record(z.string(), jsonValue),
26
26
  ]))
27
27
  .meta({ id: "JsonValue" });
28
+ /**
29
+ * A name the model sees in a tool name (R2b C6): a declared tool's, or an MCP server's, which
30
+ * prefixes its tools' names. Letters, digits, `_` and `-`, up to 64: what every provider accepts.
31
+ */
32
+ const modelFacingName = (what) => z.string().regex(DELEGATE_NAME_PATTERN, {
33
+ error: (issue) => `${what} name '${String(issue.input)}' may use only letters, digits, _ and -, up to 64 characters, so that every model provider accepts it`,
34
+ });
35
+ /** One tool's settings on an MCP server (manifest v6, R2b C9). */
36
+ const mcpToolSettingsSchema = z
37
+ .object({
38
+ enabled: z.boolean().optional(),
39
+ approval: z.enum(APPROVAL_MODES).optional(),
40
+ deferred: z.boolean().optional(),
41
+ })
42
+ .strict()
43
+ .meta({ id: "McpToolSettings" });
44
+ /** Manifest v6 (R2b C9, C10): per-tool settings keyed by the server's tool names, `"*"` for the rest. */
45
+ const mcpServerSettings = {
46
+ deferred: z.boolean().optional(),
47
+ tools: z.record(z.string().min(1), mcpToolSettingsSchema).optional(),
48
+ };
28
49
  const mcpServerSchema = z.discriminatedUnion("type", [
29
50
  z
30
51
  .object({
31
- name: z.string().min(1),
52
+ name: modelFacingName("MCP server"),
32
53
  type: z.literal("streamable-http"),
33
54
  url: z.string().min(1),
34
55
  headers: z.record(z.string(), z.string()).optional(),
35
56
  approval: z.enum(APPROVAL_MODES).optional(),
57
+ ...mcpServerSettings,
36
58
  })
37
59
  .strict(),
38
60
  z
39
61
  .object({
40
- name: z.string().min(1),
62
+ name: modelFacingName("MCP server"),
41
63
  type: z.literal("sse"),
42
64
  url: z.string().min(1),
43
65
  headers: z.record(z.string(), z.string()).optional(),
44
66
  approval: z.enum(APPROVAL_MODES).optional(),
67
+ ...mcpServerSettings,
45
68
  })
46
69
  .strict(),
47
70
  ], { error: (issue) => stdioIssue(issue.input) });
@@ -121,7 +144,7 @@ const reservedKind = (what) => z
121
144
  const reservedToolKind = reservedKind("tool");
122
145
  const toolManifestSchema = z
123
146
  .object({
124
- name: z.string().min(1),
147
+ name: modelFacingName("Tool"),
125
148
  description: z.string().optional(),
126
149
  inputSchema: jsonObject,
127
150
  outputSchema: jsonObject.optional(),
@@ -157,7 +180,10 @@ const removedFieldError = (issue) => {
157
180
  };
158
181
  export const AgentManifestSchema = z
159
182
  .object({
160
- manifestSchemaVersion: z.literal(5, { error: (issue) => manifestVersionIssue(issue.input) }),
183
+ // 6 adds an MCP server's `tools` and `deferred` (R2b C9); 5 is accepted unchanged.
184
+ manifestSchemaVersion: z.union([z.literal(5), z.literal(6)], {
185
+ error: (issue) => manifestVersionIssue(issue.input),
186
+ }),
161
187
  id: z.string().min(1),
162
188
  name: z.string().min(1).optional(),
163
189
  description: z.string().optional(),
@@ -252,6 +278,8 @@ export const AgentManifestSchema = z
252
278
  message: `Duplicate MCP server '${server.name}'`,
253
279
  });
254
280
  servers.add(server.name);
281
+ if (manifest.manifestSchemaVersion === 5 && usesMcpToolSettings(server))
282
+ ctx.addIssue({ code: "custom", message: mcpToolSettingsVersionIssue(server.name) });
255
283
  }
256
284
  }
257
285
  });
@@ -795,29 +823,6 @@ const vaultWriteBase = {
795
823
  requestId: RequestIdSchema,
796
824
  idempotencyKey: IdempotencyKeySchema,
797
825
  };
798
- const tokenEndpointAuthSchema = z.discriminatedUnion("type", [
799
- z.object({ type: z.literal("none") }).strict(),
800
- z
801
- .object({
802
- type: z.literal("client_secret_basic"),
803
- clientSecret: z.string().min(1),
804
- })
805
- .strict(),
806
- z
807
- .object({
808
- type: z.literal("client_secret_post"),
809
- clientSecret: z.string().min(1),
810
- })
811
- .strict(),
812
- ]);
813
- const oauthRefreshSchema = z
814
- .object({
815
- tokenEndpoint: z.string().min(1),
816
- clientId: z.string().min(1),
817
- refreshToken: z.string().min(1),
818
- tokenEndpointAuth: tokenEndpointAuthSchema,
819
- })
820
- .strict();
821
826
  /** The owner of every installation vault (`scope: "installation"`); a reserved subject. */
822
827
  export const INSTALLATION_OWNER = "installation";
823
828
  export const CreateVaultRequestSchema = z
@@ -845,6 +850,67 @@ export const CreateVaultRequestSchema = z
845
850
  else if (value.ownerUserId !== undefined && value.ownerUserId !== INSTALLATION_OWNER)
846
851
  ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "An installation vault is owned by installation" });
847
852
  });
853
+ /** An RFC 9110 field name. */
854
+ const HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
855
+ const CredentialHeaderNameSchema = z
856
+ .string()
857
+ .regex(HEADER_NAME_PATTERN, "A header name is an RFC 9110 token");
858
+ /** A credential header's value: no CR, LF or NUL. */
859
+ const CredentialHeaderValueSchema = z
860
+ .string()
861
+ .min(1)
862
+ .refine((value) => !/[\r\n\0]/.test(value), "A header value has no CR, LF or NUL");
863
+ /** A `headers` credential's map (Q6): one or more headers sent on every request. */
864
+ const CredentialHeadersSchema = z
865
+ .record(CredentialHeaderNameSchema, CredentialHeaderValueSchema)
866
+ .refine((value) => Object.keys(value).length > 0, "At least one header is required")
867
+ .refine((value) => new Set(Object.keys(value).map((name) => name.toLowerCase())).size === Object.keys(value).length, "Header names are case-insensitive: each may appear once");
868
+ const LOOPBACK_HOSTS = /^(?:localhost|127(?:\.\d{1,3}){3}|\[::1\])$/i;
869
+ /**
870
+ * `via` (R2b C2, Q11): where this installation reaches the credential's server, such as a
871
+ * gateway's endpoint for it. An absolute `https` URL (`http` only to a loopback host), with no
872
+ * userinfo, query string or fragment. Credentials are still matched by the URL the manifest
873
+ * names; `via` changes only where the request goes.
874
+ */
875
+ export const CredentialViaSchema = z.string().superRefine((value, ctx) => {
876
+ let url;
877
+ try {
878
+ url = new URL(value);
879
+ }
880
+ catch {
881
+ ctx.addIssue({ code: "custom", message: "via must be an absolute URL" });
882
+ return;
883
+ }
884
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && LOOPBACK_HOSTS.test(url.hostname)))
885
+ ctx.addIssue({ code: "custom", message: "via must be https (http only to a loopback host)" });
886
+ if (url.username || url.password)
887
+ ctx.addIssue({ code: "custom", message: "via may not carry userinfo" });
888
+ if (url.search || value.includes("?"))
889
+ ctx.addIssue({ code: "custom", message: "via may not carry a query string" });
890
+ if (url.hash || value.includes("#"))
891
+ ctx.addIssue({ code: "custom", message: "via may not carry a fragment" });
892
+ });
893
+ /**
894
+ * The identity header (R2b C2, Q1–Q3): each request carries the session owner's subject in
895
+ * `header`, for a gateway that keeps each person's accounts. A session with no person as its
896
+ * owner (the reserved `installation`) sends none.
897
+ */
898
+ export const CredentialIdentitySchema = z.object({ header: CredentialHeaderNameSchema }).strict();
899
+ /** Where a credential's requests go, and whom they name. Neither is secret. */
900
+ const credentialRouting = {
901
+ via: CredentialViaSchema.optional(),
902
+ identity: CredentialIdentitySchema.optional(),
903
+ };
904
+ /** On rotate: absent keeps the current value, `null` removes it. */
905
+ const credentialRoutingChange = {
906
+ via: CredentialViaSchema.nullable().optional(),
907
+ identity: CredentialIdentitySchema.nullable().optional(),
908
+ };
909
+ /**
910
+ * A credential for the server at `url` (the URL a manifest names): `bearer` sends
911
+ * `Authorization: Bearer <token>`, `headers` its header map (R2b C2). The header names may not be
912
+ * the MCP transport's headers or `Nylorun-*`.
913
+ */
848
914
  export const CreateCredentialRequestSchema = z
849
915
  .object({
850
916
  ...vaultWriteBase,
@@ -855,20 +921,24 @@ export const CreateCredentialRequestSchema = z
855
921
  type: z.literal("bearer"),
856
922
  url: z.string().min(1),
857
923
  token: z.string().min(1),
924
+ ...credentialRouting,
858
925
  })
859
926
  .strict(),
860
927
  z
861
928
  .object({
862
- type: z.literal("oauth"),
929
+ type: z.literal("headers"),
863
930
  url: z.string().min(1),
864
- accessToken: z.string().min(1),
865
- expiresAt: z.string().min(1).nullable().optional(),
866
- refresh: oauthRefreshSchema.optional(),
931
+ headers: CredentialHeadersSchema,
932
+ ...credentialRouting,
867
933
  })
868
934
  .strict(),
869
935
  ]),
870
936
  })
871
937
  .strict();
938
+ /**
939
+ * Replaces a credential's secret; its type and URL stay. `via` and `identity` are kept unless
940
+ * given (`null` removes one).
941
+ */
872
942
  export const RotateCredentialRequestSchema = z
873
943
  .object({
874
944
  ...vaultWriteBase,
@@ -877,13 +947,14 @@ export const RotateCredentialRequestSchema = z
877
947
  .object({
878
948
  type: z.literal("bearer"),
879
949
  token: z.string().min(1),
950
+ ...credentialRoutingChange,
880
951
  })
881
952
  .strict(),
882
953
  z
883
954
  .object({
884
- type: z.literal("oauth"),
885
- accessToken: z.string().min(1),
886
- expiresAt: z.string().min(1).nullable().optional(),
955
+ type: z.literal("headers"),
956
+ headers: CredentialHeadersSchema,
957
+ ...credentialRoutingChange,
887
958
  })
888
959
  .strict(),
889
960
  ]),
@@ -950,13 +1021,101 @@ export const CredentialInfoSchema = z
950
1021
  id: z.string(),
951
1022
  vaultId: z.string(),
952
1023
  name: z.string(),
953
- type: z.enum(["bearer", "oauth"]),
1024
+ type: z.enum(["bearer", "headers"]),
954
1025
  binding: z.object({ url: z.string() }).strict(),
955
- expiresAt: z.string().optional(),
1026
+ /** A `headers` credential's header names (lower case), never their values. */
1027
+ headerNames: z.array(z.string()).optional(),
1028
+ via: z.string().optional(),
1029
+ identity: CredentialIdentitySchema.optional(),
956
1030
  createdAt: z.string(),
957
1031
  rotatedAt: z.string().optional(),
958
1032
  })
959
1033
  .strict();
1034
+ /** The MCP transports a preview speaks: a manifest's remote server types. */
1035
+ export const MCP_PREVIEW_TYPES = ["streamable-http", "sse"];
1036
+ /**
1037
+ * `POST /v1/tenant/mcp/preview` (R2b C12): what a remote MCP server offers, before an agent
1038
+ * names it. The Runtime connects with the installation vault's credential for `url` (one
1039
+ * credential across the installation vaults, or the one in `vaultId`), lists the tools and
1040
+ * closes the connection; it never calls a tool.
1041
+ */
1042
+ export const McpPreviewRequestSchema = z
1043
+ .object({
1044
+ requestId: RequestIdSchema.optional(),
1045
+ /** The server's URL, as a manifest would name it: an absolute `http` or `https` URL. */
1046
+ url: z.string().min(1).superRefine((value, ctx) => {
1047
+ let url;
1048
+ try {
1049
+ url = new URL(value);
1050
+ }
1051
+ catch {
1052
+ ctx.addIssue({ code: "custom", message: "url must be an absolute URL" });
1053
+ return;
1054
+ }
1055
+ if (url.protocol !== "https:" && url.protocol !== "http:")
1056
+ ctx.addIssue({ code: "custom", message: "url must be http or https" });
1057
+ if (url.username || url.password)
1058
+ ctx.addIssue({ code: "custom", message: "url may not carry userinfo" });
1059
+ }),
1060
+ /** The transport, as a manifest declares it. Default `streamable-http`. */
1061
+ type: z.enum(MCP_PREVIEW_TYPES).optional(),
1062
+ /**
1063
+ * The server name the agent will use: it prefixes the tools' model names. Default: the URL
1064
+ * host's name before its top-level domain (`linear` for `mcp.linear.app`).
1065
+ */
1066
+ name: modelFacingName("MCP server").optional(),
1067
+ /** The installation vault whose credential to send. Default: every installation vault. */
1068
+ vaultId: z.string().min(1).optional(),
1069
+ })
1070
+ .strict();
1071
+ /** One tool a preview found. */
1072
+ export const McpPreviewToolSchema = z
1073
+ .object({
1074
+ /** The server's own name for the tool. */
1075
+ serverToolName: z.string(),
1076
+ /**
1077
+ * What the model would call it (R2b C6); absent when the Runtime leaves the tool out (its
1078
+ * input schema is not one the Runtime can use).
1079
+ */
1080
+ modelName: z.string().optional(),
1081
+ description: z.string().optional(),
1082
+ /** The server's annotations of the tool (`readOnlyHint`, `destructiveHint`, `title`, …). */
1083
+ annotations: z.record(z.string(), z.unknown()).optional(),
1084
+ /** The size of the tool's input schema as JSON: what it costs the model's context. */
1085
+ schemaBytes: z.number().int().nonnegative(),
1086
+ })
1087
+ .strict();
1088
+ /**
1089
+ * A preview (R2b C12). A server that answered `401` is `authRequired`, with its RFC 9728
1090
+ * protected-resource metadata when it publishes any: it needs a person's sign-in or a key the
1091
+ * installation vaults do not hold, so reach it with a key or through a gateway (`via`).
1092
+ */
1093
+ export const McpPreviewSchema = z
1094
+ .object({
1095
+ /** The server name the model names were made with. */
1096
+ name: z.string(),
1097
+ url: z.string(),
1098
+ type: z.enum(MCP_PREVIEW_TYPES),
1099
+ /** True when an installation vault's credential was sent. */
1100
+ credentialSent: z.boolean(),
1101
+ /** The server's `initialize` answer: its name, version and title. */
1102
+ serverInfo: z.record(z.string(), z.unknown()).optional(),
1103
+ /** The server's instructions from `initialize`, cut to 2,000 characters. */
1104
+ instructions: z.string().optional(),
1105
+ tools: z.array(McpPreviewToolSchema),
1106
+ /** Tools the model knows by another name than `server__tool` (R2b C6). */
1107
+ renamed: z.array(z.object({ serverToolName: z.string(), name: z.string() }).strict()),
1108
+ authRequired: z
1109
+ .object({
1110
+ /** Where the server's protected-resource metadata was read from. */
1111
+ resourceMetadataUrl: z.string().optional(),
1112
+ /** The metadata (RFC 9728): `resource`, `authorization_servers`, `scopes_supported`, … */
1113
+ resourceMetadata: z.record(z.string(), z.unknown()).optional(),
1114
+ })
1115
+ .strict()
1116
+ .optional(),
1117
+ })
1118
+ .strict();
960
1119
  const commandBase = {
961
1120
  requestId: RequestIdSchema,
962
1121
  idempotencyKey: IdempotencyKeySchema,
@@ -1049,7 +1208,7 @@ export const EventSourceKindSchema = z.enum([
1049
1208
  "model-gate",
1050
1209
  "tool-gate",
1051
1210
  "egress-gate",
1052
- "sandboxd",
1211
+ "sandboxes",
1053
1212
  "edge",
1054
1213
  "init",
1055
1214
  "controller",
@@ -1206,7 +1365,27 @@ export const ToolCompletedPayloadSchema = z
1206
1365
  capabilityId: z.string().min(1),
1207
1366
  toolName: z.string().min(1),
1208
1367
  output: z.unknown().optional(),
1209
- error: z.object({ code: z.string(), message: z.string() }).passthrough().optional(),
1368
+ error: z
1369
+ .object({
1370
+ code: z.string(),
1371
+ message: z.string(),
1372
+ /**
1373
+ * With `credential_rejected` (R2b C1): the MCP server, or the HTTP tool's `credential`,
1374
+ * whose server answered `401`.
1375
+ */
1376
+ server: z.string().optional(),
1377
+ /** With `credential_rejected`: the scope of the vault whose credential was sent; absent when none was. */
1378
+ vault: z.enum(["installation", "user"]).optional(),
1379
+ /** An MCP tool error (R2b C7): true when calling again may work, as for `mcp.unreachable`. */
1380
+ retryable: z.boolean().optional(),
1381
+ })
1382
+ .passthrough()
1383
+ .optional(),
1384
+ /**
1385
+ * How many credential values the Runtime replaced with `[redacted]` in `output` or `error`
1386
+ * (R2b C8): the server echoed what it was sent. Absent when none.
1387
+ */
1388
+ redacted: z.number().int().positive().optional(),
1210
1389
  ...eventAgent,
1211
1390
  })
1212
1391
  .passthrough();
@@ -1463,8 +1642,28 @@ export const McpServerOutcomeSchema = z
1463
1642
  message: z.string(),
1464
1643
  /** The tools it added to the session; 0 unless connected. */
1465
1644
  tools: z.number().int().nonnegative(),
1645
+ /**
1646
+ * Of those, the tools out of the model's tool list, which it finds with `tool_search` and runs
1647
+ * with `tool_call` (R2b C10); absent when none is.
1648
+ */
1649
+ deferred: z.number().int().positive().optional(),
1650
+ /** Listed tools the server's `tools` settings disable (R2b C9); absent when none. */
1651
+ disabled: z.number().int().positive().optional(),
1652
+ /**
1653
+ * Keys of the server's `tools` settings that name no tool it listed (R2b C9): a diagnostic,
1654
+ * since servers change their lists.
1655
+ */
1656
+ unknownTools: z.array(z.string()).optional(),
1466
1657
  /** The credentials a refusal names. */
1467
1658
  credentialIds: z.array(z.string()).optional(),
1659
+ /**
1660
+ * Tools the model knows by another name (R2b C6): `server__tool` with characters outside
1661
+ * `[A-Za-z0-9_-]` replaced by `_`, and shortened to 64 with a hash, or suffixed with the hash
1662
+ * when that collides. The server is still called by `serverToolName`.
1663
+ */
1664
+ renamed: z
1665
+ .array(z.object({ serverToolName: z.string(), name: z.string() }).passthrough())
1666
+ .optional(),
1468
1667
  })
1469
1668
  .passthrough();
1470
1669
  /**
@@ -2101,6 +2300,13 @@ export const SessionViewSchema = z
2101
2300
  agentId: z.string(),
2102
2301
  ownerUserId: z.string(),
2103
2302
  manifestHash: z.string(),
2303
+ /**
2304
+ * The hash of the definition the session was opened from (R2b C11). `manifestHash` differs
2305
+ * from it when the Runtime pinned its own capabilities beside the definition: a sandbox's
2306
+ * tools and `save_artifact`, or `read_artifact`. Compare this one with the registered
2307
+ * definition's hash. Absent for a session opened before this release.
2308
+ */
2309
+ definitionHash: z.string().optional(),
2104
2310
  implementationVersion: z.string(),
2105
2311
  status: z.enum(SESSION_STATUSES),
2106
2312
  activeTurnId: z.string().nullable(),
@@ -2305,23 +2511,6 @@ export const ListVaultsResponseSchema = z.object({ vaults: z.array(VaultInfoSche
2305
2511
  export const ListCredentialsResponseSchema = z
2306
2512
  .object({ credentials: z.array(CredentialInfoSchema) })
2307
2513
  .strict();
2308
- /**
2309
- * `POST /v1/vaults/{vaultId}/oauth/start` (F9 C2): sign the installation in to the remote MCP
2310
- * server at `url`, declared as `server`, and store its OAuth credential in the installation vault.
2311
- * `clientId` names a client registered with the authorization server; without one the Runtime
2312
- * registers itself (RFC 7591) when the server allows it.
2313
- */
2314
- export const StartOAuthRequestSchema = z
2315
- .object({
2316
- url: z.string().min(1).max(2048),
2317
- server: z.string().min(1).max(128),
2318
- clientId: z.string().min(1).max(512).optional(),
2319
- })
2320
- .strict();
2321
- /** Where to send the browser, and until when the sign-in can finish. */
2322
- export const StartOAuthResponseSchema = z
2323
- .object({ authorizeUrl: z.string(), expiresAt: z.string() })
2324
- .strict();
2325
2514
  /** A deleted vault or credential. */
2326
2515
  export const DeletedResponseSchema = z.object({ id: z.string() }).strict();
2327
2516
  /**
package/dist/define.d.ts CHANGED
@@ -7,15 +7,16 @@ export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowD
7
7
  export type { Delegate } from "./definition/delegate.js";
8
8
  export { capability, middleware, model, tool } from "./definition/helpers.js";
9
9
  export { APPROVAL_MODES, HTTP_TOOL_DEFAULT_TIMEOUT_MS, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, http, httpToolOf, isHttpTarget, withHttpTarget, type HttpTarget, type HttpTool, type HttpToolOptions, } from "./definition/http-tool.js";
10
- export { ARTIFACTS_CAPABILITY_ID, SANDBOX_CAPABILITY_ID, SAVE_ARTIFACT_TOOL, artifactsCapabilityManifest, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
11
- export { mcp, McpError, normalizeMcpServers, stdioMcpRefusal } from "./definition/mcp.js";
10
+ export { ARTIFACTS_CAPABILITY_ID, READ_ARTIFACT_MAX_BYTES, READ_ARTIFACT_TOOL, SANDBOX_CAPABILITY_ID, SAVE_ARTIFACT_TOOL, artifactsCapabilityManifest, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
11
+ export { MCP_TOOL_DEFAULTS, manifestVersionFor, mcp, mcpToolSettings, McpError, normalizeMcpServers, stdioMcpRefusal, usesMcpToolSettings, } from "./definition/mcp.js";
12
+ export { SERVER_INSTRUCTIONS_MAX_CHARS, TOOL_CALL_TOOL, TOOL_SEARCH_DEFAULT_LIMIT, TOOL_SEARCH_MAX_LIMIT, TOOL_SEARCH_TOOL, TOOLS_CAPABILITY_ID, deferredToolsInstructions, deferredToolsTools, toolsCapabilityManifest, type DeferredServerNote, } from "./definition/tools-capability.js";
12
13
  export { codeToolRefusal, codeToolsOf } from "./definition/code-tools.js";
13
14
  export type { CodeTool } from "./definition/code-tools.js";
14
15
  export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
15
16
  export type { CapabilityIdentity, CapabilityOptions } from "./definition/capability.js";
16
17
  export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, flowHttpTarget, forEachFlowNode, indexSuffix, isLeafNode, isWorkflowManifest, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
17
18
  export type { FlowAgentBuilder, Flow, Named, FlowOut, LoopOptions, StageOptions, FlowNodeVisit, FlowVisitNode, FlowHttpTarget, FlowImplementations, } from "./definition/flow/index.js";
18
- export type { McpCapability, McpOptions, McpServerSpec } from "./definition/mcp.js";
19
+ export type { McpCapability, McpOptions, McpServerSpec, ResolvedMcpToolSettings, } from "./definition/mcp.js";
19
20
  export { ToolError, isToolError } from "./definition/tool-error.js";
20
21
  export { defineSchema } from "./definition/schema.js";
21
22
  export { hashManifest } from "./utils/hash.js";
@@ -26,13 +27,13 @@ export type { SandboxToolName } from "./utils/sandbox.js";
26
27
  export { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL, SKILL_TOOL_NAMES, isSkillTool, } from "./definition/skill-tools.js";
27
28
  export { DEFINITION_FILE_MAX_BYTES, SKILL_ENTRY, SKILL_FILES_MAX, SKILL_FILE_PATH_MAX, SKILLS_MOUNT, definitionFilesOf, isDefinitionFileHash, skillFilePathIssue, skillFilesIssue, skillInstructions, } from "./utils/definition-files.js";
28
29
  export type { Implementations } from "./definition/implementations.js";
29
- export type { AgentManifest, ApprovalMode, CapabilityManifest, HttpToolMethod, HttpToolTarget, McpServerManifest, RuntimeManifest, SandboxManifest, SandboxNetworkPreset, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
30
+ export type { AgentManifest, ApprovalMode, CapabilityManifest, HttpToolMethod, HttpToolTarget, McpServerManifest, McpToolSettings, RuntimeManifest, SandboxManifest, SandboxNetworkPreset, SkillManifest, ToolManifest, ManifestSchemaVersion, } from "./types/manifest.js";
30
31
  export type { CapabilityDeclaration, CapabilityInput, CapabilityItems, MiddlewareContributions, SkillFileSource, StepMiddleware, StepRequest, StepResponse, } from "./types/middleware.js";
31
32
  export type { ModelCandidate, ModelControls, ModelDirective, ModelEvidence, ModelFinishReason, ModelFailureCode, ModelFailureOutcome, ModelProducer, ModelAdapter, ModelAdapterContext, ModelPreparedCall, ContextContributor, ContextMutationOptions, ContextSnapshot, ModelCall, ModelCallTool, ModelOutputBlock, PromptContentPart, PromptItem, ModelConfigurationContributor, ModelConfigurationInstruction, ModelConfigurationMutationOptions, ModelConfigurationSnapshot, ModelConfigurationTool, ModelRequest, ModelToolCall, ModelUsage, } from "./types/model.js";
32
33
  export type { BuildDiagnostic, ContextItem, DeferredOutcome, JsonObject, JsonPrimitive, JsonValue, Tripwire, } from "./types/shared.js";
33
34
  export type { ObserveEvent, ObserveModelConfigurationSnapshot, ObserveModelRequested, ObserveSealedCall, ObserveToolSnapshot, Observer, } from "./types/observe.js";
34
35
  export type { InputEvent, MessageInput, InteractionReply, TranscriptEntry, UserContentPart, } from "./types/transcript.js";
35
- export type { Interaction, RequiredInteraction, ToolContent, ToolDefinition, ToolDescriptor, ToolExecutionContext, AgentRef, ToolExecutionResume, ToolInputSchema, ToolOutputSchema, ToolSchema, ToolSchemaSource, StandardToolSchema, StandardSchemaIssue, SchemaIssue, SchemaValidation, SchemaOutput, ToolOwner, ToolOutcome, ToolResult, ToolValidationFailureDetails, ToolEffects, ToolApproval, ToolRunResult, SessionStateBag, } from "./types/tool.js";
36
+ export type { Interaction, RequiredInteraction, ToolContent, ToolDefinition, ToolDescriptor, ToolExecutionContext, AgentRef, ToolExecutionResume, ToolInputSchema, ToolOutputSchema, ToolSchema, ToolSchemaSource, StandardToolSchema, StandardSchemaIssue, SchemaIssue, SchemaValidation, SchemaOutput, ToolOwner, ToolOutcome, ToolResult, ToolResultFile, ToolValidationFailureDetails, ToolEffects, ToolApproval, ToolRunResult, SessionStateBag, } from "./types/tool.js";
36
37
  export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
37
38
  export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
38
39
  export type { AgentBinding } from "./definition/binding.js";
package/dist/define.js CHANGED
@@ -3,8 +3,9 @@ export { HarnessError, isHarnessError } from "./errors.js";
3
3
  export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
4
4
  export { capability, middleware, model, tool } from "./definition/helpers.js";
5
5
  export { APPROVAL_MODES, HTTP_TOOL_DEFAULT_TIMEOUT_MS, HTTP_TOOL_MAX_TIMEOUT_MS, HTTP_TOOL_METHODS, http, httpToolOf, isHttpTarget, withHttpTarget, } from "./definition/http-tool.js";
6
- export { ARTIFACTS_CAPABILITY_ID, SANDBOX_CAPABILITY_ID, SAVE_ARTIFACT_TOOL, artifactsCapabilityManifest, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
7
- export { mcp, McpError, normalizeMcpServers, stdioMcpRefusal } from "./definition/mcp.js";
6
+ export { ARTIFACTS_CAPABILITY_ID, READ_ARTIFACT_MAX_BYTES, READ_ARTIFACT_TOOL, SANDBOX_CAPABILITY_ID, SAVE_ARTIFACT_TOOL, artifactsCapabilityManifest, sandboxCapabilityManifest, } from "./definition/sandbox-capability.js";
7
+ export { MCP_TOOL_DEFAULTS, manifestVersionFor, mcp, mcpToolSettings, McpError, normalizeMcpServers, stdioMcpRefusal, usesMcpToolSettings, } from "./definition/mcp.js";
8
+ export { SERVER_INSTRUCTIONS_MAX_CHARS, TOOL_CALL_TOOL, TOOL_SEARCH_DEFAULT_LIMIT, TOOL_SEARCH_MAX_LIMIT, TOOL_SEARCH_TOOL, TOOLS_CAPABILITY_ID, deferredToolsInstructions, deferredToolsTools, toolsCapabilityManifest, } from "./definition/tools-capability.js";
8
9
  export { codeToolRefusal, codeToolsOf } from "./definition/code-tools.js";
9
10
  export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
10
11
  export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, flowHttpTarget, forEachFlowNode, indexSuffix, isLeafNode, isWorkflowManifest, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
@@ -1,6 +1,6 @@
1
1
  import type { BoundMiddleware } from "./bound.js";
2
2
  import type { BuiltAgent } from "../types/agent.js";
3
- import type { AgentManifest, RuntimeManifest } from "../types/manifest.js";
3
+ import type { AgentManifest, ManifestSchemaVersion, RuntimeManifest } from "../types/manifest.js";
4
4
  import type { BuildDiagnostic, JsonObject } from "../types/shared.js";
5
5
  import type { ToolSchemaSource } from "../types/tool.js";
6
6
  import type { StepMiddleware } from "../types/middleware.js";
@@ -22,5 +22,7 @@ export declare function assembleAgent(middleware: readonly BoundMiddleware[], id
22
22
  metadata?: JsonObject;
23
23
  outputSchema?: ToolSchemaSource;
24
24
  runtime?: RuntimeManifest;
25
+ /** A manifest rebuilt from JSON keeps its version (`agentFrom`); a new one takes the least. */
26
+ manifestSchemaVersion?: ManifestSchemaVersion;
25
27
  }>, dynamics?: ReadonlyMap<string, CapabilityDynamics>): BuildResult<BuiltAgent>;
26
28
  export {};
@@ -85,6 +85,9 @@ export function assembleAgent(middleware, identity, dynamics = new Map()) {
85
85
  outputSchema: identity.outputSchema,
86
86
  runtime: identity.runtime,
87
87
  middleware: frozenMiddleware,
88
+ ...(identity.manifestSchemaVersion === undefined
89
+ ? {}
90
+ : { manifestSchemaVersion: identity.manifestSchemaVersion }),
88
91
  });
89
92
  const agent = bindAgent(frozenMiddleware, manifest, identity, dynamics);
90
93
  return Object.freeze({ ok: true, agent, manifest });
@@ -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?: {
@@ -4,7 +4,7 @@ import { schemaFromJSON } from "./schema-json.js";
4
4
  import { copyJsonObject, deepFreeze } from "../utils/immutable.js";
5
5
  import { REMOVED_CAPABILITY_FIELDS, manifestVersionIssue } from "./removed.js";
6
6
  import { delegateFromManifest, delegateOf } from "./delegate.js";
7
- import { stdioMcpRefusal } from "./mcp.js";
7
+ import { mcpToolSettingsVersionIssue, stdioMcpRefusal, usesMcpToolSettings } from "./mcp.js";
8
8
  import { SKILL_TOOL_NAMES } from "./skill-tools.js";
9
9
  import { skillFilesIssue } from "../utils/definition-files.js";
10
10
  import { httpToolFromManifest, httpToolOf } from "./http-tool.js";
@@ -20,8 +20,12 @@ export function agentFrom(json, implementations, options) {
20
20
  for (const capability of manifest.capabilities) {
21
21
  const impl = implementations[capability.id] ?? {};
22
22
  const tools = resolveTools(capability, impl.tools);
23
- const session = sessionTools
24
- .filter((item) => item.capabilityId === capability.id)
23
+ const owned = sessionTools.filter((item) => item.capabilityId === capability.id);
24
+ const instructions = [
25
+ ...(capability.instructions ?? []),
26
+ ...owned.flatMap((item) => item.instructions ?? []),
27
+ ];
28
+ const session = owned
25
29
  .map((item) => {
26
30
  const live = impl.tools?.[item.name];
27
31
  if (!live)
@@ -35,8 +39,8 @@ export function agentFrom(json, implementations, options) {
35
39
  request.configuration.tools.set(capability.id, advertised.map((tool) => (declarative(tool)
36
40
  ? tool
37
41
  : implementations[capability.id]?.tools?.[tool.name]) ?? tool));
38
- if (capability.instructions)
39
- request.configuration.instructions.set(capability.id, capability.instructions);
42
+ if (instructions.length > 0)
43
+ request.configuration.instructions.set(capability.id, instructions);
40
44
  return next();
41
45
  });
42
46
  entries.push(Object.freeze({
@@ -97,6 +101,7 @@ export function agentFrom(json, implementations, options) {
97
101
  metadata: manifest.metadata,
98
102
  outputSchema,
99
103
  runtime: manifest.runtime,
104
+ manifestSchemaVersion: manifest.manifestSchemaVersion,
100
105
  }, dynamics);
101
106
  if (!result.ok)
102
107
  throw new HarnessError("agent.build-failed", result.diagnostics.map((item) => item.message).join("; "));
@@ -175,15 +180,19 @@ function normalizeManifest(json) {
175
180
  : undefined;
176
181
  const runtime = normalizeRuntime(value.runtime);
177
182
  const capabilities = value.capabilities.map(normalizeCapability);
183
+ const version = value.manifestSchemaVersion;
178
184
  const servers = new Set();
179
185
  for (const capability of capabilities)
180
- for (const name of Object.keys(capability.mcpServers ?? {})) {
186
+ for (const [name, server] of Object.entries(capability.mcpServers ?? {})) {
181
187
  if (servers.has(name))
182
188
  throw new HarnessError("agent.build-failed", `Duplicate MCP server '${name}'`);
183
189
  servers.add(name);
190
+ if (version === 5 && usesMcpToolSettings(server))
191
+ throw new HarnessError("agent.build-failed", mcpToolSettingsVersionIssue(name));
184
192
  }
185
193
  return deepFreeze({
186
- manifestSchemaVersion: 5,
194
+ // The manifest's own version: a v6 manifest without v6 fields keeps its hash.
195
+ manifestSchemaVersion: version,
187
196
  id: value.id,
188
197
  ...(typeof value.name === "string" && value.name ? { name: value.name } : {}),
189
198
  ...(typeof value.description === "string"
@@ -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;