@agntn/tools 0.4.0 → 0.4.1
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
CHANGED
|
@@ -33,7 +33,7 @@ export interface ToolResult<Details = unknown> {
|
|
|
33
33
|
isError?: boolean;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* What a call does to the world: MCP annotations,
|
|
36
|
+
* What a call does to the world: MCP and Pi annotations, approval on OMP, OpenCode and the AI SDK.
|
|
37
37
|
*
|
|
38
38
|
* - `read` changes nothing.
|
|
39
39
|
* - `write` changes state that the next call can undo or overwrite.
|
|
@@ -134,7 +134,7 @@ export interface ToolDefinition<Input extends TObject = TObject, Details = unkno
|
|
|
134
134
|
readonly icons?: readonly Icon[];
|
|
135
135
|
/** MCP `_meta` in `tools/list`, such as `ui` or `openai/extensions`. No other surface reads it. */
|
|
136
136
|
readonly meta?: Readonly<Record<string, unknown>>;
|
|
137
|
-
/** Schema of `details
|
|
137
|
+
/** Schema of `details`, which MCP and Pi send as `structuredContent` under its `outputSchema`. */
|
|
138
138
|
readonly output?: TObject;
|
|
139
139
|
/** Pi `promptSnippet`. */
|
|
140
140
|
readonly snippet?: string;
|
|
@@ -25,7 +25,6 @@ export interface McpHost {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Maps a tool's title and declared effect to MCP annotations. Claude Code reads its label here.
|
|
28
|
-
* A process the tool starts can delete anything, so `exec` counts as destructive.
|
|
29
28
|
*
|
|
30
29
|
* @param tool - Tool to describe.
|
|
31
30
|
* @returns {ToolAnnotations} Title and hints for the MCP client.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Check, Errors } from "./libs/typebox.mjs";
|
|
2
1
|
import { ToolInputError, indexTools, invokeTool, sanitizeLine, wireSchema } from "./src.mjs";
|
|
3
2
|
import { causeLines } from "./causes.mjs";
|
|
3
|
+
import { checkDetails, toolHints } from "./outputs.mjs";
|
|
4
4
|
import { hostAsk, readAnswer } from "./questions.mjs";
|
|
5
5
|
function mcpHost(from) {
|
|
6
6
|
const { request, meta } = from;
|
|
@@ -14,10 +14,7 @@ function mcpHost(from) {
|
|
|
14
14
|
function toolAnnotations(tool) {
|
|
15
15
|
return {
|
|
16
16
|
title: tool.title,
|
|
17
|
-
|
|
18
|
-
destructiveHint: tool.effect === "destructive" || tool.effect === "exec",
|
|
19
|
-
idempotentHint: tool.idempotent ?? tool.effect === "read",
|
|
20
|
-
openWorldHint: tool.openWorld ?? false
|
|
17
|
+
...toolHints(tool)
|
|
21
18
|
};
|
|
22
19
|
}
|
|
23
20
|
function errorResult(...lines) {
|
|
@@ -63,12 +60,12 @@ function answer(tool, result) {
|
|
|
63
60
|
content: result.content,
|
|
64
61
|
...result.isError === void 0 ? {} : { isError: result.isError }
|
|
65
62
|
};
|
|
66
|
-
|
|
67
|
-
if (
|
|
63
|
+
const checked = result.isError === true ? void 0 : checkDetails(tool, result.details);
|
|
64
|
+
if (checked === void 0) return content;
|
|
65
|
+
return checked.ok ? {
|
|
68
66
|
...content,
|
|
69
|
-
structuredContent:
|
|
70
|
-
};
|
|
71
|
-
return errorResult(`${tool.name} returned details that don't match its output schema`, ...[...Errors(tool.output, result.details)].map((failure) => `at ${failure.instancePath || "/"}: ${failure.message}`));
|
|
67
|
+
structuredContent: checked.value
|
|
68
|
+
} : errorResult(...checked.lines);
|
|
72
69
|
}
|
|
73
70
|
function questionRound(retry, form) {
|
|
74
71
|
const { responses } = retry;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Check, Errors } from "./libs/typebox.mjs";
|
|
2
|
+
function toolHints(tool) {
|
|
3
|
+
return {
|
|
4
|
+
readOnlyHint: tool.effect === "read",
|
|
5
|
+
destructiveHint: tool.effect === "destructive" || tool.effect === "exec",
|
|
6
|
+
idempotentHint: tool.idempotent ?? tool.effect === "read",
|
|
7
|
+
openWorldHint: tool.openWorld ?? false
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function checkDetails(tool, details) {
|
|
11
|
+
const { output } = tool;
|
|
12
|
+
if (output === void 0) return void 0;
|
|
13
|
+
if (Check(output, details)) return {
|
|
14
|
+
ok: true,
|
|
15
|
+
value: details
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
ok: false,
|
|
19
|
+
lines: [`${tool.name} returned details that don't match its output schema`, ...[...Errors(output, details)].map((failure) => `at ${failure.instancePath || "/"}: ${failure.message}`)]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export { checkDetails, toolHints };
|
package/dist/pi.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Check } from "./_chunks/libs/typebox.mjs";
|
|
2
2
|
import { ToolDefinitionError, ToolInputError, indexTools, invokeTool, resultText, sanitizeLine, sanitizeText, validateInput } from "./_chunks/src.mjs";
|
|
3
3
|
import { throwWithCauses } from "./_chunks/causes.mjs";
|
|
4
|
+
import { checkDetails, toolHints } from "./_chunks/outputs.mjs";
|
|
4
5
|
import { hostContext } from "./_chunks/updates.mjs";
|
|
5
6
|
const EXPOSURES = [
|
|
6
7
|
"direct",
|
|
@@ -31,17 +32,35 @@ function registerPiTools(pi, tools, options = {}) {
|
|
|
31
32
|
...tool.snippet === void 0 ? {} : { promptSnippet: tool.snippet },
|
|
32
33
|
...tool.guidelines === void 0 ? {} : { promptGuidelines: [...tool.guidelines] },
|
|
33
34
|
parameters: tool.input,
|
|
35
|
+
annotations: toolHints(tool),
|
|
36
|
+
...tool.output === void 0 ? {} : { outputSchema: tool.output },
|
|
34
37
|
...reach(exposures.get(tool.name), options.namespace),
|
|
35
38
|
async execute(_toolCallId, params, signal, onUpdate, ctx) {
|
|
36
39
|
if (ask) await approve(tool, ask, params, signal, ctx);
|
|
37
40
|
const context = hostContext(signal, onUpdate, ctx);
|
|
38
|
-
const result = await invokeTool(tool, params, context).catch(throwWithCauses);
|
|
41
|
+
const result = structured(tool, await invokeTool(tool, params, context).catch(throwWithCauses));
|
|
39
42
|
if (result.isError && failures === "throw") throw new Error(resultText(result));
|
|
40
43
|
return result;
|
|
41
44
|
}
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
}
|
|
48
|
+
function structured(tool, result) {
|
|
49
|
+
const checked = result.isError === true ? void 0 : checkDetails(tool, result.details);
|
|
50
|
+
if (checked === void 0) return result;
|
|
51
|
+
if (checked.ok) return {
|
|
52
|
+
...result,
|
|
53
|
+
structuredContent: checked.value
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
content: [{
|
|
57
|
+
type: "text",
|
|
58
|
+
text: checked.lines.map(sanitizeLine).join("\n")
|
|
59
|
+
}],
|
|
60
|
+
details: result.details,
|
|
61
|
+
isError: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
45
64
|
function parseJsonText(tool, own) {
|
|
46
65
|
if (own === void 0) return (args) => repairJsonText(tool, args);
|
|
47
66
|
return (args) => own(repairJsonText(tool, args));
|
package/package.json
CHANGED