@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
package/dist/contracts.js CHANGED
@@ -1,9 +1,9 @@
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, manifestVersionIssue, workflowVersionIssue, } from "./definition/removed.js";
5
- import { DELEGATE_INPUT_SCHEMA } from "./definition/delegate.js";
6
- import { stdioMcpRefusal } from "./definition/mcp.js";
4
+ import { REMOVED_CAPABILITY_FIELDS, REMOVED_MANIFEST_FIELDS, manifestVersionIssue, workflowVersionIssue, } from "./definition/removed.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";
@@ -13,6 +13,11 @@ import { ERROR_CODES } from "./compatibility.js";
13
13
  export const RequestIdSchema = z.string().min(1);
14
14
  export const IdempotencyKeySchema = z.string().min(1).max(256);
15
15
  const jsonObject = z.record(z.string(), z.unknown());
16
+ /**
17
+ * A JSON object in a definition document (a schema, metadata). Documents arrive as JSON, so its
18
+ * values are JSON values: the manifest types say `JsonObject`, and the schema checks no value.
19
+ */
20
+ const definitionJson = jsonObject;
16
21
  // Recursive schemas carry an `id`: a document generated from them (the Runtime's OpenAPI)
17
22
  // refers back to the named schema instead of expanding it forever.
18
23
  const jsonValue = z
@@ -25,26 +30,51 @@ const jsonValue = z
25
30
  z.record(z.string(), jsonValue),
26
31
  ]))
27
32
  .meta({ id: "JsonValue" });
33
+ /**
34
+ * A name the model sees in a tool name (R2b C6): a declared tool's, or an MCP server's, which
35
+ * prefixes its tools' names. Letters, digits, `_` and `-`, up to 64: what every provider accepts.
36
+ */
37
+ const modelFacingName = (what) => z.string().regex(DELEGATE_NAME_PATTERN, {
38
+ error: (issue) => `${what} name '${String(issue.input)}' may use only letters, digits, _ and -, up to 64 characters, so that every model provider accepts it`,
39
+ });
40
+ /** One tool's settings on an MCP server (manifest v6, R2b C9). */
41
+ const mcpToolSettingsSchema = z
42
+ .object({
43
+ enabled: z.boolean().optional(),
44
+ approval: z.enum(APPROVAL_MODES).optional(),
45
+ deferred: z.boolean().optional(),
46
+ })
47
+ .strict()
48
+ .meta({ id: "McpToolSettings" });
49
+ /** Manifest v6 (R2b C9, C10): per-tool settings keyed by the server's tool names, `"*"` for the rest. */
50
+ const mcpServerSettings = {
51
+ deferred: z.boolean().optional(),
52
+ tools: z.record(z.string().min(1), mcpToolSettingsSchema).optional(),
53
+ };
28
54
  const mcpServerSchema = z.discriminatedUnion("type", [
29
55
  z
30
56
  .object({
31
- name: z.string().min(1),
57
+ name: modelFacingName("MCP server"),
32
58
  type: z.literal("streamable-http"),
33
59
  url: z.string().min(1),
34
60
  headers: z.record(z.string(), z.string()).optional(),
35
61
  approval: z.enum(APPROVAL_MODES).optional(),
62
+ ...mcpServerSettings,
36
63
  })
37
64
  .strict(),
38
65
  z
39
66
  .object({
40
- name: z.string().min(1),
67
+ name: modelFacingName("MCP server"),
41
68
  type: z.literal("sse"),
42
69
  url: z.string().min(1),
43
70
  headers: z.record(z.string(), z.string()).optional(),
44
71
  approval: z.enum(APPROVAL_MODES).optional(),
72
+ ...mcpServerSettings,
45
73
  })
46
74
  .strict(),
47
75
  ], { error: (issue) => stdioIssue(issue.input) });
76
+ /** A remote MCP server as a manifest declares it (`streamable-http` or `sse`). */
77
+ export const McpServerManifestSchema = mcpServerSchema;
48
78
  /** The refusal of a `stdio` server; other bad declarations keep zod's own message. */
