import type { AgentTool } from "@mariozechner/pi-agent-core"; import { describe, expect, it } from "vitest"; import { toToolDefinitions } from "./pi-tool-definition-adapter.js"; describe("pi tool definition adapter", () => { it("wraps tool errors into a tool result", async () => { const tool = { name: "boom", label: "Boom", description: "throws", parameters: {}, execute: async () => { throw new Error("nope"); }, } satisfies AgentTool; const defs = toToolDefinitions([tool]); const result = await defs[0].execute("call1", {}, undefined, undefined); expect(result.details).toMatchObject({ status: "error", tool: "boom", }); expect(result.details).toMatchObject({ error: "nope" }); expect(JSON.stringify(result.details)).not.toContain("\n at "); }); });