/** * Session Manager - Manages OpenClaw agent sessions * * Each session is identified by a SessionKey and maintains: * - Conversation history (transcript) * - Token count * - State (idle, active, paused, error) */ import type { ChannelScope, Session, SessionKey, SessionState } from "./types/index.js"; /** Session manager options */ export interface SessionManagerOptions { /** Session storage directory */ sessionDir: string; /** Daily reset hour (0-23) */ dailyResetHour?: number; /** Idle timeout in minutes */ idleMinutes?: number; } /** Session manager */ export declare class SessionManager { private sessionDir; private dailyResetHour; private idleMinutes; private sessions; private index; private indexPath; private saveTimeout?; constructor(options: SessionManagerOptions); /** Initialize session manager */ initialize(): Promise; private loadIndex; /** Save sessions index (debounced) */ private scheduleSave; private saveIndex; /** Build session key */ buildSessionKey(agentId: string, channel: string, scope: ChannelScope, identifier: string): SessionKey; /** Parse session key */ parseSessionKey(key: SessionKey): { agentId: string; channel: string; scope: ChannelScope; identifier: string; }; /** Get or create session */ getOrCreateSession(agentId: string, channel: string, scope: ChannelScope, identifier: string): Promise; private createSession; /** Generate unique session ID */ private generateSessionId; /** Get session by key */ getSession(key: SessionKey): Session | undefined; /** Get all active sessions */ getActiveSessions(): Session[]; /** Get sessions for agent */ getSessionsForAgent(agentId: string): Session[]; /** Update session activity */ touchSession(key: SessionKey): void; /** Update session state */ setSessionState(key: SessionKey, state: SessionState): void; /** Increment message count */ incrementMessageCount(key: SessionKey): void; /** Update token count */ updateTokenCount(key: SessionKey, tokens: number): void; /** Append message to transcript */ appendToTranscript(key: SessionKey, message: TranscriptEntry): Promise; /** Load transcript for session */ loadTranscript(key: SessionKey): Promise; /** Reset session (clear transcript, keep metadata) */ resetSession(key: SessionKey): Promise; /** Close and remove session */ closeSession(key: SessionKey): Promise; /** Check if session should be reset (daily reset) */ shouldDailyReset(session: Session): boolean; /** Check if session is idle (timeout) */ isIdle(session: Session): boolean; /** Cleanup old/idle sessions */ cleanup(): Promise; /** Get session statistics */ getStats(): { total: number; active: number; idle: number; totalMessages: number; totalTokens: number; }; } /** Transcript entry types */ export interface TranscriptEntry { id: string; parentId?: string; timestamp: string; type: "user" | "assistant" | "tool_call" | "tool_result" | "system"; content: unknown; metadata?: Record; } /** Build session key helper */ export declare function buildSessionKey(agentId: string, channel: string, scope: ChannelScope, identifier: string): SessionKey; //# sourceMappingURL=sessions.d.ts.map