@agntn/tools 0.2.2 → 0.2.3
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/README.md +10 -8
- package/dist/_chunks/index.d.mts +48 -4
- package/dist/_chunks/libs/typebox.d.mts +1 -2
- package/dist/_chunks/libs/typebox.mjs +0 -2
- package/dist/_chunks/mcp-answers.d.mts +2 -3
- package/dist/_chunks/mcp-answers.mjs +125 -9
- package/dist/_chunks/questions.mjs +93 -0
- package/dist/_chunks/src.mjs +78 -27
- package/dist/_chunks/updates.mjs +131 -2
- package/dist/ai.d.mts +4 -4
- package/dist/ai.mjs +12 -3
- package/dist/cli.d.mts +1 -2
- package/dist/cli.mjs +60 -17
- package/dist/h3.d.mts +3 -2
- package/dist/h3.mjs +15 -6
- package/dist/index.d.mts +2 -2
- package/dist/mcp.d.mts +5 -3
- package/dist/mcp.mjs +11 -6
- package/dist/omp.d.mts +1 -2
- package/dist/omp.mjs +0 -2
- package/dist/pi.d.mts +1 -2
- package/dist/pi.mjs +1 -3
- package/dist/toolkit.d.mts +78 -0
- package/dist/toolkit.mjs +62 -0
- package/package.json +13 -3
- package/dist/_chunks/index.d.mts.map +0 -1
- package/dist/_chunks/libs/typebox.d.mts.map +0 -1
- package/dist/_chunks/libs/typebox.mjs.map +0 -1
- package/dist/_chunks/mcp-answers.d.mts.map +0 -1
- package/dist/_chunks/mcp-answers.mjs.map +0 -1
- package/dist/_chunks/src.mjs.map +0 -1
- package/dist/_chunks/updates.mjs.map +0 -1
- package/dist/ai.d.mts.map +0 -1
- package/dist/ai.mjs.map +0 -1
- package/dist/cli.d.mts.map +0 -1
- package/dist/cli.mjs.map +0 -1
- package/dist/h3.d.mts.map +0 -1
- package/dist/h3.mjs.map +0 -1
- package/dist/mcp.d.mts.map +0 -1
- package/dist/mcp.mjs.map +0 -1
- package/dist/omp.d.mts.map +0 -1
- package/dist/omp.mjs.map +0 -1
- package/dist/pi.d.mts.map +0 -1
- package/dist/pi.mjs.map +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ToolDefinition } from "./_chunks/index.mjs";
|
|
2
|
+
/** The part of the SDK v1 request `extra` a handler reads: abort signal, progress and questions. */
|
|
3
|
+
export interface ToolkitExtra {
|
|
4
|
+
readonly signal?: AbortSignal;
|
|
5
|
+
readonly _meta?: {
|
|
6
|
+
readonly progressToken?: string | number;
|
|
7
|
+
};
|
|
8
|
+
readonly sendNotification?: (notification: {
|
|
9
|
+
readonly method: "notifications/progress";
|
|
10
|
+
readonly params: {
|
|
11
|
+
readonly progressToken: string | number;
|
|
12
|
+
readonly progress: number;
|
|
13
|
+
readonly total?: number;
|
|
14
|
+
readonly message: string;
|
|
15
|
+
};
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
/** Both schemas are `never`, so SDK v1's method fits whatever Zod and schema types it carries. */
|
|
18
|
+
readonly sendRequest?: (request: {
|
|
19
|
+
readonly method: "elicitation/create";
|
|
20
|
+
readonly params: {
|
|
21
|
+
readonly mode: "form";
|
|
22
|
+
readonly message: string;
|
|
23
|
+
readonly requestedSchema: never;
|
|
24
|
+
};
|
|
25
|
+
}, resultSchema: never, options?: {
|
|
26
|
+
readonly signal?: AbortSignal;
|
|
27
|
+
}) => Promise<unknown>;
|
|
28
|
+
}
|
|
29
|
+
/** The toolkit's `useMcpElicitation`, or anything that knows if the client fills forms. */
|
|
30
|
+
export type ToolkitElicitation = () => {
|
|
31
|
+
readonly supports: (mode?: "form") => boolean;
|
|
32
|
+
};
|
|
33
|
+
/** How `toToolkitTools` reaches the person behind the client. */
|
|
34
|
+
export interface ToolkitOptions {
|
|
35
|
+
/** Pass `useMcpElicitation` to give `execute` an `ask`. It runs in every handler. */
|
|
36
|
+
readonly elicitation?: ToolkitElicitation;
|
|
37
|
+
}
|
|
38
|
+
/** What a handler answers. The toolkit runs SDK v1, so these types never name the v2 package. */
|
|
39
|
+
export interface ToolkitResult {
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
content: Array<{
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
type: string;
|
|
44
|
+
}>;
|
|
45
|
+
isError?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** One toolkit tool. Schemas stay `unknown`, since pnpm gives the toolkit its own `zod` copy. */
|
|
48
|
+
export interface ToolkitTool {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
readonly title?: string;
|
|
51
|
+
readonly description?: string;
|
|
52
|
+
readonly annotations?: {
|
|
53
|
+
readonly title?: string;
|
|
54
|
+
readonly readOnlyHint?: boolean;
|
|
55
|
+
readonly destructiveHint?: boolean;
|
|
56
|
+
readonly idempotentHint?: boolean;
|
|
57
|
+
readonly openWorldHint?: boolean;
|
|
58
|
+
};
|
|
59
|
+
readonly inputSchema: unknown;
|
|
60
|
+
readonly outputSchema?: unknown;
|
|
61
|
+
readonly _meta?: Record<string, unknown>;
|
|
62
|
+
readonly handler: (args: unknown, extra?: ToolkitExtra) => Promise<ToolkitResult>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Turns tools into toolkit entries that list what `listTools` lists and answer via `callTool`.
|
|
66
|
+
*
|
|
67
|
+
* Progress and questions need the toolkit's sessions: its stateless default answers in plain JSON.
|
|
68
|
+
* `useMcpElicitation` also needs Nitro's `asyncContext`, since it finds the server in the request.
|
|
69
|
+
*
|
|
70
|
+
* @param info - Server info; `name` is the word in the message for an unknown tool.
|
|
71
|
+
* @param tools - Tools to serve.
|
|
72
|
+
* @param options - Where `ask` comes from; without it there is none.
|
|
73
|
+
* @returns {ToolkitTool[]} Tool definitions in the order given.
|
|
74
|
+
* @throws {ToolDefinitionError} When two tools share a name.
|
|
75
|
+
*/
|
|
76
|
+
export declare function toToolkitTools(info: {
|
|
77
|
+
readonly name: string;
|
|
78
|
+
}, tools: readonly ToolDefinition[], options?: ToolkitOptions): ToolkitTool[];
|
package/dist/toolkit.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "./_chunks/src.mjs";
|
|
2
|
+
import { hostAsk } from "./_chunks/questions.mjs";
|
|
3
|
+
import { callTool, listTools, progressSteps } from "./_chunks/mcp-answers.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
function toToolkitTools(info, tools, options = {}) {
|
|
6
|
+
return listTools(tools).map((entry) => ({
|
|
7
|
+
name: entry.name,
|
|
8
|
+
title: entry.title,
|
|
9
|
+
description: entry.description,
|
|
10
|
+
annotations: entry.annotations,
|
|
11
|
+
inputSchema: wireObject(entry.inputSchema, true),
|
|
12
|
+
...entry.outputSchema === void 0 ? {} : { outputSchema: wireObject(entry.outputSchema, false) },
|
|
13
|
+
...entry._meta === void 0 ? {} : { _meta: entry._meta },
|
|
14
|
+
handler: async (args, extra) => callTool(info, tools, entry.name, args, {
|
|
15
|
+
...callContext(extra),
|
|
16
|
+
...formAsk(extra, options.elicitation)
|
|
17
|
+
})
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
function wireObject(schema, input) {
|
|
21
|
+
const object = z.looseObject({});
|
|
22
|
+
object._zod.toJSONSchema = () => ({ ...schema });
|
|
23
|
+
if (!input) return object;
|
|
24
|
+
object._zod.run = missingAsEmpty(object._zod.run.bind(object._zod));
|
|
25
|
+
return object;
|
|
26
|
+
}
|
|
27
|
+
function missingAsEmpty(run) {
|
|
28
|
+
return (payload, context) => run(payload.value === void 0 ? {
|
|
29
|
+
...payload,
|
|
30
|
+
value: {}
|
|
31
|
+
} : payload, context);
|
|
32
|
+
}
|
|
33
|
+
function callContext(extra) {
|
|
34
|
+
const progressToken = extra?._meta?.progressToken;
|
|
35
|
+
const send = extra?.sendNotification;
|
|
36
|
+
return {
|
|
37
|
+
signal: extra?.signal,
|
|
38
|
+
...progressToken === void 0 || send === void 0 ? {} : { progress: progressSteps((params) => {
|
|
39
|
+
send({
|
|
40
|
+
method: "notifications/progress",
|
|
41
|
+
params: {
|
|
42
|
+
progressToken,
|
|
43
|
+
...params
|
|
44
|
+
}
|
|
45
|
+
}).catch(() => void 0);
|
|
46
|
+
}) }
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function formAsk(extra, elicitation) {
|
|
50
|
+
const send = extra?.sendRequest;
|
|
51
|
+
if (send === void 0 || elicitation?.().supports("form") !== true) return {};
|
|
52
|
+
const reply = z.looseObject({});
|
|
53
|
+
return { ask: hostAsk(async ({ message, requested }) => await send({
|
|
54
|
+
method: "elicitation/create",
|
|
55
|
+
params: {
|
|
56
|
+
mode: "form",
|
|
57
|
+
message,
|
|
58
|
+
requestedSchema: requested
|
|
59
|
+
}
|
|
60
|
+
}, reply, { signal: extra?.signal })) };
|
|
61
|
+
}
|
|
62
|
+
export { toToolkitTools };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agntn/tools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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",
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"types": "./dist/h3.d.mts",
|
|
29
29
|
"import": "./dist/h3.mjs"
|
|
30
30
|
},
|
|
31
|
+
"./toolkit": {
|
|
32
|
+
"types": "./dist/toolkit.d.mts",
|
|
33
|
+
"import": "./dist/toolkit.mjs"
|
|
34
|
+
},
|
|
31
35
|
"./pi": {
|
|
32
36
|
"types": "./dist/pi.d.mts",
|
|
33
37
|
"import": "./dist/pi.mjs"
|
|
@@ -52,6 +56,7 @@
|
|
|
52
56
|
"@agntn/ox": "0.1.0",
|
|
53
57
|
"@earendil-works/pi-coding-agent": "1.0.1",
|
|
54
58
|
"@modelcontextprotocol/client": "2.2.0",
|
|
59
|
+
"@modelcontextprotocol/sdk": "1.32.1",
|
|
55
60
|
"@modelcontextprotocol/server": "2.2.0",
|
|
56
61
|
"@oh-my-pi/pi-coding-agent": "18.0.0",
|
|
57
62
|
"@types/node": "26.2.0",
|
|
@@ -63,14 +68,16 @@
|
|
|
63
68
|
"typebox": "1.3.34",
|
|
64
69
|
"typescript": "7.0.2",
|
|
65
70
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.0.0",
|
|
66
|
-
"vite-plus": "1.0.0"
|
|
71
|
+
"vite-plus": "1.0.0",
|
|
72
|
+
"zod": "4.6.5"
|
|
67
73
|
},
|
|
68
74
|
"peerDependencies": {
|
|
69
75
|
"@earendil-works/pi-coding-agent": ">=0.84.2 <2",
|
|
70
76
|
"@modelcontextprotocol/server": ">=2.2.0 <3",
|
|
71
77
|
"@oh-my-pi/pi-coding-agent": ">=18.0.0 <19",
|
|
72
78
|
"ai": ">=7.0.0 <8",
|
|
73
|
-
"h3-mcp": ">=0.2.0 <0.3"
|
|
79
|
+
"h3-mcp": ">=0.2.0 <0.3",
|
|
80
|
+
"zod": ">=4.1.13 <5"
|
|
74
81
|
},
|
|
75
82
|
"peerDependenciesMeta": {
|
|
76
83
|
"@earendil-works/pi-coding-agent": {
|
|
@@ -87,6 +94,9 @@
|
|
|
87
94
|
},
|
|
88
95
|
"h3-mcp": {
|
|
89
96
|
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"zod": {
|
|
99
|
+
"optional": true
|
|
90
100
|
}
|
|
91
101
|
},
|
|
92
102
|
"engines": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/escapes.ts","../../src/index.ts"],"mappings":";;;;;;;;;;wBAwDgB,aAAa;;YCtBjB;EACN;EAAc;;EACd;EAAe;EAAc;;;iBAGlB,WAAW;EAC1B,SAAS;EACT,SAAS;;EAET;;;;;;;;;YAUU;;;;;iBAMK;;WAEN;WACA;;WAEA;;WAEA;;WAEA;;WAEA,QAAQ,SAAS;;WAEjB;;WAEA;;;iBAIM;;WAEN;;WAEA;;;iBAIM;WACN;WACA;;WAEA;;WAEA;;;iBAIM;EACf,SAAS;;EAET,YAAY,iBAAiB,SAAS;;EAEtC;;iBAGe,eAAe,cAAc,UAAU,SAAS;;WAEtD;;WAEA;;WAEA;;WAEA,iBAAiB;;WAEjB;;WAEA;WACA,QAAQ;;WAER;;WAEA;WACA,OAAO;;WAEP,MAAM;;;;;;;EAOf,QACE,OAAO,OAAO,QACd,SAAS,kBACR,WAAW,WAAW,QAAQ,WAAW;;;qBAIjC,4BAA4B;EAC9B;;;qBAIE,uBAAuB;EACzB;;WAEA;;;;EAKT,YAAY;;;;;;;;wBAcE,iBAAiB,cAAc,SAAS,SACtD,MAAM,eAAe,OAAO,WAC3B,eAAe,OAAO;;;;;;;;;;wBA+GT,WAAW,MAAM,iBAAiB;;;;;;;;;;wBAalC,WAAW,gBAAgB,mBAAmB,oBAAoB;YAStE,WAAW,cAAc;EAC/B;EAAU,OAAO,OAAO;;EACxB;EAAW;;;;;;;;;;;;;;;;wBAgBD,cAAc,cAAc,SAC1C,MAAM,eAAe,iBACrB,gBACC,WAAW;;;;;;;;;;;;;wBA4JQ,WACpB,MAAM,gBACN,eACA,UAAS,kBACR,QAAQ;;;;;;;;;;;;wBAmCK,aAAa;;;;;;;wBAab,WAAW,QAAQ"}
|