/** * @license * Copyright 2023 Nuraly, Laabidi Aymen * SPDX-License-Identifier: MIT */ import { EventBus } from './event-bus.js'; import { ChatbotState, ChatbotUICallbacks, ChatbotCoreConfig, ChatbotContext, SendMessageOptions, ValidationError, ChatbotProvider, ChatbotStorage, ChatbotPlugin } from './types.js'; import { ChatbotMessage, ChatbotThread, ChatbotFile, ChatbotModule, ChatbotSuggestion } from '../chatbot.types.js'; import { StateHandler, MessageHandler, ThreadHandler, FileHandler, ModuleHandler, SuggestionHandler } from './handlers/index.js'; import { ProviderService, ValidationService, StorageService, PluginService } from './services/index.js'; /** * Pure chatbot core controller - completely UI-agnostic * All UI interactions happen through injected callbacks * Can be extended and overridden for custom behavior */ export declare class ChatbotCoreController { protected eventBus: EventBus; protected config: ChatbotCoreConfig; protected ui: ChatbotUICallbacks; protected plugins: Map; protected stateHandler: StateHandler; protected messageHandler: MessageHandler; protected threadHandler: ThreadHandler; protected fileHandler: FileHandler; protected moduleHandler: ModuleHandler; protected suggestionHandler: SuggestionHandler; protected providerService: ProviderService; protected validationService: ValidationService; protected storageService: StorageService; protected pluginService: PluginService; constructor(config?: ChatbotCoreConfig); private initializeProvider; /** * Initialize state - override to customize initial state */ protected initializeState(config: ChatbotCoreConfig): ChatbotState; /** * Process a message text through all registered plugins to render HTML tags */ protected processMessageThroughPlugins(message: ChatbotMessage): ChatbotMessage; /** * Run onMessageReceived hooks on all bot messages currently in state. * This ensures plugins like ArtifactPlugin can post-process restored * or externally-loaded messages (not just streamed/added ones). */ protected processRestoredMessagesForPlugins(): void; /** * Setup lifecycle hooks - override to add custom setup logic */ protected setupLifecycleHooks(): void; /** * Called before initialization - override for custom pre-init logic */ protected onBeforeInit(): void; /** * Called when controller is ready - override for custom initialization */ protected onReady(): Promise; /** * Called when controller is destroyed - override for cleanup */ protected onDestroy(): void; protected updateState(updates: Partial): void; /** * Send a message (main public API) */ sendMessage(text: string, options?: SendMessageOptions): Promise; /** * Stop the current provider processing/stream */ stop(): void; /** * Add a message programmatically */ addMessage(data: Partial): ChatbotMessage; /** * Update an existing message by ID */ updateMessage(id: string, updates: Partial): void; /** * Delete a message by ID */ deleteMessage(id: string): void; /** * Clear all messages from the current conversation */ clearMessages(): void; /** * Get all messages in the current conversation */ getMessages(): ChatbotMessage[]; /** * Upload files to the chatbot * @param files - Optional array of files to upload. If not provided, will trigger file dialog * @returns Array of uploaded ChatbotFile objects */ uploadFiles(files?: File[]): Promise; /** * Remove an uploaded file by ID */ removeFile(fileId: string): void; /** * Clear all uploaded files */ clearFiles(): void; /** * Get all uploaded files */ getUploadedFiles(): ChatbotFile[]; /** * Create a new conversation thread */ createThread(title?: string): Promise; /** * Switch to a different thread */ switchThread(threadId: string | number): void; /** * Fetch a thread's messages the first time it is opened. Skeleton rows from * autoLoadConversations carry messagesLoaded:false; this fills them in on * demand instead of eagerly fetching every conversation at mount time. */ protected lazyLoadThreadMessages(threadId: string | number): Promise; /** * Delete a thread by ID */ deleteThread(threadId: string): void; /** * Rename a thread */ renameThread(threadId: string, newTitle: string): void; /** * Toggle bookmark on a thread */ bookmarkThread(threadId: string): void; /** * Get the currently active thread */ getCurrentThread(): ChatbotThread | undefined; /** * Get all available threads */ getThreads(): ChatbotThread[]; /** * Set available modules for the chatbot */ setModules(modules: ChatbotModule[]): void; /** * Select specific modules by their IDs */ selectModules(moduleIds: string[]): void; /** * Toggle a module's selection state */ toggleModule(moduleId: string): void; /** * Get currently selected modules */ getSelectedModules(): ChatbotModule[]; /** * Set suggestion chips for user interaction */ setSuggestions(suggestions: ChatbotSuggestion[]): void; /** * Clear all suggestions */ clearSuggestions(): void; /** * Called before sending message - override to transform or validate */ protected beforeMessageSent(text: string, _options?: SendMessageOptions): Promise; /** * Called after message is sent - override for custom logic */ protected afterMessageSent(message: ChatbotMessage): Promise; /** * Called before provider call - override for custom logic */ protected beforeProviderCall(message: ChatbotMessage): Promise; /** * Called after provider call - override for custom logic */ protected afterProviderCall(): Promise; /** * Handle provider error - override to customize error handling */ protected handleProviderError(error: Error): Promise; /** * Handle validation error - override to customize */ protected handleValidationError(error: ValidationError): void; /** * Handle general error - override to customize */ protected handleError(error: Error): void; /** * Register a new plugin with the chatbot */ registerPlugin(plugin: ChatbotPlugin): void; /** * Unregister a plugin by ID */ unregisterPlugin(pluginId: string): void; /** * Get a registered plugin by ID */ getPlugin(pluginId: string): T | undefined; /** * Set the AI provider for the chatbot */ setProvider(provider: ChatbotProvider): void; /** * Set the storage adapter for persisting chatbot state */ setStorage(storage: ChatbotStorage): void; /** * Save current state to storage */ saveToStorage(key?: string): Promise; /** * Load state from storage */ loadFromStorage(key?: string): Promise; /** * Subscribe to an event * @returns Unsubscribe function */ on(event: string, handler: (...args: any[]) => void): () => void; /** * Emit an event */ emit(event: string, data?: any): void; /** * Get current chatbot state (readonly) */ getState(): Readonly; /** * Update chatbot state (use with caution) */ setState(updates: Partial): void; /** * Load conversations from external source (API, database, etc.) * This is a helper method that processes messages through plugins */ loadConversations(threads: ChatbotThread[]): void; /** * Auto-load conversations from provider if it has loadConversations method * This is called automatically when provider connects */ protected autoLoadConversations(provider?: ChatbotProvider): Promise; /** * Set or update UI callback functions */ setUICallbacks(callbacks: ChatbotUICallbacks): void; /** * Get chatbot configuration (readonly) */ getConfig(): Readonly; /** * Update chatbot configuration * Merges the provided partial config with existing config */ updateConfig(partialConfig: Partial): void; /** * Set typing indicator state */ setTyping(isTyping: boolean): void; /** * Set dynamic status text shown beside the loading indicator */ setStatusText(text: string): void; /** * Clear the dynamic status text */ clearStatusText(): void; /** * Get context for provider calls */ protected getContext(): ChatbotContext; /** * Destroy the chatbot controller and clean up resources */ destroy(): void; protected generateId(prefix: string): string; protected formatFileSize(bytes: number): string; protected log(...args: any[]): void; protected logError(...args: any[]): void; } //# sourceMappingURL=chatbot-core.controller.d.ts.map