@agntn/tools 0.0.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omp.mjs","names":[],"sources":["../src/omp.ts"],"sourcesContent":["/**\n * OMP adapter: registers {@link ToolDefinition}s on an OMP `ExtensionAPI`.\n *\n * Only types come from `@oh-my-pi/pi-coding-agent`. Compiled OMP injects the\n * package root into the extension file itself, not into its dependencies, so\n * the extension passes the host `Text` component in.\n */\n\nimport type {\n AgentToolResult,\n ExtensionAPI,\n Text as HostText,\n Theme,\n ToolDefinition as OmpToolDefinition,\n ToolRenderResultOptions,\n} from \"@oh-my-pi/pi-coding-agent\";\n\nimport {\n invokeTool,\n sanitizeLine,\n wireSchema,\n type ToolDefinition,\n type ToolEffect,\n} from \"./index.ts\";\n\ntype TextComponent = typeof HostText;\ntype Component = ReturnType<NonNullable<OmpToolDefinition[\"renderCall\"]>>;\n\n/** The part of a host result a renderer reads. */\nexport interface OmpResultView {\n readonly details?: unknown;\n readonly isError?: boolean;\n}\n\n/** Per-tool renderer overrides, drawn with the host theme. */\nexport interface OmpRenderers {\n /** One-line summary of the arguments after the title. Sanitized by the adapter. */\n describeCall?(args: Readonly<Record<string, unknown>>): unknown;\n /** Short metadata after the badge, one entry per fact. Each entry is sanitized. */\n describeResult?(result: OmpResultView): readonly unknown[];\n /**\n * Replaces the result status line with the package's own component, such as\n * a bounded preview of long output. It owns sanitizing what it draws.\n */\n renderResult?: OmpToolDefinition[\"renderResult\"];\n}\n\nexport interface OmpToolOptions {\n /** The host `Text` component, imported by the extension from the package root. */\n readonly Text: TextComponent;\n /** Status-line renderers by tool name. */\n readonly renderers?: Readonly<Record<string, OmpRenderers>>;\n}\n\nconst APPROVAL: Record<ToolEffect, \"read\" | \"write\"> = {\n read: \"read\",\n write: \"write\",\n // OMP has no destructive tier; `exec` means running commands.\n destructive: \"write\",\n};\n\n/**\n * Registers every tool on the OMP extension API.\n *\n * The schema reaches OMP through `pi.typebox.Type.Unsafe`: the host-injected\n * build validates the raw JSON Schema with its full validator and emits the\n * document verbatim, so `pattern` and `maxProperties` survive. A standalone\n * omptype schema would drop both.\n *\n * @param pi - OMP extension API.\n * @param tools - Tools to register.\n * @param options - Host `Text` and optional renderers.\n */\nexport function registerOmpTools(\n pi: ExtensionAPI,\n tools: readonly ToolDefinition[],\n options: OmpToolOptions,\n): void {\n const { Type } = pi.typebox;\n const { Text } = options;\n\n for (const tool of tools) {\n const renderers = Object.hasOwn(options.renderers ?? {}, tool.name)\n ? options.renderers?.[tool.name]\n : undefined;\n\n pi.registerTool({\n name: tool.name,\n label: tool.title,\n description: tool.description,\n parameters: Type.Unsafe<Record<string, unknown>>(wireSchema(tool)),\n approval: APPROVAL[tool.effect],\n async execute(_toolCallId, params, signal): Promise<AgentToolResult<unknown>> {\n // Returned as is: OMP reads `isError` from the object (`explicitError`).\n return await invokeTool(tool, params, signal ? { signal } : {});\n },\n renderCall(args, renderOptions, theme): Component {\n const summary = renderers?.describeCall ? sanitizeLine(renderers.describeCall(args)) : \"\";\n const title = theme.fg(\"accent\", sanitizeLine(tool.title));\n return new Text(\n `${callIcon(renderOptions, theme)} ${title}${summary ? `: ${theme.fg(\"muted\", summary)}` : \"\"}`,\n 0,\n 0,\n );\n },\n renderResult(result, renderOptions, theme, args): Component {\n if (renderers?.renderResult)\n return renderers.renderResult(result, renderOptions, theme, args);\n const icon = result.isError\n ? theme.styledSymbol(\"status.error\", \"error\")\n : theme.styledSymbol(\"status.done\", \"success\");\n const { bracketLeft, bracketRight } = theme.format;\n const badge = theme.fg(\"accent\", `${bracketLeft}${APPROVAL[tool.effect]}${bracketRight}`);\n const facts = result.isError\n ? []\n : (renderers?.describeResult?.(result).map(sanitizeLine).filter(Boolean) ?? []);\n const meta = facts.length > 0 ? ` ${theme.fg(\"dim\", facts.join(theme.sep.dot))}` : \"\";\n return new Text(\n `${icon} ${theme.fg(\"accent\", sanitizeLine(tool.title))} ${badge}${meta}`,\n 0,\n 0,\n );\n },\n });\n }\n}\n\n/**\n * Status icon for a call: pending, spinning or done.\n *\n * Drawn with the host theme on purpose: compiled OMP injects only the package\n * root, so importing `@oh-my-pi/pi-coding-agent/tui` would stop the extension.\n *\n * @param options - Render options from the host.\n * @param theme - Host theme.\n * @returns {string} The styled icon.\n */\nfunction callIcon(options: ToolRenderResultOptions, theme: Theme): string {\n if (!options.isPartial) return theme.styledSymbol(\"status.done\", \"success\");\n if (options.spinnerFrame === undefined) return theme.styledSymbol(\"status.pending\", \"muted\");\n return (\n theme.spinnerFrames[options.spinnerFrame % theme.spinnerFrames.length] ??\n theme.styledSymbol(\"status.running\", \"accent\")\n );\n}\n"],"mappings":";AAsDA,MAAM,WAAiD;CACrD,MAAM;CACN,OAAO;CAEP,aAAa;AACf;;;;;;;;;;;;GAcA,MAAgB,QAAA,aAEd,QACA,QACM;IACN,OAAQ,MAAA,WAAY,MAAA,QAAA,SAAA,EAAA,OAAA,IAAA,CAAA,CAAA;GACpB;GAEA,WAAW,MAAQ,eAAO,OAAA;IACxB,MAAM,UAAY,WAAO,eAAe,aAAiB,UAAS,aACtD,IAAA,CAAA,IAAA;IAGZ,MAAG,QAAa,MAAA,GAAA,UAAA,aAAA,KAAA,KAAA,CAAA;IACd,OAAM,IAAK,KAAA,GAAA,SAAA,eAAA,KAAA,EAAA,GAAA,QAAA,UAAA,KAAA,MAAA,GAAA,SAAA,OAAA,MAAA,MAAA,GAAA,CAAA;GACX;GACA,aAAa,QAAK,eAAA,OAAA,MAAA;IAClB,IAAA,WAAY,cAAqC,OAAW,UAAK,aAAA,QAAA,eAAA,OAAA,IAAA;IACjE,MAAA,OAAU,OAAS,UAAK,MAAA,aAAA,gBAAA,OAAA,IAAA,MAAA,aAAA,eAAA,SAAA;IACxB,MAAM,EAAA,aAAQ,iBAAqB,MAA2C;IAE5E,MAAA,QAAa,MAAA,GAAA,UAAiB,GAAA,cAAmB,SAAO,KAAM,UAAA,cAAA;IAChE,MAAA,QAAA,OAAA,UAAA,CAAA,IAAA,WAAA,iBAAA,MAAA,CAAA,CAAA,IAAA,YAAA,CAAA,CAAA,OAAA,OAAA,KAAA,CAAA;IACA,MAAA,OAAW,MAAM,SAAA,IAAe,IAAA,MAAkB,GAAA,OAAA,MAAA,KAAA,MAAA,IAAA,GAAA,CAAA,MAAA;IAChD,OAAM,IAAA,KAAU,GAAA,KAAA,GAAW,MAAA,GAAA,UAAe,aAAa,KAAA,KAAU,CAAA,EAAA,GAAA,QAAkB,QAAI,GAAA,CAAA;GACvF;EACA,CAAA;CAKF;AACA;AAGE,SAAA,SAAa,SAAO,OAChB;CAEJ,IAAA,CAAA,QAAQ,WAAa,OAAA,MAAA,aAAuB,eAAA,SAAA;CAC5C,IAAA,QAAM,iBAAiB,KAAA,GAAU,OAAG,MAAA,aAAuB,kBAAe,OAAA;CAC1E,OAAA,MAAM,cAAe,QAChB,eACW,MAAA,cAAiB,WAAY,MAAA,aAAqB,kBAAa,QAAA;AAC/E;AAMF,SAAA"}
package/dist/pi.d.mts ADDED
@@ -0,0 +1,27 @@
1
+ import { ToolDefinition as ToolDefinition$1 } from "./index.mjs";
2
+ import { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-agent";
3
+ interface PiToolOptions {
4
+ /**
5
+ * How a returned `isError` result reaches Pi.
6
+ *
7
+ * `throw` (default) raises the result text: `pi-agent-core` up to 0.98 marks
8
+ * every returned object as a success and records an error only after a throw.
9
+ * `return` hands the result over unchanged and keeps its `details`; use it
10
+ * only with a peer range of `>=0.99.0`, since Pi does not check peer ranges.
11
+ */
12
+ readonly failures?: "throw" | "return";
13
+ /** Host renderers by tool name, passed to Pi unchanged. */
14
+ readonly renderers?: Readonly<Record<string, PiRenderers>>;
15
+ }
16
+ /** The host's own call and result renderers for one tool. */
17
+ type PiRenderers = Pick<ToolDefinition, "renderCall" | "renderResult">;
18
+ /**
19
+ * Registers every tool on the Pi extension API.
20
+ *
21
+ * @param pi - Pi extension API.
22
+ * @param tools - Tools to register.
23
+ * @param options - Failure policy and renderers.
24
+ */
25
+ declare function registerPiTools(pi: ExtensionAPI, tools: readonly ToolDefinition$1[], options?: PiToolOptions): void;
26
+ export { PiRenderers, PiToolOptions, registerPiTools };
27
+ //# sourceMappingURL=pi.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pi.d.mts","names":["PiToolDefinition","ToolDefinition"],"sources":["../src/pi.ts"],"mappings":";;UAeiB;;;;;;;;;WASN;;WAEA,YAAY,SAAS,eAAe;;;KAInC,cAAc,KAAKA;;;;;;;;iBASf,gBACd,IAAI,cACJ,gBAAgBC,oBAChB,UAAS"}
package/dist/pi.mjs ADDED
@@ -0,0 +1,24 @@
1
+ import { invokeTool, resultText } from "./index.mjs";
2
+ function registerPiTools(pi, tools, options = {}) {
3
+ const failures = options.failures ?? "throw";
4
+ for (const tool of tools) {
5
+ const renderers = Object.hasOwn(options.renderers ?? {}, tool.name) ? options.renderers?.[tool.name] : void 0;
6
+ pi.registerTool({
7
+ ...renderers,
8
+ name: tool.name,
9
+ label: tool.title,
10
+ description: tool.description,
11
+ ...tool.snippet === void 0 ? {} : { promptSnippet: tool.snippet },
12
+ ...tool.guidelines === void 0 ? {} : { promptGuidelines: [...tool.guidelines] },
13
+ parameters: tool.input,
14
+ async execute(_toolCallId, params, signal) {
15
+ const result = await invokeTool(tool, params, signal ? { signal } : {});
16
+ if (result.isError && failures === "throw") throw new Error(resultText(result));
17
+ return result;
18
+ }
19
+ });
20
+ }
21
+ }
22
+ export { registerPiTools };
23
+
24
+ //# sourceMappingURL=pi.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pi.mjs","names":[],"sources":["../src/pi.ts"],"sourcesContent":["/**\n * Pi adapter: registers {@link ToolDefinition}s on a Pi `ExtensionAPI`.\n *\n * Only types come from `@earendil-works/pi-coding-agent`; nothing is imported\n * from the host at runtime.\n */\n\nimport type {\n AgentToolResult,\n ExtensionAPI,\n ToolDefinition as PiToolDefinition,\n} from \"@earendil-works/pi-coding-agent\";\n\nimport { invokeTool, resultText, type ToolDefinition } from \"./index.ts\";\n\nexport interface PiToolOptions {\n /**\n * How a returned `isError` result reaches Pi.\n *\n * `throw` (default) raises the result text: `pi-agent-core` up to 0.98 marks\n * every returned object as a success and records an error only after a throw.\n * `return` hands the result over unchanged and keeps its `details`; use it\n * only with a peer range of `>=0.99.0`, since Pi does not check peer ranges.\n */\n readonly failures?: \"throw\" | \"return\";\n /** Host renderers by tool name, passed to Pi unchanged. */\n readonly renderers?: Readonly<Record<string, PiRenderers>>;\n}\n\n/** The host's own call and result renderers for one tool. */\nexport type PiRenderers = Pick<PiToolDefinition, \"renderCall\" | \"renderResult\">;\n\n/**\n * Registers every tool on the Pi extension API.\n *\n * @param pi - Pi extension API.\n * @param tools - Tools to register.\n * @param options - Failure policy and renderers.\n */\nexport function registerPiTools(\n pi: ExtensionAPI,\n tools: readonly ToolDefinition[],\n options: PiToolOptions = {},\n): void {\n const failures = options.failures ?? \"throw\";\n\n for (const tool of tools) {\n const renderers = Object.hasOwn(options.renderers ?? {}, tool.name)\n ? options.renderers?.[tool.name]\n : undefined;\n pi.registerTool({\n ...renderers,\n name: tool.name,\n label: tool.title,\n description: tool.description,\n ...(tool.snippet === undefined ? {} : { promptSnippet: tool.snippet }),\n ...(tool.guidelines === undefined ? {} : { promptGuidelines: [...tool.guidelines] }),\n parameters: tool.input,\n async execute(_toolCallId, params, signal): Promise<AgentToolResult<unknown>> {\n const result = await invokeTool(tool, params, signal ? { signal } : {});\n if (result.isError && failures === \"throw\") throw new Error(resultText(result));\n return result;\n },\n });\n }\n}\n"],"mappings":";;;;;;;GAuCA,MAAgB,KAAA;GAKd,OAAM,KAAA;GAEN,aAAW,KAAQ;GACjB,GAAA,KAAM,YAAY,KAAO,IAAA,CAAA,IAAO,EAAA,eAAQ,KAAiB,QAAK;GAG9D,GAAG,KAAA,eAAa,KAAA,IAAA,CAAA,IAAA,EAAA,kBAAA,CAAA,GAAA,KAAA,UAAA,EAAA;GACd,YAAG,KAAA;GACH,MAAM,QAAK,aAAA,QAAA,QAAA;IACX,MAAO,SAAK,MAAA,WAAA,MAAA,QAAA,SAAA,EAAA,OAAA,IAAA,CAAA,CAAA;IACZ,IAAA,OAAA,WAAkB,aAAA,SAAA,MAAA,IAAA,MAAA,WAAA,MAAA,CAAA;IAClB,OAAS;GACT;EACA,CAAA;CACA;AACE;AAEA,SAAA"}
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@agntn/tools",
3
+ "version": "0.0.0",
4
+ "description": "One tool definition for MCP, Pi, OMP and the AI SDK",
5
+ "homepage": "https://github.com/agntn/tools#readme",
6
+ "bugs": "https://github.com/agntn/tools/issues",
7
+ "license": "MIT",
8
+ "author": "oritwoen (https://github.com/oritwoen)",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/agntn/tools.git"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.mts",
21
+ "import": "./dist/index.mjs"
22
+ },
23
+ "./mcp": {
24
+ "types": "./dist/mcp.d.mts",
25
+ "import": "./dist/mcp.mjs"
26
+ },
27
+ "./pi": {
28
+ "types": "./dist/pi.d.mts",
29
+ "import": "./dist/pi.mjs"
30
+ },
31
+ "./omp": {
32
+ "types": "./dist/omp.d.mts",
33
+ "import": "./dist/omp.mjs"
34
+ },
35
+ "./ai": {
36
+ "types": "./dist/ai.d.mts",
37
+ "import": "./dist/ai.mjs"
38
+ }
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "scripts": {
44
+ "build": "obuild",
45
+ "lint": "vp lint && vp fmt --check",
46
+ "lint:fix": "vp lint --fix && vp fmt",
47
+ "typecheck": "tsc --noEmit --skipLibCheck",
48
+ "test": "vp test run",
49
+ "test:watch": "vp test watch",
50
+ "release": "pnpm test && pnpm build && changelogen --release --push"
51
+ },
52
+ "devDependencies": {
53
+ "@agntn/ox": "0.1.0",
54
+ "@earendil-works/pi-coding-agent": "0.84.2",
55
+ "@modelcontextprotocol/client": "2.2.0",
56
+ "@modelcontextprotocol/server": "2.2.0",
57
+ "@oh-my-pi/pi-coding-agent": "18.0.0",
58
+ "@types/node": "26.2.0",
59
+ "ai": "7.0.66",
60
+ "changelogen": "0.6.2",
61
+ "obuild": "0.4.38",
62
+ "typebox": "1.3.34",
63
+ "typescript": "7.0.2",
64
+ "vite": "catalog:",
65
+ "vite-plus": "catalog:"
66
+ },
67
+ "peerDependencies": {
68
+ "@earendil-works/pi-coding-agent": ">=0.84.2 <1",
69
+ "@modelcontextprotocol/server": ">=2.2.0 <3",
70
+ "@oh-my-pi/pi-coding-agent": ">=18.0.0 <19",
71
+ "ai": ">=7.0.0 <8"
72
+ },
73
+ "peerDependenciesMeta": {
74
+ "@earendil-works/pi-coding-agent": {
75
+ "optional": true
76
+ },
77
+ "@modelcontextprotocol/server": {
78
+ "optional": true
79
+ },
80
+ "@oh-my-pi/pi-coding-agent": {
81
+ "optional": true
82
+ },
83
+ "ai": {
84
+ "optional": true
85
+ }
86
+ },
87
+ "engines": {
88
+ "node": ">=24"
89
+ },
90
+ "packageManager": "pnpm@11.22.0"
91
+ }