import type { Model } from "@earendil-works/pi-ai"; import { getBuiltinModels } from "@earendil-works/pi-ai/providers/all"; import type { ExtensionAPI, ProviderModelConfig } from "@earendil-works/pi-coding-agent"; const PROVIDER = "openai-codex" as const; const BASE_MODEL_ID = "gpt-5.4" as const; const TARGET_MODEL_ID = "gpt-5.5" as const; const TARGET_CONTEXT_WINDOW = 1_000_000; function cloneCompat["compat"]>(compat: T): T { if (!compat) return compat; return JSON.parse(JSON.stringify(compat)) as T; } function toProviderModelConfig(model: Model): ProviderModelConfig { return { id: model.id, name: model.name, api: model.api, reasoning: model.reasoning, input: [...model.input], cost: { ...model.cost }, contextWindow: model.contextWindow, maxTokens: model.maxTokens, headers: model.headers ? { ...model.headers } : undefined, compat: cloneCompat(model.compat), }; } export default function (pi: ExtensionAPI) { const builtInModels = getBuiltinModels(PROVIDER) as Model[]; // Newer pi versions ship gpt-5.5 in the built-in openai-codex catalog. // The native definition (and the provider's native OAuth) are strictly // better than a clone derived from gpt-5.4, so do nothing. if (builtInModels.some((model) => model.id === TARGET_MODEL_ID)) { console.log(`[pi-codex-5.5] ${PROVIDER}/${TARGET_MODEL_ID} is built into this pi version — extension is a no-op.`); return; } const baseModel = builtInModels.find((model) => model.id === BASE_MODEL_ID); if (!baseModel) { throw new Error(`Could not find ${PROVIDER}/${BASE_MODEL_ID} to derive ${TARGET_MODEL_ID}.`); } const targetModel: ProviderModelConfig = { ...toProviderModelConfig(baseModel), id: TARGET_MODEL_ID, name: "GPT-5.5", cost: { input: baseModel.cost.input * 2, output: baseModel.cost.output * 2, cacheRead: baseModel.cost.cacheRead * 2, cacheWrite: baseModel.cost.cacheWrite * 2, }, contextWindow: TARGET_CONTEXT_WINDOW, }; const models: ProviderModelConfig[] = []; let insertedTarget = false; for (const model of builtInModels) { models.push(toProviderModelConfig(model)); if (model.id === BASE_MODEL_ID && !insertedTarget) { models.push(targetModel); insertedTarget = true; } } if (!insertedTarget) { models.push(targetModel); } // Registering against the built-in provider merges this config with the // native one, so OAuth/auth handling stays with pi's own openai-codex // implementation (the old pi-ai/oauth export no longer exists). pi.registerProvider(PROVIDER, { baseUrl: baseModel.baseUrl, api: baseModel.api, models, }); }