import type { TokenWalletConfig, AuthorizeOptions, PopupOptions, PopupResult, TokenResponse, Provider, ProxyCallOptions, ProxyResponse, AllowedProvidersResponse } from './types.js'; /** * Token Wallet client. * * Two ways to obtain an access token: * * **Modal (single-page apps)** — open an iframe consent screen and * receive an OAuth authorization code. The code must be exchanged * server-side because the exchange requires `clientSecret`: * ```typescript * const { code } = await tw.popup({ suggestedBudget: 5 }); * await fetch('/api/auth/exchange', { * method: 'POST', * body: JSON.stringify({ code }), * }); * ``` * * **Redirect (server-side)** — classic OAuth bounce: * ```typescript * res.redirect(tw.getAuthorizeUrl()); * // ...later in /callback: * const { access_token } = await tw.exchangeCode(req.query.code); * ``` * * Once you have the access token, call the LLM through the proxy: * ```typescript * const result = await tw.call({ * accessToken, * provider: 'anthropic', * path: '/v1/messages', * body: { model: 'claude-3-5-sonnet-latest', max_tokens: 1024, messages: [...] }, * }); * if (isProxyError(result)) console.error(result.error); * else console.log(result.data); * ``` * * For streaming responses, use a vendor SDK with `baseURL: tw.proxyUrl(...)` * — streams bypass the unified envelope and are forwarded as-is. */ export declare const TokenWallet: (config: TokenWalletConfig) => { /** * Build the authorization URL for a full-page redirect. * Supports optional suggested budget that pre-fills the consent screen. */ getAuthorizeUrl: (options?: AuthorizeOptions) => string; /** * Open the consent screen and resolve with an OAuth authorization * code when the user approves. The code must then be exchanged * server-side via `tw.exchangeCode(code)` (the exchange requires * `clientSecret`, which must never run in browser code). * * Two presentation modes: * * - `mode: 'iframe'` (default) — overlay an iframe modal in the * current window. Cleaner UX, but the consent screen's host must * allow being framed (no `X-Frame-Options: DENY`). * - `mode: 'window'` — open a separate browser popup window via * `window.open`. Works regardless of frame policy. * * ```typescript * const { code } = await tw.popup({ suggestedBudget: 5 }); * await fetch('/api/auth/exchange', { * method: 'POST', * body: JSON.stringify({ code }), * }); * ``` */ popup: (options?: PopupOptions) => Promise; /** * Exchange an authorization code for an access token. * Call this server-side in your callback handler. * Requires clientSecret to be set in config. */ exchangeCode: (code: string) => Promise; /** * Make an authenticated, non-streaming request through the proxy. * Returns a unified envelope: `ProxySuccess` on success, `ProxyError` * on failure. Narrow the result with `isProxyError` / `isProxySuccess`. * * For streaming responses, use a vendor SDK with `baseURL: tw.proxyUrl(...)` * — streams bypass the envelope and are forwarded as-is. * * ```typescript * const result = await tw.call({ * accessToken, * provider: 'anthropic', * path: '/v1/messages', * body: { model: 'claude-3-5-sonnet-latest', max_tokens: 1024, messages: [...] }, * }); * ``` */ call: (options: ProxyCallOptions) => Promise; /** * Fetch the access context for an access token: which app it belongs * to and which providers the user has authorised it to call. * * The returned `providers` list is exactly the set that will succeed * through `tw.call()` (budget permitting). Use it to render a picker, * gate UI, or detect that the user is missing a required provider. * * ```typescript * const { app, providers } = await tw.getAllowedProviders(accessToken); * for (const p of providers) { * console.log(p.displayName, p.logoUrl); * } * ``` */ getAllowedProviders: (accessToken: string) => Promise; /** * Get the proxy URL for a specific provider. * Use as `baseURL` in a vendor SDK for streaming requests, which * bypass the unified envelope. */ proxyUrl: (provider: Provider) => string; /** The Token Wallet dashboard base URL */ baseUrl: string; /** The Token Wallet proxy base URL */ proxyBase: string; }; //# sourceMappingURL=client.d.ts.map