import EventEmitter from 'events';
import { SessionStore } from './store.js';
import type { SessionMetadata, SessionDetail, SessionListQuery, PaginatedResult, GlobalSessionStats, ExportFormat, SessionStatus } from './types.js';
import type { Message } from './types.js';
import type { CompactionConfig, CompactionResult } from '../agent/memory/compaction.js';
import type { XopcSessionTranscriptV1 } from './transcript-format.js';
import type { XopcTranscriptContextEntry } from './session-context-for-llm.js';
import { type SessionPatchBody } from './patch-metadata.js';
import type { WindowConfig } from '../agent/memory/window.js';
import type { Config } from '../config/schema.js';
export interface SessionIndexConfig {
    config: Config;
    agentId?: string;
    sessionsDir?: string;
    windowConfig?: Partial<WindowConfig>;
    compactionConfig?: Partial<CompactionConfig>;
}
export declare class SessionIndex extends EventEmitter {
    private store;
    constructor(config: SessionIndexConfig);
    initialize(): Promise<void>;
    /** Low-level store (e.g. cron resolving weixin delivery from session index). */
    getStore(): SessionStore;
    listSessions(query?: SessionListQuery): Promise<PaginatedResult<SessionMetadata>>;
    /**
     * List all subagent sessions.
     * Subagent sessions have keys starting with 'subagent:'.
     */
    listSubagents(query?: SessionListQuery): Promise<PaginatedResult<SessionMetadata>>;
    getSession(key: string, options?: {
        includeTranscriptSummary?: boolean;
        includeTranscriptRows?: boolean;
    }): Promise<SessionDetail | null>;
    getSessionMessagePage(key: string, options?: {
        offset?: number;
        limit?: number;
        before?: string;
        includeTranscriptSummary?: boolean;
        includeTranscriptRows?: boolean;
    }): Promise<{
        session: SessionDetail;
        pagination: {
            total: number;
            limit: number;
            offset: number;
            hasMore: boolean;
            before?: string;
            nextBeforeCursor?: string;
        };
    } | null>;
    /**
     * OpenClaw-style `sessions.patch`: partial metadata (name, tags, customData shallow merge).
     */
    patchSession(key: string, patch: SessionPatchBody): Promise<{
        ok: true;
    } | {
        ok: false;
        error: string;
    }>;
    getSessionMetadata(key: string): Promise<SessionMetadata | null>;
    deleteSession(key: string): Promise<boolean>;
    deleteSessions(keys: string[]): Promise<{
        success: string[];
        failed: string[];
    }>;
    renameSession(key: string, name: string): Promise<void>;
    /** Partial metadata update (caller merges nested fields like `customData` when needed). */
    updateSessionMetadata(key: string, updates: Partial<SessionMetadata>): Promise<void>;
    tagSession(key: string, tags: string[]): Promise<void>;
    untagSession(key: string, tags: string[]): Promise<void>;
    setSessionTags(key: string, tags: string[]): Promise<void>;
    archiveSession(key: string): Promise<void>;
    unarchiveSession(key: string): Promise<void>;
    pinSession(key: string): Promise<void>;
    unpinSession(key: string): Promise<void>;
    setSessionStatus(key: string, status: SessionStatus): Promise<void>;
    searchSessions(query: string): Promise<SessionMetadata[]>;
    searchInSession(key: string, keyword: string): Promise<Message[]>;
    exportSession(key: string, format: ExportFormat): Promise<string>;
    getStats(): Promise<GlobalSessionStats>;
    archiveOldSessions(olderThanDays: number): Promise<number>;
    onSessionCreated(callback: (metadata: SessionMetadata) => void): void;
    onSessionUpdated(callback: (data: {
        key: string;
        name?: string;
        tags?: string[];
    }) => void): void;
    onSessionDeleted(callback: (data: {
        key: string;
    }) => void): void;
    onSessionArchived(callback: (data: {
        key: string;
    }) => void): void;
    onSessionRestored(callback: (data: {
        key: string;
    }) => void): void;
    onSessionPinned(callback: (data: {
        key: string;
    }) => void): void;
    onSessionUnpinned(callback: (data: {
        key: string;
    }) => void): void;
    onSessionStatusChanged(callback: (data: {
        key: string;
        status: SessionStatus;
    }) => void): void;
    onSessionAccessed(callback: (data: {
        key: string;
    }) => void): void;
    /** Load messages for a session key */
    loadMessages(key: string): Promise<import("@earendil-works/pi-agent-core").AgentMessage[]>;
    /** Wrapped transcript document (stable id, compaction history); null if missing or not a valid envelope. */
    loadTranscriptDocument(key: string): Promise<XopcSessionTranscriptV1 | null>;
    /**
     * Runtime turns must use PiTranscriptManager.appendMessage; this entry point
     * is reserved for compaction, tests, and admin tools.
     */
    saveMessages(key: string, messages: any[]): Promise<void>;
    /**
     * Append `kind: 'context'` transcript row (persisted, excluded from {@link loadMessages} / LLM).
     */
    appendTranscriptContextEntry(key: string, entry: Omit<XopcTranscriptContextEntry, 'kind'> & Partial<Pick<XopcTranscriptContextEntry, 'kind'>>): Promise<void>;
    /** Delete session data */
    delete(key: string): Promise<void>;
    /** Archive transcript and start a new session id for the same key. */
    resetSession(key: string): Promise<{
        sessionId: string;
        previousSessionId: string;
    } | null>;
    /** Token/window stats for a message list */
    getWindowStats(messages: any[]): {
        total: number;
        system: number;
        user: number;
        assistant: number;
        tool: number;
        needsTrim: boolean;
    };
    /** Prepare compaction run */
    prepareCompaction(key: string, messages: any[], contextWindow: number): {
        needsCompaction: boolean;
        messages: import("@earendil-works/pi-agent-core").AgentMessage[];
        stats?: ReturnType<any>;
    };
    /** Compact session messages */
    compact(key: string, messages: any[], contextWindow: number, instructions?: string, force?: boolean): Promise<CompactionResult>;
    /** Compaction stats for a session */
    getCompactionStats(key: string): Promise<{
        compactionCount: number;
        totalTokensBefore: number;
        totalTokensAfter: number;
        lastCompactionAt: any;
    }>;
    /** List pre-compaction transcript snapshots (newest first). */
    listCompactionCheckpoints(key: string): Promise<import("./types.js").CompactionCheckpointSummary[]>;
    getCompactionCheckpointDetail(key: string, checkpointId: string): Promise<import("./types.js").CompactionCheckpointDetail>;
    restoreCompactionCheckpoint(key: string, checkpointId: string): Promise<void>;
    /** Estimate token usage for messages */
    estimateTokenUsage(key: string, messages: any[]): Promise<number>;
}
