import { T as TraceStore } from './store-CKUAgsJz.js';

/**
 * Tool-use metrics — derived purely from trace data.
 *
 * No scoring assumptions: consumers supply optional ground-truth tool
 * selections per turn + optional "information used downstream" signals.
 * Without those, we still compute descriptive metrics (error rate,
 * retry rate, duplicate-call rate) that are useful on their own.
 */

interface ToolUseMetrics {
    runId: string;
    totalCalls: number;
    byTool: Record<string, ToolStats>;
    errorRate: number;
    /** Ratio of calls with identical (toolName, argHash) already seen earlier in the same run. */
    duplicateRate: number;
    /** Ratio of error calls followed by ≥1 retry on same tool. */
    retryRate: number;
    /** Optional: of the calls agent made, fraction the evaluator marked as "correct selection". */
    selectionAccuracy?: number;
}
interface ToolStats {
    calls: number;
    errors: number;
    avgLatencyMs: number;
    duplicates: number;
}
interface ToolUseOptions {
    /** Map of spanId → whether the evaluator judged the tool selection correct. Optional. */
    selectionLabels?: Record<string, boolean>;
}
declare function computeToolUseMetrics(store: TraceStore, runId: string, options?: ToolUseOptions): Promise<ToolUseMetrics>;

/**
 * Baseline regression detection.
 *
 * Lifted from ADC baseline.ts. Every promotion-blocking signal boils down
 * to: "is this run measurably worse than baseline?" — with enough
 * statistical rigor to distinguish noise from drift.
 *
 * Uses:
 *   - Welch's t-test (unequal variance) for per-metric mean comparison
 *   - Cohen's d for effect size magnitude
 *   - IQR for stability flag (unstable samples can't be trusted for comparisons)
 *
 * Returns a structured verdict: improved | regressed | stable | unstable.
 */
interface MetricSamples {
    /** Stable metric key (e.g. "overallScore", "firstTokenMs"). */
    metric: string;
    /** Whether higher values are better. */
    higherIsBetter: boolean;
    baseline: number[];
    candidate: number[];
}
interface MetricVerdict {
    metric: string;
    baselineMean: number;
    candidateMean: number;
    delta: number;
    cohensD: number;
    welchT: number;
    welchDf: number;
    welchP: number;
    stable: boolean;
    /** IQR of the combined samples — used as a rough stability indicator. */
    iqr: number;
    verdict: 'improved' | 'regressed' | 'stable' | 'unstable';
}
interface BaselineReport {
    metrics: MetricVerdict[];
    /** True if any critical metric regressed. */
    hasRegression: boolean;
    /** True if any metric is unstable (too noisy to judge). */
    hasUnstable: boolean;
}
interface BaselineOptions {
    /** Effect size threshold for meaningful delta (default 0.5 — medium effect). */
    effectThreshold?: number;
    /** p-value threshold for statistical significance (default 0.05). */
    alpha?: number;
    /** IQR/mean ratio above which samples are flagged unstable (default 0.30). */
    unstableCvThreshold?: number;
}
/**
 * Compare candidate samples against baseline per metric. Verdict logic:
 *   - unstable: IQR/|mean| > threshold on either set — not enough signal
 *   - improved: meaningful effect in the "better" direction AND p < alpha
 *   - regressed: meaningful effect in the "worse" direction AND p < alpha
 *   - stable: otherwise (no significant change)
 */
declare function compareToBaseline(samples: MetricSamples[], options?: BaselineOptions): BaselineReport;
/** Inter-quartile range; 0 when the sample has no spread. */
declare function iqr(xs: number[]): number;
/**
 * Welch's t-test — unequal-variance two-sample t. Uses the same Student-t
 * CDF as `pairedTTest` (via incomplete beta); falls back to normal tail
 * when df is large.
 */
declare function welchsTTest(a: number[], b: number[]): {
    t: number;
    df: number;
    p: number;
};

export { type BaselineOptions as B, type MetricSamples as M, type ToolStats as T, type BaselineReport as a, type MetricVerdict as b, computeToolUseMetrics as c, type ToolUseMetrics as d, type ToolUseOptions as e, compareToBaseline as f, iqr as i, welchsTTest as w };
