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:
+43
-8
@@ -2,12 +2,45 @@
|
|||||||
* Test fixture: a sibling extension that streams through the pi-ai compat
|
* Test fixture: a sibling extension that streams through the pi-ai compat
|
||||||
* entrypoint with the active session model, the way background-agent
|
* entrypoint with the active session model, the way background-agent
|
||||||
* extensions do. Registers `/compat-call` so the test can drive it over RPC.
|
* 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"
|
// @ts-expect-error pi resolves this peer package at load time.
|
||||||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"
|
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", {
|
pi.registerCommand("compat-call", {
|
||||||
description: "Stream through @earendil-works/pi-ai/compat with the session model",
|
description: "Stream through @earendil-works/pi-ai/compat with the session model",
|
||||||
handler: async (_args, ctx) => {
|
handler: async (_args, ctx) => {
|
||||||
@@ -17,12 +50,14 @@ export default function (pi: ExtensionAPI) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const message = await streamSimple(model, {
|
const message = await compat
|
||||||
messages: [{ role: "user", content: "say mock token", timestamp: Date.now() }],
|
.streamSimple(model, {
|
||||||
}).result()
|
messages: [{ role: "user", content: "say mock token", timestamp: Date.now() }],
|
||||||
|
})
|
||||||
|
.result()
|
||||||
const text = message.content
|
const text = message.content
|
||||||
.filter((part): part is { type: "text"; text: string } => part.type === "text")
|
.filter((part) => part.type === "text")
|
||||||
.map((part) => part.text)
|
.map((part) => part.text ?? "")
|
||||||
.join("")
|
.join("")
|
||||||
ctx.ui.notify(`compat-call ok: ${text}`, "info")
|
ctx.ui.notify(`compat-call ok: ${text}`, "info")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user