@nylorun/harness 0.27.1-beta → 0.28.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 (65) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/HOST_CONTRACT.md +15 -13
  3. package/README.md +3 -1
  4. package/dist/api/executors.d.ts +79 -11
  5. package/dist/api/harness.d.ts +83 -2
  6. package/dist/api/harness.js +43 -4
  7. package/dist/api/host.d.ts +30 -2
  8. package/dist/api/host.js +156 -8
  9. package/dist/api/index.d.ts +20 -6
  10. package/dist/api/index.js +18 -4
  11. package/dist/api/run.d.ts +3 -0
  12. package/dist/api/run.js +81 -16
  13. package/dist/flow/context.d.ts +3 -0
  14. package/dist/flow/context.js +2 -1
  15. package/dist/flow/engine.d.ts +2 -0
  16. package/dist/flow/engine.js +10 -7
  17. package/dist/flow/limits.d.ts +8 -5
  18. package/dist/flow/limits.js +11 -7
  19. package/dist/index.d.ts +8 -0
  20. package/dist/index.js +8 -0
  21. package/dist/loop/compaction/config.d.ts +39 -0
  22. package/dist/loop/compaction/config.js +29 -0
  23. package/dist/loop/compaction/index.d.ts +18 -8
  24. package/dist/loop/compaction/index.js +57 -66
  25. package/dist/loop/config.d.ts +20 -0
  26. package/dist/loop/config.js +17 -0
  27. package/dist/loop/delegation.d.ts +3 -0
  28. package/dist/loop/delegation.js +14 -10
  29. package/dist/loop/invocation.d.ts +3 -0
  30. package/dist/loop/invocation.js +2 -0
  31. package/dist/loop/model/files.d.ts +77 -0
  32. package/dist/loop/model/files.js +168 -0
  33. package/dist/loop/model/json-answer.d.ts +26 -0
  34. package/dist/loop/model/json-answer.js +125 -0
  35. package/dist/loop/model/project.d.ts +14 -4
  36. package/dist/loop/model/project.js +69 -41
  37. package/dist/loop/options.js +2 -0
  38. package/dist/loop/run.js +8 -3
  39. package/dist/loop/state.js +4 -0
  40. package/dist/loop/step/run.js +19 -3
  41. package/dist/loop/step/runtime.d.ts +3 -0
  42. package/dist/run/durable.d.ts +51 -3
  43. package/dist/run/durable.js +71 -31
  44. package/dist/tools/artifacts.d.ts +33 -0
  45. package/dist/tools/artifacts.js +323 -0
  46. package/dist/tools/engine-tools.d.ts +42 -0
  47. package/dist/tools/engine-tools.js +26 -0
  48. package/dist/tools/mcp.d.ts +92 -0
  49. package/dist/tools/mcp.js +240 -0
  50. package/dist/tools/outputs.d.ts +23 -0
  51. package/dist/tools/outputs.js +193 -0
  52. package/dist/tools/results.d.ts +108 -0
  53. package/dist/tools/results.js +329 -0
  54. package/dist/tools/sandbox.d.ts +35 -0
  55. package/dist/tools/sandbox.js +129 -0
  56. package/dist/tools/skills.d.ts +94 -0
  57. package/dist/tools/skills.js +243 -0
  58. package/dist/tools/text-page.d.ts +20 -0
  59. package/dist/tools/text-page.js +64 -0
  60. package/dist/tools/tool-search.d.ts +56 -0
  61. package/dist/tools/tool-search.js +174 -0
  62. package/dist/tools/trace.d.ts +13 -0
  63. package/dist/tools/trace.js +34 -0
  64. package/dist/types/execution.d.ts +20 -0
  65. package/package.json +2 -2
