@camstack/addon-model-studio 1.1.43 → 1.1.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (17) hide show
  1. package/dist/{MotionZonesSettings-BQmeOC6s.mjs → MotionZonesSettings-BA2jeOR6.mjs} +2 -2
  2. package/dist/{PrivacyMaskSettings-MznS24IR.mjs → PrivacyMaskSettings-Bf1hFhGN.mjs} +4 -4
  3. package/dist/{SceneMonitorEditor-slpx5RVW.mjs → SceneMonitorEditor-DcKcwKsJ.mjs} +3 -3
  4. package/dist/_stub.js +10 -10
  5. package/dist/{_virtual_mf-localSharedImportMap___mfe_internal__addon_model_studio_page-Dvg3AwY0.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_model_studio_page-B-ZMvrf0.mjs} +4 -4
  6. package/dist/{_virtual_mf___mfe_internal__addon_model_studio_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-Dz7eB41h.mjs → _virtual_mf___mfe_internal__addon_model_studio_page__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-C3sZIjJ6.mjs} +1 -1
  7. package/dist/{hostInit-9uaH_tWZ.mjs → hostInit-BZM9cD30.mjs} +3 -3
  8. package/dist/model-studio.addon.js +1585 -1437
  9. package/dist/model-studio.addon.mjs +1585 -1437
  10. package/dist/{player-overlays-ZV106hch.mjs → player-overlays-CUJ2regU.mjs} +1 -1
  11. package/dist/remoteEntry.js +1 -1
  12. package/dist/{responsive-BWcJ76VI.mjs → responsive-pq6YOPGN.mjs} +1 -1
  13. package/dist/{square-DK5dno3H.mjs → square-BFrlalUj.mjs} +1 -1
  14. package/dist/{trash-2-B9ZCrm5O.mjs → trash-2-KCXgMJqK.mjs} +1 -1
  15. package/dist/{use-device-snapshot-_PNv-X_c.mjs → use-device-snapshot-C9mtUHIM.mjs} +1 -1
  16. package/dist/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_model_studio_page__remoteEntry_js-DQmO25Hm.mjs → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__addon_model_studio_page__remoteEntry_js-DlP1RQa1.mjs} +1 -1
  17. package/package.json +1 -1
@@ -16204,7 +16204,23 @@ var NcHistoryEntrySchema = object({
16204
16204
  updatedAt: number(),
16205
16205
  /** Failure detail — present on a `dead` row. */
16206
16206
  error: string().optional(),
16207
- subject: NcHistorySubjectSchema
16207
+ subject: NcHistorySubjectSchema,
16208
+ /**
16209
+ * Ids of the artefacts (still, then gif, then clip) this row's successful
16210
+ * delivery indexed in the artefact library — a REFERENCE, never the bytes
16211
+ * (an artefact is often megabytes; this row is durable JSON rewritten on
16212
+ * every delivery attempt). Absent on a row still pending/dead, a row
16213
+ * delivered before this field shipped, or a wiring with no artefact index.
16214
+ *
16215
+ * Resolve one to a fetchable URL with `resolveArtifactUrl` — an id
16216
+ * outlives any one URL's TTL, so a caller mints a fresh link on demand
16217
+ * rather than trusting one frozen at delivery time. `resolveArtifactUrl`
16218
+ * also answers `null` for an id whose artefact has since expired past the
16219
+ * retained shelf's own age bound — the degrade a caller (the Home
16220
+ * Assistant export) must render as "no image right now", never as a
16221
+ * broken link.
16222
+ */
16223
+ artifactIds: array(string().min(1)).optional()
16208
16224
  });
16209
16225
  /**
16210
16226
  * Query filter for `getHistory` (spec §4.2). Every field is a narrowing
@@ -16431,7 +16447,7 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
16431
16447
  }), method(object({}), object({
16432
16448
  catalog: array(NcConditionDescriptorSchema),
16433
16449
  taxonomy: NcTaxonomySchema.optional()
16434
- })), method(object({ filter: NcHistoryFilterSchema.default({ limit: 100 }) }), object({ entries: array(NcHistoryEntrySchema) }), { auth: "admin" }), method(object({}), object({ snoozes: array(NcSnoozeSchema) }), { caller: "required" }), method(object({ snooze: NcSnoozeInputSchema }), object({ snooze: NcSnoozeSchema }), {
16450
+ })), method(object({ filter: NcHistoryFilterSchema.default({ limit: 100 }) }), object({ entries: array(NcHistoryEntrySchema) }), { auth: "admin" }), method(object({ artifactId: string().min(1) }), object({ url: string().nullable() }), { auth: "admin" }), method(object({}), object({ snoozes: array(NcSnoozeSchema) }), { caller: "required" }), method(object({ snooze: NcSnoozeInputSchema }), object({ snooze: NcSnoozeSchema }), {
16435
16451
  kind: "mutation",
16436
16452
  caller: "required"
16437
16453
  }), method(object({ snoozeId: string() }), object({ success: literal(true) }), {
@@ -16771,896 +16787,1496 @@ var OauthIntegrationDescriptorSchema = object({
16771
16787
  });
16772
16788
  method(_void(), OauthIntegrationDescriptorSchema, { auth: "admin" });
16773
16789
  /**
16774
- * pipeline-analytics device-scoped wrapper cap. Refines raw
16775
- * per-frame detections emitted by the pipeline runner into tracked
16776
- * objects, per-kind event collections (motion / object / audio), and
16777
- * persisted media. Owns the post-detection domain end-to-end:
16778
- *
16779
- * runner emits PipelineInferenceResult
16780
- * ↓ (event bus)
16781
- * pipeline-analytics subscriber
16782
- * ↓ SORT tracker + zone engine + state analyzer + event emitter
16783
- * → three DB collections (one per kind), one FS media tree, one
16784
- * unified event emitter (FrameTracked + TrackStarted/Ended +
16785
- * DetectionEvent on bus)
16786
- *
16787
- * Pure subscriber model. No `processFrame` cap method — the runner
16788
- * already publishes the raw frame on the bus. The cap surface is
16789
- * only QUERIES + per-device settings, bound on/off via
16790
- * `device-manager.setWrapperActive`. `defaultActive: true` because
16791
- * every camera with a detection pipeline wants its raw detections
16792
- * refined; operators opt out per-device via BindingsTab when needed.
16793
- *
16794
- * Replaces the legacy `analysis-pipeline`, `analysis-data-persistence`
16795
- * (per-device surface) and `track-trail` caps — see P11 cleanup.
16790
+ * Reference to the frame's retained NATIVE surface + the parent crop's placement
16791
+ * within the frame, so the executor can re-cut a leaf child ROI at native
16792
+ * resolution on the detail plane. See the `runPipeline` `nativeCropRef` field.
16796
16793
  */
16797
- var TrackStateSchema = _enum([
16798
- "new",
16799
- "entered",
16800
- "left",
16801
- "moving",
16802
- "idle"
16803
- ]);
16804
- var EventKindSchema = _enum([
16805
- "motion",
16806
- "object",
16807
- "audio"
16808
- ]);
16794
+ var NativeCropRefSchema = object({
16795
+ /** Handle keying the retained native surface (node-pinned to its owner). */
16796
+ handle: FrameHandleSchema,
16797
+ /** The parent crop's padded/clamped rectangle in FRAME-space pixels. */
16798
+ cropFrameSpace: object({
16799
+ x: number(),
16800
+ y: number(),
16801
+ w: number(),
16802
+ h: number()
16803
+ })
16804
+ });
16805
+ object({
16806
+ crop: object({
16807
+ left: number(),
16808
+ top: number(),
16809
+ width: number().positive(),
16810
+ height: number().positive()
16811
+ }).optional(),
16812
+ content: object({
16813
+ width: number().int().positive(),
16814
+ height: number().int().positive()
16815
+ }),
16816
+ fit: _enum(["stretch", "contain"]),
16817
+ format: _enum([
16818
+ "rgb",
16819
+ "gray",
16820
+ "jpeg"
16821
+ ])
16822
+ });
16809
16823
  /**
16810
- * Spatial filter for `listTracks` the rect + polygon variants of the shared
16811
- * MaskShape vocabulary (see `mask-shape.ts`). Coordinates are NORMALIZED 0..1
16812
- * of the camera frame (top-left origin), matching the drawing-plane editor.
16824
+ * Process-local frame identity. It is serializable so it can ride an in-process
16825
+ * capability call, but `registryId` deliberately prevents resolution in any
16826
+ * other process or execution group.
16813
16827
  */
