@nylorun/core 0.22.0-beta → 0.24.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 +126 -0
- package/README.md +1 -1
- package/dist/compatibility.d.ts +120 -47
- package/dist/compatibility.js +122 -49
- package/dist/contracts.d.ts +2824 -907
- package/dist/contracts.js +1286 -585
- package/dist/define.d.ts +9 -12
- package/dist/define.js +8 -11
- package/dist/definition/assemble.d.ts +1 -3
- package/dist/definition/assemble.js +4 -8
- package/dist/definition/bound.d.ts +1 -1
- package/dist/definition/delegate.d.ts +5 -0
- package/dist/definition/delegate.js +6 -1
- package/dist/definition/from.d.ts +4 -2
- package/dist/definition/from.js +11 -29
- package/dist/definition/http-tool.d.ts +5 -3
- package/dist/definition/http-tool.js +8 -5
- package/dist/definition/manifest.d.ts +7 -6
- package/dist/definition/manifest.js +7 -6
- package/dist/definition/mcp.d.ts +1 -1
- package/dist/definition/media-reference.d.ts +2 -11
- package/dist/definition/media-reference.js +0 -12
- package/dist/definition/model-failure.js +1 -0
- package/dist/definition/removed.d.ts +7 -0
- package/dist/definition/removed.js +21 -0
- package/dist/definition/sections.d.ts +63 -0
- package/dist/definition/sections.js +204 -0
- package/dist/definition/trace.d.ts +0 -7
- package/dist/definition/trace.js +0 -34
- package/dist/definition/variant.d.ts +1 -1
- package/dist/definition/variant.js +1 -3
- package/dist/harness-api/artifacts.d.ts +84 -0
- package/dist/harness-api/artifacts.js +128 -0
- package/dist/harness-api/gates.d.ts +0 -4
- package/dist/harness-api/gates.js +0 -4
- package/dist/harness-api/harness-api.schema.json +2798 -1124
- package/dist/harness-api/index.d.ts +9 -6
- package/dist/harness-api/index.js +9 -6
- package/dist/harness-api/json-schema.js +5 -2
- package/dist/harness-api/mcp.d.ts +77 -30
- package/dist/harness-api/mcp.js +42 -25
- package/dist/harness-api/messages.d.ts +47 -17
- package/dist/harness-api/messages.js +20 -5
- package/dist/harness-api/schema.d.ts +609 -200
- package/dist/harness-api/schema.js +345 -62
- package/dist/harness-api/transcript.d.ts +8 -10
- package/dist/harness-api/transcript.js +27 -11
- package/dist/harness-api/transport.d.ts +7 -1
- package/dist/harness-api/transport.js +10 -7
- package/dist/manifest-schemas.d.ts +9 -5
- package/dist/manifest-schemas.js +23 -27
- package/dist/schemas/agent-manifest.schema.json +1508 -365
- package/dist/schemas/harness-manifest.schema.json +1273 -0
- package/dist/schemas/{environment-manifest.schema.json → runtime-manifest.schema.json} +165 -84
- package/dist/types/manifest.d.ts +72 -14
- package/dist/types/manifest.js +4 -0
- package/dist/types/model.d.ts +15 -5
- package/dist/utils/definition-files.d.ts +20 -6
- package/dist/utils/definition-files.js +31 -17
- package/dist/utils/file-systems.d.ts +20 -0
- package/dist/utils/file-systems.js +20 -0
- package/dist/utils/harness-id.d.ts +4 -1
- package/dist/utils/harness-id.js +4 -1
- package/dist/utils/media-types.d.ts +30 -0
- package/dist/utils/media-types.js +128 -0
- package/dist/utils/memory.d.ts +64 -0
- package/dist/utils/memory.js +139 -0
- package/dist/utils/runtime-limits.d.ts +280 -0
- package/dist/utils/runtime-limits.js +585 -0
- package/dist/utils/runtime-tools.d.ts +8 -16
- package/dist/utils/runtime-tools.js +8 -27
- package/dist/utils/sandbox.d.ts +4 -1
- package/dist/utils/sandbox.js +4 -1
- package/package.json +6 -5
- package/dist/definition/deferred-tools.d.ts +0 -27
- package/dist/definition/deferred-tools.js +0 -82
- package/dist/definition/runtime-manifest.d.ts +0 -30
- package/dist/definition/runtime-manifest.js +0 -132
- package/dist/definition/sandbox-tools.d.ts +0 -5
- package/dist/definition/sandbox-tools.js +0 -109
- package/dist/definition/skill-tools.d.ts +0 -23
- package/dist/definition/skill-tools.js +0 -76
package/dist/utils/sandbox.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/** Portable sandbox constants and parsers shared by the SDK, wire schema and Runtime. */
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The sandbox operations a harness runs in a session's sandbox: a `sandbox` call names one as its
|
|
4
|
+
* tool (protocol 15). Our engine offers a tool of each name.
|
|
5
|
+
*/
|
|
3
6
|
export const SANDBOX_TOOL_NAMES = Object.freeze([
|
|
4
7
|
"bash",
|
|
5
8
|
"read",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nylorun/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0-beta",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Shared agent definitions and wire contracts",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"@noble/hashes": "^2.4.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^26.6.
|
|
36
|
+
"@types/node": "^26.6.5",
|
|
37
37
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
38
|
-
"vitest": "^5.0.
|
|
38
|
+
"vitest": "^5.0.4"
|
|
39
39
|
},
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
|
@@ -72,10 +72,11 @@
|
|
|
72
72
|
"import": "./dist/manifest-schemas.js"
|
|
73
73
|
},
|
|
74
74
|
"./schemas/agent-manifest.json": "./dist/schemas/agent-manifest.schema.json",
|
|
75
|
-
"./schemas/
|
|
75
|
+
"./schemas/harness-manifest.json": "./dist/schemas/harness-manifest.schema.json",
|
|
76
|
+
"./schemas/runtime-manifest.json": "./dist/schemas/runtime-manifest.schema.json"
|
|
76
77
|
},
|
|
77
78
|
"peerDependencies": {
|
|
78
|
-
"zod": "^4.6.
|
|
79
|
+
"zod": "^4.6.7"
|
|
79
80
|
},
|
|
80
81
|
"sideEffects": false
|
|
81
82
|
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ToolManifest } from "../types/manifest.js";
|
|
2
|
-
import { TOOL_CALL_TOOL, TOOL_SEARCH_TOOL } from "../utils/runtime-tools.js";
|
|
3
|
-
export { TOOL_CALL_TOOL, TOOL_SEARCH_TOOL };
|
|
4
|
-
/** How many tools `tool_search` returns when the model sets no `limit`. */
|
|
5
|
-
export declare const TOOL_SEARCH_DEFAULT_LIMIT = 8;
|
|
6
|
-
/** The most tools one `tool_search` returns. */
|
|
7
|
-
export declare const TOOL_SEARCH_MAX_LIMIT = 20;
|
|
8
|
-
/** How much of a server's own instructions the model sees in the deferred tools' note. */
|
|
9
|
-
export declare const SERVER_INSTRUCTIONS_MAX_CHARS = 2000;
|
|
10
|
-
/** A server some of whose tools are deferred, as the model's note names it. */
|
|
11
|
-
export interface DeferredServerNote {
|
|
12
|
-
readonly serverName: string;
|
|
13
|
-
/** How many of its tools are deferred. */
|
|
14
|
-
readonly tools: number;
|
|
15
|
-
/** The server's own instructions (MCP `initialize`), if it gave any. */
|
|
16
|
-
readonly instructions?: string;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* `tool_search` and `tool_call`, as the session gives them to an agent with deferred tools. Their
|
|
20
|
-
* schemas reach the model; change them deliberately.
|
|
21
|
-
*/
|
|
22
|
-
export declare function deferredToolsTools(): readonly ToolManifest[];
|
|
23
|
-
/**
|
|
24
|
-
* The note the model reads beside `tool_search`: each server with deferred tools, how many, and
|
|
25
|
-
* its own instructions cut to `SERVER_INSTRUCTIONS_MAX_CHARS`.
|
|
26
|
-
*/
|
|
27
|
-
export declare function deferredToolsInstructions(servers: readonly DeferredServerNote[]): string;
|
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
import { TOOL_CALL_TOOL, TOOL_SEARCH_TOOL } from "../utils/runtime-tools.js";
|
|
6
|
-
export { TOOL_CALL_TOOL, TOOL_SEARCH_TOOL };
|
|
7
|
-
/** How many tools `tool_search` returns when the model sets no `limit`. */
|
|
8
|
-
export const TOOL_SEARCH_DEFAULT_LIMIT = 8;
|
|
9
|
-
/** The most tools one `tool_search` returns. */
|
|
10
|
-
export const TOOL_SEARCH_MAX_LIMIT = 20;
|
|
11
|
-
/** How much of a server's own instructions the model sees in the deferred tools' note. */
|
|
12
|
-
export const SERVER_INSTRUCTIONS_MAX_CHARS = 2_000;
|
|
13
|
-
async function toolsRuntimeOnly() {
|
|
14
|
-
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.");
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* `tool_search` and `tool_call`, as the session gives them to an agent with deferred tools. Their
|
|
18
|
-
* schemas reach the model; change them deliberately.
|
|
19
|
-
*/
|
|
20
|
-
export function deferredToolsTools() {
|
|
21
|
-
return [searchTool(), callTool()].map((item) => {
|
|
22
|
-
const schemas = normalizedSchemasFor(item);
|
|
23
|
-
return {
|
|
24
|
-
name: item.name,
|
|
25
|
-
...(item.description === undefined ? {} : { description: item.description }),
|
|
26
|
-
inputSchema: schemas.inputSchema.jsonSchema,
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* The note the model reads beside `tool_search`: each server with deferred tools, how many, and
|
|
32
|
-
* its own instructions cut to `SERVER_INSTRUCTIONS_MAX_CHARS`.
|
|
33
|
-
*/
|
|
34
|
-
export function deferredToolsInstructions(servers) {
|
|
35
|
-
const lines = servers.map((server) => {
|
|
36
|
-
const head = `- ${server.serverName}: ${server.tools} tool${server.tools === 1 ? "" : "s"}`;
|
|
37
|
-
const text = server.instructions?.trim();
|
|
38
|
-
if (!text)
|
|
39
|
-
return head;
|
|
40
|
-
const cut = text.length > SERVER_INSTRUCTIONS_MAX_CHARS
|
|
41
|
-
? `${text.slice(0, SERVER_INSTRUCTIONS_MAX_CHARS)}…`
|
|
42
|
-
: text;
|
|
43
|
-
return `${head}. The server says: ${cut}`;
|
|
44
|
-
});
|
|
45
|
-
return [
|
|
46
|
-
"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.",
|
|
47
|
-
...lines,
|
|
48
|
-
].join("\n");
|
|
49
|
-
}
|
|
50
|
-
function searchTool() {
|
|
51
|
-
return tool({
|
|
52
|
-
name: TOOL_SEARCH_TOOL,
|
|
53
|
-
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.",
|
|
54
|
-
inputSchema: z.object({
|
|
55
|
-
query: z.string().min(1).describe("Words of what the tool does, or of its name."),
|
|
56
|
-
limit: z
|
|
57
|
-
.number()
|
|
58
|
-
.int()
|
|
59
|
-
.min(1)
|
|
60
|
-
.max(TOOL_SEARCH_MAX_LIMIT)
|
|
61
|
-
.optional()
|
|
62
|
-
.describe(`How many tools to return. Default ${TOOL_SEARCH_DEFAULT_LIMIT}.`),
|
|
63
|
-
}),
|
|
64
|
-
effects: "read",
|
|
65
|
-
execute: toolsRuntimeOnly,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
function callTool() {
|
|
69
|
-
return tool({
|
|
70
|
-
name: TOOL_CALL_TOOL,
|
|
71
|
-
description: "Run a tool tool_search found, by its name. arguments must match that tool's inputSchema; the result is the tool's own.",
|
|
72
|
-
inputSchema: z.object({
|
|
73
|
-
name: z.string().min(1).describe("The tool's name, as tool_search returned it."),
|
|
74
|
-
arguments: z
|
|
75
|
-
.record(z.string(), z.unknown())
|
|
76
|
-
.optional()
|
|
77
|
-
.describe("The tool's arguments, matching its inputSchema. Default {}."),
|
|
78
|
-
}),
|
|
79
|
-
effects: "write",
|
|
80
|
-
execute: toolsRuntimeOnly,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
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;
|
|
@@ -1,132 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
import type { ToolDefinition } from "../types/tool.js";
|
|
2
|
-
/** Instructions that come with a session's sandbox tools. */
|
|
3
|
-
export declare const SANDBOX_INSTRUCTIONS: string;
|
|
4
|
-
/** The six built-in sandbox tools. Schemas are part of the hashed manifest; change them deliberately. */
|
|
5
|
-
export declare function createSandboxTools(): readonly ToolDefinition[];
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { tool } from "./helpers.js";
|
|
3
|
-
import { ToolError } from "./tool-error.js";
|
|
4
|
-
import { SANDBOX_WORKSPACE } from "../utils/sandbox.js";
|
|
5
|
-
const PATH_NOTE = `Relative paths resolve under ${SANDBOX_WORKSPACE}.`;
|
|
6
|
-
/** Instructions that come with a session's sandbox tools. */
|
|
7
|
-
export const SANDBOX_INSTRUCTIONS = `You have an isolated Linux sandbox with a persistent working directory at ${SANDBOX_WORKSPACE}. ` +
|
|
8
|
-
"Use bash to run commands, read/write/edit to work with files, and grep/glob to search. " +
|
|
9
|
-
"Network egress is limited by policy; a failed download usually means the host is not allowed.";
|
|
10
|
-
/**
|
|
11
|
-
* Stub implementation for the developer process. The Runtime executes sandbox tools;
|
|
12
|
-
* reaching this means the agent ran without a Nylorun Runtime.
|
|
13
|
-
*/
|
|
14
|
-
async function runtimeOnly() {
|
|
15
|
-
throw new ToolError("sandbox.runtime-only", "Sandbox tools run in the Nylorun Runtime. Connect the agent to a Runtime (npx nylorun up, then npm run dev) to use them.");
|
|
16
|
-
}
|
|
17
|
-
/** The six built-in sandbox tools. Schemas are part of the hashed manifest; change them deliberately. */
|
|
18
|
-
export function createSandboxTools() {
|
|
19
|
-
return Object.freeze([
|
|
20
|
-
tool({
|
|
21
|
-
name: "bash",
|
|
22
|
-
description: `Run a bash command in the sandbox. The working directory is ${SANDBOX_WORKSPACE}. ` +
|
|
23
|
-
"Returns exitCode, stdout and stderr; a non-zero exit code is a normal result, not an error. " +
|
|
24
|
-
"Long output is truncated in the middle.",
|
|
25
|
-
inputSchema: z.object({
|
|
26
|
-
command: z.string().min(1).describe("The command line to run with bash."),
|
|
27
|
-
timeout: z
|
|
28
|
-
.number()
|
|
29
|
-
.int()
|
|
30
|
-
.min(1)
|
|
31
|
-
.max(600)
|
|
32
|
-
.optional()
|
|
33
|
-
.describe("Seconds before the command is killed. Default 120, maximum 600."),
|
|
34
|
-
}),
|
|
35
|
-
effects: "write",
|
|
36
|
-
execute: runtimeOnly,
|
|
37
|
-
}),
|
|
38
|
-
tool({
|
|
39
|
-
name: "read",
|
|
40
|
-
description: `Read a text file from the sandbox. ${PATH_NOTE} Returns numbered lines. ` +
|
|
41
|
-
"Use offset and limit to page through large files.",
|
|
42
|
-
inputSchema: z.object({
|
|
43
|
-
path: z.string().min(1),
|
|
44
|
-
offset: z
|
|
45
|
-
.number()
|
|
46
|
-
.int()
|
|
47
|
-
.min(1)
|
|
48
|
-
.optional()
|
|
49
|
-
.describe("First line to return, 1-based."),
|
|
50
|
-
limit: z
|
|
51
|
-
.number()
|
|
52
|
-
.int()
|
|
53
|
-
.min(1)
|
|
54
|
-
.max(5000)
|
|
55
|
-
.optional()
|
|
56
|
-
.describe("Maximum number of lines. Default 2000."),
|
|
57
|
-
}),
|
|
58
|
-
effects: "read",
|
|
59
|
-
execute: runtimeOnly,
|
|
60
|
-
}),
|
|
61
|
-
tool({
|
|
62
|
-
name: "write",
|
|
63
|
-
description: `Create or overwrite a text file in the sandbox. ${PATH_NOTE} Parent directories are created.`,
|
|
64
|
-
inputSchema: z.object({
|
|
65
|
-
path: z.string().min(1),
|
|
66
|
-
content: z.string(),
|
|
67
|
-
}),
|
|
68
|
-
effects: "write",
|
|
69
|
-
execute: runtimeOnly,
|
|
70
|
-
}),
|
|
71
|
-
tool({
|
|
72
|
-
name: "edit",
|
|
73
|
-
description: `Replace text in a sandbox file. ${PATH_NOTE} old_string must match exactly and be unique ` +
|
|
74
|
-
"unless replace_all is true.",
|
|
75
|
-
inputSchema: z.object({
|
|
76
|
-
path: z.string().min(1),
|
|
77
|
-
old_string: z.string().min(1),
|
|
78
|
-
new_string: z.string(),
|
|
79
|
-
replace_all: z.boolean().optional(),
|
|
80
|
-
}),
|
|
81
|
-
effects: "write",
|
|
82
|
-
execute: runtimeOnly,
|
|
83
|
-
}),
|
|
84
|
-
tool({
|
|
85
|
-
name: "grep",
|
|
86
|
-
description: `Search file contents in the sandbox with an extended regular expression. ${PATH_NOTE} ` +
|
|
87
|
-
"Returns matching lines as path:line:text.",
|
|
88
|
-
inputSchema: z.object({
|
|
89
|
-
pattern: z.string().min(1),
|
|
90
|
-
path: z.string().min(1).optional().describe(`Directory or file to search. Default ${SANDBOX_WORKSPACE}.`),
|
|
91
|
-
glob: z.string().min(1).optional().describe("Only search files whose name matches, e.g. \"*.py\"."),
|
|
92
|
-
ignore_case: z.boolean().optional(),
|
|
93
|
-
max_results: z.number().int().min(1).max(1000).optional().describe("Default 200."),
|
|
94
|
-
}),
|
|
95
|
-
effects: "read",
|
|
96
|
-
execute: runtimeOnly,
|
|
97
|
-
}),
|
|
98
|
-
tool({
|
|
99
|
-
name: "glob",
|
|
100
|
-
description: `Find files in the sandbox by glob pattern, e.g. "**/*.csv". ${PATH_NOTE} Returns matching paths.`,
|
|
101
|
-
inputSchema: z.object({
|
|
102
|
-
pattern: z.string().min(1),
|
|
103
|
-
path: z.string().min(1).optional().describe(`Directory to search. Default ${SANDBOX_WORKSPACE}.`),
|
|
104
|
-
}),
|
|
105
|
-
effects: "read",
|
|
106
|
-
execute: runtimeOnly,
|
|
107
|
-
}),
|
|
108
|
-
]);
|
|
109
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { AgentManifest, SkillManifest } from "../types/manifest.js";
|
|
2
|
-
import type { ToolDefinition } from "../types/tool.js";
|
|
3
|
-
import { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL } from "../utils/runtime-tools.js";
|
|
4
|
-
export { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL };
|
|
5
|
-
export declare const SKILL_TOOL_NAMES: ReadonlySet<string>;
|
|
6
|
-
/**
|
|
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.
|
|
9
|
-
*/
|
|
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;
|
|
18
|
-
/**
|
|
19
|
-
* `load_skill` for every skill of an agent, and `read_skill_resource` when a skill has files
|
|
20
|
-
* besides `SKILL.md`. Their names and input schemas are part of the hashed manifest; the Runtime
|
|
21
|
-
* runs them.
|
|
22
|
-
*/
|
|
23
|
-
export declare function createSkillTools(skills: ReadonlyMap<string, SkillManifest>): readonly ToolDefinition[];
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { SKILL_ENTRY } from "../utils/definition-files.js";
|
|
3
|
-
import { tool } from "./helpers.js";
|
|
4
|
-
import { ToolError } from "./tool-error.js";
|
|
5
|
-
import { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL } from "../utils/runtime-tools.js";
|
|
6
|
-
export { LOAD_SKILL_TOOL, READ_SKILL_RESOURCE_TOOL };
|
|
7
|
-
export const SKILL_TOOL_NAMES = new Set([
|
|
8
|
-
LOAD_SKILL_TOOL,
|
|
9
|
-
READ_SKILL_RESOURCE_TOOL,
|
|
10
|
-
]);
|
|
11
|
-
const USAGE = "Load the full instructions for a named skill. Call this before following a skill.";
|
|
12
|
-
/**
|
|
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.
|
|
15
|
-
*/
|
|
16
|
-
export function isSkillTool(manifest, toolName) {
|
|
17
|
-
return (toolName !== undefined &&
|
|
18
|
-
SKILL_TOOL_NAMES.has(toolName) &&
|
|
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('"', """);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Stub implementation for the developer process. The Runtime serves the skill tools from the
|
|
39
|
-
* skill files uploaded with the agent; reaching this means the agent ran without a Runtime.
|
|
40
|
-
*/
|
|
41
|
-
async function runtimeOnly() {
|
|
42
|
-
throw new ToolError("skills.runtime-only", "Skills are served by the Nylorun Runtime from the files uploaded with the agent. Connect the agent to a Runtime to use them.");
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* `load_skill` for every skill of an agent, and `read_skill_resource` when a skill has files
|
|
46
|
-
* besides `SKILL.md`. Their names and input schemas are part of the hashed manifest; the Runtime
|
|
47
|
-
* runs them.
|
|
48
|
-
*/
|
|
49
|
-
export function createSkillTools(skills) {
|
|
50
|
-
const names = [...skills.keys()].sort();
|
|
51
|
-
const nameSchema = names.length === 1
|
|
52
|
-
? z.literal(names[0])
|
|
53
|
-
: z.enum(names);
|
|
54
|
-
const definitions = [
|
|
55
|
-
tool({
|
|
56
|
-
name: LOAD_SKILL_TOOL,
|
|
57
|
-
description: USAGE,
|
|
58
|
-
inputSchema: z.object({ name: nameSchema }),
|
|
59
|
-
effects: "read",
|
|
60
|
-
execute: runtimeOnly,
|
|
61
|
-
}),
|
|
62
|
-
];
|
|
63
|
-
const hasResources = [...skills.values()].some((skill) => Object.keys(skill.files).some((path) => path !== SKILL_ENTRY));
|
|
64
|
-
if (hasResources)
|
|
65
|
-
definitions.push(tool({
|
|
66
|
-
name: READ_SKILL_RESOURCE_TOOL,
|
|
67
|
-
description: "Read one text resource from a skill after load_skill.",
|
|
68
|
-
inputSchema: z.object({
|
|
69
|
-
name: nameSchema,
|
|
70
|
-
path: z.string().min(1),
|
|
71
|
-
}),
|
|
72
|
-
effects: "read",
|
|
73
|
-
execute: runtimeOnly,
|
|
74
|
-
}));
|
|
75
|
-
return definitions;
|
|
76
|
-
}
|