import { StoredSession, SessionFilter, SessionListResponse, SessionMetadata } from '../models/sessionSchema';
import { EntityStore } from '../agent/context/entityStore';
import { EnhancedSessionContext } from '../agent/context/enhancedSessionContext';
import { FocusStore, FocusStoreSnapshot } from '../agent/context/focusStore';
import { TraceAgentState } from '../agent/state/traceAgentState';
import type { SessionStateSnapshot } from '../agentv3/sessionStateSnapshot';
export declare function resolveSessionPersistenceDbPath(env?: NodeJS.ProcessEnv): string;
export declare class SessionPersistenceService {
    private db;
    private static instance;
    private constructor();
    static getInstance(): SessionPersistenceService;
    static resetForTests(): void;
    private initializeSchema;
    /**
     * Save a complete session to the database
     */
    saveSession(session: StoredSession): boolean;
    /**
     * Get a session by ID
     */
    getSession(sessionId: string): StoredSession | null;
    /**
     * List sessions with optional filtering
     */
    listSessions(filter?: SessionFilter): SessionListResponse;
    /**
     * Delete a session
     */
    deleteSession(sessionId: string): boolean;
    /**
     * Get all sessions for a specific trace
     */
    getSessionsByTrace(traceId: string): StoredSession[];
    /**
     * Export sessions as JSON for backup
     */
    exportSessions(traceId?: string): string;
    /**
     * Clean up old sessions (older than specified days)
     */
    cleanupOldSessions(daysToKeep?: number): number;
    /**
     * Save EntityStore snapshot for a session.
     * This enables entity cache restoration across process restarts.
     *
     * @param sessionId - The session ID
     * @param entityStore - The EntityStore to save
     * @returns true if save succeeded
     */
    saveEntityStore(sessionId: string, entityStore: EntityStore): boolean;
    /**
     * Load EntityStore for a session.
     * Returns null if session doesn't exist or has no EntityStore.
     *
     * @param sessionId - The session ID
     * @returns Deserialized EntityStore or null
     */
    loadEntityStore(sessionId: string): EntityStore | null;
    /**
     * Save full EnhancedSessionContext for a session.
     * This enables complete multi-turn state restoration.
     *
     * @param sessionId - The session ID
     * @param sessionContext - The EnhancedSessionContext to save
     * @returns true if save succeeded
     */
    saveSessionContext(sessionId: string, sessionContext: EnhancedSessionContext): boolean;
    /**
     * Load EnhancedSessionContext for a session.
     * Returns null if session doesn't exist or has no context snapshot.
     *
     * @param sessionId - The session ID
     * @returns Deserialized EnhancedSessionContext or null
     */
    loadSessionContext(sessionId: string): EnhancedSessionContext | null;
    /**
     * Check if a session has persisted EntityStore data.
     *
     * @param sessionId - The session ID
     * @returns true if EntityStore exists for this session
     */
    hasEntityStore(sessionId: string): boolean;
    /**
     * Check if a session has persisted SessionContext data.
     *
     * @param sessionId - The session ID
     * @returns true if SessionContext exists for this session
     */
    hasSessionContext(sessionId: string): boolean;
    /**
     * Save FocusStore snapshot for a session.
     * This restores focus-aware incremental analysis across restarts.
     */
    saveFocusStore(sessionId: string, focusStore: FocusStore): boolean;
    /**
     * Load FocusStore snapshot for a session.
     * Returns null if session doesn't exist or has no FocusStore snapshot.
     */
    loadFocusStore(sessionId: string): FocusStoreSnapshot | null;
    /**
     * Check if a session has persisted FocusStore data.
     */
    hasFocusStore(sessionId: string): boolean;
    /**
     * Save TraceAgentState snapshot for a session.
     * This is the durable single-source-of-truth state for goal-driven analysis.
     */
    saveTraceAgentState(sessionId: string, state: TraceAgentState): boolean;
    /**
     * Load TraceAgentState snapshot for a session.
     * Returns null if session doesn't exist or has no snapshot.
     */
    loadTraceAgentState(sessionId: string): TraceAgentState | null;
    /**
     * Check if a session has persisted TraceAgentState data.
     */
    hasTraceAgentState(sessionId: string): boolean;
    /**
     * Append messages to an existing session without deleting prior messages.
     * Used by agentv3 to populate the messages table after each turn.
     */
    appendMessages(sessionId: string, messages: Array<{
        id: string;
        role: string;
        content: string;
        timestamp: number;
        sqlResult?: any;
    }>): void;
    /**
     * Save architecture detection result for a session.
     * Prevents re-detection failures when trace_processor has unloaded the trace after idle.
     */
    saveArchitectureSnapshot(sessionId: string, architecture: any): boolean;
    /**
     * Load architecture detection result for a session.
     */
    loadArchitectureSnapshot(sessionId: string): any | null;
    /**
     * Atomically save a unified session state snapshot.
     *
     * Performs a single UPDATE metadata call that writes:
     * - sessionStateSnapshot (new format)
     * - runtimeArraysSnapshot (backward compat dual-write)
     * - architectureSnapshot (if present in snapshot)
     * - sessionContextSnapshot + entityStoreSnapshot (if sessionContext provided)
     * - focusStoreSnapshot (if provided)
     * - traceAgentStateSnapshot (if provided)
     *
     * Auto-creates the session record if it doesn't exist.
     * Replaces the 7 individual save*() calls that each did read-modify-write.
     */
    saveSessionStateSnapshot(sessionId: string, snapshot: SessionStateSnapshot, extras?: {
        sessionContext?: EnhancedSessionContext;
        focusStoreSnapshot?: FocusStoreSnapshot;
        traceAgentState?: TraceAgentState;
        owner?: {
            tenantId?: string;
            workspaceId?: string;
            userId?: string;
        };
    }): boolean;
    /**
     * Load a unified session state snapshot.
     *
     * V2 path: returns `metadata.sessionStateSnapshot` directly.
     * V1 fallback: reconstructs from `metadata.runtimeArraysSnapshot` for old sessions
     * (no DB migration needed).
     */
    loadSessionStateSnapshot(sessionId: string): SessionStateSnapshot | null;
    /**
     * Save runtime arrays snapshot for cross-restart report continuity.
     * Stores conversationSteps, dataEnvelopes, hypotheses, queryHistory,
     * and conclusionHistory that would otherwise be lost on backend restart.
     */
    saveRuntimeArrays(sessionId: string, snapshot: NonNullable<SessionMetadata['runtimeArraysSnapshot']>): boolean;
    /**
     * Load runtime arrays snapshot for a session.
     * Returns null if session doesn't exist or has no snapshot.
     */
    loadRuntimeArrays(sessionId: string): SessionMetadata['runtimeArraysSnapshot'] | null;
    getEntityStoreStats(sessionId: string): {
        frameCount: number;
        sessionCount: number;
        analyzedFrameCount: number;
        analyzedSessionCount: number;
    } | null;
}
export default SessionPersistenceService;
//# sourceMappingURL=sessionPersistenceService.d.ts.map