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)
This commit is contained in:
Patrick Wozniak
2026-09-01 23:29:33 +02:00
parent 0700d9b61d
commit 6e52b84036
+43 -8
View File
@@ -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>
},
): 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) {