/**
 * OTEL span exporter — streams LoopTraceEvents to an OTLP/HTTP collector.
 *
 * Reads OTEL_EXPORTER_OTLP_ENDPOINT + OTEL_EXPORTER_OTLP_HEADERS from env
 * when no explicit config is given. Keeps the runtime dep-free from
 * @opentelemetry/sdk-trace-base — minimal OTLP/JSON serializer.
 *
 * The exporter accepts both raw OtelSpan objects and LoopTraceEvents
 * (which get converted to OTLP spans automatically).
 */
interface OtelExportConfig {
    /** OTLP endpoint. Reads OTEL_EXPORTER_OTLP_ENDPOINT env by default. */
    endpoint?: string;
    /** OTLP headers. Reads OTEL_EXPORTER_OTLP_HEADERS env by default. */
    headers?: Record<string, string>;
    /** Batch size before flush. Default 64. */
    batchSize?: number;
    /** Flush interval ms. Default 5000. */
    flushIntervalMs?: number;
    /** Resource attributes stamped on every export. */
    resourceAttributes?: Record<string, string | number | boolean>;
    /** Service name. Default 'agent-runtime'. */
    serviceName?: string;
}
interface OtelExporter {
    /** Export a span. */
    exportSpan(span: OtelSpan): void;
    /** Force flush pending spans. */
    flush(): Promise<void>;
    /** Shutdown cleanly. */
    shutdown(): Promise<void>;
}
interface OtelSpan {
    traceId: string;
    spanId: string;
    parentSpanId?: string;
    name: string;
    kind?: number;
    startTimeUnixNano: string;
    endTimeUnixNano: string;
    attributes?: OtelAttribute[];
    status?: {
        code: number;
        message?: string;
    };
}
interface OtelAttribute {
    key: string;
    value: {
        stringValue?: string;
        intValue?: string;
        doubleValue?: number;
        boolValue?: boolean;
    };
}
/**
 * Create an OTEL exporter. Returns undefined when no endpoint is configured.
 */
declare function createOtelExporter(config?: OtelExportConfig): OtelExporter | undefined;
/**
 * Convert a LoopTraceEvent into an OtelSpan for export.
 */
declare function loopEventToOtelSpan(event: {
    kind: string;
    runId: string;
    timestamp: number;
    payload: object;
}, traceId: string, parentSpanId?: string): OtelSpan;
/**
 * Sink-neutral node in a reconstructed loop span tree. The root node's
 * `parentSpanId` is `undefined` — sinks decide how to parent it (the OTEL
 * mapper attaches the inherited delegation span; the delegation journal
 * leaves it as the tree root).
 */
interface LoopSpanNode {
    spanId: string;
    parentSpanId?: string;
    /** `'loop'` | `'loop.round'` | `'loop.iteration'`. */
    name: string;
    /** Topology level: loop root, plan round, or iteration branch. */
    kind: 'loop' | 'round' | 'branch';
    startMs: number;
    endMs: number;
    attrs: Record<string, string | number | boolean>;
    /** True when the iteration carried an error — maps to OTEL status code 2. */
    error: boolean;
}
/**
 * Build a nested, real-duration OTLP span tree for ONE loop run from its full
 * ordered `LoopTraceEvent` stream. Unlike `loopEventToOtelSpan` (one flat,
 * zero-duration span per event), this reconstructs the topology hierarchy a
 * GenAI trace viewer renders natively:
 *
 *   loop (invoke_workflow)
 *     └─ loop.round[k] (invoke_workflow)   ← tangle.loop.move.{kind,width,rationale}
 *          ├─ loop.iteration[i] (invoke_agent)  ← gen_ai.agent.name + usage + verdict + placement
 *          └─ …
 *
 * Attributes follow the current GenAI semconv (`gen_ai.*`) where they apply and
 * a namespaced `tangle.loop.*` / `tangle.cost.usd` extension for topology /
 * verdict / placement / cost (not yet standardized). Pure: feed it a buffered
 * per-runId event array (e.g. flushed on `loop.ended`) and export the result.
 */
declare function buildLoopOtelSpans(events: ReadonlyArray<{
    kind: string;
    runId: string;
    timestamp: number;
    payload: object;
}>, traceId: string, rootParentSpanId?: string): OtelSpan[];
/**
 * Sink-neutral core behind {@link buildLoopOtelSpans}: reconstruct the
 * loop → round → branch span tree from one run's ordered `LoopTraceEvent`
 * stream. Consumed by the OTEL mapper above and by the MCP delegation
 * journal's compact trace tee — one topology reconstruction, two sinks.
 * Tolerates partial streams (a run that never reached `loop.ended` closes
 * at the last observed event's timestamp).
 */
declare function buildLoopSpanNodes(events: ReadonlyArray<{
    kind: string;
    runId: string;
    timestamp: number;
    payload: object;
}>): LoopSpanNode[];
/** Wire version the eval-runs ingest enforces (X-Tangle-Wire-Version + body). */
declare const INTELLIGENCE_WIRE_VERSION = "2026-05-26.v1";
interface EvalRunGeneration {
    /** 0-based ordinal of this generation within the run (required by ingest). */
    index: number;
    /** Identity of the proposed surface change (content-addressed hash). */
    surfaceHash: string;
    /** Arbitrary provenance for this generation (rationale, evidence, source). */
    surface?: unknown;
    /** Per-scenario results; empty until the generation is measured. */
    cells?: unknown[];
    /** Mean composite score (0 when unmeasured — pair with labels.measured). */
    compositeMean: number;
    costUsd: number;
    durationMs: number;
}
interface EvalRunEvent {
    runId: string;
    runDir: string;
    /** ISO timestamp. */
    timestamp: string;
    status: 'started' | 'baseline-complete' | 'generation-complete' | 'gate-decided' | 'finished' | 'errored';
    labels?: Record<string, string>;
    baseline?: EvalRunGeneration;
    generations?: EvalRunGeneration[];
    gateDecision?: 'ship' | 'hold' | 'need_more_work' | 'model_ceiling' | 'arch_ceiling';
    holdoutLift?: number;
    totalCostUsd: number;
    totalDurationMs: number;
    errorMessage?: string;
}
interface EvalRunsExportConfig {
    /** Bearer key — tenant is resolved server-side from it. Reads TANGLE_API_KEY. */
    apiKey?: string;
    /** Intelligence base. Reads INTELLIGENCE_BASE env, else prod. */
    base?: string;
    /** Idempotency-Key header (e.g. the runId) — safe retries + upsert. */
    idempotencyKey?: string;
}
interface EvalRunsExportResult {
    ok: boolean;
    status: number;
    accepted: number;
    rejected: Array<{
        index: number;
        reason: string;
    }>;
}
/**
 * Ship self-improvement eval-run events to Tangle Intelligence. Unlike the
 * best-effort span exporter, this RESOLVES with the ingest verdict (accepted /
 * rejected per event) so a consumer's loop can assert its provenance landed.
 * Throws only on a missing key or network failure.
 */
declare function exportEvalRuns(events: EvalRunEvent[], config?: EvalRunsExportConfig): Promise<EvalRunsExportResult>;

export { type EvalRunEvent as E, INTELLIGENCE_WIRE_VERSION as I, type LoopSpanNode as L, type OtelExporter as O, type EvalRunGeneration as a, type EvalRunsExportConfig as b, type EvalRunsExportResult as c, type OtelAttribute as d, type OtelExportConfig as e, type OtelSpan as f, buildLoopOtelSpans as g, buildLoopSpanNodes as h, createOtelExporter as i, exportEvalRuns as j, loopEventToOtelSpan as l };
