import type { AgentMessage } from '@earendil-works/pi-agent-core'; import type { Api, Model } from '@earendil-works/pi-ai/compat'; import type { Config } from '../config/schema.js'; import { type CompactionConfig, type CompactionExecutionOptions, type CompactionResult } from '../agent/memory/compaction.js'; import { type WindowConfig } from '../agent/memory/window.js'; import { type SessionMetadataSeed } from '../storage/sqlite/index.js'; import type { XopcSessionTranscriptV1 } from './transcript-format.js'; import { type TranscriptStoredRow, type XopcTranscriptContextEntry } from './session-context-for-llm.js'; import type { SessionMetadata, SessionDetail, SessionListQuery, PaginatedResult, GlobalSessionStats, ExportFormat, CompactionBoundarySummary } from './types.js'; import { SessionStatus } from './types.js'; import type { Message } from './types.js'; import type { SessionTranscriptUpdate } from './transcript-events.js'; export interface SessionStoreOptions { config: Config; } export interface SessionCompactionHooks { before?: (event: { sessionKey: string; messageCount: number; tokenCount: number; }) => Promise | void; after?: (event: { sessionKey: string; messageCount: number; tokenCount: number; compactedCount: number; }) => Promise | void; } export type ModelFallbackPreparation = 'prompt' | 'resume' | 'unsafe'; export declare class SessionStore { private options; private window; private compactor; private compactionHooks; constructor(options: SessionStoreOptions, windowConfig?: Partial, compactionConfig?: Partial); setCompactionHooks(hooks: SessionCompactionHooks): void; private runCompactionHook; private resolveWorkspaceCwd; private runStoreMutation; initialize(): Promise; getSessionsRoot(): string; resolveTranscriptPath(sessionKey: string, options?: { metadata?: SessionMetadataSeed; }): Promise<{ sessionId: string; sessionKey: string; }>; appendTranscriptMessage(sessionKey: string, message: AgentMessage, options?: { metadata?: SessionMetadataSeed; }): Promise; getByAgent(agentId: string): Promise; getByAccount(accountId: string): Promise; getByPeer(peerKind: string, peerId: string): Promise; getMainSession(channel: string, accountId: string): Promise; refreshIndex(): Promise; list(query?: SessionListQuery): Promise>; get(key: string, options?: { includeTranscriptSummary?: boolean; includeTranscriptRows?: boolean; }): Promise; getMessagePage(key: string, options?: { offset?: number; limit?: number; before?: string; includeTranscriptSummary?: boolean; includeTranscriptRows?: boolean; includeContextRows?: boolean; }): Promise<{ session: SessionDetail; pagination: { total: number; limit: number; offset: number; hasMore: boolean; before?: string; nextBeforeCursor?: string; }; } | null>; private buildSessionDetail; loadTranscriptRows(key: string): Promise; loadTranscriptHistoryRows(key: string): Promise; prepareModelFallback(key: string, rowsBeforeAttempt: readonly TranscriptStoredRow[]): Promise; getMetadata(key: string): Promise; resolveKeyBySessionId(sessionId: string): Promise; updateMetadata(key: string, updates: Partial): Promise; reset(key: string): Promise<{ sessionId: string; previousSessionId: string; } | null>; delete(key: string): Promise; deleteMany(keys: string[]): Promise<{ success: string[]; failed: string[]; }>; setStatus(key: string, status: SessionStatus): Promise; archive(key: string): Promise; unarchive(key: string): Promise; pin(key: string): Promise; unpin(key: string): Promise; loadMessages(_key: string, _options?: { fromArchive?: boolean; }): Promise; loadTranscriptDocument(key: string): Promise; syncEmbeddedTranscriptUpdate(update: SessionTranscriptUpdate): Promise; appendTranscriptContextEntry(key: string, entry: Omit & Partial>): Promise; appendTranscriptLabelEntry(key: string, entry: { targetId: string; label?: string; }): Promise; appendTranscriptCustomEntry(key: string, entry: { customType: string; data?: unknown; }): Promise; appendTranscriptCustomMessageEntry(key: string, entry: { customType: string; content?: string | unknown[]; display?: boolean; details?: unknown; }): Promise; appendTranscriptBashExecutionEntry(key: string, entry: { command: string; output?: string; exitCode?: number | null; signal?: string | null; excludeFromContext?: boolean; truncated?: boolean; fullOutputPath?: string; }): Promise; saveMessages(key: string, messages: AgentMessage[], options?: { metadata?: SessionMetadataSeed; }): Promise; deleteUserRound(key: string, userRoundIndex: number): Promise<{ deleted: number; removedMessages: AgentMessage[]; remainingMessages: AgentMessage[]; } | null>; getWindowStats(messages: AgentMessage[]): { total: number; system: number; user: number; assistant: number; tool: number; needsTrim: boolean; }; applyCompaction(key: string, messages: AgentMessage[], result: CompactionResult): Promise; compact(key: string, messages: AgentMessage[], model: Model, instructions?: string, force?: boolean, executionOptions?: CompactionExecutionOptions): Promise; getCompactionStats(key: string): Promise<{ compactionCount: number; totalTokensBefore: number; totalTokensAfter: number; lastCompactionAt: string; }>; listCompactionBoundaries(key: string): Promise; restoreBeforeCompactionBoundary(key: string, compactionId: string): Promise; deleteSession(key: string): Promise; load(key: string, options?: { fromArchive?: boolean; }): Promise; estimateTokenUsage(_key: string, messages: AgentMessage[]): Promise; searchInSession(key: string, keyword: string): Promise; exportSession(key: string, format: ExportFormat): Promise; importSessionExport(targetKey: string, jsonContent: string): Promise<{ sessionKey: string; rowCount: number; }>; forkSession(sourceKey: string, targetKey: string): Promise<{ sessionKey: string; rowCount: number; }>; forkSessionRows(sourceKey: string, targetKey: string, options?: { throughRow?: number; }): Promise<{ sessionKey: string; rowCount: number; }>; getStats(): Promise; archiveOld(olderThanDays: number): Promise; estimateTokens(messages: AgentMessage[]): number; private loadDisplayMessages; private paginateDisplayMessages; private messageContent; private extractTextContent; private injectPostCompactionContext; private convertMessages; }