/** * Mirror existing provider configurations for re-registration. * * When we override a provider, we need to preserve its models, baseUrl, * API type, and other config. This module reads the current state from * pi-ai's model registry. */ import { getModels, getProviders, getApiProvider, type KnownProvider } from "@mariozechner/pi-ai"; export interface MirroredProvider { readonly providerId: string; readonly baseUrl: string; readonly api: string; readonly models: ReadonlyArray<{ readonly id: string; readonly name: string; readonly reasoning: boolean; readonly input: ReadonlyArray<"text" | "image">; readonly cost: { readonly input: number; readonly output: number; readonly cacheRead: number; readonly cacheWrite: number; }; readonly contextWindow: number; readonly maxTokens: number; }>; readonly hasStreamSimple: boolean; } /** * Read the current provider configuration from pi-ai's registry. * Returns undefined if the provider has no registered models. */ export function mirrorProvider(providerId: KnownProvider): MirroredProvider | undefined { const models = getModels(providerId); if (models.length === 0) { return undefined; } const first = models[0]; if (!first) { return undefined; } const baseProvider = getApiProvider(first.api); const baseUrl = first.baseUrl || ""; return { providerId, baseUrl, api: first.api, models: models.map((m) => ({ id: m.id, name: m.name, reasoning: m.reasoning, input: m.input, cost: m.cost, contextWindow: m.contextWindow, maxTokens: m.maxTokens, })), hasStreamSimple: Boolean(baseProvider), }; } /** * Get the list of all provider IDs that have registered models. * Uses pi-ai's getProviders() -- no hardcoded list needed. */ export function getRegisteredProviderIds(): KnownProvider[] { return getProviders().filter((id) => getModels(id).length > 0); }