/** * Session store for messenger conversations * * Manages conversation sessions with rolling context (history) * for cross-platform messenger integration. */ import type { SQLiteDatabase } from '../sqlite.js'; import type { Session, MessageSource, ConversationTurn } from './types.js'; /** * SQLite-backed session store for messenger conversations */ export declare class SessionStore { private db; private maxTurns; constructor(db: SQLiteDatabase, options?: { maxTurns?: number; }); /** * Run database migration */ private runMigration; /** * Get existing session or create new one */ getOrCreate(source: MessageSource, channelId: string, userId?: string, channelName?: string): Session; /** * Get session by ID */ getById(sessionId: string): Session | null; /** * Update session with new conversation turn */ updateSession(sessionId: string, userMessage: string, botResponse: string): boolean; /** * Append a single message (user or assistant) to session history. * - role='user': creates a new turn with empty bot * - role='assistant': fills bot field of last incomplete turn, or creates new turn */ appendMessage(sessionId: string, msg: { role: 'user' | 'assistant'; content: string; timestamp: number; }): boolean; /** * Flush streaming response to the last incomplete turn. * Called periodically during streaming to persist partial assistant responses. */ flushStreamingResponse(sessionId: string, accumulatedText: string): boolean; /** * Get conversation history for a session by ID */ getHistory(sessionId: string): ConversationTurn[]; /** * Get conversation history by source and channel * Used by WebSocket handler for viewer sessions */ getHistoryByChannel(source: MessageSource, channelId: string): ConversationTurn[]; /** * Clear session context (start fresh) */ clearContext(sessionId: string): boolean; /** * Delete a session */ deleteSession(sessionId: string): boolean; /** * List all sessions for a source */ listSessions(source?: MessageSource): Session[]; /** * Update channel name for a session by source and channel ID * Used to backfill channel names when gateway connects */ updateChannelName(source: MessageSource, channelId: string, channelName: string): boolean; /** * Delete inactive sessions older than specified age */ cleanupInactiveSessions(maxAgeMs: number): number; /** * Get the most recently active session for a specific source */ getLastActiveSession(source?: MessageSource): Session | null; /** * Format context as readable string for system prompt * Only includes the most recent turns to avoid token bloat */ formatContextForPrompt(sessionId: string, maxTurnsToInject?: number): string; /** * Convert database row to Session object */ private rowToSession; /** * Close database connection */ close(): void; } //# sourceMappingURL=session-store.d.ts.map