import { fauxAssistantMessage } from "@earendil-works/pi-ai"; import type { PiSession } from "../../../test/fixture/create-pi-session.ts"; import type { Evidence } from "../src/result.ts"; import type { Query } from "../src/tool.ts"; export async function nativeQuery( pi: PiSession, input: Query, ): Promise { let output: Evidence | undefined; const unsubscribe = pi.session.subscribe((event) => { if (event.type === "tool_execution_end" && event.toolName === "lsp") { const result = event.result as { content: { type: string; text?: string }[]; }; const text = result.content.find((item) => item.type === "text")?.text; if (text) output = JSON.parse(text) as Evidence; } }); pi.setResponses([ fauxAssistantMessage( [ { type: "toolCall", id: `lsp-${Date.now()}`, name: "lsp", arguments: { ...input }, }, ], { stopReason: "toolUse" }, ), fauxAssistantMessage("done"), ]); try { await pi.session.prompt("Run scripted navigation query."); } finally { unsubscribe(); } if (!output) throw new Error("Native Pi tool path emitted no result."); if (pi.errors.length) throw new Error(pi.errors.join("; ")); return output; }