| 55 | } |
| 56 | |
| 57 | function toPiTool(sdk: PiSdk, spec: PiToolSpec): ToolDefinition { |
| 58 | return sdk.defineTool({ |
| 59 | name: spec.name, |
| 60 | label: spec.name, |
| 61 | description: spec.description, |
| 62 | // double-cast-allowed: Pi accepts a plain JSON Schema at runtime (pi-ai validation.js coerceWithJsonSchema); the static type requires a TypeBox TSchema |
| 63 | parameters: spec.parameters as unknown as ToolDefinition['parameters'], |
| 64 | execute: async (_toolCallId, params) => { |
| 65 | const result = await spec.execute(params as Record<string, unknown>) |
| 66 | return { |
| 67 | content: [{ type: 'text', text: result.text }], |
| 68 | details: { isError: result.isError }, |
| 69 | } |
| 70 | }, |
| 71 | }) |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Builds a model definition for a provider Pi supports but whose bundled catalog |