49
79
  function stdioIssue(input) {
50
80
  if (!input || typeof input !== "object")
@@ -58,13 +88,14 @@ const skillManifestSchema = z
58
88
  .object({
59
89
  name: z.string().min(1),
60
90
  description: z.string().min(1),
61
- files: z.record(z.string(), z.string()).superRefine((files, ctx) => {
62
- const issue = skillFilesIssue(files);
63
- if (issue)
64
- ctx.addIssue({ code: "custom", message: `Skill ${issue}` });
65
- }),
91
+ files: z.record(z.string(), z.string()),
66
92
  })
67
- .strict();
93
+ .strict()
94
+ .superRefine((skill, ctx) => {
95
+ const issue = skillFilesIssue(skill.files);
96
+ if (issue)
97
+ ctx.addIssue({ code: "custom", path: ["files"], message: `Skill '${skill.name}' ${issue}` });
98
+ });
68
99
  const sandboxManifestSchema = z
69
100
  .object({
70
101
  image: z.string().min(1).optional(),
@@ -121,10 +152,10 @@ const reservedKind = (what) => z
121
152
  const reservedToolKind = reservedKind("tool");
122
153
  const toolManifestSchema = z
123
154
  .object({
124
- name: z.string().min(1),
155
+ name: modelFacingName("Tool"),
125
156
  description: z.string().optional(),
126
- inputSchema: jsonObject,
127
- outputSchema: jsonObject.optional(),
157
+ inputSchema: definitionJson,
158
+ outputSchema: definitionJson.optional(),
128
159
  agent: z
129
160
  .lazy(() => z.union([workflowManifestSchema, AgentManifestSchema]))
130
161
  .meta({ id: "ToolAgentManifest" })
@@ -148,39 +179,41 @@ const toolManifestSchema = z
148
179
  message: `Tool '${tool.name}' takes approval only as an HTTP tool`,
149
180
  });
150
181
  });
151
- /** A capability naming a field manifest v5 removed is refused with what replaces it. */
152
- const removedFieldError = (issue) => {
182
+ /** A manifest or capability naming a removed field is refused with what replaces it. */
183
+ const removedFieldError = (removedFields) => (issue) => {
153
184
  if (issue.code !== "unrecognized_keys")
154
185
  return undefined;
155
- const removed = issue.keys?.find((key) => REMOVED_CAPABILITY_FIELDS[key] !== undefined);
156
- return removed === undefined ? undefined : REMOVED_CAPABILITY_FIELDS[removed];
186
+ const removed = issue.keys?.find((key) => removedFields[key] !== undefined);
187
+ return removed === undefined ? undefined : removedFields[removed];
157
188
  };
158
- export const AgentManifestSchema = z
159
- .object({
160
- manifestSchemaVersion: z.literal(5, { error: (issue) => manifestVersionIssue(issue.input) }),
189
+ const agentManifestSchema = z
190
+ .strictObject({
191
+ // 6 adds an MCP server's `tools` and `deferred` (R2b C9); 5 is accepted unchanged.
192
+ manifestSchemaVersion: z.union([z.literal(5), z.literal(6)], {
193
+ error: (issue) => manifestVersionIssue(issue.input),
194
+ }),
161
195
  id: z.string().min(1),
162
196
  name: z.string().min(1).optional(),
163
197
  description: z.string().optional(),
164
- metadata: jsonObject.optional(),
165
- outputSchema: jsonObject.optional(),
198
+ metadata: definitionJson.optional(),
199
+ outputSchema: definitionJson.optional(),
166
200
  capabilities: z.array(z.strictObject({
167
201
  id: z.string().min(1),
168
202
  type: z.enum(["agent", "agent-plugin"]),
169
203
  name: z.string().min(1).optional(),
170
204
  description: z.string().optional(),
171
- metadata: jsonObject.optional(),
205
+ metadata: definitionJson.optional(),
172
206
  instructions: z.array(z.string()).optional(),
173
207
  skills: z.record(z.string(), skillManifestSchema).optional(),
174
208
  tools: z.array(toolManifestSchema).optional(),
175
209
  mcpServers: z.record(z.string(), mcpServerSchema).optional(),
176
210
  sandbox: sandboxManifestSchema.optional(),
177
- }, { error: removedFieldError })),
211
+ }, { error: removedFieldError(REMOVED_CAPABILITY_FIELDS) })),
178
212
  runtime: z.object({}).strict().optional(),
179
213
  // Reserved for Functions, which are deferred: developer code the Runtime will run from
180
214
  // uploaded definition files (a `functions/` folder). Any value is refused below.
181
215
  functions: z.unknown().optional().meta({ description: "Reserved: Functions are not available yet" }),
182
- })
183
- .strict()
216
+ }, { error: removedFieldError(REMOVED_MANIFEST_FIELDS) })
184
217
  .superRefine((manifest, ctx) => {
185
218
  if (manifest.functions !== undefined)
186
219
  ctx.addIssue({ code: "custom", path: ["functions"], message: "Functions are not available yet" });
@@ -252,9 +285,16 @@ export const AgentManifestSchema = z
252
285
  message: `Duplicate MCP server '${server.name}'`,
253
286
  });
