@camstack/addon-ai 0.4.22 → 0.4.24

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 (3) hide show
  1. package/dist/addon.js +1585 -1437
  2. package/dist/addon.mjs +1585 -1437
  3. package/package.json +1 -1
package/dist/addon.js CHANGED
@@ -15780,7 +15780,23 @@ var NcHistoryEntrySchema = object({
15780
15780
  updatedAt: number$1(),
15781
15781
  /** Failure detail — present on a `dead` row. */
15782
15782
  error: string().optional(),
15783
- subject: NcHistorySubjectSchema
15783
+ subject: NcHistorySubjectSchema,
15784
+ /**
15785
+ * Ids of the artefacts (still, then gif, then clip) this row's successful
15786
+ * delivery indexed in the artefact library — a REFERENCE, never the bytes
15787
+ * (an artefact is often megabytes; this row is durable JSON rewritten on
15788
+ * every delivery attempt). Absent on a row still pending/dead, a row
15789
+ * delivered before this field shipped, or a wiring with no artefact index.
15790
+ *
15791
+ * Resolve one to a fetchable URL with `resolveArtifactUrl` — an id
15792
+ * outlives any one URL's TTL, so a caller mints a fresh link on demand
15793
+ * rather than trusting one frozen at delivery time. `resolveArtifactUrl`
15794
+ * also answers `null` for an id whose artefact has since expired past the
15795
+ * retained shelf's own age bound — the degrade a caller (the Home
15796
+ * Assistant export) must render as "no image right now", never as a
15797
+ * broken link.
15798
+ */
15799
+ artifactIds: array(string().min(1)).optional()
15784
15800
  });
15785
15801
  /**
15786
15802
  * Query filter for `getHistory` (spec §4.2). Every field is a narrowing
@@ -16007,7 +16023,7 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
16007
16023
  }), method(object({}), object({
16008
16024
  catalog: array(NcConditionDescriptorSchema),
16009
16025
  taxonomy: NcTaxonomySchema.optional()
16010
- })), 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 }), {
16026
+ })), 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 }), {
16011
16027
  kind: "mutation",
16012
16028
  caller: "required"
16013
16029
  }), method(object({ snoozeId: string() }), object({ success: literal(true) }), {
@@ -16347,896 +16363,1496 @@ var OauthIntegrationDescriptorSchema = object({
16347
16363
  });
16348
16364
  method(_void(), OauthIntegrationDescriptorSchema, { auth: "admin" });
16349
16365
  /**
16350
- * pipeline-analytics — device-scoped wrapper cap. Refines raw
16351
- * per-frame detections emitted by the pipeline runner into tracked
16352
- * objects, per-kind event collections (motion / object / audio), and
16353
- * persisted media. Owns the post-detection domain end-to-end:
16354
- *
16355
- * runner emits PipelineInferenceResult
16356
- * ↓ (event bus)
16357
- * pipeline-analytics subscriber
16358
- * ↓ SORT tracker + zone engine + state analyzer + event emitter
16359
- * → three DB collections (one per kind), one FS media tree, one
16360
- * unified event emitter (FrameTracked + TrackStarted/Ended +
16361
- * DetectionEvent on bus)
16362
- *
16363
- * Pure subscriber model. No `processFrame` cap method — the runner
16364
- * already publishes the raw frame on the bus. The cap surface is
16365
- * only QUERIES + per-device settings, bound on/off via
16366
- * `device-manager.setWrapperActive`. `defaultActive: true` because
16367
- * every camera with a detection pipeline wants its raw detections
16368
- * refined; operators opt out per-device via BindingsTab when needed.
16369
- *
16370
- * Replaces the legacy `analysis-pipeline`, `analysis-data-persistence`
16371
- * (per-device surface) and `track-trail` caps — see P11 cleanup.
16366
+ * Reference to the frame's retained NATIVE surface + the parent crop's placement
16367
+ * within the frame, so the executor can re-cut a leaf child ROI at native
16368
+ * resolution on the detail plane. See the `runPipeline` `nativeCropRef` field.
16372
16369
  */
16373
- var TrackStateSchema = _enum([
16374
- "new",
16375
- "entered",
16376
- "left",
16377
- "moving",
16378
- "idle"
16379
- ]);
16380
- var EventKindSchema = _enum([
16381
- "motion",
16382
- "object",
16383
- "audio"
16384
- ]);
16370
+ var NativeCropRefSchema = object({
16371
+ /** Handle keying the retained native surface (node-pinned to its owner). */
16372
+ handle: FrameHandleSchema,
16373
+ /** The parent crop's padded/clamped rectangle in FRAME-space pixels. */
16374
+ cropFrameSpace: object({
16375
+ x: number$1(),
16376
+ y: number$1(),
16377
+ w: number$1(),
16378
+ h: number$1()
16379
+ })
16380
+ });
16381
+ object({
16382
+ crop: object({
16383
+ left: number$1(),
16384
+ top: number$1(),
16385
+ width: number$1().positive(),
16386
+ height: number$1().positive()
16387
+ }).optional(),
16388
+ content: object({
16389
+ width: number$1().int().positive(),
16390
+ height: number$1().int().positive()
16391
+ }),
16392
+ fit: _enum(["stretch", "contain"]),
16393
+ format: _enum([
16394
+ "rgb",
16395
+ "gray",
16396
+ "jpeg"
16397
+ ])
16398
+ });
16385
16399
  /**
16386
- * Spatial filter for `listTracks` — the rect + polygon variants of the shared
16387
- * MaskShape vocabulary (see `mask-shape.ts`). Coordinates are NORMALIZED 0..1
16388
- * of the camera frame (top-left origin), matching the drawing-plane editor.
16400
+ * Process-local frame identity. It is serializable so it can ride an in-process
16401
+ * capability call, but `registryId` deliberately prevents resolution in any
16402
+ * other process or execution group.
16389
16403
  */
