import { OAuthCallbackFlow } from "./callback-server.js"; import type { OAuthController, OAuthCredentials } from "./types.js"; /** * Per-request timeout for the post-callback provisioning phase (token exchange, * user-info, project discovery/onboarding, LRO polling). These Cloud Code * Assist calls normally settle in well under this window; a longer stall means * a hung endpoint that must surface a login error instead of hanging forever. * The callback server's own 300s deadline covers only the browser-callback wait * ({@link OAuthCallbackFlow}) and does not gate this phase. */ export declare const OAUTH_REQUEST_TIMEOUT_MS = 30000; /** Options for {@link oauthFetch}. */ export interface OAuthFetchOptions { /** Provider id recorded on any {@link AIError.OAuthError} raised. */ provider: string; /** Controller signal; when it aborts, the in-flight request is cancelled. */ signal?: AbortSignal; /** Override the per-request timeout (defaults to {@link OAUTH_REQUEST_TIMEOUT_MS}). */ timeoutMs?: number; } /** * Throw {@link AIError.LoginCancelledError} when the controller signal has * already aborted. Gates each provisioning round-trip, which the callback-wait * cancellation checks in {@link OAuthCallbackFlow} do not reach. */ export declare function throwIfLoginCancelled(signal: AbortSignal | undefined): void; /** * `fetch` for the provisioning phase: composes the controller signal with a * per-request timeout so a stalled endpoint aborts instead of hanging login, * and user cancellation aborts the in-flight request. Cancellation surfaces as * {@link AIError.LoginCancelledError}; a timeout surfaces as an * {@link AIError.OAuthError} with `kind: "timeout"`. */ export declare function oauthFetch(url: string, init: RequestInit, { provider, signal, timeoutMs }: OAuthFetchOptions): Promise; export interface GoogleOAuthFlowConfig { /** Provider id used in progress/error reporting and per-request fetches. */ provider: string; clientId: string; clientSecret: string; authUrl: string; tokenUrl: string; scopes: string[]; callbackPort: number; callbackPath: string; discoverProject: (accessToken: string, onProgress?: (message: string) => void, signal?: AbortSignal) => Promise; } export declare class GoogleOAuthFlow extends OAuthCallbackFlow { private readonly config; constructor(ctrl: OAuthController, config: GoogleOAuthFlowConfig); generateAuthUrl(state: string, redirectUri: string): Promise<{ url: string; instructions?: string; }>; exchangeToken(code: string, _state: string, redirectUri: string): Promise; } export declare function runGoogleOAuthLogin(ctrl: OAuthController, config: GoogleOAuthFlowConfig): Promise;