16814
- var TrackZoneFilterSchema = discriminatedUnion("kind", [MaskRectShapeSchema, MaskPolygonShapeSchema]);
16815
- /** Closed icon vocabulary so clients render a known glyph per kind. */
16816
- var EventKindIconSchema = _enum([
16817
- "motion",
16818
- "audio",
16819
- "person",
16820
- "vehicle",
16821
- "animal",
16822
- "door",
16823
- "pir",
16824
- "smoke",
16825
- "water",
16826
- "button",
16827
- "package",
16828
- "generic"
16828
+ var FrameRefSchema = object({
16829
+ registryId: string().min(1),
16830
+ id: string().min(1),
16831
+ width: number().int().positive(),
16832
+ height: number().int().positive(),
16833
+ format: _enum(["rgb", "gray"]),
16834
+ timestamp: number(),
16835
+ capturedAt: number().optional()
16836
+ });
16837
+ var ModelFormatSchema$1 = _enum([
16838
+ "onnx",
16839
+ "coreml",
16840
+ "openvino",
16841
+ "tflite",
16842
+ "pt",
16843
+ "gguf"
16829
16844
  ]);
16830
- var EventKindCategorySchema = _enum([
16831
- "motion",
16832
- "audio",
16833
- "detection",
16834
- "sensor",
16835
- "control",
16836
- "custom",
16837
- "package"
16845
+ var PipelineSlotSchema = _enum([
16846
+ "detector",
16847
+ "cropper",
16848
+ "classifier",
16849
+ "refiner",
16850
+ "audio-classifier"
16838
16851
  ]);
16839
- /** Taxonomy level — macro (timeline lane) vs sub (events-page leaf). */
16840
- var EventKindLevelSchema = _enum(["macro", "sub"]);
16841
- var EventKindDescriptorSchema = object({
16842
- /** Stable kind id (e.g. 'motion', 'vehicle', 'car', 'lock'). */
16843
- kind: string(),
16844
- /** i18n key resolved on the UI side; `label` is the English fallback. */
16845
- labelKey: string(),
16846
- /** English fallback label (kept for clients that don't translate). */
16847
- label: string(),
16848
- /** Hex color for timeline/legend rendering. */
16849
- color: string(),
16850
- /** Dictionary id → lucide component on the UI side. */
16851
- iconId: string(),
16852
- /** Legacy closed-vocab glyph — fallback for `iconId`. */
16853
- icon: EventKindIconSchema,
16854
- category: EventKindCategorySchema,
16855
- /** Macro parent for this kind ('car' → 'vehicle'); null for a macro. */
16856
- parentKind: string().nullable(),
16857
- /** Derived from `parentKind`, explicit for the client tree. */
16858
- level: EventKindLevelSchema,
16859
- /** Which cap + device contributes this kind. For built-ins the camera
16860
- * itself; for sensor kinds the LINKED source device. */
16861
- source: object({
16862
- capName: string(),
16863
- deviceId: number()
16864
- })
16852
+ var PipelineEngineChoiceSchema = object({
16853
+ runtime: _enum(["node", "python"]),
16854
+ backend: string(),
16855
+ format: ModelFormatSchema$1,
16856
+ device: string().optional()
16865
16857
  });
16866
- /** One camera's event vocabulary, as returned by `listEventKindsBatch`. */
16867
- var EventKindsForDeviceSchema = object({
16868
- deviceId: number(),
16869
- kinds: array(EventKindDescriptorSchema).readonly()
16858
+ var AvailableEngineSchema = object({
16859
+ engine: PipelineEngineChoiceSchema,
16860
+ devices: array(object({
16861
+ id: string(),
16862
+ label: string(),
16863
+ description: string().optional()
16864
+ })).readonly(),
16865
+ defaultDevice: string()
16870
16866
  });
16871
- var SensorEventSchema = object({
16867
+ var PipelineDefaultStepSchema = lazy(() => object({
16868
+ addonId: string(),
16869
+ addonName: string(),
16870
+ slot: PipelineSlotSchema,
16871
+ inputClasses: array(string()).readonly(),
16872
+ outputClasses: array(string()).readonly(),
16873
+ enabled: boolean(),
16874
+ modelId: string(),
16875
+ children: array(PipelineDefaultStepSchema).readonly(),
16876
+ group: string().optional(),
16877
+ settings: record(string(), unknown()).optional()
16878
+ }));
16879
+ var PipelineTemplateStepSchema = lazy(() => object({
16880
+ addonId: string(),
16881
+ enabled: boolean(),
16882
+ modelId: string(),
16883
+ children: array(PipelineTemplateStepSchema).readonly(),
16884
+ settings: record(string(), unknown()).optional()
16885
+ }));
16886
+ var PipelineTemplateSchema$1 = object({
16872
16887
  id: string(),
16873
- /** The CAMERA the event is attributed to (a sensor linked to N cameras
16874
- * yields N rows, one per camera). */
16875
- deviceId: number(),
16876
- /** The linked sensor device whose state changed. */
16877
- sourceDeviceId: number(),
16878
- /** Event kind id — matches an `EventKindDescriptor.kind`. */
16879
- kind: string(),
16880
- /** Snapshot of the sensor cap's runtime-state slice at the change. */
16881
- value: record(string(), unknown()).nullable(),
16882
- timestamp: number()
16888
+ name: string(),
16889
+ createdAt: string(),
16890
+ updatedAt: string(),
16891
+ engine: PipelineEngineChoiceSchema,
16892
+ steps: array(PipelineTemplateStepSchema).readonly()
16883
16893
  });
16884
- var TrackPositionSchema = object({
16885
- x: number(),
16886
- y: number(),
16887
- timestamp: number(),
16888
- bbox: BoundingBoxSchema
16894
+ var PipelineModelOptionSchema = object({
16895
+ id: string(),
16896
+ name: string(),
16897
+ formats: record(string(), object({
16898
+ downloaded: boolean(),
16899
+ sizeMB: number()
16900
+ })),
16901
+ group: ModelVariantGroupSchema.optional(),
16902
+ legacy: boolean().optional(),
16903
+ provider: ModelProviderIdSchema.optional()
16889
16904
  });
16890
- var TrackSnapshotSchema = object({
16891
- timestamp: number(),
16892
- position: TrackPositionSchema,
16893
- /** MediaStore key; resolve via `getTrackMedia({ trackId })`. */
16894
- mediaKey: string()
16905
+ var ConfigFieldBridge = custom();
16906
+ var PipelineAddonSchemaSchema = object({
16907
+ id: string(),
16908
+ name: string(),
16909
+ slot: PipelineSlotSchema,
16910
+ inputClasses: array(string()).readonly(),
16911
+ outputClasses: array(string()).readonly(),
16912
+ childSlots: array(PipelineSlotSchema).readonly(),
16913
+ models: array(PipelineModelOptionSchema).readonly(),
16914
+ defaultModelId: string(),
16915
+ defaultModelIdByFormat: record(string(), string()).optional(),
16916
+ enabledByDefault: boolean().optional(),
16917
+ backfillIntoExistingOverrides: boolean().optional(),
16918
+ defaultConfidence: number(),
16919
+ group: string().optional(),
16920
+ configSchema: array(ConfigFieldBridge).readonly().optional()
16895
16921
  });
16896
- /**
16897
- * Normalized 0..1 trajectory envelope (min/max over every position bbox,
16898
- * divided by the track's detection-frame dims), computed at persist time.
16899
- * Absent when the frame dims were unknown when the track was persisted
16900
- * (legacy rows / dims-less sources) and on active (in-RAM) tracks.
16901
- */
16902
- var TrackEnvelopeSchema = object({
16903
- minX: number(),
16904
- minY: number(),
16905
- maxX: number(),
16906
- maxY: number()
16922
+ var PipelineSlotSchemaSchema = object({
16923
+ id: PipelineSlotSchema,
16924
+ label: string(),
16925
+ priority: number(),
16926
+ parentSlot: PipelineSlotSchema.nullable(),
16927
+ addons: array(PipelineAddonSchemaSchema).readonly()
16907
16928
  });
16908
- /**
16909
- * Row projection for track list queries. `full` (default) returns the
16910
- * complete Track including the frame-rate `positions[]` history and the
16911
- * `snapshots[]` references — megabytes across a page of tracks. `slim`
16912
- * keeps every scalar the list surfaces actually render (ids, class(es),
16913
- * label / audioLabels / importance enrichment, firstSeen/lastSeen, state,
16914
- * zonesVisited, bestEventId, envelope, hasFace, hasEmbeddedFace, hasRider) and returns `positions` /
16915
- * `snapshots` as EMPTY arrays — detail views re-fetch the full row via
16916
- * `getTrack`. Mirrors the event-store `projection` convention
16917
- * (`getObjectEvents` et al.).
16918
- */
16919
- var TrackProjectionSchema = _enum(["full", "slim"]);
16920
- /**
16921
- * One audio-classification label heard on the track's camera while the
16922
- * track was alive, aggregated per label. An "episode" is one persisted
16923
- * audio event (the confident-classification path: score ≥ the device's
16924
- * `classificationMinScore`, class-change-or-heartbeat coalesced) — NOT
16925
- * one 32 ms inference chunk, so counts stay human-scaled.
16926
- */
16927
- var TrackAudioLabelSchema = object({
16928
- label: string(),
16929
- /** Highest classification score observed across the label's episodes. */
16930
- peakScore: number(),
16931
- /** Number of coalesced audio-event episodes carrying this label. */
16932
- count: number(),
16933
- firstAt: number(),
16934
- lastAt: number()
16929
+ var PipelineSchemaSchema = object({
16930
+ availableEngines: array(AvailableEngineSchema).readonly(),
16931
+ selectedEngine: PipelineEngineChoiceSchema,
16932
+ slots: array(PipelineSlotSchemaSchema).readonly()
16935
16933
  });
16936
- /**
16937
- * How a track was produced. `pipeline` (default / absent) = the spatial
16938
- * detection+tracking pipeline. Every OTHER value is a SYNTHETIC projection —
16939
- * no positions, a single snapshot, and no bbox trajectory at all:
16940
- *
16941
- * - `sensor` — a linked sensor/control device state change.
16942
- * - `audio` — an audio event on the camera itself that was anomalous for
16943
- * THAT camera, loud, and heard while nothing visual was happening (D62).
16944
- *
16945
- * The spatial subsystems (tracker association, occupancy count, re-id /
16946
- * embedding, resurrection) MUST skip every synthetic source. Test for that
16947
- * with `isSpatialTrack`, which allow-lists `pipeline` — a `!== 'sensor'`
16948
- * check silently readmits every source added after it was written.
16949
- */
16950
- var TrackSourceSchema = _enum([
16951
- "pipeline",
16952
- "sensor",
16953
- "audio"
16954
- ]);
16955
- /**
16956
- * Where a track sits in the RETRAIN lifecycle (D81).
16957
- *
16958
- * - `none` never marked, or un-marked. Evictable.
16959
- * - `staging`the operator wants this track as training material and has not
16960
- * finished with it. **This is the only state retention holds**: the track and
16961
- * everything it owns (object events, crops, keyframes, CLIP vector) survive
16962
- * the device's age window.
16963
- * - `trained` — the retrain page has taken what it needed. The frames it chose
16964
- * were COPIED into the retrain dataset at selection time, so the dataset no
16965
- * longer depends on the track's media and the track becomes EVICTABLE again.
16966
- * Terminal for the plain `markForTrain` toggle: returning it to `staging` is
16967
- * a deliberate action of the retrain page, not a side effect of a checkbox.
16968
- *
16969
- * There is no `null`. The state is stored `TEXT NOT NULL DEFAULT 'none'` because
16970
- * the store's filter language has only positive equality and `whereIn` — no
16971
- * negation, no IS NULL — so a NULL would be unselectable by ANY predicate and
16972
- * would make the entire pre-column history immortal in one deploy.
16973
- */
16974
- var RetrainStatusSchema = _enum([
16975
- "none",
16976
- "staging",
16977
- "trained"
16978
- ]);
16979
- /**
16980
- * Per-track OPERATOR flags — set by hand from the admin UI or the viewer, never
16981
- * by the pipeline. Spread into `TrackSchema` and `KeyEventSchema` from one place
16982
- * so the two surfaces cannot drift.
16983
- *
16984
- * **Absent ≠ false.** A track that has never been touched omits the field; an
16985
- * explicitly un-flagged track carries `false`. Legacy rows written before the
16986
- * columns existed read as absent, and a consumer that needs a boolean should say
16987
- * `flag === true`, not `flag !== false`.
16988
- *
16989
- * `markForTrain` is the WIRE FACE of {@link RetrainStatusSchema}, not a column:
16990
- * it is exactly `retrainStatus === 'staging'`, in both directions. Writing
16991
- * `true` moves `none → staging`, writing `false` moves `staging → none`, and a
16992
- * `trained` track reports `false` while refusing both writes. The boolean is
16993
- * kept because three surfaces drive a toggle off it; anything that needs to tell
16994
- * "never marked" from "already trained" must read `retrainStatus`.
16995
- *
16996
- * `debug` does NOT pin; it is attention, not durability.
16997
- *
16998
- * `favourited` IS a BOOLEAN pin (durability bit), not a retrain lifecycle.
16999
- * A favourited track is skipped by retention the same way `staging` is, but
17000
- * it does not enter `none|staging|trained` and has no staging budget.
17001
- */
17002
- var TrackFlagFields = {
17003
- /** Operator marked this track as training material — i.e. `retrainStatus` is
17004
- * `'staging'`. */
17005
- markForTrain: boolean().optional(),
17006
- /** Operator marked this track for diagnostic attention. */
17007
- debug: boolean().optional(),
17008
- /** Operator favourited this track. Pins it against pruning. */
17009
- favourited: boolean().optional()
17010
- };
17011
- /**
17012
- * The lifecycle field itself, on the READ surfaces only (`Track`, `KeyEvent`).
17013
- * Deliberately NOT part of {@link TrackFlagFields}: that group also builds the
17014
- * write patch, and the status is not something the toggle sets — it is what the
17015
- * toggle's boolean is derived from. Absent on an in-RAM track never touched;
17016
- * always present on a persisted row (the column default materialises `'none'`).
17017
- */
17018
- var TrackRetrainFields = { retrainStatus: RetrainStatusSchema.optional() };
17019
- /**
17020
- * The write half: a PARTIAL patch. An omitted key is left untouched, so setting
17021
- * one flag can never clear the other — the toggles are independent and are
17022
- * driven from three surfaces that do not know about each other.
17023
- */
17024
- var TrackFlagsPatchSchema = object(TrackFlagFields);
17025
- /**
17026
- * The resolved flag state after a write. Both fields are REQUIRED here (absent
17027
- * collapses to `false`) so a caller can drive a toggle's checked state off the
17028
- * mutation result without a re-fetch.
17029
- */
17030
- var TrackFlagsSchema = object({
17031
- trackId: string(),
17032
- markForTrain: boolean(),
17033
- debug: boolean(),
17034
- favourited: boolean(),
17035
- /** The lifecycle state the boolean was derived from. Required here (unlike on
17036
- * a track row) because this shape is only ever produced by the write body,
17037
- * which always knows it — and a surface that has just written needs to render
17038
- * `trained` without a re-fetch. */
17039
- retrainStatus: RetrainStatusSchema
16934
+ var EngineProvisioningSchema = object({
16935
+ runtimeId: _enum([
16936
+ "onnx",
16937
+ "openvino",
16938
+ "coreml",
16939
+ "edgetpu"
16940
+ ]).nullable(),
16941
+ device: string().nullable(),
16942
+ state: _enum([
16943
+ "idle",
16944
+ "installing",
16945
+ "verifying",
16946
+ "ready",
16947
+ "failed"
16948
+ ]),
16949
+ progress: number().optional(),
16950
+ error: string().optional(),
16951
+ nextRetryAt: number().optional(),
16952
+ /**
16953
+ * Gate A (config-correctness gate at engine change): human-readable
16954
+ * config issues surfaced EAGERLY when the node's engine changes — model
16955
+ * substitutions ("chose X, running Y") and zero-build steps ("no model
16956
+ * has a <format> build"). Additive/optional: informational only, never
16957
+ * enforced here `assertEngineReady` (readiness) still gates inference.
16958
+ * Absent/empty when the node-default tree resolves cleanly.
16959
+ */
16960
+ configIssues: array(string()).optional()
17040
16961
  });
17041
- union([literal(1), literal(2)]);
17042
- /**
17043
- * WHO decided a label, and when. Carried per tier so a value can be traced to
17044
- * the step and model that produced it — which is what makes the write rule
17045
- * arguable after the fact ("why is 592's label `dog` and not `Canis lupus`?")
17046
- * and what lets a migrated, UNATTRIBUTED value be told apart from a real one.
17047
- *
17048
- * `stepId` is the pipeline step id (`animal-classifier`, `bird-classifier`,
17049
- * `plate-ocr`, `face-embedding`, `object-detection`), or the sentinel
17050
- * `migration:4g` for a value the 4g migration moved from the single-slot era —
17051
- * that value has no provenance, and the write rule lets ANY properly-attributed
17052
- * write of the same tier replace it regardless of score.
17053
- */
17054
- var LabelAttributionSchema = object({
17055
- stepId: string(),
16962
+ var PipelineStepInputSchema = lazy(() => object({
16963
+ addonId: string(),
17056
16964
  modelId: string().optional(),
17057
- decidedAt: number(),
16965
+ enabled: boolean().default(true),
16966
+ children: array(PipelineStepInputSchema).optional(),
16967
+ settings: record(string(), unknown()).optional(),
16968
+ jumpDeviceKey: string().optional()
16969
+ }));
16970
+ var ModelSubstitutionSchema = object({
16971
+ addonId: string(),
16972
+ chosen: string(),
16973
+ running: string(),
16974
+ format: string()
16975
+ });
16976
+ var PipelineValidationIssueSchema = object({
16977
+ addonId: string(),
16978
+ kind: _enum(["unknown-addon", "no-format-build"]),
16979
+ detail: string()
16980
+ });
16981
+ var PipelineValidationResultSchema = object({
16982
+ ok: boolean(),
16983
+ issues: array(PipelineValidationIssueSchema).readonly(),
16984
+ substitutions: array(ModelSubstitutionSchema).readonly(),
16985
+ /** The node's `currentEngine.format` this validation ran against. */
16986
+ format: string()
16987
+ });
16988
+ var ReferenceImageEntrySchema = object({
16989
+ filename: string(),
16990
+ stepIds: array(string()).readonly().optional()
16991
+ });
16992
+ var ReferenceImageBodySchema = object({
16993
+ base64: string(),
16994
+ filename: string()
16995
+ });
16996
+ var ReferenceAudioEntrySchema = object({
16997
+ filename: string(),
16998
+ sizeKb: number()
16999
+ });
17000
+ var ReferenceAudioBodySchema = object({ base64: string() });
17001
+ var AudioBackendSchema = object({
17002
+ id: string(),
17003
+ name: string(),
17004
+ description: string(),
17005
+ available: boolean(),
17058
17006
  /**
17059
- * The GALLERY id behind a recognised tier-2 label — a face-gallery
17060
- * `Identity.id` or a plate-gallery `Vehicle.id` (both `randomUUID`).
17061
- *
17062
- * The text alone is a DISPLAY NAME, and a display name is renameable: a
17063
- * notification rule authored on "Gianluca" stopped matching the moment the
17064
- * operator fixed the spelling in the gallery, and nothing said so. The id is
17065
- * the thing that does not move, so it is what a rule matches on
17066
- * (`NcConditions.identities`) and the text is what a human is shown.
17067
- *
17068
- * Absent when the label names no gallery row — a plate the OCR read but no
17069
- * vehicle claims, a sub-class, a species, any tier-1 value.
17007
+ * Raw classifier labels this backend can emit (e.g. YAMNet's
17008
+ * 521-class set or Apple SoundAnalysis's 303-class set). Used by
17009
+ * the benchmark UI to populate the `enabledMicroClasses` filter
17010
+ * specific to the selected backend without a separate fetch.
17070
17011
  */
17071
- identityId: string().optional()
17012
+ rawLabels: array(string()).readonly().optional()
17013
+ });
17014
+ var AudioCapabilitiesSchema = object({
17015
+ activeBackend: string(),
17016
+ availableBackends: array(AudioBackendSchema).readonly(),
17017
+ sampleRate: number(),
17018
+ chunkDurationMs: number()
17019
+ });
17020
+ var DownloadModelResultSchema = object({
17021
+ filePath: string(),
17022
+ sizeMB: number(),
17023
+ durationMs: number()
17072
17024
  });
17073
17025
  /**
17074
- * The TIERED label model (roadmap 4g), spread into `TrackSchema` and
17075
- * `ObjectEventSchema` from ONE place so the two surfaces cannot drift — a
17076
- * track and its events always answer the same question the same way.
17077
- *
17078
- * Two scalar columns, not an array: every consumer wants "the coarse one" or
17079
- * "the fine one", and an array made both a scan. `label` is tier 1, `subLabel`
17080
- * is tier 2, and each carries its own score + attribution.
17081
- *
17082
- * **Reading it.** What a human should be shown is `subLabel ?? label` — the
17083
- * finest thing known. Before 4g the single `label` column held the finest
17084
- * value, so a consumer that has not been updated reads the tier-1 slot and
17085
- * shows nothing on a species-only row; that is why the migration puts every
17086
- * pre-4g value in tier 2 (it cannot regress a display that reads the fallback)
17087
- * and why the read surfaces were changed in the same train.
17088
- *
17089
- * **Writing it.** The slots are independent, which is the whole point: a
17090
- * tier-1 write (`bird`) can never overwrite a tier-2 value (`Turdus
17091
- * migratorius`), so fineness cannot regress by construction. Within a tier the
17092
- * higher score wins. One rule, one implementation — see
17093
- * `pipeline/label-tier.ts` in addon-post-analysis.
17094
- */
17095
- var TieredLabelFields = {
17096
- /** Tier 1 — the sub-class. See {@link LabelTierSchema}. */
17097
- label: string().optional(),
17098
- /** Confidence of the tier-1 value, as reported by the deciding step. */
17099
- labelScore: number().optional(),
17100
- /** Provenance of the tier-1 value. See {@link LabelAttributionSchema}. */
17101
- labelMeta: LabelAttributionSchema.optional(),
17102
- /** Tier 2 — the instance. See {@link LabelTierSchema}. */
17103
- subLabel: string().optional(),
17104
- /** Confidence of the tier-2 value, as reported by the deciding step. */
17105
- subLabelScore: number().optional(),
17106
- /** Provenance of the tier-2 value. See {@link LabelAttributionSchema}. */
17107
- subLabelMeta: LabelAttributionSchema.optional()
17108
- };
17109
- /** Per-camera slice of a training-export estimate. */
17110
- var TrainingExportDeviceTotalsSchema = object({
17111
- deviceId: number(),
17112
- tracks: number().int(),
17113
- files: number().int(),
17114
- bytes: number().int()
17115
- });
17116
- /**
17117
- * What a training export WOULD contain. Computed from media index rows only —
17118
- * no blob is read to produce this.
17026
+ * Wrapper carrying a single test run's result. Replaces the legacy
17027
+ * ad-hoc `{labels: [{className, originalClass, score}]}` shape with the
17028
+ * canonical `AudioResult` from the Phase 6 output rework: one
17029
+ * `AudioDetection` per class above `minScore`, top-N candidates in
17030
+ * `debug.alternateLabels['audio-classifier']`, per-source timings in
17031
+ * `debug.stepTimings`. The outer `success`/`error` fields stay so the
17032
+ * benchmark UI can still report a clean failure when the classifier
17033
+ * cap isn't available.
17119
17034
  */
17120
- var TrainingExportSummarySchema = object({
17121
- generatedAt: number(),
17122
- trackCount: number().int(),
17123
- fileCount: number().int(),
17124
- byteCount: number().int(),
17125
- /** More marked tracks exist than a single pass carries. */
17126
- truncated: boolean(),
17127
- devices: array(TrainingExportDeviceTotalsSchema).readonly()
17035
+ var AudioTestResultSchema = object({
17036
+ success: boolean(),
17037
+ error: string().optional(),
17038
+ frame: custom().optional()
17128
17039
  });
17129
- var TrackSchema = object({
17130
- trackId: string(),
17131
- deviceId: number(),
17132
- className: string(),
17133
- ...TieredLabelFields,
17134
- producingDeviceName: string().optional(),
17135
- /** Track provenance. Absent `pipeline` (legacy rows). */
17136
- source: TrackSourceSchema.optional(),
17137
- firstSeen: number(),
17138
- lastSeen: number(),
17139
- /** Frame-rate position history (subject to maxPositionHistory cap). */
17140
- positions: array(TrackPositionSchema).readonly(),
17141
- /** Periodic snapshots at snapshotIntervalMs cadence (subject to
17142
- * saveThumbnails policy). */
17143
- snapshots: array(TrackSnapshotSchema).readonly(),
17144
- /** Deduplicated zones the track has entered at least once. Zone IDS. */
17145
- zonesVisited: array(string()).readonly(),
17040
+ var PipelineConfigBridge = custom();
17041
+ var ConfigUISchemaBridge = custom();
17042
+ var ConfigUISchemaNullableBridge = custom();
17043
+ var InferenceCapabilitiesBridge = custom();
17044
+ var ModelAvailabilityListBridge = custom();
17045
+ var PipelineRunResultBridge = custom();
17046
+ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngineChoiceSchema), method(PipelineEngineChoiceSchema, array(PipelineDefaultStepSchema)), method(object({ nodeId: string() }), EngineProvisioningSchema), method(_void(), record(string(), object({
17047
+ modelId: string(),
17048
+ settings: record(string(), unknown()).readonly()
17049
+ }))), method(object({ steps: record(string(), object({
17050
+ modelId: string(),
17051
+ settings: record(string(), unknown()).readonly()
17052
+ })) }), object({ success: literal(true) }), {
17053
+ kind: "mutation",
17054
+ auth: "admin"
17055
+ }), method(object({ nodeId: string() }), object({
17056
+ success: literal(true),
17057
+ clearedDevices: number()
17058
+ }), {
17059
+ kind: "mutation",
17060
+ auth: "admin"
17061
+ }), method(object({ nodeId: string() }), object({ unhealthy: array(object({
17062
+ /** `<backend>:<device>`, e.g. `openvino:gpu`. */
17063
+ deviceKey: string(),
17146
17064
  /**
17147
- * Human NAMES for {@link zonesVisited}, resolved at READ time against the
17148
- * `zones` capability.
17149
- *
17150
- * `zonesVisited` persists ids (`cfeec78c-8d69-…`), which no operator can type
17151
- * and no card can render — so every free-text search surface was structurally
17152
- * unable to answer "show me the tracks in Uscio", and did not fail loudly, it
17153
- * just returned nothing. Resolving here rather than in each client keeps ONE
17154
- * derivation and costs the clients no extra call (the `zones` cap is
17155
- * per-device, so a client-side resolve would be a per-camera fan-out on a
17156
- * surface built to avoid exactly that).
17157
- *
17158
- * Resolved, never invented: a zone deleted since the track was written has no
17159
- * name and is DROPPED, so this array can be shorter than `zonesVisited` — the
17160
- * two are not positionally aligned. Absent when the track visited no zone, or
17161
- * when the zone catalogue could not be read.
17065
+ * `failed` the per-device restart budget is exhausted; no pool
17066
+ * will be spawned until an operator re-arms it or the runner
17067
+ * respawns. `backoff` — under budget, waiting out the backoff (or
17068
+ * a cached pool observed dead and not yet condemned).
17162
17069
  */
17163
- zoneNames: array(string()).readonly().optional(),
17164
- /** Deduplicated set of detector classes observed for this track over its
17165
- * life (a track may be reclassified, e.g. person→vehicle). Absent on
17166
- * legacy rows written before class accumulation shipped. */
17167
- classes: array(string()).readonly().optional(),
17168
- /** Cumulative normalized distance travelled (0..1 units = full frame width). */
17169
- totalDistance: number(),
17170
- state: TrackStateSchema,
17171
- active: boolean(),
17172
- /** Deterministic key-event importance score in [0,1] (server-computed at
17173
- * track expiry, recomputed on late label). Absent on legacy rows written
17174
- * before scoring shipped — consumers degrade to absence / compute-on-read. */
17175
- importance: number().optional(),
17176
- /** Id of the track's highest-confidence ObjectEvent (its representative
17177
- * "best" frame). Absent when the track produced no object events. */
17178
- bestEventId: string().optional(),
17179
- /** Tag of the importance sub-signal that dominated the score
17180
- * (identity|dwell|proximity|class|confidence|travel|zone). */
17181
- importanceReason: string().optional(),
17182
- /** Audio-classification labels heard on the camera during the track's
17183
- * life (score ≥ device `classificationMinScore`), aggregated per label.
17184
- * Absent on legacy rows / tracks with no confident audio. */
17185
- audioLabels: array(TrackAudioLabelSchema).readonly().optional(),
17186
- /** Normalized 0..1 trajectory envelope (see {@link TrackEnvelopeSchema}).
17187
- * Populated from the persisted envelope columns on historical reads;
17188
- * absent on legacy rows, dims-less tracks and active (in-RAM) tracks. */
17189
- envelope: TrackEnvelopeSchema.optional(),
17070
+ state: _enum(["failed", "backoff"]),
17071
+ /** Epoch ms of the death that produced this state. */
17072
+ since: number(),
17073
+ /** Pool deaths inside the current window. */
17074
+ deaths: number(),
17075
+ /** The last death's message. */
17076
+ lastError: string()
17077
+ })).readonly() })), method(object({
17078
+ nodeId: string(),
17079
+ deviceKey: string()
17080
+ }), object({ rearmed: boolean() }), {
17081
+ kind: "mutation",
17082
+ auth: "admin"
17083
+ }), method(_void(), PipelineSchemaSchema), method(_void(), array(PipelineDefaultStepSchema).readonly().nullable()), method(_void(), PipelineConfigBridge), method(_void(), ConfigUISchemaBridge), method(object({ steps: array(PipelineStepInputSchema) }), PipelineValidationResultSchema), method(_void(), array(PipelineTemplateSchema$1).readonly()), method(object({
17084
+ name: string(),
17085
+ steps: array(PipelineTemplateStepSchema).readonly(),
17086
+ engine: PipelineEngineChoiceSchema
17087
+ }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({
17088
+ id: string(),
17089
+ name: string().optional(),
17090
+ steps: array(PipelineTemplateStepSchema).readonly().optional()
17091
+ }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({ id: string() }), _void(), { kind: "mutation" }), method(_void(), InferenceCapabilitiesBridge), method(object({ addonId: string() }), ModelAvailabilityListBridge), method(object({
17092
+ addonId: string(),
17093
+ modelId: string(),
17094
+ format: ModelFormatSchema$1
17095
+ }), DownloadModelResultSchema, { kind: "mutation" }), method(object({
17096
+ addonId: string(),
17097
+ modelId: string(),
17098
+ format: ModelFormatSchema$1
17099
+ }), object({ success: literal(true) }), { kind: "mutation" }), method(object({
17100
+ engine: PipelineEngineChoiceSchema.optional(),
17101
+ steps: array(PipelineStepInputSchema).min(1),
17102
+ frame: FrameInputSchema.optional(),
17190
17103
  /**
17191
- * A face DETECTOR found a face on this track — nothing more. It says the
17192
- * detail plane produced a `face` detail; it does NOT say the face was
17193
- * embedded, matched, above `minFacePx`, or that the recognizer was even
17194
- * enabled. Set once and never cleared.
17195
- *
17196
- * **This exists so "face present but not recognised" is expressible.** A
17197
- * recognised identity lands in `subLabel` (attributed to the face chain via
17198
- * `subLabelMeta.stepId`), so before this field a track with an unmatched face
17199
- * and a track with no face at all were byte-identical on the wire and no
17200
- * surface could tell them apart. The read is `hasFace === true && subLabel
17201
- * === undefined`.
17202
- *
17203
- * **Absent ≠ false.** Every row written before the column existed omits it,
17204
- * and so does every server that predates the field — a consumer must test
17205
- * `=== true` and render nothing otherwise, never infer "no face".
17104
+ * Process-local lazy frame. Valid only when caller and provider resolve
17105
+ * in the same execution-group process; split/cross-node callers use
17106
+ * `frame`/`image` inline compatibility instead.
17206
17107
  */
17207
- hasFace: boolean().optional(),
17108
+ frameRef: FrameRefSchema.optional(),
17208
17109
  /**
17209
- * This track has a face row IN THE GALLERY: a crop **and** an embedding a
17210
- * face an operator could ASSIGN to an identity.
17211
- *
17212
- * The STRICT twin of {@link hasFace}, and the pair only earns its keep
17213
- * because the two disagree. `hasFace` is stamped at the TOP of the face
17214
- * branch, before every gate, and means no more than "a face detector produced
17215
- * a face detail". This one is stamped at the single moment the gallery row
17216
- * LANDS — after `FaceRecognizer.onTrackEnd` successfully persists it, i.e.
17217
- * past the embedding-magnitude verdict, the `minFacePx` detection gate, the
17218
- * candidate gate, the imageless-track drop (no crop was ever captured) and
17219
- * the crop-store drop. Everything between the detector and that insert can
17220
- * legitimately refuse the face, so a flag written any earlier promises the
17221
- * operator something to assign and delivers nothing.
17222
- *
17223
- * **Independent of recognition.** A face collected but never auto-matched is
17224
- * still assignable — it is in fact the face an operator most wants to reach —
17225
- * so this is NOT gated on `recognizedIdentityId`. Recognition lands in
17226
- * `subLabel`; this says only that the raw material exists.
17227
- *
17228
- * **Set once, never cleared.** A track that produced a gallery row produced
17229
- * one; deleting the row later is the gallery's business, not this flag's.
17230
- *
17231
- * **Absent ≠ false**, the same rule as {@link hasFace}: every row written
17232
- * before the column omits it, and so does every server that predates the
17233
- * field. A consumer must test `=== true` and render nothing otherwise —
17234
- * never infer "no assignable face".
17110
+ * CB5 shm passthrough a `FrameHandle` naming the same ring slot
17111
+ * the decoded pixels live in. One more member of the one-of
17112
+ * frame/frameHandle/image/imageBase64/referenceImage group.
17235
17113
  */
17236
- hasEmbeddedFace: boolean().optional(),
17114
+ frameHandle: FrameHandleSchema.optional(),
17115
+ imageBase64: string().optional(),
17237
17116
  /**
17238
- * This subject CONTAINS a folded rider a person the rider-pairing step
17239
- * ([D34](../decisions/adr-0034.md)) removed from the frame BEFORE the tracker,
17240
- * so the passage is tracked once and as a VEHICLE.
17241
- *
17242
- * It exists because the fold's record was dishonest. D34 and the code both
17243
- * said "the person is not lost — it is reported so both entities stay on the
17244
- * record"; in fact the pair went into a per-processor RAM field behind an
17245
- * accessor nobody called, and every durable surface said `vehicle`, full
17246
- * stop. This is the composition note that makes the row true.
17247
- *
17248
- * A COMPOSITION, never a class and never a label. "This vehicle contains a
17249
- * person" is not an answer to "what is this" — both label tiers would refuse
17250
- * a macro token anyway (D89), and correctly. Nothing here changes what the
17251
- * subject IS: a cyclist stays one vehicle track, occupancy still counts one,
17252
- * and a `person` rule still does not fire for someone cycling past.
17253
- *
17254
- * **Absent ≠ false**, exactly like {@link hasFace}: every row written before
17255
- * the column, and every hub that predates the field, omits it. Test
17256
- * `=== true` and render nothing otherwise — never infer "no rider".
17117
+ * Binary JPEG bytespreferred over `imageBase64` on internal
17118
+ * hops (hub forked worker via Moleculer MsgPack) because it
17119
+ * skips the 33% base64 overhead + the per-call base64 decode on
17120
+ * the detection-pipeline worker. Callers can pass either; exactly
17121
+ * one of `frame`/`image`/`imageBase64`/`referenceImage` is required.
17257
17122
  */
17258
- hasRider: boolean().optional(),
17259
- ...TrackFlagFields,
17260
- ...TrackRetrainFields
17261
- });
17262
- var BaseEventFields = {
17263
- id: string(),
17264
- deviceId: number(),
17265
- timestamp: number()
17266
- };
17267
- var MotionEventSchema = object({
17268
- ...BaseEventFields,
17269
- kind: literal("motion"),
17270
- regionCount: number(),
17271
- /** Heavy JSON array omitted in slim projection. */
17272
- regions: array(object({
17273
- bbox: BoundingBoxSchema,
17274
- pixelCount: number(),
17275
- intensity: number()
17276
- })).readonly().optional(),
17277
- /** Omitted in slim projection. */
17278
- frameWidth: number().optional(),
17279
- /** Omitted in slim projection. */
17280
- frameHeight: number().optional(),
17281
- /** Populated by B5 (recording playback URL for this event). */
17282
- mediaUrl: string().optional()
17283
- });
17123
+ image: _instanceof(Uint8Array).optional(),
17124
+ referenceImage: string().optional(),
17125
+ deviceId: number().optional(),
17126
+ sessionId: string().optional(),
17127
+ /**
17128
+ * Execution plane. 'full' (default) runs the whole tree — benchmark,
17129
+ * reference-image, and detail-subtree calls. 'frame' is the live
17130
+ * per-frame dispatch: ONLY root-plane steps run; crop children
17131
+ * (inputClasses ≠ null) are skipped and served per-track via
17132
+ * pipelineRunner.runDetailSubtree (two-plane design).
17133
+ */
17134
+ plane: _enum(["full", "frame"]).optional(),
17135
+ /**
17136
+ * Inference-device selector (Phase 2 multi-device). Format
17137
+ * `<backend>:<device>` (e.g. `openvino:gpu`, `edgetpu:usb`, `cpu`).
17138
+ * Omitted ⇒ the runner's default device (current single-engine
17139
+ * behaviour). Selects WHICH device pool of the node runs the call.
17140
+ */
17141
+ deviceKey: string().optional(),
17142
+ /**
17143
+ * Two-plane NATIVE child-crop reference. Set by `runDetailSubtree` ONLY
17144
+ * when the parent crop was resolved from the frame's retained NATIVE
17145
+ * surface (a frameHandle HIT). Lets the executor re-cut a LEAF crop
17146
+ * child's ROI (plate-ocr, face-embedding, leaf classifiers) at native
17147
+ * resolution from that surface — the SAME quality path faces already
17148
+ * had — instead of the downscaled parent tile. `handle` keys the native
17149
+ * surface (node-pinned to its owner); `cropFrameSpace` is the parent
17150
+ * crop's padded/clamped rectangle in FRAME-space pixels, used to compose
17151
+ * the executor's crop-normalized child ROI back into frame-normalized
17152
+ * coordinates. Auxiliary to the image source (`image`/`frame`/…), NOT one
17153
+ * of the mutually-exclusive image inputs. Absent ⇒ tile-crop children
17154
+ * (today's behaviour on the fallback path).
17155
+ */
17156
+ nativeCropRef: NativeCropRefSchema.optional()
17157
+ }), PipelineRunResultBridge, { kind: "mutation" }), method(object({
17158
+ engine: PipelineEngineChoiceSchema.optional(),
17159
+ steps: array(PipelineStepInputSchema).min(1),
17160
+ frames: array(FrameInputSchema).min(1).max(255),
17161
+ deviceId: number().optional(),
17162
+ sessionId: string().optional(),
17163
+ /**
17164
+ * Pure-inference benchmark hint. A NONZERO uint32 pins every frame in
17165
+ * the batch to the Python pool's bench preprocess cache
17166
+ * (`_bench_frame_id`) so a REPEATED benchmark frame is decoded +
17167
+ * preprocessed ONCE and every later inference is a pure-inference cache
17168
+ * hit — the sustained-throughput run measures inference, not
17169
+ * decode+preprocess+infer. Omitted/0 for live frames (all different →
17170
+ * full preprocess every call, correct). Fresh per sustained run;
17171
+ * released via `uncacheFrame`.
17172
+ */
17173
+ frameId: number().int().nonnegative().optional(),
17174
+ /** Inference-device selector (Phase 2 multi-device); see runPipeline. */
17175
+ deviceKey: string().optional()
17176
+ }), object({ results: array(PipelineRunResultBridge).readonly() }), { kind: "mutation" }), method(object({
17177
+ data: _instanceof(Uint8Array),
17178
+ width: number().int().positive(),
17179
+ height: number().int().positive(),
17180
+ format: _enum([
17181
+ "rgb",
17182
+ "bgr",
17183
+ "gray"
17184
+ ])
17185
+ }), object({
17186
+ frameId: number(),
17187
+ width: number(),
17188
+ height: number()
17189
+ }), { kind: "mutation" }), method(object({
17190
+ stepId: string(),
17191
+ frameId: number().int()
17192
+ }), record(string(), unknown()), { kind: "mutation" }), method(object({ frameId: number().int() }), _void(), { kind: "mutation" }), method(_void(), object({
17193
+ batchMode: string(),
17194
+ windowMs: number(),
17195
+ maxBatchSize: number(),
17196
+ concurrency: number()
17197
+ })), method(_void(), array(object({
17198
+ engineKey: string(),
17199
+ engine: PipelineEngineChoiceSchema,
17200
+ modelsLoaded: array(string()).readonly(),
17201
+ inUseByCameras: array(number()).readonly(),
17202
+ /**
17203
+ * Origin of this resident factory.
17204
+ * - `runtime` — main camera-serving engine (no idle TTL).
17205
+ * - `warm-override` — benchmark/test override held in the warm
17206
+ * cache; auto-disposed after the idle TTL.
17207
+ * - `device-pool` — a concurrent per-device pool (Phase 2
17208
+ * multi-device, keyed by `deviceKey`) resolved
17209
+ * via `resolveDeviceFactory`. Runs alongside the
17210
+ * `runtime` engine on a DIFFERENT accelerator
17211
+ * (NPU / iGPU / Coral) — this is how the
17212
+ * Engines tab shows all pools running at once.
17213
+ */
17214
+ kind: _enum([
17215
+ "runtime",
17216
+ "warm-override",
17217
+ "device-pool"
17218
+ ]),
17219
+ /** Native pid of the underlying Python pool (null when no pool). */
17220
+ poolPid: number().nullable(),
17221
+ /** ms since this factory was last used (null when not warm-tracked). */
17222
+ idleMs: number().nullable(),
17223
+ /** Idle TTL after which `warm-override` factories self-evict (null when not applicable). */
17224
+ idleTtlMs: number().nullable()
17225
+ })).readonly()), method(object({ engine: PipelineEngineChoiceSchema }), object({ success: literal(true) }), {
17226
+ kind: "mutation",
17227
+ auth: "admin"
17228
+ }), method(object({
17229
+ engine: PipelineEngineChoiceSchema,
17230
+ force: boolean().optional()
17231
+ }), object({
17232
+ success: boolean(),
17233
+ reason: string().optional()
17234
+ }), {
17235
+ kind: "mutation",
17236
+ auth: "admin"
17237
+ }), method(_void(), array(ReferenceImageEntrySchema).readonly()), method(object({ filename: string() }), ReferenceImageBodySchema.nullable()), method(_void(), array(ReferenceAudioEntrySchema).readonly()), method(object({ filename: string() }), ReferenceAudioBodySchema.nullable()), method(_void(), AudioCapabilitiesSchema), method(object({
17238
+ addonId: string(),
17239
+ modelId: string(),
17240
+ filename: string().optional(),
17241
+ settings: record(string(), unknown()).optional()
17242
+ }), AudioTestResultSchema, { kind: "mutation" }), method(_void(), ConfigUISchemaNullableBridge);
17284
17243
  /**
17285
- * Which detection SOURCE produced an object event. `pipeline` = the ML
17286
- * detection pipeline (decoded-frame inference); `onboard` = the camera's
17287
- * native on-device AI. Both flow through the SAME analysis layers (zoning,
17288
- * tracking, per-kind persistence) but stay distinguishable so consumers
17289
- * (advanced-notifier, occupancy, …) can select which source(s) to act on.
17290
- * Absent on legacy rows treat as `pipeline`.
17244
+ * Per-stage gating mode applied to the zones a rule references.
17245
+ *
17246
+ * - `include`: the rule contributes to a **whitelist** for its stage.
17247
+ * When at least one `include` rule fires for a stage, only entities
17248
+ * inside one of those zones pass that stage.
17249
+ * - `exclude`: the rule contributes to a **blacklist** for its stage.
17250
+ * Entities inside one of those zones are dropped at that stage.
17251
+ *
17252
+ * `monitor`-style observation (count without filtering) is not a rule
17253
+ * mode — zones without any matching rule are observed naturally by
17254
+ * `zone-analytics` (live snapshot + history), so an "I just want to
17255
+ * count, not filter" use case needs no rule at all.
17291
17256
  */
17292
- var DetectionSourceSchema = _enum(["pipeline", "onboard"]);
17257
+ var ZoneRuleModeEnum = _enum(["include", "exclude"]);
17293
17258
  /**
17294
- * The confirmed zone crossing that produced an object event. Present ONLY on
17295
- * an event emitted BY a crossing (`zone.enter` / `zone.exit`); a movement-state
17296
- * event (`object.entering` / `leaving` / `stationary` / `loitering`) and an
17297
- * appearance event carry none, so a rule asking for a direction fails closed
17298
- * on them.
17259
+ * Per-consumer rule that references existing zones (geometry) and
17260
+ * defines how a specific pipeline stage should treat them. Each
17261
+ * consumer addon owns its own `ZoneRule[]` array in its per-device
17262
+ * settings:
17299
17263
  *
17300
- * Exactly ONE crossing per event: the emitter turns each confirmed crossing
17301
- * into its own event, so a frame in which a track enters A while leaving B
17302
- * produces two events with two directions — never one ambiguous row.
17264
+ * - `addon-motion-wasm` `motionZoneRules: ZoneRule[]` (motion stage)
17265
+ * - `addon-detection-pipeline` `detectionZoneRules: ZoneRule[]` (detection stage)
17266
+ * - future: notification rules, audio gating, etc.
17303
17267
  *
17304
- * `zoneId` is load-bearing for an EXIT: the event's `zones` list is the
17305
- * membership the box has NOW, and by definition it no longer contains the zone
17306
- * that was just left. Without the id here, a zone-scoped rule could never match
17307
- * the exit it asked for.
17268
+ * One rule applies to N zones (`zoneIds[]`) so the operator can
17269
+ * express "ignore motion in ALL of {garden, street}" with a single
17270
+ * rule. `classFilter` narrows the rule to specific object classes
17271
+ * "drop person detections in the street, but keep cars" is one
17272
+ * `exclude` rule with `classFilter: ['person']`.
17273
+ *
17274
+ * `enabled` is a soft toggle — the operator can keep the rule
17275
+ * configured but inert without deleting it.
17308
17276
  */
17309
- var ZoneCrossingSchema = object({
17310
- direction: _enum(["enter", "exit"]),
17311
- /** Admin zone id crossed. */
17312
- zoneId: string(),
17313
- /** Zone display name at crossing time (falls back to the id). */
17314
- zoneName: string().optional()
17315
- });
17316
- var ObjectEventSchema = object({
17317
- ...BaseEventFields,
17318
- kind: literal("object"),
17319
- /** Detection source. Optional for backward-compat; absent ⇒ `pipeline`. */
17320
- source: DetectionSourceSchema.optional(),
17277
+ var ZoneRuleSchema = object({
17278
+ /** Stable rule id — survives edits, used by the UI for diffing. */
17279
+ id: string(),
17280
+ /** Optional human-readable label rendered in the rule editor. */
17281
+ name: string().optional(),
17282
+ /** Zones this rule targets. The rule's `mode` applies to ALL
17283
+ * listed zones (OR-set: a detection in any one of them counts).
17284
+ * At least one zone id required — a rule with no targets is a
17285
+ * configuration mistake and the form validator rejects it. */
17286
+ zoneIds: array(string()).min(1).readonly(),
17287
+ mode: ZoneRuleModeEnum,
17321
17288
  /**
17322
- * Inference-frame id shared by every object event emitted from the SAME frame
17323
- * the "scene/parent" key. Lets a consumer group co-occurring detections (e.g.
17324
- * 2 people + 1 dog) under one full frame, and link a track's frames over time
17325
- * (group by `trackId`, pick a representative `frameId` as the parent frame).
17326
- * Optional for backward-compat with pre-existing rows / the slim projection
17327
- * includes it (it is light). Absent on rows written before this field.
17289
+ * Class names this rule applies to. Empty / undefined rule
17290
+ * applies to every class. Class strings match the `macroClass`
17291
+ * field on detections (e.g. `person`, `car`, `dog`).
17328
17292
  */
17329
- frameId: string().optional(),
17330
- /** Omitted in slim projection. */
17331
- trackId: string().optional(),
17332
- className: string(),
17333
- ...TieredLabelFields,
17334
- /** Omitted in slim projection. */
17335
- confidence: number().optional(),
17336
- /** Heavy JSON — omitted in slim projection. */
17337
- bbox: BoundingBoxSchema.optional(),
17338
- /** Heavy JSON — omitted in slim projection. */
17339
- zones: array(string()).readonly().optional(),
17340
- /** Omitted in slim projection. */
17341
- state: TrackStateSchema.optional(),
17293
+ classFilter: array(string()).readonly().optional(),
17342
17294
  /**
17343
- * The zone crossing this event IS, when it is one. Absent on every other
17344
- * event kind (movement state, appearance, package) see
17345
- * {@link ZoneCrossingSchema}. Omitted in slim projection.
17295
+ * Minimum bbox/mask overlap (0–1) with any of the rule's zones
17296
+ * required to consider an entity "in the zone". Defaults to the
17297
+ * consumer's stage default when omitted. Kept for back-compat with
17298
+ * existing per-rule overrides; new operators pick the value via
17299
+ * `bboxInclusionPct` (operator-friendly 0–100). Whichever field is
17300
+ * set, the lower-level engine reads it as a 0–1 fraction.
17346
17301
  */
17347
- zoneCrossing: ZoneCrossingSchema.optional(),
17348
- /** Detection-frame dimensions in pixels — let consumers normalize the
17349
- * pixel-space `bbox` onto a displayed image. Omitted in slim projection. */
17350
- frameWidth: number().optional(),
17351
- frameHeight: number().optional(),
17352
- /** MediaStore key for the crop attached to this event (if any). */
17353
- mediaKey: string().optional(),
17354
- /** Design B: MediaStore key of the track's native-resolution key frame (the
17355
- * best-detection full frame). Resolve via the event-media data-plane
17356
- * (`/addon/<addonId>/event-media/<keyFrameMediaKey>`) for a detail view that
17357
- * draws `bbox` over the native frame. Absent on legacy rows / non-decoded
17358
- * sources — consumers fall back to `mediaKey` (the tight crop). */
17359
- keyFrameMediaKey: string().optional(),
17360
- /** Populated by B5 (recording playback URL for this event). */
17361
- mediaUrl: string().optional(),
17362
- /** The parent track's key-event importance [0,1], propagated to every object
17363
- * event of the track (so an event row can be sorted by importance without a
17364
- * track join). Absent on legacy rows / before the track was scored. */
17365
- importance: number().optional()
17366
- });
17367
- var AudioEventSchema = object({
17368
- ...BaseEventFields,
17369
- kind: literal("audio"),
17370
- rms: number(),
17371
- dbfs: number(),
17372
- classification: object({
17373
- className: string(),
17374
- originalClass: string().optional(),
17375
- score: number()
17376
- }).optional(),
17377
- /** Populated by B5 (recording playback URL for this event). */
17378
- mediaUrl: string().optional()
17379
- });
17380
- var MediaFileKindEnum = _enum([
17381
- "crop",
17382
- "thumbnail",
17383
- "snapshot",
17384
- "firstFrame",
17385
- "lastFrame",
17386
- "fullFrame",
17387
- "fullFrameBoxed",
17388
- "faceCrop",
17389
- "plateCrop",
17390
- "keyFrame",
17391
- "keyFrameSmall",
17392
- "thumbnailSmall"
17393
- ]);
17394
- var MediaFileSchema = object({
17395
- key: string(),
17396
- kind: MediaFileKindEnum,
17397
- base64: string(),
17398
- sizeBytes: number(),
17399
- timestamp: number()
17302
+ overlapThreshold: number().min(0).max(1).optional(),
17303
+ /**
17304
+ * Operator-friendly version of `overlapThreshold` the percentage
17305
+ * of the detection's bbox that must lie inside the zone for the
17306
+ * rule to match. Documented default is 85%; the engine substitutes
17307
+ * that when the field is omitted (kept optional so existing rules
17308
+ * stored without it stay valid).
17309
+ *
17310
+ * When BOTH `overlapThreshold` and `bboxInclusionPct` are set on a
17311
+ * rule, the engine prefers `bboxInclusionPct` because it's the
17312
+ * field exposed in the UI. Internally both feed the same gate.
17313
+ */
17314
+ bboxInclusionPct: number().min(0).max(100).optional(),
17315
+ /**
17316
+ * When `true` and a detection has a segmentation mask, use the
17317
+ * mask for overlap instead of the bbox. Detection-stage only;
17318
+ * motion rules ignore this field.
17319
+ */
17320
+ preferMask: boolean().optional(),
17321
+ /**
17322
+ * Soft-toggle: `false` disables the rule without deleting it.
17323
+ * Defaults to `true` so operators creating a rule via the UI
17324
+ * see it active immediately.
17325
+ */
17326
+ enabled: boolean().default(true)
17400
17327
  });
17328
+ array(ZoneRuleSchema).readonly();
17401
17329
  /**
17402
- * One media row WITHOUT its bytes.
17330
+ * Zone pure geometry + identity. NO filtering behaviour.
17403
17331
  *
17404
- * A track's media is 5-8 MB of base64 (measured: 7.67 MB across 23 files for a
17405
- * 140 s track), and a client that renders tiles from the media data plane needs
17406
- * to know only WHAT EXISTS the bytes then arrive per tile, lazily, over HTTP
17407
- * with an immutable cache, instead of all at once inside a tRPC response that
17408
- * blocks the whole view.
17332
+ * Zones describe **where** in the frame the operator wants to flag
17333
+ * something; consumer-owned {@link ZoneRule} arrays describe **how**
17334
+ * each pipeline stage uses them. Splitting the two means a single
17335
+ * polygon "Driveway" can simultaneously back a motion-exclude rule,
17336
+ * a detection-include rule on `['car']`, and an occupancy aggregate
17337
+ * — without three duplicated polygons.
17409
17338
  *
17410
- * `sizeBytes` is carried because it is what lets a client decide between the
17411
- * stored blob and a `?variant=thumb` rendering without fetching either.
17339
+ * Owned by the orchestrator addon (provider) and mirrored into the
17340
+ * `zones` device-state slice on every mutation. Consumers
17341
+ * (motion-wasm, pipeline-executor, analytics, admin UI) read either
17342
+ * via `api.zones.listZones` (one-shot) or via `dev.state.zones` (live
17343
+ * mirror with `onChanged`).
17344
+ *
17345
+ * Coordinates are normalised fractions of the frame (0–1) so zones
17346
+ * survive resolution changes and stream profile switches.
17347
+ *
17348
+ * `kind` discriminates between full polygons (closed regions used
17349
+ * for intrusion / occupancy filters) and tripwires (open 2-point
17350
+ * line segments used for cross events). Onboard / firmware-reported
17351
+ * zones (Reolink, ONVIF) are out of scope for now — see the deferred
17352
+ * task list.
17412
17353
  */
17413
- var MediaFileInfoSchema = MediaFileSchema.omit({ base64: true });
17354
+ var ZoneKindEnum = _enum(["polygon", "tripwire"]);
17355
+ /** Polygon vertex in fraction-of-frame coordinates (0–1). */
17356
+ var PolygonPointSchema = object({
17357
+ x: number(),
17358
+ y: number()
17359
+ });
17360
+ /** A camera detection zone — pure geometry/identity. */
17361
+ var ZoneSchema = object({
17362
+ id: string(),
17363
+ name: string(),
17364
+ kind: ZoneKindEnum.default("polygon"),
17365
+ /** Polygon vertices, fraction of frame (0–1). */
17366
+ polygon: array(PolygonPointSchema).readonly(),
17367
+ /** Visual color for UI rendering. */
17368
+ color: string().default("#3b82f6")
17369
+ });
17370
+ DeviceType.Camera, method(object({ deviceId: number() }), array(ZoneSchema).readonly()), method(object({
17371
+ deviceId: number(),
17372
+ zone: ZoneSchema
17373
+ }), _void(), {
17374
+ kind: "mutation",
17375
+ auth: "admin"
17376
+ }), method(object({
17377
+ deviceId: number(),
17378
+ zoneId: string()
17379
+ }), _void(), {
17380
+ kind: "mutation",
17381
+ auth: "admin"
17382
+ }), method(object({
17383
+ deviceId: number(),
17384
+ zone: ZoneSchema
17385
+ }), _void(), {
17386
+ kind: "mutation",
17387
+ auth: "admin"
17388
+ }), object({ zones: array(ZoneSchema).readonly() });
17414
17389
  /**
17415
- * The MACRO tier of an annotation — a CLOSED set.
17390
+ * pipeline-analytics device-scoped wrapper cap. Refines raw
17391
+ * per-frame detections emitted by the pipeline runner into tracked
17392
+ * objects, per-kind event collections (motion / object / audio), and
17393
+ * persisted media. Owns the post-detection domain end-to-end:
17416
17394
  *
17417
- * This is what the exported detector predicts, so a typo here is a new class
17418
- * with one example in it. `label` and `subLabel` are open strings by contrast:
17419
- * the whole point of the page is teaching the model things it does not know
17420
- * yet, and constraining that vocabulary would make it useless.
17395
+ * runner emits PipelineInferenceResult
17396
+ * (event bus)
17397
+ * pipeline-analytics subscriber
17398
+ * SORT tracker + zone engine + state analyzer + event emitter
17399
+ * → three DB collections (one per kind), one FS media tree, one
17400
+ * unified event emitter (FrameTracked + TrackStarted/Ended +
17401
+ * DetectionEvent on bus)
17421
17402
  *
17422
- * A macro class is NEVER a label. The provider refuses a write whose `label` or
17423
- * `subLabel` is one of these values, in any casing, because once `person`
17424
- * exists in both tiers "every person box" stops being answerable without
17425
- * knowing every string anyone ever typed — and the damage is retroactive.
17403
+ * Pure subscriber model. No `processFrame` cap method the runner
17404
+ * already publishes the raw frame on the bus. The cap surface is
17405
+ * only QUERIES + per-device settings, bound on/off via
17406
+ * `device-manager.setWrapperActive`. `defaultActive: true` because
17407
+ * every camera with a detection pipeline wants its raw detections
17408
+ * refined; operators opt out per-device via BindingsTab when needed.
17409
+ *
17410
+ * Replaces the legacy `analysis-pipeline`, `analysis-data-persistence`
17411
+ * (per-device surface) and `track-trail` caps — see P11 cleanup.
17426
17412
  */
17427
- var RetrainMacroClassSchema = _enum([
17413
+ var TrackStateSchema = _enum([
17414
+ "new",
17415
+ "entered",
17416
+ "left",
17417
+ "moving",
17418
+ "idle"
17419
+ ]);
17420
+ var EventKindSchema = _enum([
17421
+ "motion",
17422
+ "object",
17423
+ "audio"
17424
+ ]);
17425
+ /**
17426
+ * Spatial filter for `listTracks` — the rect + polygon variants of the shared
17427
+ * MaskShape vocabulary (see `mask-shape.ts`). Coordinates are NORMALIZED 0..1
17428
+ * of the camera frame (top-left origin), matching the drawing-plane editor.
17429
+ */
17430
+ var TrackZoneFilterSchema = discriminatedUnion("kind", [MaskRectShapeSchema, MaskPolygonShapeSchema]);
17431
+ /** Closed icon vocabulary so clients render a known glyph per kind. */
17432
+ var EventKindIconSchema = _enum([
17433
+ "motion",
17434
+ "audio",
17428
17435
  "person",
17429
17436
  "vehicle",
17430
17437
  "animal",
17438
+ "door",
17439
+ "pir",
17440
+ "smoke",
17441
+ "water",
17442
+ "button",
17431
17443
  "package",
17432
- "face",
17433
- "plate"
17444
+ "generic"
17434
17445
  ]);
17435
- /** A subject to learn, or a phantom to unlearn (taught by OMISSION). */
17436
- var RetrainAnnotationKindSchema = _enum(["subject", "model_error"]);
17437
- /** Did a human draw this box, or did the assist propose it? */
17438
- var RetrainAnnotationSourceSchema = _enum(["operator", "assist"]);
17439
- /** Normalised `[0,1]` rectangle against the FULL frame — the canonical form. */
17440
- var RetrainBboxSchema = object({
17446
+ var EventKindCategorySchema = _enum([
17447
+ "motion",
17448
+ "audio",
17449
+ "detection",
17450
+ "sensor",
17451
+ "control",
17452
+ "custom",
17453
+ "package"
17454
+ ]);
17455
+ /** Taxonomy level — macro (timeline lane) vs sub (events-page leaf). */
17456
+ var EventKindLevelSchema = _enum(["macro", "sub"]);
17457
+ var EventKindDescriptorSchema = object({
17458
+ /** Stable kind id (e.g. 'motion', 'vehicle', 'car', 'lock'). */
17459
+ kind: string(),
17460
+ /** i18n key resolved on the UI side; `label` is the English fallback. */
17461
+ labelKey: string(),
17462
+ /** English fallback label (kept for clients that don't translate). */
17463
+ label: string(),
17464
+ /** Hex color for timeline/legend rendering. */
17465
+ color: string(),
17466
+ /** Dictionary id → lucide component on the UI side. */
17467
+ iconId: string(),
17468
+ /** Legacy closed-vocab glyph — fallback for `iconId`. */
17469
+ icon: EventKindIconSchema,
17470
+ category: EventKindCategorySchema,
17471
+ /** Macro parent for this kind ('car' → 'vehicle'); null for a macro. */
17472
+ parentKind: string().nullable(),
17473
+ /** Derived from `parentKind`, explicit for the client tree. */
17474
+ level: EventKindLevelSchema,
17475
+ /** Which cap + device contributes this kind. For built-ins the camera
17476
+ * itself; for sensor kinds the LINKED source device. */
17477
+ source: object({
17478
+ capName: string(),
17479
+ deviceId: number()
17480
+ })
17481
+ });
17482
+ /** One camera's event vocabulary, as returned by `listEventKindsBatch`. */
17483
+ var EventKindsForDeviceSchema = object({
17484
+ deviceId: number(),
17485
+ kinds: array(EventKindDescriptorSchema).readonly()
17486
+ });
17487
+ var SensorEventSchema = object({
17488
+ id: string(),
17489
+ /** The CAMERA the event is attributed to (a sensor linked to N cameras
17490
+ * yields N rows, one per camera). */
17491
+ deviceId: number(),
17492
+ /** The linked sensor device whose state changed. */
17493
+ sourceDeviceId: number(),
17494
+ /** Event kind id — matches an `EventKindDescriptor.kind`. */
17495
+ kind: string(),
17496
+ /** Snapshot of the sensor cap's runtime-state slice at the change. */
17497
+ value: record(string(), unknown()).nullable(),
17498
+ timestamp: number()
17499
+ });
17500
+ var TrackPositionSchema = object({
17441
17501
  x: number(),
17442
17502
  y: number(),
17443
- w: number(),
17444
- h: number()
17503
+ timestamp: number(),
17504
+ bbox: BoundingBoxSchema
17505
+ });
17506
+ var TrackSnapshotSchema = object({
17507
+ timestamp: number(),
17508
+ position: TrackPositionSchema,
17509
+ /** MediaStore key; resolve via `getTrackMedia({ trackId })`. */
17510
+ mediaKey: string()
17445
17511
  });
17446
17512
  /**
17447
- * One annotated subject.
17448
- *
17449
- * `bbox` is normalised against the full frame, ALWAYS. The per-model shapes
17450
- * (letterboxed root / zone-cropped package / subject-cropped classifier) are
17451
- * derived from it at export and never stored — storing them is how one feature
17452
- * space ends up holding two crops of the same subject (D52).
17453
- */
17454
- var RetrainAnnotationSchema = object({
17455
- id: string(),
17513
+ * Normalized 0..1 trajectory envelope (min/max over every position bbox,
17514
+ * divided by the track's detection-frame dims), computed at persist time.
17515
+ * Absent when the frame dims were unknown when the track was persisted
17516
+ * (legacy rows / dims-less sources) and on active (in-RAM) tracks.
17517
+ */
17518
+ var TrackEnvelopeSchema = object({
17519
+ minX: number(),
17520
+ minY: number(),
17521
+ maxX: number(),
17522
+ maxY: number()
17523
+ });
17524
+ /**
17525
+ * Row projection for track list queries. `full` (default) returns the
17526
+ * complete Track including the frame-rate `positions[]` history and the
17527
+ * `snapshots[]` references — megabytes across a page of tracks. `slim`
17528
+ * keeps every scalar the list surfaces actually render (ids, class(es),
17529
+ * label / audioLabels / importance enrichment, firstSeen/lastSeen, state,
17530
+ * zonesVisited, bestEventId, envelope, hasFace, hasEmbeddedFace, hasRider) and returns `positions` /
17531
+ * `snapshots` as EMPTY arrays — detail views re-fetch the full row via
17532
+ * `getTrack`. Mirrors the event-store `projection` convention
17533
+ * (`getObjectEvents` et al.).
17534
+ */
17535
+ var TrackProjectionSchema = _enum(["full", "slim"]);
17536
+ /**
17537
+ * One audio-classification label heard on the track's camera while the
17538
+ * track was alive, aggregated per label. An "episode" is one persisted
17539
+ * audio event (the confident-classification path: score ≥ the device's
17540
+ * `classificationMinScore`, class-change-or-heartbeat coalesced) — NOT
17541
+ * one 32 ms inference chunk, so counts stay human-scaled.
17542
+ */
17543
+ var TrackAudioLabelSchema = object({
17544
+ label: string(),
17545
+ /** Highest classification score observed across the label's episodes. */
17546
+ peakScore: number(),
17547
+ /** Number of coalesced audio-event episodes carrying this label. */
17548
+ count: number(),
17549
+ firstAt: number(),
17550
+ lastAt: number()
17551
+ });
17552
+ /**
17553
+ * How a track was produced. `pipeline` (default / absent) = the spatial
17554
+ * detection+tracking pipeline. Every OTHER value is a SYNTHETIC projection —
17555
+ * no positions, a single snapshot, and no bbox trajectory at all:
17556
+ *
17557
+ * - `sensor` — a linked sensor/control device state change.
17558
+ * - `audio` — an audio event on the camera itself that was anomalous for
17559
+ * THAT camera, loud, and heard while nothing visual was happening (D62).
17560
+ *
17561
+ * The spatial subsystems (tracker association, occupancy count, re-id /
17562
+ * embedding, resurrection) MUST skip every synthetic source. Test for that
17563
+ * with `isSpatialTrack`, which allow-lists `pipeline` — a `!== 'sensor'`
17564
+ * check silently readmits every source added after it was written.
17565
+ */
17566
+ var TrackSourceSchema = _enum([
17567
+ "pipeline",
17568
+ "sensor",
17569
+ "audio"
17570
+ ]);
17571
+ /**
17572
+ * Where a track sits in the RETRAIN lifecycle (D81).
17573
+ *
17574
+ * - `none` — never marked, or un-marked. Evictable.
17575
+ * - `staging` — the operator wants this track as training material and has not
17576
+ * finished with it. **This is the only state retention holds**: the track and
17577
+ * everything it owns (object events, crops, keyframes, CLIP vector) survive
17578
+ * the device's age window.
17579
+ * - `trained` — the retrain page has taken what it needed. The frames it chose
17580
+ * were COPIED into the retrain dataset at selection time, so the dataset no
17581
+ * longer depends on the track's media and the track becomes EVICTABLE again.
17582
+ * Terminal for the plain `markForTrain` toggle: returning it to `staging` is
17583
+ * a deliberate action of the retrain page, not a side effect of a checkbox.
17584
+ *
17585
+ * There is no `null`. The state is stored `TEXT NOT NULL DEFAULT 'none'` because
17586
+ * the store's filter language has only positive equality and `whereIn` — no
17587
+ * negation, no IS NULL — so a NULL would be unselectable by ANY predicate and
17588
+ * would make the entire pre-column history immortal in one deploy.
17589
+ */
17590
+ var RetrainStatusSchema = _enum([
17591
+ "none",
17592
+ "staging",
17593
+ "trained"
17594
+ ]);
17595
+ /**
17596
+ * Per-track OPERATOR flags — set by hand from the admin UI or the viewer, never
17597
+ * by the pipeline. Spread into `TrackSchema` and `KeyEventSchema` from one place
17598
+ * so the two surfaces cannot drift.
17599
+ *
17600
+ * **Absent ≠ false.** A track that has never been touched omits the field; an
17601
+ * explicitly un-flagged track carries `false`. Legacy rows written before the
17602
+ * columns existed read as absent, and a consumer that needs a boolean should say
17603
+ * `flag === true`, not `flag !== false`.
17604
+ *
17605
+ * `markForTrain` is the WIRE FACE of {@link RetrainStatusSchema}, not a column:
17606
+ * it is exactly `retrainStatus === 'staging'`, in both directions. Writing
17607
+ * `true` moves `none → staging`, writing `false` moves `staging → none`, and a
17608
+ * `trained` track reports `false` while refusing both writes. The boolean is
17609
+ * kept because three surfaces drive a toggle off it; anything that needs to tell
17610
+ * "never marked" from "already trained" must read `retrainStatus`.
17611
+ *
17612
+ * `debug` does NOT pin; it is attention, not durability.
17613
+ *
17614
+ * `favourited` IS a BOOLEAN pin (durability bit), not a retrain lifecycle.
17615
+ * A favourited track is skipped by retention the same way `staging` is, but
17616
+ * it does not enter `none|staging|trained` and has no staging budget.
17617
+ */
17618
+ var TrackFlagFields = {
17619
+ /** Operator marked this track as training material — i.e. `retrainStatus` is
17620
+ * `'staging'`. */
17621
+ markForTrain: boolean().optional(),
17622
+ /** Operator marked this track for diagnostic attention. */
17623
+ debug: boolean().optional(),
17624
+ /** Operator favourited this track. Pins it against pruning. */
17625
+ favourited: boolean().optional()
17626
+ };
17627
+ /**
17628
+ * The lifecycle field itself, on the READ surfaces only (`Track`, `KeyEvent`).
17629
+ * Deliberately NOT part of {@link TrackFlagFields}: that group also builds the
17630
+ * write patch, and the status is not something the toggle sets — it is what the
17631
+ * toggle's boolean is derived from. Absent on an in-RAM track never touched;
17632
+ * always present on a persisted row (the column default materialises `'none'`).
17633
+ */
17634
+ var TrackRetrainFields = { retrainStatus: RetrainStatusSchema.optional() };
17635
+ /**
17636
+ * The write half: a PARTIAL patch. An omitted key is left untouched, so setting
17637
+ * one flag can never clear the other — the toggles are independent and are
17638
+ * driven from three surfaces that do not know about each other.
17639
+ */
17640
+ var TrackFlagsPatchSchema = object(TrackFlagFields);
17641
+ /**
17642
+ * The resolved flag state after a write. Both fields are REQUIRED here (absent
17643
+ * collapses to `false`) so a caller can drive a toggle's checked state off the
17644
+ * mutation result without a re-fetch.
17645
+ */
17646
+ var TrackFlagsSchema = object({
17456
17647
  trackId: string(),
17457
- deviceId: number(),
17458
- /** The COPY in retrain storage — never the source track's media key. */
17459
- mediaKey: string(),
17460
- bbox: RetrainBboxSchema,
17461
- macroClass: RetrainMacroClassSchema,
17648
+ markForTrain: boolean(),
17649
+ debug: boolean(),
17650
+ favourited: boolean(),
17651
+ /** The lifecycle state the boolean was derived from. Required here (unlike on
17652
+ * a track row) because this shape is only ever produced by the write body,
17653
+ * which always knows it — and a surface that has just written needs to render
17654
+ * `trained` without a re-fetch. */
17655
+ retrainStatus: RetrainStatusSchema
17656
+ });
17657
+ union([literal(1), literal(2)]);
17658
+ /**
17659
+ * WHO decided a label, and when. Carried per tier so a value can be traced to
17660
+ * the step and model that produced it — which is what makes the write rule
17661
+ * arguable after the fact ("why is 592's label `dog` and not `Canis lupus`?")
17662
+ * and what lets a migrated, UNATTRIBUTED value be told apart from a real one.
17663
+ *
17664
+ * `stepId` is the pipeline step id (`animal-classifier`, `bird-classifier`,
17665
+ * `plate-ocr`, `face-embedding`, `object-detection`), or the sentinel
17666
+ * `migration:4g` for a value the 4g migration moved from the single-slot era —
17667
+ * that value has no provenance, and the write rule lets ANY properly-attributed
17668
+ * write of the same tier replace it regardless of score.
17669
+ */
17670
+ var LabelAttributionSchema = object({
17671
+ stepId: string(),
17672
+ modelId: string().optional(),
17673
+ decidedAt: number(),
17674
+ /**
17675
+ * The GALLERY id behind a recognised tier-2 label — a face-gallery
17676
+ * `Identity.id` or a plate-gallery `Vehicle.id` (both `randomUUID`).
17677
+ *
17678
+ * The text alone is a DISPLAY NAME, and a display name is renameable: a
17679
+ * notification rule authored on "Gianluca" stopped matching the moment the
17680
+ * operator fixed the spelling in the gallery, and nothing said so. The id is
17681
+ * the thing that does not move, so it is what a rule matches on
17682
+ * (`NcConditions.identities`) and the text is what a human is shown.
17683
+ *
17684
+ * Absent when the label names no gallery row — a plate the OCR read but no
17685
+ * vehicle claims, a sub-class, a species, any tier-1 value.
17686
+ */
17687
+ identityId: string().optional()
17688
+ });
17689
+ /**
17690
+ * The TIERED label model (roadmap 4g), spread into `TrackSchema` and
17691
+ * `ObjectEventSchema` from ONE place so the two surfaces cannot drift — a
17692
+ * track and its events always answer the same question the same way.
17693
+ *
17694
+ * Two scalar columns, not an array: every consumer wants "the coarse one" or
17695
+ * "the fine one", and an array made both a scan. `label` is tier 1, `subLabel`
17696
+ * is tier 2, and each carries its own score + attribution.
17697
+ *
17698
+ * **Reading it.** What a human should be shown is `subLabel ?? label` — the
17699
+ * finest thing known. Before 4g the single `label` column held the finest
17700
+ * value, so a consumer that has not been updated reads the tier-1 slot and
17701
+ * shows nothing on a species-only row; that is why the migration puts every
17702
+ * pre-4g value in tier 2 (it cannot regress a display that reads the fallback)
17703
+ * and why the read surfaces were changed in the same train.
17704
+ *
17705
+ * **Writing it.** The slots are independent, which is the whole point: a
17706
+ * tier-1 write (`bird`) can never overwrite a tier-2 value (`Turdus
17707
+ * migratorius`), so fineness cannot regress by construction. Within a tier the
17708
+ * higher score wins. One rule, one implementation — see
17709
+ * `pipeline/label-tier.ts` in addon-post-analysis.
17710
+ */
17711
+ var TieredLabelFields = {
17712
+ /** Tier 1 — the sub-class. See {@link LabelTierSchema}. */
17462
17713
  label: string().optional(),
17714
+ /** Confidence of the tier-1 value, as reported by the deciding step. */
17715
+ labelScore: number().optional(),
17716
+ /** Provenance of the tier-1 value. See {@link LabelAttributionSchema}. */
17717
+ labelMeta: LabelAttributionSchema.optional(),
17718
+ /** Tier 2 — the instance. See {@link LabelTierSchema}. */
17463
17719
  subLabel: string().optional(),
17464
- kind: RetrainAnnotationKindSchema,
17465
- source: RetrainAnnotationSourceSchema,
17466
- /** Which model proposed this box or, on a `model_error`, drew the phantom. */
17467
- assistModelId: string().optional(),
17468
- assistScore: number().optional(),
17469
- exportedInBatch: string().optional(),
17470
- createdAt: number()
17720
+ /** Confidence of the tier-2 value, as reported by the deciding step. */
17721
+ subLabelScore: number().optional(),
17722
+ /** Provenance of the tier-2 value. See {@link LabelAttributionSchema}. */
17723
+ subLabelMeta: LabelAttributionSchema.optional()
17724
+ };
17725
+ /** Per-camera slice of a training-export estimate. */
17726
+ var TrainingExportDeviceTotalsSchema = object({
17727
+ deviceId: number(),
17728
+ tracks: number().int(),
17729
+ files: number().int(),
17730
+ bytes: number().int()
17471
17731
  });
17472
- /** The write form — the server owns `id`, `createdAt` and the frame binding. */
17473
- var RetrainAnnotationDraftSchema = RetrainAnnotationSchema.omit({
17474
- id: true,
17475
- trackId: true,
17476
- deviceId: true,
17477
- mediaKey: true,
17478
- createdAt: true,
17479
- exportedInBatch: true
17732
+ /**
17733
+ * What a training export WOULD contain. Computed from media index rows only —
17734
+ * no blob is read to produce this.
17735
+ */
17736
+ var TrainingExportSummarySchema = object({
17737
+ generatedAt: number(),
17738
+ trackCount: number().int(),
17739
+ fileCount: number().int(),
17740
+ byteCount: number().int(),
17741
+ /** More marked tracks exist than a single pass carries. */
17742
+ truncated: boolean(),
17743
+ devices: array(TrainingExportDeviceTotalsSchema).readonly()
17480
17744
  });
17481
- /** A track sitting in `staging`, with everything the worklist needs to rank it. */
17482
- var RetrainTrackSchema = object({
17745
+ var TrackSchema = object({
17483
17746
  trackId: string(),
17484
17747
  deviceId: number(),
17485
17748
  className: string(),
17486
- label: string().optional(),
17749
+ ...TieredLabelFields,
17750
+ producingDeviceName: string().optional(),
17751
+ /** Track provenance. Absent ⇒ `pipeline` (legacy rows). */
17752
+ source: TrackSourceSchema.optional(),
17487
17753
  firstSeen: number(),
17488
17754
  lastSeen: number(),
17489
- /** How many frames the dataset already holds from this track. */
17490
- frameCount: number().int(),
17491
- /** How many subjects have been annotated on those frames. `0` with
17492
- * `frameCount: 0` is exactly "staging, still to work". */
17493
- annotationCount: number().int()
17494
- });
17495
- /** A frame the picker may offer — an index row, no blob was read to produce it. */
17496
- var RetrainFrameCandidateSchema = object({
17497
- mediaKey: string(),
17498
- kind: MediaFileKindEnum,
17499
- timestamp: number(),
17500
- sizeBytes: number().int(),
17501
- /** A copy of this original already exists selecting it is free and cannot
17502
- * fail, whatever became of the original. */
17503
- copied: boolean()
17755
+ /** Frame-rate position history (subject to maxPositionHistory cap). */
17756
+ positions: array(TrackPositionSchema).readonly(),
17757
+ /** Periodic snapshots at snapshotIntervalMs cadence (subject to
17758
+ * saveThumbnails policy). */
17759
+ snapshots: array(TrackSnapshotSchema).readonly(),
17760
+ /** Deduplicated zones the track has entered at least once. Zone IDS. */
17761
+ zonesVisited: array(string()).readonly(),
17762
+ /**
17763
+ * Human NAMES for {@link zonesVisited}, resolved at READ time against the
17764
+ * `zones` capability.
17765
+ *
17766
+ * `zonesVisited` persists ids (`cfeec78c-8d69-…`), which no operator can type
17767
+ * and no card can render so every free-text search surface was structurally
17768
+ * unable to answer "show me the tracks in Uscio", and did not fail loudly, it
17769
+ * just returned nothing. Resolving here rather than in each client keeps ONE
17770
+ * derivation and costs the clients no extra call (the `zones` cap is
17771
+ * per-device, so a client-side resolve would be a per-camera fan-out on a
17772
+ * surface built to avoid exactly that).
17773
+ *
17774
+ * Resolved, never invented: a zone deleted since the track was written has no
17775
+ * name and is DROPPED, so this array can be shorter than `zonesVisited` — the
17776
+ * two are not positionally aligned. Absent when the track visited no zone, or
17777
+ * when the zone catalogue could not be read.
17778
+ */
17779
+ zoneNames: array(string()).readonly().optional(),
17780
+ /** Deduplicated set of detector classes observed for this track over its
17781
+ * life (a track may be reclassified, e.g. person→vehicle). Absent on
17782
+ * legacy rows written before class accumulation shipped. */
17783
+ classes: array(string()).readonly().optional(),
17784
+ /** Cumulative normalized distance travelled (0..1 units = full frame width). */
17785
+ totalDistance: number(),
17786
+ state: TrackStateSchema,
17787
+ active: boolean(),
17788
+ /** Deterministic key-event importance score in [0,1] (server-computed at
17789
+ * track expiry, recomputed on late label). Absent on legacy rows written
17790
+ * before scoring shipped — consumers degrade to absence / compute-on-read. */
17791
+ importance: number().optional(),
17792
+ /** Id of the track's highest-confidence ObjectEvent (its representative
17793
+ * "best" frame). Absent when the track produced no object events. */
17794
+ bestEventId: string().optional(),
17795
+ /** Tag of the importance sub-signal that dominated the score
17796
+ * (identity|dwell|proximity|class|confidence|travel|zone). */
17797
+ importanceReason: string().optional(),
17798
+ /** Audio-classification labels heard on the camera during the track's
17799
+ * life (score ≥ device `classificationMinScore`), aggregated per label.
17800
+ * Absent on legacy rows / tracks with no confident audio. */
17801
+ audioLabels: array(TrackAudioLabelSchema).readonly().optional(),
17802
+ /** Normalized 0..1 trajectory envelope (see {@link TrackEnvelopeSchema}).
17803
+ * Populated from the persisted envelope columns on historical reads;
17804
+ * absent on legacy rows, dims-less tracks and active (in-RAM) tracks. */
17805
+ envelope: TrackEnvelopeSchema.optional(),
17806
+ /**
17807
+ * A face DETECTOR found a face on this track — nothing more. It says the
17808
+ * detail plane produced a `face` detail; it does NOT say the face was
17809
+ * embedded, matched, above `minFacePx`, or that the recognizer was even
17810
+ * enabled. Set once and never cleared.
17811
+ *
17812
+ * **This exists so "face present but not recognised" is expressible.** A
17813
+ * recognised identity lands in `subLabel` (attributed to the face chain via
17814
+ * `subLabelMeta.stepId`), so before this field a track with an unmatched face
17815
+ * and a track with no face at all were byte-identical on the wire and no
17816
+ * surface could tell them apart. The read is `hasFace === true && subLabel
17817
+ * === undefined`.
17818
+ *
17819
+ * **Absent ≠ false.** Every row written before the column existed omits it,
17820
+ * and so does every server that predates the field — a consumer must test
17821
+ * `=== true` and render nothing otherwise, never infer "no face".
17822
+ */
17823
+ hasFace: boolean().optional(),
17824
+ /**
17825
+ * This track has a face row IN THE GALLERY: a crop **and** an embedding — a
17826
+ * face an operator could ASSIGN to an identity.
17827
+ *
17828
+ * The STRICT twin of {@link hasFace}, and the pair only earns its keep
17829
+ * because the two disagree. `hasFace` is stamped at the TOP of the face
17830
+ * branch, before every gate, and means no more than "a face detector produced
17831
+ * a face detail". This one is stamped at the single moment the gallery row
17832
+ * LANDS — after `FaceRecognizer.onTrackEnd` successfully persists it, i.e.
17833
+ * past the embedding-magnitude verdict, the `minFacePx` detection gate, the
17834
+ * candidate gate, the imageless-track drop (no crop was ever captured) and
17835
+ * the crop-store drop. Everything between the detector and that insert can
17836
+ * legitimately refuse the face, so a flag written any earlier promises the
17837
+ * operator something to assign and delivers nothing.
17838
+ *
17839
+ * **Independent of recognition.** A face collected but never auto-matched is
17840
+ * still assignable — it is in fact the face an operator most wants to reach —
17841
+ * so this is NOT gated on `recognizedIdentityId`. Recognition lands in
17842
+ * `subLabel`; this says only that the raw material exists.
17843
+ *
17844
+ * **Set once, never cleared.** A track that produced a gallery row produced
17845
+ * one; deleting the row later is the gallery's business, not this flag's.
17846
+ *
17847
+ * **Absent ≠ false**, the same rule as {@link hasFace}: every row written
17848
+ * before the column omits it, and so does every server that predates the
17849
+ * field. A consumer must test `=== true` and render nothing otherwise —
17850
+ * never infer "no assignable face".
17851
+ */
17852
+ hasEmbeddedFace: boolean().optional(),
17853
+ /**
17854
+ * This subject CONTAINS a folded rider — a person the rider-pairing step
17855
+ * ([D34](../decisions/adr-0034.md)) removed from the frame BEFORE the tracker,
17856
+ * so the passage is tracked once and as a VEHICLE.
17857
+ *
17858
+ * It exists because the fold's record was dishonest. D34 and the code both
17859
+ * said "the person is not lost — it is reported so both entities stay on the
17860
+ * record"; in fact the pair went into a per-processor RAM field behind an
17861
+ * accessor nobody called, and every durable surface said `vehicle`, full
17862
+ * stop. This is the composition note that makes the row true.
17863
+ *
17864
+ * A COMPOSITION, never a class and never a label. "This vehicle contains a
17865
+ * person" is not an answer to "what is this" — both label tiers would refuse
17866
+ * a macro token anyway (D89), and correctly. Nothing here changes what the
17867
+ * subject IS: a cyclist stays one vehicle track, occupancy still counts one,
17868
+ * and a `person` rule still does not fire for someone cycling past.
17869
+ *
17870
+ * **Absent ≠ false**, exactly like {@link hasFace}: every row written before
17871
+ * the column, and every hub that predates the field, omits it. Test
17872
+ * `=== true` and render nothing otherwise — never infer "no rider".
17873
+ */
17874
+ hasRider: boolean().optional(),
17875
+ ...TrackFlagFields,
17876
+ ...TrackRetrainFields
17504
17877
  });
17505
- /** A frame the dataset OWNS: bytes copied at selection time. */
17506
- var RetrainFrameSchema = object({
17507
- frameId: string(),
17878
+ var BaseEventFields = {
17879
+ id: string(),
17508
17880
  deviceId: number(),
17509
- trackId: string(),
17510
- /** Provenance only. It may already point at nothing — that is expected. */
17511
- sourceMediaKey: string(),
17512
- sourceKind: MediaFileKindEnum,
17513
- sizeBytes: number().int(),
17514
- width: number().int(),
17515
- height: number().int(),
17516
- copiedAt: number()
17517
- });
17518
- /** Why a copy-on-select could not be honoured — named, never a silent skip. */
17519
- var RetrainCopyRefusalSchema = _enum([
17520
- "source-missing",
17521
- "unreadable-image",
17522
- "write-failed"
17523
- ]);
17524
- var RetrainFrameSelectionSchema = object({
17525
- copied: array(RetrainFrameSchema).readonly(),
17526
- refused: array(object({
17527
- sourceMediaKey: string(),
17528
- reason: RetrainCopyRefusalSchema
17529
- })).readonly()
17530
- });
17531
- var RetrainFrameListSchema = object({
17532
- candidates: array(RetrainFrameCandidateSchema).readonly(),
17533
- copies: array(RetrainFrameSchema).readonly(),
17534
- /** What the page pre-selects — the native key frame when one survives. */
17535
- autoPickMediaKey: string().optional()
17881
+ timestamp: number()
17882
+ };
17883
+ var MotionEventSchema = object({
17884
+ ...BaseEventFields,
17885
+ kind: literal("motion"),
17886
+ regionCount: number(),
17887
+ /** Heavy JSON array — omitted in slim projection. */
17888
+ regions: array(object({
17889
+ bbox: BoundingBoxSchema,
17890
+ pixelCount: number(),
17891
+ intensity: number()
17892
+ })).readonly().optional(),
17893
+ /** Omitted in slim projection. */
17894
+ frameWidth: number().optional(),
17895
+ /** Omitted in slim projection. */
17896
+ frameHeight: number().optional(),
17897
+ /** Populated by B5 (recording playback URL for this event). */
17898
+ mediaUrl: string().optional()
17536
17899
  });
17537
- /** What the operator asked the assist to look for. */
17538
- var RetrainAssistSubjectSchema = discriminatedUnion("kind", [object({
17539
- kind: literal("package"),
17540
- zone: RetrainBboxSchema.optional()
17541
- }), object({
17542
- kind: literal("objects"),
17543
- modelId: string(),
17544
- minScore: number().optional()
17545
- })]);
17546
17900
  /**
17547
- * The assist's answer a discriminated union, because "the model saw nothing"
17548
- * and "this node cannot run that model" lead to different next moves and a
17549
- * nullable result cannot tell them apart.
17901
+ * Which detection SOURCE produced an object event. `pipeline` = the ML
17902
+ * detection pipeline (decoded-frame inference); `onboard` = the camera's
17903
+ * native on-device AI. Both flow through the SAME analysis layers (zoning,
17904
+ * tracking, per-kind persistence) but stay distinguishable so consumers
17905
+ * (advanced-notifier, occupancy, …) can select which source(s) to act on.
17906
+ * Absent on legacy rows ⇒ treat as `pipeline`.
17550
17907
  */
17551
- var RetrainAssistResultSchema = discriminatedUnion("kind", [object({
17552
- kind: literal("proposed"),
17553
- modelId: string(),
17554
- stepId: string(),
17555
- minScore: number(),
17556
- /** Drafts, ready to edit. `source: 'assist'` until the operator touches one. */
17557
- proposals: array(RetrainAnnotationDraftSchema).readonly(),
17558
- /** Returned by the runner but removed by the threshold. */
17559
- belowThreshold: number().int()
17560
- }), object({
17561
- kind: literal("refused"),
17562
- /** `no-zone` is ours; the rest are the runner's own refusal vocabulary. */
17563
- reason: string(),
17564
- detail: string().optional()
17565
- })]);
17566
- /** The outcome of a lifecycle move owned by the retrain page. */
17567
- var RetrainTransitionResultSchema = object({
17568
- trackId: string(),
17569
- /** Where the track ended up, whatever happened. */
17570
- retrainStatus: RetrainStatusSchema,
17571
- /** `false` ⇒ the move was refused or was a no-op; `reason` says which. */
17572
- changed: boolean(),
17573
- reason: _enum([
17574
- "unknown-track",
17575
- "no-frames-copied",
17576
- "not-staging",
17577
- "not-trained",
17578
- "unchanged"
17579
- ]).optional()
17908
+ var DetectionSourceSchema = _enum(["pipeline", "onboard"]);
17909
+ /**
17910
+ * The confirmed zone crossing that produced an object event. Present ONLY on
17911
+ * an event emitted BY a crossing (`zone.enter` / `zone.exit`); a movement-state
17912
+ * event (`object.entering` / `leaving` / `stationary` / `loitering`) and an
17913
+ * appearance event carry none, so a rule asking for a direction fails closed
17914
+ * on them.
17915
+ *
17916
+ * Exactly ONE crossing per event: the emitter turns each confirmed crossing
17917
+ * into its own event, so a frame in which a track enters A while leaving B
17918
+ * produces two events with two directions — never one ambiguous row.
17919
+ *
17920
+ * `zoneId` is load-bearing for an EXIT: the event's `zones` list is the
17921
+ * membership the box has NOW, and by definition it no longer contains the zone
17922
+ * that was just left. Without the id here, a zone-scoped rule could never match
17923
+ * the exit it asked for.
17924
+ */
17925
+ var ZoneCrossingSchema = object({
17926
+ direction: _enum(["enter", "exit"]),
17927
+ /** Admin zone id crossed. */
17928
+ zoneId: string(),
17929
+ /** Zone display name at crossing time (falls back to the id). */
17930
+ zoneName: string().optional()
17580
17931
  });
17581
- var DEFAULT_EVENT_QUERY_LIMIT = 1e3;
17582
- var MAX_EVENT_QUERY_LIMIT = 5e3;
17583
- var DeviceEventQueryInput = object({
17584
- deviceId: number(),
17585
- since: number().optional(),
17586
- until: number().optional(),
17587
- limit: number().int().min(1).max(MAX_EVENT_QUERY_LIMIT).default(DEFAULT_EVENT_QUERY_LIMIT),
17588
- /** `slim` drops heavy JSON fields (regions/bbox/zones) and carries an
17589
- * optional `mediaUrl` (populated by B5). `full` (default) keeps today's
17590
- * exact behaviour. Callers may omit this field the store defaults to
17591
- * `full` when not provided. */
17592
- projection: _enum(["full", "slim"]).optional()
17932
+ var ObjectEventSchema = object({
17933
+ ...BaseEventFields,
17934
+ kind: literal("object"),
17935
+ /** Detection source. Optional for backward-compat; absent ⇒ `pipeline`. */
17936
+ source: DetectionSourceSchema.optional(),
17937
+ /**
17938
+ * Inference-frame id shared by every object event emitted from the SAME frame
17939
+ * the "scene/parent" key. Lets a consumer group co-occurring detections (e.g.
17940
+ * 2 people + 1 dog) under one full frame, and link a track's frames over time
17941
+ * (group by `trackId`, pick a representative `frameId` as the parent frame).
17942
+ * Optional for backward-compat with pre-existing rows / the slim projection
17943
+ * includes it (it is light). Absent on rows written before this field.
17944
+ */
17945
+ frameId: string().optional(),
17946
+ /** Omitted in slim projection. */
17947
+ trackId: string().optional(),
17948
+ className: string(),
17949
+ ...TieredLabelFields,
17950
+ /** Omitted in slim projection. */
17951
+ confidence: number().optional(),
17952
+ /** Heavy JSON — omitted in slim projection. */
17953
+ bbox: BoundingBoxSchema.optional(),
17954
+ /** Heavy JSON — omitted in slim projection. */
17955
+ zones: array(string()).readonly().optional(),
17956
+ /** Omitted in slim projection. */
17957
+ state: TrackStateSchema.optional(),
17958
+ /**
17959
+ * The zone crossing this event IS, when it is one. Absent on every other
17960
+ * event kind (movement state, appearance, package) — see
17961
+ * {@link ZoneCrossingSchema}. Omitted in slim projection.
17962
+ */
17963
+ zoneCrossing: ZoneCrossingSchema.optional(),
17964
+ /** Detection-frame dimensions in pixels — let consumers normalize the
17965
+ * pixel-space `bbox` onto a displayed image. Omitted in slim projection. */
17966
+ frameWidth: number().optional(),
17967
+ frameHeight: number().optional(),
17968
+ /** MediaStore key for the crop attached to this event (if any). */
17969
+ mediaKey: string().optional(),
17970
+ /** Design B: MediaStore key of the track's native-resolution key frame (the
17971
+ * best-detection full frame). Resolve via the event-media data-plane
17972
+ * (`/addon/<addonId>/event-media/<keyFrameMediaKey>`) for a detail view that
17973
+ * draws `bbox` over the native frame. Absent on legacy rows / non-decoded
17974
+ * sources — consumers fall back to `mediaKey` (the tight crop). */
17975
+ keyFrameMediaKey: string().optional(),
17976
+ /** Populated by B5 (recording playback URL for this event). */
17977
+ mediaUrl: string().optional(),
17978
+ /** The parent track's key-event importance [0,1], propagated to every object
17979
+ * event of the track (so an event row can be sorted by importance without a
17980
+ * track join). Absent on legacy rows / before the track was scored. */
17981
+ importance: number().optional()
17593
17982
  });
17594
- var ObjectEventQueryInput = DeviceEventQueryInput.extend({ classFilter: string().optional() });
17595
- var RecentTracksQueryInput = object({
17596
- /** Devices to merge. An empty array yields `{ tracks: [], nextCursor: null }`. */
17597
- deviceIds: array(number()),
17598
- /** Window lower bound on `lastSeen` (inclusive). */
17599
- since: number().optional(),
17600
- /** Window upper bound on `lastSeen` (inclusive). */
17601
- until: number().optional(),
17602
- /** Page size. Default 200, max 1000. */
17603
- limit: number().int().min(1).max(1e3).default(200),
17604
- /** Opaque continuation cursor from a previous page's `nextCursor`.
17605
- * Encodes the (lastSeen, trackId) sort position — treat as opaque. */
17606
- cursor: string().optional(),
17607
- /** See {@link TrackProjectionSchema}. Default `full`. */
17608
- projection: TrackProjectionSchema.optional(),
17609
- /** Include stationary-promoted rows (parked objects). Default false: the
17610
- * feed lists passages; parking records live on the stationary registry. */
17611
- includeStationary: boolean().optional()
17983
+ var AudioEventSchema = object({
17984
+ ...BaseEventFields,
17985
+ kind: literal("audio"),
17986
+ rms: number(),
17987
+ dbfs: number(),
17988
+ classification: object({
17989
+ className: string(),
17990
+ originalClass: string().optional(),
17991
+ score: number()
17992
+ }).optional(),
17993
+ /** Populated by B5 (recording playback URL for this event). */
17994
+ mediaUrl: string().optional()
17612
17995
  });
17613
- var RecentTracksPageSchema = object({
17614
- /** Merged page, ordered by (`lastSeen` DESC, `trackId` DESC). */
17615
- tracks: array(TrackSchema).readonly(),
17616
- /** Cursor for the next page, or null when this page is the last. */
17617
- nextCursor: string().nullable()
17996
+ var MediaFileKindEnum = _enum([
17997
+ "crop",
17998
+ "thumbnail",
17999
+ "snapshot",
18000
+ "firstFrame",
18001
+ "lastFrame",
18002
+ "fullFrame",
18003
+ "fullFrameBoxed",
18004
+ "faceCrop",
18005
+ "plateCrop",
18006
+ "keyFrame",
18007
+ "keyFrameSmall",
18008
+ "thumbnailSmall"
18009
+ ]);
18010
+ var MediaFileSchema = object({
18011
+ key: string(),
18012
+ kind: MediaFileKindEnum,
18013
+ base64: string(),
18014
+ sizeBytes: number(),
18015
+ timestamp: number()
17618
18016
  });
17619
- var LIST_GROUPS_DEFAULT_LIMIT = 40;
17620
- var LIST_GROUPS_MAX_LIMIT = 100;
17621
- var AnalyticsGroupRecordSchema = object({
18017
+ /**
18018
+ * One media row WITHOUT its bytes.
18019
+ *
18020
+ * A track's media is 5-8 MB of base64 (measured: 7.67 MB across 23 files for a
18021
+ * 140 s track), and a client that renders tiles from the media data plane needs
18022
+ * to know only WHAT EXISTS — the bytes then arrive per tile, lazily, over HTTP
18023
+ * with an immutable cache, instead of all at once inside a tRPC response that
18024
+ * blocks the whole view.
18025
+ *
18026
+ * `sizeBytes` is carried because it is what lets a client decide between the
18027
+ * stored blob and a `?variant=thumb` rendering without fetching either.
18028
+ */
18029
+ var MediaFileInfoSchema = MediaFileSchema.omit({ base64: true });
18030
+ /**
18031
+ * The MACRO tier of an annotation — a CLOSED set.
18032
+ *
18033
+ * This is what the exported detector predicts, so a typo here is a new class
18034
+ * with one example in it. `label` and `subLabel` are open strings by contrast:
18035
+ * the whole point of the page is teaching the model things it does not know
18036
+ * yet, and constraining that vocabulary would make it useless.
18037
+ *
18038
+ * A macro class is NEVER a label. The provider refuses a write whose `label` or
18039
+ * `subLabel` is one of these values, in any casing, because once `person`
18040
+ * exists in both tiers "every person box" stops being answerable without
18041
+ * knowing every string anyone ever typed — and the damage is retroactive.
18042
+ */
18043
+ var RetrainMacroClassSchema = _enum([
18044
+ "person",
18045
+ "vehicle",
18046
+ "animal",
18047
+ "package",
18048
+ "face",
18049
+ "plate"
18050
+ ]);
18051
+ /** A subject to learn, or a phantom to unlearn (taught by OMISSION). */
18052
+ var RetrainAnnotationKindSchema = _enum(["subject", "model_error"]);
18053
+ /** Did a human draw this box, or did the assist propose it? */
18054
+ var RetrainAnnotationSourceSchema = _enum(["operator", "assist"]);
18055
+ /** Normalised `[0,1]` rectangle against the FULL frame — the canonical form. */
18056
+ var RetrainBboxSchema = object({
18057
+ x: number(),
18058
+ y: number(),
18059
+ w: number(),
18060
+ h: number()
18061
+ });
18062
+ /**
18063
+ * One annotated subject.
18064
+ *
18065
+ * `bbox` is normalised against the full frame, ALWAYS. The per-model shapes
18066
+ * (letterboxed root / zone-cropped package / subject-cropped classifier) are
18067
+ * derived from it at export and never stored — storing them is how one feature
18068
+ * space ends up holding two crops of the same subject (D52).
18069
+ */
18070
+ var RetrainAnnotationSchema = object({
17622
18071
  id: string(),
17623
- deviceId: number().int(),
17624
- openedAt: number().int(),
17625
- closedAt: number().int(),
17626
- timestamp: number().int(),
17627
- memberCount: number().int(),
17628
- memberTrackIds: array(string()).readonly(),
17629
- className: string(),
17630
- classes: array(string()).readonly(),
17631
- /** Relative event-media path, or null when the group has no picture yet. */
17632
- mediaUrl: string().nullable(),
17633
- singleton: boolean()
18072
+ trackId: string(),
18073
+ deviceId: number(),
18074
+ /** The COPY in retrain storage — never the source track's media key. */
18075
+ mediaKey: string(),
18076
+ bbox: RetrainBboxSchema,
18077
+ macroClass: RetrainMacroClassSchema,
18078
+ label: string().optional(),
18079
+ subLabel: string().optional(),
18080
+ kind: RetrainAnnotationKindSchema,
18081
+ source: RetrainAnnotationSourceSchema,
18082
+ /** Which model proposed this box — or, on a `model_error`, drew the phantom. */
18083
+ assistModelId: string().optional(),
18084
+ assistScore: number().optional(),
18085
+ exportedInBatch: string().optional(),
18086
+ createdAt: number()
17634
18087
  });
17635
- var AnalyticsGroupMemberSchema = object({
18088
+ /** The write form — the server owns `id`, `createdAt` and the frame binding. */
18089
+ var RetrainAnnotationDraftSchema = RetrainAnnotationSchema.omit({
18090
+ id: true,
18091
+ trackId: true,
18092
+ deviceId: true,
18093
+ mediaKey: true,
18094
+ createdAt: true,
18095
+ exportedInBatch: true
18096
+ });
18097
+ /** A track sitting in `staging`, with everything the worklist needs to rank it. */
18098
+ var RetrainTrackSchema = object({
17636
18099
  trackId: string(),
17637
- deviceId: number().int(),
18100
+ deviceId: number(),
17638
18101
  className: string(),
17639
- firstSeen: number().int(),
17640
- lastSeen: number().int(),
17641
- mediaUrl: string().nullable()
17642
- });
17643
- var AnalyticsGroupDetailSchema = AnalyticsGroupRecordSchema.extend({ members: array(AnalyticsGroupMemberSchema).readonly() });
17644
- var ListGroupsQueryInput = object({
17645
- /** Devices to merge. An empty array yields `{ groups: [], nextCursor: null }`. */
17646
- deviceIds: array(number()),
17647
- /** Window lower bound on `closedAt` (inclusive). */
17648
- since: number().optional(),
17649
- /** Window upper bound on `openedAt` (inclusive). */
17650
- until: number().optional(),
17651
- limit: number().int().min(1).max(LIST_GROUPS_MAX_LIMIT).default(LIST_GROUPS_DEFAULT_LIMIT),
17652
- /** Opaque continuation cursor from a previous page's `nextCursor`. */
17653
- cursor: string().optional()
18102
+ label: string().optional(),
18103
+ firstSeen: number(),
18104
+ lastSeen: number(),
18105
+ /** How many frames the dataset already holds from this track. */
18106
+ frameCount: number().int(),
18107
+ /** How many subjects have been annotated on those frames. `0` with
18108
+ * `frameCount: 0` is exactly "staging, still to work". */
18109
+ annotationCount: number().int()
17654
18110
  });
17655
- var ListGroupsPageSchema = object({
17656
- groups: array(AnalyticsGroupRecordSchema).readonly(),
17657
- nextCursor: string().nullable()
18111
+ /** A frame the picker may offer — an index row, no blob was read to produce it. */
18112
+ var RetrainFrameCandidateSchema = object({
18113
+ mediaKey: string(),
18114
+ kind: MediaFileKindEnum,
18115
+ timestamp: number(),
18116
+ sizeBytes: number().int(),
18117
+ /** A copy of this original already exists — selecting it is free and cannot
18118
+ * fail, whatever became of the original. */
18119
+ copied: boolean()
17658
18120
  });
17659
- var KeyEventQueryInput = object({
18121
+ /** A frame the dataset OWNS: bytes copied at selection time. */
18122
+ var RetrainFrameSchema = object({
18123
+ frameId: string(),
17660
18124
  deviceId: number(),
17661
- /** Window lower bound (track firstSeen ≥ since). */
17662
- since: number(),
17663
- /** Window upper bound (track firstSeen ≤ until). */
18125
+ trackId: string(),
18126
+ /** Provenance only. It may already point at nothing — that is expected. */
18127
+ sourceMediaKey: string(),
18128
+ sourceKind: MediaFileKindEnum,
18129
+ sizeBytes: number().int(),
18130
+ width: number().int(),
18131
+ height: number().int(),
18132
+ copiedAt: number()
18133
+ });
18134
+ /** Why a copy-on-select could not be honoured — named, never a silent skip. */
18135
+ var RetrainCopyRefusalSchema = _enum([
18136
+ "source-missing",
18137
+ "unreadable-image",
18138
+ "write-failed"
18139
+ ]);
18140
+ var RetrainFrameSelectionSchema = object({
18141
+ copied: array(RetrainFrameSchema).readonly(),
18142
+ refused: array(object({
18143
+ sourceMediaKey: string(),
18144
+ reason: RetrainCopyRefusalSchema
18145
+ })).readonly()
18146
+ });
18147
+ var RetrainFrameListSchema = object({
18148
+ candidates: array(RetrainFrameCandidateSchema).readonly(),
18149
+ copies: array(RetrainFrameSchema).readonly(),
18150
+ /** What the page pre-selects — the native key frame when one survives. */
18151
+ autoPickMediaKey: string().optional()
18152
+ });
18153
+ /** What the operator asked the assist to look for. */
18154
+ var RetrainAssistSubjectSchema = discriminatedUnion("kind", [object({
18155
+ kind: literal("package"),
18156
+ zone: RetrainBboxSchema.optional()
18157
+ }), object({
18158
+ kind: literal("objects"),
18159
+ modelId: string(),
18160
+ minScore: number().optional()
18161
+ })]);
18162
+ /**
18163
+ * The assist's answer — a discriminated union, because "the model saw nothing"
18164
+ * and "this node cannot run that model" lead to different next moves and a
18165
+ * nullable result cannot tell them apart.
18166
+ */
18167
+ var RetrainAssistResultSchema = discriminatedUnion("kind", [object({
18168
+ kind: literal("proposed"),
18169
+ modelId: string(),
18170
+ stepId: string(),
18171
+ minScore: number(),
18172
+ /** Drafts, ready to edit. `source: 'assist'` until the operator touches one. */
18173
+ proposals: array(RetrainAnnotationDraftSchema).readonly(),
18174
+ /** Returned by the runner but removed by the threshold. */
18175
+ belowThreshold: number().int()
18176
+ }), object({
18177
+ kind: literal("refused"),
18178
+ /** `no-zone` is ours; the rest are the runner's own refusal vocabulary. */
18179
+ reason: string(),
18180
+ detail: string().optional()
18181
+ })]);
18182
+ /** The outcome of a lifecycle move owned by the retrain page. */
18183
+ var RetrainTransitionResultSchema = object({
18184
+ trackId: string(),
18185
+ /** Where the track ended up, whatever happened. */
18186
+ retrainStatus: RetrainStatusSchema,
18187
+ /** `false` ⇒ the move was refused or was a no-op; `reason` says which. */
18188
+ changed: boolean(),
18189
+ reason: _enum([
18190
+ "unknown-track",
18191
+ "no-frames-copied",
18192
+ "not-staging",
18193
+ "not-trained",
18194
+ "unchanged"
18195
+ ]).optional()
18196
+ });
18197
+ var DEFAULT_EVENT_QUERY_LIMIT = 1e3;
18198
+ var MAX_EVENT_QUERY_LIMIT = 5e3;
18199
+ var DeviceEventQueryInput = object({
18200
+ deviceId: number(),
18201
+ since: number().optional(),
18202
+ until: number().optional(),
18203
+ limit: number().int().min(1).max(MAX_EVENT_QUERY_LIMIT).default(DEFAULT_EVENT_QUERY_LIMIT),
18204
+ /** `slim` drops heavy JSON fields (regions/bbox/zones) and carries an
18205
+ * optional `mediaUrl` (populated by B5). `full` (default) keeps today's
18206
+ * exact behaviour. Callers may omit this field — the store defaults to
18207
+ * `full` when not provided. */
18208
+ projection: _enum(["full", "slim"]).optional()
18209
+ });
18210
+ var ObjectEventQueryInput = DeviceEventQueryInput.extend({ classFilter: string().optional() });
18211
+ var RecentTracksQueryInput = object({
18212
+ /** Devices to merge. An empty array yields `{ tracks: [], nextCursor: null }`. */
18213
+ deviceIds: array(number()),
18214
+ /** Window lower bound on `lastSeen` (inclusive). */
18215
+ since: number().optional(),
18216
+ /** Window upper bound on `lastSeen` (inclusive). */
18217
+ until: number().optional(),
18218
+ /** Page size. Default 200, max 1000. */
18219
+ limit: number().int().min(1).max(1e3).default(200),
18220
+ /** Opaque continuation cursor from a previous page's `nextCursor`.
18221
+ * Encodes the (lastSeen, trackId) sort position — treat as opaque. */
18222
+ cursor: string().optional(),
18223
+ /** See {@link TrackProjectionSchema}. Default `full`. */
18224
+ projection: TrackProjectionSchema.optional(),
18225
+ /** Include stationary-promoted rows (parked objects). Default false: the
18226
+ * feed lists passages; parking records live on the stationary registry. */
18227
+ includeStationary: boolean().optional()
18228
+ });
18229
+ var RecentTracksPageSchema = object({
18230
+ /** Merged page, ordered by (`lastSeen` DESC, `trackId` DESC). */
18231
+ tracks: array(TrackSchema).readonly(),
18232
+ /** Cursor for the next page, or null when this page is the last. */
18233
+ nextCursor: string().nullable()
18234
+ });
18235
+ var LIST_GROUPS_DEFAULT_LIMIT = 40;
18236
+ var LIST_GROUPS_MAX_LIMIT = 100;
18237
+ var AnalyticsGroupRecordSchema = object({
18238
+ id: string(),
18239
+ deviceId: number().int(),
18240
+ openedAt: number().int(),
18241
+ closedAt: number().int(),
18242
+ timestamp: number().int(),
18243
+ memberCount: number().int(),
18244
+ memberTrackIds: array(string()).readonly(),
18245
+ className: string(),
18246
+ classes: array(string()).readonly(),
18247
+ /** Relative event-media path, or null when the group has no picture yet. */
18248
+ mediaUrl: string().nullable(),
18249
+ singleton: boolean()
18250
+ });
18251
+ var AnalyticsGroupMemberSchema = object({
18252
+ trackId: string(),
18253
+ deviceId: number().int(),
18254
+ className: string(),
18255
+ firstSeen: number().int(),
18256
+ lastSeen: number().int(),
18257
+ mediaUrl: string().nullable()
18258
+ });
18259
+ var AnalyticsGroupDetailSchema = AnalyticsGroupRecordSchema.extend({ members: array(AnalyticsGroupMemberSchema).readonly() });
18260
+ var ListGroupsQueryInput = object({
18261
+ /** Devices to merge. An empty array yields `{ groups: [], nextCursor: null }`. */
18262
+ deviceIds: array(number()),
18263
+ /** Window lower bound on `closedAt` (inclusive). */
18264
+ since: number().optional(),
18265
+ /** Window upper bound on `openedAt` (inclusive). */
18266
+ until: number().optional(),
18267
+ limit: number().int().min(1).max(LIST_GROUPS_MAX_LIMIT).default(LIST_GROUPS_DEFAULT_LIMIT),
18268
+ /** Opaque continuation cursor from a previous page's `nextCursor`. */
18269
+ cursor: string().optional()
18270
+ });
18271
+ var ListGroupsPageSchema = object({
18272
+ groups: array(AnalyticsGroupRecordSchema).readonly(),
18273
+ nextCursor: string().nullable()
18274
+ });
18275
+ var KeyEventQueryInput = object({
18276
+ deviceId: number(),
18277
+ /** Window lower bound (track firstSeen ≥ since). */
18278
+ since: number(),
18279
+ /** Window upper bound (track firstSeen ≤ until). */
17664
18280
  until: number(),
17665
18281
  limit: number().int().min(1).max(200).default(50),
17666
18282
  /** Drop tracks scoring below this importance. */
@@ -17859,6 +18475,24 @@ var RebuildStatusSchema = object({
17859
18475
  /** Present when the pass ended by throwing. */
17860
18476
  error: string().nullable()
17861
18477
  });
18478
+ var ReplayFrameInputSchema = object({
18479
+ timestamp: number(),
18480
+ frame: PipelineRunResultBridge
18481
+ });
18482
+ var RunReplayFrameProcessorResultSchema = object({ tracks: array(object({
18483
+ className: string(),
18484
+ firstSeenMs: number(),
18485
+ lastSeenMs: number(),
18486
+ /** Bbox of the track's FIRST matched detection, pixel-space in the clip's
18487
+ * frame — a representative box for the diff's `(className, window, IoU)`
18488
+ * pairing (`replay-diff.ts`). A replay does not need the full per-frame
18489
+ * trajectory production's `Track.positions` keeps. */
18490
+ bbox: BoundingBoxSchema,
18491
+ /** How many of the input frames this track matched a real detection on
18492
+ * (never a coasted/extrapolated frame) — the replay's own signal for "how
18493
+ * solid is this track", cheaper than re-deriving it from a trajectory. */
18494
+ framesMatched: number().int()
18495
+ })).readonly() });
17862
18496
  DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).readonly()), method(object({
17863
18497
  deviceId: number(),
17864
18498
  trackId: string()
@@ -18029,502 +18663,80 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
18029
18663
  }), RetrainAssistResultSchema, {
18030
18664
  kind: "mutation",
18031
18665
  auth: "admin"
18032
- }), method(object({ trackId: string() }), array(RetrainAnnotationSchema).readonly(), {
18033
- kind: "query",
18034
- auth: "admin"
18035
- }), method(object({
18036
- deviceId: number(),
18037
- trackId: string(),
18038
- frameId: string(),
18039
- annotations: array(RetrainAnnotationDraftSchema)
18040
- }), array(RetrainAnnotationSchema).readonly(), {
18041
- kind: "mutation",
18042
- auth: "admin"
18043
- }), method(object({
18044
- deviceId: number(),
18045
- trackId: string()
18046
- }), RetrainTransitionResultSchema, {
18047
- kind: "mutation",
18048
- auth: "admin"
18049
18666
  }), method(object({
18050
18667
  deviceId: number(),
18051
- trackId: string()
18052
- }), RetrainTransitionResultSchema, {
18668
+ source: DetectionSourceSchema,
18669
+ zones: array(ZoneSchema).readonly().optional(),
18670
+ detectionRules: array(ZoneRuleSchema).readonly().optional(),
18671
+ zoneMembershipMinOverlap: number().min(0).max(1).optional(),
18672
+ frames: array(ReplayFrameInputSchema).min(1)
18673
+ }), RunReplayFrameProcessorResultSchema, {
18053
18674
  kind: "mutation",
18054
18675
  auth: "admin"
18055
- }), method(object({ deviceIds: array(number()).optional() }), object({ url: string() }), {
18676
+ }), method(object({ trackId: string() }), array(RetrainAnnotationSchema).readonly(), {
18056
18677
  kind: "query",
18057
18678
  auth: "admin"
18058
18679
  }), method(object({
18059
- eventId: string(),
18060
- kind: MediaFileKindEnum.optional(),
18061
- deviceId: number()
18062
- }), array(MediaFileSchema).readonly()), method(object({
18063
- trackId: string(),
18064
- kinds: array(MediaFileKindEnum).optional(),
18065
- deviceId: number()
18066
- }), array(MediaFileSchema).readonly()), method(object({
18067
- trackId: string(),
18068
- deviceId: number()
18069
- }), array(MediaFileInfoSchema).readonly()), method(SearchObjectEventsInput, array(ScoredObjectEventSchema).readonly()), method(object({}), WipeObjectEmbeddingsResultSchema, {
18070
- kind: "mutation",
18071
- auth: "admin"
18072
- }), method(RebuildObjectEmbeddingsInput, RebuildObjectEmbeddingsResultSchema, {
18073
- kind: "mutation",
18074
- auth: "admin"
18075
- }), method(object({}), RebuildStatusSchema), object({
18076
- deviceId: number(),
18077
- timestamp: number(),
18078
- frameWidth: number(),
18079
- frameHeight: number(),
18080
- detections: array(OverlayDetectionSchema).readonly()
18081
- }), object({
18082
- deviceId: number(),
18083
- trackId: string(),
18084
- className: string()
18085
- }), object({
18086
18680
  deviceId: number(),
18087
18681
  trackId: string(),
18088
- className: string(),
18089
- durationMs: number()
18090
- }), object({
18091
- deviceId: number(),
18092
- kind: EventKindSchema,
18093
- eventId: string(),
18094
- timestamp: number()
18095
- });
18096
- /**
18097
- * Reference to the frame's retained NATIVE surface + the parent crop's placement
18098
- * within the frame, so the executor can re-cut a leaf child ROI at native
18099
- * resolution on the detail plane. See the `runPipeline` `nativeCropRef` field.
18100
- */
18101
- var NativeCropRefSchema = object({
18102
- /** Handle keying the retained native surface (node-pinned to its owner). */
18103
- handle: FrameHandleSchema,
18104
- /** The parent crop's padded/clamped rectangle in FRAME-space pixels. */
18105
- cropFrameSpace: object({
18106
- x: number(),
18107
- y: number(),
18108
- w: number(),
18109
- h: number()
18110
- })
18111
- });
18112
- object({
18113
- crop: object({
18114
- left: number(),
18115
- top: number(),
18116
- width: number().positive(),
18117
- height: number().positive()
18118
- }).optional(),
18119
- content: object({
18120
- width: number().int().positive(),
18121
- height: number().int().positive()
18122
- }),
18123
- fit: _enum(["stretch", "contain"]),
18124
- format: _enum([
18125
- "rgb",
18126
- "gray",
18127
- "jpeg"
18128
- ])
18129
- });
18130
- /**
18131
- * Process-local frame identity. It is serializable so it can ride an in-process
18132
- * capability call, but `registryId` deliberately prevents resolution in any
18133
- * other process or execution group.
18134
- */
18135
- var FrameRefSchema = object({
18136
- registryId: string().min(1),
18137
- id: string().min(1),
18138
- width: number().int().positive(),
18139
- height: number().int().positive(),
18140
- format: _enum(["rgb", "gray"]),
18141
- timestamp: number(),
18142
- capturedAt: number().optional()
18143
- });
18144
- var ModelFormatSchema$1 = _enum([
18145
- "onnx",
18146
- "coreml",
18147
- "openvino",
18148
- "tflite",
18149
- "pt",
18150
- "gguf"
18151
- ]);
18152
- var PipelineSlotSchema = _enum([
18153
- "detector",
18154
- "cropper",
18155
- "classifier",
18156
- "refiner",
18157
- "audio-classifier"
18158
- ]);
18159
- var PipelineEngineChoiceSchema = object({
18160
- runtime: _enum(["node", "python"]),
18161
- backend: string(),
18162
- format: ModelFormatSchema$1,
18163
- device: string().optional()
18164
- });
18165
- var AvailableEngineSchema = object({
18166
- engine: PipelineEngineChoiceSchema,
18167
- devices: array(object({
18168
- id: string(),
18169
- label: string(),
18170
- description: string().optional()
18171
- })).readonly(),
18172
- defaultDevice: string()
18173
- });
18174
- var PipelineDefaultStepSchema = lazy(() => object({
18175
- addonId: string(),
18176
- addonName: string(),
18177
- slot: PipelineSlotSchema,
18178
- inputClasses: array(string()).readonly(),
18179
- outputClasses: array(string()).readonly(),
18180
- enabled: boolean(),
18181
- modelId: string(),
18182
- children: array(PipelineDefaultStepSchema).readonly(),
18183
- group: string().optional(),
18184
- settings: record(string(), unknown()).optional()
18185
- }));
18186
- var PipelineTemplateStepSchema = lazy(() => object({
18187
- addonId: string(),
18188
- enabled: boolean(),
18189
- modelId: string(),
18190
- children: array(PipelineTemplateStepSchema).readonly(),
18191
- settings: record(string(), unknown()).optional()
18192
- }));
18193
- var PipelineTemplateSchema$1 = object({
18194
- id: string(),
18195
- name: string(),
18196
- createdAt: string(),
18197
- updatedAt: string(),
18198
- engine: PipelineEngineChoiceSchema,
18199
- steps: array(PipelineTemplateStepSchema).readonly()
18200
- });
18201
- var PipelineModelOptionSchema = object({
18202
- id: string(),
18203
- name: string(),
18204
- formats: record(string(), object({
18205
- downloaded: boolean(),
18206
- sizeMB: number()
18207
- })),
18208
- group: ModelVariantGroupSchema.optional(),
18209
- legacy: boolean().optional(),
18210
- provider: ModelProviderIdSchema.optional()
18211
- });
18212
- var ConfigFieldBridge = custom();
18213
- var PipelineAddonSchemaSchema = object({
18214
- id: string(),
18215
- name: string(),
18216
- slot: PipelineSlotSchema,
18217
- inputClasses: array(string()).readonly(),
18218
- outputClasses: array(string()).readonly(),
18219
- childSlots: array(PipelineSlotSchema).readonly(),
18220
- models: array(PipelineModelOptionSchema).readonly(),
18221
- defaultModelId: string(),
18222
- defaultModelIdByFormat: record(string(), string()).optional(),
18223
- enabledByDefault: boolean().optional(),
18224
- backfillIntoExistingOverrides: boolean().optional(),
18225
- defaultConfidence: number(),
18226
- group: string().optional(),
18227
- configSchema: array(ConfigFieldBridge).readonly().optional()
18228
- });
18229
- var PipelineSlotSchemaSchema = object({
18230
- id: PipelineSlotSchema,
18231
- label: string(),
18232
- priority: number(),
18233
- parentSlot: PipelineSlotSchema.nullable(),
18234
- addons: array(PipelineAddonSchemaSchema).readonly()
18235
- });
18236
- var PipelineSchemaSchema = object({
18237
- availableEngines: array(AvailableEngineSchema).readonly(),
18238
- selectedEngine: PipelineEngineChoiceSchema,
18239
- slots: array(PipelineSlotSchemaSchema).readonly()
18240
- });
18241
- var EngineProvisioningSchema = object({
18242
- runtimeId: _enum([
18243
- "onnx",
18244
- "openvino",
18245
- "coreml",
18246
- "edgetpu"
18247
- ]).nullable(),
18248
- device: string().nullable(),
18249
- state: _enum([
18250
- "idle",
18251
- "installing",
18252
- "verifying",
18253
- "ready",
18254
- "failed"
18255
- ]),
18256
- progress: number().optional(),
18257
- error: string().optional(),
18258
- nextRetryAt: number().optional(),
18259
- /**
18260
- * Gate A (config-correctness gate at engine change): human-readable
18261
- * config issues surfaced EAGERLY when the node's engine changes — model
18262
- * substitutions ("chose X, running Y") and zero-build steps ("no model
18263
- * has a <format> build"). Additive/optional: informational only, never
18264
- * enforced here — `assertEngineReady` (readiness) still gates inference.
18265
- * Absent/empty when the node-default tree resolves cleanly.
18266
- */
18267
- configIssues: array(string()).optional()
18268
- });
18269
- var PipelineStepInputSchema = lazy(() => object({
18270
- addonId: string(),
18271
- modelId: string().optional(),
18272
- enabled: boolean().default(true),
18273
- children: array(PipelineStepInputSchema).optional(),
18274
- settings: record(string(), unknown()).optional(),
18275
- jumpDeviceKey: string().optional()
18276
- }));
18277
- var ModelSubstitutionSchema = object({
18278
- addonId: string(),
18279
- chosen: string(),
18280
- running: string(),
18281
- format: string()
18282
- });
18283
- var PipelineValidationIssueSchema = object({
18284
- addonId: string(),
18285
- kind: _enum(["unknown-addon", "no-format-build"]),
18286
- detail: string()
18287
- });
18288
- var PipelineValidationResultSchema = object({
18289
- ok: boolean(),
18290
- issues: array(PipelineValidationIssueSchema).readonly(),
18291
- substitutions: array(ModelSubstitutionSchema).readonly(),
18292
- /** The node's `currentEngine.format` this validation ran against. */
18293
- format: string()
18294
- });
18295
- var ReferenceImageEntrySchema = object({
18296
- filename: string(),
18297
- stepIds: array(string()).readonly().optional()
18298
- });
18299
- var ReferenceImageBodySchema = object({
18300
- base64: string(),
18301
- filename: string()
18302
- });
18303
- var ReferenceAudioEntrySchema = object({
18304
- filename: string(),
18305
- sizeKb: number()
18306
- });
18307
- var ReferenceAudioBodySchema = object({ base64: string() });
18308
- var AudioBackendSchema = object({
18309
- id: string(),
18310
- name: string(),
18311
- description: string(),
18312
- available: boolean(),
18313
- /**
18314
- * Raw classifier labels this backend can emit (e.g. YAMNet's
18315
- * 521-class set or Apple SoundAnalysis's 303-class set). Used by
18316
- * the benchmark UI to populate the `enabledMicroClasses` filter
18317
- * specific to the selected backend without a separate fetch.
18318
- */
18319
- rawLabels: array(string()).readonly().optional()
18320
- });
18321
- var AudioCapabilitiesSchema = object({
18322
- activeBackend: string(),
18323
- availableBackends: array(AudioBackendSchema).readonly(),
18324
- sampleRate: number(),
18325
- chunkDurationMs: number()
18326
- });
18327
- var DownloadModelResultSchema = object({
18328
- filePath: string(),
18329
- sizeMB: number(),
18330
- durationMs: number()
18331
- });
18332
- /**
18333
- * Wrapper carrying a single test run's result. Replaces the legacy
18334
- * ad-hoc `{labels: [{className, originalClass, score}]}` shape with the
18335
- * canonical `AudioResult` from the Phase 6 output rework: one
18336
- * `AudioDetection` per class above `minScore`, top-N candidates in
18337
- * `debug.alternateLabels['audio-classifier']`, per-source timings in
18338
- * `debug.stepTimings`. The outer `success`/`error` fields stay so the
18339
- * benchmark UI can still report a clean failure when the classifier
18340
- * cap isn't available.
18341
- */
18342
- var AudioTestResultSchema = object({
18343
- success: boolean(),
18344
- error: string().optional(),
18345
- frame: custom().optional()
18346
- });
18347
- var PipelineConfigBridge = custom();
18348
- var ConfigUISchemaBridge = custom();
18349
- var ConfigUISchemaNullableBridge = custom();
18350
- var InferenceCapabilitiesBridge = custom();
18351
- var ModelAvailabilityListBridge = custom();
18352
- var PipelineRunResultBridge = custom();
18353
- method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngineChoiceSchema), method(PipelineEngineChoiceSchema, array(PipelineDefaultStepSchema)), method(object({ nodeId: string() }), EngineProvisioningSchema), method(_void(), record(string(), object({
18354
- modelId: string(),
18355
- settings: record(string(), unknown()).readonly()
18356
- }))), method(object({ steps: record(string(), object({
18357
- modelId: string(),
18358
- settings: record(string(), unknown()).readonly()
18359
- })) }), object({ success: literal(true) }), {
18360
- kind: "mutation",
18361
- auth: "admin"
18362
- }), method(object({ nodeId: string() }), object({
18363
- success: literal(true),
18364
- clearedDevices: number()
18365
- }), {
18366
- kind: "mutation",
18367
- auth: "admin"
18368
- }), method(_void(), PipelineSchemaSchema), method(_void(), array(PipelineDefaultStepSchema).readonly().nullable()), method(_void(), PipelineConfigBridge), method(_void(), ConfigUISchemaBridge), method(object({ steps: array(PipelineStepInputSchema) }), PipelineValidationResultSchema), method(_void(), array(PipelineTemplateSchema$1).readonly()), method(object({
18369
- name: string(),
18370
- steps: array(PipelineTemplateStepSchema).readonly(),
18371
- engine: PipelineEngineChoiceSchema
18372
- }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({
18373
- id: string(),
18374
- name: string().optional(),
18375
- steps: array(PipelineTemplateStepSchema).readonly().optional()
18376
- }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({ id: string() }), _void(), { kind: "mutation" }), method(_void(), InferenceCapabilitiesBridge), method(object({ addonId: string() }), ModelAvailabilityListBridge), method(object({
18377
- addonId: string(),
18378
- modelId: string(),
18379
- format: ModelFormatSchema$1
18380
- }), DownloadModelResultSchema, { kind: "mutation" }), method(object({
18381
- addonId: string(),
18382
- modelId: string(),
18383
- format: ModelFormatSchema$1
18384
- }), object({ success: literal(true) }), { kind: "mutation" }), method(object({
18385
- engine: PipelineEngineChoiceSchema.optional(),
18386
- steps: array(PipelineStepInputSchema).min(1),
18387
- frame: FrameInputSchema.optional(),
18388
- /**
18389
- * Process-local lazy frame. Valid only when caller and provider resolve
18390
- * in the same execution-group process; split/cross-node callers use
18391
- * `frame`/`image` inline compatibility instead.
18392
- */
18393
- frameRef: FrameRefSchema.optional(),
18394
- /**
18395
- * CB5 shm passthrough — a `FrameHandle` naming the same ring slot
18396
- * the decoded pixels live in. One more member of the one-of
18397
- * frame/frameHandle/image/imageBase64/referenceImage group.
18398
- */
18399
- frameHandle: FrameHandleSchema.optional(),
18400
- imageBase64: string().optional(),
18401
- /**
18402
- * Binary JPEG bytes — preferred over `imageBase64` on internal
18403
- * hops (hub → forked worker via Moleculer MsgPack) because it
18404
- * skips the 33% base64 overhead + the per-call base64 decode on
18405
- * the detection-pipeline worker. Callers can pass either; exactly
18406
- * one of `frame`/`image`/`imageBase64`/`referenceImage` is required.
18407
- */
18408
- image: _instanceof(Uint8Array).optional(),
18409
- referenceImage: string().optional(),
18410
- deviceId: number().optional(),
18411
- sessionId: string().optional(),
18412
- /**
18413
- * Execution plane. 'full' (default) runs the whole tree — benchmark,
18414
- * reference-image, and detail-subtree calls. 'frame' is the live
18415
- * per-frame dispatch: ONLY root-plane steps run; crop children
18416
- * (inputClasses ≠ null) are skipped and served per-track via
18417
- * pipelineRunner.runDetailSubtree (two-plane design).
18418
- */
18419
- plane: _enum(["full", "frame"]).optional(),
18420
- /**
18421
- * Inference-device selector (Phase 2 multi-device). Format
18422
- * `<backend>:<device>` (e.g. `openvino:gpu`, `edgetpu:usb`, `cpu`).
18423
- * Omitted ⇒ the runner's default device (current single-engine
18424
- * behaviour). Selects WHICH device pool of the node runs the call.
18425
- */
18426
- deviceKey: string().optional(),
18427
- /**
18428
- * Two-plane NATIVE child-crop reference. Set by `runDetailSubtree` ONLY
18429
- * when the parent crop was resolved from the frame's retained NATIVE
18430
- * surface (a frameHandle HIT). Lets the executor re-cut a LEAF crop
18431
- * child's ROI (plate-ocr, face-embedding, leaf classifiers) at native
18432
- * resolution from that surface — the SAME quality path faces already
18433
- * had — instead of the downscaled parent tile. `handle` keys the native
18434
- * surface (node-pinned to its owner); `cropFrameSpace` is the parent
18435
- * crop's padded/clamped rectangle in FRAME-space pixels, used to compose
18436
- * the executor's crop-normalized child ROI back into frame-normalized
18437
- * coordinates. Auxiliary to the image source (`image`/`frame`/…), NOT one
18438
- * of the mutually-exclusive image inputs. Absent ⇒ tile-crop children
18439
- * (today's behaviour on the fallback path).
18440
- */
18441
- nativeCropRef: NativeCropRefSchema.optional()
18442
- }), PipelineRunResultBridge, { kind: "mutation" }), method(object({
18443
- engine: PipelineEngineChoiceSchema.optional(),
18444
- steps: array(PipelineStepInputSchema).min(1),
18445
- frames: array(FrameInputSchema).min(1).max(255),
18446
- deviceId: number().optional(),
18447
- sessionId: string().optional(),
18448
- /**
18449
- * Pure-inference benchmark hint. A NONZERO uint32 pins every frame in
18450
- * the batch to the Python pool's bench preprocess cache
18451
- * (`_bench_frame_id`) so a REPEATED benchmark frame is decoded +
18452
- * preprocessed ONCE and every later inference is a pure-inference cache
18453
- * hit — the sustained-throughput run measures inference, not
18454
- * decode+preprocess+infer. Omitted/0 for live frames (all different →
18455
- * full preprocess every call, correct). Fresh per sustained run;
18456
- * released via `uncacheFrame`.
18457
- */
18458
- frameId: number().int().nonnegative().optional(),
18459
- /** Inference-device selector (Phase 2 multi-device); see runPipeline. */
18460
- deviceKey: string().optional()
18461
- }), object({ results: array(PipelineRunResultBridge).readonly() }), { kind: "mutation" }), method(object({
18462
- data: _instanceof(Uint8Array),
18463
- width: number().int().positive(),
18464
- height: number().int().positive(),
18465
- format: _enum([
18466
- "rgb",
18467
- "bgr",
18468
- "gray"
18469
- ])
18470
- }), object({
18471
- frameId: number(),
18472
- width: number(),
18473
- height: number()
18474
- }), { kind: "mutation" }), method(object({
18475
- stepId: string(),
18476
- frameId: number().int()
18477
- }), record(string(), unknown()), { kind: "mutation" }), method(object({ frameId: number().int() }), _void(), { kind: "mutation" }), method(_void(), object({
18478
- batchMode: string(),
18479
- windowMs: number(),
18480
- maxBatchSize: number(),
18481
- concurrency: number()
18482
- })), method(_void(), array(object({
18483
- engineKey: string(),
18484
- engine: PipelineEngineChoiceSchema,
18485
- modelsLoaded: array(string()).readonly(),
18486
- inUseByCameras: array(number()).readonly(),
18487
- /**
18488
- * Origin of this resident factory.
18489
- * - `runtime` — main camera-serving engine (no idle TTL).
18490
- * - `warm-override` — benchmark/test override held in the warm
18491
- * cache; auto-disposed after the idle TTL.
18492
- * - `device-pool` — a concurrent per-device pool (Phase 2
18493
- * multi-device, keyed by `deviceKey`) resolved
18494
- * via `resolveDeviceFactory`. Runs alongside the
18495
- * `runtime` engine on a DIFFERENT accelerator
18496
- * (NPU / iGPU / Coral) — this is how the
18497
- * Engines tab shows all pools running at once.
18498
- */
18499
- kind: _enum([
18500
- "runtime",
18501
- "warm-override",
18502
- "device-pool"
18503
- ]),
18504
- /** Native pid of the underlying Python pool (null when no pool). */
18505
- poolPid: number().nullable(),
18506
- /** ms since this factory was last used (null when not warm-tracked). */
18507
- idleMs: number().nullable(),
18508
- /** Idle TTL after which `warm-override` factories self-evict (null when not applicable). */
18509
- idleTtlMs: number().nullable()
18510
- })).readonly()), method(object({ engine: PipelineEngineChoiceSchema }), object({ success: literal(true) }), {
18682
+ frameId: string(),
18683
+ annotations: array(RetrainAnnotationDraftSchema)
18684
+ }), array(RetrainAnnotationSchema).readonly(), {
18511
18685
  kind: "mutation",
18512
18686
  auth: "admin"
18513
18687
  }), method(object({
18514
- engine: PipelineEngineChoiceSchema,
18515
- force: boolean().optional()
18516
- }), object({
18517
- success: boolean(),
18518
- reason: string().optional()
18519
- }), {
18688
+ deviceId: number(),
18689
+ trackId: string()
18690
+ }), RetrainTransitionResultSchema, {
18520
18691
  kind: "mutation",
18521
18692
  auth: "admin"
18522
- }), method(_void(), array(ReferenceImageEntrySchema).readonly()), method(object({ filename: string() }), ReferenceImageBodySchema.nullable()), method(_void(), array(ReferenceAudioEntrySchema).readonly()), method(object({ filename: string() }), ReferenceAudioBodySchema.nullable()), method(_void(), AudioCapabilitiesSchema), method(object({
18523
- addonId: string(),
18524
- modelId: string(),
18525
- filename: string().optional(),
18526
- settings: record(string(), unknown()).optional()
18527
- }), AudioTestResultSchema, { kind: "mutation" }), method(_void(), ConfigUISchemaNullableBridge);
18693
+ }), method(object({
18694
+ deviceId: number(),
18695
+ trackId: string()
18696
+ }), RetrainTransitionResultSchema, {
18697
+ kind: "mutation",
18698
+ auth: "admin"
18699
+ }), method(object({ deviceIds: array(number()).optional() }), object({ url: string() }), {
18700
+ kind: "query",
18701
+ auth: "admin"
18702
+ }), method(object({
18703
+ eventId: string(),
18704
+ kind: MediaFileKindEnum.optional(),
18705
+ deviceId: number()
18706
+ }), array(MediaFileSchema).readonly()), method(object({
18707
+ trackId: string(),
18708
+ kinds: array(MediaFileKindEnum).optional(),
18709
+ deviceId: number()
18710
+ }), array(MediaFileSchema).readonly()), method(object({
18711
+ trackId: string(),
18712
+ deviceId: number()
18713
+ }), array(MediaFileInfoSchema).readonly()), method(SearchObjectEventsInput, array(ScoredObjectEventSchema).readonly()), method(object({}), WipeObjectEmbeddingsResultSchema, {
18714
+ kind: "mutation",
18715
+ auth: "admin"
18716
+ }), method(RebuildObjectEmbeddingsInput, RebuildObjectEmbeddingsResultSchema, {
18717
+ kind: "mutation",
18718
+ auth: "admin"
18719
+ }), method(object({}), RebuildStatusSchema), object({
18720
+ deviceId: number(),
18721
+ timestamp: number(),
18722
+ frameWidth: number(),
18723
+ frameHeight: number(),
18724
+ detections: array(OverlayDetectionSchema).readonly()
18725
+ }), object({
18726
+ deviceId: number(),
18727
+ trackId: string(),
18728
+ className: string()
18729
+ }), object({
18730
+ deviceId: number(),
18731
+ trackId: string(),
18732
+ className: string(),
18733
+ durationMs: number()
18734
+ }), object({
18735
+ deviceId: number(),
18736
+ kind: EventKindSchema,
18737
+ eventId: string(),
18738
+ timestamp: number()
18739
+ });
18528
18740
  object({
18529
18741
  activeCameras: number(),
18530
18742
  throttledCameras: number(),
@@ -18550,66 +18762,6 @@ var CameraMetricsSchema = object({
18550
18762
  });
18551
18763
  var CameraMetricsWithDeviceIdSchema = CameraMetricsSchema.extend({ deviceId: number() });
18552
18764
  /**
18553
- * Zone — pure geometry + identity. NO filtering behaviour.
18554
- *
18555
- * Zones describe **where** in the frame the operator wants to flag
18556
- * something; consumer-owned {@link ZoneRule} arrays describe **how**
18557
- * each pipeline stage uses them. Splitting the two means a single
18558
- * polygon "Driveway" can simultaneously back a motion-exclude rule,
18559
- * a detection-include rule on `['car']`, and an occupancy aggregate
18560
- * — without three duplicated polygons.
18561
- *
18562
- * Owned by the orchestrator addon (provider) and mirrored into the
18563
- * `zones` device-state slice on every mutation. Consumers
18564
- * (motion-wasm, pipeline-executor, analytics, admin UI) read either
18565
- * via `api.zones.listZones` (one-shot) or via `dev.state.zones` (live
18566
- * mirror with `onChanged`).
18567
- *
18568
- * Coordinates are normalised fractions of the frame (0–1) so zones
18569
- * survive resolution changes and stream profile switches.
18570
- *
18571
- * `kind` discriminates between full polygons (closed regions used
18572
- * for intrusion / occupancy filters) and tripwires (open 2-point
18573
- * line segments used for cross events). Onboard / firmware-reported
18574
- * zones (Reolink, ONVIF) are out of scope for now — see the deferred
18575
- * task list.
18576
- */
18577
- var ZoneKindEnum = _enum(["polygon", "tripwire"]);
18578
- /** Polygon vertex in fraction-of-frame coordinates (0–1). */
18579
- var PolygonPointSchema = object({
18580
- x: number(),
18581
- y: number()
18582
- });
18583
- /** A camera detection zone — pure geometry/identity. */
18584
- var ZoneSchema = object({
18585
- id: string(),
18586
- name: string(),
18587
- kind: ZoneKindEnum.default("polygon"),
18588
- /** Polygon vertices, fraction of frame (0–1). */
18589
- polygon: array(PolygonPointSchema).readonly(),
18590
- /** Visual color for UI rendering. */
18591
- color: string().default("#3b82f6")
18592
- });
18593
- DeviceType.Camera, method(object({ deviceId: number() }), array(ZoneSchema).readonly()), method(object({
18594
- deviceId: number(),
18595
- zone: ZoneSchema
18596
- }), _void(), {
18597
- kind: "mutation",
18598
- auth: "admin"
18599
- }), method(object({
18600
- deviceId: number(),
18601
- zoneId: string()
18602
- }), _void(), {
18603
- kind: "mutation",
18604
- auth: "admin"
18605
- }), method(object({
18606
- deviceId: number(),
18607
- zone: ZoneSchema
18608
- }), _void(), {
18609
- kind: "mutation",
18610
- auth: "admin"
18611
- }), object({ zones: array(ZoneSchema).readonly() });
18612
- /**
18613
18765
  * A bounding box in NORMALIZED [0,1] frame coordinates for `getNativeCrop`. The
18614
18766
  * decode worker resolves it against the RETAINED native frame's real pixel dims,
18615
18767
  * so the caller supplies only the detection-res bbox divided by the detection
@@ -25587,6 +25739,39 @@ var ReadGopBytesResultSchema = object({
25587
25739
  /** Media ms the returned fragment covers. */
25588
25740
  gopDurMs: number()
25589
25741
  });
25742
+ /**
25743
+ * A time WINDOW of one finalized segment, cut by byte range — the multi-GOP
25744
+ * twin of {@link ReadGopBytesResultSchema}'s single instant. Built for the
25745
+ * replay clip's `recording` source (`docs/design/plans/2026-08-26-replay-clip-su-pipeline.md`):
25746
+ * a replay needs several seconds of native pixels, not one frame.
25747
+ *
25748
+ * `ok.data` is standalone-demuxable, same as a GOP read. `ok.reachesRequestedEnd`
25749
+ * is `false` when the returned bytes were cut short by the read's own safety
25750
+ * byte cap before covering `[fromMs, toMs)` — a truncation, reported, not a
25751
+ * silently shorter answer. `spans-multiple-segments` is a REFUSAL, not a
25752
+ * degradation: a window whose end falls past the covering segment would need
25753
+ * bytes stitched from a second segment file (its own `ftyp`+`moov`), which is
25754
+ * not one standalone-demuxable stream — the caller's answer is to request a
25755
+ * shorter window or one aligned to a single segment, not to receive spliced
25756
+ * bytes nothing has proven decodable.
25757
+ */
25758
+ var ReadWindowBytesResultSchema = discriminatedUnion("kind", [object({
25759
+ kind: literal("ok"),
25760
+ data: _instanceof(Uint8Array),
25761
+ /** Absolute epoch ms of the returned bytes' first sample — at or before
25762
+ * the requested `fromMs` (anchored on the nearest keyframe). */
25763
+ gopStartMs: number(),
25764
+ /** Media ms the returned bytes cover, from `gopStartMs`. */
25765
+ gopDurMs: number(),
25766
+ /** `false` ⇒ the safety byte cap cut the read short before it reached
25767
+ * the requested `toMs`; the caller got fewer frames than asked for. */
25768
+ reachesRequestedEnd: boolean()
25769
+ }), object({
25770
+ kind: literal("spans-multiple-segments"),
25771
+ /** Where the covering segment's own footage runs out — informational,
25772
+ * not a retry hint (retrying the same window would refuse again). */
25773
+ segmentEndMs: number()
25774
+ })]);
25590
25775
  method(object({
25591
25776
  deviceId: number(),
25592
25777
  fromMs: number(),
@@ -25637,6 +25822,15 @@ method(object({
25637
25822
  }), ReadGopBytesResultSchema, {
25638
25823
  kind: "query",
25639
25824
  auth: "admin"
25825
+ }), method(object({
25826
+ deviceId: number(),
25827
+ profile: string(),
25828
+ startMs: number(),
25829
+ fromMs: number(),
25830
+ toMs: number()
25831
+ }), ReadWindowBytesResultSchema, {
25832
+ kind: "query",
25833
+ auth: "admin"
25640
25834
  }), method(object({
25641
25835
  deviceId: number(),
25642
25836
  config: RecordingConfigSchema
@@ -26191,92 +26385,6 @@ DeviceType.Camera, method(object({ deviceId: number() }), SceneMonitorStatusSche
26191
26385
  kind: "mutation",
26192
26386
  auth: "admin"
26193
26387
  });
26194
- /**
26195
- * Per-stage gating mode applied to the zones a rule references.
26196
- *
26197
- * - `include`: the rule contributes to a **whitelist** for its stage.
26198
- * When at least one `include` rule fires for a stage, only entities
26199
- * inside one of those zones pass that stage.
26200
- * - `exclude`: the rule contributes to a **blacklist** for its stage.
26201
- * Entities inside one of those zones are dropped at that stage.
26202
- *
26203
- * `monitor`-style observation (count without filtering) is not a rule
26204
- * mode — zones without any matching rule are observed naturally by
26205
- * `zone-analytics` (live snapshot + history), so an "I just want to
26206
- * count, not filter" use case needs no rule at all.
26207
- */
26208
- var ZoneRuleModeEnum = _enum(["include", "exclude"]);
26209
- /**
26210
- * Per-consumer rule that references existing zones (geometry) and
26211
- * defines how a specific pipeline stage should treat them. Each
26212
- * consumer addon owns its own `ZoneRule[]` array in its per-device
26213
- * settings:
26214
- *
26215
- * - `addon-motion-wasm` → `motionZoneRules: ZoneRule[]` (motion stage)
26216
- * - `addon-detection-pipeline` → `detectionZoneRules: ZoneRule[]` (detection stage)
26217
- * - future: notification rules, audio gating, etc.
26218
- *
26219
- * One rule applies to N zones (`zoneIds[]`) so the operator can
26220
- * express "ignore motion in ALL of {garden, street}" with a single
26221
- * rule. `classFilter` narrows the rule to specific object classes —
26222
- * "drop person detections in the street, but keep cars" is one
26223
- * `exclude` rule with `classFilter: ['person']`.
26224
- *
26225
- * `enabled` is a soft toggle — the operator can keep the rule
26226
- * configured but inert without deleting it.
26227
- */
26228
- var ZoneRuleSchema = object({
26229
- /** Stable rule id — survives edits, used by the UI for diffing. */
26230
- id: string(),
26231
- /** Optional human-readable label rendered in the rule editor. */
26232
- name: string().optional(),
26233
- /** Zones this rule targets. The rule's `mode` applies to ALL
26234
- * listed zones (OR-set: a detection in any one of them counts).
26235
- * At least one zone id required — a rule with no targets is a
26236
- * configuration mistake and the form validator rejects it. */
26237
- zoneIds: array(string()).min(1).readonly(),
26238
- mode: ZoneRuleModeEnum,
26239
- /**
26240
- * Class names this rule applies to. Empty / undefined ⇒ rule
26241
- * applies to every class. Class strings match the `macroClass`
26242
- * field on detections (e.g. `person`, `car`, `dog`).
26243
- */
26244
- classFilter: array(string()).readonly().optional(),
26245
- /**
26246
- * Minimum bbox/mask overlap (0–1) with any of the rule's zones
26247
- * required to consider an entity "in the zone". Defaults to the
26248
- * consumer's stage default when omitted. Kept for back-compat with
26249
- * existing per-rule overrides; new operators pick the value via
26250
- * `bboxInclusionPct` (operator-friendly 0–100). Whichever field is
26251
- * set, the lower-level engine reads it as a 0–1 fraction.
26252
- */
26253
- overlapThreshold: number().min(0).max(1).optional(),
26254
- /**
26255
- * Operator-friendly version of `overlapThreshold` — the percentage
26256
- * of the detection's bbox that must lie inside the zone for the
26257
- * rule to match. Documented default is 85%; the engine substitutes
26258
- * that when the field is omitted (kept optional so existing rules
26259
- * stored without it stay valid).
26260
- *
26261
- * When BOTH `overlapThreshold` and `bboxInclusionPct` are set on a
26262
- * rule, the engine prefers `bboxInclusionPct` because it's the
26263
- * field exposed in the UI. Internally both feed the same gate.
26264
- */
26265
- bboxInclusionPct: number().min(0).max(100).optional(),
26266
- /**
26267
- * When `true` and a detection has a segmentation mask, use the
26268
- * mask for overlap instead of the bbox. Detection-stage only;
26269
- * motion rules ignore this field.
26270
- */
26271
- preferMask: boolean().optional(),
26272
- /**
26273
- * Soft-toggle: `false` disables the rule without deleting it.
26274
- * Defaults to `true` so operators creating a rule via the UI
26275
- * see it active immediately.
26276
- */
26277
- enabled: boolean().default(true)
26278
- });
26279
- array(ZoneRuleSchema).readonly();
26280
26388
  object({
26281
26389
  /** Whether the script is currently executing. */
26282
26390
  isRunning: boolean(),
@@ -30141,6 +30249,12 @@ Object.freeze({
30141
30249
  addonId: null,
30142
30250
  access: "view"
30143
30251
  },
30252
+ "notificationRules.resolveArtifactUrl": {
30253
+ capName: "notification-rules",
30254
+ capScope: "system",
30255
+ addonId: null,
30256
+ access: "view"
30257
+ },
30144
30258
  "notificationRules.setAlarmConfig": {
30145
30259
  capName: "notification-rules",
30146
30260
  capScope: "system",
@@ -30585,6 +30699,12 @@ Object.freeze({
30585
30699
  addonId: null,
30586
30700
  access: "create"
30587
30701
  },
30702
+ "pipelineAnalytics.runReplayFrameProcessor": {
30703
+ capName: "pipeline-analytics",
30704
+ capScope: "device",
30705
+ addonId: null,
30706
+ access: "create"
30707
+ },
30588
30708
  "pipelineAnalytics.saveRetrainAnnotations": {
30589
30709
  capName: "pipeline-analytics",
30590
30710
  capScope: "device",
@@ -30717,6 +30837,12 @@ Object.freeze({
30717
30837
  addonId: null,
30718
30838
  access: "view"
30719
30839
  },
30840
+ "pipelineExecutor.getInferenceDeviceHealth": {
30841
+ capName: "pipeline-executor",
30842
+ capScope: "system",
30843
+ addonId: null,
30844
+ access: "view"
30845
+ },
30720
30846
  "pipelineExecutor.getOrchestratorConfigSchema": {
30721
30847
  capName: "pipeline-executor",
30722
30848
  capScope: "system",
@@ -30789,6 +30915,12 @@ Object.freeze({
30789
30915
  addonId: null,
30790
30916
  access: "view"
30791
30917
  },
30918
+ "pipelineExecutor.rearmInferenceDevice": {
30919
+ capName: "pipeline-executor",
30920
+ capScope: "system",
30921
+ addonId: null,
30922
+ access: "create"
30923
+ },
30792
30924
  "pipelineExecutor.runAudioTest": {
30793
30925
  capName: "pipeline-executor",
30794
30926
  capScope: "system",
@@ -31527,6 +31659,12 @@ Object.freeze({
31527
31659
  addonId: null,
31528
31660
  access: "view"
31529
31661
  },
31662
+ "recording.readWindowBytes": {
31663
+ capName: "recording",
31664
+ capScope: "system",
31665
+ addonId: null,
31666
+ access: "view"
31667
+ },
31530
31668
  "recording.refreshStorageLocationsForMigration": {
31531
31669
  capName: "recording",
31532
31670
  capScope: "system",
@@ -34037,6 +34175,11 @@ Object.freeze({
34037
34175
  form: "single",
34038
34176
  optional: false
34039
34177
  }],
34178
+ "pipelineAnalytics.runReplayFrameProcessor": [{
34179
+ name: "deviceId",
34180
+ form: "single",
34181
+ optional: false
34182
+ }],
34040
34183
  "pipelineAnalytics.saveRetrainAnnotations": [{
34041
34184
  name: "deviceId",
34042
34185
  form: "single",
@@ -34352,6 +34495,11 @@ Object.freeze({
34352
34495
  form: "single",
34353
34496
  optional: false
34354
34497
  }],
34498
+ "recording.readWindowBytes": [{
34499
+ name: "deviceId",
34500
+ form: "single",
34501
+ optional: false
34502
+ }],
34355
34503
  "recording.relocateFootage": [{
34356
34504
  name: "deviceId",
34357
34505
  form: "single",