index.ts 1012 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Example extension with its own npm dependencies.
  3. * Tests that jiti resolves modules from the extension's own node_modules.
  4. *
  5. * Requires: npm install in this directory
  6. */
  7. import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
  8. import ms from "ms";
  9. import { Type } from "typebox";
  10. export default function (pi: ExtensionAPI) {
  11. // Register a tool that uses ms
  12. pi.registerTool({
  13. name: "parse_duration",
  14. label: "Parse Duration",
  15. description: "Parse a human-readable duration string (e.g., '2 days', '1h', '5m') to milliseconds",
  16. parameters: Type.Object({
  17. duration: Type.String({ description: "Duration string like '2 days', '1h', '5m'" }),
  18. }),
  19. execute: async (_toolCallId, params) => {
  20. const result = ms(params.duration as ms.StringValue);
  21. if (result === undefined) {
  22. throw new Error(`Invalid duration: "${params.duration}"`);
  23. }
  24. return {
  25. content: [{ type: "text", text: `${params.duration} = ${result} milliseconds` }],
  26. details: {},
  27. };
  28. },
  29. });
  30. }