@agentman/chat-widget
Version:
Agentman Chat Widget for easy integration with web applications
219 lines (218 loc) • 5.59 kB
TypeScript
import type { ChatConfig, ChatState, ChatTheme, ChatAssets, Message } from '../types/types';
import { InputComponent } from './InputComponent';
/**
* ConversationView Component - Traditional chat interface
*
* Features:
* - Header with title and controls
* - Scrollable messages area
* - Input area with prompts
* - File attachments support
*/
export declare class ConversationView {
private config;
private theme;
private assets;
private element;
private boundToggleHandler;
private boundExpandHandler?;
private boundSendHandler;
private boundInputKeyHandler;
private boundPromptClickHandler?;
private boundAttachmentClickHandler?;
private boundFileSelectHandler?;
private boundAttachmentRemoveHandler?;
private cachedElements;
private messageRenderer;
private domRenderer;
private loadingMessageElement;
private inputComponent;
private scrollManager;
private disclaimerUpdateTimer;
constructor(config: ChatConfig, theme: ChatTheme, assets: ChatAssets, eventHandlers: {
onToggle: () => void;
onExpand?: () => void;
onSend: () => void;
onInputKey: (e: KeyboardEvent) => void;
onPromptClick?: (prompt: string) => void;
onAttachmentClick?: () => void;
onFileSelect?: (files: FileList) => void;
onAttachmentRemove?: (fileId: string) => void;
});
/**
* Create and return the conversation view DOM element
*/
create(): HTMLElement;
/**
* Update UI based on state changes
*/
updateUI(_state: ChatState): void;
/**
* Update theme colors
*/
updateTheme(theme: Partial<ChatTheme>): void;
/**
* Get specific DOM elements with caching
*/
getElement(selector: string): HTMLElement | null;
/**
* Get the messages container
*/
getMessagesContainer(): HTMLElement | null;
/**
* Get the input element
*/
getInputElement(): HTMLTextAreaElement | null;
/**
* Get the input value
*/
getInputValue(): string;
/**
* Clear the input
*/
clearInput(): void;
/**
* Focus the input
*/
focusInput(): void;
/**
* Hide message prompts
*/
hideMessagePrompts(): void;
/**
* Show message prompts
*/
showMessagePrompts(): void;
/**
* Update attachment preview
*/
updateAttachmentPreview(attachments: Record<string, unknown>[]): void;
/**
* Clear file input
*/
clearFileInput(): void;
/**
* Get the input component instance
*/
getInputComponent(): InputComponent | null;
/**
* Get the header element for dynamic button management
*/
getHeaderElement(): HTMLElement | null;
/**
* Update header buttons dynamically based on conversation state
*/
updateHeaderButtons(conversationManager: any, hasConversations: boolean): void;
/**
* Clear dynamic buttons from header while preserving static ones
*/
private clearDynamicButtons;
/**
* Add a message to the conversation view
*/
addMessage(message: Message): Promise<void>;
/**
* Render message attachments HTML
*/
private renderMessageAttachments;
/**
* Show loading indicator
*/
showLoadingIndicator(): void;
/**
* Hide loading indicator
*/
hideLoadingIndicator(): void;
/**
* Update an existing message (for streaming)
*/
updateMessage(message: Message): void;
/**
* Check if a message exists (for streaming)
*/
hasMessage(messageId: string): boolean;
/**
* Clear all messages from the view
*/
clearMessages(): void;
/**
* Destroy the component and clean up
*/
destroy(): void;
/**
* Generate the conversation view HTML template
*/
private generateTemplate;
/**
* Generate header HTML - basic structure with dynamic button management
*/
private generateHeader;
/**
* Generate messages area HTML
*/
private generateMessagesArea;
/**
* Generate input area HTML - using shared InputComponent
*/
private generateInputArea;
/**
* Escape HTML to prevent XSS
*/
private escapeHtml;
/**
* Generate message prompts HTML
*/
private generateMessagePrompts;
/**
* Generate attachment button and file input
*/
private generateAttachmentButton;
/**
* Generate attachment preview container
*/
private generateAttachmentPreview;
/**
* Generate branding HTML - no longer includes disclaimer
*/
private generateBranding;
/**
* Update or add disclaimer after messages (debounced)
*/
private updateDisclaimerInMessages;
/**
* Perform the actual disclaimer update
*/
private performDisclaimerUpdate;
/**
* Attach event listeners - matches original ChatWidget exactly
*/
private attachEventListeners;
/**
* Remove event listeners
*/
private removeEventListeners;
/**
* Handle prompt button clicks
*/
private handlePromptClick;
/**
* Update header styling
*/
private updateHeaderStyling;
/**
* Update input area styling
*/
private updateInputStyling;
/**
* Create and mount the input component
*/
private createInputComponent;
/**
* Apply theme to the component
*/
private applyTheme;
/**
* Get appropriate icon for file type
*/
private getFileTypeIcon;
}