16390
- var TrackZoneFilterSchema = discriminatedUnion("kind", [MaskRectShapeSchema, MaskPolygonShapeSchema]);
16391
- /** Closed icon vocabulary so clients render a known glyph per kind. */
16392
- var EventKindIconSchema = _enum([
16393
- "motion",
16394
- "audio",
16395
- "person",
16396
- "vehicle",
16397
- "animal",
16398
- "door",
16399
- "pir",
16400
- "smoke",
16401
- "water",
16402
- "button",
16403
- "package",
16404
- "generic"
16404
+ var FrameRefSchema = object({
16405
+ registryId: string().min(1),
16406
+ id: string().min(1),
16407
+ width: number$1().int().positive(),
16408
+ height: number$1().int().positive(),
16409
+ format: _enum(["rgb", "gray"]),
16410
+ timestamp: number$1(),
16411
+ capturedAt: number$1().optional()
16412
+ });
16413
+ var ModelFormatSchema$1 = _enum([
16414
+ "onnx",
16415
+ "coreml",
16416
+ "openvino",
16417
+ "tflite",
16418
+ "pt",
16419
+ "gguf"
16405
16420
  ]);
16406
- var EventKindCategorySchema = _enum([
16407
- "motion",
16408
- "audio",
16409
- "detection",
16410
- "sensor",
16411
- "control",
16412
- "custom",
16413
- "package"
16421
+ var PipelineSlotSchema = _enum([
16422
+ "detector",
16423
+ "cropper",
16424
+ "classifier",
16425
+ "refiner",
16426
+ "audio-classifier"
16414
16427
  ]);
16415
- /** Taxonomy level — macro (timeline lane) vs sub (events-page leaf). */
16416
- var EventKindLevelSchema = _enum(["macro", "sub"]);
16417
- var EventKindDescriptorSchema = object({
16418
- /** Stable kind id (e.g. 'motion', 'vehicle', 'car', 'lock'). */
16419
- kind: string(),
16420
- /** i18n key resolved on the UI side; `label` is the English fallback. */
16421
- labelKey: string(),
16422
- /** English fallback label (kept for clients that don't translate). */
16423
- label: string(),
16424
- /** Hex color for timeline/legend rendering. */
16425
- color: string(),
16426
- /** Dictionary id → lucide component on the UI side. */
16427
- iconId: string(),
16428
- /** Legacy closed-vocab glyph — fallback for `iconId`. */
16429
- icon: EventKindIconSchema,
16430
- category: EventKindCategorySchema,
16431
- /** Macro parent for this kind ('car' → 'vehicle'); null for a macro. */
16432
- parentKind: string().nullable(),
16433
- /** Derived from `parentKind`, explicit for the client tree. */
16434
- level: EventKindLevelSchema,
16435
- /** Which cap + device contributes this kind. For built-ins the camera
16436
- * itself; for sensor kinds the LINKED source device. */
16437
- source: object({
16438
- capName: string(),
16439
- deviceId: number$1()
16440
- })
16428
+ var PipelineEngineChoiceSchema = object({
16429
+ runtime: _enum(["node", "python"]),
16430
+ backend: string(),
16431
+ format: ModelFormatSchema$1,
16432
+ device: string().optional()
16441
16433
  });
16442
- /** One camera's event vocabulary, as returned by `listEventKindsBatch`. */
16443
- var EventKindsForDeviceSchema = object({
16444
- deviceId: number$1(),
16445
- kinds: array(EventKindDescriptorSchema).readonly()
16434
+ var AvailableEngineSchema = object({
16435
+ engine: PipelineEngineChoiceSchema,
16436
+ devices: array(object({
16437
+ id: string(),
16438
+ label: string(),
16439
+ description: string().optional()
16440
+ })).readonly(),
16441
+ defaultDevice: string()
16446
16442
  });
16447
- var SensorEventSchema = object({
16443
+ var PipelineDefaultStepSchema = lazy(() => object({
16444
+ addonId: string(),
16445
+ addonName: string(),
16446
+ slot: PipelineSlotSchema,
16447
+ inputClasses: array(string()).readonly(),
16448
+ outputClasses: array(string()).readonly(),
16449
+ enabled: boolean(),
16450
+ modelId: string(),
16451
+ children: array(PipelineDefaultStepSchema).readonly(),
16452
+ group: string().optional(),
16453
+ settings: record(string(), unknown()).optional()
16454
+ }));
16455
+ var PipelineTemplateStepSchema = lazy(() => object({
16456
+ addonId: string(),
16457
+ enabled: boolean(),
16458
+ modelId: string(),
16459
+ children: array(PipelineTemplateStepSchema).readonly(),
16460
+ settings: record(string(), unknown()).optional()
16461
+ }));
16462
+ var PipelineTemplateSchema$1 = object({
16448
16463
  id: string(),
16449
- /** The CAMERA the event is attributed to (a sensor linked to N cameras
16450
- * yields N rows, one per camera). */
16451
- deviceId: number$1(),
16452
- /** The linked sensor device whose state changed. */
16453
- sourceDeviceId: number$1(),
16454
- /** Event kind id — matches an `EventKindDescriptor.kind`. */
16455
- kind: string(),
16456
- /** Snapshot of the sensor cap's runtime-state slice at the change. */
16457
- value: record(string(), unknown()).nullable(),
16458
- timestamp: number$1()
16464
+ name: string(),
16465
+ createdAt: string(),
16466
+ updatedAt: string(),
16467
+ engine: PipelineEngineChoiceSchema,
16468
+ steps: array(PipelineTemplateStepSchema).readonly()
16459
16469
  });
16460
- var TrackPositionSchema = object({
16461
- x: number$1(),
16462
- y: number$1(),
16463
- timestamp: number$1(),
16464
- bbox: BoundingBoxSchema
16470
+ var PipelineModelOptionSchema = object({
16471
+ id: string(),
16472
+ name: string(),
16473
+ formats: record(string(), object({
16474
+ downloaded: boolean(),
16475
+ sizeMB: number$1()
16476
+ })),
16477
+ group: ModelVariantGroupSchema.optional(),
16478
+ legacy: boolean().optional(),
16479
+ provider: ModelProviderIdSchema.optional()
16465
16480
  });
16466
- var TrackSnapshotSchema = object({
16467
- timestamp: number$1(),
16468
- position: TrackPositionSchema,
16469
- /** MediaStore key; resolve via `getTrackMedia({ trackId })`. */
16470
- mediaKey: string()
16481
+ var ConfigFieldBridge = custom();
16482
+ var PipelineAddonSchemaSchema = object({
16483
+ id: string(),
16484
+ name: string(),
16485
+ slot: PipelineSlotSchema,
16486
+ inputClasses: array(string()).readonly(),
16487
+ outputClasses: array(string()).readonly(),
16488
+ childSlots: array(PipelineSlotSchema).readonly(),
16489
+ models: array(PipelineModelOptionSchema).readonly(),
16490
+ defaultModelId: string(),
16491
+ defaultModelIdByFormat: record(string(), string()).optional(),
16492
+ enabledByDefault: boolean().optional(),
16493
+ backfillIntoExistingOverrides: boolean().optional(),
16494
+ defaultConfidence: number$1(),
16495
+ group: string().optional(),
16496
+ configSchema: array(ConfigFieldBridge).readonly().optional()
16471
16497
  });
16472
- /**
16473
- * Normalized 0..1 trajectory envelope (min/max over every position bbox,
16474
- * divided by the track's detection-frame dims), computed at persist time.
16475
- * Absent when the frame dims were unknown when the track was persisted
16476
- * (legacy rows / dims-less sources) and on active (in-RAM) tracks.
16477
- */
16478
- var TrackEnvelopeSchema = object({
16479
- minX: number$1(),
16480
- minY: number$1(),
16481
- maxX: number$1(),
16482
- maxY: number$1()
16498
+ var PipelineSlotSchemaSchema = object({
16499
+ id: PipelineSlotSchema,
16500
+ label: string(),
16501
+ priority: number$1(),
16502
+ parentSlot: PipelineSlotSchema.nullable(),
16503
+ addons: array(PipelineAddonSchemaSchema).readonly()
16483
16504
  });
16484
- /**
16485
- * Row projection for track list queries. `full` (default) returns the
16486
- * complete Track including the frame-rate `positions[]` history and the
16487
- * `snapshots[]` references — megabytes across a page of tracks. `slim`
16488
- * keeps every scalar the list surfaces actually render (ids, class(es),
16489
- * label / audioLabels / importance enrichment, firstSeen/lastSeen, state,
16490
- * zonesVisited, bestEventId, envelope, hasFace, hasEmbeddedFace, hasRider) and returns `positions` /
16491
- * `snapshots` as EMPTY arrays — detail views re-fetch the full row via
16492
- * `getTrack`. Mirrors the event-store `projection` convention
16493
- * (`getObjectEvents` et al.).
16494
- */
16495
- var TrackProjectionSchema = _enum(["full", "slim"]);
16496
- /**
16497
- * One audio-classification label heard on the track's camera while the
16498
- * track was alive, aggregated per label. An "episode" is one persisted
16499
- * audio event (the confident-classification path: score ≥ the device's
16500
- * `classificationMinScore`, class-change-or-heartbeat coalesced) — NOT
16501
- * one 32 ms inference chunk, so counts stay human-scaled.
16502
- */
16503
- var TrackAudioLabelSchema = object({
16504
- label: string(),
16505
- /** Highest classification score observed across the label's episodes. */
16506
- peakScore: number$1(),
16507
- /** Number of coalesced audio-event episodes carrying this label. */
16508
- count: number$1(),
16509
- firstAt: number$1(),
16510
- lastAt: number$1()
16505
+ var PipelineSchemaSchema = object({
16506
+ availableEngines: array(AvailableEngineSchema).readonly(),
16507
+ selectedEngine: PipelineEngineChoiceSchema,
16508
+ slots: array(PipelineSlotSchemaSchema).readonly()
16511
16509
  });
16512
- /**
16513
- * How a track was produced. `pipeline` (default / absent) = the spatial
16514
- * detection+tracking pipeline. Every OTHER value is a SYNTHETIC projection —
16515
- * no positions, a single snapshot, and no bbox trajectory at all:
16516
- *
16517
- * - `sensor` — a linked sensor/control device state change.
16518
- * - `audio` — an audio event on the camera itself that was anomalous for
16519
- * THAT camera, loud, and heard while nothing visual was happening (D62).
16520
- *
16521
- * The spatial subsystems (tracker association, occupancy count, re-id /
16522
- * embedding, resurrection) MUST skip every synthetic source. Test for that
16523
- * with `isSpatialTrack`, which allow-lists `pipeline` — a `!== 'sensor'`
16524
- * check silently readmits every source added after it was written.
16525
- */
16526
- var TrackSourceSchema = _enum([
16527
- "pipeline",
16528
- "sensor",
16529
- "audio"
16530
- ]);
16531
- /**
16532
- * Where a track sits in the RETRAIN lifecycle (D81).
16533
- *
16534
- * - `none` — never marked, or un-marked. Evictable.
16535
- * - `staging` — the operator wants this track as training material and has not
16536
- * finished with it. **This is the only state retention holds**: the track and
16537
- * everything it owns (object events, crops, keyframes, CLIP vector) survive
16538
- * the device's age window.
16539
- * - `trained` — the retrain page has taken what it needed. The frames it chose
16540
- * were COPIED into the retrain dataset at selection time, so the dataset no
16541
- * longer depends on the track's media and the track becomes EVICTABLE again.
16542
- * Terminal for the plain `markForTrain` toggle: returning it to `staging` is
16543
- * a deliberate action of the retrain page, not a side effect of a checkbox.
16544
- *
16545
- * There is no `null`. The state is stored `TEXT NOT NULL DEFAULT 'none'` because
16546
- * the store's filter language has only positive equality and `whereIn` — no
16547
- * negation, no IS NULL — so a NULL would be unselectable by ANY predicate and
16548
- * would make the entire pre-column history immortal in one deploy.
16549
- */
16550
- var RetrainStatusSchema = _enum([
16551
- "none",
16552
- "staging",
16553
- "trained"
16554
- ]);
16555
- /**
16556
- * Per-track OPERATOR flags — set by hand from the admin UI or the viewer, never
16557
- * by the pipeline. Spread into `TrackSchema` and `KeyEventSchema` from one place
16558
- * so the two surfaces cannot drift.
16559
- *
16560
- * **Absent ≠ false.** A track that has never been touched omits the field; an
16561
- * explicitly un-flagged track carries `false`. Legacy rows written before the
16562
- * columns existed read as absent, and a consumer that needs a boolean should say
16563
- * `flag === true`, not `flag !== false`.
16564
- *
16565
- * `markForTrain` is the WIRE FACE of {@link RetrainStatusSchema}, not a column:
16566
- * it is exactly `retrainStatus === 'staging'`, in both directions. Writing
16567
- * `true` moves `none → staging`, writing `false` moves `staging → none`, and a
16568
- * `trained` track reports `false` while refusing both writes. The boolean is
16569
- * kept because three surfaces drive a toggle off it; anything that needs to tell
16570
- * "never marked" from "already trained" must read `retrainStatus`.
16571
- *
16572
- * `debug` does NOT pin; it is attention, not durability.
16573
- *
16574
- * `favourited` IS a BOOLEAN pin (durability bit), not a retrain lifecycle.
16575
- * A favourited track is skipped by retention the same way `staging` is, but
16576
- * it does not enter `none|staging|trained` and has no staging budget.
16577
- */
16578
- var TrackFlagFields = {
16579
- /** Operator marked this track as training material — i.e. `retrainStatus` is
16580
- * `'staging'`. */
16581
- markForTrain: boolean().optional(),
16582
- /** Operator marked this track for diagnostic attention. */
16583
- debug: boolean().optional(),
16584
- /** Operator favourited this track. Pins it against pruning. */
16585
- favourited: boolean().optional()
16586
- };
16587
- /**
16588
- * The lifecycle field itself, on the READ surfaces only (`Track`, `KeyEvent`).
16589
- * Deliberately NOT part of {@link TrackFlagFields}: that group also builds the
16590
- * write patch, and the status is not something the toggle sets — it is what the
16591
- * toggle's boolean is derived from. Absent on an in-RAM track never touched;
16592
- * always present on a persisted row (the column default materialises `'none'`).
16593
- */
16594
- var TrackRetrainFields = { retrainStatus: RetrainStatusSchema.optional() };
16595
- /**
16596
- * The write half: a PARTIAL patch. An omitted key is left untouched, so setting
16597
- * one flag can never clear the other — the toggles are independent and are
16598
- * driven from three surfaces that do not know about each other.
16599
- */
16600
- var TrackFlagsPatchSchema = object(TrackFlagFields);
16601
- /**
16602
- * The resolved flag state after a write. Both fields are REQUIRED here (absent
16603
- * collapses to `false`) so a caller can drive a toggle's checked state off the
16604
- * mutation result without a re-fetch.
16605
- */
16606
- var TrackFlagsSchema = object({
16607
- trackId: string(),
16608
- markForTrain: boolean(),
16609
- debug: boolean(),
16610
- favourited: boolean(),
16611
- /** The lifecycle state the boolean was derived from. Required here (unlike on
16612
- * a track row) because this shape is only ever produced by the write body,
16613
- * which always knows it — and a surface that has just written needs to render
16614
- * `trained` without a re-fetch. */
16615
- retrainStatus: RetrainStatusSchema
16510
+ var EngineProvisioningSchema = object({
16511
+ runtimeId: _enum([
16512
+ "onnx",
16513
+ "openvino",
16514
+ "coreml",
16515
+ "edgetpu"
16516
+ ]).nullable(),
16517
+ device: string().nullable(),
16518
+ state: _enum([
16519
+ "idle",
16520
+ "installing",
16521
+ "verifying",
16522
+ "ready",
16523
+ "failed"
16524
+ ]),
16525
+ progress: number$1().optional(),
16526
+ error: string().optional(),
16527
+ nextRetryAt: number$1().optional(),
16528
+ /**
16529
+ * Gate A (config-correctness gate at engine change): human-readable
16530
+ * config issues surfaced EAGERLY when the node's engine changes — model
16531
+ * substitutions ("chose X, running Y") and zero-build steps ("no model
16532
+ * has a <format> build"). Additive/optional: informational only, never
16533
+ * enforced here — `assertEngineReady` (readiness) still gates inference.
16534
+ * Absent/empty when the node-default tree resolves cleanly.
16535
+ */
16536
+ configIssues: array(string()).optional()
16616
16537
  });
16617
- union([literal(1), literal(2)]);
16618
- /**
16619
- * WHO decided a label, and when. Carried per tier so a value can be traced to
16620
- * the step and model that produced it — which is what makes the write rule
16621
- * arguable after the fact ("why is 592's label `dog` and not `Canis lupus`?")
16622
- * and what lets a migrated, UNATTRIBUTED value be told apart from a real one.
16623
- *
16624
- * `stepId` is the pipeline step id (`animal-classifier`, `bird-classifier`,
16625
- * `plate-ocr`, `face-embedding`, `object-detection`), or the sentinel
16626
- * `migration:4g` for a value the 4g migration moved from the single-slot era —
16627
- * that value has no provenance, and the write rule lets ANY properly-attributed
16628
- * write of the same tier replace it regardless of score.
16629
- */
16630
- var LabelAttributionSchema = object({
16631
- stepId: string(),
16538
+ var PipelineStepInputSchema = lazy(() => object({
16539
+ addonId: string(),
16632
16540
  modelId: string().optional(),
16633
- decidedAt: number$1(),
16541
+ enabled: boolean().default(true),
16542
+ children: array(PipelineStepInputSchema).optional(),
16543
+ settings: record(string(), unknown()).optional(),
16544
+ jumpDeviceKey: string().optional()
16545
+ }));
16546
+ var ModelSubstitutionSchema = object({
16547
+ addonId: string(),
16548
+ chosen: string(),
16549
+ running: string(),
16550
+ format: string()
16551
+ });
16552
+ var PipelineValidationIssueSchema = object({
16553
+ addonId: string(),
16554
+ kind: _enum(["unknown-addon", "no-format-build"]),
16555
+ detail: string()
16556
+ });
16557
+ var PipelineValidationResultSchema = object({
16558
+ ok: boolean(),
16559
+ issues: array(PipelineValidationIssueSchema).readonly(),
16560
+ substitutions: array(ModelSubstitutionSchema).readonly(),
16561
+ /** The node's `currentEngine.format` this validation ran against. */
16562
+ format: string()
16563
+ });
16564
+ var ReferenceImageEntrySchema = object({
16565
+ filename: string(),
16566
+ stepIds: array(string()).readonly().optional()
16567
+ });
16568
+ var ReferenceImageBodySchema = object({
16569
+ base64: string(),
16570
+ filename: string()
16571
+ });
16572
+ var ReferenceAudioEntrySchema = object({
16573
+ filename: string(),
16574
+ sizeKb: number$1()
16575
+ });
16576
+ var ReferenceAudioBodySchema = object({ base64: string() });
16577
+ var AudioBackendSchema = object({
16578
+ id: string(),
16579
+ name: string(),
16580
+ description: string(),
16581
+ available: boolean(),
16634
16582
  /**
16635
- * The GALLERY id behind a recognised tier-2 label — a face-gallery
16636
- * `Identity.id` or a plate-gallery `Vehicle.id` (both `randomUUID`).
16637
- *
16638
- * The text alone is a DISPLAY NAME, and a display name is renameable: a
16639
- * notification rule authored on "Gianluca" stopped matching the moment the
16640
- * operator fixed the spelling in the gallery, and nothing said so. The id is
16641
- * the thing that does not move, so it is what a rule matches on
16642
- * (`NcConditions.identities`) and the text is what a human is shown.
16643
- *
16644
- * Absent when the label names no gallery row — a plate the OCR read but no
16645
- * vehicle claims, a sub-class, a species, any tier-1 value.
16583
+ * Raw classifier labels this backend can emit (e.g. YAMNet's
16584
+ * 521-class set or Apple SoundAnalysis's 303-class set). Used by
16585
+ * the benchmark UI to populate the `enabledMicroClasses` filter
16586
+ * specific to the selected backend without a separate fetch.
16646
16587
  */
16647
- identityId: string().optional()
16588
+ rawLabels: array(string()).readonly().optional()
16589
+ });
16590
+ var AudioCapabilitiesSchema = object({
16591
+ activeBackend: string(),
16592
+ availableBackends: array(AudioBackendSchema).readonly(),
16593
+ sampleRate: number$1(),
16594
+ chunkDurationMs: number$1()
16595
+ });
16596
+ var DownloadModelResultSchema = object({
16597
+ filePath: string(),
16598
+ sizeMB: number$1(),
16599
+ durationMs: number$1()
16648
16600
  });
16649
16601
  /**
16650
- * The TIERED label model (roadmap 4g), spread into `TrackSchema` and
16651
- * `ObjectEventSchema` from ONE place so the two surfaces cannot drift — a
16652
- * track and its events always answer the same question the same way.
16653
- *
16654
- * Two scalar columns, not an array: every consumer wants "the coarse one" or
16655
- * "the fine one", and an array made both a scan. `label` is tier 1, `subLabel`
16656
- * is tier 2, and each carries its own score + attribution.
16657
- *
16658
- * **Reading it.** What a human should be shown is `subLabel ?? label` — the
16659
- * finest thing known. Before 4g the single `label` column held the finest
16660
- * value, so a consumer that has not been updated reads the tier-1 slot and
16661
- * shows nothing on a species-only row; that is why the migration puts every
16662
- * pre-4g value in tier 2 (it cannot regress a display that reads the fallback)
16663
- * and why the read surfaces were changed in the same train.
16664
- *
16665
- * **Writing it.** The slots are independent, which is the whole point: a
16666
- * tier-1 write (`bird`) can never overwrite a tier-2 value (`Turdus
16667
- * migratorius`), so fineness cannot regress by construction. Within a tier the
16668
- * higher score wins. One rule, one implementation — see
16669
- * `pipeline/label-tier.ts` in addon-post-analysis.
16670
- */
16671
- var TieredLabelFields = {
16672
- /** Tier 1 — the sub-class. See {@link LabelTierSchema}. */
16673
- label: string().optional(),
16674
- /** Confidence of the tier-1 value, as reported by the deciding step. */
16675
- labelScore: number$1().optional(),
16676
- /** Provenance of the tier-1 value. See {@link LabelAttributionSchema}. */
16677
- labelMeta: LabelAttributionSchema.optional(),
16678
- /** Tier 2 — the instance. See {@link LabelTierSchema}. */
16679
- subLabel: string().optional(),
16680
- /** Confidence of the tier-2 value, as reported by the deciding step. */
16681
- subLabelScore: number$1().optional(),
16682
- /** Provenance of the tier-2 value. See {@link LabelAttributionSchema}. */
16683
- subLabelMeta: LabelAttributionSchema.optional()
16684
- };
16685
- /** Per-camera slice of a training-export estimate. */
16686
- var TrainingExportDeviceTotalsSchema = object({
16687
- deviceId: number$1(),
16688
- tracks: number$1().int(),
16689
- files: number$1().int(),
16690
- bytes: number$1().int()
16691
- });
16692
- /**
16693
- * What a training export WOULD contain. Computed from media index rows only —
16694
- * no blob is read to produce this.
16602
+ * Wrapper carrying a single test run's result. Replaces the legacy
16603
+ * ad-hoc `{labels: [{className, originalClass, score}]}` shape with the
16604
+ * canonical `AudioResult` from the Phase 6 output rework: one
16605
+ * `AudioDetection` per class above `minScore`, top-N candidates in
16606
+ * `debug.alternateLabels['audio-classifier']`, per-source timings in
16607
+ * `debug.stepTimings`. The outer `success`/`error` fields stay so the
16608
+ * benchmark UI can still report a clean failure when the classifier
16609
+ * cap isn't available.
16695
16610
  */
16696
- var TrainingExportSummarySchema = object({
16697
- generatedAt: number$1(),
16698
- trackCount: number$1().int(),
16699
- fileCount: number$1().int(),
16700
- byteCount: number$1().int(),
16701
- /** More marked tracks exist than a single pass carries. */
16702
- truncated: boolean(),
16703
- devices: array(TrainingExportDeviceTotalsSchema).readonly()
16611
+ var AudioTestResultSchema = object({
16612
+ success: boolean(),
16613
+ error: string().optional(),
16614
+ frame: custom().optional()
16704
16615
  });
16705
- var TrackSchema = object({
16706
- trackId: string(),
16707
- deviceId: number$1(),
16708
- className: string(),
16709
- ...TieredLabelFields,
16710
- producingDeviceName: string().optional(),
16711
- /** Track provenance. Absent ⇒ `pipeline` (legacy rows). */
16712
- source: TrackSourceSchema.optional(),
16713
- firstSeen: number$1(),
16714
- lastSeen: number$1(),
16715
- /** Frame-rate position history (subject to maxPositionHistory cap). */
16716
- positions: array(TrackPositionSchema).readonly(),
16717
- /** Periodic snapshots at snapshotIntervalMs cadence (subject to
16718
- * saveThumbnails policy). */
16719
- snapshots: array(TrackSnapshotSchema).readonly(),
16720
- /** Deduplicated zones the track has entered at least once. Zone IDS. */
16721
- zonesVisited: array(string()).readonly(),
16616
+ var PipelineConfigBridge = custom();
16617
+ var ConfigUISchemaBridge = custom();
16618
+ var ConfigUISchemaNullableBridge = custom();
16619
+ var InferenceCapabilitiesBridge = custom();
16620
+ var ModelAvailabilityListBridge = custom();
16621
+ var PipelineRunResultBridge = custom();
16622
+ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngineChoiceSchema), method(PipelineEngineChoiceSchema, array(PipelineDefaultStepSchema)), method(object({ nodeId: string() }), EngineProvisioningSchema), method(_void(), record(string(), object({
16623
+ modelId: string(),
16624
+ settings: record(string(), unknown()).readonly()
16625
+ }))), method(object({ steps: record(string(), object({
16626
+ modelId: string(),
16627
+ settings: record(string(), unknown()).readonly()
16628
+ })) }), object({ success: literal(true) }), {
16629
+ kind: "mutation",
16630
+ auth: "admin"
16631
+ }), method(object({ nodeId: string() }), object({
16632
+ success: literal(true),
16633
+ clearedDevices: number$1()
16634
+ }), {
16635
+ kind: "mutation",
16636
+ auth: "admin"
16637
+ }), method(object({ nodeId: string() }), object({ unhealthy: array(object({
16638
+ /** `<backend>:<device>`, e.g. `openvino:gpu`. */
16639
+ deviceKey: string(),
16722
16640
  /**
16723
- * Human NAMES for {@link zonesVisited}, resolved at READ time against the
16724
- * `zones` capability.
16725
- *
16726
- * `zonesVisited` persists ids (`cfeec78c-8d69-…`), which no operator can type
16727
- * and no card can render — so every free-text search surface was structurally
16728
- * unable to answer "show me the tracks in Uscio", and did not fail loudly, it
16729
- * just returned nothing. Resolving here rather than in each client keeps ONE
16730
- * derivation and costs the clients no extra call (the `zones` cap is
16731
- * per-device, so a client-side resolve would be a per-camera fan-out on a
16732
- * surface built to avoid exactly that).
16733
- *
16734
- * Resolved, never invented: a zone deleted since the track was written has no
16735
- * name and is DROPPED, so this array can be shorter than `zonesVisited` — the
16736
- * two are not positionally aligned. Absent when the track visited no zone, or
16737
- * when the zone catalogue could not be read.
16641
+ * `failed` — the per-device restart budget is exhausted; no pool
16642
+ * will be spawned until an operator re-arms it or the runner
16643
+ * respawns. `backoff` — under budget, waiting out the backoff (or
16644
+ * a cached pool observed dead and not yet condemned).
16738
16645
  */
16739
- zoneNames: array(string()).readonly().optional(),
16740
- /** Deduplicated set of detector classes observed for this track over its
16741
- * life (a track may be reclassified, e.g. person→vehicle). Absent on
16742
- * legacy rows written before class accumulation shipped. */
16743
- classes: array(string()).readonly().optional(),
16744
- /** Cumulative normalized distance travelled (0..1 units = full frame width). */
16745
- totalDistance: number$1(),
16746
- state: TrackStateSchema,
16747
- active: boolean(),
16748
- /** Deterministic key-event importance score in [0,1] (server-computed at
16749
- * track expiry, recomputed on late label). Absent on legacy rows written
16750
- * before scoring shipped — consumers degrade to absence / compute-on-read. */
16751
- importance: number$1().optional(),
16752
- /** Id of the track's highest-confidence ObjectEvent (its representative
16753
- * "best" frame). Absent when the track produced no object events. */
16754
- bestEventId: string().optional(),
16755
- /** Tag of the importance sub-signal that dominated the score
16756
- * (identity|dwell|proximity|class|confidence|travel|zone). */
16757
- importanceReason: string().optional(),
16758
- /** Audio-classification labels heard on the camera during the track's
16759
- * life (score ≥ device `classificationMinScore`), aggregated per label.
16760
- * Absent on legacy rows / tracks with no confident audio. */
16761
- audioLabels: array(TrackAudioLabelSchema).readonly().optional(),
16762
- /** Normalized 0..1 trajectory envelope (see {@link TrackEnvelopeSchema}).
16763
- * Populated from the persisted envelope columns on historical reads;
16764
- * absent on legacy rows, dims-less tracks and active (in-RAM) tracks. */
16765
- envelope: TrackEnvelopeSchema.optional(),
16646
+ state: _enum(["failed", "backoff"]),
16647
+ /** Epoch ms of the death that produced this state. */
16648
+ since: number$1(),
16649
+ /** Pool deaths inside the current window. */
16650
+ deaths: number$1(),
16651
+ /** The last death's message. */
16652
+ lastError: string()
16653
+ })).readonly() })), method(object({
16654
+ nodeId: string(),
16655
+ deviceKey: string()
16656
+ }), object({ rearmed: boolean() }), {
16657
+ kind: "mutation",
16658
+ auth: "admin"
16659
+ }), 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({
16660
+ name: string(),
16661
+ steps: array(PipelineTemplateStepSchema).readonly(),
16662
+ engine: PipelineEngineChoiceSchema
16663
+ }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({
16664
+ id: string(),
16665
+ name: string().optional(),
16666
+ steps: array(PipelineTemplateStepSchema).readonly().optional()
16667
+ }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({ id: string() }), _void(), { kind: "mutation" }), method(_void(), InferenceCapabilitiesBridge), method(object({ addonId: string() }), ModelAvailabilityListBridge), method(object({
16668
+ addonId: string(),
16669
+ modelId: string(),
16670
+ format: ModelFormatSchema$1
16671
+ }), DownloadModelResultSchema, { kind: "mutation" }), method(object({
16672
+ addonId: string(),
16673
+ modelId: string(),
16674
+ format: ModelFormatSchema$1
16675
+ }), object({ success: literal(true) }), { kind: "mutation" }), method(object({
16676
+ engine: PipelineEngineChoiceSchema.optional(),
16677
+ steps: array(PipelineStepInputSchema).min(1),
16678
+ frame: FrameInputSchema.optional(),
16766
16679
  /**
16767
- * A face DETECTOR found a face on this track — nothing more. It says the
16768
- * detail plane produced a `face` detail; it does NOT say the face was
16769
- * embedded, matched, above `minFacePx`, or that the recognizer was even
16770
- * enabled. Set once and never cleared.
16771
- *
16772
- * **This exists so "face present but not recognised" is expressible.** A
16773
- * recognised identity lands in `subLabel` (attributed to the face chain via
16774
- * `subLabelMeta.stepId`), so before this field a track with an unmatched face
16775
- * and a track with no face at all were byte-identical on the wire and no
16776
- * surface could tell them apart. The read is `hasFace === true && subLabel
16777
- * === undefined`.
16778
- *
16779
- * **Absent ≠ false.** Every row written before the column existed omits it,
16780
- * and so does every server that predates the field — a consumer must test
16781
- * `=== true` and render nothing otherwise, never infer "no face".
16680
+ * Process-local lazy frame. Valid only when caller and provider resolve
16681
+ * in the same execution-group process; split/cross-node callers use
16682
+ * `frame`/`image` inline compatibility instead.
16782
16683
  */
16783
- hasFace: boolean().optional(),
16684
+ frameRef: FrameRefSchema.optional(),
16784
16685
  /**
16785
- * This track has a face row IN THE GALLERY: a crop **and** an embedding — a
16786
- * face an operator could ASSIGN to an identity.
16787
- *
16788
- * The STRICT twin of {@link hasFace}, and the pair only earns its keep
16789
- * because the two disagree. `hasFace` is stamped at the TOP of the face
16790
- * branch, before every gate, and means no more than "a face detector produced
16791
- * a face detail". This one is stamped at the single moment the gallery row
16792
- * LANDS — after `FaceRecognizer.onTrackEnd` successfully persists it, i.e.
16793
- * past the embedding-magnitude verdict, the `minFacePx` detection gate, the
16794
- * candidate gate, the imageless-track drop (no crop was ever captured) and
16795
- * the crop-store drop. Everything between the detector and that insert can
16796
- * legitimately refuse the face, so a flag written any earlier promises the
16797
- * operator something to assign and delivers nothing.
16798
- *
16799
- * **Independent of recognition.** A face collected but never auto-matched is
16800
- * still assignable — it is in fact the face an operator most wants to reach —
16801
- * so this is NOT gated on `recognizedIdentityId`. Recognition lands in
16802
- * `subLabel`; this says only that the raw material exists.
16803
- *
16804
- * **Set once, never cleared.** A track that produced a gallery row produced
16805
- * one; deleting the row later is the gallery's business, not this flag's.
16806
- *
16807
- * **Absent ≠ false**, the same rule as {@link hasFace}: every row written
16808
- * before the column omits it, and so does every server that predates the
16809
- * field. A consumer must test `=== true` and render nothing otherwise —
16810
- * never infer "no assignable face".
16686
+ * CB5 shm passthrough — a `FrameHandle` naming the same ring slot
16687
+ * the decoded pixels live in. One more member of the one-of
16688
+ * frame/frameHandle/image/imageBase64/referenceImage group.
16811
16689
  */
16812
- hasEmbeddedFace: boolean().optional(),
16690
+ frameHandle: FrameHandleSchema.optional(),
16691
+ imageBase64: string().optional(),
16813
16692
  /**
16814
- * This subject CONTAINS a folded rider — a person the rider-pairing step
16815
- * ([D34](../decisions/adr-0034.md)) removed from the frame BEFORE the tracker,
16816
- * so the passage is tracked once and as a VEHICLE.
16817
- *
16818
- * It exists because the fold's record was dishonest. D34 and the code both
16819
- * said "the person is not lost — it is reported so both entities stay on the
16820
- * record"; in fact the pair went into a per-processor RAM field behind an
16821
- * accessor nobody called, and every durable surface said `vehicle`, full
16822
- * stop. This is the composition note that makes the row true.
16823
- *
16824
- * A COMPOSITION, never a class and never a label. "This vehicle contains a
16825
- * person" is not an answer to "what is this" — both label tiers would refuse
16826
- * a macro token anyway (D89), and correctly. Nothing here changes what the
16827
- * subject IS: a cyclist stays one vehicle track, occupancy still counts one,
16828
- * and a `person` rule still does not fire for someone cycling past.
16829
- *
16830
- * **Absent ≠ false**, exactly like {@link hasFace}: every row written before
16831
- * the column, and every hub that predates the field, omits it. Test
16832
- * `=== true` and render nothing otherwise — never infer "no rider".
16693
+ * Binary JPEG bytes — preferred over `imageBase64` on internal
16694
+ * hops (hub → forked worker via Moleculer MsgPack) because it
16695
+ * skips the 33% base64 overhead + the per-call base64 decode on
16696
+ * the detection-pipeline worker. Callers can pass either; exactly
16697
+ * one of `frame`/`image`/`imageBase64`/`referenceImage` is required.
16833
16698
  */
16834
- hasRider: boolean().optional(),
16835
- ...TrackFlagFields,
16836
- ...TrackRetrainFields
16837
- });
16838
- var BaseEventFields = {
16839
- id: string(),
16840
- deviceId: number$1(),
16841
- timestamp: number$1()
16842
- };
16843
- var MotionEventSchema = object({
16844
- ...BaseEventFields,
16845
- kind: literal("motion"),
16846
- regionCount: number$1(),
16847
- /** Heavy JSON array — omitted in slim projection. */
16848
- regions: array(object({
16849
- bbox: BoundingBoxSchema,
16850
- pixelCount: number$1(),
16851
- intensity: number$1()
16852
- })).readonly().optional(),
16853
- /** Omitted in slim projection. */
16854
- frameWidth: number$1().optional(),
16855
- /** Omitted in slim projection. */
16856
- frameHeight: number$1().optional(),
16857
- /** Populated by B5 (recording playback URL for this event). */
16858
- mediaUrl: string().optional()
16859
- });
16699
+ image: _instanceof(Uint8Array).optional(),
16700
+ referenceImage: string().optional(),
16701
+ deviceId: number$1().optional(),
16702
+ sessionId: string().optional(),
16703
+ /**
16704
+ * Execution plane. 'full' (default) runs the whole tree — benchmark,
16705
+ * reference-image, and detail-subtree calls. 'frame' is the live
16706
+ * per-frame dispatch: ONLY root-plane steps run; crop children
16707
+ * (inputClasses ≠ null) are skipped and served per-track via
16708
+ * pipelineRunner.runDetailSubtree (two-plane design).
16709
+ */
16710
+ plane: _enum(["full", "frame"]).optional(),
16711
+ /**
16712
+ * Inference-device selector (Phase 2 multi-device). Format
16713
+ * `<backend>:<device>` (e.g. `openvino:gpu`, `edgetpu:usb`, `cpu`).
16714
+ * Omitted ⇒ the runner's default device (current single-engine
16715
+ * behaviour). Selects WHICH device pool of the node runs the call.
16716
+ */
16717
+ deviceKey: string().optional(),
16718
+ /**
16719
+ * Two-plane NATIVE child-crop reference. Set by `runDetailSubtree` ONLY
16720
+ * when the parent crop was resolved from the frame's retained NATIVE
16721
+ * surface (a frameHandle HIT). Lets the executor re-cut a LEAF crop
16722
+ * child's ROI (plate-ocr, face-embedding, leaf classifiers) at native
16723
+ * resolution from that surface — the SAME quality path faces already
16724
+ * had — instead of the downscaled parent tile. `handle` keys the native
16725
+ * surface (node-pinned to its owner); `cropFrameSpace` is the parent
16726
+ * crop's padded/clamped rectangle in FRAME-space pixels, used to compose
16727
+ * the executor's crop-normalized child ROI back into frame-normalized
16728
+ * coordinates. Auxiliary to the image source (`image`/`frame`/…), NOT one
16729
+ * of the mutually-exclusive image inputs. Absent ⇒ tile-crop children
16730
+ * (today's behaviour on the fallback path).
16731
+ */
16732
+ nativeCropRef: NativeCropRefSchema.optional()
16733
+ }), PipelineRunResultBridge, { kind: "mutation" }), method(object({
16734
+ engine: PipelineEngineChoiceSchema.optional(),
16735
+ steps: array(PipelineStepInputSchema).min(1),
16736
+ frames: array(FrameInputSchema).min(1).max(255),
16737
+ deviceId: number$1().optional(),
16738
+ sessionId: string().optional(),
16739
+ /**
16740
+ * Pure-inference benchmark hint. A NONZERO uint32 pins every frame in
16741
+ * the batch to the Python pool's bench preprocess cache
16742
+ * (`_bench_frame_id`) so a REPEATED benchmark frame is decoded +
16743
+ * preprocessed ONCE and every later inference is a pure-inference cache
16744
+ * hit — the sustained-throughput run measures inference, not
16745
+ * decode+preprocess+infer. Omitted/0 for live frames (all different →
16746
+ * full preprocess every call, correct). Fresh per sustained run;
16747
+ * released via `uncacheFrame`.
16748
+ */
16749
+ frameId: number$1().int().nonnegative().optional(),
16750
+ /** Inference-device selector (Phase 2 multi-device); see runPipeline. */
16751
+ deviceKey: string().optional()
16752
+ }), object({ results: array(PipelineRunResultBridge).readonly() }), { kind: "mutation" }), method(object({
16753
+ data: _instanceof(Uint8Array),
16754
+ width: number$1().int().positive(),
16755
+ height: number$1().int().positive(),
16756
+ format: _enum([
16757
+ "rgb",
16758
+ "bgr",
16759
+ "gray"
16760
+ ])
16761
+ }), object({
16762
+ frameId: number$1(),
16763
+ width: number$1(),
16764
+ height: number$1()
16765
+ }), { kind: "mutation" }), method(object({
16766
+ stepId: string(),
16767
+ frameId: number$1().int()
16768
+ }), record(string(), unknown()), { kind: "mutation" }), method(object({ frameId: number$1().int() }), _void(), { kind: "mutation" }), method(_void(), object({
16769
+ batchMode: string(),
16770
+ windowMs: number$1(),
16771
+ maxBatchSize: number$1(),
16772
+ concurrency: number$1()
16773
+ })), method(_void(), array(object({
16774
+ engineKey: string(),
16775
+ engine: PipelineEngineChoiceSchema,
16776
+ modelsLoaded: array(string()).readonly(),
16777
+ inUseByCameras: array(number$1()).readonly(),
16778
+ /**
16779
+ * Origin of this resident factory.
16780
+ * - `runtime` — main camera-serving engine (no idle TTL).
16781
+ * - `warm-override` — benchmark/test override held in the warm
16782
+ * cache; auto-disposed after the idle TTL.
16783
+ * - `device-pool` — a concurrent per-device pool (Phase 2
16784
+ * multi-device, keyed by `deviceKey`) resolved
16785
+ * via `resolveDeviceFactory`. Runs alongside the
16786
+ * `runtime` engine on a DIFFERENT accelerator
16787
+ * (NPU / iGPU / Coral) — this is how the
16788
+ * Engines tab shows all pools running at once.
16789
+ */
16790
+ kind: _enum([
16791
+ "runtime",
16792
+ "warm-override",
16793
+ "device-pool"
16794
+ ]),
16795
+ /** Native pid of the underlying Python pool (null when no pool). */
16796
+ poolPid: number$1().nullable(),
16797
+ /** ms since this factory was last used (null when not warm-tracked). */
16798
+ idleMs: number$1().nullable(),
16799
+ /** Idle TTL after which `warm-override` factories self-evict (null when not applicable). */
16800
+ idleTtlMs: number$1().nullable()
16801
+ })).readonly()), method(object({ engine: PipelineEngineChoiceSchema }), object({ success: literal(true) }), {
16802
+ kind: "mutation",
16803
+ auth: "admin"
16804
+ }), method(object({
16805
+ engine: PipelineEngineChoiceSchema,
16806
+ force: boolean().optional()
16807
+ }), object({
16808
+ success: boolean(),
16809
+ reason: string().optional()
16810
+ }), {
16811
+ kind: "mutation",
16812
+ auth: "admin"
16813
+ }), 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({
16814
+ addonId: string(),
16815
+ modelId: string(),
16816
+ filename: string().optional(),
16817
+ settings: record(string(), unknown()).optional()
16818
+ }), AudioTestResultSchema, { kind: "mutation" }), method(_void(), ConfigUISchemaNullableBridge);
16860
16819
  /**
16861
- * Which detection SOURCE produced an object event. `pipeline` = the ML
16862
- * detection pipeline (decoded-frame inference); `onboard` = the camera's
16863
- * native on-device AI. Both flow through the SAME analysis layers (zoning,
16864
- * tracking, per-kind persistence) but stay distinguishable so consumers
16865
- * (advanced-notifier, occupancy, …) can select which source(s) to act on.
16866
- * Absent on legacy rows ⇒ treat as `pipeline`.
16820
+ * Per-stage gating mode applied to the zones a rule references.
16821
+ *
16822
+ * - `include`: the rule contributes to a **whitelist** for its stage.
16823
+ * When at least one `include` rule fires for a stage, only entities
16824
+ * inside one of those zones pass that stage.
16825
+ * - `exclude`: the rule contributes to a **blacklist** for its stage.
16826
+ * Entities inside one of those zones are dropped at that stage.
16827
+ *
16828
+ * `monitor`-style observation (count without filtering) is not a rule
16829
+ * mode — zones without any matching rule are observed naturally by
16830
+ * `zone-analytics` (live snapshot + history), so an "I just want to
16831
+ * count, not filter" use case needs no rule at all.
16867
16832
  */
16868
- var DetectionSourceSchema = _enum(["pipeline", "onboard"]);
16833
+ var ZoneRuleModeEnum = _enum(["include", "exclude"]);
16869
16834
  /**
16870
- * The confirmed zone crossing that produced an object event. Present ONLY on
16871
- * an event emitted BY a crossing (`zone.enter` / `zone.exit`); a movement-state
16872
- * event (`object.entering` / `leaving` / `stationary` / `loitering`) and an
16873
- * appearance event carry none, so a rule asking for a direction fails closed
16874
- * on them.
16835
+ * Per-consumer rule that references existing zones (geometry) and
16836
+ * defines how a specific pipeline stage should treat them. Each
16837
+ * consumer addon owns its own `ZoneRule[]` array in its per-device
16838
+ * settings:
16875
16839
  *
16876
- * Exactly ONE crossing per event: the emitter turns each confirmed crossing
16877
- * into its own event, so a frame in which a track enters A while leaving B
16878
- * produces two events with two directions — never one ambiguous row.
16840
+ * - `addon-motion-wasm` → `motionZoneRules: ZoneRule[]` (motion stage)
16841
+ * - `addon-detection-pipeline` → `detectionZoneRules: ZoneRule[]` (detection stage)
16842
+ * - future: notification rules, audio gating, etc.
16879
16843
  *
16880
- * `zoneId` is load-bearing for an EXIT: the event's `zones` list is the
16881
- * membership the box has NOW, and by definition it no longer contains the zone
16882
- * that was just left. Without the id here, a zone-scoped rule could never match
16883
- * the exit it asked for.
16844
+ * One rule applies to N zones (`zoneIds[]`) so the operator can
16845
+ * express "ignore motion in ALL of {garden, street}" with a single
16846
+ * rule. `classFilter` narrows the rule to specific object classes —
16847
+ * "drop person detections in the street, but keep cars" is one
16848
+ * `exclude` rule with `classFilter: ['person']`.
16849
+ *
16850
+ * `enabled` is a soft toggle — the operator can keep the rule
16851
+ * configured but inert without deleting it.
16884
16852
  */
16885
- var ZoneCrossingSchema = object({
16886
- direction: _enum(["enter", "exit"]),
16887
- /** Admin zone id crossed. */
16888
- zoneId: string(),
16889
- /** Zone display name at crossing time (falls back to the id). */
16890
- zoneName: string().optional()
16891
- });
16892
- var ObjectEventSchema = object({
16893
- ...BaseEventFields,
16894
- kind: literal("object"),
16895
- /** Detection source. Optional for backward-compat; absent ⇒ `pipeline`. */
16896
- source: DetectionSourceSchema.optional(),
16853
+ var ZoneRuleSchema = object({
16854
+ /** Stable rule id — survives edits, used by the UI for diffing. */
16855
+ id: string(),
16856
+ /** Optional human-readable label rendered in the rule editor. */
16857
+ name: string().optional(),
16858
+ /** Zones this rule targets. The rule's `mode` applies to ALL
16859
+ * listed zones (OR-set: a detection in any one of them counts).
16860
+ * At least one zone id required — a rule with no targets is a
16861
+ * configuration mistake and the form validator rejects it. */
16862
+ zoneIds: array(string()).min(1).readonly(),
16863
+ mode: ZoneRuleModeEnum,
16897
16864
  /**
16898
- * Inference-frame id shared by every object event emitted from the SAME frame
16899
- * — the "scene/parent" key. Lets a consumer group co-occurring detections (e.g.
16900
- * 2 people + 1 dog) under one full frame, and link a track's frames over time
16901
- * (group by `trackId`, pick a representative `frameId` as the parent frame).
16902
- * Optional for backward-compat with pre-existing rows / the slim projection
16903
- * includes it (it is light). Absent on rows written before this field.
16865
+ * Class names this rule applies to. Empty / undefined ⇒ rule
16866
+ * applies to every class. Class strings match the `macroClass`
16867
+ * field on detections (e.g. `person`, `car`, `dog`).
16904
16868
  */
16905
- frameId: string().optional(),
16906
- /** Omitted in slim projection. */
16907
- trackId: string().optional(),
16908
- className: string(),
16909
- ...TieredLabelFields,
16910
- /** Omitted in slim projection. */
16911
- confidence: number$1().optional(),
16912
- /** Heavy JSON — omitted in slim projection. */
16913
- bbox: BoundingBoxSchema.optional(),
16914
- /** Heavy JSON — omitted in slim projection. */
16915
- zones: array(string()).readonly().optional(),
16916
- /** Omitted in slim projection. */
16917
- state: TrackStateSchema.optional(),
16869
+ classFilter: array(string()).readonly().optional(),
16918
16870
  /**
16919
- * The zone crossing this event IS, when it is one. Absent on every other
16920
- * event kind (movement state, appearance, package) — see
16921
- * {@link ZoneCrossingSchema}. Omitted in slim projection.
16871
+ * Minimum bbox/mask overlap (0–1) with any of the rule's zones
16872
+ * required to consider an entity "in the zone". Defaults to the
16873
+ * consumer's stage default when omitted. Kept for back-compat with
16874
+ * existing per-rule overrides; new operators pick the value via
16875
+ * `bboxInclusionPct` (operator-friendly 0–100). Whichever field is
16876
+ * set, the lower-level engine reads it as a 0–1 fraction.
16922
16877
  */
16923
- zoneCrossing: ZoneCrossingSchema.optional(),
16924
- /** Detection-frame dimensions in pixels — let consumers normalize the
16925
- * pixel-space `bbox` onto a displayed image. Omitted in slim projection. */
16926
- frameWidth: number$1().optional(),
16927
- frameHeight: number$1().optional(),
16928
- /** MediaStore key for the crop attached to this event (if any). */
16929
- mediaKey: string().optional(),
16930
- /** Design B: MediaStore key of the track's native-resolution key frame (the
16931
- * best-detection full frame). Resolve via the event-media data-plane
16932
- * (`/addon/<addonId>/event-media/<keyFrameMediaKey>`) for a detail view that
16933
- * draws `bbox` over the native frame. Absent on legacy rows / non-decoded
16934
- * sources — consumers fall back to `mediaKey` (the tight crop). */
16935
- keyFrameMediaKey: string().optional(),
16936
- /** Populated by B5 (recording playback URL for this event). */
16937
- mediaUrl: string().optional(),
16938
- /** The parent track's key-event importance [0,1], propagated to every object
16939
- * event of the track (so an event row can be sorted by importance without a
16940
- * track join). Absent on legacy rows / before the track was scored. */
16941
- importance: number$1().optional()
16942
- });
16943
- var AudioEventSchema = object({
16944
- ...BaseEventFields,
16945
- kind: literal("audio"),
16946
- rms: number$1(),
16947
- dbfs: number$1(),
16948
- classification: object({
16949
- className: string(),
16950
- originalClass: string().optional(),
16951
- score: number$1()
16952
- }).optional(),
16953
- /** Populated by B5 (recording playback URL for this event). */
16954
- mediaUrl: string().optional()
16955
- });
16956
- var MediaFileKindEnum = _enum([
16957
- "crop",
16958
- "thumbnail",
16959
- "snapshot",
16960
- "firstFrame",
16961
- "lastFrame",
16962
- "fullFrame",
16963
- "fullFrameBoxed",
16964
- "faceCrop",
16965
- "plateCrop",
16966
- "keyFrame",
16967
- "keyFrameSmall",
16968
- "thumbnailSmall"
16969
- ]);
16970
- var MediaFileSchema = object({
16971
- key: string(),
16972
- kind: MediaFileKindEnum,
16973
- base64: string(),
16974
- sizeBytes: number$1(),
16975
- timestamp: number$1()
16878
+ overlapThreshold: number$1().min(0).max(1).optional(),
16879
+ /**
16880
+ * Operator-friendly version of `overlapThreshold` — the percentage
16881
+ * of the detection's bbox that must lie inside the zone for the
16882
+ * rule to match. Documented default is 85%; the engine substitutes
16883
+ * that when the field is omitted (kept optional so existing rules
16884
+ * stored without it stay valid).
16885
+ *
16886
+ * When BOTH `overlapThreshold` and `bboxInclusionPct` are set on a
16887
+ * rule, the engine prefers `bboxInclusionPct` because it's the
16888
+ * field exposed in the UI. Internally both feed the same gate.
16889
+ */
16890
+ bboxInclusionPct: number$1().min(0).max(100).optional(),
16891
+ /**
16892
+ * When `true` and a detection has a segmentation mask, use the
16893
+ * mask for overlap instead of the bbox. Detection-stage only;
16894
+ * motion rules ignore this field.
16895
+ */
16896
+ preferMask: boolean().optional(),
16897
+ /**
16898
+ * Soft-toggle: `false` disables the rule without deleting it.
16899
+ * Defaults to `true` so operators creating a rule via the UI
16900
+ * see it active immediately.
16901
+ */
16902
+ enabled: boolean().default(true)
16976
16903
  });
16904
+ array(ZoneRuleSchema).readonly();
16977
16905
  /**
16978
- * One media row WITHOUT its bytes.
16906
+ * Zone — pure geometry + identity. NO filtering behaviour.
16979
16907
  *
16980
- * A track's media is 5-8 MB of base64 (measured: 7.67 MB across 23 files for a
16981
- * 140 s track), and a client that renders tiles from the media data plane needs
16982
- * to know only WHAT EXISTS — the bytes then arrive per tile, lazily, over HTTP
16983
- * with an immutable cache, instead of all at once inside a tRPC response that
16984
- * blocks the whole view.
16908
+ * Zones describe **where** in the frame the operator wants to flag
16909
+ * something; consumer-owned {@link ZoneRule} arrays describe **how**
16910
+ * each pipeline stage uses them. Splitting the two means a single
16911
+ * polygon "Driveway" can simultaneously back a motion-exclude rule,
16912
+ * a detection-include rule on `['car']`, and an occupancy aggregate
16913
+ * — without three duplicated polygons.
16985
16914
  *
16986
- * `sizeBytes` is carried because it is what lets a client decide between the
16987
- * stored blob and a `?variant=thumb` rendering without fetching either.
16915
+ * Owned by the orchestrator addon (provider) and mirrored into the
16916
+ * `zones` device-state slice on every mutation. Consumers
16917
+ * (motion-wasm, pipeline-executor, analytics, admin UI) read either
16918
+ * via `api.zones.listZones` (one-shot) or via `dev.state.zones` (live
16919
+ * mirror with `onChanged`).
16920
+ *
16921
+ * Coordinates are normalised fractions of the frame (0–1) so zones
16922
+ * survive resolution changes and stream profile switches.
16923
+ *
16924
+ * `kind` discriminates between full polygons (closed regions used
16925
+ * for intrusion / occupancy filters) and tripwires (open 2-point
16926
+ * line segments used for cross events). Onboard / firmware-reported
16927
+ * zones (Reolink, ONVIF) are out of scope for now — see the deferred
16928
+ * task list.
16988
16929
  */
16989
- var MediaFileInfoSchema = MediaFileSchema.omit({ base64: true });
16930
+ var ZoneKindEnum = _enum(["polygon", "tripwire"]);
16931
+ /** Polygon vertex in fraction-of-frame coordinates (0–1). */
16932
+ var PolygonPointSchema = object({
16933
+ x: number$1(),
16934
+ y: number$1()
16935
+ });
16936
+ /** A camera detection zone — pure geometry/identity. */
16937
+ var ZoneSchema = object({
16938
+ id: string(),
16939
+ name: string(),
16940
+ kind: ZoneKindEnum.default("polygon"),
16941
+ /** Polygon vertices, fraction of frame (0–1). */
16942
+ polygon: array(PolygonPointSchema).readonly(),
16943
+ /** Visual color for UI rendering. */
16944
+ color: string().default("#3b82f6")
16945
+ });
16946
+ DeviceType.Camera, method(object({ deviceId: number$1() }), array(ZoneSchema).readonly()), method(object({
16947
+ deviceId: number$1(),
16948
+ zone: ZoneSchema
16949
+ }), _void(), {
16950
+ kind: "mutation",
16951
+ auth: "admin"
16952
+ }), method(object({
16953
+ deviceId: number$1(),
16954
+ zoneId: string()
16955
+ }), _void(), {
16956
+ kind: "mutation",
16957
+ auth: "admin"
16958
+ }), method(object({
16959
+ deviceId: number$1(),
16960
+ zone: ZoneSchema
16961
+ }), _void(), {
16962
+ kind: "mutation",
16963
+ auth: "admin"
16964
+ }), object({ zones: array(ZoneSchema).readonly() });
16990
16965
  /**
16991
- * The MACRO tier of an annotation — a CLOSED set.
16966
+ * pipeline-analytics — device-scoped wrapper cap. Refines raw
16967
+ * per-frame detections emitted by the pipeline runner into tracked
16968
+ * objects, per-kind event collections (motion / object / audio), and
16969
+ * persisted media. Owns the post-detection domain end-to-end:
16992
16970
  *
16993
- * This is what the exported detector predicts, so a typo here is a new class
16994
- * with one example in it. `label` and `subLabel` are open strings by contrast:
16995
- * the whole point of the page is teaching the model things it does not know
16996
- * yet, and constraining that vocabulary would make it useless.
16971
+ * runner emits PipelineInferenceResult
16972
+ * ↓ (event bus)
16973
+ * pipeline-analytics subscriber
16974
+ * ↓ SORT tracker + zone engine + state analyzer + event emitter
16975
+ * → three DB collections (one per kind), one FS media tree, one
16976
+ * unified event emitter (FrameTracked + TrackStarted/Ended +
16977
+ * DetectionEvent on bus)
16997
16978
  *
16998
- * A macro class is NEVER a label. The provider refuses a write whose `label` or
16999
- * `subLabel` is one of these values, in any casing, because once `person`
17000
- * exists in both tiers "every person box" stops being answerable without
17001
- * knowing every string anyone ever typed — and the damage is retroactive.
16979
+ * Pure subscriber model. No `processFrame` cap method — the runner
16980
+ * already publishes the raw frame on the bus. The cap surface is
16981
+ * only QUERIES + per-device settings, bound on/off via
16982
+ * `device-manager.setWrapperActive`. `defaultActive: true` because
16983
+ * every camera with a detection pipeline wants its raw detections
16984
+ * refined; operators opt out per-device via BindingsTab when needed.
16985
+ *
16986
+ * Replaces the legacy `analysis-pipeline`, `analysis-data-persistence`
16987
+ * (per-device surface) and `track-trail` caps — see P11 cleanup.
17002
16988
  */
17003
- var RetrainMacroClassSchema = _enum([
16989
+ var TrackStateSchema = _enum([
16990
+ "new",
16991
+ "entered",
16992
+ "left",
16993
+ "moving",
16994
+ "idle"
16995
+ ]);
16996
+ var EventKindSchema = _enum([
16997
+ "motion",
16998
+ "object",
16999
+ "audio"
17000
+ ]);
17001
+ /**
17002
+ * Spatial filter for `listTracks` — the rect + polygon variants of the shared
17003
+ * MaskShape vocabulary (see `mask-shape.ts`). Coordinates are NORMALIZED 0..1
17004
+ * of the camera frame (top-left origin), matching the drawing-plane editor.
17005
+ */
17006
+ var TrackZoneFilterSchema = discriminatedUnion("kind", [MaskRectShapeSchema, MaskPolygonShapeSchema]);
17007
+ /** Closed icon vocabulary so clients render a known glyph per kind. */
17008
+ var EventKindIconSchema = _enum([
17009
+ "motion",
17010
+ "audio",
17004
17011
  "person",
17005
17012
  "vehicle",
17006
17013
  "animal",
17014
+ "door",
17015
+ "pir",
17016
+ "smoke",
17017
+ "water",
17018
+ "button",
17007
17019
  "package",
17008
- "face",
17009
- "plate"
17020
+ "generic"
17010
17021
  ]);
17011
- /** A subject to learn, or a phantom to unlearn (taught by OMISSION). */
17012
- var RetrainAnnotationKindSchema = _enum(["subject", "model_error"]);
17013
- /** Did a human draw this box, or did the assist propose it? */
17014
- var RetrainAnnotationSourceSchema = _enum(["operator", "assist"]);
17015
- /** Normalised `[0,1]` rectangle against the FULL frame — the canonical form. */
17016
- var RetrainBboxSchema = object({
17022
+ var EventKindCategorySchema = _enum([
17023
+ "motion",
17024
+ "audio",
17025
+ "detection",
17026
+ "sensor",
17027
+ "control",
17028
+ "custom",
17029
+ "package"
17030
+ ]);
17031
+ /** Taxonomy level — macro (timeline lane) vs sub (events-page leaf). */
17032
+ var EventKindLevelSchema = _enum(["macro", "sub"]);
17033
+ var EventKindDescriptorSchema = object({
17034
+ /** Stable kind id (e.g. 'motion', 'vehicle', 'car', 'lock'). */
17035
+ kind: string(),
17036
+ /** i18n key resolved on the UI side; `label` is the English fallback. */
17037
+ labelKey: string(),
17038
+ /** English fallback label (kept for clients that don't translate). */
17039
+ label: string(),
17040
+ /** Hex color for timeline/legend rendering. */
17041
+ color: string(),
17042
+ /** Dictionary id → lucide component on the UI side. */
17043
+ iconId: string(),
17044
+ /** Legacy closed-vocab glyph — fallback for `iconId`. */
17045
+ icon: EventKindIconSchema,
17046
+ category: EventKindCategorySchema,
17047
+ /** Macro parent for this kind ('car' → 'vehicle'); null for a macro. */
17048
+ parentKind: string().nullable(),
17049
+ /** Derived from `parentKind`, explicit for the client tree. */
17050
+ level: EventKindLevelSchema,
17051
+ /** Which cap + device contributes this kind. For built-ins the camera
17052
+ * itself; for sensor kinds the LINKED source device. */
17053
+ source: object({
17054
+ capName: string(),
17055
+ deviceId: number$1()
17056
+ })
17057
+ });
17058
+ /** One camera's event vocabulary, as returned by `listEventKindsBatch`. */
17059
+ var EventKindsForDeviceSchema = object({
17060
+ deviceId: number$1(),
17061
+ kinds: array(EventKindDescriptorSchema).readonly()
17062
+ });
17063
+ var SensorEventSchema = object({
17064
+ id: string(),
17065
+ /** The CAMERA the event is attributed to (a sensor linked to N cameras
17066
+ * yields N rows, one per camera). */
17067
+ deviceId: number$1(),
17068
+ /** The linked sensor device whose state changed. */
17069
+ sourceDeviceId: number$1(),
17070
+ /** Event kind id — matches an `EventKindDescriptor.kind`. */
17071
+ kind: string(),
17072
+ /** Snapshot of the sensor cap's runtime-state slice at the change. */
17073
+ value: record(string(), unknown()).nullable(),
17074
+ timestamp: number$1()
17075
+ });
17076
+ var TrackPositionSchema = object({
17017
17077
  x: number$1(),
17018
17078
  y: number$1(),
17019
- w: number$1(),
17020
- h: number$1()
17079
+ timestamp: number$1(),
17080
+ bbox: BoundingBoxSchema
17081
+ });
17082
+ var TrackSnapshotSchema = object({
17083
+ timestamp: number$1(),
17084
+ position: TrackPositionSchema,
17085
+ /** MediaStore key; resolve via `getTrackMedia({ trackId })`. */
17086
+ mediaKey: string()
17021
17087
  });
17022
17088
  /**
17023
- * One annotated subject.
17024
- *
17025
- * `bbox` is normalised against the full frame, ALWAYS. The per-model shapes
17026
- * (letterboxed root / zone-cropped package / subject-cropped classifier) are
17027
- * derived from it at export and never stored — storing them is how one feature
17028
- * space ends up holding two crops of the same subject (D52).
17029
- */
17030
- var RetrainAnnotationSchema = object({
17031
- id: string(),
17089
+ * Normalized 0..1 trajectory envelope (min/max over every position bbox,
17090
+ * divided by the track's detection-frame dims), computed at persist time.
17091
+ * Absent when the frame dims were unknown when the track was persisted
17092
+ * (legacy rows / dims-less sources) and on active (in-RAM) tracks.
17093
+ */
17094
+ var TrackEnvelopeSchema = object({
17095
+ minX: number$1(),
17096
+ minY: number$1(),
17097
+ maxX: number$1(),
17098
+ maxY: number$1()
17099
+ });
17100
+ /**
17101
+ * Row projection for track list queries. `full` (default) returns the
17102
+ * complete Track including the frame-rate `positions[]` history and the
17103
+ * `snapshots[]` references — megabytes across a page of tracks. `slim`
17104
+ * keeps every scalar the list surfaces actually render (ids, class(es),
17105
+ * label / audioLabels / importance enrichment, firstSeen/lastSeen, state,
17106
+ * zonesVisited, bestEventId, envelope, hasFace, hasEmbeddedFace, hasRider) and returns `positions` /
17107
+ * `snapshots` as EMPTY arrays — detail views re-fetch the full row via
17108
+ * `getTrack`. Mirrors the event-store `projection` convention
17109
+ * (`getObjectEvents` et al.).
17110
+ */
17111
+ var TrackProjectionSchema = _enum(["full", "slim"]);
17112
+ /**
17113
+ * One audio-classification label heard on the track's camera while the
17114
+ * track was alive, aggregated per label. An "episode" is one persisted
17115
+ * audio event (the confident-classification path: score ≥ the device's
17116
+ * `classificationMinScore`, class-change-or-heartbeat coalesced) — NOT
17117
+ * one 32 ms inference chunk, so counts stay human-scaled.
17118
+ */
17119
+ var TrackAudioLabelSchema = object({
17120
+ label: string(),
17121
+ /** Highest classification score observed across the label's episodes. */
17122
+ peakScore: number$1(),
17123
+ /** Number of coalesced audio-event episodes carrying this label. */
17124
+ count: number$1(),
17125
+ firstAt: number$1(),
17126
+ lastAt: number$1()
17127
+ });
17128
+ /**
17129
+ * How a track was produced. `pipeline` (default / absent) = the spatial
17130
+ * detection+tracking pipeline. Every OTHER value is a SYNTHETIC projection —
17131
+ * no positions, a single snapshot, and no bbox trajectory at all:
17132
+ *
17133
+ * - `sensor` — a linked sensor/control device state change.
17134
+ * - `audio` — an audio event on the camera itself that was anomalous for
17135
+ * THAT camera, loud, and heard while nothing visual was happening (D62).
17136
+ *
17137
+ * The spatial subsystems (tracker association, occupancy count, re-id /
17138
+ * embedding, resurrection) MUST skip every synthetic source. Test for that
17139
+ * with `isSpatialTrack`, which allow-lists `pipeline` — a `!== 'sensor'`
17140
+ * check silently readmits every source added after it was written.
17141
+ */
17142
+ var TrackSourceSchema = _enum([
17143
+ "pipeline",
17144
+ "sensor",
17145
+ "audio"
17146
+ ]);
17147
+ /**
17148
+ * Where a track sits in the RETRAIN lifecycle (D81).
17149
+ *
17150
+ * - `none` — never marked, or un-marked. Evictable.
17151
+ * - `staging` — the operator wants this track as training material and has not
17152
+ * finished with it. **This is the only state retention holds**: the track and
17153
+ * everything it owns (object events, crops, keyframes, CLIP vector) survive
17154
+ * the device's age window.
17155
+ * - `trained` — the retrain page has taken what it needed. The frames it chose
17156
+ * were COPIED into the retrain dataset at selection time, so the dataset no
17157
+ * longer depends on the track's media and the track becomes EVICTABLE again.
17158
+ * Terminal for the plain `markForTrain` toggle: returning it to `staging` is
17159
+ * a deliberate action of the retrain page, not a side effect of a checkbox.
17160
+ *
17161
+ * There is no `null`. The state is stored `TEXT NOT NULL DEFAULT 'none'` because
17162
+ * the store's filter language has only positive equality and `whereIn` — no
17163
+ * negation, no IS NULL — so a NULL would be unselectable by ANY predicate and
17164
+ * would make the entire pre-column history immortal in one deploy.
17165
+ */
17166
+ var RetrainStatusSchema = _enum([
17167
+ "none",
17168
+ "staging",
17169
+ "trained"
17170
+ ]);
17171
+ /**
17172
+ * Per-track OPERATOR flags — set by hand from the admin UI or the viewer, never
17173
+ * by the pipeline. Spread into `TrackSchema` and `KeyEventSchema` from one place
17174
+ * so the two surfaces cannot drift.
17175
+ *
17176
+ * **Absent ≠ false.** A track that has never been touched omits the field; an
17177
+ * explicitly un-flagged track carries `false`. Legacy rows written before the
17178
+ * columns existed read as absent, and a consumer that needs a boolean should say
17179
+ * `flag === true`, not `flag !== false`.
17180
+ *
17181
+ * `markForTrain` is the WIRE FACE of {@link RetrainStatusSchema}, not a column:
17182
+ * it is exactly `retrainStatus === 'staging'`, in both directions. Writing
17183
+ * `true` moves `none → staging`, writing `false` moves `staging → none`, and a
17184
+ * `trained` track reports `false` while refusing both writes. The boolean is
17185
+ * kept because three surfaces drive a toggle off it; anything that needs to tell
17186
+ * "never marked" from "already trained" must read `retrainStatus`.
17187
+ *
17188
+ * `debug` does NOT pin; it is attention, not durability.
17189
+ *
17190
+ * `favourited` IS a BOOLEAN pin (durability bit), not a retrain lifecycle.
17191
+ * A favourited track is skipped by retention the same way `staging` is, but
17192
+ * it does not enter `none|staging|trained` and has no staging budget.
17193
+ */
17194
+ var TrackFlagFields = {
17195
+ /** Operator marked this track as training material — i.e. `retrainStatus` is
17196
+ * `'staging'`. */
17197
+ markForTrain: boolean().optional(),
17198
+ /** Operator marked this track for diagnostic attention. */
17199
+ debug: boolean().optional(),
17200
+ /** Operator favourited this track. Pins it against pruning. */
17201
+ favourited: boolean().optional()
17202
+ };
17203
+ /**
17204
+ * The lifecycle field itself, on the READ surfaces only (`Track`, `KeyEvent`).
17205
+ * Deliberately NOT part of {@link TrackFlagFields}: that group also builds the
17206
+ * write patch, and the status is not something the toggle sets — it is what the
17207
+ * toggle's boolean is derived from. Absent on an in-RAM track never touched;
17208
+ * always present on a persisted row (the column default materialises `'none'`).
17209
+ */
17210
+ var TrackRetrainFields = { retrainStatus: RetrainStatusSchema.optional() };
17211
+ /**
17212
+ * The write half: a PARTIAL patch. An omitted key is left untouched, so setting
17213
+ * one flag can never clear the other — the toggles are independent and are
17214
+ * driven from three surfaces that do not know about each other.
17215
+ */
17216
+ var TrackFlagsPatchSchema = object(TrackFlagFields);
17217
+ /**
17218
+ * The resolved flag state after a write. Both fields are REQUIRED here (absent
17219
+ * collapses to `false`) so a caller can drive a toggle's checked state off the
17220
+ * mutation result without a re-fetch.
17221
+ */
17222
+ var TrackFlagsSchema = object({
17032
17223
  trackId: string(),
17033
- deviceId: number$1(),
17034
- /** The COPY in retrain storage — never the source track's media key. */
17035
- mediaKey: string(),
17036
- bbox: RetrainBboxSchema,
17037
- macroClass: RetrainMacroClassSchema,
17224
+ markForTrain: boolean(),
17225
+ debug: boolean(),
17226
+ favourited: boolean(),
17227
+ /** The lifecycle state the boolean was derived from. Required here (unlike on
17228
+ * a track row) because this shape is only ever produced by the write body,
17229
+ * which always knows it — and a surface that has just written needs to render
17230
+ * `trained` without a re-fetch. */
17231
+ retrainStatus: RetrainStatusSchema
17232
+ });
17233
+ union([literal(1), literal(2)]);
17234
+ /**
17235
+ * WHO decided a label, and when. Carried per tier so a value can be traced to
17236
+ * the step and model that produced it — which is what makes the write rule
17237
+ * arguable after the fact ("why is 592's label `dog` and not `Canis lupus`?")
17238
+ * and what lets a migrated, UNATTRIBUTED value be told apart from a real one.
17239
+ *
17240
+ * `stepId` is the pipeline step id (`animal-classifier`, `bird-classifier`,
17241
+ * `plate-ocr`, `face-embedding`, `object-detection`), or the sentinel
17242
+ * `migration:4g` for a value the 4g migration moved from the single-slot era —
17243
+ * that value has no provenance, and the write rule lets ANY properly-attributed
17244
+ * write of the same tier replace it regardless of score.
17245
+ */
17246
+ var LabelAttributionSchema = object({
17247
+ stepId: string(),
17248
+ modelId: string().optional(),
17249
+ decidedAt: number$1(),
17250
+ /**
17251
+ * The GALLERY id behind a recognised tier-2 label — a face-gallery
17252
+ * `Identity.id` or a plate-gallery `Vehicle.id` (both `randomUUID`).
17253
+ *
17254
+ * The text alone is a DISPLAY NAME, and a display name is renameable: a
17255
+ * notification rule authored on "Gianluca" stopped matching the moment the
17256
+ * operator fixed the spelling in the gallery, and nothing said so. The id is
17257
+ * the thing that does not move, so it is what a rule matches on
17258
+ * (`NcConditions.identities`) and the text is what a human is shown.
17259
+ *
17260
+ * Absent when the label names no gallery row — a plate the OCR read but no
17261
+ * vehicle claims, a sub-class, a species, any tier-1 value.
17262
+ */
17263
+ identityId: string().optional()
17264
+ });
17265
+ /**
17266
+ * The TIERED label model (roadmap 4g), spread into `TrackSchema` and
17267
+ * `ObjectEventSchema` from ONE place so the two surfaces cannot drift — a
17268
+ * track and its events always answer the same question the same way.
17269
+ *
17270
+ * Two scalar columns, not an array: every consumer wants "the coarse one" or
17271
+ * "the fine one", and an array made both a scan. `label` is tier 1, `subLabel`
17272
+ * is tier 2, and each carries its own score + attribution.
17273
+ *
17274
+ * **Reading it.** What a human should be shown is `subLabel ?? label` — the
17275
+ * finest thing known. Before 4g the single `label` column held the finest
17276
+ * value, so a consumer that has not been updated reads the tier-1 slot and
17277
+ * shows nothing on a species-only row; that is why the migration puts every
17278
+ * pre-4g value in tier 2 (it cannot regress a display that reads the fallback)
17279
+ * and why the read surfaces were changed in the same train.
17280
+ *
17281
+ * **Writing it.** The slots are independent, which is the whole point: a
17282
+ * tier-1 write (`bird`) can never overwrite a tier-2 value (`Turdus
17283
+ * migratorius`), so fineness cannot regress by construction. Within a tier the
17284
+ * higher score wins. One rule, one implementation — see
17285
+ * `pipeline/label-tier.ts` in addon-post-analysis.
17286
+ */
17287
+ var TieredLabelFields = {
17288
+ /** Tier 1 — the sub-class. See {@link LabelTierSchema}. */
17038
17289
  label: string().optional(),
17290
+ /** Confidence of the tier-1 value, as reported by the deciding step. */
17291
+ labelScore: number$1().optional(),
17292
+ /** Provenance of the tier-1 value. See {@link LabelAttributionSchema}. */
17293
+ labelMeta: LabelAttributionSchema.optional(),
17294
+ /** Tier 2 — the instance. See {@link LabelTierSchema}. */
17039
17295
  subLabel: string().optional(),
17040
- kind: RetrainAnnotationKindSchema,
17041
- source: RetrainAnnotationSourceSchema,
17042
- /** Which model proposed this box — or, on a `model_error`, drew the phantom. */
17043
- assistModelId: string().optional(),
17044
- assistScore: number$1().optional(),
17045
- exportedInBatch: string().optional(),
17046
- createdAt: number$1()
17296
+ /** Confidence of the tier-2 value, as reported by the deciding step. */
17297
+ subLabelScore: number$1().optional(),
17298
+ /** Provenance of the tier-2 value. See {@link LabelAttributionSchema}. */
17299
+ subLabelMeta: LabelAttributionSchema.optional()
17300
+ };
17301
+ /** Per-camera slice of a training-export estimate. */
17302
+ var TrainingExportDeviceTotalsSchema = object({
17303
+ deviceId: number$1(),
17304
+ tracks: number$1().int(),
17305
+ files: number$1().int(),
17306
+ bytes: number$1().int()
17047
17307
  });
17048
- /** The write form — the server owns `id`, `createdAt` and the frame binding. */
17049
- var RetrainAnnotationDraftSchema = RetrainAnnotationSchema.omit({
17050
- id: true,
17051
- trackId: true,
17052
- deviceId: true,
17053
- mediaKey: true,
17054
- createdAt: true,
17055
- exportedInBatch: true
17308
+ /**
17309
+ * What a training export WOULD contain. Computed from media index rows only —
17310
+ * no blob is read to produce this.
17311
+ */
17312
+ var TrainingExportSummarySchema = object({
17313
+ generatedAt: number$1(),
17314
+ trackCount: number$1().int(),
17315
+ fileCount: number$1().int(),
17316
+ byteCount: number$1().int(),
17317
+ /** More marked tracks exist than a single pass carries. */
17318
+ truncated: boolean(),
17319
+ devices: array(TrainingExportDeviceTotalsSchema).readonly()
17056
17320
  });
17057
- /** A track sitting in `staging`, with everything the worklist needs to rank it. */
17058
- var RetrainTrackSchema = object({
17321
+ var TrackSchema = object({
17059
17322
  trackId: string(),
17060
17323
  deviceId: number$1(),
17061
17324
  className: string(),
17062
- label: string().optional(),
17325
+ ...TieredLabelFields,
17326
+ producingDeviceName: string().optional(),
17327
+ /** Track provenance. Absent ⇒ `pipeline` (legacy rows). */
17328
+ source: TrackSourceSchema.optional(),
17063
17329
  firstSeen: number$1(),
17064
17330
  lastSeen: number$1(),
17065
- /** How many frames the dataset already holds from this track. */
17066
- frameCount: number$1().int(),
17067
- /** How many subjects have been annotated on those frames. `0` with
17068
- * `frameCount: 0` is exactly "staging, still to work". */
17069
- annotationCount: number$1().int()
17070
- });
17071
- /** A frame the picker may offer — an index row, no blob was read to produce it. */
17072
- var RetrainFrameCandidateSchema = object({
17073
- mediaKey: string(),
17074
- kind: MediaFileKindEnum,
17075
- timestamp: number$1(),
17076
- sizeBytes: number$1().int(),
17077
- /** A copy of this original already exists — selecting it is free and cannot
17078
- * fail, whatever became of the original. */
17079
- copied: boolean()
17331
+ /** Frame-rate position history (subject to maxPositionHistory cap). */
17332
+ positions: array(TrackPositionSchema).readonly(),
17333
+ /** Periodic snapshots at snapshotIntervalMs cadence (subject to
17334
+ * saveThumbnails policy). */
17335
+ snapshots: array(TrackSnapshotSchema).readonly(),
17336
+ /** Deduplicated zones the track has entered at least once. Zone IDS. */
17337
+ zonesVisited: array(string()).readonly(),
17338
+ /**
17339
+ * Human NAMES for {@link zonesVisited}, resolved at READ time against the
17340
+ * `zones` capability.
17341
+ *
17342
+ * `zonesVisited` persists ids (`cfeec78c-8d69-…`), which no operator can type
17343
+ * and no card can render — so every free-text search surface was structurally
17344
+ * unable to answer "show me the tracks in Uscio", and did not fail loudly, it
17345
+ * just returned nothing. Resolving here rather than in each client keeps ONE
17346
+ * derivation and costs the clients no extra call (the `zones` cap is
17347
+ * per-device, so a client-side resolve would be a per-camera fan-out on a
17348
+ * surface built to avoid exactly that).
17349
+ *
17350
+ * Resolved, never invented: a zone deleted since the track was written has no
17351
+ * name and is DROPPED, so this array can be shorter than `zonesVisited` — the
17352
+ * two are not positionally aligned. Absent when the track visited no zone, or
17353
+ * when the zone catalogue could not be read.
17354
+ */
17355
+ zoneNames: array(string()).readonly().optional(),
17356
+ /** Deduplicated set of detector classes observed for this track over its
17357
+ * life (a track may be reclassified, e.g. person→vehicle). Absent on
17358
+ * legacy rows written before class accumulation shipped. */
17359
+ classes: array(string()).readonly().optional(),
17360
+ /** Cumulative normalized distance travelled (0..1 units = full frame width). */
17361
+ totalDistance: number$1(),
17362
+ state: TrackStateSchema,
17363
+ active: boolean(),
17364
+ /** Deterministic key-event importance score in [0,1] (server-computed at
17365
+ * track expiry, recomputed on late label). Absent on legacy rows written
17366
+ * before scoring shipped — consumers degrade to absence / compute-on-read. */
17367
+ importance: number$1().optional(),
17368
+ /** Id of the track's highest-confidence ObjectEvent (its representative
17369
+ * "best" frame). Absent when the track produced no object events. */
17370
+ bestEventId: string().optional(),
17371
+ /** Tag of the importance sub-signal that dominated the score
17372
+ * (identity|dwell|proximity|class|confidence|travel|zone). */
17373
+ importanceReason: string().optional(),
17374
+ /** Audio-classification labels heard on the camera during the track's
17375
+ * life (score ≥ device `classificationMinScore`), aggregated per label.
17376
+ * Absent on legacy rows / tracks with no confident audio. */
17377
+ audioLabels: array(TrackAudioLabelSchema).readonly().optional(),
17378
+ /** Normalized 0..1 trajectory envelope (see {@link TrackEnvelopeSchema}).
17379
+ * Populated from the persisted envelope columns on historical reads;
17380
+ * absent on legacy rows, dims-less tracks and active (in-RAM) tracks. */
17381
+ envelope: TrackEnvelopeSchema.optional(),
17382
+ /**
17383
+ * A face DETECTOR found a face on this track — nothing more. It says the
17384
+ * detail plane produced a `face` detail; it does NOT say the face was
17385
+ * embedded, matched, above `minFacePx`, or that the recognizer was even
17386
+ * enabled. Set once and never cleared.
17387
+ *
17388
+ * **This exists so "face present but not recognised" is expressible.** A
17389
+ * recognised identity lands in `subLabel` (attributed to the face chain via
17390
+ * `subLabelMeta.stepId`), so before this field a track with an unmatched face
17391
+ * and a track with no face at all were byte-identical on the wire and no
17392
+ * surface could tell them apart. The read is `hasFace === true && subLabel
17393
+ * === undefined`.
17394
+ *
17395
+ * **Absent ≠ false.** Every row written before the column existed omits it,
17396
+ * and so does every server that predates the field — a consumer must test
17397
+ * `=== true` and render nothing otherwise, never infer "no face".
17398
+ */
17399
+ hasFace: boolean().optional(),
17400
+ /**
17401
+ * This track has a face row IN THE GALLERY: a crop **and** an embedding — a
17402
+ * face an operator could ASSIGN to an identity.
17403
+ *
17404
+ * The STRICT twin of {@link hasFace}, and the pair only earns its keep
17405
+ * because the two disagree. `hasFace` is stamped at the TOP of the face
17406
+ * branch, before every gate, and means no more than "a face detector produced
17407
+ * a face detail". This one is stamped at the single moment the gallery row
17408
+ * LANDS — after `FaceRecognizer.onTrackEnd` successfully persists it, i.e.
17409
+ * past the embedding-magnitude verdict, the `minFacePx` detection gate, the
17410
+ * candidate gate, the imageless-track drop (no crop was ever captured) and
17411
+ * the crop-store drop. Everything between the detector and that insert can
17412
+ * legitimately refuse the face, so a flag written any earlier promises the
17413
+ * operator something to assign and delivers nothing.
17414
+ *
17415
+ * **Independent of recognition.** A face collected but never auto-matched is
17416
+ * still assignable — it is in fact the face an operator most wants to reach —
17417
+ * so this is NOT gated on `recognizedIdentityId`. Recognition lands in
17418
+ * `subLabel`; this says only that the raw material exists.
17419
+ *
17420
+ * **Set once, never cleared.** A track that produced a gallery row produced
17421
+ * one; deleting the row later is the gallery's business, not this flag's.
17422
+ *
17423
+ * **Absent ≠ false**, the same rule as {@link hasFace}: every row written
17424
+ * before the column omits it, and so does every server that predates the
17425
+ * field. A consumer must test `=== true` and render nothing otherwise —
17426
+ * never infer "no assignable face".
17427
+ */
17428
+ hasEmbeddedFace: boolean().optional(),
17429
+ /**
17430
+ * This subject CONTAINS a folded rider — a person the rider-pairing step
17431
+ * ([D34](../decisions/adr-0034.md)) removed from the frame BEFORE the tracker,
17432
+ * so the passage is tracked once and as a VEHICLE.
17433
+ *
17434
+ * It exists because the fold's record was dishonest. D34 and the code both
17435
+ * said "the person is not lost — it is reported so both entities stay on the
17436
+ * record"; in fact the pair went into a per-processor RAM field behind an
17437
+ * accessor nobody called, and every durable surface said `vehicle`, full
17438
+ * stop. This is the composition note that makes the row true.
17439
+ *
17440
+ * A COMPOSITION, never a class and never a label. "This vehicle contains a
17441
+ * person" is not an answer to "what is this" — both label tiers would refuse
17442
+ * a macro token anyway (D89), and correctly. Nothing here changes what the
17443
+ * subject IS: a cyclist stays one vehicle track, occupancy still counts one,
17444
+ * and a `person` rule still does not fire for someone cycling past.
17445
+ *
17446
+ * **Absent ≠ false**, exactly like {@link hasFace}: every row written before
17447
+ * the column, and every hub that predates the field, omits it. Test
17448
+ * `=== true` and render nothing otherwise — never infer "no rider".
17449
+ */
17450
+ hasRider: boolean().optional(),
17451
+ ...TrackFlagFields,
17452
+ ...TrackRetrainFields
17080
17453
  });
17081
- /** A frame the dataset OWNS: bytes copied at selection time. */
17082
- var RetrainFrameSchema = object({
17083
- frameId: string(),
17454
+ var BaseEventFields = {
17455
+ id: string(),
17084
17456
  deviceId: number$1(),
17085
- trackId: string(),
17086
- /** Provenance only. It may already point at nothing — that is expected. */
17087
- sourceMediaKey: string(),
17088
- sourceKind: MediaFileKindEnum,
17089
- sizeBytes: number$1().int(),
17090
- width: number$1().int(),
17091
- height: number$1().int(),
17092
- copiedAt: number$1()
17093
- });
17094
- /** Why a copy-on-select could not be honoured — named, never a silent skip. */
17095
- var RetrainCopyRefusalSchema = _enum([
17096
- "source-missing",
17097
- "unreadable-image",
17098
- "write-failed"
17099
- ]);
17100
- var RetrainFrameSelectionSchema = object({
17101
- copied: array(RetrainFrameSchema).readonly(),
17102
- refused: array(object({
17103
- sourceMediaKey: string(),
17104
- reason: RetrainCopyRefusalSchema
17105
- })).readonly()
17106
- });
17107
- var RetrainFrameListSchema = object({
17108
- candidates: array(RetrainFrameCandidateSchema).readonly(),
17109
- copies: array(RetrainFrameSchema).readonly(),
17110
- /** What the page pre-selects — the native key frame when one survives. */
17111
- autoPickMediaKey: string().optional()
17457
+ timestamp: number$1()
17458
+ };
17459
+ var MotionEventSchema = object({
17460
+ ...BaseEventFields,
17461
+ kind: literal("motion"),
17462
+ regionCount: number$1(),
17463
+ /** Heavy JSON array — omitted in slim projection. */
17464
+ regions: array(object({
17465
+ bbox: BoundingBoxSchema,
17466
+ pixelCount: number$1(),
17467
+ intensity: number$1()
17468
+ })).readonly().optional(),
17469
+ /** Omitted in slim projection. */
17470
+ frameWidth: number$1().optional(),
17471
+ /** Omitted in slim projection. */
17472
+ frameHeight: number$1().optional(),
17473
+ /** Populated by B5 (recording playback URL for this event). */
17474
+ mediaUrl: string().optional()
17112
17475
  });
17113
- /** What the operator asked the assist to look for. */
17114
- var RetrainAssistSubjectSchema = discriminatedUnion("kind", [object({
17115
- kind: literal("package"),
17116
- zone: RetrainBboxSchema.optional()
17117
- }), object({
17118
- kind: literal("objects"),
17119
- modelId: string(),
17120
- minScore: number$1().optional()
17121
- })]);
17122
17476
  /**
17123
- * The assist's answer — a discriminated union, because "the model saw nothing"
17124
- * and "this node cannot run that model" lead to different next moves and a
17125
- * nullable result cannot tell them apart.
17477
+ * Which detection SOURCE produced an object event. `pipeline` = the ML
17478
+ * detection pipeline (decoded-frame inference); `onboard` = the camera's
17479
+ * native on-device AI. Both flow through the SAME analysis layers (zoning,
17480
+ * tracking, per-kind persistence) but stay distinguishable so consumers
17481
+ * (advanced-notifier, occupancy, …) can select which source(s) to act on.
17482
+ * Absent on legacy rows ⇒ treat as `pipeline`.
17126
17483
  */
17127
- var RetrainAssistResultSchema = discriminatedUnion("kind", [object({
17128
- kind: literal("proposed"),
17129
- modelId: string(),
17130
- stepId: string(),
17131
- minScore: number$1(),
17132
- /** Drafts, ready to edit. `source: 'assist'` until the operator touches one. */
17133
- proposals: array(RetrainAnnotationDraftSchema).readonly(),
17134
- /** Returned by the runner but removed by the threshold. */
17135
- belowThreshold: number$1().int()
17136
- }), object({
17137
- kind: literal("refused"),
17138
- /** `no-zone` is ours; the rest are the runner's own refusal vocabulary. */
17139
- reason: string(),
17140
- detail: string().optional()
17141
- })]);
17142
- /** The outcome of a lifecycle move owned by the retrain page. */
17143
- var RetrainTransitionResultSchema = object({
17144
- trackId: string(),
17145
- /** Where the track ended up, whatever happened. */
17146
- retrainStatus: RetrainStatusSchema,
17147
- /** `false` ⇒ the move was refused or was a no-op; `reason` says which. */
17148
- changed: boolean(),
17149
- reason: _enum([
17150
- "unknown-track",
17151
- "no-frames-copied",
17152
- "not-staging",
17153
- "not-trained",
17154
- "unchanged"
17155
- ]).optional()
17484
+ var DetectionSourceSchema = _enum(["pipeline", "onboard"]);
17485
+ /**
17486
+ * The confirmed zone crossing that produced an object event. Present ONLY on
17487
+ * an event emitted BY a crossing (`zone.enter` / `zone.exit`); a movement-state
17488
+ * event (`object.entering` / `leaving` / `stationary` / `loitering`) and an
17489
+ * appearance event carry none, so a rule asking for a direction fails closed
17490
+ * on them.
17491
+ *
17492
+ * Exactly ONE crossing per event: the emitter turns each confirmed crossing
17493
+ * into its own event, so a frame in which a track enters A while leaving B
17494
+ * produces two events with two directions — never one ambiguous row.
17495
+ *
17496
+ * `zoneId` is load-bearing for an EXIT: the event's `zones` list is the
17497
+ * membership the box has NOW, and by definition it no longer contains the zone
17498
+ * that was just left. Without the id here, a zone-scoped rule could never match
17499
+ * the exit it asked for.
17500
+ */
17501
+ var ZoneCrossingSchema = object({
17502
+ direction: _enum(["enter", "exit"]),
17503
+ /** Admin zone id crossed. */
17504
+ zoneId: string(),
17505
+ /** Zone display name at crossing time (falls back to the id). */
17506
+ zoneName: string().optional()
17156
17507
  });
17157
- var DEFAULT_EVENT_QUERY_LIMIT = 1e3;
17158
- var MAX_EVENT_QUERY_LIMIT = 5e3;
17159
- var DeviceEventQueryInput = object({
17160
- deviceId: number$1(),
17161
- since: number$1().optional(),
17162
- until: number$1().optional(),
17163
- limit: number$1().int().min(1).max(MAX_EVENT_QUERY_LIMIT).default(DEFAULT_EVENT_QUERY_LIMIT),
17164
- /** `slim` drops heavy JSON fields (regions/bbox/zones) and carries an
17165
- * optional `mediaUrl` (populated by B5). `full` (default) keeps today's
17166
- * exact behaviour. Callers may omit this field — the store defaults to
17167
- * `full` when not provided. */
17168
- projection: _enum(["full", "slim"]).optional()
17508
+ var ObjectEventSchema = object({
17509
+ ...BaseEventFields,
17510
+ kind: literal("object"),
17511
+ /** Detection source. Optional for backward-compat; absent ⇒ `pipeline`. */
17512
+ source: DetectionSourceSchema.optional(),
17513
+ /**
17514
+ * Inference-frame id shared by every object event emitted from the SAME frame
17515
+ * — the "scene/parent" key. Lets a consumer group co-occurring detections (e.g.
17516
+ * 2 people + 1 dog) under one full frame, and link a track's frames over time
17517
+ * (group by `trackId`, pick a representative `frameId` as the parent frame).
17518
+ * Optional for backward-compat with pre-existing rows / the slim projection
17519
+ * includes it (it is light). Absent on rows written before this field.
17520
+ */
17521
+ frameId: string().optional(),
17522
+ /** Omitted in slim projection. */
17523
+ trackId: string().optional(),
17524
+ className: string(),
17525
+ ...TieredLabelFields,
17526
+ /** Omitted in slim projection. */
17527
+ confidence: number$1().optional(),
17528
+ /** Heavy JSON — omitted in slim projection. */
17529
+ bbox: BoundingBoxSchema.optional(),
17530
+ /** Heavy JSON — omitted in slim projection. */
17531
+ zones: array(string()).readonly().optional(),
17532
+ /** Omitted in slim projection. */
17533
+ state: TrackStateSchema.optional(),
17534
+ /**
17535
+ * The zone crossing this event IS, when it is one. Absent on every other
17536
+ * event kind (movement state, appearance, package) — see
17537
+ * {@link ZoneCrossingSchema}. Omitted in slim projection.
17538
+ */
17539
+ zoneCrossing: ZoneCrossingSchema.optional(),
17540
+ /** Detection-frame dimensions in pixels — let consumers normalize the
17541
+ * pixel-space `bbox` onto a displayed image. Omitted in slim projection. */
17542
+ frameWidth: number$1().optional(),
17543
+ frameHeight: number$1().optional(),
17544
+ /** MediaStore key for the crop attached to this event (if any). */
17545
+ mediaKey: string().optional(),
17546
+ /** Design B: MediaStore key of the track's native-resolution key frame (the
17547
+ * best-detection full frame). Resolve via the event-media data-plane
17548
+ * (`/addon/<addonId>/event-media/<keyFrameMediaKey>`) for a detail view that
17549
+ * draws `bbox` over the native frame. Absent on legacy rows / non-decoded
17550
+ * sources — consumers fall back to `mediaKey` (the tight crop). */
17551
+ keyFrameMediaKey: string().optional(),
17552
+ /** Populated by B5 (recording playback URL for this event). */
17553
+ mediaUrl: string().optional(),
17554
+ /** The parent track's key-event importance [0,1], propagated to every object
17555
+ * event of the track (so an event row can be sorted by importance without a
17556
+ * track join). Absent on legacy rows / before the track was scored. */
17557
+ importance: number$1().optional()
17169
17558
  });
17170
- var ObjectEventQueryInput = DeviceEventQueryInput.extend({ classFilter: string().optional() });
17171
- var RecentTracksQueryInput = object({
17172
- /** Devices to merge. An empty array yields `{ tracks: [], nextCursor: null }`. */
17173
- deviceIds: array(number$1()),
17174
- /** Window lower bound on `lastSeen` (inclusive). */
17175
- since: number$1().optional(),
17176
- /** Window upper bound on `lastSeen` (inclusive). */
17177
- until: number$1().optional(),
17178
- /** Page size. Default 200, max 1000. */
17179
- limit: number$1().int().min(1).max(1e3).default(200),
17180
- /** Opaque continuation cursor from a previous page's `nextCursor`.
17181
- * Encodes the (lastSeen, trackId) sort position — treat as opaque. */
17182
- cursor: string().optional(),
17183
- /** See {@link TrackProjectionSchema}. Default `full`. */
17184
- projection: TrackProjectionSchema.optional(),
17185
- /** Include stationary-promoted rows (parked objects). Default false: the
17186
- * feed lists passages; parking records live on the stationary registry. */
17187
- includeStationary: boolean().optional()
17559
+ var AudioEventSchema = object({
17560
+ ...BaseEventFields,
17561
+ kind: literal("audio"),
17562
+ rms: number$1(),
17563
+ dbfs: number$1(),
17564
+ classification: object({
17565
+ className: string(),
17566
+ originalClass: string().optional(),
17567
+ score: number$1()
17568
+ }).optional(),
17569
+ /** Populated by B5 (recording playback URL for this event). */
17570
+ mediaUrl: string().optional()
17188
17571
  });
17189
- var RecentTracksPageSchema = object({
17190
- /** Merged page, ordered by (`lastSeen` DESC, `trackId` DESC). */
17191
- tracks: array(TrackSchema).readonly(),
17192
- /** Cursor for the next page, or null when this page is the last. */
17193
- nextCursor: string().nullable()
17572
+ var MediaFileKindEnum = _enum([
17573
+ "crop",
17574
+ "thumbnail",
17575
+ "snapshot",
17576
+ "firstFrame",
17577
+ "lastFrame",
17578
+ "fullFrame",
17579
+ "fullFrameBoxed",
17580
+ "faceCrop",
17581
+ "plateCrop",
17582
+ "keyFrame",
17583
+ "keyFrameSmall",
17584
+ "thumbnailSmall"
17585
+ ]);
17586
+ var MediaFileSchema = object({
17587
+ key: string(),
17588
+ kind: MediaFileKindEnum,
17589
+ base64: string(),
17590
+ sizeBytes: number$1(),
17591
+ timestamp: number$1()
17194
17592
  });
17195
- var LIST_GROUPS_DEFAULT_LIMIT = 40;
17196
- var LIST_GROUPS_MAX_LIMIT = 100;
17197
- var AnalyticsGroupRecordSchema = object({
17593
+ /**
17594
+ * One media row WITHOUT its bytes.
17595
+ *
17596
+ * A track's media is 5-8 MB of base64 (measured: 7.67 MB across 23 files for a
17597
+ * 140 s track), and a client that renders tiles from the media data plane needs
17598
+ * to know only WHAT EXISTS — the bytes then arrive per tile, lazily, over HTTP
17599
+ * with an immutable cache, instead of all at once inside a tRPC response that
17600
+ * blocks the whole view.
17601
+ *
17602
+ * `sizeBytes` is carried because it is what lets a client decide between the
17603
+ * stored blob and a `?variant=thumb` rendering without fetching either.
17604
+ */
17605
+ var MediaFileInfoSchema = MediaFileSchema.omit({ base64: true });
17606
+ /**
17607
+ * The MACRO tier of an annotation — a CLOSED set.
17608
+ *
17609
+ * This is what the exported detector predicts, so a typo here is a new class
17610
+ * with one example in it. `label` and `subLabel` are open strings by contrast:
17611
+ * the whole point of the page is teaching the model things it does not know
17612
+ * yet, and constraining that vocabulary would make it useless.
17613
+ *
17614
+ * A macro class is NEVER a label. The provider refuses a write whose `label` or
17615
+ * `subLabel` is one of these values, in any casing, because once `person`
17616
+ * exists in both tiers "every person box" stops being answerable without
17617
+ * knowing every string anyone ever typed — and the damage is retroactive.
17618
+ */
17619
+ var RetrainMacroClassSchema = _enum([
17620
+ "person",
17621
+ "vehicle",
17622
+ "animal",
17623
+ "package",
17624
+ "face",
17625
+ "plate"
17626
+ ]);
17627
+ /** A subject to learn, or a phantom to unlearn (taught by OMISSION). */
17628
+ var RetrainAnnotationKindSchema = _enum(["subject", "model_error"]);
17629
+ /** Did a human draw this box, or did the assist propose it? */
17630
+ var RetrainAnnotationSourceSchema = _enum(["operator", "assist"]);
17631
+ /** Normalised `[0,1]` rectangle against the FULL frame — the canonical form. */
17632
+ var RetrainBboxSchema = object({
17633
+ x: number$1(),
17634
+ y: number$1(),
17635
+ w: number$1(),
17636
+ h: number$1()
17637
+ });
17638
+ /**
17639
+ * One annotated subject.
17640
+ *
17641
+ * `bbox` is normalised against the full frame, ALWAYS. The per-model shapes
17642
+ * (letterboxed root / zone-cropped package / subject-cropped classifier) are
17643
+ * derived from it at export and never stored — storing them is how one feature
17644
+ * space ends up holding two crops of the same subject (D52).
17645
+ */
17646
+ var RetrainAnnotationSchema = object({
17198
17647
  id: string(),
17199
- deviceId: number$1().int(),
17200
- openedAt: number$1().int(),
17201
- closedAt: number$1().int(),
17202
- timestamp: number$1().int(),
17203
- memberCount: number$1().int(),
17204
- memberTrackIds: array(string()).readonly(),
17205
- className: string(),
17206
- classes: array(string()).readonly(),
17207
- /** Relative event-media path, or null when the group has no picture yet. */
17208
- mediaUrl: string().nullable(),
17209
- singleton: boolean()
17648
+ trackId: string(),
17649
+ deviceId: number$1(),
17650
+ /** The COPY in retrain storage — never the source track's media key. */
17651
+ mediaKey: string(),
17652
+ bbox: RetrainBboxSchema,
17653
+ macroClass: RetrainMacroClassSchema,
17654
+ label: string().optional(),
17655
+ subLabel: string().optional(),
17656
+ kind: RetrainAnnotationKindSchema,
17657
+ source: RetrainAnnotationSourceSchema,
17658
+ /** Which model proposed this box — or, on a `model_error`, drew the phantom. */
17659
+ assistModelId: string().optional(),
17660
+ assistScore: number$1().optional(),
17661
+ exportedInBatch: string().optional(),
17662
+ createdAt: number$1()
17210
17663
  });
17211
- var AnalyticsGroupMemberSchema = object({
17664
+ /** The write form — the server owns `id`, `createdAt` and the frame binding. */
17665
+ var RetrainAnnotationDraftSchema = RetrainAnnotationSchema.omit({
17666
+ id: true,
17667
+ trackId: true,
17668
+ deviceId: true,
17669
+ mediaKey: true,
17670
+ createdAt: true,
17671
+ exportedInBatch: true
17672
+ });
17673
+ /** A track sitting in `staging`, with everything the worklist needs to rank it. */
17674
+ var RetrainTrackSchema = object({
17212
17675
  trackId: string(),
17213
- deviceId: number$1().int(),
17676
+ deviceId: number$1(),
17214
17677
  className: string(),
17215
- firstSeen: number$1().int(),
17216
- lastSeen: number$1().int(),
17217
- mediaUrl: string().nullable()
17218
- });
17219
- var AnalyticsGroupDetailSchema = AnalyticsGroupRecordSchema.extend({ members: array(AnalyticsGroupMemberSchema).readonly() });
17220
- var ListGroupsQueryInput = object({
17221
- /** Devices to merge. An empty array yields `{ groups: [], nextCursor: null }`. */
17222
- deviceIds: array(number$1()),
17223
- /** Window lower bound on `closedAt` (inclusive). */
17224
- since: number$1().optional(),
17225
- /** Window upper bound on `openedAt` (inclusive). */
17226
- until: number$1().optional(),
17227
- limit: number$1().int().min(1).max(LIST_GROUPS_MAX_LIMIT).default(LIST_GROUPS_DEFAULT_LIMIT),
17228
- /** Opaque continuation cursor from a previous page's `nextCursor`. */
17229
- cursor: string().optional()
17678
+ label: string().optional(),
17679
+ firstSeen: number$1(),
17680
+ lastSeen: number$1(),
17681
+ /** How many frames the dataset already holds from this track. */
17682
+ frameCount: number$1().int(),
17683
+ /** How many subjects have been annotated on those frames. `0` with
17684
+ * `frameCount: 0` is exactly "staging, still to work". */
17685
+ annotationCount: number$1().int()
17230
17686
  });
17231
- var ListGroupsPageSchema = object({
17232
- groups: array(AnalyticsGroupRecordSchema).readonly(),
17233
- nextCursor: string().nullable()
17687
+ /** A frame the picker may offer — an index row, no blob was read to produce it. */
17688
+ var RetrainFrameCandidateSchema = object({
17689
+ mediaKey: string(),
17690
+ kind: MediaFileKindEnum,
17691
+ timestamp: number$1(),
17692
+ sizeBytes: number$1().int(),
17693
+ /** A copy of this original already exists — selecting it is free and cannot
17694
+ * fail, whatever became of the original. */
17695
+ copied: boolean()
17234
17696
  });
17235
- var KeyEventQueryInput = object({
17697
+ /** A frame the dataset OWNS: bytes copied at selection time. */
17698
+ var RetrainFrameSchema = object({
17699
+ frameId: string(),
17236
17700
  deviceId: number$1(),
17237
- /** Window lower bound (track firstSeen ≥ since). */
17238
- since: number$1(),
17239
- /** Window upper bound (track firstSeen ≤ until). */
17701
+ trackId: string(),
17702
+ /** Provenance only. It may already point at nothing — that is expected. */
17703
+ sourceMediaKey: string(),
17704
+ sourceKind: MediaFileKindEnum,
17705
+ sizeBytes: number$1().int(),
17706
+ width: number$1().int(),
17707
+ height: number$1().int(),
17708
+ copiedAt: number$1()
17709
+ });
17710
+ /** Why a copy-on-select could not be honoured — named, never a silent skip. */
17711
+ var RetrainCopyRefusalSchema = _enum([
17712
+ "source-missing",
17713
+ "unreadable-image",
17714
+ "write-failed"
17715
+ ]);
17716
+ var RetrainFrameSelectionSchema = object({
17717
+ copied: array(RetrainFrameSchema).readonly(),
17718
+ refused: array(object({
17719
+ sourceMediaKey: string(),
17720
+ reason: RetrainCopyRefusalSchema
17721
+ })).readonly()
17722
+ });
17723
+ var RetrainFrameListSchema = object({
17724
+ candidates: array(RetrainFrameCandidateSchema).readonly(),
17725
+ copies: array(RetrainFrameSchema).readonly(),
17726
+ /** What the page pre-selects — the native key frame when one survives. */
17727
+ autoPickMediaKey: string().optional()
17728
+ });
17729
+ /** What the operator asked the assist to look for. */
17730
+ var RetrainAssistSubjectSchema = discriminatedUnion("kind", [object({
17731
+ kind: literal("package"),
17732
+ zone: RetrainBboxSchema.optional()
17733
+ }), object({
17734
+ kind: literal("objects"),
17735
+ modelId: string(),
17736
+ minScore: number$1().optional()
17737
+ })]);
17738
+ /**
17739
+ * The assist's answer — a discriminated union, because "the model saw nothing"
17740
+ * and "this node cannot run that model" lead to different next moves and a
17741
+ * nullable result cannot tell them apart.
17742
+ */
17743
+ var RetrainAssistResultSchema = discriminatedUnion("kind", [object({
17744
+ kind: literal("proposed"),
17745
+ modelId: string(),
17746
+ stepId: string(),
17747
+ minScore: number$1(),
17748
+ /** Drafts, ready to edit. `source: 'assist'` until the operator touches one. */
17749
+ proposals: array(RetrainAnnotationDraftSchema).readonly(),
17750
+ /** Returned by the runner but removed by the threshold. */
17751
+ belowThreshold: number$1().int()
17752
+ }), object({
17753
+ kind: literal("refused"),
17754
+ /** `no-zone` is ours; the rest are the runner's own refusal vocabulary. */
17755
+ reason: string(),
17756
+ detail: string().optional()
17757
+ })]);
17758
+ /** The outcome of a lifecycle move owned by the retrain page. */
17759
+ var RetrainTransitionResultSchema = object({
17760
+ trackId: string(),
17761
+ /** Where the track ended up, whatever happened. */
17762
+ retrainStatus: RetrainStatusSchema,
17763
+ /** `false` ⇒ the move was refused or was a no-op; `reason` says which. */
17764
+ changed: boolean(),
17765
+ reason: _enum([
17766
+ "unknown-track",
17767
+ "no-frames-copied",
17768
+ "not-staging",
17769
+ "not-trained",
17770
+ "unchanged"
17771
+ ]).optional()
17772
+ });
17773
+ var DEFAULT_EVENT_QUERY_LIMIT = 1e3;
17774
+ var MAX_EVENT_QUERY_LIMIT = 5e3;
17775
+ var DeviceEventQueryInput = object({
17776
+ deviceId: number$1(),
17777
+ since: number$1().optional(),
17778
+ until: number$1().optional(),
17779
+ limit: number$1().int().min(1).max(MAX_EVENT_QUERY_LIMIT).default(DEFAULT_EVENT_QUERY_LIMIT),
17780
+ /** `slim` drops heavy JSON fields (regions/bbox/zones) and carries an
17781
+ * optional `mediaUrl` (populated by B5). `full` (default) keeps today's
17782
+ * exact behaviour. Callers may omit this field — the store defaults to
17783
+ * `full` when not provided. */
17784
+ projection: _enum(["full", "slim"]).optional()
17785
+ });
17786
+ var ObjectEventQueryInput = DeviceEventQueryInput.extend({ classFilter: string().optional() });
17787
+ var RecentTracksQueryInput = object({
17788
+ /** Devices to merge. An empty array yields `{ tracks: [], nextCursor: null }`. */
17789
+ deviceIds: array(number$1()),
17790
+ /** Window lower bound on `lastSeen` (inclusive). */
17791
+ since: number$1().optional(),
17792
+ /** Window upper bound on `lastSeen` (inclusive). */
17793
+ until: number$1().optional(),
17794
+ /** Page size. Default 200, max 1000. */
17795
+ limit: number$1().int().min(1).max(1e3).default(200),
17796
+ /** Opaque continuation cursor from a previous page's `nextCursor`.
17797
+ * Encodes the (lastSeen, trackId) sort position — treat as opaque. */
17798
+ cursor: string().optional(),
17799
+ /** See {@link TrackProjectionSchema}. Default `full`. */
17800
+ projection: TrackProjectionSchema.optional(),
17801
+ /** Include stationary-promoted rows (parked objects). Default false: the
17802
+ * feed lists passages; parking records live on the stationary registry. */
17803
+ includeStationary: boolean().optional()
17804
+ });
17805
+ var RecentTracksPageSchema = object({
17806
+ /** Merged page, ordered by (`lastSeen` DESC, `trackId` DESC). */
17807
+ tracks: array(TrackSchema).readonly(),
17808
+ /** Cursor for the next page, or null when this page is the last. */
17809
+ nextCursor: string().nullable()
17810
+ });
17811
+ var LIST_GROUPS_DEFAULT_LIMIT = 40;
17812
+ var LIST_GROUPS_MAX_LIMIT = 100;
17813
+ var AnalyticsGroupRecordSchema = object({
17814
+ id: string(),
17815
+ deviceId: number$1().int(),
17816
+ openedAt: number$1().int(),
17817
+ closedAt: number$1().int(),
17818
+ timestamp: number$1().int(),
17819
+ memberCount: number$1().int(),
17820
+ memberTrackIds: array(string()).readonly(),
17821
+ className: string(),
17822
+ classes: array(string()).readonly(),
17823
+ /** Relative event-media path, or null when the group has no picture yet. */
17824
+ mediaUrl: string().nullable(),
17825
+ singleton: boolean()
17826
+ });
17827
+ var AnalyticsGroupMemberSchema = object({
17828
+ trackId: string(),
17829
+ deviceId: number$1().int(),
17830
+ className: string(),
17831
+ firstSeen: number$1().int(),
17832
+ lastSeen: number$1().int(),
17833
+ mediaUrl: string().nullable()
17834
+ });
17835
+ var AnalyticsGroupDetailSchema = AnalyticsGroupRecordSchema.extend({ members: array(AnalyticsGroupMemberSchema).readonly() });
17836
+ var ListGroupsQueryInput = object({
17837
+ /** Devices to merge. An empty array yields `{ groups: [], nextCursor: null }`. */
17838
+ deviceIds: array(number$1()),
17839
+ /** Window lower bound on `closedAt` (inclusive). */
17840
+ since: number$1().optional(),
17841
+ /** Window upper bound on `openedAt` (inclusive). */
17842
+ until: number$1().optional(),
17843
+ limit: number$1().int().min(1).max(LIST_GROUPS_MAX_LIMIT).default(LIST_GROUPS_DEFAULT_LIMIT),
17844
+ /** Opaque continuation cursor from a previous page's `nextCursor`. */
17845
+ cursor: string().optional()
17846
+ });
17847
+ var ListGroupsPageSchema = object({
17848
+ groups: array(AnalyticsGroupRecordSchema).readonly(),
17849
+ nextCursor: string().nullable()
17850
+ });
17851
+ var KeyEventQueryInput = object({
17852
+ deviceId: number$1(),
17853
+ /** Window lower bound (track firstSeen ≥ since). */
17854
+ since: number$1(),
17855
+ /** Window upper bound (track firstSeen ≤ until). */
17240
17856
  until: number$1(),
17241
17857
  limit: number$1().int().min(1).max(200).default(50),
17242
17858
  /** Drop tracks scoring below this importance. */
@@ -17435,6 +18051,24 @@ var RebuildStatusSchema = object({
17435
18051
  /** Present when the pass ended by throwing. */
17436
18052
  error: string().nullable()
17437
18053
  });
18054
+ var ReplayFrameInputSchema = object({
18055
+ timestamp: number$1(),
18056
+ frame: PipelineRunResultBridge
18057
+ });
18058
+ var RunReplayFrameProcessorResultSchema = object({ tracks: array(object({
18059
+ className: string(),
18060
+ firstSeenMs: number$1(),
18061
+ lastSeenMs: number$1(),
18062
+ /** Bbox of the track's FIRST matched detection, pixel-space in the clip's
18063
+ * frame — a representative box for the diff's `(className, window, IoU)`
18064
+ * pairing (`replay-diff.ts`). A replay does not need the full per-frame
18065
+ * trajectory production's `Track.positions` keeps. */
18066
+ bbox: BoundingBoxSchema,
18067
+ /** How many of the input frames this track matched a real detection on
18068
+ * (never a coasted/extrapolated frame) — the replay's own signal for "how
18069
+ * solid is this track", cheaper than re-deriving it from a trajectory. */
18070
+ framesMatched: number$1().int()
18071
+ })).readonly() });
17438
18072
  DeviceType.Camera, method(object({ deviceId: number$1() }), array(TrackSchema).readonly()), method(object({
17439
18073
  deviceId: number$1(),
17440
18074
  trackId: string()
@@ -17605,502 +18239,80 @@ DeviceType.Camera, method(object({ deviceId: number$1() }), array(TrackSchema).r
17605
18239
  }), RetrainAssistResultSchema, {
17606
18240
  kind: "mutation",
17607
18241
  auth: "admin"
17608
- }), method(object({ trackId: string() }), array(RetrainAnnotationSchema).readonly(), {
17609
- kind: "query",
17610
- auth: "admin"
17611
- }), method(object({
17612
- deviceId: number$1(),
17613
- trackId: string(),
17614
- frameId: string(),
17615
- annotations: array(RetrainAnnotationDraftSchema)
17616
- }), array(RetrainAnnotationSchema).readonly(), {
17617
- kind: "mutation",
17618
- auth: "admin"
17619
- }), method(object({
17620
- deviceId: number$1(),
17621
- trackId: string()
17622
- }), RetrainTransitionResultSchema, {
17623
- kind: "mutation",
17624
- auth: "admin"
17625
18242
  }), method(object({
17626
18243
  deviceId: number$1(),
17627
- trackId: string()
17628
- }), RetrainTransitionResultSchema, {
18244
+ source: DetectionSourceSchema,
18245
+ zones: array(ZoneSchema).readonly().optional(),
18246
+ detectionRules: array(ZoneRuleSchema).readonly().optional(),
18247
+ zoneMembershipMinOverlap: number$1().min(0).max(1).optional(),
18248
+ frames: array(ReplayFrameInputSchema).min(1)
18249
+ }), RunReplayFrameProcessorResultSchema, {
17629
18250
  kind: "mutation",
17630
18251
  auth: "admin"
17631
- }), method(object({ deviceIds: array(number$1()).optional() }), object({ url: string() }), {
18252
+ }), method(object({ trackId: string() }), array(RetrainAnnotationSchema).readonly(), {
17632
18253
  kind: "query",
17633
18254
  auth: "admin"
17634
18255
  }), method(object({
17635
- eventId: string(),
17636
- kind: MediaFileKindEnum.optional(),
17637
- deviceId: number$1()
17638
- }), array(MediaFileSchema).readonly()), method(object({
17639
- trackId: string(),
17640
- kinds: array(MediaFileKindEnum).optional(),
17641
- deviceId: number$1()
17642
- }), array(MediaFileSchema).readonly()), method(object({
17643
- trackId: string(),
17644
- deviceId: number$1()
17645
- }), array(MediaFileInfoSchema).readonly()), method(SearchObjectEventsInput, array(ScoredObjectEventSchema).readonly()), method(object({}), WipeObjectEmbeddingsResultSchema, {
17646
- kind: "mutation",
17647
- auth: "admin"
17648
- }), method(RebuildObjectEmbeddingsInput, RebuildObjectEmbeddingsResultSchema, {
17649
- kind: "mutation",
17650
- auth: "admin"
17651
- }), method(object({}), RebuildStatusSchema), object({
17652
- deviceId: number$1(),
17653
- timestamp: number$1(),
17654
- frameWidth: number$1(),
17655
- frameHeight: number$1(),
17656
- detections: array(OverlayDetectionSchema).readonly()
17657
- }), object({
17658
- deviceId: number$1(),
17659
- trackId: string(),
17660
- className: string()
17661
- }), object({
17662
18256
  deviceId: number$1(),
17663
18257
  trackId: string(),
17664
- className: string(),
17665
- durationMs: number$1()
17666
- }), object({
17667
- deviceId: number$1(),
17668
- kind: EventKindSchema,
17669
- eventId: string(),
17670
- timestamp: number$1()
17671
- });
17672
- /**
17673
- * Reference to the frame's retained NATIVE surface + the parent crop's placement
17674
- * within the frame, so the executor can re-cut a leaf child ROI at native
17675
- * resolution on the detail plane. See the `runPipeline` `nativeCropRef` field.
17676
- */
17677
- var NativeCropRefSchema = object({
17678
- /** Handle keying the retained native surface (node-pinned to its owner). */
17679
- handle: FrameHandleSchema,
17680
- /** The parent crop's padded/clamped rectangle in FRAME-space pixels. */
17681
- cropFrameSpace: object({
17682
- x: number$1(),
17683
- y: number$1(),
17684
- w: number$1(),
17685
- h: number$1()
17686
- })
17687
- });
17688
- object({
17689
- crop: object({
17690
- left: number$1(),
17691
- top: number$1(),
17692
- width: number$1().positive(),
17693
- height: number$1().positive()
17694
- }).optional(),
17695
- content: object({
17696
- width: number$1().int().positive(),
17697
- height: number$1().int().positive()
17698
- }),
17699
- fit: _enum(["stretch", "contain"]),
17700
- format: _enum([
17701
- "rgb",
17702
- "gray",
17703
- "jpeg"
17704
- ])
17705
- });
17706
- /**
17707
- * Process-local frame identity. It is serializable so it can ride an in-process
17708
- * capability call, but `registryId` deliberately prevents resolution in any
17709
- * other process or execution group.
17710
- */
17711
- var FrameRefSchema = object({
17712
- registryId: string().min(1),
17713
- id: string().min(1),
17714
- width: number$1().int().positive(),
17715
- height: number$1().int().positive(),
17716
- format: _enum(["rgb", "gray"]),
17717
- timestamp: number$1(),
17718
- capturedAt: number$1().optional()
17719
- });
17720
- var ModelFormatSchema$1 = _enum([
17721
- "onnx",
17722
- "coreml",
17723
- "openvino",
17724
- "tflite",
17725
- "pt",
17726
- "gguf"
17727
- ]);
17728
- var PipelineSlotSchema = _enum([
17729
- "detector",
17730
- "cropper",
17731
- "classifier",
17732
- "refiner",
17733
- "audio-classifier"
17734
- ]);
17735
- var PipelineEngineChoiceSchema = object({
17736
- runtime: _enum(["node", "python"]),
17737
- backend: string(),
17738
- format: ModelFormatSchema$1,
17739
- device: string().optional()
17740
- });
17741
- var AvailableEngineSchema = object({
17742
- engine: PipelineEngineChoiceSchema,
17743
- devices: array(object({
17744
- id: string(),
17745
- label: string(),
17746
- description: string().optional()
17747
- })).readonly(),
17748
- defaultDevice: string()
17749
- });
17750
- var PipelineDefaultStepSchema = lazy(() => object({
17751
- addonId: string(),
17752
- addonName: string(),
17753
- slot: PipelineSlotSchema,
17754
- inputClasses: array(string()).readonly(),
17755
- outputClasses: array(string()).readonly(),
17756
- enabled: boolean(),
17757
- modelId: string(),
17758
- children: array(PipelineDefaultStepSchema).readonly(),
17759
- group: string().optional(),
17760
- settings: record(string(), unknown()).optional()
17761
- }));
17762
- var PipelineTemplateStepSchema = lazy(() => object({
17763
- addonId: string(),
17764
- enabled: boolean(),
17765
- modelId: string(),
17766
- children: array(PipelineTemplateStepSchema).readonly(),
17767
- settings: record(string(), unknown()).optional()
17768
- }));
17769
- var PipelineTemplateSchema$1 = object({
17770
- id: string(),
17771
- name: string(),
17772
- createdAt: string(),
17773
- updatedAt: string(),
17774
- engine: PipelineEngineChoiceSchema,
17775
- steps: array(PipelineTemplateStepSchema).readonly()
17776
- });
17777
- var PipelineModelOptionSchema = object({
17778
- id: string(),
17779
- name: string(),
17780
- formats: record(string(), object({
17781
- downloaded: boolean(),
17782
- sizeMB: number$1()
17783
- })),
17784
- group: ModelVariantGroupSchema.optional(),
17785
- legacy: boolean().optional(),
17786
- provider: ModelProviderIdSchema.optional()
17787
- });
17788
- var ConfigFieldBridge = custom();
17789
- var PipelineAddonSchemaSchema = object({
17790
- id: string(),
17791
- name: string(),
17792
- slot: PipelineSlotSchema,
17793
- inputClasses: array(string()).readonly(),
17794
- outputClasses: array(string()).readonly(),
17795
- childSlots: array(PipelineSlotSchema).readonly(),
17796
- models: array(PipelineModelOptionSchema).readonly(),
17797
- defaultModelId: string(),
17798
- defaultModelIdByFormat: record(string(), string()).optional(),
17799
- enabledByDefault: boolean().optional(),
17800
- backfillIntoExistingOverrides: boolean().optional(),
17801
- defaultConfidence: number$1(),
17802
- group: string().optional(),
17803
- configSchema: array(ConfigFieldBridge).readonly().optional()
17804
- });
17805
- var PipelineSlotSchemaSchema = object({
17806
- id: PipelineSlotSchema,
17807
- label: string(),
17808
- priority: number$1(),
17809
- parentSlot: PipelineSlotSchema.nullable(),
17810
- addons: array(PipelineAddonSchemaSchema).readonly()
17811
- });
17812
- var PipelineSchemaSchema = object({
17813
- availableEngines: array(AvailableEngineSchema).readonly(),
17814
- selectedEngine: PipelineEngineChoiceSchema,
17815
- slots: array(PipelineSlotSchemaSchema).readonly()
17816
- });
17817
- var EngineProvisioningSchema = object({
17818
- runtimeId: _enum([
17819
- "onnx",
17820
- "openvino",
17821
- "coreml",
17822
- "edgetpu"
17823
- ]).nullable(),
17824
- device: string().nullable(),
17825
- state: _enum([
17826
- "idle",
17827
- "installing",
17828
- "verifying",
17829
- "ready",
17830
- "failed"
17831
- ]),
17832
- progress: number$1().optional(),
17833
- error: string().optional(),
17834
- nextRetryAt: number$1().optional(),
17835
- /**
17836
- * Gate A (config-correctness gate at engine change): human-readable
17837
- * config issues surfaced EAGERLY when the node's engine changes — model
17838
- * substitutions ("chose X, running Y") and zero-build steps ("no model
17839
- * has a <format> build"). Additive/optional: informational only, never
17840
- * enforced here — `assertEngineReady` (readiness) still gates inference.
17841
- * Absent/empty when the node-default tree resolves cleanly.
17842
- */
17843
- configIssues: array(string()).optional()
17844
- });
17845
- var PipelineStepInputSchema = lazy(() => object({
17846
- addonId: string(),
17847
- modelId: string().optional(),
17848
- enabled: boolean().default(true),
17849
- children: array(PipelineStepInputSchema).optional(),
17850
- settings: record(string(), unknown()).optional(),
17851
- jumpDeviceKey: string().optional()
17852
- }));
17853
- var ModelSubstitutionSchema = object({
17854
- addonId: string(),
17855
- chosen: string(),
17856
- running: string(),
17857
- format: string()
17858
- });
17859
- var PipelineValidationIssueSchema = object({
17860
- addonId: string(),
17861
- kind: _enum(["unknown-addon", "no-format-build"]),
17862
- detail: string()
17863
- });
17864
- var PipelineValidationResultSchema = object({
17865
- ok: boolean(),
17866
- issues: array(PipelineValidationIssueSchema).readonly(),
17867
- substitutions: array(ModelSubstitutionSchema).readonly(),
17868
- /** The node's `currentEngine.format` this validation ran against. */
17869
- format: string()
17870
- });
17871
- var ReferenceImageEntrySchema = object({
17872
- filename: string(),
17873
- stepIds: array(string()).readonly().optional()
17874
- });
17875
- var ReferenceImageBodySchema = object({
17876
- base64: string(),
17877
- filename: string()
17878
- });
17879
- var ReferenceAudioEntrySchema = object({
17880
- filename: string(),
17881
- sizeKb: number$1()
17882
- });
17883
- var ReferenceAudioBodySchema = object({ base64: string() });
17884
- var AudioBackendSchema = object({
17885
- id: string(),
17886
- name: string(),
17887
- description: string(),
17888
- available: boolean(),
17889
- /**
17890
- * Raw classifier labels this backend can emit (e.g. YAMNet's
17891
- * 521-class set or Apple SoundAnalysis's 303-class set). Used by
17892
- * the benchmark UI to populate the `enabledMicroClasses` filter
17893
- * specific to the selected backend without a separate fetch.
17894
- */
17895
- rawLabels: array(string()).readonly().optional()
17896
- });
17897
- var AudioCapabilitiesSchema = object({
17898
- activeBackend: string(),
17899
- availableBackends: array(AudioBackendSchema).readonly(),
17900
- sampleRate: number$1(),
17901
- chunkDurationMs: number$1()
17902
- });
17903
- var DownloadModelResultSchema = object({
17904
- filePath: string(),
17905
- sizeMB: number$1(),
17906
- durationMs: number$1()
17907
- });
17908
- /**
17909
- * Wrapper carrying a single test run's result. Replaces the legacy
17910
- * ad-hoc `{labels: [{className, originalClass, score}]}` shape with the
17911
- * canonical `AudioResult` from the Phase 6 output rework: one
17912
- * `AudioDetection` per class above `minScore`, top-N candidates in
17913
- * `debug.alternateLabels['audio-classifier']`, per-source timings in
17914
- * `debug.stepTimings`. The outer `success`/`error` fields stay so the
17915
- * benchmark UI can still report a clean failure when the classifier
17916
- * cap isn't available.
17917
- */
17918
- var AudioTestResultSchema = object({
17919
- success: boolean(),
17920
- error: string().optional(),
17921
- frame: custom().optional()
17922
- });
17923
- var PipelineConfigBridge = custom();
17924
- var ConfigUISchemaBridge = custom();
17925
- var ConfigUISchemaNullableBridge = custom();
17926
- var InferenceCapabilitiesBridge = custom();
17927
- var ModelAvailabilityListBridge = custom();
17928
- var PipelineRunResultBridge = custom();
17929
- method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngineChoiceSchema), method(PipelineEngineChoiceSchema, array(PipelineDefaultStepSchema)), method(object({ nodeId: string() }), EngineProvisioningSchema), method(_void(), record(string(), object({
17930
- modelId: string(),
17931
- settings: record(string(), unknown()).readonly()
17932
- }))), method(object({ steps: record(string(), object({
17933
- modelId: string(),
17934
- settings: record(string(), unknown()).readonly()
17935
- })) }), object({ success: literal(true) }), {
17936
- kind: "mutation",
17937
- auth: "admin"
17938
- }), method(object({ nodeId: string() }), object({
17939
- success: literal(true),
17940
- clearedDevices: number$1()
17941
- }), {
17942
- kind: "mutation",
17943
- auth: "admin"
17944
- }), 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({
17945
- name: string(),
17946
- steps: array(PipelineTemplateStepSchema).readonly(),
17947
- engine: PipelineEngineChoiceSchema
17948
- }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({
17949
- id: string(),
17950
- name: string().optional(),
17951
- steps: array(PipelineTemplateStepSchema).readonly().optional()
17952
- }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({ id: string() }), _void(), { kind: "mutation" }), method(_void(), InferenceCapabilitiesBridge), method(object({ addonId: string() }), ModelAvailabilityListBridge), method(object({
17953
- addonId: string(),
17954
- modelId: string(),
17955
- format: ModelFormatSchema$1
17956
- }), DownloadModelResultSchema, { kind: "mutation" }), method(object({
17957
- addonId: string(),
17958
- modelId: string(),
17959
- format: ModelFormatSchema$1
17960
- }), object({ success: literal(true) }), { kind: "mutation" }), method(object({
17961
- engine: PipelineEngineChoiceSchema.optional(),
17962
- steps: array(PipelineStepInputSchema).min(1),
17963
- frame: FrameInputSchema.optional(),
17964
- /**
17965
- * Process-local lazy frame. Valid only when caller and provider resolve
17966
- * in the same execution-group process; split/cross-node callers use
17967
- * `frame`/`image` inline compatibility instead.
17968
- */
17969
- frameRef: FrameRefSchema.optional(),
17970
- /**
17971
- * CB5 shm passthrough — a `FrameHandle` naming the same ring slot
17972
- * the decoded pixels live in. One more member of the one-of
17973
- * frame/frameHandle/image/imageBase64/referenceImage group.
17974
- */
17975
- frameHandle: FrameHandleSchema.optional(),
17976
- imageBase64: string().optional(),
17977
- /**
17978
- * Binary JPEG bytes — preferred over `imageBase64` on internal
17979
- * hops (hub → forked worker via Moleculer MsgPack) because it
17980
- * skips the 33% base64 overhead + the per-call base64 decode on
17981
- * the detection-pipeline worker. Callers can pass either; exactly
17982
- * one of `frame`/`image`/`imageBase64`/`referenceImage` is required.
17983
- */
17984
- image: _instanceof(Uint8Array).optional(),
17985
- referenceImage: string().optional(),
17986
- deviceId: number$1().optional(),
17987
- sessionId: string().optional(),
17988
- /**
17989
- * Execution plane. 'full' (default) runs the whole tree — benchmark,
17990
- * reference-image, and detail-subtree calls. 'frame' is the live
17991
- * per-frame dispatch: ONLY root-plane steps run; crop children
17992
- * (inputClasses ≠ null) are skipped and served per-track via
17993
- * pipelineRunner.runDetailSubtree (two-plane design).
17994
- */
17995
- plane: _enum(["full", "frame"]).optional(),
17996
- /**
17997
- * Inference-device selector (Phase 2 multi-device). Format
17998
- * `<backend>:<device>` (e.g. `openvino:gpu`, `edgetpu:usb`, `cpu`).
17999
- * Omitted ⇒ the runner's default device (current single-engine
18000
- * behaviour). Selects WHICH device pool of the node runs the call.
18001
- */
18002
- deviceKey: string().optional(),
18003
- /**
18004
- * Two-plane NATIVE child-crop reference. Set by `runDetailSubtree` ONLY
18005
- * when the parent crop was resolved from the frame's retained NATIVE
18006
- * surface (a frameHandle HIT). Lets the executor re-cut a LEAF crop
18007
- * child's ROI (plate-ocr, face-embedding, leaf classifiers) at native
18008
- * resolution from that surface — the SAME quality path faces already
18009
- * had — instead of the downscaled parent tile. `handle` keys the native
18010
- * surface (node-pinned to its owner); `cropFrameSpace` is the parent
18011
- * crop's padded/clamped rectangle in FRAME-space pixels, used to compose
18012
- * the executor's crop-normalized child ROI back into frame-normalized
18013
- * coordinates. Auxiliary to the image source (`image`/`frame`/…), NOT one
18014
- * of the mutually-exclusive image inputs. Absent ⇒ tile-crop children
18015
- * (today's behaviour on the fallback path).
18016
- */
18017
- nativeCropRef: NativeCropRefSchema.optional()
18018
- }), PipelineRunResultBridge, { kind: "mutation" }), method(object({
18019
- engine: PipelineEngineChoiceSchema.optional(),
18020
- steps: array(PipelineStepInputSchema).min(1),
18021
- frames: array(FrameInputSchema).min(1).max(255),
18022
- deviceId: number$1().optional(),
18023
- sessionId: string().optional(),
18024
- /**
18025
- * Pure-inference benchmark hint. A NONZERO uint32 pins every frame in
18026
- * the batch to the Python pool's bench preprocess cache
18027
- * (`_bench_frame_id`) so a REPEATED benchmark frame is decoded +
18028
- * preprocessed ONCE and every later inference is a pure-inference cache
18029
- * hit — the sustained-throughput run measures inference, not
18030
- * decode+preprocess+infer. Omitted/0 for live frames (all different →
18031
- * full preprocess every call, correct). Fresh per sustained run;
18032
- * released via `uncacheFrame`.
18033
- */
18034
- frameId: number$1().int().nonnegative().optional(),
18035
- /** Inference-device selector (Phase 2 multi-device); see runPipeline. */
18036
- deviceKey: string().optional()
18037
- }), object({ results: array(PipelineRunResultBridge).readonly() }), { kind: "mutation" }), method(object({
18038
- data: _instanceof(Uint8Array),
18039
- width: number$1().int().positive(),
18040
- height: number$1().int().positive(),
18041
- format: _enum([
18042
- "rgb",
18043
- "bgr",
18044
- "gray"
18045
- ])
18046
- }), object({
18047
- frameId: number$1(),
18048
- width: number$1(),
18049
- height: number$1()
18050
- }), { kind: "mutation" }), method(object({
18051
- stepId: string(),
18052
- frameId: number$1().int()
18053
- }), record(string(), unknown()), { kind: "mutation" }), method(object({ frameId: number$1().int() }), _void(), { kind: "mutation" }), method(_void(), object({
18054
- batchMode: string(),
18055
- windowMs: number$1(),
18056
- maxBatchSize: number$1(),
18057
- concurrency: number$1()
18058
- })), method(_void(), array(object({
18059
- engineKey: string(),
18060
- engine: PipelineEngineChoiceSchema,
18061
- modelsLoaded: array(string()).readonly(),
18062
- inUseByCameras: array(number$1()).readonly(),
18063
- /**
18064
- * Origin of this resident factory.
18065
- * - `runtime` — main camera-serving engine (no idle TTL).
18066
- * - `warm-override` — benchmark/test override held in the warm
18067
- * cache; auto-disposed after the idle TTL.
18068
- * - `device-pool` — a concurrent per-device pool (Phase 2
18069
- * multi-device, keyed by `deviceKey`) resolved
18070
- * via `resolveDeviceFactory`. Runs alongside the
18071
- * `runtime` engine on a DIFFERENT accelerator
18072
- * (NPU / iGPU / Coral) — this is how the
18073
- * Engines tab shows all pools running at once.
18074
- */
18075
- kind: _enum([
18076
- "runtime",
18077
- "warm-override",
18078
- "device-pool"
18079
- ]),
18080
- /** Native pid of the underlying Python pool (null when no pool). */
18081
- poolPid: number$1().nullable(),
18082
- /** ms since this factory was last used (null when not warm-tracked). */
18083
- idleMs: number$1().nullable(),
18084
- /** Idle TTL after which `warm-override` factories self-evict (null when not applicable). */
18085
- idleTtlMs: number$1().nullable()
18086
- })).readonly()), method(object({ engine: PipelineEngineChoiceSchema }), object({ success: literal(true) }), {
18258
+ frameId: string(),
18259
+ annotations: array(RetrainAnnotationDraftSchema)
18260
+ }), array(RetrainAnnotationSchema).readonly(), {
18087
18261
  kind: "mutation",
18088
18262
  auth: "admin"
18089
18263
  }), method(object({
18090
- engine: PipelineEngineChoiceSchema,
18091
- force: boolean().optional()
18092
- }), object({
18093
- success: boolean(),
18094
- reason: string().optional()
18095
- }), {
18264
+ deviceId: number$1(),
18265
+ trackId: string()
18266
+ }), RetrainTransitionResultSchema, {
18096
18267
  kind: "mutation",
18097
18268
  auth: "admin"
18098
- }), 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({
18099
- addonId: string(),
18100
- modelId: string(),
18101
- filename: string().optional(),
18102
- settings: record(string(), unknown()).optional()
18103
- }), AudioTestResultSchema, { kind: "mutation" }), method(_void(), ConfigUISchemaNullableBridge);
18269
+ }), method(object({
18270
+ deviceId: number$1(),
18271
+ trackId: string()
18272
+ }), RetrainTransitionResultSchema, {
18273
+ kind: "mutation",
18274
+ auth: "admin"
18275
+ }), method(object({ deviceIds: array(number$1()).optional() }), object({ url: string() }), {
18276
+ kind: "query",
18277
+ auth: "admin"
18278
+ }), method(object({
18279
+ eventId: string(),
18280
+ kind: MediaFileKindEnum.optional(),
18281
+ deviceId: number$1()
18282
+ }), array(MediaFileSchema).readonly()), method(object({
18283
+ trackId: string(),
18284
+ kinds: array(MediaFileKindEnum).optional(),
18285
+ deviceId: number$1()
18286
+ }), array(MediaFileSchema).readonly()), method(object({
18287
+ trackId: string(),
18288
+ deviceId: number$1()
18289
+ }), array(MediaFileInfoSchema).readonly()), method(SearchObjectEventsInput, array(ScoredObjectEventSchema).readonly()), method(object({}), WipeObjectEmbeddingsResultSchema, {
18290
+ kind: "mutation",
18291
+ auth: "admin"
18292
+ }), method(RebuildObjectEmbeddingsInput, RebuildObjectEmbeddingsResultSchema, {
18293
+ kind: "mutation",
18294
+ auth: "admin"
18295
+ }), method(object({}), RebuildStatusSchema), object({
18296
+ deviceId: number$1(),
18297
+ timestamp: number$1(),
18298
+ frameWidth: number$1(),
18299
+ frameHeight: number$1(),
18300
+ detections: array(OverlayDetectionSchema).readonly()
18301
+ }), object({
18302
+ deviceId: number$1(),
18303
+ trackId: string(),
18304
+ className: string()
18305
+ }), object({
18306
+ deviceId: number$1(),
18307
+ trackId: string(),
18308
+ className: string(),
18309
+ durationMs: number$1()
18310
+ }), object({
18311
+ deviceId: number$1(),
18312
+ kind: EventKindSchema,
18313
+ eventId: string(),
18314
+ timestamp: number$1()
18315
+ });
18104
18316
  object({
18105
18317
  activeCameras: number$1(),
18106
18318
  throttledCameras: number$1(),
@@ -18126,66 +18338,6 @@ var CameraMetricsSchema = object({
18126
18338
  });
18127
18339
  var CameraMetricsWithDeviceIdSchema = CameraMetricsSchema.extend({ deviceId: number$1() });
18128
18340
  /**
18129
- * Zone — pure geometry + identity. NO filtering behaviour.
18130
- *
18131
- * Zones describe **where** in the frame the operator wants to flag
18132
- * something; consumer-owned {@link ZoneRule} arrays describe **how**
18133
- * each pipeline stage uses them. Splitting the two means a single
18134
- * polygon "Driveway" can simultaneously back a motion-exclude rule,
18135
- * a detection-include rule on `['car']`, and an occupancy aggregate
18136
- * — without three duplicated polygons.
18137
- *
18138
- * Owned by the orchestrator addon (provider) and mirrored into the
18139
- * `zones` device-state slice on every mutation. Consumers
18140
- * (motion-wasm, pipeline-executor, analytics, admin UI) read either
18141
- * via `api.zones.listZones` (one-shot) or via `dev.state.zones` (live
18142
- * mirror with `onChanged`).
18143
- *
18144
- * Coordinates are normalised fractions of the frame (0–1) so zones
18145
- * survive resolution changes and stream profile switches.
18146
- *
18147
- * `kind` discriminates between full polygons (closed regions used
18148
- * for intrusion / occupancy filters) and tripwires (open 2-point
18149
- * line segments used for cross events). Onboard / firmware-reported
18150
- * zones (Reolink, ONVIF) are out of scope for now — see the deferred
18151
- * task list.
18152
- */
18153
- var ZoneKindEnum = _enum(["polygon", "tripwire"]);
18154
- /** Polygon vertex in fraction-of-frame coordinates (0–1). */
18155
- var PolygonPointSchema = object({
18156
- x: number$1(),
18157
- y: number$1()
18158
- });
18159
- /** A camera detection zone — pure geometry/identity. */
18160
- var ZoneSchema = object({
18161
- id: string(),
18162
- name: string(),
18163
- kind: ZoneKindEnum.default("polygon"),
18164
- /** Polygon vertices, fraction of frame (0–1). */
18165
- polygon: array(PolygonPointSchema).readonly(),
18166
- /** Visual color for UI rendering. */
18167
- color: string().default("#3b82f6")
18168
- });
18169
- DeviceType.Camera, method(object({ deviceId: number$1() }), array(ZoneSchema).readonly()), method(object({
18170
- deviceId: number$1(),
18171
- zone: ZoneSchema
18172
- }), _void(), {
18173
- kind: "mutation",
18174
- auth: "admin"
18175
- }), method(object({
18176
- deviceId: number$1(),
18177
- zoneId: string()
18178
- }), _void(), {
18179
- kind: "mutation",
18180
- auth: "admin"
18181
- }), method(object({
18182
- deviceId: number$1(),
18183
- zone: ZoneSchema
18184
- }), _void(), {
18185
- kind: "mutation",
18186
- auth: "admin"
18187
- }), object({ zones: array(ZoneSchema).readonly() });
18188
- /**
18189
18341
  * A bounding box in NORMALIZED [0,1] frame coordinates for `getNativeCrop`. The
18190
18342
  * decode worker resolves it against the RETAINED native frame's real pixel dims,
18191
18343
  * so the caller supplies only the detection-res bbox divided by the detection
@@ -25163,6 +25315,39 @@ var ReadGopBytesResultSchema = object({
25163
25315
  /** Media ms the returned fragment covers. */
25164
25316
  gopDurMs: number$1()
25165
25317
  });
25318
+ /**
25319
+ * A time WINDOW of one finalized segment, cut by byte range — the multi-GOP
25320
+ * twin of {@link ReadGopBytesResultSchema}'s single instant. Built for the
25321
+ * replay clip's `recording` source (`docs/design/plans/2026-08-26-replay-clip-su-pipeline.md`):
25322
+ * a replay needs several seconds of native pixels, not one frame.
25323
+ *
25324
+ * `ok.data` is standalone-demuxable, same as a GOP read. `ok.reachesRequestedEnd`
25325
+ * is `false` when the returned bytes were cut short by the read's own safety
25326
+ * byte cap before covering `[fromMs, toMs)` — a truncation, reported, not a
25327
+ * silently shorter answer. `spans-multiple-segments` is a REFUSAL, not a
25328
+ * degradation: a window whose end falls past the covering segment would need
25329
+ * bytes stitched from a second segment file (its own `ftyp`+`moov`), which is
25330
+ * not one standalone-demuxable stream — the caller's answer is to request a
25331
+ * shorter window or one aligned to a single segment, not to receive spliced
25332
+ * bytes nothing has proven decodable.
25333
+ */
25334
+ var ReadWindowBytesResultSchema = discriminatedUnion("kind", [object({
25335
+ kind: literal("ok"),
25336
+ data: _instanceof(Uint8Array),
25337
+ /** Absolute epoch ms of the returned bytes' first sample — at or before
25338
+ * the requested `fromMs` (anchored on the nearest keyframe). */
25339
+ gopStartMs: number$1(),
25340
+ /** Media ms the returned bytes cover, from `gopStartMs`. */
25341
+ gopDurMs: number$1(),
25342
+ /** `false` ⇒ the safety byte cap cut the read short before it reached
25343
+ * the requested `toMs`; the caller got fewer frames than asked for. */
25344
+ reachesRequestedEnd: boolean()
25345
+ }), object({
25346
+ kind: literal("spans-multiple-segments"),
25347
+ /** Where the covering segment's own footage runs out — informational,
25348
+ * not a retry hint (retrying the same window would refuse again). */
25349
+ segmentEndMs: number$1()
25350
+ })]);
25166
25351
  method(object({
25167
25352
  deviceId: number$1(),
25168
25353
  fromMs: number$1(),
@@ -25213,6 +25398,15 @@ method(object({
25213
25398
  }), ReadGopBytesResultSchema, {
25214
25399
  kind: "query",
25215
25400
  auth: "admin"
25401
+ }), method(object({
25402
+ deviceId: number$1(),
25403
+ profile: string(),
25404
+ startMs: number$1(),
25405
+ fromMs: number$1(),
25406
+ toMs: number$1()
25407
+ }), ReadWindowBytesResultSchema, {
25408
+ kind: "query",
25409
+ auth: "admin"
25216
25410
  }), method(object({
25217
25411
  deviceId: number$1(),
25218
25412
  config: RecordingConfigSchema
@@ -25767,92 +25961,6 @@ DeviceType.Camera, method(object({ deviceId: number$1() }), SceneMonitorStatusSc
25767
25961
  kind: "mutation",
25768
25962
  auth: "admin"
25769
25963
  });
25770
- /**
25771
- * Per-stage gating mode applied to the zones a rule references.
25772
- *
25773
- * - `include`: the rule contributes to a **whitelist** for its stage.
25774
- * When at least one `include` rule fires for a stage, only entities
25775
- * inside one of those zones pass that stage.
25776
- * - `exclude`: the rule contributes to a **blacklist** for its stage.
25777
- * Entities inside one of those zones are dropped at that stage.
25778
- *
25779
- * `monitor`-style observation (count without filtering) is not a rule
25780
- * mode — zones without any matching rule are observed naturally by
25781
- * `zone-analytics` (live snapshot + history), so an "I just want to
25782
- * count, not filter" use case needs no rule at all.
25783
- */
25784
- var ZoneRuleModeEnum = _enum(["include", "exclude"]);
25785
- /**
25786
- * Per-consumer rule that references existing zones (geometry) and
25787
- * defines how a specific pipeline stage should treat them. Each
25788
- * consumer addon owns its own `ZoneRule[]` array in its per-device
25789
- * settings:
25790
- *
25791
- * - `addon-motion-wasm` → `motionZoneRules: ZoneRule[]` (motion stage)
25792
- * - `addon-detection-pipeline` → `detectionZoneRules: ZoneRule[]` (detection stage)
25793
- * - future: notification rules, audio gating, etc.
25794
- *
25795
- * One rule applies to N zones (`zoneIds[]`) so the operator can
25796
- * express "ignore motion in ALL of {garden, street}" with a single
25797
- * rule. `classFilter` narrows the rule to specific object classes —
25798
- * "drop person detections in the street, but keep cars" is one
25799
- * `exclude` rule with `classFilter: ['person']`.
25800
- *
25801
- * `enabled` is a soft toggle — the operator can keep the rule
25802
- * configured but inert without deleting it.
25803
- */
25804
- var ZoneRuleSchema = object({
25805
- /** Stable rule id — survives edits, used by the UI for diffing. */
25806
- id: string(),
25807
- /** Optional human-readable label rendered in the rule editor. */
25808
- name: string().optional(),
25809
- /** Zones this rule targets. The rule's `mode` applies to ALL
25810
- * listed zones (OR-set: a detection in any one of them counts).
25811
- * At least one zone id required — a rule with no targets is a
25812
- * configuration mistake and the form validator rejects it. */
25813
- zoneIds: array(string()).min(1).readonly(),
25814
- mode: ZoneRuleModeEnum,
25815
- /**
25816
- * Class names this rule applies to. Empty / undefined ⇒ rule
25817
- * applies to every class. Class strings match the `macroClass`
25818
- * field on detections (e.g. `person`, `car`, `dog`).
25819
- */
25820
- classFilter: array(string()).readonly().optional(),
25821
- /**
25822
- * Minimum bbox/mask overlap (0–1) with any of the rule's zones
25823
- * required to consider an entity "in the zone". Defaults to the
25824
- * consumer's stage default when omitted. Kept for back-compat with
25825
- * existing per-rule overrides; new operators pick the value via
25826
- * `bboxInclusionPct` (operator-friendly 0–100). Whichever field is
25827
- * set, the lower-level engine reads it as a 0–1 fraction.
25828
- */
25829
- overlapThreshold: number$1().min(0).max(1).optional(),
25830
- /**
25831
- * Operator-friendly version of `overlapThreshold` — the percentage
25832
- * of the detection's bbox that must lie inside the zone for the
25833
- * rule to match. Documented default is 85%; the engine substitutes
25834
- * that when the field is omitted (kept optional so existing rules
25835
- * stored without it stay valid).
25836
- *
25837
- * When BOTH `overlapThreshold` and `bboxInclusionPct` are set on a
25838
- * rule, the engine prefers `bboxInclusionPct` because it's the
25839
- * field exposed in the UI. Internally both feed the same gate.
25840
- */
25841
- bboxInclusionPct: number$1().min(0).max(100).optional(),
25842
- /**
25843
- * When `true` and a detection has a segmentation mask, use the
25844
- * mask for overlap instead of the bbox. Detection-stage only;
25845
- * motion rules ignore this field.
25846
- */
25847
- preferMask: boolean().optional(),
25848
- /**
25849
- * Soft-toggle: `false` disables the rule without deleting it.
25850
- * Defaults to `true` so operators creating a rule via the UI
25851
- * see it active immediately.
25852
- */
25853
- enabled: boolean().default(true)
25854
- });
25855
- array(ZoneRuleSchema).readonly();
25856
25964
  object({
25857
25965
  /** Whether the script is currently executing. */
25858
25966
  isRunning: boolean(),
@@ -29717,6 +29825,12 @@ Object.freeze({
29717
29825
  addonId: null,
29718
29826
  access: "view"
29719
29827
  },
29828
+ "notificationRules.resolveArtifactUrl": {
29829
+ capName: "notification-rules",
29830
+ capScope: "system",
29831
+ addonId: null,
29832
+ access: "view"
29833
+ },
29720
29834
  "notificationRules.setAlarmConfig": {
29721
29835
  capName: "notification-rules",
29722
29836
  capScope: "system",
@@ -30161,6 +30275,12 @@ Object.freeze({
30161
30275
  addonId: null,
30162
30276
  access: "create"
30163
30277
  },
30278
+ "pipelineAnalytics.runReplayFrameProcessor": {
30279
+ capName: "pipeline-analytics",
30280
+ capScope: "device",
30281
+ addonId: null,
30282
+ access: "create"
30283
+ },
30164
30284
  "pipelineAnalytics.saveRetrainAnnotations": {
30165
30285
  capName: "pipeline-analytics",
30166
30286
  capScope: "device",
@@ -30293,6 +30413,12 @@ Object.freeze({
30293
30413
  addonId: null,
30294
30414
  access: "view"
30295
30415
  },
30416
+ "pipelineExecutor.getInferenceDeviceHealth": {
30417
+ capName: "pipeline-executor",
30418
+ capScope: "system",
30419
+ addonId: null,
30420
+ access: "view"
30421
+ },
30296
30422
  "pipelineExecutor.getOrchestratorConfigSchema": {
30297
30423
  capName: "pipeline-executor",
30298
30424
  capScope: "system",
@@ -30365,6 +30491,12 @@ Object.freeze({
30365
30491
  addonId: null,
30366
30492
  access: "view"
30367
30493
  },
30494
+ "pipelineExecutor.rearmInferenceDevice": {
30495
+ capName: "pipeline-executor",
30496
+ capScope: "system",
30497
+ addonId: null,
30498
+ access: "create"
30499
+ },
30368
30500
  "pipelineExecutor.runAudioTest": {
30369
30501
  capName: "pipeline-executor",
30370
30502
  capScope: "system",
@@ -31103,6 +31235,12 @@ Object.freeze({
31103
31235
  addonId: null,
31104
31236
  access: "view"
31105
31237
  },
31238
+ "recording.readWindowBytes": {
31239
+ capName: "recording",
31240
+ capScope: "system",
31241
+ addonId: null,
31242
+ access: "view"
31243
+ },
31106
31244
  "recording.refreshStorageLocationsForMigration": {
31107
31245
  capName: "recording",
31108
31246
  capScope: "system",
@@ -33613,6 +33751,11 @@ Object.freeze({
33613
33751
  form: "single",
33614
33752
  optional: false
33615
33753
  }],
33754
+ "pipelineAnalytics.runReplayFrameProcessor": [{
33755
+ name: "deviceId",
33756
+ form: "single",
33757
+ optional: false
33758
+ }],
33616
33759
  "pipelineAnalytics.saveRetrainAnnotations": [{
33617
33760
  name: "deviceId",
33618
33761
  form: "single",
@@ -33928,6 +34071,11 @@ Object.freeze({
33928
34071
  form: "single",
33929
34072
  optional: false
33930
34073
  }],
34074
+ "recording.readWindowBytes": [{
34075
+ name: "deviceId",
34076
+ form: "single",
34077
+ optional: false
34078
+ }],
33931
34079
  "recording.relocateFootage": [{
33932
34080
  name: "deviceId",
33933
34081
  form: "single",