Files
oh-my-pi/packages/coding-agent/examples/extensions/with-deps/index.ts
T
can1357 e9888367d1 refactor: migrated packages to internal utility modules and removed external dependencies
- Implemented in-house, zero-dependency utility modules in `pi-utils` covering DOM manipulation, markdown parsing, templating, browser automation helpers, and terminal buffers.
- Migrated packages across the repository to consume the new internal utilities and `omptype` schema validators instead of external dependencies.
- Removed multiple external runtime and development dependencies including Zod, Marked, LRU cache, Turndown, and Puppeteer browser packages.
2026-08-05 13:39:09 +02:00

37 lines
1.0 KiB
TypeScript

/**
* Example extension with its own npm dependencies.
* Tests that jiti resolves modules from the extension's own node_modules.
*
* Requires: npm install in this directory
*/
import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent";
import ms from "ms";
export default function (pi: ExtensionAPI) {
const z = pi.zod;
// Register a tool that uses ms
pi.registerTool({
name: "parse_duration",
label: "Parse Duration",
description: "Parse a human-readable duration string (e.g., '2 days', '1h', '5m') to milliseconds",
parameters: z.object({
duration: z.string().describe("Duration string like '2 days', '1h', '5m'"),
}),
execute: async (_toolCallId, params) => {
const result = ms(params.duration as ms.StringValue);
if (result === undefined) {
return {
content: [{ type: "text", text: `Invalid duration: "${params.duration}"` }],
isError: true,
details: {},
};
}
return {
content: [{ type: "text", text: `${params.duration} = ${result} milliseconds` }],
details: {},
};
},
});
}