import SistaAiEngine from '../../SistaAiEngine'; import { SistaAiRealTimeSession, WebRTCConnection } from '../../_types/sharedTypes'; /** * OpenAiEngine - Handles WebRTC connections and AI model interactions * * 4-TIER FALLBACK STRATEGY IMPLEMENTATION: * * This engine implements a sophisticated fallback system to ensure the AI model * always responds to user requests, even when the initial prompt is too complex. * * STRATEGY OVERVIEW: * 1. FIRST ATTEMPT: Full prompt + screen content + tools * - Always starts here for best user experience * - Provides complete context and functionality * - Uses the full prompt template with all features enabled * * 2. SECOND ATTEMPT: Basic prompt without screen content + tools * - Triggered if first attempt fails with "unable to assist" * - Removes heavy screen content that might cause issues * - Maintains tool functionality for user interactions * * 3. THIRD ATTEMPT: Basic prompt without screen content + tools (retry) * - Triggered if second attempt also fails * - Still trying with tools for functionality * - Uses same basic prompt but gives tools another chance * * 4. FOURTH ATTEMPT: Minimal fallback template (no tools) * - Triggered if third attempt also fails * - Removes tools as final fallback * - Ensures the model can always respond, even if limited * * WHY THIS WORKS: * - Progressive complexity reduction prevents model failures * - Maintains functionality as long as possible * - Gives tools multiple chances to work before removing them * - Provides graceful degradation for better user experience * - Handles edge cases where complex prompts overwhelm the model * * IMPLEMENTATION DETAILS: * - Screen content is always included on first attempt (no more gating) * - Fallback system tracks attempt count and progressively simplifies * - All prompts come from OpenAiPrompts.ts for maintainability * - Comprehensive logging tracks strategy execution and outcomes * * @author Sista AI Team * @version 3.7.12 */ export declare class OpenAiEngine { private static instance; private readonly apiKey; private readonly apiUrl; private readonly audioElement; private readonly navigationObserver; private readonly scraper; private readonly toolsAutomatedDiscovery; private openAiConnection; private readonly engine; private _lastEventTraceLogAtMs; private _fallbackInjectionCount; private currentSession; private constructor(); static getInstance(apiKey: string, apiUrl: string, audioElement: HTMLAudioElement, engine: SistaAiEngine): OpenAiEngine; initializeConnection(session: SistaAiRealTimeSession): Promise; private injectDataInSession; private fallbackDataInjectionInSession; private handleAllConnectionEvents; private handleToolCallingRequests; private sendTranscriptToBackendForLogging; }