import type { FetchImpl } from "../../types"; import type { OAuthProviderUnion } from "../registry"; export type OAuthCredentials = { refresh: string; access: string; expires: number; enterpriseUrl?: string; projectId?: string; email?: string; accountId?: string; apiEndpoint?: string; }; export type OAuthProvider = OAuthProviderUnion; export type OAuthProviderId = OAuthProvider | (string & {}); export type OAuthPrompt = { message: string; placeholder?: string; allowEmpty?: boolean; }; export type OAuthAuthInfo = { url: string; instructions?: string; }; export interface OAuthProviderInfo { id: OAuthProviderId; name: string; available: boolean; /** * Provider id the login stores credentials under, when it differs from `id` * (e.g. `openai-codex-device` ⇒ `openai-codex`). Lets callers map a login * entry back to the model provider it authenticates. */ storeCredentialsAs?: string; } export interface OAuthController { onAuth?(info: OAuthAuthInfo): void; onProgress?(message: string): void; onManualCodeInput?(): Promise; onPrompt?(prompt: OAuthPrompt): Promise; signal?: AbortSignal; fetch?: FetchImpl; } export interface OAuthLoginCallbacks extends OAuthController { onAuth: (info: OAuthAuthInfo) => void; onPrompt: (prompt: OAuthPrompt) => Promise; } export interface OAuthProviderInterface { readonly id: OAuthProviderId; readonly name: string; readonly sourceId?: string; login(callbacks: OAuthLoginCallbacks): Promise; refreshToken?(credentials: OAuthCredentials): Promise; getApiKey?(credentials: OAuthCredentials): string; /** Store resulting OAuth credentials under a different provider id. */ readonly storeCredentialsAs?: string; }