254
287
  servers.add(server.name);
288
+ if (manifest.manifestSchemaVersion === 5 && usesMcpToolSettings(server))
289
+ ctx.addIssue({ code: "custom", message: mcpToolSettingsVersionIssue(server.name) });
255
290
  }
256
291
  }
257
292
  });
293
+ /**
294
+ * An agent's manifest (manifest v5 and v6). Its output is checked against `AgentManifest` here and
295
+ * below (`ManifestDrift`): the hand-written type keeps its read-only fields and its docs.
296
+ */
297
+ export const AgentManifestSchema = agentManifestSchema;
258
298
  /** Agents used as tools: one level deep, `{ task }` input, one shared sandbox spec. */
259
299
  function delegationIssues(manifest, issue) {
260
300
  const sandboxes = new Set();
@@ -328,8 +368,8 @@ const workflowLoopVerifySchema = z
328
368
  else if (verify.http !== undefined && verify.id !== undefined)
329
369
  ctx.addIssue({ code: "custom", path: ["id"], message: "An HTTP verifier takes no id" });
330
370
  })
331
- .meta({ id: "WorkflowLoopVerify" });
332
- const workflowNodeSchema = z.lazy(() => z.union([
371
+ .meta({ id: "WorkflowLoopVerify" }); // the refinement picks one kind
372
+ const workflowNodeKinds = z.lazy(() => z.union([
333
373
  workflowAgentNodeSchema,
334
374
  z
335
375
  .object({
@@ -337,8 +377,8 @@ const workflowNodeSchema = z.lazy(() => z.union([
337
377
  .object({
338
378
  name: z.string().min(1),
339
379
  description: z.string().optional(),
340
- inputSchema: jsonObject.optional(),
341
- outputSchema: jsonObject.optional(),
380
+ inputSchema: definitionJson.optional(),
381
+ outputSchema: definitionJson.optional(),
342
382
  /** An HTTP stage: the Runtime makes the request, as for an agent's HTTP tool. */
343
383
  http: httpToolTargetSchema.optional(),
344
384
  })
@@ -387,7 +427,8 @@ const workflowNodeSchema = z.lazy(() => z.union([
387
427
  })
388
428
  .strict(),
389
429
  ])).meta({ id: "WorkflowNode" });
390
- const workflowManifestSchema = z.lazy(() => z
430
+ const workflowNodeSchema = workflowNodeKinds;
431
+ const workflowManifestObject = z.lazy(() => z
391
432
  .object({
392
433
  kind: z.literal("workflow"),
393
434
  workflowSchemaVersion: z.literal(3, {
@@ -396,9 +437,9 @@ const workflowManifestSchema = z.lazy(() => z
396
437
  id: z.string().min(1),
397
438
  name: z.string().min(1).optional(),
398
439
  description: z.string().optional(),
399
- metadata: jsonObject.optional(),
400
- inputSchema: jsonObject.optional(),
401
- outputSchema: jsonObject.optional(),
440
+ metadata: definitionJson.optional(),
441
+ inputSchema: definitionJson.optional(),
442
+ outputSchema: definitionJson.optional(),
402
443
  sandbox: sandboxManifestSchema.optional(),
403
444
  root: workflowNodeSchema,
404
445
  agents: z.record(z.string().min(1), z.union([workflowManifestSchema, AgentManifestSchema])),
@@ -422,6 +463,7 @@ const workflowManifestSchema = z.lazy(() => z
422
463
  });
423
464
  }
424
465
  })).meta({ id: "WorkflowManifest" });
466
+ const workflowManifestSchema = workflowManifestObject;
425
467
  function referencedAgents(node) {
426
468
  const out = [];
427
469
  const visit = (child) => {
@@ -795,29 +837,6 @@ const vaultWriteBase = {
795
837
  requestId: RequestIdSchema,
796
838
  idempotencyKey: IdempotencyKeySchema,
797
839
  };
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
840
  /** The owner of every installation vault (`scope: "installation"`); a reserved subject. */
822
841
  export const INSTALLATION_OWNER = "installation";
823
842
  export const CreateVaultRequestSchema = z
@@ -845,6 +864,68 @@ export const CreateVaultRequestSchema = z
845
864
  else if (value.ownerUserId !== undefined && value.ownerUserId !== INSTALLATION_OWNER)
846
865
  ctx.addIssue({ code: "custom", path: ["ownerUserId"], message: "An installation vault is owned by installation" });
847
866
  });
867
+ /** An RFC 9110 field name. */
868
+ export const HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
869
+ const CredentialHeaderNameSchema = z
870
+ .string()
871
+ .regex(HEADER_NAME_PATTERN, "A header name is an RFC 9110 token");
872
+ /** A credential header's value: no CR, LF or NUL. */
873
+ const CredentialHeaderValueSchema = z
874
+ .string()
875
+ .min(1)
876
+ .refine((value) => !/[\r\n\0]/.test(value), "A header value has no CR, LF or NUL");
877
+ /** A `headers` credential's map (Q6): one or more headers sent on every request. */
878
+ const CredentialHeadersSchema = z
879
+ .record(CredentialHeaderNameSchema, CredentialHeaderValueSchema)
880
+ .refine((value) => Object.keys(value).length > 0, "At least one header is required")
881
+ .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");
882
+ /** A loopback host as a URL's `hostname` names it: plain `http` reaches only these. */
883
+ export const LOOPBACK_HOSTS = /^(?:localhost|127(?:\.\d{1,3}){3}|\[::1\])$/i;
884
+ /**
885
+ * `via` (R2b C2, Q11): where this installation reaches the credential's server, such as a
886
+ * gateway's endpoint for it. An absolute `https` URL (`http` only to a loopback host), with no
887
+ * userinfo, query string or fragment. Credentials are still matched by the URL the manifest
888
+ * names; `via` changes only where the request goes.
889
+ */
890
+ export const CredentialViaSchema = z.string().superRefine((value, ctx) => {
891
+ let url;
892
+ try {
893
+ url = new URL(value);
894
+ }
895
+ catch {
896
+ ctx.addIssue({ code: "custom", message: "via must be an absolute URL" });
897
+ return;
898
+ }
899
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && LOOPBACK_HOSTS.test(url.hostname)))
900
+ ctx.addIssue({ code: "custom", message: "via must be https (http only to a loopback host)" });
901
+ if (url.username || url.password)
902
+ ctx.addIssue({ code: "custom", message: "via may not carry userinfo" });
903
+ if (url.search || value.includes("?"))
904
+ ctx.addIssue({ code: "custom", message: "via may not carry a query string" });
905
+ if (url.hash || value.includes("#"))
906
+ ctx.addIssue({ code: "custom", message: "via may not carry a fragment" });
907
+ });
908
+ /**
909
+ * The identity header (R2b C2, Q1–Q3): each request carries the session owner's subject in
910
+ * `header`, for a gateway that keeps each person's accounts. A session with no person as its
911
+ * owner (the reserved `installation`) sends none.
912
+ */
913
+ export const CredentialIdentitySchema = z.object({ header: CredentialHeaderNameSchema }).strict();
914
+ /** Where a credential's requests go, and whom they name. Neither is secret. */
915
+ const credentialRouting = {
916
+ via: CredentialViaSchema.optional(),
917
+ identity: CredentialIdentitySchema.optional(),
918
+ };
919
+ /** On rotate: absent keeps the current value, `null` removes it. */
920
+ const credentialRoutingChange = {
921
+ via: CredentialViaSchema.nullable().optional(),
922
+ identity: CredentialIdentitySchema.nullable().optional(),
923
+ };
924
+ /**
925
+ * A credential for the server at `url` (the URL a manifest names): `bearer` sends
926
+ * `Authorization: Bearer <token>`, `headers` its header map (R2b C2). The header names may not be
927
+ * the MCP transport's headers or `Nylorun-*`.
928
+ */
848
929
  export const CreateCredentialRequestSchema = z
849
930
  .object({
850
931
  ...vaultWriteBase,
@@ -855,20 +936,24 @@ export const CreateCredentialRequestSchema = z
855
936
  type: z.literal("bearer"),
856
937
  url: z.string().min(1),
857
938
  token: z.string().min(1),
939
+ ...credentialRouting,
858
940
  })
859
941
  .strict(),
860
942
  z
861
943
  .object({
862
- type: z.literal("oauth"),
944
+ type: z.literal("headers"),
863
945
  url: z.string().min(1),
864
- accessToken: z.string().min(1),
865
- expiresAt: z.string().min(1).nullable().optional(),
866
- refresh: oauthRefreshSchema.optional(),
946
+ headers: CredentialHeadersSchema,
947
+ ...credentialRouting,
867
948
  })
868
949
  .strict(),
869
950
  ]),
870
951
  })
871
952
  .strict();
953
+ /**
954
+ * Replaces a credential's secret; its type and URL stay. `via` and `identity` are kept unless
955
+ * given (`null` removes one).
956
+ */
872
957
  export const RotateCredentialRequestSchema = z
873
958
  .object({
874
959
  ...vaultWriteBase,
@@ -877,13 +962,14 @@ export const RotateCredentialRequestSchema = z
877
962
  .object({
878
963
  type: z.literal("bearer"),
879
964
  token: z.string().min(1),
965
+ ...credentialRoutingChange,
880
966
  })
881
967
  .strict(),
882
968
  z
883
969
  .object({
884
- type: z.literal("oauth"),
885
- accessToken: z.string().min(1),
886
- expiresAt: z.string().min(1).nullable().optional(),
970
+ type: z.literal("headers"),
971
+ headers: CredentialHeadersSchema,
972
+ ...credentialRoutingChange,
887
973
  })
888
974
  .strict(),
889
975
  ]),
@@ -950,13 +1036,101 @@ export const CredentialInfoSchema = z
950
1036
  id: z.string(),
951
1037
  vaultId: z.string(),
952
1038
  name: z.string(),
953
- type: z.enum(["bearer", "oauth"]),
1039
+ type: z.enum(["bearer", "headers"]),
954
1040
  binding: z.object({ url: z.string() }).strict(),
955
- expiresAt: z.string().optional(),
1041
+ /** A `headers` credential's header names (lower case), never their values. */
1042
+ headerNames: z.array(z.string()).optional(),
1043
+ via: z.string().optional(),
1044
+ identity: CredentialIdentitySchema.optional(),
956
1045
  createdAt: z.string(),
957
1046
  rotatedAt: z.string().optional(),
958
1047
  })
959
1048
  .strict();
1049
+ /** The MCP transports a preview speaks: a manifest's remote server types. */
1050
+ export const MCP_PREVIEW_TYPES = ["streamable-http", "sse"];
1051
+ /**
1052
+ * `POST /v1/tenant/mcp/preview` (R2b C12): what a remote MCP server offers, before an agent
1053
+ * names it. The Runtime connects with the installation vault's credential for `url` (one
1054
+ * credential across the installation vaults, or the one in `vaultId`), lists the tools and
1055
+ * closes the connection; it never calls a tool.
1056
+ */
1057
+ export const McpPreviewRequestSchema = z
1058
+ .object({
1059
+ requestId: RequestIdSchema.optional(),
1060
+ /** The server's URL, as a manifest would name it: an absolute `http` or `https` URL. */
1061
+ url: z.string().min(1).superRefine((value, ctx) => {
1062
+ let url;
1063
+ try {
1064
+ url = new URL(value);
1065
+ }
1066
+ catch {
1067
+ ctx.addIssue({ code: "custom", message: "url must be an absolute URL" });
1068
+ return;
1069
+ }
1070
+ if (url.protocol !== "https:" && url.protocol !== "http:")
1071
+ ctx.addIssue({ code: "custom", message: "url must be http or https" });
1072
+ if (url.username || url.password)
1073
+ ctx.addIssue({ code: "custom", message: "url may not carry userinfo" });
1074
+ }),
1075
+ /** The transport, as a manifest declares it. Default `streamable-http`. */
1076
+ type: z.enum(MCP_PREVIEW_TYPES).optional(),
1077
+ /**
1078
+ * The server name the agent will use: it prefixes the tools' model names. Default: the URL
1079
+ * host's name before its top-level domain (`linear` for `mcp.linear.app`).
1080
+ */
1081
+ name: modelFacingName("MCP server").optional(),
1082
+ /** The installation vault whose credential to send. Default: every installation vault. */
1083
+ vaultId: z.string().min(1).optional(),
1084
+ })
1085
+ .strict();
1086
+ /** One tool a preview found. */
1087
+ export const McpPreviewToolSchema = z
1088
+ .object({
1089
+ /** The server's own name for the tool. */
1090
+ serverToolName: z.string(),
1091
+ /**
1092
+ * What the model would call it (R2b C6); absent when the Runtime leaves the tool out (its
1093
+ * input schema is not one the Runtime can use).
1094
+ */
1095
+ modelName: z.string().optional(),
1096
+ description: z.string().optional(),
1097
+ /** The server's annotations of the tool (`readOnlyHint`, `destructiveHint`, `title`, …). */
1098
+ annotations: z.record(z.string(), z.unknown()).optional(),
1099
+ /** The size of the tool's input schema as JSON: what it costs the model's context. */
1100
+ schemaBytes: z.number().int().nonnegative(),
1101
+ })
1102
+ .strict();
1103
+ /**
1104
+ * A preview (R2b C12). A server that answered `401` is `authRequired`, with its RFC 9728
1105
+ * protected-resource metadata when it publishes any: it needs a person's sign-in or a key the
1106
+ * installation vaults do not hold, so reach it with a key or through a gateway (`via`).
1107
+ */
1108
+ export const McpPreviewSchema = z
1109
+ .object({
1110
+ /** The server name the model names were made with. */
1111
+ name: z.string(),
1112
+ url: z.string(),
1113
+ type: z.enum(MCP_PREVIEW_TYPES),
1114
+ /** True when an installation vault's credential was sent. */
1115
+ credentialSent: z.boolean(),
1116
+ /** The server's `initialize` answer: its name, version and title. */
1117
+ serverInfo: z.record(z.string(), z.unknown()).optional(),
1118
+ /** The server's instructions from `initialize`, cut to 2,000 characters. */
1119
+ instructions: z.string().optional(),
1120
+ tools: z.array(McpPreviewToolSchema),
1121
+ /** Tools the model knows by another name than `server__tool` (R2b C6). */
1122
+ renamed: z.array(z.object({ serverToolName: z.string(), name: z.string() }).strict()),
1123
+ authRequired: z
1124
+ .object({
1125
+ /** Where the server's protected-resource metadata was read from. */
1126
+ resourceMetadataUrl: z.string().optional(),
1127
+ /** The metadata (RFC 9728): `resource`, `authorization_servers`, `scopes_supported`, … */
1128
+ resourceMetadata: z.record(z.string(), z.unknown()).optional(),
1129
+ })
1130
+ .strict()
1131
+ .optional(),
1132
+ })
1133
+ .strict();
960
1134
  const commandBase = {
961
1135
  requestId: RequestIdSchema,
962
1136
  idempotencyKey: IdempotencyKeySchema,
@@ -1206,7 +1380,27 @@ export const ToolCompletedPayloadSchema = z
1206
1380
  capabilityId: z.string().min(1),
1207
1381
  toolName: z.string().min(1),
1208
1382
  output: z.unknown().optional(),
1209
- error: z.object({ code: z.string(), message: z.string() }).passthrough().optional(),
1383
+ error: z
1384
+ .object({
1385
+ code: z.string(),
1386
+ message: z.string(),
1387
+ /**
1388
+ * With `credential_rejected` (R2b C1): the MCP server, or the HTTP tool's `credential`,
1389
+ * whose server answered `401`.
1390
+ */
1391
+ server: z.string().optional(),
1392
+ /** With `credential_rejected`: the scope of the vault whose credential was sent; absent when none was. */
1393
+ vault: z.enum(["installation", "user"]).optional(),
1394
+ /** An MCP tool error (R2b C7): true when calling again may work, as for `mcp.unreachable`. */
1395
+ retryable: z.boolean().optional(),
1396
+ })
1397
+ .passthrough()
1398
+ .optional(),
1399
+ /**
1400
+ * How many credential values the Runtime replaced with `[redacted]` in `output` or `error`
1401
+ * (R2b C8): the server echoed what it was sent. Absent when none.
1402
+ */
1403
+ redacted: z.number().int().positive().optional(),
1210
1404
  ...eventAgent,
1211
1405
  })
1212
1406
  .passthrough();
@@ -1463,8 +1657,28 @@ export const McpServerOutcomeSchema = z
1463
1657
  message: z.string(),
1464
1658
  /** The tools it added to the session; 0 unless connected. */
1465
1659
  tools: z.number().int().nonnegative(),
1660
+ /**
1661
+ * Of those, the tools out of the model's tool list, which it finds with `tool_search` and runs
1662
+ * with `tool_call` (R2b C10); absent when none is.
1663
+ */
1664
+ deferred: z.number().int().positive().optional(),
1665
+ /** Listed tools the server's `tools` settings disable (R2b C9); absent when none. */
1666
+ disabled: z.number().int().positive().optional(),
1667
+ /**
1668
+ * Keys of the server's `tools` settings that name no tool it listed (R2b C9): a diagnostic,
1669
+ * since servers change their lists.
1670
+ */
1671
+ unknownTools: z.array(z.string()).optional(),
1466
1672
  /** The credentials a refusal names. */
1467
1673
  credentialIds: z.array(z.string()).optional(),
1674
+ /**
1675
+ * Tools the model knows by another name (R2b C6): `server__tool` with characters outside
1676
+ * `[A-Za-z0-9_-]` replaced by `_`, and shortened to 64 with a hash, or suffixed with the hash
1677
+ * when that collides. The server is still called by `serverToolName`.
1678
+ */
1679
+ renamed: z
1680
+ .array(z.object({ serverToolName: z.string(), name: z.string() }).passthrough())
1681
+ .optional(),
1468
1682
  })
