@nylorun/core 0.21.0-beta → 0.23.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/README.md +1 -1
  3. package/dist/compatibility.d.ts +37 -20
  4. package/dist/compatibility.js +38 -21
  5. package/dist/contracts.d.ts +531 -88
  6. package/dist/contracts.js +315 -204
  7. package/dist/define.d.ts +8 -12
  8. package/dist/define.js +7 -11
  9. package/dist/definition/assemble.d.ts +1 -3
  10. package/dist/definition/assemble.js +4 -8
  11. package/dist/definition/bound.d.ts +1 -1
  12. package/dist/definition/delegate.d.ts +5 -0
  13. package/dist/definition/delegate.js +6 -1
  14. package/dist/definition/from.d.ts +4 -2
  15. package/dist/definition/from.js +11 -29
  16. package/dist/definition/http-tool.d.ts +54 -8
  17. package/dist/definition/http-tool.js +175 -10
  18. package/dist/definition/manifest.d.ts +7 -6
  19. package/dist/definition/manifest.js +7 -6
  20. package/dist/definition/mcp.d.ts +1 -1
  21. package/dist/definition/media-reference.d.ts +2 -11
  22. package/dist/definition/media-reference.js +0 -12
  23. package/dist/definition/model-failure.js +1 -0
  24. package/dist/definition/removed.js +1 -0
  25. package/dist/definition/trace.d.ts +0 -7
  26. package/dist/definition/trace.js +0 -34
  27. package/dist/definition/variant.d.ts +1 -1
  28. package/dist/definition/variant.js +1 -3
  29. package/dist/harness-api/artifacts.d.ts +84 -0
  30. package/dist/harness-api/artifacts.js +128 -0
  31. package/dist/harness-api/gates.d.ts +0 -4
  32. package/dist/harness-api/gates.js +0 -4
  33. package/dist/harness-api/harness-api.schema.json +2422 -924
  34. package/dist/harness-api/index.d.ts +9 -6
  35. package/dist/harness-api/index.js +9 -6
  36. package/dist/harness-api/json-schema.js +5 -2
  37. package/dist/harness-api/mcp.d.ts +77 -30
  38. package/dist/harness-api/mcp.js +42 -25
  39. package/dist/harness-api/messages.d.ts +45 -17
  40. package/dist/harness-api/messages.js +20 -5
  41. package/dist/harness-api/schema.d.ts +538 -198
  42. package/dist/harness-api/schema.js +298 -59
  43. package/dist/harness-api/transcript.d.ts +8 -10
  44. package/dist/harness-api/transcript.js +27 -11
  45. package/dist/harness-api/transport.d.ts +7 -1
  46. package/dist/harness-api/transport.js +10 -7
  47. package/dist/manifest-schemas.js +14 -2
  48. package/dist/schemas/agent-manifest.schema.json +14 -147
  49. package/dist/schemas/environment-manifest.schema.json +76 -16
  50. package/dist/types/manifest.d.ts +17 -18
  51. package/dist/types/model.d.ts +10 -5
  52. package/dist/utils/definition-files.d.ts +20 -6
  53. package/dist/utils/definition-files.js +31 -17
  54. package/dist/utils/file-systems.d.ts +20 -0
  55. package/dist/utils/file-systems.js +20 -0
  56. package/dist/utils/harness-id.d.ts +4 -1
  57. package/dist/utils/harness-id.js +4 -1
  58. package/dist/utils/media-types.d.ts +30 -0
  59. package/dist/utils/media-types.js +128 -0
  60. package/dist/utils/runtime-limits.d.ts +229 -0
  61. package/dist/utils/runtime-limits.js +482 -0
  62. package/dist/utils/runtime-tools.d.ts +8 -16
  63. package/dist/utils/runtime-tools.js +8 -27
  64. package/dist/utils/sandbox.d.ts +4 -1
  65. package/dist/utils/sandbox.js +4 -1
  66. package/package.json +1 -1
  67. package/dist/definition/deferred-tools.d.ts +0 -27
  68. package/dist/definition/deferred-tools.js +0 -82
  69. package/dist/definition/runtime-manifest.d.ts +0 -30
  70. package/dist/definition/runtime-manifest.js +0 -132
  71. package/dist/definition/sandbox-tools.d.ts +0 -5
  72. package/dist/definition/sandbox-tools.js +0 -109
  73. package/dist/definition/skill-tools.d.ts +0 -23
  74. package/dist/definition/skill-tools.js +0 -76
@@ -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("&", "&amp;")
33
- .replaceAll("<", "&lt;")
34
- .replaceAll(">", "&gt;")
35
- .replaceAll('"', "&quot;");
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
- }