@agntn/tools 0.2.3 → 0.2.4
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/dist/_chunks/index.d.mts +5 -2
- package/dist/_chunks/src.mjs +4 -2
- package/dist/cli.d.mts +2 -2
- package/dist/cli.mjs +21 -6
- package/dist/pi.mjs +1 -1
- package/package.json +2 -2
package/dist/_chunks/index.d.mts
CHANGED
|
@@ -78,7 +78,7 @@ export type ToolAnswer<Content> = {
|
|
|
78
78
|
readonly action: "decline" | "cancel";
|
|
79
79
|
};
|
|
80
80
|
/** Puts a {@link ToolQuestion} in front of the user and waits for the {@link ToolAnswer}. */
|
|
81
|
-
export type ToolAsk = <Schema extends TObject>(question: ToolQuestion<Schema>) => Promise<ToolAnswer<
|
|
81
|
+
export type ToolAsk = <Schema extends TObject, Content extends Static<Schema> = Static<Schema>>(question: ToolQuestion<Schema>) => Promise<ToolAnswer<Content>>;
|
|
82
82
|
/** An MCP icon, the SDK's own shape: a URL or `data:` URI a client can draw on its card. */
|
|
83
83
|
export interface Icon {
|
|
84
84
|
readonly src: string;
|
|
@@ -158,11 +158,14 @@ export declare class ToolInputError extends Error {
|
|
|
158
158
|
readonly lines: readonly string[];
|
|
159
159
|
/** The schema failures behind the lines, empty when the lines come from elsewhere. */
|
|
160
160
|
readonly issues: readonly InputIssue[];
|
|
161
|
+
/** The tool whose schema turned the input down, unset on a refusal an executor wrote itself. */
|
|
162
|
+
readonly tool: string | undefined;
|
|
161
163
|
/**
|
|
162
164
|
* @param lines - One validation failure per line.
|
|
163
165
|
* @param issues - The schema failures behind them, if any.
|
|
166
|
+
* @param tool - Name of the tool whose schema failed, when the core validated.
|
|
164
167
|
*/
|
|
165
|
-
constructor(lines: readonly string[], issues?: readonly InputIssue[]);
|
|
168
|
+
constructor(lines: readonly string[], issues?: readonly InputIssue[], tool?: string);
|
|
166
169
|
}
|
|
167
170
|
/**
|
|
168
171
|
* Declares a tool and checks the schema rules every surface depends on.
|
package/dist/_chunks/src.mjs
CHANGED
|
@@ -24,10 +24,12 @@ var ToolInputError = class extends Error {
|
|
|
24
24
|
name = "ToolInputError";
|
|
25
25
|
lines;
|
|
26
26
|
issues;
|
|
27
|
-
|
|
27
|
+
tool;
|
|
28
|
+
constructor(lines, issues = [], tool) {
|
|
28
29
|
super(lines.join("\n"));
|
|
29
30
|
this.lines = lines;
|
|
30
31
|
this.issues = issues;
|
|
32
|
+
this.tool = tool;
|
|
31
33
|
}
|
|
32
34
|
};
|
|
33
35
|
const TOOL_NAME = /^[a-z][a-z0-9_]{0,63}$/;
|
|
@@ -175,7 +177,7 @@ function schemaAt(root, pointer) {
|
|
|
175
177
|
}
|
|
176
178
|
async function invokeTool(tool, args, context = {}) {
|
|
177
179
|
const checked = validateInput(tool, args);
|
|
178
|
-
if (!checked.ok) throw new ToolInputError(checked.lines, checked.issues);
|
|
180
|
+
if (!checked.ok) throw new ToolInputError(checked.lines, checked.issues, tool.name);
|
|
179
181
|
const { progress, ask } = context;
|
|
180
182
|
if (!progress && !ask) return await tool.execute(checked.value, context);
|
|
181
183
|
let settled = false;
|
package/dist/cli.d.mts
CHANGED
|
@@ -56,8 +56,8 @@ export declare function createCli(options: CliOptions): Cli;
|
|
|
56
56
|
/**
|
|
57
57
|
* Applies `default` and `fallback`: an empty command line runs `default`, and
|
|
58
58
|
* a first word that names no command goes to `fallback` as its first
|
|
59
|
-
* argument
|
|
60
|
-
*
|
|
59
|
+
* argument, a flag included, so `web --provider brave query` searches. Only
|
|
60
|
+
* the root's own `--help` and `--version` stay at the root.
|
|
61
61
|
*
|
|
62
62
|
* @param options - CLI options.
|
|
63
63
|
* @param argv - Words after the executable and script.
|
package/dist/cli.mjs
CHANGED
|
@@ -422,11 +422,21 @@ function cliIssueLines(fields, issue) {
|
|
|
422
422
|
if (field === void 0) return [issue.line];
|
|
423
423
|
return [`Invalid arguments at ${placeIn(field, inner)}: ${issue.problem}`];
|
|
424
424
|
}
|
|
425
|
+
function cliLines(fields, refusal) {
|
|
426
|
+
const lines = refusal.issues.flatMap((issue) => cliIssueLines(fields, issue));
|
|
427
|
+
return lines.length > 0 ? [...new Set(lines)] : refusal.lines;
|
|
428
|
+
}
|
|
425
429
|
function checkInput(tool, fields, input) {
|
|
426
430
|
const checked = validateInput(tool, input);
|
|
427
|
-
if (checked.ok)
|
|
428
|
-
|
|
429
|
-
|
|
431
|
+
if (!checked.ok) throw new ToolInputError(cliLines(fields, checked), checked.issues, tool.name);
|
|
432
|
+
}
|
|
433
|
+
async function invokeInCliWords(tool, fields, input, context) {
|
|
434
|
+
try {
|
|
435
|
+
return await invokeTool(tool, input, context);
|
|
436
|
+
} catch (error) {
|
|
437
|
+
if (!(error instanceof ToolInputError) || error.tool !== void 0) throw error;
|
|
438
|
+
throw new ToolInputError(cliLines(fields, error), error.issues);
|
|
439
|
+
}
|
|
430
440
|
}
|
|
431
441
|
function writeLine(stream, text) {
|
|
432
442
|
process[stream].write(text.endsWith("\n") ? text : `${text}\n`);
|
|
@@ -516,7 +526,7 @@ function toolCommand(tool) {
|
|
|
516
526
|
try {
|
|
517
527
|
const input = toolInput(fields, words.values);
|
|
518
528
|
checkInput(tool, fields, input);
|
|
519
|
-
result = await
|
|
529
|
+
result = await invokeInCliWords(tool, fields, input, {
|
|
520
530
|
...line.context,
|
|
521
531
|
host
|
|
522
532
|
});
|
|
@@ -571,11 +581,16 @@ function createCli(options) {
|
|
|
571
581
|
if (missing !== void 0) throw new ToolDefinitionError(`${options.name}: no command ${missing}`);
|
|
572
582
|
return { run: (argv) => dispatch(options, commands, normalizeArgv(options, argv)) };
|
|
573
583
|
}
|
|
584
|
+
const ROOT_FLAGS = /* @__PURE__ */ new Set([
|
|
585
|
+
"--help",
|
|
586
|
+
"-h",
|
|
587
|
+
"--version",
|
|
588
|
+
"-v"
|
|
589
|
+
]);
|
|
574
590
|
function normalizeArgv(options, argv) {
|
|
575
591
|
const [first] = argv;
|
|
576
592
|
if (first === void 0) return options.default === void 0 ? [] : [options.default];
|
|
577
|
-
|
|
578
|
-
if (options.fallback === void 0 || option || commandWords(options).includes(first)) return [...argv];
|
|
593
|
+
if (options.fallback === void 0 || ROOT_FLAGS.has(first) || commandWords(options).includes(first)) return [...argv];
|
|
579
594
|
return [options.fallback, ...argv];
|
|
580
595
|
}
|
|
581
596
|
async function dispatch(options, commands, argv) {
|
package/dist/pi.mjs
CHANGED
|
@@ -30,7 +30,7 @@ function byName(entries, name) {
|
|
|
30
30
|
}
|
|
31
31
|
async function approve(tool, ask, params, signal, ctx) {
|
|
32
32
|
const checked = validateInput(tool, params);
|
|
33
|
-
if (!checked.ok) throw new ToolInputError(checked.lines, checked.issues);
|
|
33
|
+
if (!checked.ok) throw new ToolInputError(checked.lines, checked.issues, tool.name);
|
|
34
34
|
const question = await ask(checked.value);
|
|
35
35
|
if (question === void 0) return;
|
|
36
36
|
if (!ctx.hasUI) throw new Error(`${tool.name} needs interactive approval in Pi TUI or RPC mode`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agntn/tools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "One tool definition for MCP, Pi, OMP and the AI SDK",
|
|
5
5
|
"homepage": "https://github.com/agntn/tools#readme",
|
|
6
6
|
"bugs": "https://github.com/agntn/tools/issues",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"lint": "vp lint && vp fmt --check",
|
|
108
108
|
"lint:fix": "vp lint --fix && vp fmt",
|
|
109
109
|
"typecheck": "tsc --noEmit --skipLibCheck",
|
|
110
|
-
"typecheck:dist": "tsc -p tsconfig.dist.json",
|
|
110
|
+
"typecheck:dist": "tsc -p tsconfig.dist.json && tsc -p test/copies",
|
|
111
111
|
"test": "vp test run",
|
|
112
112
|
"test:watch": "vp test watch",
|
|
113
113
|
"release": "pnpm test && pnpm build && pnpm typecheck:dist && changelogen --release --push"
|