diff --git a/CHANGELOG.md b/CHANGELOG.md index 279f22b..f7ee868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Fix `omp plugin install` on Oh My Pi 18.x, which rejected 0.6.1 because its pi-ai lacks the `registerApiProvider` export; the compat registration now resolves at runtime and is skipped on hosts that register custom APIs themselves. + ## 0.6.1 - 2026-09-01 - Expose selectable thinking levels (`minimal`, `low`, `medium`, `high`, `xhigh`) for `meta/muse-spark-1.1`, `meta/muse-spark-1.2`, and `meta/muse-spark-1.2-contributor` through a manual catalog override, so `/thinking` and `Shift+Tab` no longer stay locked on `off` for these reasoning models. diff --git a/index.ts b/index.ts index 12af76c..89a9816 100644 --- a/index.ts +++ b/index.ts @@ -6,11 +6,8 @@ */ import { AssistantMessageEventStream } from "@earendil-works/pi-ai" -import { - registerApiProvider, - streamSimple as streamNativeProvider, - type ApiStreamSimpleFunction, -} from "@earendil-works/pi-ai/compat" +import * as piAiCompat from "@earendil-works/pi-ai/compat" +import { streamSimple as streamNativeProvider } from "@earendil-works/pi-ai/compat" import { getAgentDir, type ExtensionAPI, @@ -45,6 +42,24 @@ import { createCommandCodeTransportRouter } from "./src/transport.ts" const COMMAND_CODE_API = "commandcode-custom" const COMPAT_SOURCE_ID = "pi-commandcode-provider" +type CompatStreamFunction = ( + model: Parameters[0], + context: Parameters[1], + options?: Parameters[2], +) => AssistantMessageEventStream + +/** + * pi's compat entrypoint exposes `registerApiProvider`; Oh My Pi maps + * `@earendil-works/pi-ai/compat` onto its own pi-ai, which lacks that export + * and registers custom APIs itself inside `registerProvider`. Resolve the + * function at runtime so the extension loads on both hosts. + */ +function registerCompatApiProvider(stream: CompatStreamFunction): void { + const register = (piAiCompat as { registerApiProvider?: unknown }).registerApiProvider + if (typeof register !== "function") return + register({ api: COMMAND_CODE_API, stream, streamSimple: stream }, COMPAT_SOURCE_ID) +} + function commandCodeHeaders(): Record | undefined { if (process.env.CMD_ZDR === "1" || process.env.COMMANDCODE_ZDR === "1") { return { "x-cmd-zdr": "1" } @@ -135,16 +150,13 @@ export default async function (pi: ExtensionAPI) { // custom api there so those calls reach the same transport. The registry // resolves no credentials for extension providers, so fall back to the // configured key when the caller passes none. - const compatStream: ApiStreamSimpleFunction = (model, context, options) => + const compatStream: CompatStreamFunction = (model, context, options) => transport.stream( model, context, options?.apiKey ? options : { ...options, apiKey: getConfiguredApiKey() }, ) as AssistantMessageEventStream - registerApiProvider( - { api: COMMAND_CODE_API, stream: compatStream, streamSimple: compatStream }, - COMPAT_SOURCE_ID, - ) + registerCompatApiProvider(compatStream) pi.on("message_end", async (event, ctx) => { if (event.message.role !== "assistant") return