From 6e52b84036abbf41b8ca7ec9f894ab829c834d12 Mon Sep 17 00:00:00 2001 From: Patrick Wozniak Date: Tue, 1 Sep 2026 23:11:10 +0200 Subject: [PATCH] test(pi-local): keep the compat caller fixture free of peer type deps Declare the fixture's pi types inline so npm run typecheck passes without the optional peer packages, matching the existing fixture convention. (cherry picked from commit 0ba5827c58a0f6ccf54387454ae38d93bbead3d9) --- tests/fixtures/compat-caller-extension.ts | 51 +++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/tests/fixtures/compat-caller-extension.ts b/tests/fixtures/compat-caller-extension.ts index 214533f..a028299 100644 --- a/tests/fixtures/compat-caller-extension.ts +++ b/tests/fixtures/compat-caller-extension.ts @@ -2,12 +2,45 @@ * Test fixture: a sibling extension that streams through the pi-ai compat * entrypoint with the active session model, the way background-agent * extensions do. Registers `/compat-call` so the test can drive it over RPC. + * + * Types are declared inline so the fixture has no typecheck dependency on the + * optional pi peer packages; the host's extension loader resolves the import. */ -import { streamSimple } from "@earendil-works/pi-ai/compat" -import type { ExtensionAPI } from "@earendil-works/pi-coding-agent" +// @ts-expect-error pi resolves this peer package at load time. +import * as compatModule from "@earendil-works/pi-ai/compat" -export default function (pi: ExtensionAPI) { +interface CompatTextPart { + type: string + text?: string +} + +interface CompatStreamResult { + result(): Promise<{ content: readonly CompatTextPart[] }> +} + +interface CompatModule { + streamSimple(model: unknown, context: unknown): CompatStreamResult +} + +interface CompatCallerContext { + model?: unknown + ui: { notify(message: string, level: "info" | "error"): void } +} + +interface CompatCallerExtensionApi { + registerCommand( + name: string, + command: { + description: string + handler: (args: string, ctx: CompatCallerContext) => Promise + }, + ): void +} + +const compat = compatModule as CompatModule + +export default function (pi: CompatCallerExtensionApi) { pi.registerCommand("compat-call", { description: "Stream through @earendil-works/pi-ai/compat with the session model", handler: async (_args, ctx) => { @@ -17,12 +50,14 @@ export default function (pi: ExtensionAPI) { return } try { - const message = await streamSimple(model, { - messages: [{ role: "user", content: "say mock token", timestamp: Date.now() }], - }).result() + const message = await compat + .streamSimple(model, { + messages: [{ role: "user", content: "say mock token", timestamp: Date.now() }], + }) + .result() const text = message.content - .filter((part): part is { type: "text"; text: string } => part.type === "text") - .map((part) => part.text) + .filter((part) => part.type === "text") + .map((part) => part.text ?? "") .join("") ctx.ui.notify(`compat-call ok: ${text}`, "info") } catch (error) {