export interface BackendConfig { baseURL: string; userId?: string; jwt?: string; serviceKey?: string; apiKey?: string; /** Back-compat: previous name for JWT token (Bearer). */ authToken?: string; } export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; export interface BackendRequestOptions { params?: Record; data?: unknown; headers?: Record; /** Override per-request timeout in milliseconds. */ timeoutMs?: number; } export interface BinaryBackendResponse { content_type: string; content_length: number; encoding: "base64"; data_base64: string; } export declare const DASHBOARD_ACCOUNT_URL = "https://openephemeris.com/dashboard?tab=account"; export declare const LOGIN_SIGNUP_URL = "https://openephemeris.com/login?signup=true&redirect=%2Fdashboard%3Ftab%3Daccount"; export declare const UPGRADE_URL = "https://openephemeris.com/pricing"; /** One-tap $5 → 150-credit top-up (signs the user in if needed, then redirects to the prefilled Stripe Payment Link). */ export declare const TOPUP_URL = "https://openephemeris.com/topup?pack=payg_5"; export declare const WALLET_TOPUP_URL = "https://openephemeris.com/wallet"; export declare class BackendError extends Error { readonly status: number; readonly code: string; readonly retryable: boolean; readonly upgradeUrl?: string | undefined; constructor(message: string, status: number, code: string, retryable: boolean, upgradeUrl?: string | undefined); } export declare class BackendClient { private client; private userId; private jwt?; private serviceKey?; private apiKey?; private credentialManager; private _pendingAuthFlow; private _authFlowResult; constructor(config: BackendConfig); /** * Override the API key at runtime. Used by the SSE server to inject the * per-session user's key so that all tool calls are authenticated and * metered against the correct user account. */ setApiKey(key: string): void; /** * Override the stored JWT at runtime. Used by the SSE/HTTP server to refresh * a session's Bearer token when the host (e.g. claude.ai) rotates it via * /oauth/token. Self-signed Supabase JWTs expire after 1h, so without this a * long-lived session would keep sending the frozen expired token and 401 on * every tool call. Only takes effect when no API key / service key is set * (JWT is the lowest-priority credential in the interceptor). */ setJwt(jwt: string): void; /** * Start the device auth flow in the background if not already running. * Called automatically when no credentials are found in the interceptor. * Idempotent — only starts once per client lifetime. */ private autoStartDeviceAuth; /** The actual device-auth start + background poll. Kicked off by (and stored * on) autoStartDeviceAuth so the guard is race-safe. */ private _runDeviceAuth; private expectsBinaryResponse; private toBuffer; private decodePayload; private extractMessage; private normalizeContentType; private isBinaryContentType; /** Maps an AxiosError to a structured BackendError. */ private mapError; get(path: string, params?: Record, timeoutMs?: number): Promise; post(path: string, data?: any, timeoutMs?: number): Promise; delete(path: string): Promise; request(method: HttpMethod, path: string, options?: BackendRequestOptions): Promise; getUserId(): string; } export declare const backendClient: BackendClient; /** * Run `fn` in an async context where `getActiveClient()` returns `client`. * Used by the SSE server to scope each connection to its own BackendClient. */ export declare function runWithClient(client: BackendClient, fn: () => T): T; /** * Returns the per-session BackendClient when called inside `runWithClient`, * otherwise falls back to the module-level singleton (stdio mode). */ export declare function getActiveClient(): BackendClient;