import type { BoundingBox as EngineBoundingBox, Landmark, FrameInput } from './io.js';
export interface SpatialDetection {
    readonly class: string;
    readonly originalClass: string;
    readonly score: number;
    readonly bbox: EngineBoundingBox;
    readonly landmarks?: readonly Landmark[];
    readonly mask?: Uint8Array;
    readonly maskWidth?: number;
    readonly maskHeight?: number;
}
export interface CropInput {
    readonly frame: FrameInput;
    readonly roi: EngineBoundingBox;
    readonly parentDetection: SpatialDetection;
}
export interface Classification {
    readonly class: string;
    readonly score: number;
    readonly text?: string;
    readonly embedding?: Float32Array;
    readonly metadata?: Readonly<Record<string, unknown>>;
}
export interface DetectorOutput {
    readonly detections: readonly SpatialDetection[];
    readonly inferenceMs: number;
    readonly modelId: string;
}
export interface CropperOutput {
    readonly crops: readonly SpatialDetection[];
    readonly inferenceMs: number;
    readonly modelId: string;
}
export interface ClassifierOutput {
    readonly classifications: readonly Classification[];
    readonly inferenceMs: number;
    readonly modelId: string;
}
export interface RefinerOutput {
    /** Base64-encoded binary mask for the refined detection region */
    readonly mask: string;
    readonly maskWidth: number;
    readonly maskHeight: number;
    readonly inferenceMs: number;
    readonly modelId: string;
}
/** Axis-aligned bounding box in absolute pixel coordinates of the source frame. */
export interface DetectionBoundingBox {
    readonly x: number;
    readonly y: number;
    readonly width: number;
    readonly height: number;
}
/**
 * A single enriched label attached to a detection.
 *
 * - In `Detection.labels[]` it represents an enrichment that "won" on this
 *   detection (either produced directly on it, or inherited from a child
 *   detail in the same frame).
 * - In `DetectionDebug.alternateLabels[source][]` it represents one
 *   candidate from a top-N ranked list.
 */
export interface ScoredLabel {
    readonly label: string;
    readonly score: number;
    /**
     * When this label was inherited from a child detail (e.g. a person
     * carrying a recognized face name), this is the child detection's id.
     * Omitted on own enrichments — the label already lives on the entry
     * that carries it.
     */
    readonly detectionId?: string;
}
/** What kind of entry a detection is at the root of `detections[]`. */
export type DetectionKind = 'first-level' | 'detail' | 'audio';
/** First-level macro classes produced by object detectors. */
export type FirstLevelMacro = 'person' | 'vehicle' | 'animal';
/** Detail macro classes produced by crop+recognize steps. */
export type DetailMacro = 'face' | 'plate';
/**
 * Macro class carried at the root of each Detection entry. Kept as an
 * extensible string union so future detectors (e.g. a custom
 * `first-level-fire` classifier) can plug in without a type change.
 */
