UNPKG

@agentman/chat-widget

Version:

Agentman Chat Widget for easy integration with web applications

117 lines (116 loc) 3.63 kB
import type { Message } from '../types/types'; import type { StateManager } from '../StateManager'; import type { ViewManager } from '../components/ViewManager'; import type { PersistenceManager } from '../PersistenceManager'; import type { ApiService } from '../services/ApiService'; import type { MessageService } from '../services/MessageService'; import type { AgentService } from '../services/AgentService'; import type { ErrorHandler } from './ErrorHandler'; import type { EventBus } from '../utils/EventBus'; /** * MessageHandler - Orchestrates message flow and UI updates * * This handler manages: * - Message sending flow * - Response processing * - Loading state management * - Message view updates * - Error handling for message operations */ export declare class MessageHandler { private stateManager; private viewManager; private apiService; private messageService; private agentService; private errorHandler; private eventBus; private persistenceManager; private config; private logger; private lastMessageCount; private isProcessingMessage; private loadingManager; private unifiedLoadingManager; private currentLoadingOperation; constructor(stateManager: StateManager, viewManager: ViewManager, apiService: ApiService, messageService: MessageService, agentService: AgentService, errorHandler: ErrorHandler, eventBus: EventBus, persistenceManager: PersistenceManager | null, config: { streaming?: { enabled?: boolean; }; debug?: boolean; }, debug?: boolean); /** * Send a message through the complete flow */ sendMessage(message: string, conversationId: string, config: { agentToken: string; clientMetadata?: any; attachmentFileIds?: string[]; attachmentUrls?: string[]; }): Promise<void>; /** * Process initial response (e.g., from agent initialization) */ handleInitialResponse(responseData: any[]): Promise<void>; /** * Handle API response with messages */ handleApiResponse(responseData: any[], conversationId: string): Promise<void>; /** * Add a message to the view and state */ addMessageToView(message: Message): Promise<void>; /** * Show loading indicator (delegated to LoadingManager) */ showLoadingIndicator(): void; /** * Hide loading indicator (delegated to LoadingManager) */ hideLoadingIndicator(): void; /** * Reset message count (e.g., when switching conversations) */ resetMessageCount(): void; /** * Update message count (e.g., when loading conversation) */ setMessageCount(count: number): void; /** * Get current message count */ getMessageCount(): number; /** * Check if currently processing a message */ isProcessing(): boolean; /** * Clear all messages from view */ clearMessages(): void; /** * Load messages into view (e.g., when switching conversations) */ loadMessages(messages: Message[]): void; /** * Handle prompt click from welcome screen */ handlePromptClick(prompt: string, conversationId: string, config: any): Promise<void>; /** * Save conversation state */ private saveConversation; /** * Schedule conversation save with debouncing */ private saveDebounceTimer; private scheduleConversationSave; /** * Setup unified loading event listeners */ private setupUnifiedLoadingListeners; /** * Clean up resources */ destroy(): void; }