/** Host-owned OpenAI Codex OAuth lifecycle. */ import type { AuthInteraction, Credential, CredentialStore, Models } from '@earendil-works/pi-ai'; import type { CodexCallbackBridgeFactory } from './callback-bridge.ts'; import type { CodexAuthFailureReason, CodexAuthState, CodexLoginMethod } from './types.ts'; /** Bound a browser flow that pi-ai would otherwise wait on indefinitely. */ export declare const CODEX_BROWSER_CALLBACK_TIMEOUT_MS: number; /** Classify a Host-side OAuth exception without returning its potentially sensitive text. */ export declare function classifyCodexLoginFailure(error: unknown): CodexAuthFailureReason; /** Narrow pi-ai surface used by the auth service and its tests. */ export interface CodexAuthModels { login(providerId: string, type: 'oauth', interaction: AuthInteraction): Promise; logout(providerId: string): Promise; } /** Host-only sink for full provider errors that must not cross the browser RPC. */ export type CodexLoginFailureReporter = (error: unknown, method: CodexLoginMethod) => void; /** Own one background Codex login flow and expose secret-free state. */ export declare class CodexAuthService { private readonly models; private readonly credentials; private readonly startBrowserCallbackBridge?; private readonly reportLoginFailure?; private readonly browserCallbackTimeoutMs; private active; private current; private stateListener; /** * Sticks once a refresh fails terminally, independent of the displayed * phase, until a refresh, login, or logout succeeds. Survives status * recomputation, so a still-stored dead credential cannot reappear as * connected after startup, a cancelled reconnect, or a failed one. */ private refreshFailed; /** Invalidates request-path refresh outcomes started before login/logout. */ private refreshGeneration; private disposed; constructor(models: CodexAuthModels, credentials: CredentialStore, startBrowserCallbackBridge?: CodexCallbackBridgeFactory | undefined, reportLoginFailure?: CodexLoginFailureReporter | undefined, browserCallbackTimeoutMs?: number); /** Monotonic credential generation captured by refresh operations. */ getRefreshGeneration(): number; /** Register a Host-only observer notified after every published state change. */ setStateListener(listener: ((state: CodexAuthState) => void) | undefined): void; private publish; private interaction; /** Read current stored or in-progress state without exposing token values. */ status(): Promise; /** Record a terminal token-refresh failure; Host-only and secret-free. */ noteRefreshFailure(_error: unknown, generation?: number, failedExpires?: number): void; /** Record a successful token refresh after a terminal failure. */ noteRefreshSuccess(expiresAt: number, generation?: number): void; /** Start browser-callback or device-code OAuth in background. */ login(method: CodexLoginMethod): CodexAuthState; private completeLogin; /** Cancel the active login without deleting an earlier usable credential. */ cancel(): Promise; /** Cancel active work and remove the stored credential. */ logout(): Promise; private stopActive; /** Drain background login work during plugin teardown and reject stale outcomes. */ dispose(): Promise; } /** Narrow a real pi-ai collection to authentication operations. */ export declare function codexAuthModels(models: Models): CodexAuthModels;