UNPKG

@agentman/chat-widget

Version:

Agentman Chat Widget for easy integration with web applications

126 lines (125 loc) 3.47 kB
import type { ViewManager } from '../components/ViewManager'; import type { EventBus } from '../utils/EventBus'; import type { ErrorHandler } from './ErrorHandler'; /** * FileHandler - Manages file operations and attachment handling * * This handler manages: * - File selection and validation * - File upload operations with progress tracking * - Attachment preview and removal * - File type and size validation * - Upload error handling and retry logic */ export declare class FileHandler { private viewManager; private eventBus; private errorHandler; private apiUrl; private agentToken; private logger; private loadingManager; private activeUploads; private uploadProgress; private attachments; private uploadedFileIds; private readonly MAX_FILE_SIZE; private readonly DEFAULT_ALLOWED_TYPES; private supportedMimeTypes; private getConversationId; private ensureConversation; constructor(viewManager: ViewManager, eventBus: EventBus, errorHandler: ErrorHandler, apiUrl: string, agentToken: string, debug?: boolean, getConversationId?: () => string | null, ensureConversation?: () => string); /** * Handle file selection from input */ handleFileSelection(files: FileList): void; /** * Process a selected file (validation + upload) */ private processSelectedFile; /** * Get MIME type from file extension as fallback */ private getMimeTypeFromExtension; /** * Validate file size and type, returns the correct MIME type */ private validateFileAndGetMimeType; /** * Validate file size and type (legacy method for compatibility) */ private validateFile; /** * Upload file with progress tracking */ private uploadFile; /** * Upload with progress tracking using XMLHttpRequest */ private uploadWithProgress; /** * Remove an attachment */ removeAttachment(fileId: string): void; /** * Get all current attachments */ getAttachments(): Record<string, any>[]; /** * Get uploaded file IDs for sending with messages */ getUploadedFileIds(): string[]; /** * Get uploaded file URLs for sending with messages (deprecated - use getUploadedFileIds) * @deprecated Use getUploadedFileIds instead */ getUploadedFileUrls(): string[]; /** * Clear all attachments */ clearAllAttachments(): void; /** * Update supported MIME types from agent capabilities */ updateSupportedMimeTypes(mimeTypes: string[]): void; /** * Check if files are currently uploading */ isUploading(): boolean; /** * Get upload progress for a specific file */ getUploadProgress(fileId: string): number; /** * Generate unique file ID */ private generateFileId; /** * Get file error type from error */ private getFileErrorType; /** * Get attachment status */ private getAttachmentStatus; /** * Get file type from MIME type */ private getFileTypeFromMimeType; /** * Update attachment preview in UI */ private updateAttachmentPreview; /** * Update upload progress in UI */ private updateUploadProgress; /** * Update attachment with upload result */ private updateAttachmentResult; /** * Clean up resources */ destroy(): void; }