import type { Api, AssistantMessageEventStream, Context, Model, SimpleStreamOptions } from "@earendil-works/pi-ai"; import type { AccountSlot } from "../../core/accounts.js"; import { type MigrationNotice } from "../../core/failover.js"; import { readPool, writePool } from "../../core/store.js"; import { type CodexTokens, refreshCodex } from "./oauth.js"; /** * Per-request account resolution for the `codex-pool` provider. * * A provider-level `getApiKey(credentials)` cannot serve a pool: it is resolved * once from the stored credential, so every request would reuse whichever * account happened to be stored and rotation could never happen. (Registering * the account-manager menu result as the credential also means there is no real * token there at all, which upstream rejects with "Could not parse your * authentication token".) * * So, exactly like the Kiro package, streaming goes through `streamSimple`: * read the pool per request, pick an account, inject *that* account's token, * and on a retryable failure block it and replay on the next account. Stock's * `openai-codex-responses` API does the actual streaming — we only choose who * pays for it. */ export declare const CODEX_POOL_PROVIDER_ID = "codex-pool"; export declare function slotToCodexTokens(slot: AccountSlot): CodexTokens; export interface CodexStreamDeps { readPoolState?: typeof readPool; writePoolState?: typeof writePool; refresh?: typeof refreshCodex; /** Stock's `openai-codex-responses` stream, injected for testability. */ createStream?: (model: Model, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream; onFailover?: (message: string) => void; reportMigration?: (providerId: string, notice: MigrationNotice) => void; } export declare function createCodexStreamSimple(agentDir: string, deps?: CodexStreamDeps): (model: Model, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;