import { AccessRequestStatusResponse, CreateAccessRequest, CreateAccessRequestResponse, PingResponse } from '@bodhiapp/ts-client'; import { IExtensionClient, Chat, Models, Embeddings, Mcps, AuthState, BackendServerState, ClientState, ExtensionState, InitParams, LoginOptions, LogLevel, StateChangeCallback, StreamTextResult } from '@bodhiapp/bodhi-js-core'; import { ApiResponse } from '@bodhiapp/bodhi-browser-types'; export type SerializedExt2ExtState = { extensionId?: string; }; /** * Configuration for ExtClient */ export interface ExtClientConfig { authClientId?: string; logLevel?: LogLevel; apiTimeoutMs?: number; initParams?: { extension?: { timeoutMs?: number; attempts?: number; attemptWaitMs?: number; attemptTimeout?: number; }; }; } /** * ExtClient - extension-to-extension client for chrome.runtime operations * * Encapsulates all complexity of communicating with background script * for both auth and bodhi-browser-ext operations. * * Implements IExtensionClient interface with state callback for state changes * */ export declare class ExtClient implements IExtensionClient { private state; private logger; private onStateChange; private extensionId; private broadcastListenerActive; private config; private apiTimeoutMs; private authClientId; private _chat; private _models; private _embeddings; private _mcps; constructor(config?: ExtClientConfig, onStateChange?: StateChangeCallback); /** * Set client state and notify callback */ private setState; /** * Set auth state and notify callback */ private setAuthState; /** * Set or update the state change callback */ setStateCallback(callback: StateChangeCallback): void; /** * Setup persistent broadcast listener for auth state changes * Idempotent - only sets up listener once */ private setupBroadcastListener; /** * Handle authStateChanged broadcast from background * Fetches fresh auth state and notifies via callback */ private handleAuthStateChangedBroadcast; /** * Generate a unique request ID for message correlation */ private generateRequestId; /** * Get current client state */ getState(): ClientState; isClientInitialized(): boolean; isServerReady(): boolean; /** * Initialize extension discovery with optional timeout * Returns ExtensionState with extension and server status * * For sdk/ext: * - CAN store extensionId for fast restoration (via SET_EXTENSION_ID) * - Avoids chrome.runtime discovery messages on page reload */ init(params?: InitParams): Promise; /** * Helper method to send ext message with timeout support */ private sendExtMessageWithTimeout; /** * Send an EXT2EXT_CLIENT_REQUEST message and await EXT2EXT_CLIENT_RESPONSE * Public for generic ext2ext testing */ sendExtRequest(action: string, params?: TParams): Promise; /** * Send an API_REQUEST message and await API_RESPONSE (internal) * Returns ext2ext-specific ExtClientApiResponseMessage */ private sendRawApiMessage; /** * Send an API message and return ApiResponse * @throws BodhiError on operational errors (network, timeout, extension-level) */ sendApiRequest(method: string, endpoint: string, body?: TReq, headers?: Record, authenticated?: boolean): Promise>; /** * Login user via OAuth * @param options - Optional login parameters * @throws ExtError if login fails * @returns AuthState with login state and user info */ login(options?: LoginOptions): Promise; /** * Logout current user * @throws ExtError if logout fails * @returns AuthLoggedOut with logged out state */ logout(): Promise; /** * Get current authentication state * @returns AuthState (discriminated union: AuthLoggedIn | AuthLoggedOut) * @throws ExtError if request fails */ getAuthState(): Promise; /** * Ping bodhi-browser-ext API via /ping endpoint */ pingApi(): Promise>; /** * Get backend server state * Calls /bodhi/v1/info and returns structured server state */ getServerState(): Promise; /** * Generic streaming method */ stream(method: string, endpoint: string, body?: TReq, headers?: Record, authenticated?: boolean): AsyncGenerator; /** * Raw text streaming method - no SSE/JSON parsing * Returns status, headers, and async generator of raw text chunks */ streamText(method: string, endpoint: string, body?: unknown, headers?: Record, authenticated?: boolean): Promise; get chat(): Chat; get models(): Models; get embeddings(): Embeddings; get mcps(): Mcps; requestAccess(body: CreateAccessRequest): Promise>; getAccessRequestStatus(requestId: string): Promise>; pollAccessRequestStatus(requestId: string, options?: { intervalMs?: number; timeoutMs?: number; }): Promise; /** * Serialize ext2ext client state for persistence */ serialize(): SerializedExt2ExtState; /** * Debug dump of ExtClient internal state */ debug(): Promise>; }