langflow-chatbot
Version:
Add a Langflow-powered chatbot to your website.
64 lines (63 loc) • 3.1 kB
TypeScript
import { LangflowChatClient, ChatMessageData } from '../clients/LangflowChatClient';
import { Logger } from '../utils/logger';
import { SenderConfig } from '../types';
/** Callbacks for UI display operations required by the ChatSessionManager. */
export interface SessionManagerDisplayCallbacks {
/** Clears all messages from the display. */
clearMessages: () => void;
/** Adds a message to the display. */
addMessage: (sender: string, message: string, isThinking?: boolean, datetime?: string) => HTMLElement | null;
/** Scrolls the chat display to the bottom. */
scrollChatToBottom: () => void;
}
/**
* Manages chat sessions, including session ID state and chat history loading/display.
*/
export declare class ChatSessionManager {
private client;
private config;
private displayCallbacks;
private logger;
private _currentSessionId;
private _isHistoryLoaded;
private welcomeMessage?;
/**
* Constructs a ChatSessionManager instance.
* @param client The LangflowChatClient for API interactions.
* @param config Configuration for sender names.
* @param displayCallbacks Callbacks for UI display operations.
* @param logger Logger instance.
* @param initialSessionId Optional initial session ID to load history for.
* @param welcomeMessage Optional message to display if chat history is empty.
*/
constructor(client: LangflowChatClient, config: SenderConfig, displayCallbacks: SessionManagerDisplayCallbacks, logger: Logger, initialSessionId?: string, welcomeMessage?: string);
/** Gets the current session ID. */
get currentSessionId(): string | null;
/** Indicates if the history for the current session has been loaded. */
get isHistoryLoaded(): boolean;
/**
* Updates the current session ID and resets the history loaded flag.
* @param newSessionId The new session ID, or null to clear the session.
*/
updateCurrentSessionId(newSessionId: string | null): void;
/**
* Processes a session ID update that originated from a flow response.
* This typically updates the internal session ID but does not automatically trigger history loading,
* as the flow itself might manage message display or further interactions.
* @param newSessionId The new session ID from the flow.
*/
processSessionIdUpdateFromFlow(newSessionId: string): void;
/**
* Loads and displays chat history messages.
* This method clears existing messages before displaying the new history.
* It determines sender types based on configuration and message data.
* @param history An array of ChatMessageData objects representing the history.
*/
loadAndDisplayHistory(history: ChatMessageData[]): Promise<void>;
/**
* Sets the session ID and loads/displays its history.
* If no session ID is provided (or it's empty), the current session is cleared.
* @param sessionId The session ID to set. If undefined or empty, clears the session.
*/
setSessionIdAndLoadHistory(sessionId?: string): Promise<void>;
}