1469
1683
  .passthrough();
1470
1684
  /**
@@ -2101,6 +2315,13 @@ export const SessionViewSchema = z
2101
2315
  agentId: z.string(),
2102
2316
  ownerUserId: z.string(),
2103
2317
  manifestHash: z.string(),
2318
+ /**
2319
+ * The hash of the definition the session was opened from (R2b C11). `manifestHash` differs
2320
+ * from it when the Runtime pinned its own capabilities beside the definition: a sandbox's
2321
+ * tools and `save_artifact`, or `read_artifact`. Compare this one with the registered
2322
+ * definition's hash. Absent for a session opened before this release.
2323
+ */
2324
+ definitionHash: z.string().optional(),
2104
2325
  implementationVersion: z.string(),
2105
2326
  status: z.enum(SESSION_STATUSES),
2106
2327
  activeTurnId: z.string().nullable(),
@@ -2305,23 +2526,6 @@ export const ListVaultsResponseSchema = z.object({ vaults: z.array(VaultInfoSche
2305
2526
  export const ListCredentialsResponseSchema = z
2306
2527
  .object({ credentials: z.array(CredentialInfoSchema) })
2307
2528
  .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
2529
  /** A deleted vault or credential. */
2326
2530
  export const DeletedResponseSchema = z.object({ id: z.string() }).strict();
2327
2531
  /**
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 });