@nylorun/core 0.20.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 +76 -0
- package/README.md +2 -2
- package/dist/compatibility.d.ts +84 -10
- package/dist/compatibility.js +84 -10
- package/dist/contracts.d.ts +1328 -110
- package/dist/contracts.js +544 -157
- package/dist/define.d.ts +14 -12
- package/dist/define.js +10 -7
- package/dist/definition/approval.js +12 -14
- 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 +3 -3
- package/dist/definition/code-tools.js +6 -21
- 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/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/implementations.d.ts +6 -8
- package/dist/definition/manifest.d.ts +11 -5
- package/dist/definition/manifest.js +26 -26
- package/dist/definition/mcp.d.ts +1 -52
- package/dist/definition/mcp.js +0 -52
- 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 +18 -51
- package/dist/definition/workflow/runnable.js +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/harness-api/entries.d.ts +1 -0
- package/dist/harness-api/entries.js +1 -0
- package/dist/harness-api/gates.d.ts +1 -6
- package/dist/harness-api/gates.js +1 -3
- package/dist/harness-api/harness-api.schema.json +11 -92
- package/dist/harness-api/index.d.ts +2 -2
- package/dist/harness-api/index.js +2 -2
- package/dist/harness-api/mcp.d.ts +0 -4
- package/dist/harness-api/mcp.js +0 -2
- package/dist/harness-api/messages.d.ts +1 -3
- package/dist/harness-api/messages.js +1 -3
- package/dist/harness-api/schema.d.ts +5 -17
- package/dist/harness-api/schema.js +9 -6
- 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 +33 -19
- package/dist/types/model.d.ts +2 -2
- package/dist/types/observe.d.ts +5 -18
- 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/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 +9 -3
- 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
|
@@ -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;
|
|
@@ -8,7 +8,7 @@ function toolsByName(tools) {
|
|
|
8
8
|
map.set(tool.name, tool);
|
|
9
9
|
return map;
|
|
10
10
|
}
|
|
11
|
-
/** Candidate tools
|
|
11
|
+
/** Candidate tools (agents used as tools included) may only be removed, never added or changed. */
|
|
12
12
|
function removeOnlyTools(pinned, candidate) {
|
|
13
13
|
const base = toolsByName(pinned);
|
|
14
14
|
for (const tool of candidate ?? []) {
|
|
@@ -18,15 +18,6 @@ function removeOnlyTools(pinned, candidate) {
|
|
|
18
18
|
}
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
|
-
function removeOnlySkills(pinned, candidate) {
|
|
22
|
-
const base = pinned ?? {};
|
|
23
|
-
for (const [name, skill] of Object.entries(candidate ?? {})) {
|
|
24
|
-
const prior = base[name];
|
|
25
|
-
if (!prior || !same(prior, skill))
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
21
|
/**
|
|
31
22
|
* One tool setting, or the `"*"` entry, only tightened (R2b C9, Q18): `enabled` kept or set to
|
|
32
23
|
* `false`, `approval` and `deferred` kept. Each level of a tool's resolution (its entry, then
|
|
@@ -63,51 +54,27 @@ function tightensServers(pinned, candidate) {
|
|
|
63
54
|
});
|
|
64
55
|
}
|
|
65
56
|
/**
|
|
66
|
-
* Whether `candidate` is a valid turn-manifest variant of the session's pinned
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
57
|
+
* Whether `candidate` is a valid turn-manifest variant of the session's pinned manifest
|
|
58
|
+
* (`loops.md` §3.4). A variant may remove tools (agents used as tools and HTTP tools included),
|
|
59
|
+
* tighten its MCP servers' tool settings (R2b C9, Q18), and change its instructions, name,
|
|
60
|
+
* description and metadata. Its skills and servers are setup: the sandbox holds the skills from
|
|
61
|
+
* the session's start. It never sets `runtime`; the turn runs with the pin's.
|
|
70
62
|
*/
|
|
71
63
|
export function isVariantOf(candidate, pinned) {
|
|
72
64
|
if (candidate.id !== pinned.id)
|
|
73
65
|
return false;
|
|
74
|
-
|
|
75
|
-
if (candidate.manifestSchemaVersion < pinned.manifestSchemaVersion)
|
|
66
|
+
if (candidate.manifestSchemaVersion !== pinned.manifestSchemaVersion)
|
|
76
67
|
return false;
|
|
77
|
-
if (
|
|
68
|
+
if (candidate.runtime !== undefined)
|
|
78
69
|
return false;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!next || !same(next.sandbox, prior.sandbox))
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
for (const [id, next] of candidateById) {
|
|
94
|
-
const prior = pinnedById.get(id);
|
|
95
|
-
if (!prior)
|
|
96
|
-
return false; // cannot add capabilities
|
|
97
|
-
if (next.type !== prior.type)
|
|
98
|
-
return false;
|
|
99
|
-
if (!removeOnlyTools(prior.tools, next.tools))
|
|
100
|
-
return false;
|
|
101
|
-
if (!removeOnlySkills(prior.skills, next.skills))
|
|
102
|
-
return false;
|
|
103
|
-
// Free: name, description, metadata, instructions (and model once it exists).
|
|
104
|
-
if (!tightensServers(prior.mcpServers, next.mcpServers))
|
|
105
|
-
return false;
|
|
106
|
-
if (!same(next.sandbox, prior.sandbox))
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
// Dropping a capability is allowed only when it had no MCP / sandbox
|
|
110
|
-
// (those are enforced above). Tools and skills on a dropped capability are
|
|
111
|
-
// removals, which §3.4 permits.
|
|
112
|
-
return true;
|
|
70
|
+
if (!same(candidate.outputSchema, pinned.outputSchema))
|
|
71
|
+
return false;
|
|
72
|
+
// What the agent needs of its Environment was checked when the session opened (D65).
|
|
73
|
+
if (!same(candidate.requires, pinned.requires))
|
|
74
|
+
return false;
|
|
75
|
+
if (!removeOnlyTools(pinned.tools, candidate.tools))
|
|
76
|
+
return false;
|
|
77
|
+
if (!same(candidate.skills, pinned.skills))
|
|
78
|
+
return false;
|
|
79
|
+
return tightensServers(pinned.mcpServers, candidate.mcpServers);
|
|
113
80
|
}
|
|
@@ -60,7 +60,7 @@ export function bindToolNode(tool) {
|
|
|
60
60
|
execute: execute.bind(normalized),
|
|
61
61
|
...(normalized.approval === undefined ? {} : { approval: normalized.approval }),
|
|
62
62
|
...(normalized.effects === undefined ? {} : { effects: normalized.effects }),
|
|
63
|
-
owner: Object.freeze({
|
|
63
|
+
owner: Object.freeze({ partId: "workflow", slot: "tool-node" }),
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
/** Normalize a schema for a workflow tool node (any JSON Schema root type allowed). */
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Machine-readable error raised by Harness-owned code. */
|
|
2
|
-
export type HarnessErrorCode = "execution.invalid-state" | "execution.invalid-input" | "execution.incompatible" | "execution.record-failed" | "tool.unregistered" | "tool.invalid-binding" | "agent.build-failed" | "agent.lifecycle-sealed" | "context.invalid-item" | "context.invalid-item-type" | "context.invalid-order" | "context.invalid-reason" | "context.invalid-slot" | "interaction.invalid" | "interaction.missing-resume" | "interaction.uncorrelated-resume" | "input.invalid-content" | "output.invalid" | "output.invalid-schema" | "json.invalid-data" | "json.invalid-object" | "
|
|
2
|
+
export type HarnessErrorCode = "execution.invalid-state" | "execution.invalid-input" | "execution.incompatible" | "execution.record-failed" | "tool.unregistered" | "tool.invalid-binding" | "agent.build-failed" | "agent.lifecycle-sealed" | "context.invalid-item" | "context.invalid-item-type" | "context.invalid-order" | "context.invalid-reason" | "context.invalid-slot" | "interaction.invalid" | "interaction.missing-resume" | "interaction.uncorrelated-resume" | "input.invalid-content" | "output.invalid" | "output.invalid-schema" | "json.invalid-data" | "json.invalid-object" | "model.candidate-missing" | "model.adapter-invalid-options" | "model.adapter-invalid-response" | "model.invalid-candidate" | "model.invalid-directive" | "model.unsupported-content" | "model.unsupported-output-schema"
|
|
3
3
|
/** A provider failure the model adapter classified (Model Calls §6.1). */
|
|
4
4
|
| `model.${import("./types/model.js").ModelFailureCode}` | "configuration.duplicate-tool-name" | "configuration.invalid" | "configuration.invalid-instructions" | "configuration.invalid-order" | "configuration.invalid-reason" | "configuration.invalid-slot" | "configuration.invalid-tools" | "configuration.model-selection-conflict" | "response.invalid-replacement" | "tool.invalid" | "tool.invalid-arguments" | "tool.invalid-output" | "tool.invalid-name" | "tool.invalid-schema" | "tool.invalid-tool-result";
|
|
5
5
|
export type HarnessErrorDetails = Readonly<Record<string, string | number | boolean>>;
|
|
@@ -229,6 +229,7 @@ export declare const TranscriptEntrySchema: z.ZodDiscriminatedUnion<[z.ZodObject
|
|
|
229
229
|
}>;
|
|
230
230
|
tokensBefore: z.ZodNumber;
|
|
231
231
|
tokensAfter: z.ZodNumber;
|
|
232
|
+
files: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
232
233
|
}, z.core.$strip>], "kind">;
|
|
233
234
|
/** The prefix every effect id of a segment carries. */
|
|
234
235
|
export declare function effectIdPrefix(turnId: string, segment: number): string;
|
|
@@ -98,6 +98,7 @@ export const TranscriptEntrySchema = z.discriminatedUnion("kind", [
|
|
|
98
98
|
trigger: z.enum(["threshold", "overflow"]),
|
|
99
99
|
tokensBefore: z.number(),
|
|
100
100
|
tokensAfter: z.number(),
|
|
101
|
+
files: z.array(z.string()).optional(),
|
|
101
102
|
}),
|
|
102
103
|
]);
|
|
103
104
|
/** The prefix every effect id of a segment carries. */
|
|
@@ -81,7 +81,6 @@ export type GateErrorBody = z.infer<typeof GateErrorBodySchema>;
|
|
|
81
81
|
export declare const McpServerRefSchema: z.ZodObject<{
|
|
82
82
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
83
83
|
agentId: z.ZodOptional<z.ZodString>;
|
|
84
|
-
capabilityId: z.ZodString;
|
|
85
84
|
serverName: z.ZodString;
|
|
86
85
|
}, z.core.$strip>;
|
|
87
86
|
export type McpServerRef = z.infer<typeof McpServerRefSchema>;
|
|
@@ -90,7 +89,6 @@ export declare const McpServerBodySchema: z.ZodObject<{
|
|
|
90
89
|
server: z.ZodObject<{
|
|
91
90
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
92
91
|
agentId: z.ZodOptional<z.ZodString>;
|
|
93
|
-
capabilityId: z.ZodString;
|
|
94
92
|
serverName: z.ZodString;
|
|
95
93
|
}, z.core.$strip>;
|
|
96
94
|
}, z.core.$strip>;
|
|
@@ -99,7 +97,6 @@ export declare const McpListBodySchema: z.ZodObject<{
|
|
|
99
97
|
server: z.ZodObject<{
|
|
100
98
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
101
99
|
agentId: z.ZodOptional<z.ZodString>;
|
|
102
|
-
capabilityId: z.ZodString;
|
|
103
100
|
serverName: z.ZodString;
|
|
104
101
|
}, z.core.$strip>;
|
|
105
102
|
cursor: z.ZodOptional<z.ZodString>;
|
|
@@ -109,7 +106,6 @@ export declare const ToolCallBodySchema: z.ZodObject<{
|
|
|
109
106
|
server: z.ZodObject<{
|
|
110
107
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
111
108
|
agentId: z.ZodOptional<z.ZodString>;
|
|
112
|
-
capabilityId: z.ZodString;
|
|
113
109
|
serverName: z.ZodString;
|
|
114
110
|
}, z.core.$strip>;
|
|
115
111
|
effectId: z.ZodString;
|
|
@@ -118,7 +114,7 @@ export declare const ToolCallBodySchema: z.ZodObject<{
|
|
|
118
114
|
}, z.core.$strip>;
|
|
119
115
|
export type ToolCallBody = z.infer<typeof ToolCallBodySchema>;
|
|
120
116
|
/**
|
|
121
|
-
* `http-calls`: one call of an HTTP tool, named by its agent
|
|
117
|
+
* `http-calls`: one call of an HTTP tool, named by its agent and tool, or a flow's
|
|
122
118
|
* HTTP stage or verifier by its stage key. The gate finds its URL, method and credential in the
|
|
123
119
|
* session's pinned manifest. A run token's turn is the call's; `turnId` counts only under core's
|
|
124
120
|
* credential.
|
|
@@ -127,7 +123,6 @@ export declare const HttpCallBodySchema: z.ZodObject<{
|
|
|
127
123
|
tool: z.ZodUnion<readonly [z.ZodObject<{
|
|
128
124
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
129
125
|
agentId: z.ZodOptional<z.ZodString>;
|
|
130
|
-
capabilityId: z.ZodString;
|
|
131
126
|
toolName: z.ZodString;
|
|
132
127
|
}, z.core.$strip>, z.ZodObject<{
|
|
133
128
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
@@ -66,7 +66,6 @@ export const McpServerRefSchema = z.object({
|
|
|
66
66
|
sessionId: z.string().min(1).optional(),
|
|
67
67
|
/** The agent used as a tool that declares the server; absent for the session's root agent. */
|
|
68
68
|
agentId: z.string().min(1).optional(),
|
|
69
|
-
capabilityId: z.string().min(1),
|
|
70
69
|
serverName: z.string().min(1),
|
|
71
70
|
});
|
|
72
71
|
/** `mcp/connect` and `mcp/close`. */
|
|
@@ -84,7 +83,7 @@ export const ToolCallBodySchema = z.object({
|
|
|
84
83
|
arguments: z.record(z.string(), z.unknown()),
|
|
85
84
|
});
|
|
86
85
|
/**
|
|
87
|
-
* `http-calls`: one call of an HTTP tool, named by its agent
|
|
86
|
+
* `http-calls`: one call of an HTTP tool, named by its agent and tool, or a flow's
|
|
88
87
|
* HTTP stage or verifier by its stage key. The gate finds its URL, method and credential in the
|
|
89
88
|
* session's pinned manifest. A run token's turn is the call's; `turnId` counts only under core's
|
|
90
89
|
* credential.
|
|
@@ -94,7 +93,6 @@ export const HttpCallBodySchema = z.object({
|
|
|
94
93
|
z.object({
|
|
95
94
|
sessionId: z.string().min(1).optional(),
|
|
96
95
|
agentId: z.string().min(1).optional(),
|
|
97
|
-
capabilityId: z.string().min(1),
|
|
98
96
|
toolName: z.string().min(1),
|
|
99
97
|
}),
|
|
100
98
|
z.object({
|