import { SalesApiClient } from './SalesApiClient.js'; import { CyberneticOfflineStorage } from './CyberneticOfflineStorage.js'; import type { StoredMessage } from './CyberneticSessionStorage.js'; import { LicenseManager } from './license/index.js'; import type { CyberneticConfig, CyberneticResponse, CyberneticError, ConnectionStatus, AskOptions, StreamCallbacks, CacheStatus, SystemSettings, AgenticConfig, SourcesConfig, SalesChatResponse, VisitorInitResponse, LeadCaptureResponse } from './types.js'; import type { LicenseState } from './license/types.js'; /** * Interface for agentic capabilities registration * Used by registerAgenticCapabilities() helper from agentic module */ export interface AgenticCapabilities { /** CyberneticAgent class for DOM interactions */ agent: any; /** CyberneticIntentClassifier class for intent detection */ intentClassifier?: any; } /** * Cybernetic Chatbot Client * * Provides API access to AsterMind backend with offline fallback. * Always returns a response, never throws exceptions. */ export declare class CyberneticClient { private config; private apiClient; private wsTransport; private cache; private localRAG; private status; private lastError; private systemSettings; private settingsLastChecked; private readonly SETTINGS_CHECK_INTERVAL; private agenticCapabilities; private licenseManager; private offlineStorage; private omegaRAG; private salesClient; private sessionStorage; private offlineWarningShown; /** Debug logger — only outputs when config.debug is true */ private log; constructor(config: CyberneticConfig); /** * Register agentic capabilities * Called by registerAgenticCapabilities() helper from agentic module * * @example * ```typescript * import { CyberneticClient, registerAgenticCapabilities } from '@astermind/cybernetic-chatbot-client'; * const client = new CyberneticClient(config); * registerAgenticCapabilities(client); * ``` */ registerAgentic(capabilities: AgenticCapabilities): void; /** * Check if agentic capabilities are available and enabled */ isAgenticEnabled(): boolean; /** * Get registered agentic capabilities (for advanced use) */ getAgenticCapabilities(): AgenticCapabilities | null; /** * Get agentic configuration */ getAgenticConfig(): AgenticConfig | null; /** * Get sources configuration * Returns merged configuration with all defaults applied */ getSourcesConfig(): SourcesConfig; /** * Check if a specific source feature is available * Takes into account configuration, connection status, and requirements * * @param feature - The feature to check ('summary' or 'download') * @returns Whether the feature is available */ isSourceFeatureAvailable(feature: 'summary' | 'download'): boolean; /** * Classify user message intent for agentic action * Only works if agentic capabilities are registered and enabled * * @param message - User's message to classify * @returns Intent classification or null if agentic not available */ classifyIntent(message: string): { action: { id: string; type: string; target: string; confidence: number; explanation?: string; params?: Record; } | null; shouldEscalate: boolean; rawConfidence: number; matchedPatterns?: string[]; } | null; /** * Execute an agent action * Only works if agentic capabilities are registered and enabled * * @param action - Action to execute * @returns Action result or error */ executeAction(action: { id: string; type: string; target: string; confidence: number; params?: Record; }): Promise<{ success: boolean; message: string; error?: string; }>; /** * Smart ask - checks for action intent first, then falls back to RAG * Combines agentic classification with standard RAG query * * @param message - User's message * @param options - Optional request configuration * @returns Object containing response, action, and/or action result */ smartAsk(message: string, options?: AskOptions): Promise<{ response?: CyberneticResponse; action?: { id: string; type: string; target: string; confidence: number; explanation?: string; params?: Record; }; actionResult?: { success: boolean; message: string; error?: string; }; }>; /** * Initialize offline vector support * Loads pre-exported vectors from URL or inline data */ private initializeOffline; /** * Initialize Omega RAG module */ private initializeOmega; /** * Manually reload offline vectors * Clears cache and re-fetches from configured source */ reloadOfflineVectors(): Promise; /** * Check if Omega offline RAG is enabled and ready */ isOmegaOfflineEnabled(): boolean; /** * Get offline model info (if Omega is loaded) */ getOfflineModelInfo(): { version: string; savedAt: string; documentCount: number; vocabularySize: number; } | null; /** * Get local RAG export status */ getLocalRAGStatus(): { loaded: boolean; loadedFromExport: boolean; documentCount: number; exportVersion?: string; }; /** * Get offline storage instance for advanced operations */ getOfflineStorage(): CyberneticOfflineStorage | null; /** * Get stored messages from a previous session for UI restoration. * Call after construction to check for resumable conversations. */ getStoredMessages(): StoredMessage[]; /** * Check if a valid stored session exists that can be resumed. */ hasStoredSession(): boolean; /** * Get session info for debugging/status display. */ getSessionInfo(): { hasSession: boolean; sessionId: string | null; messageCount: number; lastUpdated: Date | null; ttlRemaining: number | null; }; /** * Clear the stored session and start fresh. * Use for "New Conversation" actions. */ clearSession(): void; /** * Start a new session, clearing any stored data. * Optionally sets a new sessionId immediately. */ startNewSession(sessionId?: string): void; /** * Check if sales mode is enabled */ isSalesModeEnabled(): boolean; /** * Get the sales API client for direct access */ getSalesClient(): SalesApiClient | null; /** * Send a sales-aware chat message. * Returns the assistant reply with sales context (lead score, CTA buttons, etc.). * Requires salesMode to be enabled in config. */ salesChat(message: string, options?: { sessionId?: string; visitorId?: string; conversationId?: string; pageUrl?: string; }): Promise; /** * Initialize or resume a visitor session. * Call on first page load to register the visitor with the backend. * Requires salesMode to be enabled in config. */ initVisitor(visitorId: string, pageUrl: string, referrer?: string, utmParams?: Record): Promise; /** * Track a page view event for a visitor. * Call when the visitor navigates to a new page. * Requires salesMode to be enabled in config. */ trackPageView(visitorId: string, url: string, title: string, timeOnPageMs?: number, scrollDepth?: number): Promise<{ success: boolean; }>; /** * Submit a lead capture form. * Creates or updates a lead record in the backend. * Requires salesMode to be enabled in config. */ captureLeadForm(data: { email: string; firstName?: string; lastName?: string; company?: string; role?: string; useCase?: string; budgetRange?: string; timeline?: string; visitorId?: string; playbookId?: string; customFields?: Record; }): Promise; /** * Send a message to the chatbot * Always returns a response, never throws * * @param message - User's message * @param options - Optional request configuration */ ask(message: string, options?: AskOptions): Promise; /** * Send a message with streaming response * * @param message - User's message * @param callbacks - Streaming event callbacks * @param options - Optional request configuration */ askStream(message: string, callbacks: StreamCallbacks, options?: AskOptions): Promise; /** * Stream chat via REST+SSE (original transport). * Used as the primary transport for on-prem, or as fallback for SaaS WebSocket failures. */ private streamViaSSE; /** * Sync documents to local cache for offline use */ syncCache(): Promise; /** * Get current connection status including system settings */ getStatus(): { connection: ConnectionStatus; cache: CacheStatus; lastError: CyberneticError | null; systemSettings: SystemSettings | null; license: LicenseState | null; }; /** * Get license manager for advanced license operations */ getLicenseManager(): LicenseManager; /** * Clear local cache */ clearCache(): Promise; /** * Clean up all resources (WebSocket connection, caches, event listeners). * Call this when the client is no longer needed to prevent memory leaks. */ destroy(): void; /** * Manually check if backend is reachable */ checkConnection(): Promise; /** * Check system status including maintenance mode * Called periodically and before API calls */ checkSystemStatus(): Promise; /** * Fetch widget configuration (including persona) from the backend. * Requires apiKey and apiUrl to be configured. * Returns null on any error (network, auth, server) — callers should * fall back to static config when null is returned. */ fetchConfig(): Promise; /** * Check if maintenance mode is active */ isMaintenanceMode(): boolean; /** * Get maintenance message if in maintenance mode */ getMaintenanceMessage(): string | undefined; /** * Validate cache using server-configured retention hours */ isCacheValid(): boolean; /** * API call with retry logic */ private apiWithRetry; /** * Fallback to local RAG processing * Uses Omega RAG if available, falls back to simple TF-IDF */ private fallbackAsk; /** * Monitor browser online/offline events */ private monitorConnection; /** * Update connection status and notify listeners */ private setStatus; /** * Normalize various error types to CyberneticError */ private normalizeError; /** * Create standardized error response */ private createErrorResponse; /** * Async sleep utility */ private sleep; } //# sourceMappingURL=CyberneticClient.d.ts.map