Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142import { ExtensionAPI } from "@earendil-works/pi-coding-agent";
const PROVIDERS = ["cloudflare-workers-ai", "cloudflare-ai-gateway"];const ENV = ["CLOUDFLARE_ACCOUNT_ID", "CLOUDFLARE_GATEWAY_ID"] as const;
export default function (pi: ExtensionAPI) { pi.on("session_start", (_event, ctx) => { for (const provider of PROVIDERS) { const base = ctx.modelRegistry.getProvider(provider); const auth = base?.auth.apiKey; if (!base || !auth) { continue; }
// Re-register the Cloudflare AI providers but allow env vars to override the stored // configuration. This makes it easy for projects to opt in to separate accounts. ctx.modelRegistry.registerProvider({ ...base, auth: { ...base.auth, apiKey: { ...auth, resolve: async (input) => { const env = { ...input.credential?.env }; for (const name of ENV) { const value = await input.ctx.env(name); if (value !== undefined) { env[name] = value; } } return auth.resolve({ ...input, credential: input.credential && { ...input.credential, env }, }); }, }, }, }); } });}