/** * OpenAI Codex (ChatGPT OAuth) flow * * Inspired by pi-mono's OAuth implementation: * https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/utils/oauth/openai-codex.ts * * NOTE: This module uses Node.js crypto and http for the OAuth callback. * It is only intended for CLI use, not browser environments. */ import type { AuthMode, OAuthCredentials, OAuthPrompt, OAuthProviderInterface } from '../types.js'; export declare const OPENAI_CODEX_AUTH_MODES: ReadonlyArray; declare const JWT_CLAIM_PATH = "https://api.openai.com/auth"; type JwtPayload = { chatgpt_account_id?: string; [JWT_CLAIM_PATH]?: { chatgpt_account_id?: string; }; [key: string]: unknown; }; declare function decodeJwt(token: string): JwtPayload | null; declare function extractAccountIdFromClaims(payload: JwtPayload | null | undefined): string | null; declare function getAccountId(tokens: { idToken?: string; access: string; }, fallback?: string): string | undefined; declare function requireAccountId(tokens: { idToken?: string; access: string; }, fallback?: string): string; declare function createAuthorizationFlow(redirectUri: string, state: string, originator?: string): Promise<{ verifier: string; url: string; }>; type OAuthServerInfo = { redirectUri: string; warning?: string; close: () => void; cancelWait: () => void; waitForCode: () => Promise<{ code: string; } | null>; }; type CallbackPorts = { defaultPort: number; fallbackPort: number; }; declare function startLocalOAuthServer(state: string, ports?: CallbackPorts): Promise; declare function loginOpenAICodexDevice(options: { onAuth: (info: { url: string; instructions?: string; }) => void; onProgress?: (message: string) => void; signal?: AbortSignal; sleep?: (ms: number) => Promise; }): Promise; /** * Login with OpenAI Codex OAuth * * @param options.onAuth - Called with URL and instructions when auth starts * @param options.onPrompt - Called to prompt user for manual code paste (fallback if no onManualCodeInput) * @param options.onProgress - Optional progress messages * @param options.onManualCodeInput - Optional promise that resolves with user-pasted code. * Races with browser callback - whichever completes first wins. * Useful for showing paste input immediately alongside browser flow. * @param options.originator - OAuth originator parameter (defaults to "mastracode") */ export declare function loginOpenAICodex(options: { onAuth: (info: { url: string; instructions?: string; }) => void; onPrompt: (prompt: OAuthPrompt) => Promise; onProgress?: (message: string) => void; onManualCodeInput?: () => Promise; signal?: AbortSignal; originator?: string; mode?: 'browser' | 'device'; }): Promise; export declare const __testing: { createAuthorizationFlow: typeof createAuthorizationFlow; decodeJwt: typeof decodeJwt; extractAccountIdFromClaims: typeof extractAccountIdFromClaims; getAccountId: typeof getAccountId; loginOpenAICodexDevice: typeof loginOpenAICodexDevice; requireAccountId: typeof requireAccountId; startLocalOAuthServer: typeof startLocalOAuthServer; }; /** * Refresh OpenAI Codex OAuth token */ export declare function refreshOpenAICodexToken(refreshToken: string, previousAccountId?: string): Promise; export declare const openaiCodexOAuthProvider: OAuthProviderInterface; export {}; //# sourceMappingURL=openai-codex.d.ts.map