@@ -0,0 +1,323 @@
1
+ /**
2
+ * Our engine's artifact tools (protocol 15), which run here, in the harness, over the Harness
3
+ * API's artifact seam (`artifact.read`, `artifact.write`) and the run's sandbox files:
4
+ *
5
+ * - `read_artifact` (every agent) reads an artifact the session may read in pages: a tool result
6
+ * the Runtime stored because it was too large to show, a file of an earlier turn. A text file
7
+ * comes back a page of at most `artifactPageBytes` at a time (escaped as JSON); any other file
8
+ * goes to the model as a file of the result when the turn's model reads it (`fileView`), and is
9
+ * `artifact.unsupported` when it does not. With
10
+ * a sandbox, `path` copies the artifact into the sandbox instead.
11
+ * - `save_artifact` (with a sandbox) saves a sandbox file, or text the model passes, as an
12
+ * artifact of the session. Its effect id is the write's key, so a write the harness repeats
13
+ * answers the version it wrote, and links the artifact to the call (`artifact.created` carries
14
+ * the call id).
15
+ *
16
+ * The model's tools are ours to name, describe and instruct; the Runtime decides what a run may
17
+ * read and write, and holds the limits. Expected problems (no such artifact, too large, not a
18
+ * file) are failed outcomes the model sees; only the run's own failures throw.
19
+ */
20
+ import { READ_ARTIFACT_TOOL, SANDBOX_WORKSPACE, SAVE_ARTIFACT_TOOL, } from "@nylorun/core/define";
21
+ import { ARTIFACT_NAME_MAX, DEFAULT_CONTENT_TYPE, contentTypeFor, essence, isText, normalizeContentType, } from "@nylorun/core/contracts";
22
+ import { HarnessApiError, fromBase64, openArtifactWrite, readArtifact, writeArtifactBytes, } from "@nylorun/core/harness-api";
23
+ import { textPage } from "./text-page.js";
24
+ import { fileView } from "../loop/model/files.js";
25
+ const ARTIFACTS_INSTRUCTIONS = "Use save_artifact to hand the user a file you made: a path in the sandbox, or text you pass as content. " +
26
+ "The user sees it as an artifact of this session and can download it; reply with its name, not its bytes. " +
27
+ "Files you write under /workspace/outputs reach the user too: when your turn ends, they become the session's outputs folder.";
28
+ const READ_ARTIFACT_INSTRUCTIONS = "A tool result too large to show is saved as an artifact of this session: the result says truncated: true, with its artifactId, its size in bytes and a preview of its start and end. " +
29
+ "Images and other files a tool returns are saved as artifacts too. Use read_artifact to read more of one, a page at a time, only when the preview is not enough. " +
30
+ '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.';
31
+ const SAVE_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. ` +
32
+ "Returns the artifact's id and version. Pass artifactId to save a new version of an artifact you saved before.";
33
+ const SAVE_SCHEMA = {
34
+ $schema: "http://json-schema.org/draft-07/schema#",
35
+ type: "object",
36
+ properties: {
37
+ path: { description: "A file in the sandbox.", type: "string", minLength: 1 },
38
+ content: { description: "Text to save instead of a file.", type: "string" },
39
+ name: {
40
+ description: "The artifact's name. Default: the file's name.",
41
+ type: "string",
42
+ minLength: 1,
43
+ maxLength: ARTIFACT_NAME_MAX,
44
+ },
45
+ contentType: {
46
+ description: "The media type, e.g. image/png. Default: from the name's extension.",
47
+ type: "string",
48
+ minLength: 1,
49
+ },
50
+ artifactId: {
51
+ description: "Save a new version of this artifact.",
52
+ type: "string",
53
+ minLength: 1,
54
+ },
55
+ },
56
+ additionalProperties: false,
57
+ };
58
+ function readDescription(pageBytes, sandboxed) {
59
+ return (`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 ${pageBytes} bytes from offset, ` +
60
+ "with nextOffset while more remains: pass it as offset to read on. An image or another file you can read is shown to you." +
61
+ (sandboxed
62
+ ? ` Pass path to copy the whole artifact into the sandbox instead (relative paths resolve under ${SANDBOX_WORKSPACE}), for a command to use.`
63
+ : ""));
64
+ }
65
+ function readSchema(pageBytes, sandboxed) {
66
+ return {
67
+ $schema: "http://json-schema.org/draft-07/schema#",
68
+ type: "object",
69
+ properties: {
70
+ artifactId: {
71
+ type: "string",
72
+ minLength: 1,
73
+ description: "The artifact to read, e.g. a truncated result's artifactId.",
74
+ },
75
+ version: {
76
+ description: "The version to read. Default: the latest.",
77
+ type: "integer",
78
+ minimum: 1,
79
+ maximum: Number.MAX_SAFE_INTEGER,
80
+ },
81
+ offset: {
82
+ description: "The byte to start at. Default 0.",
83
+ type: "integer",
84
+ minimum: 0,
85
+ maximum: Number.MAX_SAFE_INTEGER,
86
+ },
87
+ length: {
88
+ description: `How many bytes to read. Default and most: ${pageBytes}.`,
89
+ type: "integer",
90
+ minimum: 1,
91
+ maximum: pageBytes,
92
+ },
93
+ ...(sandboxed
94
+ ? {
95
+ path: {
96
+ description: "Copy the artifact to this file in the sandbox instead of reading it.",
97
+ type: "string",
98
+ minLength: 1,
99
+ },
100
+ }
101
+ : {}),
102
+ },
103
+ required: ["artifactId"],
104
+ additionalProperties: false,
105
+ };
106
+ }
107
+ /** True when `name` is one of our engine's artifact tools. */
108
+ export function isArtifactTool(name) {
109
+ return name === READ_ARTIFACT_TOOL || name === SAVE_ARTIFACT_TOOL;
110
+ }
111
+ const HARNESS = Object.freeze({ kind: "harness" });
112
+ /**
113
+ * The artifact tools our engine offers an agent: `save_artifact` when the session has a sandbox,
114
+ * and `read_artifact`, which takes `path` only then. Each runs here (`harness`).
115
+ */
116
+ export function artifactToolsFor(sandboxed, options) {
117
+ return [
118
+ ...(sandboxed
119
+ ? [
120
+ {
121
+ name: SAVE_ARTIFACT_TOOL,
122
+ description: SAVE_DESCRIPTION,
123
+ inputSchema: SAVE_SCHEMA,
124
+ target: HARNESS,
125
+ },
126
+ ]
127
+ : []),
128
+ {
129
+ name: READ_ARTIFACT_TOOL,
130
+ description: readDescription(options.pageBytes, sandboxed),
131
+ inputSchema: readSchema(options.pageBytes, sandboxed),
132
+ target: HARNESS,
133
+ },
134
+ ];
135
+ }
136
+ /** What the model reads with the artifact tools, in their order. */
137
+ export function artifactInstructions(sandboxed) {
138
+ return [...(sandboxed ? [ARTIFACTS_INSTRUCTIONS] : []), READ_ARTIFACT_INSTRUCTIONS];
139
+ }
140
+ const failed = (code, message) => ({
141
+ kind: "failed",
142
+ code,
143
+ message,
144
+ });
145
+ /** Runs a call of one of our engine's artifact tools, as its outcome. */
146
+ export async function runArtifactTool(effect, context) {
147
+ try {
148
+ return effect.toolName === SAVE_ARTIFACT_TOOL
149
+ ? await save(effect, context)
150
+ : await read(effect, context);
151
+ }
152
+ catch (error) {
153
+ // The seam's refusals are the model's to see; anything else is the run's.
154
+ if (error instanceof HarnessApiError) {
155
+ if (error.code === "not_found")
156
+ return failed("artifact.not_found", error.message);
157
+ if (error.code === "limit_exceeded")
158
+ return failed("artifact.too_large", error.message);
159
+ if (error.code === "invalid")
160
+ return failed("artifact.invalid_input", error.message);
161
+ }
162
+ throw error;
163
+ }
164
+ }
165
+ /** Whether the run's session has a sandbox (`turn.start.environment.sandbox`): its agents share it. */
166
+ function sandboxed(context) {
167
+ return context.files !== undefined && context.run.start.environment?.sandbox !== undefined;
168
+ }
169
+ function about(artifact) {
170
+ return {
171
+ artifactId: artifact.artifactId,
172
+ version: artifact.version,
173
+ name: artifact.name,
174
+ contentType: artifact.contentType,
175
+ size: artifact.size,
176
+ };
177
+ }
178
+ const isCount = (value, min) => typeof value === "number" && Number.isSafeInteger(value) && value >= min;
179
+ async function read(effect, context) {
180
+ const { channel, run, pageBytes, signal } = context;
181
+ const input = (effect.input ?? {});
182
+ const artifactId = typeof input.artifactId === "string" ? input.artifactId : "";
183
+ const wanted = input.version;
184
+ const offset = input.offset ?? 0;
185
+ const length = input.length ?? pageBytes;
186
+ const path = typeof input.path === "string" && input.path !== "" ? input.path : undefined;
187
+ if (artifactId === "" ||
188
+ (wanted !== undefined && !isCount(wanted, 1)) ||
189
+ !isCount(offset, 0) ||
190
+ !isCount(length, 1) ||
191
+ length > pageBytes)
192
+ return failed("artifact.invalid_input", `Give artifactId, a version of 1 or more if any, an offset of 0 or more, and a length of 1 to ${pageBytes}.`);
193
+ const chunkBytes = run.start.limits.chunkBytes;
194
+ const version = typeof wanted === "number" ? { version: wanted } : {};
195
+ if (path !== undefined) {
196
+ if (!sandboxed(context))
197
+ return failed("artifact.no_sandbox", "This session has no sandbox to copy an artifact into.");
198
+ const opened = await readArtifact(channel, {
199
+ runId: run.runId,
200
+ artifactId,
201
+ ...version,
202
+ chunkBytes,
203
+ signal,
204
+ });
205
+ if (opened.artifact.kind !== "file")
206
+ return failed("artifact.not_text", `${opened.artifact.name} is a folder; read_artifact reads a file.`);
207
+ const written = await context.files.write(run, path, opened.chunks(), signal);
208
+ if (written.kind === "failed")
209
+ return written;
210
+ return { kind: "completed", output: { ...about(opened.artifact), path: written.path } };
211
+ }
212
+ const answer = await channel.request("artifact.read", { runId: run.runId, artifactId, ...version, offset, length: Math.min(length, chunkBytes) }, signal);
213
+ const { artifact } = answer;
214
+ if (artifact.kind !== "file")
215
+ return failed("artifact.not_text", `${artifact.name} is a folder; read_artifact reads a file.`);
216
+ if (!isText(artifact.contentType)) {
217
+ // A file the turn's model reads goes to it beside the result (protocol 12); for one it does
218
+ // not, the model is told why (protocol 15).
219
+ const file = {
220
+ mediaType: artifact.contentType,
221
+ reference: {
222
+ artifactId: artifact.artifactId,
223
+ version: artifact.version,
224
+ name: artifact.name,
225
+ size: artifact.size,
226
+ },
227
+ };
228
+ const view = fileView(file, run.start.model, run.start.limits);
229
+ if (view.kind === "note")
230
+ return failed("artifact.unsupported", `${artifact.name} is ${essence(artifact.contentType)}: ${view.why}.`);
231
+ return { kind: "completed", output: about(artifact), files: [file] };
232
+ }
233
+ if (offset > artifact.size || (offset === artifact.size && artifact.size > 0))
234
+ return failed("artifact.invalid_input", `Offset ${offset} is past the end of ${artifact.name}, which is ${artifact.size} bytes.`);
235
+ const bytes = fromBase64(answer.base64);
236
+ const page = textPage(bytes, offset + bytes.byteLength >= artifact.size, pageBytes);
237
+ const next = offset + page.bytes;
238
+ return {
239
+ kind: "completed",
240
+ output: {
241
+ ...about(artifact),
242
+ offset,
243
+ content: page.text,
244
+ ...(next < artifact.size ? { nextOffset: next } : {}),
245
+ },
246
+ };
247
+ }
248
+ async function save(effect, context) {
249
+ const { channel, run, signal } = context;
250
+ const input = (effect.input ?? {});
251
+ const path = typeof input.path === "string" && input.path !== "" ? input.path : undefined;
252
+ const content = typeof input.content === "string" ? input.content : undefined;
253
+ if ((path === undefined) === (content === undefined))
254
+ return failed("artifact.invalid_input", "Give path or content, not both.");
255
+ if (path !== undefined && !sandboxed(context))
256
+ return failed("artifact.no_sandbox", "This session has no sandbox to read a path from.");
257
+ const artifactId = typeof input.artifactId === "string" ? input.artifactId : undefined;
258
+ const name = typeof input.name === "string" && input.name !== ""
259
+ ? input.name
260
+ : path !== undefined
261
+ ? basename(path)
262
+ : "artifact.txt";
263
+ let contentType;
264
+ if (typeof input.contentType === "string") {
265
+ const declared = normalizeContentType(input.contentType);
266
+ if (declared === undefined)
267
+ return failed("artifact.invalid_input", `${input.contentType} is not a media type.`);
268
+ contentType = declared;
269
+ }
270
+ else {
271
+ contentType = contentTypeFor(name);
272
+ if (content !== undefined && contentType === DEFAULT_CONTENT_TYPE)
273
+ contentType = "text/plain; charset=utf-8";
274
+ }
275
+ const options = {
276
+ runId: run.runId,
277
+ // The call is the write: a repeat of it answers the version it wrote.
278
+ key: effect.effectId,
279
+ effectId: effect.effectId,
280
+ ...(artifactId !== undefined ? { artifactId } : { name }),
281
+ contentType,
282
+ chunkBytes: run.start.limits.chunkBytes,
283
+ signal,
284
+ };
285
+ if (content !== undefined)
286
+ return saved(await writeArtifactBytes(channel, options, new TextEncoder().encode(content)));
287
+ const upload = await openArtifactWrite(channel, options);
288
+ if (upload.kind === "written")
289
+ return saved(upload);
290
+ try {
291
+ const file = await context.files.read(run, path, upload.maxBytes, signal);
292
+ if (file.kind !== "read") {
293
+ await upload.abort().catch(() => undefined);
294
+ return file.kind === "missing"
295
+ ? failed("artifact.not_found", `${file.path} does not exist in the sandbox.`)
296
+ : file;
297
+ }
298
+ await upload.write(file.bytes);
299
+ return saved(await upload.commit());
300
+ }
301
+ catch (error) {
302
+ await upload.abort().catch(() => undefined);
303
+ throw error;
304
+ }
305
+ }
306
+ function saved({ artifact }) {
307
+ return {
308
+ kind: "completed",
309
+ output: {
310
+ artifactId: artifact.artifactId,
311
+ version: artifact.version,
312
+ name: artifact.name,
313
+ contentType: artifact.contentType,
314
+ size: artifact.size,
315
+ sha256: artifact.sha256,
316
+ },
317
+ };
318
+ }
319
+ /** The last segment of a POSIX path. */
320
+ function basename(path) {
321
+ const trimmed = path.replace(/\/+$/, "");
322
+ return trimmed.slice(trimmed.lastIndexOf("/") + 1) || trimmed;
323
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * What our engine adds to each agent of a session (protocol 15): the model-facing text and tools
3
+ * that come with the session's Environment and the agent's skills. The Runtime states facts in
4
+ * `turn.start` (the Environment, its sandbox's workspace, the agent's skills); our engine words
5
+ * them and defines the tools, in one order, which keeps the prompt's prefix stable:
6
+ *
7
+ * - instructions: the skills' usage and catalog; the sandbox note; the skills' folder note;
8
+ * the artifact notes;
9
+ * - tools: the six sandbox tools; the skill tools; `save_artifact`; `read_artifact`.
10
+ *
11
+ * They come after the agent's own and before the session's MCP tools (`mcpToolSet`), and are
12
+ * not hashed.
13
+ */
14
+ import type { AgentManifest } from "@nylorun/core/define";
15
+ import type { TurnEnvironment } from "@nylorun/core/harness-api";
16
+ import type { DurableSessionTool } from "../run/durable.js";
17
+ import { type SandboxToolLimits } from "./sandbox.js";
18
+ import type { McpToolConfig } from "./mcp.js";
19
+ import type { ToolResultConfig } from "./results.js";
20
+ import type { OutputsConfig } from "./outputs.js";
21
+ /** The harness's configuration of our engine's own tools. */
22
+ export interface EngineToolOptions {
23
+ /** The most bytes one `read_artifact` page holds, escaped as JSON. */
24
+ readonly artifactPageBytes: number;
25
+ /** The sandbox tools' limits: their schemas' maxima and defaults. */
26
+ readonly sandboxTools: SandboxToolLimits;
27
+ /** The most bytes of one skill file the skill tools read into the model's context. */
28
+ readonly skillReadBytes: number;
29
+ /** How our engine names and defers the session's MCP tools, and `tool_search`'s limits. */
30
+ readonly mcpTools: McpToolConfig;
31
+ /** How our engine shapes tool results to fit the record: inline caps, previews, step budget. */
32
+ readonly toolResults: ToolResultConfig;
33
+ /** Where our engine finds a turn's outputs folder, and the most bytes it saves of it. */
34
+ readonly outputs: OutputsConfig;
35
+ }
36
+ /** Our engine's tools for one agent, and the text the model reads with them, in order. */
37
+ export interface EngineTools {
38
+ readonly tools: readonly DurableSessionTool[];
39
+ readonly instructions: readonly string[];
40
+ }
41
+ /** Our engine's tools and text for `agent`, in a session in `environment`. */
42
+ export declare function engineToolsFor(agent: Pick<AgentManifest, "skills">, environment: TurnEnvironment | undefined, options: Pick<EngineToolOptions, "artifactPageBytes" | "sandboxTools" | "skillReadBytes">): EngineTools;
@@ -0,0 +1,26 @@
1
+ import { artifactInstructions, artifactToolsFor } from "./artifacts.js";
2
+ import { sandboxInstructions, sandboxTools } from "./sandbox.js";
3
+ import { skillCatalogText, skillFolderNote, skillTools } from "./skills.js";
4
+ /** Our engine's tools and text for `agent`, in a session in `environment`. */
5
+ export function engineToolsFor(agent, environment, options) {
6
+ const skills = Object.values(agent.skills ?? {});
7
+ const workspace = environment?.sandbox?.workspace;
8
+ const sandboxed = workspace !== undefined;
9
+ const instructions = [];
10
+ if (skills.length > 0)
11
+ instructions.push(...skillCatalogText(skills));
12
+ if (sandboxed) {
13
+ instructions.push(sandboxInstructions(workspace));
14
+ if (skills.length > 0)
15
+ instructions.push(skillFolderNote(skills));
16
+ }
17
+ instructions.push(...artifactInstructions(sandboxed));
18
+ return {
19
+ tools: [
20
+ ...(sandboxed ? sandboxTools(options.sandboxTools, workspace) : []),
21
+ ...skillTools(skills),
22
+ ...artifactToolsFor(sandboxed, { pageBytes: options.artifactPageBytes }),
23
+ ],
24
+ instructions,
25
+ };
26
+ }
@@ -0,0 +1,92 @@
1
+ import { type AgentManifest } from "@nylorun/core/define";
2
+ import { MODEL_TOOL_NAME_MAX } from "@nylorun/core/define";
3
+ import type { McpFacts, ModelDescriptor } from "@nylorun/core/harness-api";
4
+ import type { DurableSessionTool } from "../run/durable.js";
5
+ export { MODEL_TOOL_NAME_MAX };
6
+ /** The harness's configuration of the MCP tools our engine offers. */
7
+ export interface McpToolConfig {
8
+ /**
9
+ * The share of the model's context window past which an agent's MCP tools are deferred, when
10
+ * the manifest does not say (Q21). Default 0.1.
11
+ */
12
+ readonly deferShare: number;
13
+ /** Characters per token, to estimate what tool definitions take of a context window. Default 4. */
14
+ readonly charsPerToken: number;
15
+ /**
16
+ * The context window, in tokens, assumed when the turn names no model (`turn.start.model`).
17
+ * Default 32,768, small, as for a custom endpoint.
18
+ */
19
+ readonly fallbackContextWindow: number;
20
+ /** How much of a server's own instructions the deferred tools' note shows. Default 2,000. */
21
+ readonly serverInstructionsMaxChars: number;
22
+ /** How many tools `tool_search` returns when the model sets no `limit`. Default 8. */
23
+ readonly toolSearchDefaultLimit: number;
24
+ /** The most tools one `tool_search` returns. Default 20. */
25
+ readonly toolSearchMaxLimit: number;
26
+ }
27
+ export declare const DEFAULT_MCP_TOOL_CONFIG: McpToolConfig;
28
+ /** `set` over the defaults. */
29
+ export declare function mcpToolConfigOf(set?: Partial<McpToolConfig>): McpToolConfig;
30
+ /**
31
+ * The name the model knows an MCP tool by (R2b C6, Q13): `server__tool` with each character
32
+ * outside `[A-Za-z0-9_-]` replaced by `_`. A name over 64 characters, or one that collides
33
+ * (`suffixed`), keeps 55 and adds `_` and 8 hex characters of the SHA-256 of the raw
34
+ * `server/tool`.
35
+ */
36
+ export declare function mcpToolName(server: string, tool: string, options?: {
37
+ readonly suffixed?: boolean;
38
+ }): string;
39
+ /** A tool whose model-facing name is not `server__tool`. */
40
+ export interface McpRenamedTool {
41
+ readonly serverToolName: string;
42
+ readonly name: string;
43
+ }
44
+ /**
45
+ * The model-facing names of a server's tools (`tools`, raw names, in the server's order), and
46
+ * those it renamed or left out. Names that need no change go first, so a renamed tool never takes
47
+ * the name of another of the server's tools; a renamed one that collides gets the hash suffix;
48
+ * a name `taken` holds (the agent's own tools, an earlier server's tools) leaves the tool out.
49
+ * Adds the names it gives to `taken`.
50
+ */
51
+ export declare function mcpToolNames(server: string, tools: readonly string[], taken: Set<string>): {
52
+ names: Map<string, string>;
53
+ renamed: McpRenamedTool[];
54
+ omitted: string[];
55
+ };
56
+ /**
57
+ * The deferral our engine decided for a session's MCP tools (R2b C10): the identities of the
58
+ * deferred ones (`mcpToolKey`), for the facts whose hash is `factsHash`. Kept in our engine's
59
+ * state, so the session keeps it while its facts stay the same.
60
+ */
61
+ export interface McpLayout {
62
+ readonly factsHash: string;
63
+ readonly deferred: readonly string[];
64
+ }
65
+ /** The key of an MCP tool's identity in a layout: its agent, server and own name. */
66
+ export declare function mcpToolKey(agentId: string | undefined, server: string, tool: string): string;
67
+ /** The session's MCP tools as our engine offers them, for one run. */
68
+ export interface McpToolSet {
69
+ /**
70
+ * Every agent's MCP tools in the model's order: the listed ones, then for each agent with
71
+ * deferred tools `tool_search` (with the note on its servers), `tool_call` and the deferred
72
+ * ones (`deferred: true`). An agent used as a tool's carry its `agentId`.
73
+ */
74
+ readonly tools: readonly DurableSessionTool[];
75
+ /** The layout these tools follow: the one given, or the one decided now. */
76
+ readonly layout: McpLayout;
77
+ /** The deferred tools of an agent (`agentId` absent for the root), which `tool_search` searches. */
78
+ deferredOf(agentId: string | undefined): readonly DurableSessionTool[];
79
+ }
80
+ /**
81
+ * The session's MCP tools from the turn's facts (`turn.start.mcp`) for the agent tree `manifest`.
82
+ * `layout` is the one our engine's state keeps: followed while its `factsHash` matches, else the
83
+ * deferral is decided again from the model's window (`model.contextWindow`, or
84
+ * `config.fallbackContextWindow`). `taken(agent)` names an agent's other tools (our engine's
85
+ * own), which an MCP tool's name may not take besides the agent's declared tools.
86
+ */
87
+ export declare function mcpToolSet(facts: McpFacts | undefined, manifest: AgentManifest, options: {
88
+ readonly config: McpToolConfig;
89
+ readonly model?: ModelDescriptor;
90
+ readonly layout?: McpLayout;
91
+ readonly taken?: (agent: AgentManifest) => readonly string[];
92
+ }): McpToolSet;