export type TurnStatus = 'processing' | 'completed' | 'superseded'; export interface LedgerTurn { turnIndex: number; userMessageTs: string; userMessageText: string; statusMessageTs: string | null; responseMessageTimestamps: string[]; executionId: string | null; backupPath: string | null; status: TurnStatus; createdAt: string; updatedAt: string; } export interface ChannelConversation { sessionId: string | null; sessionName: string | null; backend: string; /** Profile name used when the conversation was created or switched — needed * by !new / pre-close hooks to resume the session with the same profile. */ profileName: string | null; turns: LedgerTurn[]; updatedAt: string; } export type LedgerData = Record; export declare class ConversationLedgerRepo { private repo; getConversation(channel: string): Promise; findTurn(channel: string, userMessageTs: string): Promise<{ conversation: ChannelConversation; turn: LedgerTurn; turnIndex: number; } | null>; initConversation(channel: string, opts: { sessionId: string | null; sessionName: string | null; backend: string; profileName?: string | null; }): Promise; updateSessionId(channel: string, sessionId: string): Promise; beginTurn(channel: string, opts: { userMessageTs: string; userMessageText: string; statusMessageTs?: string | null; backupPath?: string | null; }): Promise; addResponseTs(channel: string, userMessageTs: string, responseTs: string): Promise; completeTurn(channel: string, userMessageTs: string, opts?: { executionId?: string | null; }): Promise; rollbackTo(channel: string, turnIndex: number): Promise<{ supersededTurns: LedgerTurn[]; conversation: ChannelConversation; } | null>; truncateTurns(channel: string, fromIndex: number): Promise; clearConversation(channel: string): Promise; switchSession(channel: string, opts: { sessionId: string; sessionName: string | null; backend: string; profileName?: string | null; }): Promise; /** * Atomic init-if-missing + beginTurn. Captures the turn index under mutex * so callers can safely pass it to sessionBackup.createBackup. * Returns { turn, turnIndex } for the caller. */ initAndBeginTurn(channel: string, opts: { sessionId: string | null; sessionName: string | null; backend: string; profileName?: string | null; userMessageTs: string; userMessageText: string; statusMessageTs: string; }): Promise<{ turn: LedgerTurn; turnIndex: number; }>; /** Set the backup path on the turn identified by userMessageTs. */ setBackupPath(channel: string, userMessageTs: string, backupPath: string | null): Promise; /** Drop the in-memory cache so the next read() fetches from disk. For testing. */ invalidate(): void; /** Wait for any in-flight mutate() to complete. For graceful SIGTERM drain. */ flush(): Promise; } export declare const conversationLedger: ConversationLedgerRepo;