/**
 * Telemetry persistence — specs/006 + data-model.md
 */
import type Database from 'better-sqlite3';
import type { EventType, TelemetryEventInput, TelemetryEventQueryFilters, TelemetryEventRow, TelemetryPeriod } from '../types/telemetry.types.js';
export interface SearchQualityResult {
    period: TelemetryPeriod;
    owner_id: string | null;
    search_count: number | null;
    avg_latency_ms: number | null;
    p95_latency_ms: number | null;
    empty_retrieval_rate: number | null;
    avg_candidate_count: number | null;
    top_k_selected_rate: number | null;
    timestamp: string;
}
export interface MemoryQualityResult {
    owner_id: string | null;
    total_memories: number | null;
    type_distribution: Record<string, number> | null;
    duplicate_write_rate_24h: number | null;
    relation_coverage_ratio: number | null;
    orphan_memory_ratio: number | null;
    timestamp: string;
}
/** 공고화 파이프라인 품질 (FR-009, SC-007) */
export interface ConsolidationQualityResult {
    episodic_consolidation_rate: number | null;
    triple_extraction_success_rate: number | null;
    cluster_processing_efficiency: number | null;
    recent_semantic_count_7d: number | null;
    pipeline_error_count: number | null;
    timestamp: string;
}
export interface ToolMetricBucket {
    request_count: number | null;
    success_count: number | null;
    error_count: number | null;
    error_rate: number | null;
    avg_latency_ms: number | null;
    p95_latency_ms: number | null;
}
export interface BackgroundJobMetric {
    last_run_at: string | null;
    last_outcome: 'success' | 'failure' | null;
    total_runs_24h: number | null;
    success_runs_24h: number | null;
    failure_runs_24h: number | null;
    /** 24h 롤링 평균(ms); 미구현 시 null */
    avg_duration_ms: number | null;
    /** 직전 실행 duration(ms); avg_duration_ms가 null일 때 참고 */
    last_duration_ms: number | null;
}
export interface SystemMetricsResult {
    period: TelemetryPeriod;
    tools: {
        recall: ToolMetricBucket;
        remember: ToolMetricBucket;
        feedback: ToolMetricBucket;
    };
    background_jobs: {
        sleep_consolidation: BackgroundJobMetric;
        telemetry_cleanup: BackgroundJobMetric;
    };
    timestamp: string;
}
export interface SchedulerJobSnapshot {
    lastExecution: Date | null;
    lastSuccess: boolean | null;
    lastDurationMs: number | null;
    /** 롤링 24h(UTC) 텔레메트리 집계; 알 수 없는 잡 이름이면 null */
    successRuns24h: number | null;
    failureRuns24h: number | null;
    /** 24h 평균 duration(ms); 해당 기간 latency 샘플 없으면 null */
    avgDurationMs24h: number | null;
}
/** UTC 롤링 24h 윈도우의 background 잡 텔레메트리 집계 (contracts/admin-api.md `background_jobs` 24h 필드) */
export interface BackgroundJobRolling24hStats {
    successRuns24h: number;
    failureRuns24h: number;
    avgDurationMs24h: number | null;
}
/** p95 from sorted ascending latencies (1-based rank) */
export declare function percentile95Sorted(sorted: number[]): number | null;
export declare class TelemetryRepository {
    private readonly db;
    constructor(db: Database.Database);
    /** candidates_retrieved의 candidate_count 평균 — DB에서 json_extract·AVG로 집계(대량 행 JS 파싱 회피) */
    private avgCandidateCountForPeriod;
    insertEventSync(event: TelemetryEventInput): void;
    private upsertDailyMetricRow;
    deleteExpiredEvents(retentionDays: number): number;
    /**
     * `consolidation.performed` / `telemetry.cleanup.performed` 등 잡 단위 이벤트의 롤링 24h 집계.
     * 스펙: `background_jobs.*.total_runs_24h` 등은 UTC 롤링 24h이며 `period` 쿼리와 무관.
     */
    getBackgroundJobRolling24hStats(eventType: EventType): BackgroundJobRolling24hStats;
    hasPriorWriteCompletedWithContentHash(ownerId: string | null, contentHash: string, sinceIso: string): boolean;
    querySearchQuality(period: TelemetryPeriod, ownerId?: string | null): SearchQualityResult;
    queryMemoryQuality(ownerId?: string | null): MemoryQualityResult;
    /**
     * Sleep 공고화·트리플 추출 등 구조화 파이프라인 품질 지표 (최근 7일 윈도우, owner 선택)
     */
    queryConsolidationQuality(ownerId?: string | null): ConsolidationQualityResult;
    private toolBucketFromEvents;
    querySystemMetrics(period: TelemetryPeriod, ownerId: string | null | undefined, jobMeta: {
        sleep: SchedulerJobSnapshot;
        telemetryCleanup: SchedulerJobSnapshot;
    }): SystemMetricsResult;
    queryEvents(filters: TelemetryEventQueryFilters): {
        events: TelemetryEventRow[];
        total: number;
    };
    /** Test helper: read events for request */
    listEventsForRequest(requestId: string): TelemetryEventRow[];
}
//# sourceMappingURL=telemetry-repository.d.ts.map