@agentman/chat-widget
Version:
Agentman Chat Widget for easy integration with web applications
195 lines (194 loc) • 5.63 kB
TypeScript
import type { ChatConfig, ChatState, ChatTheme, ChatAssets } from '../types/types';
import { WelcomeScreen } from './WelcomeScreen';
import { InputBarSheetWelcomeView } from './InputBarSheetWelcomeView';
/**
* ViewManager - Handles view transitions and state management
*
* Responsibilities:
* - Switch between welcome screen and conversation view
* - Manage view transitions and animations
* - Coordinate event handling between views
* - Maintain consistent state across view changes
*/
export declare class ViewManager {
private config;
private theme;
private assets;
private container;
private isInputBarFullMode;
private currentView;
private isTransitioning;
private welcomeScreen;
private conversationView;
private toggleButton;
private lastConfiguredMimeTypes?;
private lastConfiguredSupportsAttachments?;
private eventHandlers;
constructor(config: ChatConfig, theme: ChatTheme, assets: ChatAssets, container: HTMLElement, 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;
onViewTransition?: (from: string, to: string) => void;
onConversationsClick?: () => void;
hasConversations?: () => boolean;
});
/**
* Get the current view type
*/
getCurrentView(): 'welcome' | 'conversation';
/**
* Check if currently transitioning between views
*/
isInTransition(): boolean;
/**
* Transition to conversation view (from welcome screen)
*/
transitionToConversation(): Promise<void>;
/**
* Transition back to welcome screen (for new conversation)
*/
transitionToWelcome(): Promise<void>;
/**
* Update the current view's UI state
*/
updateUI(state: ChatState): void;
/**
* Update theme for the current view
*/
updateTheme(theme: Partial<ChatTheme>): void;
/**
* Get the current input value from active view
*/
getInputValue(): string;
/**
* Clear the input in the active view
*/
clearInput(): void;
/**
* Focus the input in the active view
*/
focusInput(): void;
/**
* Get a DOM element from the current view
*/
getElement(selector: string): HTMLElement | null;
/**
* Get the messages container (conversation view only)
*/
getMessagesContainer(): HTMLElement | null;
/**
* Hide message prompts (conversation view only)
*/
hideMessagePrompts(): void;
/**
* Show message prompts (conversation view only)
*/
showMessagePrompts(): void;
/**
* Update attachment preview
*/
updateAttachmentPreview(attachments: Record<string, unknown>[]): void;
/**
* Clear file input
*/
clearFileInput(): void;
/**
* Destroy the view manager and clean up
*/
destroy(): void;
/**
* Initialize and show the welcome screen
*/
private showWelcomeScreen;
/**
* Perform animated transition between views
*/
private performViewTransition;
/**
* Get the root element of the current view
*/
getRootElement(): HTMLElement | null;
/**
* Create toggle button for corner variant
*/
createToggleButton(): HTMLElement | null;
/**
* Get the toggle button element
*/
getToggleButton(): HTMLElement | null;
/**
* Update toggle button visibility
*/
updateToggleButton(isOpen: boolean): void;
/**
* Update expand button state
*/
updateExpandButton(isExpanded: boolean): void;
/**
* Configure attachments for all input components
*/
configureAttachments(supportedMimeTypes: string[], supportsAttachments: boolean): void;
/**
* Add message to current view (if conversation view)
*/
addMessage(message: any): Promise<void>;
/**
* Update an existing message (for streaming)
*/
updateMessage(message: any): void;
/**
* Check if a message exists (for streaming)
*/
hasMessage(messageId: string): boolean;
/**
* Show loading indicator in conversation view
*/
showLoadingIndicator(): void;
/**
* Hide loading indicator in conversation view
*/
hideLoadingIndicator(): void;
/**
* Clear messages in conversation view
*/
clearMessages(): void;
/**
* Update conversation header buttons based on conversation state
*/
updateConversationHeader(conversationManager: any, hasConversations: boolean): void;
/**
* Get header element from current view
*/
getHeaderElement(): HTMLElement | null;
/**
* Get the main container element
*/
getContainer(): HTMLElement;
/**
* Get the current welcome screen instance
*/
getWelcomeScreen(): WelcomeScreen | InputBarSheetWelcomeView | null;
/**
* Refresh prompts in the current welcome screen (for dynamic URL-based prompts)
*/
refreshWelcomePrompts(): void;
/**
* Type guard to check if welcome screen is InputBarSheetWelcomeView
*/
private isInputBarSheetWelcomeView;
}
declare module './WelcomeScreen' {
interface WelcomeScreen {
getRootElement(): HTMLElement | null;
}
}
declare module './ConversationView' {
interface ConversationView {
getRootElement(): HTMLElement | null;
}
}