operon-agents-core 0.1.0-alpha.20 → 0.1.0-alpha.22
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.
|
@@ -8,7 +8,9 @@ export function computeContextBreakdown(input) {
|
|
|
8
8
|
let builtinTools = 0;
|
|
9
9
|
let mcpTools = 0;
|
|
10
10
|
for (const tool of input.tools) {
|
|
11
|
-
|
|
11
|
+
// What goes on the wire: `outputSchema` is for programs calling the tool, never sent to the model.
|
|
12
|
+
const { outputSchema: _programOnly, ...sent } = tool.schema;
|
|
13
|
+
const tokens = estimateTokens(JSON.stringify(sent));
|
|
12
14
|
if (isMcpToolName(tool.schema.name))
|
|
13
15
|
mcpTools += tokens;
|
|
14
16
|
else
|
package/dist/mcp/provider.js
CHANGED
|
@@ -2,6 +2,9 @@ import { ToolAccesses } from "../index.js";
|
|
|
2
2
|
import { applyMcpToolFilter } from "./filter.js";
|
|
3
3
|
import { qualifyMcpToolName } from "./tool-naming.js";
|
|
4
4
|
import { mcpResultToContent } from "./output.js";
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7
|
+
}
|
|
5
8
|
function asArgs(raw) {
|
|
6
9
|
return raw !== null && typeof raw === "object" ? raw : null;
|
|
7
10
|
}
|
|
@@ -20,6 +23,7 @@ export function wrapMcpTool(server, def) {
|
|
|
20
23
|
name: qualifiedName,
|
|
21
24
|
description: def.description ?? `MCP tool "${rawName}" from server "${server.name}".`,
|
|
22
25
|
parameters: def.inputSchema ?? { type: "object", properties: {} },
|
|
26
|
+
...(isRecord(def.outputSchema) ? { outputSchema: def.outputSchema } : {}),
|
|
23
27
|
},
|
|
24
28
|
resolve: (rawArgs) => {
|
|
25
29
|
const args = asArgs(rawArgs);
|
|
@@ -32,7 +36,7 @@ export function wrapMcpTool(server, def) {
|
|
|
32
36
|
try {
|
|
33
37
|
const result = await server.callTool(rawName, args, { signal: ctx.signal });
|
|
34
38
|
const { content, isError } = mcpResultToContent(result, qualifiedName);
|
|
35
|
-
return { content, isError };
|
|
39
|
+
return { content, isError, ...(result.structuredContent !== undefined ? { structured: result.structuredContent } : {}) };
|
|
36
40
|
}
|
|
37
41
|
catch (error) {
|
|
38
42
|
const text = await defaultErrorText(server, rawName, error);
|
package/dist/mcp/types.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export interface MCPTool {
|
|
|
2
2
|
readonly name: string;
|
|
3
3
|
readonly description?: string;
|
|
4
4
|
readonly inputSchema?: Record<string, unknown>;
|
|
5
|
+
/** JSON Schema of `structuredContent` in this tool's results, when the server declares one. */
|
|
6
|
+
readonly outputSchema?: Record<string, unknown>;
|
|
5
7
|
readonly [key: string]: unknown;
|
|
6
8
|
}
|
|
7
9
|
export interface MCPContentBlock {
|
|
@@ -21,6 +23,8 @@ export interface MCPContentBlock {
|
|
|
21
23
|
}
|
|
22
24
|
export interface MCPToolResult {
|
|
23
25
|
readonly content: readonly MCPContentBlock[];
|
|
26
|
+
/** The result as JSON, conforming to the tool's `outputSchema`. */
|
|
27
|
+
readonly structuredContent?: unknown;
|
|
24
28
|
readonly isError?: boolean;
|
|
25
29
|
readonly [key: string]: unknown;
|
|
26
30
|
}
|
|
@@ -2,5 +2,11 @@ export interface ToolSchema {
|
|
|
2
2
|
readonly name: string;
|
|
3
3
|
readonly description: string;
|
|
4
4
|
readonly parameters: Readonly<Record<string, unknown>>;
|
|
5
|
+
/**
|
|
6
|
+
* JSON Schema of the tool's machine-readable result ({@link ToolResult.structured}), when it
|
|
7
|
+
* has one (an MCP tool that declares `outputSchema`). Never sent to the model: it is the
|
|
8
|
+
* contract for a program calling the tool (Code Mode), which receives the value instead of text.
|
|
9
|
+
*/
|
|
10
|
+
readonly outputSchema?: Readonly<Record<string, unknown>>;
|
|
5
11
|
}
|
|
6
12
|
//# sourceMappingURL=tool-schema.d.ts.map
|
|
@@ -32,6 +32,30 @@ const READS_ALL_ARGS = new Set([
|
|
|
32
32
|
"cat", "head", "tail", "less", "more", "wc", "file", "stat", "nl", "od", "xxd", "strings",
|
|
33
33
|
"base64", "md5sum", "sha1sum", "sha256sum", "shasum", "cmp", "diff", "sort", "readlink",
|
|
34
34
|
]);
|
|
35
|
+
/**
|
|
36
|
+
* Options of the read commands above that take a value as the next word (`head -n 100`), so
|
|
37
|
+
* the value is not mistaken for a file. A value glued to its option (`-n100`) is one word and
|
|
38
|
+
* already dropped as an option.
|
|
39
|
+
*/
|
|
40
|
+
const OPTION_VALUES = {
|
|
41
|
+
head: new Set(["-n", "-c", "--lines", "--bytes"]),
|
|
42
|
+
tail: new Set(["-n", "-c", "--lines", "--bytes", "-s", "--sleep-interval", "--pid"]),
|
|
43
|
+
sort: new Set(["-k", "-t", "-S", "-T", "--key", "--field-separator", "--buffer-size", "--temporary-directory"]),
|
|
44
|
+
nl: new Set(["-b", "-d", "-f", "-h", "-i", "-l", "-n", "-s", "-v", "-w"]),
|
|
45
|
+
od: new Set(["-A", "-j", "-N", "-t", "-w"]),
|
|
46
|
+
xxd: new Set(["-c", "-g", "-l", "-o", "-s"]),
|
|
47
|
+
strings: new Set(["-n", "-t", "-e"]),
|
|
48
|
+
base64: new Set(["-w", "--wrap"]),
|
|
49
|
+
diff: new Set(["-U", "-C", "-L", "--label", "-I", "--ignore-matching-lines"]),
|
|
50
|
+
cmp: new Set(["-i", "-n", "--ignore-initial", "--bytes"]),
|
|
51
|
+
shasum: new Set(["-a", "--algorithm"]),
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Character and stream devices a command reads or writes without touching a file: `2>/dev/null`
|
|
55
|
+
* is how a command discards its errors, not a write outside the workspace. Reporting them would
|
|
56
|
+
* prompt for exactly the most common harmless redirect.
|
|
57
|
+
*/
|
|
58
|
+
const STREAM_DEVICE = /^\/dev\/(?:null|zero|u?random|stdin|stdout|stderr|tty|fd\/\d+)$/;
|
|
35
59
|
/**
|
|
36
60
|
* Split one simple command into words, tracking whether each is a knowable literal.
|
|
37
61
|
*
|
|
@@ -180,17 +204,24 @@ function scriptCommandFiles(name, rawArgs) {
|
|
|
180
204
|
const nonEmpty = operandWords.filter((word) => word.text.length > 0);
|
|
181
205
|
return { inPlace, files: scriptIsAnOption ? nonEmpty : nonEmpty.slice(1) };
|
|
182
206
|
}
|
|
183
|
-
/**
|
|
184
|
-
|
|
207
|
+
/**
|
|
208
|
+
* Drop option flags — and the value of an option in `withValue` — and stop treating anything as
|
|
209
|
+
* an option after a bare `--`.
|
|
210
|
+
*/
|
|
211
|
+
function operands(words, withValue) {
|
|
185
212
|
const result = [];
|
|
186
213
|
let optionsEnded = false;
|
|
187
|
-
for (
|
|
214
|
+
for (let i = 0; i < words.length; i++) {
|
|
215
|
+
const word = words[i];
|
|
188
216
|
if (!optionsEnded && word.text === "--") {
|
|
189
217
|
optionsEnded = true;
|
|
190
218
|
continue;
|
|
191
219
|
}
|
|
192
|
-
if (!optionsEnded && word.text.startsWith("-") && word.text.length > 1)
|
|
220
|
+
if (!optionsEnded && word.text.startsWith("-") && word.text.length > 1) {
|
|
221
|
+
if (withValue?.has(word.text))
|
|
222
|
+
i++;
|
|
193
223
|
continue;
|
|
224
|
+
}
|
|
194
225
|
result.push(word);
|
|
195
226
|
}
|
|
196
227
|
return result;
|
|
@@ -219,8 +250,8 @@ export function extractBashPaths(command) {
|
|
|
219
250
|
if (verb === undefined || !verb.literal)
|
|
220
251
|
continue;
|
|
221
252
|
const rawArgs = words.slice(1);
|
|
222
|
-
const args = operands(rawArgs);
|
|
223
253
|
const name = verb.text.replace(/^.*\//, ""); // /bin/rm → rm
|
|
254
|
+
const args = operands(rawArgs, OPTION_VALUES[name]);
|
|
224
255
|
if (SCRIPT_COMMANDS.has(name)) {
|
|
225
256
|
const { inPlace, files } = scriptCommandFiles(name, rawArgs);
|
|
226
257
|
pushLiteral(files, inPlace ? "write" : "read", out);
|
|
@@ -242,6 +273,6 @@ export function extractBashPaths(command) {
|
|
|
242
273
|
pushLiteral(args, "read", out);
|
|
243
274
|
}
|
|
244
275
|
}
|
|
245
|
-
return out;
|
|
276
|
+
return out.filter((access) => !STREAM_DEVICE.test(access.path));
|
|
246
277
|
}
|
|
247
278
|
//# sourceMappingURL=bash-paths.js.map
|
package/dist/tool/types.d.ts
CHANGED
|
@@ -40,6 +40,12 @@ export interface ToolResumeContext {
|
|
|
40
40
|
}
|
|
41
41
|
export interface ToolResult<Details = unknown> {
|
|
42
42
|
readonly content: ToolResultContent;
|
|
43
|
+
/**
|
|
44
|
+
* The result as plain JSON data, conforming to the tool's `schema.outputSchema` (an MCP tool's
|
|
45
|
+
* `structuredContent`). The model reads `content`; a program calling the tool (Code Mode)
|
|
46
|
+
* receives this value instead of the text.
|
|
47
|
+
*/
|
|
48
|
+
readonly structured?: unknown;
|
|
43
49
|
readonly details?: Details;
|
|
44
50
|
readonly isError?: boolean;
|
|
45
51
|
readonly stopTurn?: boolean;
|