export type MacroClass = FirstLevelMacro | DetailMacro | 'audio' | string;
/** Tracker-enriched info attached to first-level detections only. */
export interface TrackInfo {
    readonly trackId: string;
    readonly moving?: boolean;
    /** Pixels per second in frame coordinates. */
    readonly speedPx?: number;
    /** IDs of zones the bbox overlaps at this frame. */
    readonly zones?: readonly string[];
    /** Wall-clock timestamp (ms) when the track was first seen. */
    readonly firstSeenMs?: number;
    /** Wall-clock timestamp (ms) of the last update on this track. */
    readonly lastSeenMs?: number;
}
/** Per-detection debug bag — populated only when detection debug is enabled. */
export interface DetectionDebug {
    /** Latency of each step that touched this detection (source → ms). */
    readonly stepLatencyMs?: Readonly<Record<string, number>>;
    /** Model id used by each step that touched this detection (source → modelId). */
    readonly modelIds?: Readonly<Record<string, string>>;
    /** How the step read the image — full frame or cropped ROI. */
    readonly extractMode?: 'full-frame' | 'crop-roi';
    /**
     * Raw detector class before any macro mapping. Present only when it
     * differs from `macroClass` (e.g. object-detection returned `'dog'`,
     * mapped to `macroClass: 'animal'`).
     */
    readonly originalClass?: string;
    /**
     * Full top-N ranked alternatives per source (classifier / recognizer).
     * The winner of each list already appears in `detection.labels[]` —
     * this field surfaces the rest for the benchmark UI and debug inspectors.
     */
    readonly alternateLabels?: Readonly<Record<string, readonly ScoredLabel[]>>;
    /** Base64 binary segmentation mask (when a seg/refiner step produced one). */
    readonly mask?: string;
    readonly maskWidth?: number;
    readonly maskHeight?: number;
    /** Id of the embedding stored by face/voice/plate recognition, when any. */
    readonly embeddingId?: string;
}
/** Per-step timing in a frame-level debug bag. Aggregate across all the detections. */
export interface FrameStepTiming {
    /** Step addon id. */
    readonly source: string;
    /** Model id used during this frame. */
    readonly modelId?: string;
    /** Total wall-clock latency contributed by this step to the frame. */
    readonly ms: number;
    /** How many detections this step contributed (for per-step throughput). */
    readonly detectionCount?: number;
}
/** Per-frame debug bag — populated only when detection debug is enabled. */
export interface FrameDebug {
    /** Sum of all step latencies for this frame (not wall-clock). */
    readonly totalInferenceMs?: number;
    /** Flat list of per-step timings. */
    readonly stepTimings?: readonly FrameStepTiming[];
    /** Engine descriptor — e.g. `'python/coreml'`. */
    readonly engine?: string;
    /** Pipeline template id in use (for comparing across runs). */
    readonly pipelineId?: string;
    /** JPEG → dimensions probe + buffer alloc (benchmark / reference-image paths only). */
    readonly decodeMs?: number;
    /** Per-run setup: step conversion, engine factory init, model load, tree build. */
    readonly setupMs?: number;
    /** Total wall-clock of runPipeline from entry to return — includes decode, setup, inference, progress emit. */
    readonly wallMs?: number;
    /** Residual = wallMs - (decodeMs + setupMs + totalInferenceMs). Surfaces tRPC / IPC / overhead. */
    readonly overheadMs?: number;
    /** Python-pool preprocess wall (PIL resize + tensor pack). Excludes IPC + window-accumulator wait. */
    readonly preprocessMs?: number;
    /** Python-pool predict wall (model.predict only). Pure ANE/CoreML/ORT execute time. */
    readonly predictMs?: number;
    /** Window-accumulator batch size used for the predict call (1 = no batching, N = N frames coalesced). */
    readonly batchSize?: number;
}
/** Common shape shared by every entry in `FrameResult.detections` / `AudioResult.detections`. */
export interface DetectionBase {
    readonly id: string;
    readonly kind: DetectionKind;
    readonly macroClass: MacroClass;
    /** Score of the macro class itself (from the detector that emitted this entry). */
    readonly score: number;
    /**
     * Enrichment labels — each with its own score. Ordered:
     * (1) catena di enricher diretti sulla detection,
     * (2) labels ereditate dai children details (in ordine di apparizione).
     * Lo score preserva il valore prodotto dall'enricher originale anche
     * quando la label è ereditata.
     */
    readonly labels: readonly ScoredLabel[];
    readonly track?: TrackInfo;
    readonly debug?: DetectionDebug;
}
/** Object detection (first-level person/vehicle/animal OR detail face/plate). */
export interface ObjectDetection extends DetectionBase {
    readonly kind: 'first-level' | 'detail';
    /** Absolute pixel coordinates in the source frame. */
    readonly bbox: DetectionBoundingBox;
    /**
     * For details (face, plate): id of the first-level parent entry in
     * the same frame. Allows the UI to correlate a face crop back to the
     * person box (or a plate back to the vehicle box).
     */
    readonly parentId?: string;
}
/** Audio detection — flat, time-localised within the window. */
export interface AudioDetection extends DetectionBase {
    readonly kind: 'audio';
    readonly startMs: number;
    readonly endMs: number;
}
/**
 * Union of every possible detection entry at the root of a result payload.
 *
 * Named `DetectionEntry` rather than `Detection` because the
 * device-capabilities namespace already exports a different `Detection`
 * interface for Scrypted-style object detectors. The two live in
 * separate files but both are re-exported at the package root, so
 * keeping names distinct avoids an import-level collision.
 */
export type DetectionEntry = ObjectDetection | AudioDetection;
/**
 * Per-frame pipeline result — the canonical container emitted by
 * `pipelineExecutor.runPipeline` (one-shot benchmark + runtime dispatch)
 * and by the live video pipeline. Carries only `ObjectDetection` entries
 * (video has no audio events).
 */
export interface FrameResult {
    readonly kind: 'frame';
    readonly frameId: string;
    readonly deviceId: number;
    /** Wall-clock timestamp (ms) of frame capture / emission. */
    readonly timestamp: number;
    readonly width: number;
    readonly height: number;
    readonly detections: readonly ObjectDetection[];
    readonly debug?: FrameDebug;
}
/**
 * Per-audio-window pipeline result — the canonical container emitted by
 * the audio pipeline. Carries only `AudioDetection` entries plus optional
 * window-level level metrics.
 */
export interface AudioResult {
    readonly kind: 'audio-window';
    readonly windowId: string;
    readonly deviceId: number;
    /** Wall-clock timestamp (ms) of the window start. */
    readonly timestamp: number;
    /** Offset (ms) of the window start inside the source audio stream. */
    readonly startMs: number;
    /** Offset (ms) of the window end inside the source audio stream. */
    readonly endMs: number;
    /** Aggregate audio level metrics (RMS / dBFS), independent from detections. */
    readonly level?: {
        readonly rms: number;
        readonly dbfs: number;
    };
    readonly detections: readonly AudioDetection[];
    readonly debug?: FrameDebug;
}
/** Discriminated union of every top-level pipeline result payload shape. */
export type PipelineFrameResult = FrameResult | AudioResult;
//# sourceMappingURL=detection.d.ts.map