@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/CHANGELOG.md +69 -0
- package/dist/compatibility.d.ts +40 -14
- package/dist/compatibility.js +38 -12
- package/dist/contracts.d.ts +171 -51
- package/dist/contracts.js +246 -57
- package/dist/define.d.ts +6 -5
- package/dist/define.js +3 -2
- package/dist/definition/assemble.d.ts +3 -1
- package/dist/definition/assemble.js +3 -0
- package/dist/definition/code-tools.d.ts +4 -4
- package/dist/definition/code-tools.js +3 -2
- package/dist/definition/from.d.ts +5 -0
- package/dist/definition/from.js +16 -7
- package/dist/definition/manifest.d.ts +3 -1
- package/dist/definition/manifest.js +4 -1
- package/dist/definition/mcp.d.ts +45 -1
- package/dist/definition/mcp.js +85 -2
- package/dist/definition/removed.d.ts +4 -1
- package/dist/definition/removed.js +5 -2
- package/dist/definition/sandbox-capability.d.ts +21 -4
- package/dist/definition/sandbox-capability.js +56 -19
- package/dist/definition/tools-capability.d.ts +37 -0
- package/dist/definition/tools-capability.js +98 -0
- package/dist/definition/variant.d.ts +2 -1
- package/dist/definition/variant.js +40 -4
- package/dist/harness-api/transcript.d.ts +5 -1
- package/dist/harness-api/transcript.js +6 -2
- package/dist/types/manifest.d.ts +42 -14
- package/dist/types/tool.d.ts +22 -0
- package/package.json +1 -1
|
@@ -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:
|
|
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
|
package/dist/definition/mcp.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/definition/mcp.js
CHANGED
|
@@ -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 ||
|
|
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
|
}
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
* during a session (see MIGRATION.md).
|
|
5
5
|
*/
|
|
6
6
|
export declare const REMOVED_CAPABILITY_FIELDS: Readonly<Record<string, string>>;
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5 and
|
|
9
|
+
* version 6 (R2b C9: an MCP server's `tools` and `deferred`; v5 is accepted unchanged).
|
|
10
|
+
*/
|
|
8
11
|
export declare function manifestVersionIssue(version: unknown): string | undefined;
|
|
9
12
|
/** Why a workflow manifest with this `workflowSchemaVersion` is refused, or undefined for version 3. */
|
|
10
13
|
export declare function workflowVersionIssue(version: unknown): string | undefined;
|
|
@@ -8,9 +8,12 @@ export const REMOVED_CAPABILITY_FIELDS = Object.freeze({
|
|
|
8
8
|
beforeModelCall: "beforeModelCall was removed with hooks (see MIGRATION.md)",
|
|
9
9
|
afterModelCall: "afterModelCall was removed with hooks (see MIGRATION.md)",
|
|
10
10
|
});
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5 and
|
|
13
|
+
* version 6 (R2b C9: an MCP server's `tools` and `deferred`; v5 is accepted unchanged).
|
|
14
|
+
*/
|
|
12
15
|
export function manifestVersionIssue(version) {
|
|
13
|
-
if (version === 5)
|
|
16
|
+
if (version === 5 || version === 6)
|
|
14
17
|
return undefined;
|
|
15
18
|
if (version === 4 || version === 3)
|
|
16
19
|
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
|
|
13
|
-
*
|
|
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
|
|
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
|
|
@@ -15,19 +15,69 @@ export const SANDBOX_CAPABILITY_ID = "nylorun.sandbox";
|
|
|
15
15
|
*/
|
|
16
16
|
export const ARTIFACTS_CAPABILITY_ID = "nylorun.artifacts";
|
|
17
17
|
export const SAVE_ARTIFACT_TOOL = "save_artifact";
|
|
18
|
+
/**
|
|
19
|
+
* The tool that reads an artifact of the session in pages (R2b C11, Q24): how the model reads a
|
|
20
|
+
* tool result the Runtime stored because it was too large to show. With or without a sandbox.
|
|
21
|
+
*/
|
|
22
|
+
export const READ_ARTIFACT_TOOL = "read_artifact";
|
|
23
|
+
/** The most `read_artifact` returns per call (R2b C11): 32 KiB, the inline cap of a tool result. */
|
|
24
|
+
export const READ_ARTIFACT_MAX_BYTES = 32 * 1024;
|
|
18
25
|
const ARTIFACTS_INSTRUCTIONS = "Use save_artifact to hand the user a file you made: a path in the sandbox, or text you pass as content. " +
|
|
19
26
|
"The user sees it as an artifact of this session and can download it; reply with its name, not its bytes. " +
|
|
20
27
|
"Files you write under /workspace/outputs reach the user too: when your turn ends, they become the session's outputs folder.";
|
|
28
|
+
const READ_ARTIFACT_INSTRUCTIONS = "A tool result too large to show is saved as an artifact of this session: the result says truncated: true, with its artifactId, its size in bytes and a preview of its start and end. " +
|
|
29
|
+
"Images and other files a tool returns are saved as artifacts too. Use read_artifact to read more of one, a page at a time, only when the preview is not enough.";
|
|
21
30
|
async function artifactsRuntimeOnly() {
|
|
22
|
-
throw new ToolError("artifacts.runtime-only", "
|
|
31
|
+
throw new ToolError("artifacts.runtime-only", "The artifact tools run in the Nylorun Runtime. Connect the agent to a Runtime to use them.");
|
|
23
32
|
}
|
|
24
33
|
/**
|
|
25
|
-
* The capability manifest that gives a session `save_artifact
|
|
26
|
-
*
|
|
27
|
-
* manifest; change
|
|
34
|
+
* The capability manifest that gives a session `save_artifact`, which stores a sandbox file, or
|
|
35
|
+
* inline text, as a file artifact of the session, and `read_artifact`, which reads one in pages.
|
|
36
|
+
* Its schemas are part of the hashed manifest; change them deliberately.
|
|
28
37
|
*/
|
|
29
|
-
export function artifactsCapabilityManifest() {
|
|
30
|
-
const
|
|
38
|
+
export function artifactsCapabilityManifest(options = {}) {
|
|
39
|
+
const save = options.save ?? true;
|
|
40
|
+
const read = options.read ?? false;
|
|
41
|
+
const tools = [...(save ? [saveArtifactTool()] : []), ...(read ? [readArtifactTool()] : [])];
|
|
42
|
+
return {
|
|
43
|
+
id: ARTIFACTS_CAPABILITY_ID,
|
|
44
|
+
type: "agent",
|
|
45
|
+
instructions: [
|
|
46
|
+
...(save ? [ARTIFACTS_INSTRUCTIONS] : []),
|
|
47
|
+
...(read ? [READ_ARTIFACT_INSTRUCTIONS] : []),
|
|
48
|
+
],
|
|
49
|
+
tools: tools.map((item) => {
|
|
50
|
+
const schemas = normalizedSchemasFor(item);
|
|
51
|
+
return {
|
|
52
|
+
name: item.name,
|
|
53
|
+
...(item.description === undefined ? {} : { description: item.description }),
|
|
54
|
+
inputSchema: schemas.inputSchema.jsonSchema,
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function readArtifactTool() {
|
|
60
|
+
return tool({
|
|
61
|
+
name: READ_ARTIFACT_TOOL,
|
|
62
|
+
description: `Read a text artifact of this session, such as a tool result marked truncated: up to ${READ_ARTIFACT_MAX_BYTES} bytes from offset. ` +
|
|
63
|
+
"Returns content, and nextOffset while more remains: pass it as offset to read on. An image is shown to you when you can see images.",
|
|
64
|
+
inputSchema: z.object({
|
|
65
|
+
artifactId: z.string().min(1).describe("The artifact to read, e.g. a truncated result's artifactId."),
|
|
66
|
+
offset: z.number().int().min(0).optional().describe("The byte to start at. Default 0."),
|
|
67
|
+
length: z
|
|
68
|
+
.number()
|
|
69
|
+
.int()
|
|
70
|
+
.min(1)
|
|
71
|
+
.max(READ_ARTIFACT_MAX_BYTES)
|
|
72
|
+
.optional()
|
|
73
|
+
.describe(`How many bytes to read. Default and most: ${READ_ARTIFACT_MAX_BYTES}.`),
|
|
74
|
+
}),
|
|
75
|
+
effects: "read",
|
|
76
|
+
execute: artifactsRuntimeOnly,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function saveArtifactTool() {
|
|
80
|
+
return tool({
|
|
31
81
|
name: SAVE_ARTIFACT_TOOL,
|
|
32
82
|
description: `Save a file as an artifact of this session, for the user to download. Give path (a file in the sandbox; relative paths resolve under ${SANDBOX_WORKSPACE}) or content (text), not both. ` +
|
|
33
83
|
"Returns the artifact's id and version. Pass artifactId to save a new version of an artifact you saved before.",
|
|
@@ -50,19 +100,6 @@ export function artifactsCapabilityManifest() {
|
|
|
50
100
|
effects: "write",
|
|
51
101
|
execute: artifactsRuntimeOnly,
|
|
52
102
|
});
|
|
53
|
-
const schemas = normalizedSchemasFor(saveArtifact);
|
|
54
|
-
return {
|
|
55
|
-
id: ARTIFACTS_CAPABILITY_ID,
|
|
56
|
-
type: "agent",
|
|
57
|
-
instructions: [ARTIFACTS_INSTRUCTIONS],
|
|
58
|
-
tools: [
|
|
59
|
-
{
|
|
60
|
-
name: saveArtifact.name,
|
|
61
|
-
...(saveArtifact.description === undefined ? {} : { description: saveArtifact.description }),
|
|
62
|
-
inputSchema: schemas.inputSchema.jsonSchema,
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
};
|
|
66
103
|
}
|
|
67
104
|
/**
|
|
68
105
|
* The capability manifest that gives a session its sandbox: the six built-in tools, the sandbox
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CapabilityManifest, ToolManifest } from "../types/manifest.js";
|
|
2
|
+
/**
|
|
3
|
+
* Id of the capability that holds `tool_search` and `tool_call` (R2b C10): the Runtime adds it at
|
|
4
|
+
* session open to each agent with a remote MCP server, empty. When some of the agent's MCP tools
|
|
5
|
+
* are deferred, the session's tools put `tool_search` and `tool_call` in it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const TOOLS_CAPABILITY_ID = "nylorun.tools";
|
|
8
|
+
/** Finds deferred tools by a query (BM25 over their names and descriptions). */
|
|
9
|
+
export declare const TOOL_SEARCH_TOOL = "tool_search";
|
|
10
|
+
/** Runs a deferred tool by name, as a call of that tool. */
|
|
11
|
+
export declare const TOOL_CALL_TOOL = "tool_call";
|
|
12
|
+
/** How many tools `tool_search` returns when the model sets no `limit`. */
|
|
13
|
+
export declare const TOOL_SEARCH_DEFAULT_LIMIT = 8;
|
|
14
|
+
/** The most tools one `tool_search` returns. */
|
|
15
|
+
export declare const TOOL_SEARCH_MAX_LIMIT = 20;
|
|
16
|
+
/** How much of a server's own instructions the model sees in the deferred tools' note. */
|
|
17
|
+
export declare const SERVER_INSTRUCTIONS_MAX_CHARS = 2000;
|
|
18
|
+
/** A server some of whose tools are deferred, as the model's note names it. */
|
|
19
|
+
export interface DeferredServerNote {
|
|
20
|
+
readonly serverName: string;
|
|
21
|
+
/** How many of its tools are deferred. */
|
|
22
|
+
readonly tools: number;
|
|
23
|
+
/** The server's own instructions (MCP `initialize`), if it gave any. */
|
|
24
|
+
readonly instructions?: string;
|
|
25
|
+
}
|
|
26
|
+
/** The capability the Runtime adds to an agent with a remote MCP server: empty, until tools are deferred. */
|
|
27
|
+
export declare function toolsCapabilityManifest(): CapabilityManifest;
|
|
28
|
+
/**
|
|
29
|
+
* `tool_search` and `tool_call`, as the session gives them to an agent with deferred tools. Their
|
|
30
|
+
* schemas reach the model; change them deliberately.
|
|
31
|
+
*/
|
|
32
|
+
export declare function deferredToolsTools(): readonly ToolManifest[];
|
|
33
|
+
/**
|
|
34
|
+
* The note the model reads beside `tool_search`: each server with deferred tools, how many, and
|
|
35
|
+
* its own instructions cut to `SERVER_INSTRUCTIONS_MAX_CHARS`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function deferredToolsInstructions(servers: readonly DeferredServerNote[]): string;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "./helpers.js";
|
|
3
|
+
import { ToolError } from "./tool-error.js";
|
|
4
|
+
import { normalizedSchemasFor } from "./schema.js";
|
|
5
|
+
/**
|
|
6
|
+
* Id of the capability that holds `tool_search` and `tool_call` (R2b C10): the Runtime adds it at
|
|
7
|
+
* session open to each agent with a remote MCP server, empty. When some of the agent's MCP tools
|
|
8
|
+
* are deferred, the session's tools put `tool_search` and `tool_call` in it.
|
|
9
|
+
*/
|
|
10
|
+
export const TOOLS_CAPABILITY_ID = "nylorun.tools";
|
|
11
|
+
/** Finds deferred tools by a query (BM25 over their names and descriptions). */
|
|
12
|
+
export const TOOL_SEARCH_TOOL = "tool_search";
|
|
13
|
+
/** Runs a deferred tool by name, as a call of that tool. */
|
|
14
|
+
export const TOOL_CALL_TOOL = "tool_call";
|
|
15
|
+
/** How many tools `tool_search` returns when the model sets no `limit`. */
|
|
16
|
+
export const TOOL_SEARCH_DEFAULT_LIMIT = 8;
|
|
17
|
+
/** The most tools one `tool_search` returns. */
|
|
18
|
+
export const TOOL_SEARCH_MAX_LIMIT = 20;
|
|
19
|
+
/** How much of a server's own instructions the model sees in the deferred tools' note. */
|
|
20
|
+
export const SERVER_INSTRUCTIONS_MAX_CHARS = 2_000;
|
|
21
|
+
async function toolsRuntimeOnly() {
|
|
22
|
+
throw new ToolError("tools.runtime-only", "tool_search and tool_call run in the Nylorun Runtime. Connect the agent to a Runtime to use them.");
|
|
23
|
+
}
|
|
24
|
+
/** The capability the Runtime adds to an agent with a remote MCP server: empty, until tools are deferred. */
|
|
25
|
+
export function toolsCapabilityManifest() {
|
|
26
|
+
return {
|
|
27
|
+
id: TOOLS_CAPABILITY_ID,
|
|
28
|
+
type: "agent",
|
|
29
|
+
description: "Deferred MCP tools: tool_search finds them and tool_call runs them.",
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `tool_search` and `tool_call`, as the session gives them to an agent with deferred tools. Their
|
|
34
|
+
* schemas reach the model; change them deliberately.
|
|
35
|
+
*/
|
|
36
|
+
export function deferredToolsTools() {
|
|
37
|
+
return [searchTool(), callTool()].map((item) => {
|
|
38
|
+
const schemas = normalizedSchemasFor(item);
|
|
39
|
+
return {
|
|
40
|
+
name: item.name,
|
|
41
|
+
...(item.description === undefined ? {} : { description: item.description }),
|
|
42
|
+
inputSchema: schemas.inputSchema.jsonSchema,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The note the model reads beside `tool_search`: each server with deferred tools, how many, and
|
|
48
|
+
* its own instructions cut to `SERVER_INSTRUCTIONS_MAX_CHARS`.
|
|
49
|
+
*/
|
|
50
|
+
export function deferredToolsInstructions(servers) {
|
|
51
|
+
const lines = servers.map((server) => {
|
|
52
|
+
const head = `- ${server.serverName}: ${server.tools} tool${server.tools === 1 ? "" : "s"}`;
|
|
53
|
+
const text = server.instructions?.trim();
|
|
54
|
+
if (!text)
|
|
55
|
+
return head;
|
|
56
|
+
const cut = text.length > SERVER_INSTRUCTIONS_MAX_CHARS
|
|
57
|
+
? `${text.slice(0, SERVER_INSTRUCTIONS_MAX_CHARS)}…`
|
|
58
|
+
: text;
|
|
59
|
+
return `${head}. The server says: ${cut}`;
|
|
60
|
+
});
|
|
61
|
+
return [
|
|
62
|
+
"Some tools of these MCP servers are not in your tool list. Find them with tool_search (a few words of what you need), then run one with tool_call, passing its name and arguments that match its inputSchema.",
|
|
63
|
+
...lines,
|
|
64
|
+
].join("\n");
|
|
65
|
+
}
|
|
66
|
+
function searchTool() {
|
|
67
|
+
return tool({
|
|
68
|
+
name: TOOL_SEARCH_TOOL,
|
|
69
|
+
description: "Search the tools not in your tool list by name and description. Returns the best matches, each with its name, description and inputSchema. Run one with tool_call.",
|
|
70
|
+
inputSchema: z.object({
|
|
71
|
+
query: z.string().min(1).describe("Words of what the tool does, or of its name."),
|
|
72
|
+
limit: z
|
|
73
|
+
.number()
|
|
74
|
+
.int()
|
|
75
|
+
.min(1)
|
|
76
|
+
.max(TOOL_SEARCH_MAX_LIMIT)
|
|
77
|
+
.optional()
|
|
78
|
+
.describe(`How many tools to return. Default ${TOOL_SEARCH_DEFAULT_LIMIT}.`),
|
|
79
|
+
}),
|
|
80
|
+
effects: "read",
|
|
81
|
+
execute: toolsRuntimeOnly,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function callTool() {
|
|
85
|
+
return tool({
|
|
86
|
+
name: TOOL_CALL_TOOL,
|
|
87
|
+
description: "Run a tool tool_search found, by its name. arguments must match that tool's inputSchema; the result is the tool's own.",
|
|
88
|
+
inputSchema: z.object({
|
|
89
|
+
name: z.string().min(1).describe("The tool's name, as tool_search returned it."),
|
|
90
|
+
arguments: z
|
|
91
|
+
.record(z.string(), z.unknown())
|
|
92
|
+
.optional()
|
|
93
|
+
.describe("The tool's arguments, matching its inputSchema. Default {}."),
|
|
94
|
+
}),
|
|
95
|
+
effects: "write",
|
|
96
|
+
execute: toolsRuntimeOnly,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { AgentManifest } from "../types/manifest.js";
|
|
2
2
|
/**
|
|
3
3
|
* Whether `candidate` is a valid turn-manifest variant of the session's pinned
|
|
4
|
-
* manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed
|
|
4
|
+
* manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed, but a variant may disable an MCP
|
|
5
|
+
* server's tools or require their approval (R2b C9, Q18);
|
|
5
6
|
* code-backed tools/skills/agents-as-tools are remove-only; plain data may change.
|
|
6
7
|
*/
|
|
7
8
|
export declare function isVariantOf(candidate: AgentManifest, pinned: AgentManifest): boolean;
|
|
@@ -27,15 +27,51 @@ function removeOnlySkills(pinned, candidate) {
|
|
|
27
27
|
}
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* One tool setting, or the `"*"` entry, only tightened (R2b C9, Q18): `enabled` kept or set to
|
|
32
|
+
* `false`, `approval` kept or set to `always`, `deferred` kept. Each level of a tool's resolution
|
|
33
|
+
* (its entry, then `"*"`) either keeps its value or tightens it, so the tool does too.
|
|
34
|
+
*/
|
|
35
|
+
function tightensSettings(prior, next) {
|
|
36
|
+
return ((next.enabled === prior?.enabled || next.enabled === false) &&
|
|
37
|
+
(next.approval === prior?.approval || next.approval === "always") &&
|
|
38
|
+
next.deferred === prior?.deferred);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The servers of a turn variant: the pinned ones, the same but for their `tools` maps, where a
|
|
42
|
+
* variant may only disable a tool or require its approval (R2b C9, Q18). An entry the pin has
|
|
43
|
+
* stays, since dropping one could widen.
|
|
44
|
+
*/
|
|
45
|
+
function tightensServers(pinned, candidate) {
|
|
46
|
+
if (pinned === undefined || candidate === undefined)
|
|
47
|
+
return same(candidate, pinned);
|
|
48
|
+
const names = Object.keys(pinned);
|
|
49
|
+
if (!same(Object.keys(candidate).sort(), [...names].sort()))
|
|
50
|
+
return false;
|
|
51
|
+
return names.every((name) => {
|
|
52
|
+
const { tools: priorTools, ...prior } = pinned[name];
|
|
53
|
+
const { tools: nextTools, ...next } = candidate[name];
|
|
54
|
+
if (!same(next, prior))
|
|
55
|
+
return false;
|
|
56
|
+
if (nextTools === undefined)
|
|
57
|
+
return priorTools === undefined;
|
|
58
|
+
for (const key of Object.keys(priorTools ?? {}))
|
|
59
|
+
if (!Object.hasOwn(nextTools, key))
|
|
60
|
+
return false;
|
|
61
|
+
return Object.entries(nextTools).every(([key, settings]) => tightensSettings(Object.hasOwn(priorTools ?? {}, key) ? priorTools[key] : undefined, settings));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
30
64
|
/**
|
|
31
65
|
* Whether `candidate` is a valid turn-manifest variant of the session's pinned
|
|
32
|
-
* manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed
|
|
66
|
+
* manifest (`loops.md` §3.4). Setup (MCP, sandbox) is fixed, but a variant may disable an MCP
|
|
67
|
+
* server's tools or require their approval (R2b C9, Q18);
|
|
33
68
|
* code-backed tools/skills/agents-as-tools are remove-only; plain data may change.
|
|
34
69
|
*/
|
|
35
70
|
export function isVariantOf(candidate, pinned) {
|
|
36
71
|
if (candidate.id !== pinned.id)
|
|
37
72
|
return false;
|
|
38
|
-
|
|
73
|
+
// A variant of a v5 pin may be v6, to set an MCP server's tools; never older than its pin.
|
|
74
|
+
if (candidate.manifestSchemaVersion < pinned.manifestSchemaVersion)
|
|
39
75
|
return false;
|
|
40
76
|
if (!same(candidate.runtime ?? {}, pinned.runtime ?? {}))
|
|
41
77
|
return false;
|
|
@@ -45,7 +81,7 @@ export function isVariantOf(candidate, pinned) {
|
|
|
45
81
|
const next = candidateById.get(prior.id);
|
|
46
82
|
// Setup — and any capability that declares it — must not change or be removed.
|
|
47
83
|
if (prior.mcpServers !== undefined) {
|
|
48
|
-
if (!next || !
|
|
84
|
+
if (!next || !tightensServers(prior.mcpServers, next.mcpServers))
|
|
49
85
|
return false;
|
|
50
86
|
}
|
|
51
87
|
if (prior.sandbox !== undefined) {
|
|
@@ -64,7 +100,7 @@ export function isVariantOf(candidate, pinned) {
|
|
|
64
100
|
if (!removeOnlySkills(prior.skills, next.skills))
|
|
65
101
|
return false;
|
|
66
102
|
// Free: name, description, metadata, instructions (and model once it exists).
|
|
67
|
-
if (!
|
|
103
|
+
if (!tightensServers(prior.mcpServers, next.mcpServers))
|
|
68
104
|
return false;
|
|
69
105
|
if (!same(next.sandbox, prior.sandbox))
|
|
70
106
|
return false;
|
|
@@ -9,7 +9,11 @@ export interface TranscriptUpdate {
|
|
|
9
9
|
entries: unknown[];
|
|
10
10
|
length: number;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* An edit's entries are split so each event stays well under S2's 1 MiB record limit: under
|
|
14
|
+
* 64 KiB when no entry is larger, as a step with one tool result is once the result fits its
|
|
15
|
+
* 32 KiB cap (R2b C11). An entry larger than this is an event of its own.
|
|
16
|
+
*/
|
|
13
17
|
export declare const CHUNK_BYTES: number;
|
|
14
18
|
export declare class TranscriptFoldError extends Error {
|
|
15
19
|
constructor(message: string);
|
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
* `transcript.updated` events, each an edit of the transcript before it. Shared by core, which
|
|
4
4
|
* records and folds them, and a harness, which computes them and keeps its cache with them.
|
|
5
5
|
*/
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* An edit's entries are split so each event stays well under S2's 1 MiB record limit: under
|
|
8
|
+
* 64 KiB when no entry is larger, as a step with one tool result is once the result fits its
|
|
9
|
+
* 32 KiB cap (R2b C11). An entry larger than this is an event of its own.
|
|
10
|
+
*/
|
|
11
|
+
export const CHUNK_BYTES = 48 * 1024;
|
|
8
12
|
export class TranscriptFoldError extends Error {
|
|
9
13
|
constructor(message) {
|
|
10
14
|
super(message);
|