@nylorun/core 0.19.0-beta → 0.21.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 +191 -0
- package/README.md +2 -2
- package/dist/compatibility.d.ts +148 -32
- package/dist/compatibility.js +154 -33
- package/dist/contracts.d.ts +2714 -495
- package/dist/contracts.js +1395 -493
- package/dist/define.d.ts +15 -12
- package/dist/define.js +11 -7
- package/dist/definition/approval.d.ts +16 -0
- package/dist/definition/approval.js +33 -0
- package/dist/definition/assemble.d.ts +6 -10
- package/dist/definition/assemble.js +48 -105
- package/dist/definition/bind-agent.d.ts +3 -4
- package/dist/definition/bind-agent.js +12 -30
- package/dist/definition/binding.d.ts +2 -2
- package/dist/definition/bound.d.ts +10 -10
- package/dist/definition/builder.d.ts +16 -20
- package/dist/definition/builder.js +29 -81
- package/dist/definition/code-tools.d.ts +4 -4
- package/dist/definition/code-tools.js +7 -22
- package/dist/definition/declaration.d.ts +4 -7
- package/dist/definition/declaration.js +29 -99
- package/dist/definition/{tools-capability.d.ts → deferred-tools.d.ts} +3 -13
- package/dist/definition/{tools-capability.js → deferred-tools.js} +2 -18
- package/dist/definition/delegate.d.ts +2 -4
- package/dist/definition/delegate.js +8 -10
- package/dist/definition/flow/compile.js +0 -2
- package/dist/definition/from.d.ts +7 -4
- package/dist/definition/from.js +72 -117
- package/dist/definition/helpers.d.ts +0 -7
- package/dist/definition/helpers.js +0 -5
- package/dist/definition/http-tool.d.ts +7 -4
- package/dist/definition/http-tool.js +6 -10
- package/dist/definition/implementations.d.ts +6 -8
- package/dist/definition/manifest.d.ts +11 -5
- package/dist/definition/manifest.js +27 -26
- package/dist/definition/mcp.d.ts +1 -52
- package/dist/definition/mcp.js +11 -60
- package/dist/definition/media-reference.d.ts +23 -0
- package/dist/definition/media-reference.js +26 -0
- package/dist/definition/removed.d.ts +3 -10
- package/dist/definition/removed.js +10 -17
- package/dist/definition/runtime-manifest.d.ts +30 -0
- package/dist/definition/runtime-manifest.js +132 -0
- package/dist/definition/sandbox-tools.d.ts +1 -1
- package/dist/definition/sandbox-tools.js +1 -1
- package/dist/definition/skill-tools.d.ts +13 -7
- package/dist/definition/skill-tools.js +23 -10
- package/dist/definition/trace.d.ts +18 -0
- package/dist/definition/trace.js +42 -0
- package/dist/definition/variant.d.ts +5 -4
- package/dist/definition/variant.js +23 -55
- package/dist/definition/workflow/runnable.js +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/harness-api/entries.d.ts +242 -0
- package/dist/harness-api/entries.js +118 -0
- package/dist/harness-api/gates.d.ts +167 -0
- package/dist/harness-api/gates.js +117 -0
- package/dist/harness-api/harness-api.schema.json +4975 -0
- package/dist/harness-api/index.d.ts +19 -3
- package/dist/harness-api/index.js +16 -3
- package/dist/harness-api/json-schema.d.ts +12 -0
- package/dist/harness-api/json-schema.js +61 -0
- package/dist/harness-api/mcp.d.ts +57 -0
- package/dist/harness-api/mcp.js +39 -0
- package/dist/harness-api/messages.d.ts +11 -5
- package/dist/harness-api/messages.js +5 -3
- package/dist/harness-api/schema.d.ts +346 -36
- package/dist/harness-api/schema.js +143 -22
- package/dist/harness-api/transport.d.ts +55 -0
- package/dist/harness-api/transport.js +61 -0
- package/dist/index.d.ts +1 -1
- package/dist/manifest-schemas.d.ts +6 -0
- package/dist/manifest-schemas.js +34 -0
- package/dist/schemas/agent-manifest.schema.json +897 -0
- package/dist/schemas/environment-manifest.schema.json +329 -0
- package/dist/types/agent.d.ts +1 -1
- package/dist/types/manifest.d.ts +48 -28
- package/dist/types/model.d.ts +2 -2
- package/dist/types/observe.d.ts +8 -20
- package/dist/types/part.d.ts +25 -0
- package/dist/types/tool.d.ts +1 -1
- package/dist/types/transcript.d.ts +5 -0
- package/dist/utils/definition-files.d.ts +11 -6
- package/dist/utils/definition-files.js +19 -9
- package/dist/utils/harness-id.d.ts +9 -0
- package/dist/utils/harness-id.js +11 -0
- package/dist/utils/runtime-tools.d.ts +19 -0
- package/dist/utils/runtime-tools.js +30 -0
- package/dist/utils/sandbox.d.ts +1 -1
- package/dist/utils/sandbox.js +1 -1
- package/package.json +11 -4
- package/dist/definition/capability.d.ts +0 -43
- package/dist/definition/capability.js +0 -82
- package/dist/definition/sandbox-capability.d.ts +0 -44
- package/dist/definition/sandbox-capability.js +0 -139
- package/dist/types/middleware.d.ts +0 -94
- /package/dist/types/{middleware.js → part.js} +0 -0
package/dist/definition/mcp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { APPROVAL_REMOVED } from "./approval.js";
|
|
2
2
|
export class McpError extends Error {
|
|
3
3
|
code;
|
|
4
4
|
constructor(code, message) {
|
|
@@ -7,41 +7,6 @@ export class McpError extends Error {
|
|
|
7
7
|
this.code = code;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Declare MCP servers as one capability.
|
|
12
|
-
*
|
|
13
|
-
* Prefer `Agent(...).mcp({ ... })`. Each key names a server; its `name` defaults to
|
|
14
|
-
* the key and, when given, must equal it. Nylorun accepts remote servers only:
|
|
15
|
-
* `streamable-http` and `sse` (see https://agent-plugins.org/plugin-authors/mcp-servers).
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* Agent({ id: "assistant" }).mcp({
|
|
19
|
-
* github: { type: "streamable-http", url: "https://mcp.example.com/github" },
|
|
20
|
-
* })
|
|
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
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export function mcp(servers, options = {}) {
|
|
42
|
-
const id = options.id ?? "mcp";
|
|
43
|
-
return { id, mcpServers: normalizeMcpServers(servers, "mcp()") };
|
|
44
|
-
}
|
|
45
10
|
/** Why a `stdio` MCP server is refused: the one message the builder, plugins and manifests give. */
|
|
46
11
|
export function stdioMcpRefusal(name) {
|
|
47
12
|
return `MCP server '${name}' uses stdio; Nylorun accepts remote MCP servers only (streamable-http or sse). Run the server behind an HTTP transport and declare its URL.`;
|
|
@@ -60,10 +25,12 @@ export function normalizeMcpServers(servers, caller = "mcp()") {
|
|
|
60
25
|
const server = isRecord(spec) && spec.name === undefined ? { ...spec, name: key } : spec;
|
|
61
26
|
if (isRecord(server) && server.type === "stdio")
|
|
62
27
|
throw new McpError("mcp.stdio", stdioMcpRefusal(key));
|
|
28
|
+
if (isRecord(server) && setsApproval(server))
|
|
29
|
+
throw new McpError("mcp.approval-removed", `MCP server '${key}': ${APPROVAL_REMOVED}`);
|
|
63
30
|
if (!isMcpServer(server)) {
|
|
64
31
|
throw new McpError("mcp.invalid-server", `MCP server '${key}' is not a valid streamable-http or sse declaration` +
|
|
65
32
|
(isRecord(server) && (server.tools !== undefined || server.deferred !== undefined)
|
|
66
|
-
? ": deferred is a boolean, and tools maps tool names to { enabled?,
|
|
33
|
+
? ": deferred is a boolean, and tools maps tool names to { enabled?, deferred? }"
|
|
67
34
|
: ""));
|
|
68
35
|
}
|
|
69
36
|
if (server.name !== key) {
|
|
@@ -92,23 +59,6 @@ export function mcpToolSettings(server, serverToolName) {
|
|
|
92
59
|
...(deferred === undefined ? {} : { deferred }),
|
|
93
60
|
};
|
|
94
61
|
}
|
|
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
|
-
}
|
|
112
62
|
function freezeServer(server) {
|
|
113
63
|
return Object.freeze({
|
|
114
64
|
name: server.name,
|
|
@@ -117,7 +67,6 @@ function freezeServer(server) {
|
|
|
117
67
|
...(server.headers === undefined
|
|
118
68
|
? {}
|
|
119
69
|
: { headers: Object.freeze({ ...server.headers }) }),
|
|
120
|
-
...(server.approval === undefined ? {} : { approval: server.approval }),
|
|
121
70
|
...(server.deferred === undefined ? {} : { deferred: server.deferred }),
|
|
122
71
|
...(server.tools === undefined
|
|
123
72
|
? {}
|
|
@@ -126,7 +75,6 @@ function freezeServer(server) {
|
|
|
126
75
|
name,
|
|
127
76
|
Object.freeze({
|
|
128
77
|
...(settings.enabled === undefined ? {} : { enabled: settings.enabled }),
|
|
129
|
-
...(settings.approval === undefined ? {} : { approval: settings.approval }),
|
|
130
78
|
...(settings.deferred === undefined ? {} : { deferred: settings.deferred }),
|
|
131
79
|
}),
|
|
132
80
|
]))),
|
|
@@ -139,20 +87,23 @@ function isMcpServer(value) {
|
|
|
139
87
|
if (value.type === "streamable-http" || value.type === "sse")
|
|
140
88
|
return (typeof value.url === "string" &&
|
|
141
89
|
value.url.length > 0 &&
|
|
142
|
-
(value.approval === undefined || isApprovalMode(value.approval)) &&
|
|
143
90
|
(value.deferred === undefined || typeof value.deferred === "boolean") &&
|
|
144
91
|
(value.tools === undefined || isToolSettingsMap(value.tools)));
|
|
145
92
|
return false;
|
|
146
93
|
}
|
|
147
|
-
|
|
94
|
+
/** A server, or one of its tools' settings, that sets `approval` (removed in R5 step 2). */
|
|
95
|
+
function setsApproval(server) {
|
|
96
|
+
if (server.approval !== undefined)
|
|
97
|
+
return true;
|
|
98
|
+
return isRecord(server.tools) && Object.values(server.tools).some((settings) => isRecord(settings) && settings.approval !== undefined);
|
|
99
|
+
}
|
|
148
100
|
function isToolSettingsMap(value) {
|
|
149
101
|
if (!isRecord(value))
|
|
150
102
|
return false;
|
|
151
103
|
return Object.entries(value).every(([name, settings]) => name.length > 0 &&
|
|
152
104
|
isRecord(settings) &&
|
|
153
|
-
Object.keys(settings).every((key) => key === "enabled" || key === "
|
|
105
|
+
Object.keys(settings).every((key) => key === "enabled" || key === "deferred") &&
|
|
154
106
|
(settings.enabled === undefined || typeof settings.enabled === "boolean") &&
|
|
155
|
-
(settings.approval === undefined || isApprovalMode(settings.approval)) &&
|
|
156
107
|
(settings.deferred === undefined || typeof settings.deferred === "boolean"));
|
|
157
108
|
}
|
|
158
109
|
function isRecord(value) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { JsonValue } from "../types/shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* What a media part's `reference` holds when the Runtime made it (protocol 6, 12): the artifact
|
|
4
|
+
* version, by id, with the file's name and size in bytes when known.
|
|
5
|
+
*/
|
|
6
|
+
export interface MediaReference {
|
|
7
|
+
readonly artifactId: string;
|
|
8
|
+
readonly version: number;
|
|
9
|
+
readonly name?: string;
|
|
10
|
+
readonly size?: number;
|
|
11
|
+
}
|
|
12
|
+
/** The reference of a media part the Runtime made, or undefined for another host's. */
|
|
13
|
+
export declare function mediaReferenceOf(value: JsonValue | undefined): MediaReference | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The line a file stands for in a prompt once its turn is over (protocol 12): its name, artifact
|
|
16
|
+
* id and version, and how the model reads it again. A file a tool returned names the tool.
|
|
17
|
+
*/
|
|
18
|
+
export declare function mediaReferenceLine(part: {
|
|
19
|
+
readonly mediaType: string;
|
|
20
|
+
readonly reference: JsonValue;
|
|
21
|
+
}, origin: "uploaded" | {
|
|
22
|
+
readonly tool: string;
|
|
23
|
+
}): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** The reference of a media part the Runtime made, or undefined for another host's. */
|
|
2
|
+
export function mediaReferenceOf(value) {
|
|
3
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
4
|
+
return undefined;
|
|
5
|
+
const { artifactId, version, name, size } = value;
|
|
6
|
+
if (typeof artifactId !== "string" || typeof version !== "number" || !Number.isInteger(version))
|
|
7
|
+
return undefined;
|
|
8
|
+
return {
|
|
9
|
+
artifactId,
|
|
10
|
+
version,
|
|
11
|
+
...(typeof name === "string" ? { name } : {}),
|
|
12
|
+
...(typeof size === "number" ? { size } : {}),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The line a file stands for in a prompt once its turn is over (protocol 12): its name, artifact
|
|
17
|
+
* id and version, and how the model reads it again. A file a tool returned names the tool.
|
|
18
|
+
*/
|
|
19
|
+
export function mediaReferenceLine(part, origin) {
|
|
20
|
+
const reference = mediaReferenceOf(part.reference);
|
|
21
|
+
const what = origin === "uploaded" ? "Uploaded artifact" : `Tool ${origin.tool} returned artifact`;
|
|
22
|
+
if (!reference)
|
|
23
|
+
return `[${what} (${part.mediaType})]`;
|
|
24
|
+
const name = JSON.stringify(reference.name ?? reference.artifactId);
|
|
25
|
+
return `[${what} ${name} · ${reference.artifactId} v${reference.version} · read_artifact to view]`;
|
|
26
|
+
}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
* manifest v3 for flow agents) is the first where the Runtime never calls the developer's code
|
|
4
|
-
* during a session (see MIGRATION.md). `model` went earlier: the Runtime owns the model.
|
|
5
|
-
*/
|
|
6
|
-
export declare const REMOVED_CAPABILITY_FIELDS: Readonly<Record<string, string>>;
|
|
1
|
+
/** Why a part may not carry a field that manifest v5 removed. */
|
|
2
|
+
export declare const REMOVED_PART_FIELDS: Readonly<Record<string, string>>;
|
|
7
3
|
/** Manifest fields an older SDK wrote, and why each is refused. */
|
|
8
4
|
export declare const REMOVED_MANIFEST_FIELDS: Readonly<Record<string, string>>;
|
|
9
|
-
/**
|
|
10
|
-
* Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5 and
|
|
11
|
-
* version 6 (R2b C9: an MCP server's `tools` and `deferred`; v5 is accepted unchanged).
|
|
12
|
-
*/
|
|
5
|
+
/** Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 7. */
|
|
13
6
|
export declare function manifestVersionIssue(version: unknown): string | undefined;
|
|
14
7
|
/** Why a workflow manifest with this `workflowSchemaVersion` is refused, or undefined for version 3. */
|
|
15
8
|
export declare function workflowVersionIssue(version: unknown): string | undefined;
|
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
export const REMOVED_CAPABILITY_FIELDS = Object.freeze({
|
|
7
|
-
hooks: "hooks were removed: the Runtime no longer calls your code during a session. Use an HTTP tool, approval on a tool, or a loop verifier instead (see MIGRATION.md)",
|
|
8
|
-
beforeModelCall: "beforeModelCall was removed with hooks (see MIGRATION.md)",
|
|
9
|
-
afterModelCall: "afterModelCall was removed with hooks (see MIGRATION.md)",
|
|
10
|
-
model: "A capability must not include model; the Runtime owns model resolution",
|
|
1
|
+
/** Why a part may not carry a field that manifest v5 removed. */
|
|
2
|
+
export const REMOVED_PART_FIELDS = Object.freeze({
|
|
3
|
+
hooks: "hooks were removed: the Runtime runs agents from their manifests alone. Use an HTTP tool, the Tenant's tool policy, or a loop verifier instead (see MIGRATION.md)",
|
|
4
|
+
model: "An agent must not include model; the Runtime owns model resolution",
|
|
11
5
|
});
|
|
12
6
|
/** Manifest fields an older SDK wrote, and why each is refused. */
|
|
13
7
|
export const REMOVED_MANIFEST_FIELDS = Object.freeze({
|
|
14
8
|
schemaVersion: "Manifest field schemaVersion was renamed to manifestSchemaVersion",
|
|
15
9
|
model: "Manifest must not include top-level model; Runtime owns model resolution",
|
|
10
|
+
hooks: "hooks were removed: the Runtime runs agents from their manifests alone. Use an HTTP tool, the Tenant's tool policy, or a loop verifier instead (see MIGRATION.md)",
|
|
11
|
+
capabilities: "Manifest v7 has no capabilities: the agent's instructions, tools, skills and mcpServers are top-level fields. Rebuild the agent with the current SDK (see MIGRATION.md)",
|
|
16
12
|
});
|
|
17
|
-
/**
|
|
18
|
-
* Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 5 and
|
|
19
|
-
* version 6 (R2b C9: an MCP server's `tools` and `deferred`; v5 is accepted unchanged).
|
|
20
|
-
*/
|
|
13
|
+
/** Why a manifest with this `manifestSchemaVersion` is refused, or undefined for version 7. */
|
|
21
14
|
export function manifestVersionIssue(version) {
|
|
22
|
-
if (version ===
|
|
15
|
+
if (version === 7)
|
|
23
16
|
return undefined;
|
|
24
|
-
if (version ===
|
|
25
|
-
return `manifestSchemaVersion ${version} is no longer supported: manifest
|
|
17
|
+
if (typeof version === "number" && version >= 3 && version <= 6)
|
|
18
|
+
return `manifestSchemaVersion ${version} is no longer supported: manifest v7 has no capabilities. Rebuild the agent with the current SDK (see MIGRATION.md)`;
|
|
26
19
|
return `Unsupported manifestSchemaVersion ${String(version)}`;
|
|
27
20
|
}
|
|
28
21
|
/** Why a workflow manifest with this `workflowSchemaVersion` is refused, or undefined for version 3. */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL } from "../utils/runtime-tools.js";
|
|
2
|
+
import type { AgentManifest, RuntimeManifest, SandboxManifest, ToolManifest } from "../types/manifest.js";
|
|
3
|
+
/**
|
|
4
|
+
* `save_artifact` stores a file the agent made (protocol 6). `read_artifact` reads an artifact of
|
|
5
|
+
* the session in pages (R2b C11, Q24): a tool result the Runtime stored because it was too large
|
|
6
|
+
* to show, or a file of an earlier turn (protocol 12).
|
|
7
|
+
*/
|
|
8
|
+
export { READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL };
|
|
9
|
+
/** The most `read_artifact` returns per call (R2b C11): 32 KiB, the inline cap of a tool result. */
|
|
10
|
+
export declare const READ_ARTIFACT_MAX_BYTES: number;
|
|
11
|
+
/** What the Runtime adds to a session's agent (`runtimeManifestFor`). */
|
|
12
|
+
export interface RuntimeManifestOptions {
|
|
13
|
+
/** The session's sandbox: the six sandbox tools, their instructions and the spec. */
|
|
14
|
+
readonly sandbox?: SandboxManifest;
|
|
15
|
+
/** The workspace path the backend uses, named in the tools' text. Default `/workspace`. */
|
|
16
|
+
readonly workspace?: string;
|
|
17
|
+
/** `save_artifact`, which stores a sandbox file or text. Default: with a sandbox. */
|
|
18
|
+
readonly save?: boolean;
|
|
19
|
+
/** `read_artifact`, which reads the session's artifacts. Default false. */
|
|
20
|
+
readonly read?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The `runtime` block the Runtime pins on a session's agent: the sandbox and its tools, the
|
|
24
|
+
* artifact tools, and the skill tools with the skill catalog when the agent has skills. Its tools
|
|
25
|
+
* are projected the way the builder projects any tool, so their schemas are part of the pinned
|
|
26
|
+
* manifest's hash; change them deliberately. Undefined when the Runtime adds nothing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runtimeManifestFor(manifest: Pick<AgentManifest, "skills">, options?: RuntimeManifestOptions): RuntimeManifest | undefined;
|
|
29
|
+
/** The tool of `name` the Runtime added to `manifest`, if any. */
|
|
30
|
+
export declare function runtimeToolOf(manifest: AgentManifest | undefined, name: string | undefined): ToolManifest | undefined;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SANDBOX_INSTRUCTIONS, createSandboxTools } from "./sandbox-tools.js";
|
|
3
|
+
import { tool } from "./helpers.js";
|
|
4
|
+
import { ToolError } from "./tool-error.js";
|
|
5
|
+
import { SANDBOX_WORKSPACE } from "../utils/sandbox.js";
|
|
6
|
+
import { SKILLS_MOUNT, skillFolderOf } from "../utils/definition-files.js";
|
|
7
|
+
import { normalizedSchemasFor } from "./schema.js";
|
|
8
|
+
import { createSkillTools, formatSkillCatalog, SKILLS_USAGE } from "./skill-tools.js";
|
|
9
|
+
import { copyJsonObject } from "../utils/immutable.js";
|
|
10
|
+
import { READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL } from "../utils/runtime-tools.js";
|
|
11
|
+
/**
|
|
12
|
+
* `save_artifact` stores a file the agent made (protocol 6). `read_artifact` reads an artifact of
|
|
13
|
+
* the session in pages (R2b C11, Q24): a tool result the Runtime stored because it was too large
|
|
14
|
+
* to show, or a file of an earlier turn (protocol 12).
|
|
15
|
+
*/
|
|
16
|
+
export { READ_ARTIFACT_TOOL, SAVE_ARTIFACT_TOOL };
|
|
17
|
+
/** The most `read_artifact` returns per call (R2b C11): 32 KiB, the inline cap of a tool result. */
|
|
18
|
+
export const READ_ARTIFACT_MAX_BYTES = 32 * 1024;
|
|
19
|
+
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. " +
|
|
20
|
+
"The user sees it as an artifact of this session and can download it; reply with its name, not its bytes. " +
|
|
21
|
+
"Files you write under /workspace/outputs reach the user too: when your turn ends, they become the session's outputs folder.";
|
|
22
|
+
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. " +
|
|
23
|
+
"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. " +
|
|
24
|
+
'Files from earlier turns appear as lines like [Uploaded artifact "name" · <artifactId> v<version> · read_artifact to view]: call read_artifact with that artifactId and version only when you need the file again.';
|
|
25
|
+
async function artifactsRuntimeOnly() {
|
|
26
|
+
throw new ToolError("artifacts.runtime-only", "The artifact tools run in the Nylorun Runtime. Connect the agent to a Runtime to use them.");
|
|
27
|
+
}
|
|
28
|
+
function readArtifactTool() {
|
|
29
|
+
return tool({
|
|
30
|
+
name: READ_ARTIFACT_TOOL,
|
|
31
|
+
description: `Read an artifact of this session, such as a tool result marked truncated or a file from an earlier turn. A text file returns up to ${READ_ARTIFACT_MAX_BYTES} bytes from offset, ` +
|
|
32
|
+
"with nextOffset while more remains: pass it as offset to read on. An image or another file you can read is shown to you.",
|
|
33
|
+
inputSchema: z.object({
|
|
34
|
+
artifactId: z.string().min(1).describe("The artifact to read, e.g. a truncated result's artifactId."),
|
|
35
|
+
version: z.number().int().min(1).optional().describe("The version to read. Default: the latest."),
|
|
36
|
+
offset: z.number().int().min(0).optional().describe("The byte to start at. Default 0."),
|
|
37
|
+
length: z
|
|
38
|
+
.number()
|
|
39
|
+
.int()
|
|
40
|
+
.min(1)
|
|
41
|
+
.max(READ_ARTIFACT_MAX_BYTES)
|
|
42
|
+
.optional()
|
|
43
|
+
.describe(`How many bytes to read. Default and most: ${READ_ARTIFACT_MAX_BYTES}.`),
|
|
44
|
+
}),
|
|
45
|
+
effects: "read",
|
|
46
|
+
execute: artifactsRuntimeOnly,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function saveArtifactTool() {
|
|
50
|
+
return tool({
|
|
51
|
+
name: SAVE_ARTIFACT_TOOL,
|
|
52
|
+
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. ` +
|
|
53
|
+
"Returns the artifact's id and version. Pass artifactId to save a new version of an artifact you saved before.",
|
|
54
|
+
inputSchema: z.object({
|
|
55
|
+
path: z.string().min(1).optional().describe("A file in the sandbox."),
|
|
56
|
+
content: z.string().optional().describe("Text to save instead of a file."),
|
|
57
|
+
name: z
|
|
58
|
+
.string()
|
|
59
|
+
.min(1)
|
|
60
|
+
.max(255)
|
|
61
|
+
.optional()
|
|
62
|
+
.describe("The artifact's name. Default: the file's name."),
|
|
63
|
+
contentType: z
|
|
64
|
+
.string()
|
|
65
|
+
.min(1)
|
|
66
|
+
.optional()
|
|
67
|
+
.describe("The media type, e.g. image/png. Default: from the name's extension."),
|
|
68
|
+
artifactId: z.string().min(1).optional().describe("Save a new version of this artifact."),
|
|
69
|
+
}),
|
|
70
|
+
effects: "write",
|
|
71
|
+
execute: artifactsRuntimeOnly,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The `runtime` block the Runtime pins on a session's agent: the sandbox and its tools, the
|
|
76
|
+
* artifact tools, and the skill tools with the skill catalog when the agent has skills. Its tools
|
|
77
|
+
* are projected the way the builder projects any tool, so their schemas are part of the pinned
|
|
78
|
+
* manifest's hash; change them deliberately. Undefined when the Runtime adds nothing.
|
|
79
|
+
*/
|
|
80
|
+
export function runtimeManifestFor(manifest, options = {}) {
|
|
81
|
+
const workspace = options.workspace ?? SANDBOX_WORKSPACE;
|
|
82
|
+
const text = (value) => value.replaceAll(SANDBOX_WORKSPACE, workspace);
|
|
83
|
+
const skills = Object.values(manifest.skills ?? {});
|
|
84
|
+
const save = options.save ?? options.sandbox !== undefined;
|
|
85
|
+
const read = options.read ?? false;
|
|
86
|
+
const instructions = [];
|
|
87
|
+
const tools = [];
|
|
88
|
+
if (skills.length > 0)
|
|
89
|
+
instructions.push(SKILLS_USAGE, formatSkillCatalog(skills.map(({ name, description }) => ({ name, description }))));
|
|
90
|
+
if (options.sandbox !== undefined) {
|
|
91
|
+
instructions.push(text(SANDBOX_INSTRUCTIONS));
|
|
92
|
+
if (skills.length > 0)
|
|
93
|
+
instructions.push(`Each skill's files are in the sandbox, read-only, in its own folder under ${SKILLS_MOUNT}/ (${skills
|
|
94
|
+
.map((skill) => `${skill.name}: ${skillFolderOf(skill)}/`)
|
|
95
|
+
.join(", ")}): read them there and run their scripts with bash.`);
|
|
96
|
+
tools.push(...createSandboxTools());
|
|
97
|
+
}
|
|
98
|
+
if (save) {
|
|
99
|
+
instructions.push(ARTIFACTS_INSTRUCTIONS);
|
|
100
|
+
tools.push(saveArtifactTool());
|
|
101
|
+
}
|
|
102
|
+
if (read) {
|
|
103
|
+
instructions.push(READ_ARTIFACT_INSTRUCTIONS);
|
|
104
|
+
tools.push(readArtifactTool());
|
|
105
|
+
}
|
|
106
|
+
if (skills.length > 0)
|
|
107
|
+
tools.push(...createSkillTools(new Map(skills.map((skill) => [skill.name, skill]))));
|
|
108
|
+
if (instructions.length === 0 && tools.length === 0 && options.sandbox === undefined)
|
|
109
|
+
return undefined;
|
|
110
|
+
return {
|
|
111
|
+
...(options.sandbox === undefined
|
|
112
|
+
? {}
|
|
113
|
+
: { sandbox: copyJsonObject(options.sandbox, "sandbox") }),
|
|
114
|
+
...(tools.length === 0 ? {} : { tools: tools.map((tool) => projectRuntimeTool(tool, text)) }),
|
|
115
|
+
...(instructions.length === 0 ? {} : { instructions }),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** The tool of `name` the Runtime added to `manifest`, if any. */
|
|
119
|
+
export function runtimeToolOf(manifest, name) {
|
|
120
|
+
if (name === undefined)
|
|
121
|
+
return undefined;
|
|
122
|
+
return manifest?.runtime?.tools?.find((tool) => tool.name === name);
|
|
123
|
+
}
|
|
124
|
+
function projectRuntimeTool(tool, text) {
|
|
125
|
+
const schemas = normalizedSchemasFor(tool);
|
|
126
|
+
return {
|
|
127
|
+
name: tool.name,
|
|
128
|
+
...(tool.description === undefined ? {} : { description: text(tool.description) }),
|
|
129
|
+
inputSchema: schemas.inputSchema.jsonSchema,
|
|
130
|
+
...(schemas.outputSchema === undefined ? {} : { outputSchema: schemas.outputSchema.jsonSchema }),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ToolDefinition } from "../types/tool.js";
|
|
2
|
-
/** Instructions
|
|
2
|
+
/** Instructions that come with a session's sandbox tools. */
|
|
3
3
|
export declare const SANDBOX_INSTRUCTIONS: string;
|
|
4
4
|
/** The six built-in sandbox tools. Schemas are part of the hashed manifest; change them deliberately. */
|
|
5
5
|
export declare function createSandboxTools(): readonly ToolDefinition[];
|
|
@@ -3,7 +3,7 @@ import { tool } from "./helpers.js";
|
|
|
3
3
|
import { ToolError } from "./tool-error.js";
|
|
4
4
|
import { SANDBOX_WORKSPACE } from "../utils/sandbox.js";
|
|
5
5
|
const PATH_NOTE = `Relative paths resolve under ${SANDBOX_WORKSPACE}.`;
|
|
6
|
-
/** Instructions
|
|
6
|
+
/** Instructions that come with a session's sandbox tools. */
|
|
7
7
|
export const SANDBOX_INSTRUCTIONS = `You have an isolated Linux sandbox with a persistent working directory at ${SANDBOX_WORKSPACE}. ` +
|
|
8
8
|
"Use bash to run commands, read/write/edit to work with files, and grep/glob to search. " +
|
|
9
9
|
"Network egress is limited by policy; a failed download usually means the host is not allowed.";
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentManifest, SkillManifest } from "../types/manifest.js";
|
|
2
2
|
import type { ToolDefinition } from "../types/tool.js";
|
|
3
|
-
|
|
4
|
-
export
|
|
3
|
+
import { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL } from "../utils/runtime-tools.js";
|
|
4
|
+
export { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL };
|
|
5
5
|
export declare const SKILL_TOOL_NAMES: ReadonlySet<string>;
|
|
6
6
|
/**
|
|
7
|
-
* Whether `toolName` is a skill tool the Runtime serves: `load_skill` or `read_skill_resource`
|
|
8
|
-
*
|
|
9
|
-
* tool of that name elsewhere is the author's own.
|
|
7
|
+
* Whether `toolName` is a skill tool the Runtime serves: `load_skill` or `read_skill_resource` in
|
|
8
|
+
* the pinned manifest's `runtime.tools`, which the Runtime adds when the agent has skills.
|
|
10
9
|
*/
|
|
11
|
-
export declare function isSkillTool(
|
|
10
|
+
export declare function isSkillTool(manifest: AgentManifest | undefined, toolName: string | undefined): boolean;
|
|
11
|
+
/** The text before the skill catalog: when to load a skill. */
|
|
12
|
+
export declare const SKILLS_USAGE = "The following skills provide specialized instructions. When a task matches a skill description, call load_skill with that name before proceeding.";
|
|
13
|
+
/** The skills the model may load, by name and description. */
|
|
14
|
+
export declare function formatSkillCatalog(skills: readonly {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly description: string;
|
|
17
|
+
}[]): string;
|
|
12
18
|
/**
|
|
13
19
|
* `load_skill` for every skill of an agent, and `read_skill_resource` when a skill has files
|
|
14
20
|
* besides `SKILL.md`. Their names and input schemas are part of the hashed manifest; the Runtime
|
|
@@ -2,24 +2,37 @@ import { z } from "zod";
|
|
|
2
2
|
import { SKILL_ENTRY } from "../utils/definition-files.js";
|
|
3
3
|
import { tool } from "./helpers.js";
|
|
4
4
|
import { ToolError } from "./tool-error.js";
|
|
5
|
-
|
|
6
|
-
export
|
|
5
|
+
import { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL } from "../utils/runtime-tools.js";
|
|
6
|
+
export { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL };
|
|
7
7
|
export const SKILL_TOOL_NAMES = new Set([
|
|
8
8
|
LOAD_SKILL_TOOL,
|
|
9
9
|
READ_SKILL_RESOURCE_TOOL,
|
|
10
10
|
]);
|
|
11
11
|
const USAGE = "Load the full instructions for a named skill. Call this before following a skill.";
|
|
12
12
|
/**
|
|
13
|
-
* Whether `toolName` is a skill tool the Runtime serves: `load_skill` or `read_skill_resource`
|
|
14
|
-
*
|
|
15
|
-
* tool of that name elsewhere is the author's own.
|
|
13
|
+
* Whether `toolName` is a skill tool the Runtime serves: `load_skill` or `read_skill_resource` in
|
|
14
|
+
* the pinned manifest's `runtime.tools`, which the Runtime adds when the agent has skills.
|
|
16
15
|
*/
|
|
17
|
-
export function isSkillTool(
|
|
18
|
-
return (
|
|
19
|
-
toolName !== undefined &&
|
|
16
|
+
export function isSkillTool(manifest, toolName) {
|
|
17
|
+
return (toolName !== undefined &&
|
|
20
18
|
SKILL_TOOL_NAMES.has(toolName) &&
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
manifest?.runtime?.tools?.some((item) => item.name === toolName) === true);
|
|
20
|
+
}
|
|
21
|
+
/** The text before the skill catalog: when to load a skill. */
|
|
22
|
+
export const SKILLS_USAGE = "The following skills provide specialized instructions. When a task matches a skill description, call load_skill with that name before proceeding.";
|
|
23
|
+
/** The skills the model may load, by name and description. */
|
|
24
|
+
export function formatSkillCatalog(skills) {
|
|
25
|
+
const entries = skills
|
|
26
|
+
.map((skill) => ` <skill>\n <name>${escapeXml(skill.name)}</name>\n <description>${escapeXml(skill.description)}</description>\n </skill>`)
|
|
27
|
+
.join("\n");
|
|
28
|
+
return `<available_skills>\n${entries}\n</available_skills>`;
|
|
29
|
+
}
|
|
30
|
+
function escapeXml(value) {
|
|
31
|
+
return value
|
|
32
|
+
.replaceAll("&", "&")
|
|
33
|
+
.replaceAll("<", "<")
|
|
34
|
+
.replaceAll(">", ">")
|
|
35
|
+
.replaceAll('"', """);
|
|
23
36
|
}
|
|
24
37
|
/**
|
|
25
38
|
* Stub implementation for the developer process. The Runtime serves the skill tools from the
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AgentManifest, PluginLabel } from "../types/manifest.js";
|
|
2
|
+
/** What a tool call is traced to: the skill it ran, and the plugin that brought its skill or server. */
|
|
3
|
+
export interface ToolCallTrace {
|
|
4
|
+
readonly skill?: string;
|
|
5
|
+
readonly plugin?: PluginLabel;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The skill of `manifest` a tool call ran. `load_skill` and `read_skill_resource` name it in their
|
|
9
|
+
* input. A sandbox tool (`bash`, `read`, `grep`, `glob`, …) is matched on the skills' mount path,
|
|
10
|
+
* `/skills/<name>@<hash>/` (or `/skills/<name>/`, before D66), in its input's text: exact for a path argument, and for `bash` only when the
|
|
11
|
+
* command names the path. The first skill of the agent the input names wins.
|
|
12
|
+
*/
|
|
13
|
+
export declare function skillOfToolCall(manifest: Pick<AgentManifest, "skills"> | undefined, toolName: string | undefined, input: unknown): string | undefined;
|
|
14
|
+
/** The plugin that brought the skill or MCP server `name` to `manifest`, if one did. */
|
|
15
|
+
export declare function pluginOf(manifest: Pick<AgentManifest, "skills" | "mcpServers"> | undefined, what: {
|
|
16
|
+
readonly skill?: string;
|
|
17
|
+
readonly server?: string;
|
|
18
|
+
}): PluginLabel | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SKILLS_MOUNT } from "../utils/definition-files.js";
|
|
2
|
+
import { isSandboxToolName } from "../utils/sandbox.js";
|
|
3
|
+
import { SKILL_TOOL_NAMES } from "./skill-tools.js";
|
|
4
|
+
const MOUNT = new RegExp(`${SKILLS_MOUNT}/([^/@\\s"'\`]+)(?:@[0-9a-f]{12})?/`, "g");
|
|
5
|
+
/**
|
|
6
|
+
* The skill of `manifest` a tool call ran. `load_skill` and `read_skill_resource` name it in their
|
|
7
|
+
* input. A sandbox tool (`bash`, `read`, `grep`, `glob`, …) is matched on the skills' mount path,
|
|
8
|
+
* `/skills/<name>@<hash>/` (or `/skills/<name>/`, before D66), in its input's text: exact for a path argument, and for `bash` only when the
|
|
9
|
+
* command names the path. The first skill of the agent the input names wins.
|
|
10
|
+
*/
|
|
11
|
+
export function skillOfToolCall(manifest, toolName, input) {
|
|
12
|
+
const skills = manifest?.skills;
|
|
13
|
+
if (!skills || toolName === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
if (SKILL_TOOL_NAMES.has(toolName)) {
|
|
16
|
+
const name = input?.name;
|
|
17
|
+
return typeof name === "string" && skills[name] !== undefined ? name : undefined;
|
|
18
|
+
}
|
|
19
|
+
if (!isSandboxToolName(toolName))
|
|
20
|
+
return undefined;
|
|
21
|
+
for (const text of strings(input))
|
|
22
|
+
for (const match of text.matchAll(MOUNT))
|
|
23
|
+
if (skills[match[1]] !== undefined)
|
|
24
|
+
return match[1];
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
/** The plugin that brought the skill or MCP server `name` to `manifest`, if one did. */
|
|
28
|
+
export function pluginOf(manifest, what) {
|
|
29
|
+
if (what.skill !== undefined)
|
|
30
|
+
return manifest?.skills?.[what.skill]?.plugin;
|
|
31
|
+
if (what.server !== undefined)
|
|
32
|
+
return manifest?.mcpServers?.[what.server]?.plugin;
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
/** The string values of a tool's input, one level deep: its path, pattern or command. */
|
|
36
|
+
function strings(input) {
|
|
37
|
+
if (typeof input === "string")
|
|
38
|
+
return [input];
|
|
39
|
+
if (!input || typeof input !== "object")
|
|
40
|
+
return [];
|
|
41
|
+
return Object.values(input).filter((value) => typeof value === "string");
|
|
42
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AgentManifest } from "../types/manifest.js";
|
|
2
2
|
/**
|
|
3
|
-
* Whether `candidate` is a valid turn-manifest variant of the session's pinned
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* Whether `candidate` is a valid turn-manifest variant of the session's pinned manifest
|
|
4
|
+
* (`loops.md` §3.4). A variant may remove tools (agents used as tools and HTTP tools included),
|
|
5
|
+
* tighten its MCP servers' tool settings (R2b C9, Q18), and change its instructions, name,
|
|
6
|
+
* description and metadata. Its skills and servers are setup: the sandbox holds the skills from
|
|
7
|
+
* the session's start. It never sets `runtime`; the turn runs with the pin's.
|
|
7
8
|
*/
|
|
8
9
|
export declare function isVariantOf(candidate: AgentManifest, pinned: AgentManifest): boolean;
|