/**
 * Marker OCR Bridge - Local GPU Processing (Daemon Mode)
 *
 * Spawns python/ocr_worker_local.py in daemon mode (--daemon).
 * Models are loaded ONCE on first use and reused across all documents.
 * Local GPU processing via Marker-pdf v1.10.2.
 * NO cloud API calls, NO fallbacks - real local GPU processing only.
 */
import type { OCRResult, PageOffset } from '../../models/document.js';
/**
 * Kill all active OCR worker processes.
 * Called on process exit to prevent orphaned GPU-consuming workers.
 */
export declare function killAllOCRWorkers(): void;
export interface ProcessingProgress {
    documentId: string;
    stage: string;
    percent: number;
    current: number;
    total: number;
    pipelineStep: string;
    updatedAt: number;
}
export declare function getProcessingProgress(): Map<string, ProcessingProgress>;
export declare function updatePipelineStep(documentId: string, step: string, detail?: string): void;
export declare function clearProcessingProgress(documentId: string): void;
export interface MarkerClientConfig {
    pythonPath?: string;
    timeout?: number;
}
export declare class MarkerClient {
    private readonly pythonPath;
    private readonly workerPath;
    private readonly timeout;
    /** Daemon process state */
    private _daemonProcess;
    private _daemonReadline;
    private _daemonReady;
    private _daemonStarting;
    private _pendingResolve;
    private _pendingReject;
    /** Simple promise-based lock for serial access to daemon */
    private _lockPromise;
    constructor(config?: MarkerClientConfig);
    /**
     * Acquire exclusive access to the daemon for one request.
     * Requests are serialized because the daemon processes one at a time.
     */
    private withLock;
    /**
     * Ensure daemon is running and ready. Spawns on first call, restarts on crash.
     */
    private ensureDaemon;
    /**
     * Spawn the Python daemon process and wait for the ready signal.
     */
    private _spawnDaemon;
    /**
     * Send a JSON request to the daemon and wait for a JSON response line.
     * Caller must hold the lock.
     */
    private _sendRequest;
    /**
     * Clean up daemon process and associated resources.
     */
    private _cleanupDaemon;
    private _isDaemonReady;
    private _isErrorResponse;
    /**
     * Process document through Marker OCR (local GPU) via daemon
     *
     * FAIL-FAST: Throws on any error, no fallbacks
     */
    processDocument(filePath: string, documentId: string, provenanceId: string, mode?: 'fast' | 'balanced' | 'accurate', ocrOptions?: {
        maxPages?: number;
        pageRange?: string;
        skipCache?: boolean;
        disableImageExtraction?: boolean;
        extras?: string[];
        pageSchema?: string;
        additionalConfig?: Record<string, unknown>;
        fileUrl?: string;
    }): Promise<{
        result: OCRResult;
        pageOffsets: PageOffset[];
        images: Record<string, string>;
        jsonBlocks: Record<string, unknown> | null;
        metadata: Record<string, unknown> | null;
        extractionJson: Record<string, unknown> | unknown[] | null;
        docTitle: string | null;
        docAuthor: string | null;
        docSubject: string | null;
    }>;
    /**
     * Process a file through Marker OCR and return raw results without storing in DB.
     * Used by ocr_convert_raw tool for quick one-off conversions.
     *
     * FAIL-FAST: Throws on any error, no fallbacks
     */
    processRaw(filePath: string, mode?: 'fast' | 'balanced' | 'accurate', ocrOptions?: {
        maxPages?: number;
        pageRange?: string;
        fileUrl?: string;
    }): Promise<{
        markdown: string;
        pageCount: number;
        qualityScore: number | null;
        costCents: number | null;
        durationMs: number;
        metadata: Record<string, unknown> | null;
    }>;
    /**
     * Wrap a promise with a timeout. On timeout, throws OCRError('OCR_TIMEOUT').
     */
    private _withTimeout;
    /**
     * Parse a JSON response line from the daemon.
     */
    private _parseResponse;
    private _toOCRResult;
    private _toPageOffsets;
    /**
     * Destroy this client instance and release all resources.
     * Kills the daemon process and WAITS for it to fully exit so CUDA VRAM is
     * released before the caller loads another model (e.g. Chandra VLM).
     *
     * Without waiting, the Marker process still holds VRAM when Chandra starts
     * loading (~10.6GB), causing the Linux OOM killer to SIGKILL Marker. The SIGKILL
     * triggers the pending-request reject handler, which rolls back the entire
     * document even though OCR already succeeded.
     *
     * See: https://docs.pytorch.org/docs/stable/torch_cuda_memory.html
     */
    destroyAndWait(timeoutMs?: number): Promise<void>;
    /**
     * Synchronous destroy — does NOT wait for VRAM release.
     * Use destroyAndWait() when loading another GPU model after this.
     */
    destroy(): void;
}
/**
 * Get or create MarkerClient singleton.
 * Ensures only ONE Python daemon process runs for OCR,
 * preventing GPU memory contention from multiple model loads.
 */
export declare function getMarkerClient(config?: MarkerClientConfig): MarkerClient;
/**
 * Reset singleton for testing.
 * Cleans up daemon process to prevent orphaned GPU-consuming workers.
 */
export declare function resetMarkerClient(): void;
//# sourceMappingURL=marker.d.ts.map