import { LoggerBackend } from './logger.js';

interface OpikExporterConfig {
    enabled: boolean;
    /** Base URL of the Opik API, e.g. http://192.168.3.147:5173/api */
    apiUrl: string;
    projectName: string;
    workspaceName: string;
    /** Optional API key (not required for self-hosted deployments) */
    apiKey?: string;
    /** Include recalled memory text in spans (default false) */
    traceRecallContent: boolean;
}
declare class OpikExporter {
    private readonly cfg;
    private readonly log;
    private _handler;
    private readonly inFlight;
    /** Track which trace_ids we have already created parent trace objects for. */
    private readonly createdTraces;
    /** In-flight ensureTrace promises keyed by traceId — concurrent callers await the same promise. */
    private readonly pendingTraces;
    /** TTL for in-flight LLM entries (ms). Entries older than this are discarded. */
    private static readonly IN_FLIGHT_TTL_MS;
    constructor(cfg: OpikExporterConfig, log: LoggerBackend);
    /**
     * Subscribe to Engram's global trace slot. Safe to call multiple times —
     * chains with existing subscribers (e.g. Langfuse) rather than replacing.
     */
    subscribe(): void;
    /** Deactivate this exporter instance.
     *
     * We intentionally do NOT restore __openclawEngramTrace to a prior handler
     * because any subscriber that chained *after* us would be silently dropped
     * by such a restoration. Instead we mark the instance as disabled so that
     * handleEvent() becomes a no-op while the callback chain itself is left
     * untouched. The next subscribe() call from a fresh instance will re-enter
     * the chain on top of whatever is there at that point.
     */
    _detach(): void;
    unsubscribe(): void;
    private handleEvent;
    private onRecall;
    private onLlmStart;
    private sweepStaleInFlight;
    private onLlmEnd;
    /**
     * Create a parent trace object in Opik if we haven't already.
     * Opik does NOT auto-create traces from spans, so without this
     * the spans are orphaned and don't show up in the trace list UI.
     */
    private ensureTrace;
    /**
     * Convert a sessionKey to a stable, deterministic UUID v7-shaped ID so that
     * spans for the same session share a trace_id and are threaded in Opik.
     * Uses SHA-256 for collision resistance. The timestamp bytes (0-5) come from
     * the hash itself — they don't reflect real time, but Opik only validates
     * the version/variant bits, not timestamp ordering.
     */
    private sessionToTraceId;
}
interface OpikExporterRawConfig {
    opikTraceEnabled?: boolean;
    opikApiUrl?: string;
    opikProjectName?: string;
    opikWorkspaceName?: string;
    opikApiKey?: string;
    opikTraceRecallContent?: boolean;
}
declare function createOpikExporter(raw: OpikExporterRawConfig, log: LoggerBackend): OpikExporter | null;

export { OpikExporter, type OpikExporterConfig, type OpikExporterRawConfig, createOpikExporter };
