import Database from "better-sqlite3";
/** ULID-like server ID: time-sortable (monotonic within same ms), globally unique. */
export declare function generateServerId(): string;
export type SyncMessageRecord = {
    server_id: string;
    session_key: string;
    local_id: string | null;
    sender_type: "user" | "assistant";
    sender_name: string;
    content: string;
    timestamp_ms: number;
    seq: number;
    status: string;
    is_from_current_user: number;
    message_json: string;
    run_id: string | null;
    created_at: string;
};
export type SyncSessionRecord = {
    session_key: string;
    device_id: string;
    title: string;
    created_at: string;
    last_active_at: string;
    message_count: number;
    latest_msg_id: string | null;
};
export type SyncStateRecord = {
    device_id: string;
    last_sync_seq: number;
    updated_at: string;
};
export declare function resolveSyncDbPath(): string;
export declare function initDatabase(dbPath?: string): void;
/** Test-only: initialize with an in-memory database. */
export declare function initMemoryDatabase(): void;
export declare function getDatabase(): Database.Database;
export declare function closeDatabase(): void;
export interface InsertMessageParams {
    serverId: string;
    sessionKey: string;
    deviceId?: string;
    localId?: string | null;
    senderType: "user" | "assistant";
    senderName: string;
    content: string;
    timestampMs: number;
    seq: number;
    status: string;
    isFromCurrentUser: boolean;
    messageJson: string;
    runId?: string | null;
}
export declare function insertMessage(params: InsertMessageParams): void;
export declare function getMessagesAfterCursor(sessionKey: string, afterServerId: string, limit: number): string[];
export declare function getLatestServerId(sessionKey: string): string | null;
export declare function getMessagesBeforeCursor(sessionKey: string, beforeServerId: string, limit: number): string[];
export declare function getLastMessageJson(sessionKey: string): string | null;
export declare function getLastSyncSeq(deviceId: string): number;
export declare function setLastSyncSeq(deviceId: string, seq: number): void;
export declare function sessionExists(sessionKey: string): boolean;
export declare function getSessionMessageCount(sessionKey: string): number;
export declare function listSessionsByDevice(deviceId: string): SyncSessionRecord[];
export declare function listAllSessions(): SyncSessionRecord[];
export declare function findServerIdByRunAndSender(runId: string, senderType: string): string | null;
export declare function deleteSessionFromDb(sessionKey: string): void;
