@camstack/addon-remote-storage 1.2.28 → 1.2.30

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.
@@ -15465,7 +15465,23 @@ var NcHistoryEntrySchema = object({
15465
15465
  updatedAt: number(),
15466
15466
  /** Failure detail — present on a `dead` row. */
15467
15467
  error: string().optional(),
15468
- subject: NcHistorySubjectSchema
15468
+ subject: NcHistorySubjectSchema,
15469
+ /**
15470
+ * Ids of the artefacts (still, then gif, then clip) this row's successful
15471
+ * delivery indexed in the artefact library — a REFERENCE, never the bytes
15472
+ * (an artefact is often megabytes; this row is durable JSON rewritten on
15473
+ * every delivery attempt). Absent on a row still pending/dead, a row
15474
+ * delivered before this field shipped, or a wiring with no artefact index.
15475
+ *
15476
+ * Resolve one to a fetchable URL with `resolveArtifactUrl` — an id
15477
+ * outlives any one URL's TTL, so a caller mints a fresh link on demand
15478
+ * rather than trusting one frozen at delivery time. `resolveArtifactUrl`
15479
+ * also answers `null` for an id whose artefact has since expired past the
15480
+ * retained shelf's own age bound — the degrade a caller (the Home
15481
+ * Assistant export) must render as "no image right now", never as a
15482
+ * broken link.
15483
+ */
15484
+ artifactIds: array(string().min(1)).optional()
15469
15485
  });
15470
15486
  /**
15471
15487
  * Query filter for `getHistory` (spec §4.2). Every field is a narrowing
@@ -15692,7 +15708,7 @@ method(object({}), object({ rules: array(NcRuleSchema) }), { auth: "admin" }), m
15692
15708
  }), method(object({}), object({
15693
15709
  catalog: array(NcConditionDescriptorSchema),
15694
15710
  taxonomy: NcTaxonomySchema.optional()
15695
- })), 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 }), {
15711
+ })), 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 }), {
15696
15712
  kind: "mutation",
15697
15713
  caller: "required"
15698
15714
  }), method(object({ snoozeId: string() }), object({ success: literal(true) }), {
@@ -16032,896 +16048,1496 @@ var OauthIntegrationDescriptorSchema = object({
16032
16048
  });
16033
16049
  method(_void(), OauthIntegrationDescriptorSchema, { auth: "admin" });
16034
16050
  /**
16035
- * pipeline-analytics device-scoped wrapper cap. Refines raw
16036
- * per-frame detections emitted by the pipeline runner into tracked
16037
- * objects, per-kind event collections (motion / object / audio), and
16038
- * persisted media. Owns the post-detection domain end-to-end:
16039
- *
16040
- * runner emits PipelineInferenceResult
16041
- * ↓ (event bus)
16042
- * pipeline-analytics subscriber
16043
- * ↓ SORT tracker + zone engine + state analyzer + event emitter
16044
- * → three DB collections (one per kind), one FS media tree, one
16045
- * unified event emitter (FrameTracked + TrackStarted/Ended +
16046
- * DetectionEvent on bus)
16047
- *
16048
- * Pure subscriber model. No `processFrame` cap method — the runner
16049
- * already publishes the raw frame on the bus. The cap surface is
16050
- * only QUERIES + per-device settings, bound on/off via
16051
- * `device-manager.setWrapperActive`. `defaultActive: true` because
16052
- * every camera with a detection pipeline wants its raw detections
16053
- * refined; operators opt out per-device via BindingsTab when needed.
16054
- *
16055
- * Replaces the legacy `analysis-pipeline`, `analysis-data-persistence`
16056
- * (per-device surface) and `track-trail` caps — see P11 cleanup.
16051
+ * Reference to the frame's retained NATIVE surface + the parent crop's placement
16052
+ * within the frame, so the executor can re-cut a leaf child ROI at native
16053
+ * resolution on the detail plane. See the `runPipeline` `nativeCropRef` field.
16057
16054
  */
16058
- var TrackStateSchema = _enum([
16059
- "new",
16060
- "entered",
16061
- "left",
16062
- "moving",
16063
- "idle"
16064
- ]);
16065
- var EventKindSchema = _enum([
16066
- "motion",
16067
- "object",
16068
- "audio"
16069
- ]);
16055
+ var NativeCropRefSchema = object({
16056
+ /** Handle keying the retained native surface (node-pinned to its owner). */
16057
+ handle: FrameHandleSchema,
16058
+ /** The parent crop's padded/clamped rectangle in FRAME-space pixels. */
16059
+ cropFrameSpace: object({
16060
+ x: number(),
16061
+ y: number(),
16062
+ w: number(),
16063
+ h: number()
16064
+ })
16065
+ });
16066
+ object({
16067
+ crop: object({
16068
+ left: number(),
16069
+ top: number(),
16070
+ width: number().positive(),
16071
+ height: number().positive()
16072
+ }).optional(),
16073
+ content: object({
16074
+ width: number().int().positive(),
16075
+ height: number().int().positive()
16076
+ }),
16077
+ fit: _enum(["stretch", "contain"]),
16078
+ format: _enum([
16079
+ "rgb",
16080
+ "gray",
16081
+ "jpeg"
16082
+ ])
16083
+ });
16070
16084
  /**
16071
- * Spatial filter for `listTracks` the rect + polygon variants of the shared
16072
- * MaskShape vocabulary (see `mask-shape.ts`). Coordinates are NORMALIZED 0..1
16073
- * of the camera frame (top-left origin), matching the drawing-plane editor.
16085
+ * Process-local frame identity. It is serializable so it can ride an in-process
16086
+ * capability call, but `registryId` deliberately prevents resolution in any
16087
+ * other process or execution group.
16074
16088
  */
16075
- var TrackZoneFilterSchema = discriminatedUnion("kind", [MaskRectShapeSchema, MaskPolygonShapeSchema]);
16076
- /** Closed icon vocabulary so clients render a known glyph per kind. */
16077
- var EventKindIconSchema = _enum([
16078
- "motion",
16079
- "audio",
16080
- "person",
16081
- "vehicle",
16082
- "animal",
16083
- "door",
16084
- "pir",
16085
- "smoke",
16086
- "water",
16087
- "button",
16088
- "package",
16089
- "generic"
16089
+ var FrameRefSchema = object({
16090
+ registryId: string().min(1),
16091
+ id: string().min(1),
16092
+ width: number().int().positive(),
16093
+ height: number().int().positive(),
16094
+ format: _enum(["rgb", "gray"]),
16095
+ timestamp: number(),
16096
+ capturedAt: number().optional()
16097
+ });
16098
+ var ModelFormatSchema$1 = _enum([
16099
+ "onnx",
16100
+ "coreml",
16101
+ "openvino",
16102
+ "tflite",
16103
+ "pt",
16104
+ "gguf"
16090
16105
  ]);
16091
- var EventKindCategorySchema = _enum([
16092
- "motion",
16093
- "audio",
16094
- "detection",
16095
- "sensor",
16096
- "control",
16097
- "custom",
16098
- "package"
16106
+ var PipelineSlotSchema = _enum([
16107
+ "detector",
16108
+ "cropper",
16109
+ "classifier",
16110
+ "refiner",
16111
+ "audio-classifier"
16099
16112
  ]);
16100
- /** Taxonomy level — macro (timeline lane) vs sub (events-page leaf). */
16101
- var EventKindLevelSchema = _enum(["macro", "sub"]);
16102
- var EventKindDescriptorSchema = object({
16103
- /** Stable kind id (e.g. 'motion', 'vehicle', 'car', 'lock'). */
16104
- kind: string(),
16105
- /** i18n key resolved on the UI side; `label` is the English fallback. */
16106
- labelKey: string(),
16107
- /** English fallback label (kept for clients that don't translate). */
16108
- label: string(),
16109
- /** Hex color for timeline/legend rendering. */
16110
- color: string(),
16111
- /** Dictionary id → lucide component on the UI side. */
16112
- iconId: string(),
16113
- /** Legacy closed-vocab glyph — fallback for `iconId`. */
16114
- icon: EventKindIconSchema,
16115
- category: EventKindCategorySchema,
16116
- /** Macro parent for this kind ('car' → 'vehicle'); null for a macro. */
16117
- parentKind: string().nullable(),
16118
- /** Derived from `parentKind`, explicit for the client tree. */
16119
- level: EventKindLevelSchema,
16120
- /** Which cap + device contributes this kind. For built-ins the camera
16121
- * itself; for sensor kinds the LINKED source device. */
16122
- source: object({
16123
- capName: string(),
16124
- deviceId: number()
16125
- })
16113
+ var PipelineEngineChoiceSchema = object({
16114
+ runtime: _enum(["node", "python"]),
16115
+ backend: string(),
16116
+ format: ModelFormatSchema$1,
16117
+ device: string().optional()
16126
16118
  });
16127
- /** One camera's event vocabulary, as returned by `listEventKindsBatch`. */
16128
- var EventKindsForDeviceSchema = object({
16129
- deviceId: number(),
16130
- kinds: array(EventKindDescriptorSchema).readonly()
16119
+ var AvailableEngineSchema = object({
16120
+ engine: PipelineEngineChoiceSchema,
16121
+ devices: array(object({
16122
+ id: string(),
16123
+ label: string(),
16124
+ description: string().optional()
16125
+ })).readonly(),
16126
+ defaultDevice: string()
16131
16127
  });
16132
- var SensorEventSchema = object({
16128
+ var PipelineDefaultStepSchema = lazy(() => object({
16129
+ addonId: string(),
16130
+ addonName: string(),
16131
+ slot: PipelineSlotSchema,
16132
+ inputClasses: array(string()).readonly(),
16133
+ outputClasses: array(string()).readonly(),
16134
+ enabled: boolean(),
16135
+ modelId: string(),
16136
+ children: array(PipelineDefaultStepSchema).readonly(),
16137
+ group: string().optional(),
16138
+ settings: record(string(), unknown()).optional()
16139
+ }));
16140
+ var PipelineTemplateStepSchema = lazy(() => object({
16141
+ addonId: string(),
16142
+ enabled: boolean(),
16143
+ modelId: string(),
16144
+ children: array(PipelineTemplateStepSchema).readonly(),
16145
+ settings: record(string(), unknown()).optional()
16146
+ }));
16147
+ var PipelineTemplateSchema$1 = object({
16133
16148
  id: string(),
16134
- /** The CAMERA the event is attributed to (a sensor linked to N cameras
16135
- * yields N rows, one per camera). */
16136
- deviceId: number(),
16137
- /** The linked sensor device whose state changed. */
16138
- sourceDeviceId: number(),
16139
- /** Event kind id — matches an `EventKindDescriptor.kind`. */
16140
- kind: string(),
16141
- /** Snapshot of the sensor cap's runtime-state slice at the change. */
16142
- value: record(string(), unknown()).nullable(),
16143
- timestamp: number()
16149
+ name: string(),
16150
+ createdAt: string(),
16151
+ updatedAt: string(),
16152
+ engine: PipelineEngineChoiceSchema,
16153
+ steps: array(PipelineTemplateStepSchema).readonly()
16144
16154
  });
16145
- var TrackPositionSchema = object({
16146
- x: number(),
16147
- y: number(),
16148
- timestamp: number(),
16149
- bbox: BoundingBoxSchema
16155
+ var PipelineModelOptionSchema = object({
16156
+ id: string(),
16157
+ name: string(),
16158
+ formats: record(string(), object({
16159
+ downloaded: boolean(),
16160
+ sizeMB: number()
16161
+ })),
16162
+ group: ModelVariantGroupSchema.optional(),
16163
+ legacy: boolean().optional(),
16164
+ provider: ModelProviderIdSchema.optional()
16150
16165
  });
16151
- var TrackSnapshotSchema = object({
16152
- timestamp: number(),
16153
- position: TrackPositionSchema,
16154
- /** MediaStore key; resolve via `getTrackMedia({ trackId })`. */
16155
- mediaKey: string()
16166
+ var ConfigFieldBridge = custom();
16167
+ var PipelineAddonSchemaSchema = object({
16168
+ id: string(),
16169
+ name: string(),
16170
+ slot: PipelineSlotSchema,
16171
+ inputClasses: array(string()).readonly(),
16172
+ outputClasses: array(string()).readonly(),
16173
+ childSlots: array(PipelineSlotSchema).readonly(),
16174
+ models: array(PipelineModelOptionSchema).readonly(),
16175
+ defaultModelId: string(),
16176
+ defaultModelIdByFormat: record(string(), string()).optional(),
16177
+ enabledByDefault: boolean().optional(),
16178
+ backfillIntoExistingOverrides: boolean().optional(),
16179
+ defaultConfidence: number(),
16180
+ group: string().optional(),
16181
+ configSchema: array(ConfigFieldBridge).readonly().optional()
16156
16182
  });
16157
- /**
16158
- * Normalized 0..1 trajectory envelope (min/max over every position bbox,
16159
- * divided by the track's detection-frame dims), computed at persist time.
16160
- * Absent when the frame dims were unknown when the track was persisted
16161
- * (legacy rows / dims-less sources) and on active (in-RAM) tracks.
16162
- */
16163
- var TrackEnvelopeSchema = object({
16164
- minX: number(),
16165
- minY: number(),
16166
- maxX: number(),
16167
- maxY: number()
16183
+ var PipelineSlotSchemaSchema = object({
16184
+ id: PipelineSlotSchema,
16185
+ label: string(),
16186
+ priority: number(),
16187
+ parentSlot: PipelineSlotSchema.nullable(),
16188
+ addons: array(PipelineAddonSchemaSchema).readonly()
16168
16189
  });
16169
- /**
16170
- * Row projection for track list queries. `full` (default) returns the
16171
- * complete Track including the frame-rate `positions[]` history and the
16172
- * `snapshots[]` references — megabytes across a page of tracks. `slim`
16173
- * keeps every scalar the list surfaces actually render (ids, class(es),
16174
- * label / audioLabels / importance enrichment, firstSeen/lastSeen, state,
16175
- * zonesVisited, bestEventId, envelope, hasFace, hasEmbeddedFace, hasRider) and returns `positions` /
16176
- * `snapshots` as EMPTY arrays — detail views re-fetch the full row via
16177
- * `getTrack`. Mirrors the event-store `projection` convention
16178
- * (`getObjectEvents` et al.).
16179
- */
16180
- var TrackProjectionSchema = _enum(["full", "slim"]);
16181
- /**
16182
- * One audio-classification label heard on the track's camera while the
16183
- * track was alive, aggregated per label. An "episode" is one persisted
16184
- * audio event (the confident-classification path: score ≥ the device's
16185
- * `classificationMinScore`, class-change-or-heartbeat coalesced) — NOT
16186
- * one 32 ms inference chunk, so counts stay human-scaled.
16187
- */
16188
- var TrackAudioLabelSchema = object({
16189
- label: string(),
16190
- /** Highest classification score observed across the label's episodes. */
16191
- peakScore: number(),
16192
- /** Number of coalesced audio-event episodes carrying this label. */
16193
- count: number(),
16194
- firstAt: number(),
16195
- lastAt: number()
16190
+ var PipelineSchemaSchema = object({
16191
+ availableEngines: array(AvailableEngineSchema).readonly(),
16192
+ selectedEngine: PipelineEngineChoiceSchema,
16193
+ slots: array(PipelineSlotSchemaSchema).readonly()
16196
16194
  });
16197
- /**
16198
- * How a track was produced. `pipeline` (default / absent) = the spatial
16199
- * detection+tracking pipeline. Every OTHER value is a SYNTHETIC projection —
16200
- * no positions, a single snapshot, and no bbox trajectory at all:
16201
- *
16202
- * - `sensor` — a linked sensor/control device state change.
16203
- * - `audio` — an audio event on the camera itself that was anomalous for
16204
- * THAT camera, loud, and heard while nothing visual was happening (D62).
16205
- *
16206
- * The spatial subsystems (tracker association, occupancy count, re-id /
16207
- * embedding, resurrection) MUST skip every synthetic source. Test for that
16208
- * with `isSpatialTrack`, which allow-lists `pipeline` — a `!== 'sensor'`
16209
- * check silently readmits every source added after it was written.
16210
- */
16211
- var TrackSourceSchema = _enum([
16212
- "pipeline",
16213
- "sensor",
16214
- "audio"
16215
- ]);
16216
- /**
16217
- * Where a track sits in the RETRAIN lifecycle (D81).
16218
- *
16219
- * - `none` never marked, or un-marked. Evictable.
16220
- * - `staging`the operator wants this track as training material and has not
16221
- * finished with it. **This is the only state retention holds**: the track and
16222
- * everything it owns (object events, crops, keyframes, CLIP vector) survive
16223
- * the device's age window.
16224
- * - `trained` — the retrain page has taken what it needed. The frames it chose
16225
- * were COPIED into the retrain dataset at selection time, so the dataset no
16226
- * longer depends on the track's media and the track becomes EVICTABLE again.
16227
- * Terminal for the plain `markForTrain` toggle: returning it to `staging` is
16228
- * a deliberate action of the retrain page, not a side effect of a checkbox.
16229
- *
16230
- * There is no `null`. The state is stored `TEXT NOT NULL DEFAULT 'none'` because
16231
- * the store's filter language has only positive equality and `whereIn` — no
16232
- * negation, no IS NULL — so a NULL would be unselectable by ANY predicate and
16233
- * would make the entire pre-column history immortal in one deploy.
16234
- */
16235
- var RetrainStatusSchema = _enum([
16236
- "none",
16237
- "staging",
16238
- "trained"
16239
- ]);
16240
- /**
16241
- * Per-track OPERATOR flags — set by hand from the admin UI or the viewer, never
16242
- * by the pipeline. Spread into `TrackSchema` and `KeyEventSchema` from one place
16243
- * so the two surfaces cannot drift.
16244
- *
16245
- * **Absent ≠ false.** A track that has never been touched omits the field; an
16246
- * explicitly un-flagged track carries `false`. Legacy rows written before the
16247
- * columns existed read as absent, and a consumer that needs a boolean should say
16248
- * `flag === true`, not `flag !== false`.
16249
- *
16250
- * `markForTrain` is the WIRE FACE of {@link RetrainStatusSchema}, not a column:
16251
- * it is exactly `retrainStatus === 'staging'`, in both directions. Writing
16252
- * `true` moves `none → staging`, writing `false` moves `staging → none`, and a
16253
- * `trained` track reports `false` while refusing both writes. The boolean is
16254
- * kept because three surfaces drive a toggle off it; anything that needs to tell
16255
- * "never marked" from "already trained" must read `retrainStatus`.
16256
- *
16257
- * `debug` does NOT pin; it is attention, not durability.
16258
- *
16259
- * `favourited` IS a BOOLEAN pin (durability bit), not a retrain lifecycle.
16260
- * A favourited track is skipped by retention the same way `staging` is, but
16261
- * it does not enter `none|staging|trained` and has no staging budget.
16262
- */
16263
- var TrackFlagFields = {
16264
- /** Operator marked this track as training material — i.e. `retrainStatus` is
16265
- * `'staging'`. */
16266
- markForTrain: boolean().optional(),
16267
- /** Operator marked this track for diagnostic attention. */
16268
- debug: boolean().optional(),
16269
- /** Operator favourited this track. Pins it against pruning. */
16270
- favourited: boolean().optional()
16271
- };
16272
- /**
16273
- * The lifecycle field itself, on the READ surfaces only (`Track`, `KeyEvent`).
16274
- * Deliberately NOT part of {@link TrackFlagFields}: that group also builds the
16275
- * write patch, and the status is not something the toggle sets — it is what the
16276
- * toggle's boolean is derived from. Absent on an in-RAM track never touched;
16277
- * always present on a persisted row (the column default materialises `'none'`).
16278
- */
16279
- var TrackRetrainFields = { retrainStatus: RetrainStatusSchema.optional() };
16280
- /**
16281
- * The write half: a PARTIAL patch. An omitted key is left untouched, so setting
16282
- * one flag can never clear the other — the toggles are independent and are
16283
- * driven from three surfaces that do not know about each other.
16284
- */
16285
- var TrackFlagsPatchSchema = object(TrackFlagFields);
16286
- /**
16287
- * The resolved flag state after a write. Both fields are REQUIRED here (absent
16288
- * collapses to `false`) so a caller can drive a toggle's checked state off the
16289
- * mutation result without a re-fetch.
16290
- */
16291
- var TrackFlagsSchema = object({
16292
- trackId: string(),
16293
- markForTrain: boolean(),
16294
- debug: boolean(),
16295
- favourited: boolean(),
16296
- /** The lifecycle state the boolean was derived from. Required here (unlike on
16297
- * a track row) because this shape is only ever produced by the write body,
16298
- * which always knows it — and a surface that has just written needs to render
16299
- * `trained` without a re-fetch. */
16300
- retrainStatus: RetrainStatusSchema
16195
+ var EngineProvisioningSchema = object({
16196
+ runtimeId: _enum([
16197
+ "onnx",
16198
+ "openvino",
16199
+ "coreml",
16200
+ "edgetpu"
16201
+ ]).nullable(),
16202
+ device: string().nullable(),
16203
+ state: _enum([
16204
+ "idle",
16205
+ "installing",
16206
+ "verifying",
16207
+ "ready",
16208
+ "failed"
16209
+ ]),
16210
+ progress: number().optional(),
16211
+ error: string().optional(),
16212
+ nextRetryAt: number().optional(),
16213
+ /**
16214
+ * Gate A (config-correctness gate at engine change): human-readable
16215
+ * config issues surfaced EAGERLY when the node's engine changes — model
16216
+ * substitutions ("chose X, running Y") and zero-build steps ("no model
16217
+ * has a <format> build"). Additive/optional: informational only, never
16218
+ * enforced here `assertEngineReady` (readiness) still gates inference.
16219
+ * Absent/empty when the node-default tree resolves cleanly.
16220
+ */
16221
+ configIssues: array(string()).optional()
16301
16222
  });
16302
- union([literal(1), literal(2)]);
16303
- /**
16304
- * WHO decided a label, and when. Carried per tier so a value can be traced to
16305
- * the step and model that produced it — which is what makes the write rule
16306
- * arguable after the fact ("why is 592's label `dog` and not `Canis lupus`?")
16307
- * and what lets a migrated, UNATTRIBUTED value be told apart from a real one.
16308
- *
16309
- * `stepId` is the pipeline step id (`animal-classifier`, `bird-classifier`,
16310
- * `plate-ocr`, `face-embedding`, `object-detection`), or the sentinel
16311
- * `migration:4g` for a value the 4g migration moved from the single-slot era —
16312
- * that value has no provenance, and the write rule lets ANY properly-attributed
16313
- * write of the same tier replace it regardless of score.
16314
- */
16315
- var LabelAttributionSchema = object({
16316
- stepId: string(),
16223
+ var PipelineStepInputSchema = lazy(() => object({
16224
+ addonId: string(),
16317
16225
  modelId: string().optional(),
16318
- decidedAt: number(),
16226
+ enabled: boolean().default(true),
16227
+ children: array(PipelineStepInputSchema).optional(),
16228
+ settings: record(string(), unknown()).optional(),
16229
+ jumpDeviceKey: string().optional()
16230
+ }));
16231
+ var ModelSubstitutionSchema = object({
16232
+ addonId: string(),
16233
+ chosen: string(),
16234
+ running: string(),
16235
+ format: string()
16236
+ });
16237
+ var PipelineValidationIssueSchema = object({
16238
+ addonId: string(),
16239
+ kind: _enum(["unknown-addon", "no-format-build"]),
16240
+ detail: string()
16241
+ });
16242
+ var PipelineValidationResultSchema = object({
16243
+ ok: boolean(),
16244
+ issues: array(PipelineValidationIssueSchema).readonly(),
16245
+ substitutions: array(ModelSubstitutionSchema).readonly(),
16246
+ /** The node's `currentEngine.format` this validation ran against. */
16247
+ format: string()
16248
+ });
16249
+ var ReferenceImageEntrySchema = object({
16250
+ filename: string(),
16251
+ stepIds: array(string()).readonly().optional()
16252
+ });
16253
+ var ReferenceImageBodySchema = object({
16254
+ base64: string(),
16255
+ filename: string()
16256
+ });
16257
+ var ReferenceAudioEntrySchema = object({
16258
+ filename: string(),
16259
+ sizeKb: number()
16260
+ });
16261
+ var ReferenceAudioBodySchema = object({ base64: string() });
16262
+ var AudioBackendSchema = object({
16263
+ id: string(),
16264
+ name: string(),
16265
+ description: string(),
16266
+ available: boolean(),
16319
16267
  /**
16320
- * The GALLERY id behind a recognised tier-2 label — a face-gallery
16321
- * `Identity.id` or a plate-gallery `Vehicle.id` (both `randomUUID`).
16322
- *
16323
- * The text alone is a DISPLAY NAME, and a display name is renameable: a
16324
- * notification rule authored on "Gianluca" stopped matching the moment the
16325
- * operator fixed the spelling in the gallery, and nothing said so. The id is
16326
- * the thing that does not move, so it is what a rule matches on
16327
- * (`NcConditions.identities`) and the text is what a human is shown.
16328
- *
16329
- * Absent when the label names no gallery row — a plate the OCR read but no
16330
- * vehicle claims, a sub-class, a species, any tier-1 value.
16268
+ * Raw classifier labels this backend can emit (e.g. YAMNet's
16269
+ * 521-class set or Apple SoundAnalysis's 303-class set). Used by
16270
+ * the benchmark UI to populate the `enabledMicroClasses` filter
16271
+ * specific to the selected backend without a separate fetch.
16331
16272
  */
16332
- identityId: string().optional()
16273
+ rawLabels: array(string()).readonly().optional()
16274
+ });
16275
+ var AudioCapabilitiesSchema = object({
16276
+ activeBackend: string(),
16277
+ availableBackends: array(AudioBackendSchema).readonly(),
16278
+ sampleRate: number(),
16279
+ chunkDurationMs: number()
16280
+ });
16281
+ var DownloadModelResultSchema = object({
16282
+ filePath: string(),
16283
+ sizeMB: number(),
16284
+ durationMs: number()
16333
16285
  });
16334
16286
  /**
16335
- * The TIERED label model (roadmap 4g), spread into `TrackSchema` and
16336
- * `ObjectEventSchema` from ONE place so the two surfaces cannot drift — a
16337
- * track and its events always answer the same question the same way.
16338
- *
16339
- * Two scalar columns, not an array: every consumer wants "the coarse one" or
16340
- * "the fine one", and an array made both a scan. `label` is tier 1, `subLabel`
16341
- * is tier 2, and each carries its own score + attribution.
16342
- *
16343
- * **Reading it.** What a human should be shown is `subLabel ?? label` — the
16344
- * finest thing known. Before 4g the single `label` column held the finest
16345
- * value, so a consumer that has not been updated reads the tier-1 slot and
16346
- * shows nothing on a species-only row; that is why the migration puts every
16347
- * pre-4g value in tier 2 (it cannot regress a display that reads the fallback)
16348
- * and why the read surfaces were changed in the same train.
16349
- *
16350
- * **Writing it.** The slots are independent, which is the whole point: a
16351
- * tier-1 write (`bird`) can never overwrite a tier-2 value (`Turdus
16352
- * migratorius`), so fineness cannot regress by construction. Within a tier the
16353
- * higher score wins. One rule, one implementation — see
16354
- * `pipeline/label-tier.ts` in addon-post-analysis.
16355
- */
16356
- var TieredLabelFields = {
16357
- /** Tier 1 — the sub-class. See {@link LabelTierSchema}. */
16358
- label: string().optional(),
16359
- /** Confidence of the tier-1 value, as reported by the deciding step. */
16360
- labelScore: number().optional(),
16361
- /** Provenance of the tier-1 value. See {@link LabelAttributionSchema}. */
16362
- labelMeta: LabelAttributionSchema.optional(),
16363
- /** Tier 2 — the instance. See {@link LabelTierSchema}. */
16364
- subLabel: string().optional(),
16365
- /** Confidence of the tier-2 value, as reported by the deciding step. */
16366
- subLabelScore: number().optional(),
16367
- /** Provenance of the tier-2 value. See {@link LabelAttributionSchema}. */
16368
- subLabelMeta: LabelAttributionSchema.optional()
16369
- };
16370
- /** Per-camera slice of a training-export estimate. */
16371
- var TrainingExportDeviceTotalsSchema = object({
16372
- deviceId: number(),
16373
- tracks: number().int(),
16374
- files: number().int(),
16375
- bytes: number().int()
16376
- });
16377
- /**
16378
- * What a training export WOULD contain. Computed from media index rows only —
16379
- * no blob is read to produce this.
16287
+ * Wrapper carrying a single test run's result. Replaces the legacy
16288
+ * ad-hoc `{labels: [{className, originalClass, score}]}` shape with the
16289
+ * canonical `AudioResult` from the Phase 6 output rework: one
16290
+ * `AudioDetection` per class above `minScore`, top-N candidates in
16291
+ * `debug.alternateLabels['audio-classifier']`, per-source timings in
16292
+ * `debug.stepTimings`. The outer `success`/`error` fields stay so the
16293
+ * benchmark UI can still report a clean failure when the classifier
16294
+ * cap isn't available.
16380
16295
  */
16381
- var TrainingExportSummarySchema = object({
16382
- generatedAt: number(),
16383
- trackCount: number().int(),
16384
- fileCount: number().int(),
16385
- byteCount: number().int(),
16386
- /** More marked tracks exist than a single pass carries. */
16387
- truncated: boolean(),
16388
- devices: array(TrainingExportDeviceTotalsSchema).readonly()
16296
+ var AudioTestResultSchema = object({
16297
+ success: boolean(),
16298
+ error: string().optional(),
16299
+ frame: custom().optional()
16389
16300
  });
16390
- var TrackSchema = object({
16391
- trackId: string(),
16392
- deviceId: number(),
16393
- className: string(),
16394
- ...TieredLabelFields,
16395
- producingDeviceName: string().optional(),
16396
- /** Track provenance. Absent `pipeline` (legacy rows). */
16397
- source: TrackSourceSchema.optional(),
16398
- firstSeen: number(),
16399
- lastSeen: number(),
16400
- /** Frame-rate position history (subject to maxPositionHistory cap). */
16401
- positions: array(TrackPositionSchema).readonly(),
16402
- /** Periodic snapshots at snapshotIntervalMs cadence (subject to
16403
- * saveThumbnails policy). */
16404
- snapshots: array(TrackSnapshotSchema).readonly(),
16405
- /** Deduplicated zones the track has entered at least once. Zone IDS. */
16406
- zonesVisited: array(string()).readonly(),
16301
+ var PipelineConfigBridge = custom();
16302
+ var ConfigUISchemaBridge = custom();
16303
+ var ConfigUISchemaNullableBridge = custom();
16304
+ var InferenceCapabilitiesBridge = custom();
16305
+ var ModelAvailabilityListBridge = custom();
16306
+ var PipelineRunResultBridge = custom();
16307
+ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngineChoiceSchema), method(PipelineEngineChoiceSchema, array(PipelineDefaultStepSchema)), method(object({ nodeId: string() }), EngineProvisioningSchema), method(_void(), record(string(), object({
16308
+ modelId: string(),
16309
+ settings: record(string(), unknown()).readonly()
16310
+ }))), method(object({ steps: record(string(), object({
16311
+ modelId: string(),
16312
+ settings: record(string(), unknown()).readonly()
16313
+ })) }), object({ success: literal(true) }), {
16314
+ kind: "mutation",
16315
+ auth: "admin"
16316
+ }), method(object({ nodeId: string() }), object({
16317
+ success: literal(true),
16318
+ clearedDevices: number()
16319
+ }), {
16320
+ kind: "mutation",
16321
+ auth: "admin"
16322
+ }), method(object({ nodeId: string() }), object({ unhealthy: array(object({
16323
+ /** `<backend>:<device>`, e.g. `openvino:gpu`. */
16324
+ deviceKey: string(),
16407
16325
  /**
16408
- * Human NAMES for {@link zonesVisited}, resolved at READ time against the
16409
- * `zones` capability.
16410
- *
16411
- * `zonesVisited` persists ids (`cfeec78c-8d69-…`), which no operator can type
16412
- * and no card can render — so every free-text search surface was structurally
16413
- * unable to answer "show me the tracks in Uscio", and did not fail loudly, it
16414
- * just returned nothing. Resolving here rather than in each client keeps ONE
16415
- * derivation and costs the clients no extra call (the `zones` cap is
16416
- * per-device, so a client-side resolve would be a per-camera fan-out on a
16417
- * surface built to avoid exactly that).
16418
- *
16419
- * Resolved, never invented: a zone deleted since the track was written has no
16420
- * name and is DROPPED, so this array can be shorter than `zonesVisited` — the
16421
- * two are not positionally aligned. Absent when the track visited no zone, or
16422
- * when the zone catalogue could not be read.
16326
+ * `failed` the per-device restart budget is exhausted; no pool
16327
+ * will be spawned until an operator re-arms it or the runner
16328
+ * respawns. `backoff` — under budget, waiting out the backoff (or
16329
+ * a cached pool observed dead and not yet condemned).
16423
16330
  */
16424
- zoneNames: array(string()).readonly().optional(),
16425
- /** Deduplicated set of detector classes observed for this track over its
16426
- * life (a track may be reclassified, e.g. person→vehicle). Absent on
16427
- * legacy rows written before class accumulation shipped. */
16428
- classes: array(string()).readonly().optional(),
16429
- /** Cumulative normalized distance travelled (0..1 units = full frame width). */
16430
- totalDistance: number(),
16431
- state: TrackStateSchema,
16432
- active: boolean(),
16433
- /** Deterministic key-event importance score in [0,1] (server-computed at
16434
- * track expiry, recomputed on late label). Absent on legacy rows written
16435
- * before scoring shipped — consumers degrade to absence / compute-on-read. */
16436
- importance: number().optional(),
16437
- /** Id of the track's highest-confidence ObjectEvent (its representative
16438
- * "best" frame). Absent when the track produced no object events. */
16439
- bestEventId: string().optional(),
16440
- /** Tag of the importance sub-signal that dominated the score
16441
- * (identity|dwell|proximity|class|confidence|travel|zone). */
16442
- importanceReason: string().optional(),
16443
- /** Audio-classification labels heard on the camera during the track's
16444
- * life (score ≥ device `classificationMinScore`), aggregated per label.
16445
- * Absent on legacy rows / tracks with no confident audio. */
16446
- audioLabels: array(TrackAudioLabelSchema).readonly().optional(),
16447
- /** Normalized 0..1 trajectory envelope (see {@link TrackEnvelopeSchema}).
16448
- * Populated from the persisted envelope columns on historical reads;
16449
- * absent on legacy rows, dims-less tracks and active (in-RAM) tracks. */
16450
- envelope: TrackEnvelopeSchema.optional(),
16331
+ state: _enum(["failed", "backoff"]),
16332
+ /** Epoch ms of the death that produced this state. */
16333
+ since: number(),
16334
+ /** Pool deaths inside the current window. */
16335
+ deaths: number(),
16336
+ /** The last death's message. */
16337
+ lastError: string()
16338
+ })).readonly() })), method(object({
16339
+ nodeId: string(),
16340
+ deviceKey: string()
16341
+ }), object({ rearmed: boolean() }), {
16342
+ kind: "mutation",
16343
+ auth: "admin"
16344
+ }), 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({
16345
+ name: string(),
16346
+ steps: array(PipelineTemplateStepSchema).readonly(),
16347
+ engine: PipelineEngineChoiceSchema
16348
+ }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({
16349
+ id: string(),
16350
+ name: string().optional(),
16351
+ steps: array(PipelineTemplateStepSchema).readonly().optional()
16352
+ }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({ id: string() }), _void(), { kind: "mutation" }), method(_void(), InferenceCapabilitiesBridge), method(object({ addonId: string() }), ModelAvailabilityListBridge), method(object({
16353
+ addonId: string(),
16354
+ modelId: string(),
16355
+ format: ModelFormatSchema$1
16356
+ }), DownloadModelResultSchema, { kind: "mutation" }), method(object({
16357
+ addonId: string(),
16358
+ modelId: string(),
16359
+ format: ModelFormatSchema$1
16360
+ }), object({ success: literal(true) }), { kind: "mutation" }), method(object({
16361
+ engine: PipelineEngineChoiceSchema.optional(),
16362
+ steps: array(PipelineStepInputSchema).min(1),
16363
+ frame: FrameInputSchema.optional(),
16451
16364
  /**
16452
- * A face DETECTOR found a face on this track — nothing more. It says the
16453
- * detail plane produced a `face` detail; it does NOT say the face was
16454
- * embedded, matched, above `minFacePx`, or that the recognizer was even
16455
- * enabled. Set once and never cleared.
16456
- *
16457
- * **This exists so "face present but not recognised" is expressible.** A
16458
- * recognised identity lands in `subLabel` (attributed to the face chain via
16459
- * `subLabelMeta.stepId`), so before this field a track with an unmatched face
16460
- * and a track with no face at all were byte-identical on the wire and no
16461
- * surface could tell them apart. The read is `hasFace === true && subLabel
16462
- * === undefined`.
16463
- *
16464
- * **Absent ≠ false.** Every row written before the column existed omits it,
16465
- * and so does every server that predates the field — a consumer must test
16466
- * `=== true` and render nothing otherwise, never infer "no face".
16365
+ * Process-local lazy frame. Valid only when caller and provider resolve
16366
+ * in the same execution-group process; split/cross-node callers use
16367
+ * `frame`/`image` inline compatibility instead.
16467
16368
  */
16468
- hasFace: boolean().optional(),
16369
+ frameRef: FrameRefSchema.optional(),
16469
16370
  /**
16470
- * This track has a face row IN THE GALLERY: a crop **and** an embedding a
16471
- * face an operator could ASSIGN to an identity.
16472
- *
16473
- * The STRICT twin of {@link hasFace}, and the pair only earns its keep
16474
- * because the two disagree. `hasFace` is stamped at the TOP of the face
16475
- * branch, before every gate, and means no more than "a face detector produced
16476
- * a face detail". This one is stamped at the single moment the gallery row
16477
- * LANDS — after `FaceRecognizer.onTrackEnd` successfully persists it, i.e.
16478
- * past the embedding-magnitude verdict, the `minFacePx` detection gate, the
16479
- * candidate gate, the imageless-track drop (no crop was ever captured) and
16480
- * the crop-store drop. Everything between the detector and that insert can
16481
- * legitimately refuse the face, so a flag written any earlier promises the
16482
- * operator something to assign and delivers nothing.
16483
- *
16484
- * **Independent of recognition.** A face collected but never auto-matched is
16485
- * still assignable — it is in fact the face an operator most wants to reach —
16486
- * so this is NOT gated on `recognizedIdentityId`. Recognition lands in
16487
- * `subLabel`; this says only that the raw material exists.
16488
- *
16489
- * **Set once, never cleared.** A track that produced a gallery row produced
16490
- * one; deleting the row later is the gallery's business, not this flag's.
16491
- *
16492
- * **Absent ≠ false**, the same rule as {@link hasFace}: every row written
16493
- * before the column omits it, and so does every server that predates the
16494
- * field. A consumer must test `=== true` and render nothing otherwise —
16495
- * never infer "no assignable face".
16371
+ * CB5 shm passthrough a `FrameHandle` naming the same ring slot
16372
+ * the decoded pixels live in. One more member of the one-of
16373
+ * frame/frameHandle/image/imageBase64/referenceImage group.
16496
16374
  */
16497
- hasEmbeddedFace: boolean().optional(),
16375
+ frameHandle: FrameHandleSchema.optional(),
16376
+ imageBase64: string().optional(),
16498
16377
  /**
16499
- * This subject CONTAINS a folded rider a person the rider-pairing step
16500
- * ([D34](../decisions/adr-0034.md)) removed from the frame BEFORE the tracker,
16501
- * so the passage is tracked once and as a VEHICLE.
16502
- *
16503
- * It exists because the fold's record was dishonest. D34 and the code both
16504
- * said "the person is not lost — it is reported so both entities stay on the
16505
- * record"; in fact the pair went into a per-processor RAM field behind an
16506
- * accessor nobody called, and every durable surface said `vehicle`, full
16507
- * stop. This is the composition note that makes the row true.
16508
- *
16509
- * A COMPOSITION, never a class and never a label. "This vehicle contains a
16510
- * person" is not an answer to "what is this" — both label tiers would refuse
16511
- * a macro token anyway (D89), and correctly. Nothing here changes what the
16512
- * subject IS: a cyclist stays one vehicle track, occupancy still counts one,
16513
- * and a `person` rule still does not fire for someone cycling past.
16514
- *
16515
- * **Absent ≠ false**, exactly like {@link hasFace}: every row written before
16516
- * the column, and every hub that predates the field, omits it. Test
16517
- * `=== true` and render nothing otherwise — never infer "no rider".
16378
+ * Binary JPEG bytespreferred over `imageBase64` on internal
16379
+ * hops (hub forked worker via Moleculer MsgPack) because it
16380
+ * skips the 33% base64 overhead + the per-call base64 decode on
16381
+ * the detection-pipeline worker. Callers can pass either; exactly
16382
+ * one of `frame`/`image`/`imageBase64`/`referenceImage` is required.
16518
16383
  */
16519
- hasRider: boolean().optional(),
16520
- ...TrackFlagFields,
16521
- ...TrackRetrainFields
16522
- });
16523
- var BaseEventFields = {
16524
- id: string(),
16525
- deviceId: number(),
16526
- timestamp: number()
16527
- };
16528
- var MotionEventSchema = object({
16529
- ...BaseEventFields,
16530
- kind: literal("motion"),
16531
- regionCount: number(),
16532
- /** Heavy JSON array omitted in slim projection. */
16533
- regions: array(object({
16534
- bbox: BoundingBoxSchema,
16535
- pixelCount: number(),
16536
- intensity: number()
16537
- })).readonly().optional(),
16538
- /** Omitted in slim projection. */
16539
- frameWidth: number().optional(),
16540
- /** Omitted in slim projection. */
16541
- frameHeight: number().optional(),
16542
- /** Populated by B5 (recording playback URL for this event). */
16543
- mediaUrl: string().optional()
16544
- });
16384
+ image: _instanceof(Uint8Array).optional(),
16385
+ referenceImage: string().optional(),
16386
+ deviceId: number().optional(),
16387
+ sessionId: string().optional(),
16388
+ /**
16389
+ * Execution plane. 'full' (default) runs the whole tree — benchmark,
16390
+ * reference-image, and detail-subtree calls. 'frame' is the live
16391
+ * per-frame dispatch: ONLY root-plane steps run; crop children
16392
+ * (inputClasses ≠ null) are skipped and served per-track via
16393
+ * pipelineRunner.runDetailSubtree (two-plane design).
16394
+ */
16395
+ plane: _enum(["full", "frame"]).optional(),
16396
+ /**
16397
+ * Inference-device selector (Phase 2 multi-device). Format
16398
+ * `<backend>:<device>` (e.g. `openvino:gpu`, `edgetpu:usb`, `cpu`).
16399
+ * Omitted ⇒ the runner's default device (current single-engine
16400
+ * behaviour). Selects WHICH device pool of the node runs the call.
16401
+ */
16402
+ deviceKey: string().optional(),
16403
+ /**
16404
+ * Two-plane NATIVE child-crop reference. Set by `runDetailSubtree` ONLY
16405
+ * when the parent crop was resolved from the frame's retained NATIVE
16406
+ * surface (a frameHandle HIT). Lets the executor re-cut a LEAF crop
16407
+ * child's ROI (plate-ocr, face-embedding, leaf classifiers) at native
16408
+ * resolution from that surface — the SAME quality path faces already
16409
+ * had — instead of the downscaled parent tile. `handle` keys the native
16410
+ * surface (node-pinned to its owner); `cropFrameSpace` is the parent
16411
+ * crop's padded/clamped rectangle in FRAME-space pixels, used to compose
16412
+ * the executor's crop-normalized child ROI back into frame-normalized
16413
+ * coordinates. Auxiliary to the image source (`image`/`frame`/…), NOT one
16414
+ * of the mutually-exclusive image inputs. Absent ⇒ tile-crop children
16415
+ * (today's behaviour on the fallback path).
16416
+ */
16417
+ nativeCropRef: NativeCropRefSchema.optional()
16418
+ }), PipelineRunResultBridge, { kind: "mutation" }), method(object({
16419
+ engine: PipelineEngineChoiceSchema.optional(),
16420
+ steps: array(PipelineStepInputSchema).min(1),
16421
+ frames: array(FrameInputSchema).min(1).max(255),
16422
+ deviceId: number().optional(),
16423
+ sessionId: string().optional(),
16424
+ /**
16425
+ * Pure-inference benchmark hint. A NONZERO uint32 pins every frame in
16426
+ * the batch to the Python pool's bench preprocess cache
16427
+ * (`_bench_frame_id`) so a REPEATED benchmark frame is decoded +
16428
+ * preprocessed ONCE and every later inference is a pure-inference cache
16429
+ * hit — the sustained-throughput run measures inference, not
16430
+ * decode+preprocess+infer. Omitted/0 for live frames (all different →
16431
+ * full preprocess every call, correct). Fresh per sustained run;
16432
+ * released via `uncacheFrame`.
16433
+ */
16434
+ frameId: number().int().nonnegative().optional(),
16435
+ /** Inference-device selector (Phase 2 multi-device); see runPipeline. */
16436
+ deviceKey: string().optional()
16437
+ }), object({ results: array(PipelineRunResultBridge).readonly() }), { kind: "mutation" }), method(object({
16438
+ data: _instanceof(Uint8Array),
16439
+ width: number().int().positive(),
16440
+ height: number().int().positive(),
16441
+ format: _enum([
16442
+ "rgb",
16443
+ "bgr",
16444
+ "gray"
16445
+ ])
16446
+ }), object({
16447
+ frameId: number(),
16448
+ width: number(),
16449
+ height: number()
16450
+ }), { kind: "mutation" }), method(object({
16451
+ stepId: string(),
16452
+ frameId: number().int()
16453
+ }), record(string(), unknown()), { kind: "mutation" }), method(object({ frameId: number().int() }), _void(), { kind: "mutation" }), method(_void(), object({
16454
+ batchMode: string(),
16455
+ windowMs: number(),
16456
+ maxBatchSize: number(),
16457
+ concurrency: number()
16458
+ })), method(_void(), array(object({
16459
+ engineKey: string(),
16460
+ engine: PipelineEngineChoiceSchema,
16461
+ modelsLoaded: array(string()).readonly(),
16462
+ inUseByCameras: array(number()).readonly(),
16463
+ /**
16464
+ * Origin of this resident factory.
16465
+ * - `runtime` — main camera-serving engine (no idle TTL).
16466
+ * - `warm-override` — benchmark/test override held in the warm
16467
+ * cache; auto-disposed after the idle TTL.
16468
+ * - `device-pool` — a concurrent per-device pool (Phase 2
16469
+ * multi-device, keyed by `deviceKey`) resolved
16470
+ * via `resolveDeviceFactory`. Runs alongside the
16471
+ * `runtime` engine on a DIFFERENT accelerator
16472
+ * (NPU / iGPU / Coral) — this is how the
16473
+ * Engines tab shows all pools running at once.
16474
+ */
16475
+ kind: _enum([
16476
+ "runtime",
16477
+ "warm-override",
16478
+ "device-pool"
16479
+ ]),
16480
+ /** Native pid of the underlying Python pool (null when no pool). */
16481
+ poolPid: number().nullable(),
16482
+ /** ms since this factory was last used (null when not warm-tracked). */
16483
+ idleMs: number().nullable(),
16484
+ /** Idle TTL after which `warm-override` factories self-evict (null when not applicable). */
16485
+ idleTtlMs: number().nullable()
16486
+ })).readonly()), method(object({ engine: PipelineEngineChoiceSchema }), object({ success: literal(true) }), {
16487
+ kind: "mutation",
16488
+ auth: "admin"
16489
+ }), method(object({
16490
+ engine: PipelineEngineChoiceSchema,
16491
+ force: boolean().optional()
16492
+ }), object({
16493
+ success: boolean(),
16494
+ reason: string().optional()
16495
+ }), {
16496
+ kind: "mutation",
16497
+ auth: "admin"
16498
+ }), 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({
16499
+ addonId: string(),
16500
+ modelId: string(),
16501
+ filename: string().optional(),
16502
+ settings: record(string(), unknown()).optional()
16503
+ }), AudioTestResultSchema, { kind: "mutation" }), method(_void(), ConfigUISchemaNullableBridge);
16545
16504
  /**
16546
- * Which detection SOURCE produced an object event. `pipeline` = the ML
16547
- * detection pipeline (decoded-frame inference); `onboard` = the camera's
16548
- * native on-device AI. Both flow through the SAME analysis layers (zoning,
16549
- * tracking, per-kind persistence) but stay distinguishable so consumers
16550
- * (advanced-notifier, occupancy, …) can select which source(s) to act on.
16551
- * Absent on legacy rows treat as `pipeline`.
16505
+ * Per-stage gating mode applied to the zones a rule references.
16506
+ *
16507
+ * - `include`: the rule contributes to a **whitelist** for its stage.
16508
+ * When at least one `include` rule fires for a stage, only entities
16509
+ * inside one of those zones pass that stage.
16510
+ * - `exclude`: the rule contributes to a **blacklist** for its stage.
16511
+ * Entities inside one of those zones are dropped at that stage.
16512
+ *
16513
+ * `monitor`-style observation (count without filtering) is not a rule
16514
+ * mode — zones without any matching rule are observed naturally by
16515
+ * `zone-analytics` (live snapshot + history), so an "I just want to
16516
+ * count, not filter" use case needs no rule at all.
16552
16517
  */
16553
- var DetectionSourceSchema = _enum(["pipeline", "onboard"]);
16518
+ var ZoneRuleModeEnum = _enum(["include", "exclude"]);
16554
16519
  /**
16555
- * The confirmed zone crossing that produced an object event. Present ONLY on
16556
- * an event emitted BY a crossing (`zone.enter` / `zone.exit`); a movement-state
16557
- * event (`object.entering` / `leaving` / `stationary` / `loitering`) and an
16558
- * appearance event carry none, so a rule asking for a direction fails closed
16559
- * on them.
16520
+ * Per-consumer rule that references existing zones (geometry) and
16521
+ * defines how a specific pipeline stage should treat them. Each
16522
+ * consumer addon owns its own `ZoneRule[]` array in its per-device
16523
+ * settings:
16560
16524
  *
16561
- * Exactly ONE crossing per event: the emitter turns each confirmed crossing
16562
- * into its own event, so a frame in which a track enters A while leaving B
16563
- * produces two events with two directions — never one ambiguous row.
16525
+ * - `addon-motion-wasm` `motionZoneRules: ZoneRule[]` (motion stage)
16526
+ * - `addon-detection-pipeline` `detectionZoneRules: ZoneRule[]` (detection stage)
16527
+ * - future: notification rules, audio gating, etc.
16564
16528
  *
16565
- * `zoneId` is load-bearing for an EXIT: the event's `zones` list is the
16566
- * membership the box has NOW, and by definition it no longer contains the zone
16567
- * that was just left. Without the id here, a zone-scoped rule could never match
16568
- * the exit it asked for.
16529
+ * One rule applies to N zones (`zoneIds[]`) so the operator can
16530
+ * express "ignore motion in ALL of {garden, street}" with a single
16531
+ * rule. `classFilter` narrows the rule to specific object classes
16532
+ * "drop person detections in the street, but keep cars" is one
16533
+ * `exclude` rule with `classFilter: ['person']`.
16534
+ *
16535
+ * `enabled` is a soft toggle — the operator can keep the rule
16536
+ * configured but inert without deleting it.
16569
16537
  */
16570
- var ZoneCrossingSchema = object({
16571
- direction: _enum(["enter", "exit"]),
16572
- /** Admin zone id crossed. */
16573
- zoneId: string(),
16574
- /** Zone display name at crossing time (falls back to the id). */
16575
- zoneName: string().optional()
16576
- });
16577
- var ObjectEventSchema = object({
16578
- ...BaseEventFields,
16579
- kind: literal("object"),
16580
- /** Detection source. Optional for backward-compat; absent ⇒ `pipeline`. */
16581
- source: DetectionSourceSchema.optional(),
16538
+ var ZoneRuleSchema = object({
16539
+ /** Stable rule id — survives edits, used by the UI for diffing. */
16540
+ id: string(),
16541
+ /** Optional human-readable label rendered in the rule editor. */
16542
+ name: string().optional(),
16543
+ /** Zones this rule targets. The rule's `mode` applies to ALL
16544
+ * listed zones (OR-set: a detection in any one of them counts).
16545
+ * At least one zone id required — a rule with no targets is a
16546
+ * configuration mistake and the form validator rejects it. */
16547
+ zoneIds: array(string()).min(1).readonly(),
16548
+ mode: ZoneRuleModeEnum,
16582
16549
  /**
16583
- * Inference-frame id shared by every object event emitted from the SAME frame
16584
- * the "scene/parent" key. Lets a consumer group co-occurring detections (e.g.
16585
- * 2 people + 1 dog) under one full frame, and link a track's frames over time
16586
- * (group by `trackId`, pick a representative `frameId` as the parent frame).
16587
- * Optional for backward-compat with pre-existing rows / the slim projection
16588
- * includes it (it is light). Absent on rows written before this field.
16550
+ * Class names this rule applies to. Empty / undefined rule
16551
+ * applies to every class. Class strings match the `macroClass`
16552
+ * field on detections (e.g. `person`, `car`, `dog`).
16589
16553
  */
16590
- frameId: string().optional(),
16591
- /** Omitted in slim projection. */
16592
- trackId: string().optional(),
16593
- className: string(),
16594
- ...TieredLabelFields,
16595
- /** Omitted in slim projection. */
16596
- confidence: number().optional(),
16597
- /** Heavy JSON — omitted in slim projection. */
16598
- bbox: BoundingBoxSchema.optional(),
16599
- /** Heavy JSON — omitted in slim projection. */
16600
- zones: array(string()).readonly().optional(),
16601
- /** Omitted in slim projection. */
16602
- state: TrackStateSchema.optional(),
16554
+ classFilter: array(string()).readonly().optional(),
16603
16555
  /**
16604
- * The zone crossing this event IS, when it is one. Absent on every other
16605
- * event kind (movement state, appearance, package) see
16606
- * {@link ZoneCrossingSchema}. Omitted in slim projection.
16556
+ * Minimum bbox/mask overlap (0–1) with any of the rule's zones
16557
+ * required to consider an entity "in the zone". Defaults to the
16558
+ * consumer's stage default when omitted. Kept for back-compat with
16559
+ * existing per-rule overrides; new operators pick the value via
16560
+ * `bboxInclusionPct` (operator-friendly 0–100). Whichever field is
16561
+ * set, the lower-level engine reads it as a 0–1 fraction.
16607
16562
  */
16608
- zoneCrossing: ZoneCrossingSchema.optional(),
16609
- /** Detection-frame dimensions in pixels — let consumers normalize the
16610
- * pixel-space `bbox` onto a displayed image. Omitted in slim projection. */
16611
- frameWidth: number().optional(),
16612
- frameHeight: number().optional(),
16613
- /** MediaStore key for the crop attached to this event (if any). */
16614
- mediaKey: string().optional(),
16615
- /** Design B: MediaStore key of the track's native-resolution key frame (the
16616
- * best-detection full frame). Resolve via the event-media data-plane
16617
- * (`/addon/<addonId>/event-media/<keyFrameMediaKey>`) for a detail view that
16618
- * draws `bbox` over the native frame. Absent on legacy rows / non-decoded
16619
- * sources — consumers fall back to `mediaKey` (the tight crop). */
16620
- keyFrameMediaKey: string().optional(),
16621
- /** Populated by B5 (recording playback URL for this event). */
16622
- mediaUrl: string().optional(),
16623
- /** The parent track's key-event importance [0,1], propagated to every object
16624
- * event of the track (so an event row can be sorted by importance without a
16625
- * track join). Absent on legacy rows / before the track was scored. */
16626
- importance: number().optional()
16627
- });
16628
- var AudioEventSchema = object({
16629
- ...BaseEventFields,
16630
- kind: literal("audio"),
16631
- rms: number(),
16632
- dbfs: number(),
16633
- classification: object({
16634
- className: string(),
16635
- originalClass: string().optional(),
16636
- score: number()
16637
- }).optional(),
16638
- /** Populated by B5 (recording playback URL for this event). */
16639
- mediaUrl: string().optional()
16640
- });
16641
- var MediaFileKindEnum = _enum([
16642
- "crop",
16643
- "thumbnail",
16644
- "snapshot",
16645
- "firstFrame",
16646
- "lastFrame",
16647
- "fullFrame",
16648
- "fullFrameBoxed",
16649
- "faceCrop",
16650
- "plateCrop",
16651
- "keyFrame",
16652
- "keyFrameSmall",
16653
- "thumbnailSmall"
16654
- ]);
16655
- var MediaFileSchema = object({
16656
- key: string(),
16657
- kind: MediaFileKindEnum,
16658
- base64: string(),
16659
- sizeBytes: number(),
16660
- timestamp: number()
16563
+ overlapThreshold: number().min(0).max(1).optional(),
16564
+ /**
16565
+ * Operator-friendly version of `overlapThreshold` the percentage
16566
+ * of the detection's bbox that must lie inside the zone for the
16567
+ * rule to match. Documented default is 85%; the engine substitutes
16568
+ * that when the field is omitted (kept optional so existing rules
16569
+ * stored without it stay valid).
16570
+ *
16571
+ * When BOTH `overlapThreshold` and `bboxInclusionPct` are set on a
16572
+ * rule, the engine prefers `bboxInclusionPct` because it's the
16573
+ * field exposed in the UI. Internally both feed the same gate.
16574
+ */
16575
+ bboxInclusionPct: number().min(0).max(100).optional(),
16576
+ /**
16577
+ * When `true` and a detection has a segmentation mask, use the
16578
+ * mask for overlap instead of the bbox. Detection-stage only;
16579
+ * motion rules ignore this field.
16580
+ */
16581
+ preferMask: boolean().optional(),
16582
+ /**
16583
+ * Soft-toggle: `false` disables the rule without deleting it.
16584
+ * Defaults to `true` so operators creating a rule via the UI
16585
+ * see it active immediately.
16586
+ */
16587
+ enabled: boolean().default(true)
16661
16588
  });
16589
+ array(ZoneRuleSchema).readonly();
16662
16590
  /**
16663
- * One media row WITHOUT its bytes.
16591
+ * Zone pure geometry + identity. NO filtering behaviour.
16664
16592
  *
16665
- * A track's media is 5-8 MB of base64 (measured: 7.67 MB across 23 files for a
16666
- * 140 s track), and a client that renders tiles from the media data plane needs
16667
- * to know only WHAT EXISTS the bytes then arrive per tile, lazily, over HTTP
16668
- * with an immutable cache, instead of all at once inside a tRPC response that
16669
- * blocks the whole view.
16593
+ * Zones describe **where** in the frame the operator wants to flag
16594
+ * something; consumer-owned {@link ZoneRule} arrays describe **how**
16595
+ * each pipeline stage uses them. Splitting the two means a single
16596
+ * polygon "Driveway" can simultaneously back a motion-exclude rule,
16597
+ * a detection-include rule on `['car']`, and an occupancy aggregate
16598
+ * — without three duplicated polygons.
16670
16599
  *
16671
- * `sizeBytes` is carried because it is what lets a client decide between the
16672
- * stored blob and a `?variant=thumb` rendering without fetching either.
16600
+ * Owned by the orchestrator addon (provider) and mirrored into the
16601
+ * `zones` device-state slice on every mutation. Consumers
16602
+ * (motion-wasm, pipeline-executor, analytics, admin UI) read either
16603
+ * via `api.zones.listZones` (one-shot) or via `dev.state.zones` (live
16604
+ * mirror with `onChanged`).
16605
+ *
16606
+ * Coordinates are normalised fractions of the frame (0–1) so zones
16607
+ * survive resolution changes and stream profile switches.
16608
+ *
16609
+ * `kind` discriminates between full polygons (closed regions used
16610
+ * for intrusion / occupancy filters) and tripwires (open 2-point
16611
+ * line segments used for cross events). Onboard / firmware-reported
16612
+ * zones (Reolink, ONVIF) are out of scope for now — see the deferred
16613
+ * task list.
16673
16614
  */
16674
- var MediaFileInfoSchema = MediaFileSchema.omit({ base64: true });
16615
+ var ZoneKindEnum = _enum(["polygon", "tripwire"]);
16616
+ /** Polygon vertex in fraction-of-frame coordinates (0–1). */
16617
+ var PolygonPointSchema = object({
16618
+ x: number(),
16619
+ y: number()
16620
+ });
16621
+ /** A camera detection zone — pure geometry/identity. */
16622
+ var ZoneSchema = object({
16623
+ id: string(),
16624
+ name: string(),
16625
+ kind: ZoneKindEnum.default("polygon"),
16626
+ /** Polygon vertices, fraction of frame (0–1). */
16627
+ polygon: array(PolygonPointSchema).readonly(),
16628
+ /** Visual color for UI rendering. */
16629
+ color: string().default("#3b82f6")
16630
+ });
16631
+ DeviceType.Camera, method(object({ deviceId: number() }), array(ZoneSchema).readonly()), method(object({
16632
+ deviceId: number(),
16633
+ zone: ZoneSchema
16634
+ }), _void(), {
16635
+ kind: "mutation",
16636
+ auth: "admin"
16637
+ }), method(object({
16638
+ deviceId: number(),
16639
+ zoneId: string()
16640
+ }), _void(), {
16641
+ kind: "mutation",
16642
+ auth: "admin"
16643
+ }), method(object({
16644
+ deviceId: number(),
16645
+ zone: ZoneSchema
16646
+ }), _void(), {
16647
+ kind: "mutation",
16648
+ auth: "admin"
16649
+ }), object({ zones: array(ZoneSchema).readonly() });
16675
16650
  /**
16676
- * The MACRO tier of an annotation — a CLOSED set.
16651
+ * pipeline-analytics device-scoped wrapper cap. Refines raw
16652
+ * per-frame detections emitted by the pipeline runner into tracked
16653
+ * objects, per-kind event collections (motion / object / audio), and
16654
+ * persisted media. Owns the post-detection domain end-to-end:
16677
16655
  *
16678
- * This is what the exported detector predicts, so a typo here is a new class
16679
- * with one example in it. `label` and `subLabel` are open strings by contrast:
16680
- * the whole point of the page is teaching the model things it does not know
16681
- * yet, and constraining that vocabulary would make it useless.
16656
+ * runner emits PipelineInferenceResult
16657
+ * (event bus)
16658
+ * pipeline-analytics subscriber
16659
+ * SORT tracker + zone engine + state analyzer + event emitter
16660
+ * → three DB collections (one per kind), one FS media tree, one
16661
+ * unified event emitter (FrameTracked + TrackStarted/Ended +
16662
+ * DetectionEvent on bus)
16682
16663
  *
16683
- * A macro class is NEVER a label. The provider refuses a write whose `label` or
16684
- * `subLabel` is one of these values, in any casing, because once `person`
16685
- * exists in both tiers "every person box" stops being answerable without
16686
- * knowing every string anyone ever typed — and the damage is retroactive.
16664
+ * Pure subscriber model. No `processFrame` cap method the runner
16665
+ * already publishes the raw frame on the bus. The cap surface is
16666
+ * only QUERIES + per-device settings, bound on/off via
16667
+ * `device-manager.setWrapperActive`. `defaultActive: true` because
16668
+ * every camera with a detection pipeline wants its raw detections
16669
+ * refined; operators opt out per-device via BindingsTab when needed.
16670
+ *
16671
+ * Replaces the legacy `analysis-pipeline`, `analysis-data-persistence`
16672
+ * (per-device surface) and `track-trail` caps — see P11 cleanup.
16687
16673
  */
16688
- var RetrainMacroClassSchema = _enum([
16674
+ var TrackStateSchema = _enum([
16675
+ "new",
16676
+ "entered",
16677
+ "left",
16678
+ "moving",
16679
+ "idle"
16680
+ ]);
16681
+ var EventKindSchema = _enum([
16682
+ "motion",
16683
+ "object",
16684
+ "audio"
16685
+ ]);
16686
+ /**
16687
+ * Spatial filter for `listTracks` — the rect + polygon variants of the shared
16688
+ * MaskShape vocabulary (see `mask-shape.ts`). Coordinates are NORMALIZED 0..1
16689
+ * of the camera frame (top-left origin), matching the drawing-plane editor.
16690
+ */
16691
+ var TrackZoneFilterSchema = discriminatedUnion("kind", [MaskRectShapeSchema, MaskPolygonShapeSchema]);
16692
+ /** Closed icon vocabulary so clients render a known glyph per kind. */
16693
+ var EventKindIconSchema = _enum([
16694
+ "motion",
16695
+ "audio",
16689
16696
  "person",
16690
16697
  "vehicle",
16691
16698
  "animal",
16699
+ "door",
16700
+ "pir",
16701
+ "smoke",
16702
+ "water",
16703
+ "button",
16692
16704
  "package",
16693
- "face",
16694
- "plate"
16705
+ "generic"
16695
16706
  ]);
16696
- /** A subject to learn, or a phantom to unlearn (taught by OMISSION). */
16697
- var RetrainAnnotationKindSchema = _enum(["subject", "model_error"]);
16698
- /** Did a human draw this box, or did the assist propose it? */
16699
- var RetrainAnnotationSourceSchema = _enum(["operator", "assist"]);
16700
- /** Normalised `[0,1]` rectangle against the FULL frame — the canonical form. */
16701
- var RetrainBboxSchema = object({
16707
+ var EventKindCategorySchema = _enum([
16708
+ "motion",
16709
+ "audio",
16710
+ "detection",
16711
+ "sensor",
16712
+ "control",
16713
+ "custom",
16714
+ "package"
16715
+ ]);
16716
+ /** Taxonomy level — macro (timeline lane) vs sub (events-page leaf). */
16717
+ var EventKindLevelSchema = _enum(["macro", "sub"]);
16718
+ var EventKindDescriptorSchema = object({
16719
+ /** Stable kind id (e.g. 'motion', 'vehicle', 'car', 'lock'). */
16720
+ kind: string(),
16721
+ /** i18n key resolved on the UI side; `label` is the English fallback. */
16722
+ labelKey: string(),
16723
+ /** English fallback label (kept for clients that don't translate). */
16724
+ label: string(),
16725
+ /** Hex color for timeline/legend rendering. */
16726
+ color: string(),
16727
+ /** Dictionary id → lucide component on the UI side. */
16728
+ iconId: string(),
16729
+ /** Legacy closed-vocab glyph — fallback for `iconId`. */
16730
+ icon: EventKindIconSchema,
16731
+ category: EventKindCategorySchema,
16732
+ /** Macro parent for this kind ('car' → 'vehicle'); null for a macro. */
16733
+ parentKind: string().nullable(),
16734
+ /** Derived from `parentKind`, explicit for the client tree. */
16735
+ level: EventKindLevelSchema,
16736
+ /** Which cap + device contributes this kind. For built-ins the camera
16737
+ * itself; for sensor kinds the LINKED source device. */
16738
+ source: object({
16739
+ capName: string(),
16740
+ deviceId: number()
16741
+ })
16742
+ });
16743
+ /** One camera's event vocabulary, as returned by `listEventKindsBatch`. */
16744
+ var EventKindsForDeviceSchema = object({
16745
+ deviceId: number(),
16746
+ kinds: array(EventKindDescriptorSchema).readonly()
16747
+ });
16748
+ var SensorEventSchema = object({
16749
+ id: string(),
16750
+ /** The CAMERA the event is attributed to (a sensor linked to N cameras
16751
+ * yields N rows, one per camera). */
16752
+ deviceId: number(),
16753
+ /** The linked sensor device whose state changed. */
16754
+ sourceDeviceId: number(),
16755
+ /** Event kind id — matches an `EventKindDescriptor.kind`. */
16756
+ kind: string(),
16757
+ /** Snapshot of the sensor cap's runtime-state slice at the change. */
16758
+ value: record(string(), unknown()).nullable(),
16759
+ timestamp: number()
16760
+ });
16761
+ var TrackPositionSchema = object({
16702
16762
  x: number(),
16703
16763
  y: number(),
16704
- w: number(),
16705
- h: number()
16764
+ timestamp: number(),
16765
+ bbox: BoundingBoxSchema
16766
+ });
16767
+ var TrackSnapshotSchema = object({
16768
+ timestamp: number(),
16769
+ position: TrackPositionSchema,
16770
+ /** MediaStore key; resolve via `getTrackMedia({ trackId })`. */
16771
+ mediaKey: string()
16706
16772
  });
16707
16773
  /**
16708
- * One annotated subject.
16709
- *
16710
- * `bbox` is normalised against the full frame, ALWAYS. The per-model shapes
16711
- * (letterboxed root / zone-cropped package / subject-cropped classifier) are
16712
- * derived from it at export and never stored — storing them is how one feature
16713
- * space ends up holding two crops of the same subject (D52).
16714
- */
16715
- var RetrainAnnotationSchema = object({
16716
- id: string(),
16774
+ * Normalized 0..1 trajectory envelope (min/max over every position bbox,
16775
+ * divided by the track's detection-frame dims), computed at persist time.
16776
+ * Absent when the frame dims were unknown when the track was persisted
16777
+ * (legacy rows / dims-less sources) and on active (in-RAM) tracks.
16778
+ */
16779
+ var TrackEnvelopeSchema = object({
16780
+ minX: number(),
16781
+ minY: number(),
16782
+ maxX: number(),
16783
+ maxY: number()
16784
+ });
16785
+ /**
16786
+ * Row projection for track list queries. `full` (default) returns the
16787
+ * complete Track including the frame-rate `positions[]` history and the
16788
+ * `snapshots[]` references — megabytes across a page of tracks. `slim`
16789
+ * keeps every scalar the list surfaces actually render (ids, class(es),
16790
+ * label / audioLabels / importance enrichment, firstSeen/lastSeen, state,
16791
+ * zonesVisited, bestEventId, envelope, hasFace, hasEmbeddedFace, hasRider) and returns `positions` /
16792
+ * `snapshots` as EMPTY arrays — detail views re-fetch the full row via
16793
+ * `getTrack`. Mirrors the event-store `projection` convention
16794
+ * (`getObjectEvents` et al.).
16795
+ */
16796
+ var TrackProjectionSchema = _enum(["full", "slim"]);
16797
+ /**
16798
+ * One audio-classification label heard on the track's camera while the
16799
+ * track was alive, aggregated per label. An "episode" is one persisted
16800
+ * audio event (the confident-classification path: score ≥ the device's
16801
+ * `classificationMinScore`, class-change-or-heartbeat coalesced) — NOT
16802
+ * one 32 ms inference chunk, so counts stay human-scaled.
16803
+ */
16804
+ var TrackAudioLabelSchema = object({
16805
+ label: string(),
16806
+ /** Highest classification score observed across the label's episodes. */
16807
+ peakScore: number(),
16808
+ /** Number of coalesced audio-event episodes carrying this label. */
16809
+ count: number(),
16810
+ firstAt: number(),
16811
+ lastAt: number()
16812
+ });
16813
+ /**
16814
+ * How a track was produced. `pipeline` (default / absent) = the spatial
16815
+ * detection+tracking pipeline. Every OTHER value is a SYNTHETIC projection —
16816
+ * no positions, a single snapshot, and no bbox trajectory at all:
16817
+ *
16818
+ * - `sensor` — a linked sensor/control device state change.
16819
+ * - `audio` — an audio event on the camera itself that was anomalous for
16820
+ * THAT camera, loud, and heard while nothing visual was happening (D62).
16821
+ *
16822
+ * The spatial subsystems (tracker association, occupancy count, re-id /
16823
+ * embedding, resurrection) MUST skip every synthetic source. Test for that
16824
+ * with `isSpatialTrack`, which allow-lists `pipeline` — a `!== 'sensor'`
16825
+ * check silently readmits every source added after it was written.
16826
+ */
16827
+ var TrackSourceSchema = _enum([
16828
+ "pipeline",
16829
+ "sensor",
16830
+ "audio"
16831
+ ]);
16832
+ /**
16833
+ * Where a track sits in the RETRAIN lifecycle (D81).
16834
+ *
16835
+ * - `none` — never marked, or un-marked. Evictable.
16836
+ * - `staging` — the operator wants this track as training material and has not
16837
+ * finished with it. **This is the only state retention holds**: the track and
16838
+ * everything it owns (object events, crops, keyframes, CLIP vector) survive
16839
+ * the device's age window.
16840
+ * - `trained` — the retrain page has taken what it needed. The frames it chose
16841
+ * were COPIED into the retrain dataset at selection time, so the dataset no
16842
+ * longer depends on the track's media and the track becomes EVICTABLE again.
16843
+ * Terminal for the plain `markForTrain` toggle: returning it to `staging` is
16844
+ * a deliberate action of the retrain page, not a side effect of a checkbox.
16845
+ *
16846
+ * There is no `null`. The state is stored `TEXT NOT NULL DEFAULT 'none'` because
16847
+ * the store's filter language has only positive equality and `whereIn` — no
16848
+ * negation, no IS NULL — so a NULL would be unselectable by ANY predicate and
16849
+ * would make the entire pre-column history immortal in one deploy.
16850
+ */
16851
+ var RetrainStatusSchema = _enum([
16852
+ "none",
16853
+ "staging",
16854
+ "trained"
16855
+ ]);
16856
+ /**
16857
+ * Per-track OPERATOR flags — set by hand from the admin UI or the viewer, never
16858
+ * by the pipeline. Spread into `TrackSchema` and `KeyEventSchema` from one place
16859
+ * so the two surfaces cannot drift.
16860
+ *
16861
+ * **Absent ≠ false.** A track that has never been touched omits the field; an
16862
+ * explicitly un-flagged track carries `false`. Legacy rows written before the
16863
+ * columns existed read as absent, and a consumer that needs a boolean should say
16864
+ * `flag === true`, not `flag !== false`.
16865
+ *
16866
+ * `markForTrain` is the WIRE FACE of {@link RetrainStatusSchema}, not a column:
16867
+ * it is exactly `retrainStatus === 'staging'`, in both directions. Writing
16868
+ * `true` moves `none → staging`, writing `false` moves `staging → none`, and a
16869
+ * `trained` track reports `false` while refusing both writes. The boolean is
16870
+ * kept because three surfaces drive a toggle off it; anything that needs to tell
16871
+ * "never marked" from "already trained" must read `retrainStatus`.
16872
+ *
16873
+ * `debug` does NOT pin; it is attention, not durability.
16874
+ *
16875
+ * `favourited` IS a BOOLEAN pin (durability bit), not a retrain lifecycle.
16876
+ * A favourited track is skipped by retention the same way `staging` is, but
16877
+ * it does not enter `none|staging|trained` and has no staging budget.
16878
+ */
16879
+ var TrackFlagFields = {
16880
+ /** Operator marked this track as training material — i.e. `retrainStatus` is
16881
+ * `'staging'`. */
16882
+ markForTrain: boolean().optional(),
16883
+ /** Operator marked this track for diagnostic attention. */
16884
+ debug: boolean().optional(),
16885
+ /** Operator favourited this track. Pins it against pruning. */
16886
+ favourited: boolean().optional()
16887
+ };
16888
+ /**
16889
+ * The lifecycle field itself, on the READ surfaces only (`Track`, `KeyEvent`).
16890
+ * Deliberately NOT part of {@link TrackFlagFields}: that group also builds the
16891
+ * write patch, and the status is not something the toggle sets — it is what the
16892
+ * toggle's boolean is derived from. Absent on an in-RAM track never touched;
16893
+ * always present on a persisted row (the column default materialises `'none'`).
16894
+ */
16895
+ var TrackRetrainFields = { retrainStatus: RetrainStatusSchema.optional() };
16896
+ /**
16897
+ * The write half: a PARTIAL patch. An omitted key is left untouched, so setting
16898
+ * one flag can never clear the other — the toggles are independent and are
16899
+ * driven from three surfaces that do not know about each other.
16900
+ */
16901
+ var TrackFlagsPatchSchema = object(TrackFlagFields);
16902
+ /**
16903
+ * The resolved flag state after a write. Both fields are REQUIRED here (absent
16904
+ * collapses to `false`) so a caller can drive a toggle's checked state off the
16905
+ * mutation result without a re-fetch.
16906
+ */
16907
+ var TrackFlagsSchema = object({
16717
16908
  trackId: string(),
16718
- deviceId: number(),
16719
- /** The COPY in retrain storage — never the source track's media key. */
16720
- mediaKey: string(),
16721
- bbox: RetrainBboxSchema,
16722
- macroClass: RetrainMacroClassSchema,
16909
+ markForTrain: boolean(),
16910
+ debug: boolean(),
16911
+ favourited: boolean(),
16912
+ /** The lifecycle state the boolean was derived from. Required here (unlike on
16913
+ * a track row) because this shape is only ever produced by the write body,
16914
+ * which always knows it — and a surface that has just written needs to render
16915
+ * `trained` without a re-fetch. */
16916
+ retrainStatus: RetrainStatusSchema
16917
+ });
16918
+ union([literal(1), literal(2)]);
16919
+ /**
16920
+ * WHO decided a label, and when. Carried per tier so a value can be traced to
16921
+ * the step and model that produced it — which is what makes the write rule
16922
+ * arguable after the fact ("why is 592's label `dog` and not `Canis lupus`?")
16923
+ * and what lets a migrated, UNATTRIBUTED value be told apart from a real one.
16924
+ *
16925
+ * `stepId` is the pipeline step id (`animal-classifier`, `bird-classifier`,
16926
+ * `plate-ocr`, `face-embedding`, `object-detection`), or the sentinel
16927
+ * `migration:4g` for a value the 4g migration moved from the single-slot era —
16928
+ * that value has no provenance, and the write rule lets ANY properly-attributed
16929
+ * write of the same tier replace it regardless of score.
16930
+ */
16931
+ var LabelAttributionSchema = object({
16932
+ stepId: string(),
16933
+ modelId: string().optional(),
16934
+ decidedAt: number(),
16935
+ /**
16936
+ * The GALLERY id behind a recognised tier-2 label — a face-gallery
16937
+ * `Identity.id` or a plate-gallery `Vehicle.id` (both `randomUUID`).
16938
+ *
16939
+ * The text alone is a DISPLAY NAME, and a display name is renameable: a
16940
+ * notification rule authored on "Gianluca" stopped matching the moment the
16941
+ * operator fixed the spelling in the gallery, and nothing said so. The id is
16942
+ * the thing that does not move, so it is what a rule matches on
16943
+ * (`NcConditions.identities`) and the text is what a human is shown.
16944
+ *
16945
+ * Absent when the label names no gallery row — a plate the OCR read but no
16946
+ * vehicle claims, a sub-class, a species, any tier-1 value.
16947
+ */
16948
+ identityId: string().optional()
16949
+ });
16950
+ /**
16951
+ * The TIERED label model (roadmap 4g), spread into `TrackSchema` and
16952
+ * `ObjectEventSchema` from ONE place so the two surfaces cannot drift — a
16953
+ * track and its events always answer the same question the same way.
16954
+ *
16955
+ * Two scalar columns, not an array: every consumer wants "the coarse one" or
16956
+ * "the fine one", and an array made both a scan. `label` is tier 1, `subLabel`
16957
+ * is tier 2, and each carries its own score + attribution.
16958
+ *
16959
+ * **Reading it.** What a human should be shown is `subLabel ?? label` — the
16960
+ * finest thing known. Before 4g the single `label` column held the finest
16961
+ * value, so a consumer that has not been updated reads the tier-1 slot and
16962
+ * shows nothing on a species-only row; that is why the migration puts every
16963
+ * pre-4g value in tier 2 (it cannot regress a display that reads the fallback)
16964
+ * and why the read surfaces were changed in the same train.
16965
+ *
16966
+ * **Writing it.** The slots are independent, which is the whole point: a
16967
+ * tier-1 write (`bird`) can never overwrite a tier-2 value (`Turdus
16968
+ * migratorius`), so fineness cannot regress by construction. Within a tier the
16969
+ * higher score wins. One rule, one implementation — see
16970
+ * `pipeline/label-tier.ts` in addon-post-analysis.
16971
+ */
16972
+ var TieredLabelFields = {
16973
+ /** Tier 1 — the sub-class. See {@link LabelTierSchema}. */
16723
16974
  label: string().optional(),
16975
+ /** Confidence of the tier-1 value, as reported by the deciding step. */
16976
+ labelScore: number().optional(),
16977
+ /** Provenance of the tier-1 value. See {@link LabelAttributionSchema}. */
16978
+ labelMeta: LabelAttributionSchema.optional(),
16979
+ /** Tier 2 — the instance. See {@link LabelTierSchema}. */
16724
16980
  subLabel: string().optional(),
16725
- kind: RetrainAnnotationKindSchema,
16726
- source: RetrainAnnotationSourceSchema,
16727
- /** Which model proposed this box or, on a `model_error`, drew the phantom. */
16728
- assistModelId: string().optional(),
16729
- assistScore: number().optional(),
16730
- exportedInBatch: string().optional(),
16731
- createdAt: number()
16981
+ /** Confidence of the tier-2 value, as reported by the deciding step. */
16982
+ subLabelScore: number().optional(),
16983
+ /** Provenance of the tier-2 value. See {@link LabelAttributionSchema}. */
16984
+ subLabelMeta: LabelAttributionSchema.optional()
16985
+ };
16986
+ /** Per-camera slice of a training-export estimate. */
16987
+ var TrainingExportDeviceTotalsSchema = object({
16988
+ deviceId: number(),
16989
+ tracks: number().int(),
16990
+ files: number().int(),
16991
+ bytes: number().int()
16732
16992
  });
16733
- /** The write form — the server owns `id`, `createdAt` and the frame binding. */
16734
- var RetrainAnnotationDraftSchema = RetrainAnnotationSchema.omit({
16735
- id: true,
16736
- trackId: true,
16737
- deviceId: true,
16738
- mediaKey: true,
16739
- createdAt: true,
16740
- exportedInBatch: true
16993
+ /**
16994
+ * What a training export WOULD contain. Computed from media index rows only —
16995
+ * no blob is read to produce this.
16996
+ */
16997
+ var TrainingExportSummarySchema = object({
16998
+ generatedAt: number(),
16999
+ trackCount: number().int(),
17000
+ fileCount: number().int(),
17001
+ byteCount: number().int(),
17002
+ /** More marked tracks exist than a single pass carries. */
17003
+ truncated: boolean(),
17004
+ devices: array(TrainingExportDeviceTotalsSchema).readonly()
16741
17005
  });
16742
- /** A track sitting in `staging`, with everything the worklist needs to rank it. */
16743
- var RetrainTrackSchema = object({
17006
+ var TrackSchema = object({
16744
17007
  trackId: string(),
16745
17008
  deviceId: number(),
16746
17009
  className: string(),
16747
- label: string().optional(),
17010
+ ...TieredLabelFields,
17011
+ producingDeviceName: string().optional(),
17012
+ /** Track provenance. Absent ⇒ `pipeline` (legacy rows). */
17013
+ source: TrackSourceSchema.optional(),
16748
17014
  firstSeen: number(),
16749
17015
  lastSeen: number(),
16750
- /** How many frames the dataset already holds from this track. */
16751
- frameCount: number().int(),
16752
- /** How many subjects have been annotated on those frames. `0` with
16753
- * `frameCount: 0` is exactly "staging, still to work". */
16754
- annotationCount: number().int()
16755
- });
16756
- /** A frame the picker may offer — an index row, no blob was read to produce it. */
16757
- var RetrainFrameCandidateSchema = object({
16758
- mediaKey: string(),
16759
- kind: MediaFileKindEnum,
16760
- timestamp: number(),
16761
- sizeBytes: number().int(),
16762
- /** A copy of this original already exists selecting it is free and cannot
16763
- * fail, whatever became of the original. */
16764
- copied: boolean()
17016
+ /** Frame-rate position history (subject to maxPositionHistory cap). */
17017
+ positions: array(TrackPositionSchema).readonly(),
17018
+ /** Periodic snapshots at snapshotIntervalMs cadence (subject to
17019
+ * saveThumbnails policy). */
17020
+ snapshots: array(TrackSnapshotSchema).readonly(),
17021
+ /** Deduplicated zones the track has entered at least once. Zone IDS. */
17022
+ zonesVisited: array(string()).readonly(),
17023
+ /**
17024
+ * Human NAMES for {@link zonesVisited}, resolved at READ time against the
17025
+ * `zones` capability.
17026
+ *
17027
+ * `zonesVisited` persists ids (`cfeec78c-8d69-…`), which no operator can type
17028
+ * and no card can render so every free-text search surface was structurally
17029
+ * unable to answer "show me the tracks in Uscio", and did not fail loudly, it
17030
+ * just returned nothing. Resolving here rather than in each client keeps ONE
17031
+ * derivation and costs the clients no extra call (the `zones` cap is
17032
+ * per-device, so a client-side resolve would be a per-camera fan-out on a
17033
+ * surface built to avoid exactly that).
17034
+ *
17035
+ * Resolved, never invented: a zone deleted since the track was written has no
17036
+ * name and is DROPPED, so this array can be shorter than `zonesVisited` — the
17037
+ * two are not positionally aligned. Absent when the track visited no zone, or
17038
+ * when the zone catalogue could not be read.
17039
+ */
17040
+ zoneNames: array(string()).readonly().optional(),
17041
+ /** Deduplicated set of detector classes observed for this track over its
17042
+ * life (a track may be reclassified, e.g. person→vehicle). Absent on
17043
+ * legacy rows written before class accumulation shipped. */
17044
+ classes: array(string()).readonly().optional(),
17045
+ /** Cumulative normalized distance travelled (0..1 units = full frame width). */
17046
+ totalDistance: number(),
17047
+ state: TrackStateSchema,
17048
+ active: boolean(),
17049
+ /** Deterministic key-event importance score in [0,1] (server-computed at
17050
+ * track expiry, recomputed on late label). Absent on legacy rows written
17051
+ * before scoring shipped — consumers degrade to absence / compute-on-read. */
17052
+ importance: number().optional(),
17053
+ /** Id of the track's highest-confidence ObjectEvent (its representative
17054
+ * "best" frame). Absent when the track produced no object events. */
17055
+ bestEventId: string().optional(),
17056
+ /** Tag of the importance sub-signal that dominated the score
17057
+ * (identity|dwell|proximity|class|confidence|travel|zone). */
17058
+ importanceReason: string().optional(),
17059
+ /** Audio-classification labels heard on the camera during the track's
17060
+ * life (score ≥ device `classificationMinScore`), aggregated per label.
17061
+ * Absent on legacy rows / tracks with no confident audio. */
17062
+ audioLabels: array(TrackAudioLabelSchema).readonly().optional(),
17063
+ /** Normalized 0..1 trajectory envelope (see {@link TrackEnvelopeSchema}).
17064
+ * Populated from the persisted envelope columns on historical reads;
17065
+ * absent on legacy rows, dims-less tracks and active (in-RAM) tracks. */
17066
+ envelope: TrackEnvelopeSchema.optional(),
17067
+ /**
17068
+ * A face DETECTOR found a face on this track — nothing more. It says the
17069
+ * detail plane produced a `face` detail; it does NOT say the face was
17070
+ * embedded, matched, above `minFacePx`, or that the recognizer was even
17071
+ * enabled. Set once and never cleared.
17072
+ *
17073
+ * **This exists so "face present but not recognised" is expressible.** A
17074
+ * recognised identity lands in `subLabel` (attributed to the face chain via
17075
+ * `subLabelMeta.stepId`), so before this field a track with an unmatched face
17076
+ * and a track with no face at all were byte-identical on the wire and no
17077
+ * surface could tell them apart. The read is `hasFace === true && subLabel
17078
+ * === undefined`.
17079
+ *
17080
+ * **Absent ≠ false.** Every row written before the column existed omits it,
17081
+ * and so does every server that predates the field — a consumer must test
17082
+ * `=== true` and render nothing otherwise, never infer "no face".
17083
+ */
17084
+ hasFace: boolean().optional(),
17085
+ /**
17086
+ * This track has a face row IN THE GALLERY: a crop **and** an embedding — a
17087
+ * face an operator could ASSIGN to an identity.
17088
+ *
17089
+ * The STRICT twin of {@link hasFace}, and the pair only earns its keep
17090
+ * because the two disagree. `hasFace` is stamped at the TOP of the face
17091
+ * branch, before every gate, and means no more than "a face detector produced
17092
+ * a face detail". This one is stamped at the single moment the gallery row
17093
+ * LANDS — after `FaceRecognizer.onTrackEnd` successfully persists it, i.e.
17094
+ * past the embedding-magnitude verdict, the `minFacePx` detection gate, the
17095
+ * candidate gate, the imageless-track drop (no crop was ever captured) and
17096
+ * the crop-store drop. Everything between the detector and that insert can
17097
+ * legitimately refuse the face, so a flag written any earlier promises the
17098
+ * operator something to assign and delivers nothing.
17099
+ *
17100
+ * **Independent of recognition.** A face collected but never auto-matched is
17101
+ * still assignable — it is in fact the face an operator most wants to reach —
17102
+ * so this is NOT gated on `recognizedIdentityId`. Recognition lands in
17103
+ * `subLabel`; this says only that the raw material exists.
17104
+ *
17105
+ * **Set once, never cleared.** A track that produced a gallery row produced
17106
+ * one; deleting the row later is the gallery's business, not this flag's.
17107
+ *
17108
+ * **Absent ≠ false**, the same rule as {@link hasFace}: every row written
17109
+ * before the column omits it, and so does every server that predates the
17110
+ * field. A consumer must test `=== true` and render nothing otherwise —
17111
+ * never infer "no assignable face".
17112
+ */
17113
+ hasEmbeddedFace: boolean().optional(),
17114
+ /**
17115
+ * This subject CONTAINS a folded rider — a person the rider-pairing step
17116
+ * ([D34](../decisions/adr-0034.md)) removed from the frame BEFORE the tracker,
17117
+ * so the passage is tracked once and as a VEHICLE.
17118
+ *
17119
+ * It exists because the fold's record was dishonest. D34 and the code both
17120
+ * said "the person is not lost — it is reported so both entities stay on the
17121
+ * record"; in fact the pair went into a per-processor RAM field behind an
17122
+ * accessor nobody called, and every durable surface said `vehicle`, full
17123
+ * stop. This is the composition note that makes the row true.
17124
+ *
17125
+ * A COMPOSITION, never a class and never a label. "This vehicle contains a
17126
+ * person" is not an answer to "what is this" — both label tiers would refuse
17127
+ * a macro token anyway (D89), and correctly. Nothing here changes what the
17128
+ * subject IS: a cyclist stays one vehicle track, occupancy still counts one,
17129
+ * and a `person` rule still does not fire for someone cycling past.
17130
+ *
17131
+ * **Absent ≠ false**, exactly like {@link hasFace}: every row written before
17132
+ * the column, and every hub that predates the field, omits it. Test
17133
+ * `=== true` and render nothing otherwise — never infer "no rider".
17134
+ */
17135
+ hasRider: boolean().optional(),
17136
+ ...TrackFlagFields,
17137
+ ...TrackRetrainFields
16765
17138
  });
16766
- /** A frame the dataset OWNS: bytes copied at selection time. */
16767
- var RetrainFrameSchema = object({
16768
- frameId: string(),
17139
+ var BaseEventFields = {
17140
+ id: string(),
16769
17141
  deviceId: number(),
16770
- trackId: string(),
16771
- /** Provenance only. It may already point at nothing — that is expected. */
16772
- sourceMediaKey: string(),
16773
- sourceKind: MediaFileKindEnum,
16774
- sizeBytes: number().int(),
16775
- width: number().int(),
16776
- height: number().int(),
16777
- copiedAt: number()
16778
- });
16779
- /** Why a copy-on-select could not be honoured — named, never a silent skip. */
16780
- var RetrainCopyRefusalSchema = _enum([
16781
- "source-missing",
16782
- "unreadable-image",
16783
- "write-failed"
16784
- ]);
16785
- var RetrainFrameSelectionSchema = object({
16786
- copied: array(RetrainFrameSchema).readonly(),
16787
- refused: array(object({
16788
- sourceMediaKey: string(),
16789
- reason: RetrainCopyRefusalSchema
16790
- })).readonly()
16791
- });
16792
- var RetrainFrameListSchema = object({
16793
- candidates: array(RetrainFrameCandidateSchema).readonly(),
16794
- copies: array(RetrainFrameSchema).readonly(),
16795
- /** What the page pre-selects — the native key frame when one survives. */
16796
- autoPickMediaKey: string().optional()
17142
+ timestamp: number()
17143
+ };
17144
+ var MotionEventSchema = object({
17145
+ ...BaseEventFields,
17146
+ kind: literal("motion"),
17147
+ regionCount: number(),
17148
+ /** Heavy JSON array — omitted in slim projection. */
17149
+ regions: array(object({
17150
+ bbox: BoundingBoxSchema,
17151
+ pixelCount: number(),
17152
+ intensity: number()
17153
+ })).readonly().optional(),
17154
+ /** Omitted in slim projection. */
17155
+ frameWidth: number().optional(),
17156
+ /** Omitted in slim projection. */
17157
+ frameHeight: number().optional(),
17158
+ /** Populated by B5 (recording playback URL for this event). */
17159
+ mediaUrl: string().optional()
16797
17160
  });
16798
- /** What the operator asked the assist to look for. */
16799
- var RetrainAssistSubjectSchema = discriminatedUnion("kind", [object({
16800
- kind: literal("package"),
16801
- zone: RetrainBboxSchema.optional()
16802
- }), object({
16803
- kind: literal("objects"),
16804
- modelId: string(),
16805
- minScore: number().optional()
16806
- })]);
16807
17161
  /**
16808
- * The assist's answer a discriminated union, because "the model saw nothing"
16809
- * and "this node cannot run that model" lead to different next moves and a
16810
- * nullable result cannot tell them apart.
17162
+ * Which detection SOURCE produced an object event. `pipeline` = the ML
17163
+ * detection pipeline (decoded-frame inference); `onboard` = the camera's
17164
+ * native on-device AI. Both flow through the SAME analysis layers (zoning,
17165
+ * tracking, per-kind persistence) but stay distinguishable so consumers
17166
+ * (advanced-notifier, occupancy, …) can select which source(s) to act on.
17167
+ * Absent on legacy rows ⇒ treat as `pipeline`.
16811
17168
  */
16812
- var RetrainAssistResultSchema = discriminatedUnion("kind", [object({
16813
- kind: literal("proposed"),
16814
- modelId: string(),
16815
- stepId: string(),
16816
- minScore: number(),
16817
- /** Drafts, ready to edit. `source: 'assist'` until the operator touches one. */
16818
- proposals: array(RetrainAnnotationDraftSchema).readonly(),
16819
- /** Returned by the runner but removed by the threshold. */
16820
- belowThreshold: number().int()
16821
- }), object({
16822
- kind: literal("refused"),
16823
- /** `no-zone` is ours; the rest are the runner's own refusal vocabulary. */
16824
- reason: string(),
16825
- detail: string().optional()
16826
- })]);
16827
- /** The outcome of a lifecycle move owned by the retrain page. */
16828
- var RetrainTransitionResultSchema = object({
16829
- trackId: string(),
16830
- /** Where the track ended up, whatever happened. */
16831
- retrainStatus: RetrainStatusSchema,
16832
- /** `false` ⇒ the move was refused or was a no-op; `reason` says which. */
16833
- changed: boolean(),
16834
- reason: _enum([
16835
- "unknown-track",
16836
- "no-frames-copied",
16837
- "not-staging",
16838
- "not-trained",
16839
- "unchanged"
16840
- ]).optional()
17169
+ var DetectionSourceSchema = _enum(["pipeline", "onboard"]);
17170
+ /**
17171
+ * The confirmed zone crossing that produced an object event. Present ONLY on
17172
+ * an event emitted BY a crossing (`zone.enter` / `zone.exit`); a movement-state
17173
+ * event (`object.entering` / `leaving` / `stationary` / `loitering`) and an
17174
+ * appearance event carry none, so a rule asking for a direction fails closed
17175
+ * on them.
17176
+ *
17177
+ * Exactly ONE crossing per event: the emitter turns each confirmed crossing
17178
+ * into its own event, so a frame in which a track enters A while leaving B
17179
+ * produces two events with two directions — never one ambiguous row.
17180
+ *
17181
+ * `zoneId` is load-bearing for an EXIT: the event's `zones` list is the
17182
+ * membership the box has NOW, and by definition it no longer contains the zone
17183
+ * that was just left. Without the id here, a zone-scoped rule could never match
17184
+ * the exit it asked for.
17185
+ */
17186
+ var ZoneCrossingSchema = object({
17187
+ direction: _enum(["enter", "exit"]),
17188
+ /** Admin zone id crossed. */
17189
+ zoneId: string(),
17190
+ /** Zone display name at crossing time (falls back to the id). */
17191
+ zoneName: string().optional()
16841
17192
  });
16842
- var DEFAULT_EVENT_QUERY_LIMIT = 1e3;
16843
- var MAX_EVENT_QUERY_LIMIT = 5e3;
16844
- var DeviceEventQueryInput = object({
16845
- deviceId: number(),
16846
- since: number().optional(),
16847
- until: number().optional(),
16848
- limit: number().int().min(1).max(MAX_EVENT_QUERY_LIMIT).default(DEFAULT_EVENT_QUERY_LIMIT),
16849
- /** `slim` drops heavy JSON fields (regions/bbox/zones) and carries an
16850
- * optional `mediaUrl` (populated by B5). `full` (default) keeps today's
16851
- * exact behaviour. Callers may omit this field the store defaults to
16852
- * `full` when not provided. */
16853
- projection: _enum(["full", "slim"]).optional()
17193
+ var ObjectEventSchema = object({
17194
+ ...BaseEventFields,
17195
+ kind: literal("object"),
17196
+ /** Detection source. Optional for backward-compat; absent ⇒ `pipeline`. */
17197
+ source: DetectionSourceSchema.optional(),
17198
+ /**
17199
+ * Inference-frame id shared by every object event emitted from the SAME frame
17200
+ * the "scene/parent" key. Lets a consumer group co-occurring detections (e.g.
17201
+ * 2 people + 1 dog) under one full frame, and link a track's frames over time
17202
+ * (group by `trackId`, pick a representative `frameId` as the parent frame).
17203
+ * Optional for backward-compat with pre-existing rows / the slim projection
17204
+ * includes it (it is light). Absent on rows written before this field.
17205
+ */
17206
+ frameId: string().optional(),
17207
+ /** Omitted in slim projection. */
17208
+ trackId: string().optional(),
17209
+ className: string(),
17210
+ ...TieredLabelFields,
17211
+ /** Omitted in slim projection. */
17212
+ confidence: number().optional(),
17213
+ /** Heavy JSON — omitted in slim projection. */
17214
+ bbox: BoundingBoxSchema.optional(),
17215
+ /** Heavy JSON — omitted in slim projection. */
17216
+ zones: array(string()).readonly().optional(),
17217
+ /** Omitted in slim projection. */
17218
+ state: TrackStateSchema.optional(),
17219
+ /**
17220
+ * The zone crossing this event IS, when it is one. Absent on every other
17221
+ * event kind (movement state, appearance, package) — see
17222
+ * {@link ZoneCrossingSchema}. Omitted in slim projection.
17223
+ */
17224
+ zoneCrossing: ZoneCrossingSchema.optional(),
17225
+ /** Detection-frame dimensions in pixels — let consumers normalize the
17226
+ * pixel-space `bbox` onto a displayed image. Omitted in slim projection. */
17227
+ frameWidth: number().optional(),
17228
+ frameHeight: number().optional(),
17229
+ /** MediaStore key for the crop attached to this event (if any). */
17230
+ mediaKey: string().optional(),
17231
+ /** Design B: MediaStore key of the track's native-resolution key frame (the
17232
+ * best-detection full frame). Resolve via the event-media data-plane
17233
+ * (`/addon/<addonId>/event-media/<keyFrameMediaKey>`) for a detail view that
17234
+ * draws `bbox` over the native frame. Absent on legacy rows / non-decoded
17235
+ * sources — consumers fall back to `mediaKey` (the tight crop). */
17236
+ keyFrameMediaKey: string().optional(),
17237
+ /** Populated by B5 (recording playback URL for this event). */
17238
+ mediaUrl: string().optional(),
17239
+ /** The parent track's key-event importance [0,1], propagated to every object
17240
+ * event of the track (so an event row can be sorted by importance without a
17241
+ * track join). Absent on legacy rows / before the track was scored. */
17242
+ importance: number().optional()
16854
17243
  });
16855
- var ObjectEventQueryInput = DeviceEventQueryInput.extend({ classFilter: string().optional() });
16856
- var RecentTracksQueryInput = object({
16857
- /** Devices to merge. An empty array yields `{ tracks: [], nextCursor: null }`. */
16858
- deviceIds: array(number()),
16859
- /** Window lower bound on `lastSeen` (inclusive). */
16860
- since: number().optional(),
16861
- /** Window upper bound on `lastSeen` (inclusive). */
16862
- until: number().optional(),
16863
- /** Page size. Default 200, max 1000. */
16864
- limit: number().int().min(1).max(1e3).default(200),
16865
- /** Opaque continuation cursor from a previous page's `nextCursor`.
16866
- * Encodes the (lastSeen, trackId) sort position — treat as opaque. */
16867
- cursor: string().optional(),
16868
- /** See {@link TrackProjectionSchema}. Default `full`. */
16869
- projection: TrackProjectionSchema.optional(),
16870
- /** Include stationary-promoted rows (parked objects). Default false: the
16871
- * feed lists passages; parking records live on the stationary registry. */
16872
- includeStationary: boolean().optional()
17244
+ var AudioEventSchema = object({
17245
+ ...BaseEventFields,
17246
+ kind: literal("audio"),
17247
+ rms: number(),
17248
+ dbfs: number(),
17249
+ classification: object({
17250
+ className: string(),
17251
+ originalClass: string().optional(),
17252
+ score: number()
17253
+ }).optional(),
17254
+ /** Populated by B5 (recording playback URL for this event). */
17255
+ mediaUrl: string().optional()
16873
17256
  });
16874
- var RecentTracksPageSchema = object({
16875
- /** Merged page, ordered by (`lastSeen` DESC, `trackId` DESC). */
16876
- tracks: array(TrackSchema).readonly(),
16877
- /** Cursor for the next page, or null when this page is the last. */
16878
- nextCursor: string().nullable()
17257
+ var MediaFileKindEnum = _enum([
17258
+ "crop",
17259
+ "thumbnail",
17260
+ "snapshot",
17261
+ "firstFrame",
17262
+ "lastFrame",
17263
+ "fullFrame",
17264
+ "fullFrameBoxed",
17265
+ "faceCrop",
17266
+ "plateCrop",
17267
+ "keyFrame",
17268
+ "keyFrameSmall",
17269
+ "thumbnailSmall"
17270
+ ]);
17271
+ var MediaFileSchema = object({
17272
+ key: string(),
17273
+ kind: MediaFileKindEnum,
17274
+ base64: string(),
17275
+ sizeBytes: number(),
17276
+ timestamp: number()
16879
17277
  });
16880
- var LIST_GROUPS_DEFAULT_LIMIT = 40;
16881
- var LIST_GROUPS_MAX_LIMIT = 100;
16882
- var AnalyticsGroupRecordSchema = object({
17278
+ /**
17279
+ * One media row WITHOUT its bytes.
17280
+ *
17281
+ * A track's media is 5-8 MB of base64 (measured: 7.67 MB across 23 files for a
17282
+ * 140 s track), and a client that renders tiles from the media data plane needs
17283
+ * to know only WHAT EXISTS — the bytes then arrive per tile, lazily, over HTTP
17284
+ * with an immutable cache, instead of all at once inside a tRPC response that
17285
+ * blocks the whole view.
17286
+ *
17287
+ * `sizeBytes` is carried because it is what lets a client decide between the
17288
+ * stored blob and a `?variant=thumb` rendering without fetching either.
17289
+ */
17290
+ var MediaFileInfoSchema = MediaFileSchema.omit({ base64: true });
17291
+ /**
17292
+ * The MACRO tier of an annotation — a CLOSED set.
17293
+ *
17294
+ * This is what the exported detector predicts, so a typo here is a new class
17295
+ * with one example in it. `label` and `subLabel` are open strings by contrast:
17296
+ * the whole point of the page is teaching the model things it does not know
17297
+ * yet, and constraining that vocabulary would make it useless.
17298
+ *
17299
+ * A macro class is NEVER a label. The provider refuses a write whose `label` or
17300
+ * `subLabel` is one of these values, in any casing, because once `person`
17301
+ * exists in both tiers "every person box" stops being answerable without
17302
+ * knowing every string anyone ever typed — and the damage is retroactive.
17303
+ */
17304
+ var RetrainMacroClassSchema = _enum([
17305
+ "person",
17306
+ "vehicle",
17307
+ "animal",
17308
+ "package",
17309
+ "face",
17310
+ "plate"
17311
+ ]);
17312
+ /** A subject to learn, or a phantom to unlearn (taught by OMISSION). */
17313
+ var RetrainAnnotationKindSchema = _enum(["subject", "model_error"]);
17314
+ /** Did a human draw this box, or did the assist propose it? */
17315
+ var RetrainAnnotationSourceSchema = _enum(["operator", "assist"]);
17316
+ /** Normalised `[0,1]` rectangle against the FULL frame — the canonical form. */
17317
+ var RetrainBboxSchema = object({
17318
+ x: number(),
17319
+ y: number(),
17320
+ w: number(),
17321
+ h: number()
17322
+ });
17323
+ /**
17324
+ * One annotated subject.
17325
+ *
17326
+ * `bbox` is normalised against the full frame, ALWAYS. The per-model shapes
17327
+ * (letterboxed root / zone-cropped package / subject-cropped classifier) are
17328
+ * derived from it at export and never stored — storing them is how one feature
17329
+ * space ends up holding two crops of the same subject (D52).
17330
+ */
17331
+ var RetrainAnnotationSchema = object({
16883
17332
  id: string(),
16884
- deviceId: number().int(),
16885
- openedAt: number().int(),
16886
- closedAt: number().int(),
16887
- timestamp: number().int(),
16888
- memberCount: number().int(),
16889
- memberTrackIds: array(string()).readonly(),
16890
- className: string(),
16891
- classes: array(string()).readonly(),
16892
- /** Relative event-media path, or null when the group has no picture yet. */
16893
- mediaUrl: string().nullable(),
16894
- singleton: boolean()
17333
+ trackId: string(),
17334
+ deviceId: number(),
17335
+ /** The COPY in retrain storage — never the source track's media key. */
17336
+ mediaKey: string(),
17337
+ bbox: RetrainBboxSchema,
17338
+ macroClass: RetrainMacroClassSchema,
17339
+ label: string().optional(),
17340
+ subLabel: string().optional(),
17341
+ kind: RetrainAnnotationKindSchema,
17342
+ source: RetrainAnnotationSourceSchema,
17343
+ /** Which model proposed this box — or, on a `model_error`, drew the phantom. */
17344
+ assistModelId: string().optional(),
17345
+ assistScore: number().optional(),
17346
+ exportedInBatch: string().optional(),
17347
+ createdAt: number()
16895
17348
  });
16896
- var AnalyticsGroupMemberSchema = object({
17349
+ /** The write form — the server owns `id`, `createdAt` and the frame binding. */
17350
+ var RetrainAnnotationDraftSchema = RetrainAnnotationSchema.omit({
17351
+ id: true,
17352
+ trackId: true,
17353
+ deviceId: true,
17354
+ mediaKey: true,
17355
+ createdAt: true,
17356
+ exportedInBatch: true
17357
+ });
17358
+ /** A track sitting in `staging`, with everything the worklist needs to rank it. */
17359
+ var RetrainTrackSchema = object({
16897
17360
  trackId: string(),
16898
- deviceId: number().int(),
17361
+ deviceId: number(),
16899
17362
  className: string(),
16900
- firstSeen: number().int(),
16901
- lastSeen: number().int(),
16902
- mediaUrl: string().nullable()
16903
- });
16904
- var AnalyticsGroupDetailSchema = AnalyticsGroupRecordSchema.extend({ members: array(AnalyticsGroupMemberSchema).readonly() });
16905
- var ListGroupsQueryInput = object({
16906
- /** Devices to merge. An empty array yields `{ groups: [], nextCursor: null }`. */
16907
- deviceIds: array(number()),
16908
- /** Window lower bound on `closedAt` (inclusive). */
16909
- since: number().optional(),
16910
- /** Window upper bound on `openedAt` (inclusive). */
16911
- until: number().optional(),
16912
- limit: number().int().min(1).max(LIST_GROUPS_MAX_LIMIT).default(LIST_GROUPS_DEFAULT_LIMIT),
16913
- /** Opaque continuation cursor from a previous page's `nextCursor`. */
16914
- cursor: string().optional()
17363
+ label: string().optional(),
17364
+ firstSeen: number(),
17365
+ lastSeen: number(),
17366
+ /** How many frames the dataset already holds from this track. */
17367
+ frameCount: number().int(),
17368
+ /** How many subjects have been annotated on those frames. `0` with
17369
+ * `frameCount: 0` is exactly "staging, still to work". */
17370
+ annotationCount: number().int()
16915
17371
  });
16916
- var ListGroupsPageSchema = object({
16917
- groups: array(AnalyticsGroupRecordSchema).readonly(),
16918
- nextCursor: string().nullable()
17372
+ /** A frame the picker may offer — an index row, no blob was read to produce it. */
17373
+ var RetrainFrameCandidateSchema = object({
17374
+ mediaKey: string(),
17375
+ kind: MediaFileKindEnum,
17376
+ timestamp: number(),
17377
+ sizeBytes: number().int(),
17378
+ /** A copy of this original already exists — selecting it is free and cannot
17379
+ * fail, whatever became of the original. */
17380
+ copied: boolean()
16919
17381
  });
16920
- var KeyEventQueryInput = object({
17382
+ /** A frame the dataset OWNS: bytes copied at selection time. */
17383
+ var RetrainFrameSchema = object({
17384
+ frameId: string(),
16921
17385
  deviceId: number(),
16922
- /** Window lower bound (track firstSeen ≥ since). */
16923
- since: number(),
16924
- /** Window upper bound (track firstSeen ≤ until). */
17386
+ trackId: string(),
17387
+ /** Provenance only. It may already point at nothing — that is expected. */
17388
+ sourceMediaKey: string(),
17389
+ sourceKind: MediaFileKindEnum,
17390
+ sizeBytes: number().int(),
17391
+ width: number().int(),
17392
+ height: number().int(),
17393
+ copiedAt: number()
17394
+ });
17395
+ /** Why a copy-on-select could not be honoured — named, never a silent skip. */
17396
+ var RetrainCopyRefusalSchema = _enum([
17397
+ "source-missing",
17398
+ "unreadable-image",
17399
+ "write-failed"
17400
+ ]);
17401
+ var RetrainFrameSelectionSchema = object({
17402
+ copied: array(RetrainFrameSchema).readonly(),
17403
+ refused: array(object({
17404
+ sourceMediaKey: string(),
17405
+ reason: RetrainCopyRefusalSchema
17406
+ })).readonly()
17407
+ });
17408
+ var RetrainFrameListSchema = object({
17409
+ candidates: array(RetrainFrameCandidateSchema).readonly(),
17410
+ copies: array(RetrainFrameSchema).readonly(),
17411
+ /** What the page pre-selects — the native key frame when one survives. */
17412
+ autoPickMediaKey: string().optional()
17413
+ });
17414
+ /** What the operator asked the assist to look for. */
17415
+ var RetrainAssistSubjectSchema = discriminatedUnion("kind", [object({
17416
+ kind: literal("package"),
17417
+ zone: RetrainBboxSchema.optional()
17418
+ }), object({
17419
+ kind: literal("objects"),
17420
+ modelId: string(),
17421
+ minScore: number().optional()
17422
+ })]);
17423
+ /**
17424
+ * The assist's answer — a discriminated union, because "the model saw nothing"
17425
+ * and "this node cannot run that model" lead to different next moves and a
17426
+ * nullable result cannot tell them apart.
17427
+ */
17428
+ var RetrainAssistResultSchema = discriminatedUnion("kind", [object({
17429
+ kind: literal("proposed"),
17430
+ modelId: string(),
17431
+ stepId: string(),
17432
+ minScore: number(),
17433
+ /** Drafts, ready to edit. `source: 'assist'` until the operator touches one. */
17434
+ proposals: array(RetrainAnnotationDraftSchema).readonly(),
17435
+ /** Returned by the runner but removed by the threshold. */
17436
+ belowThreshold: number().int()
17437
+ }), object({
17438
+ kind: literal("refused"),
17439
+ /** `no-zone` is ours; the rest are the runner's own refusal vocabulary. */
17440
+ reason: string(),
17441
+ detail: string().optional()
17442
+ })]);
17443
+ /** The outcome of a lifecycle move owned by the retrain page. */
17444
+ var RetrainTransitionResultSchema = object({
17445
+ trackId: string(),
17446
+ /** Where the track ended up, whatever happened. */
17447
+ retrainStatus: RetrainStatusSchema,
17448
+ /** `false` ⇒ the move was refused or was a no-op; `reason` says which. */
17449
+ changed: boolean(),
17450
+ reason: _enum([
17451
+ "unknown-track",
17452
+ "no-frames-copied",
17453
+ "not-staging",
17454
+ "not-trained",
17455
+ "unchanged"
17456
+ ]).optional()
17457
+ });
17458
+ var DEFAULT_EVENT_QUERY_LIMIT = 1e3;
17459
+ var MAX_EVENT_QUERY_LIMIT = 5e3;
17460
+ var DeviceEventQueryInput = object({
17461
+ deviceId: number(),
17462
+ since: number().optional(),
17463
+ until: number().optional(),
17464
+ limit: number().int().min(1).max(MAX_EVENT_QUERY_LIMIT).default(DEFAULT_EVENT_QUERY_LIMIT),
17465
+ /** `slim` drops heavy JSON fields (regions/bbox/zones) and carries an
17466
+ * optional `mediaUrl` (populated by B5). `full` (default) keeps today's
17467
+ * exact behaviour. Callers may omit this field — the store defaults to
17468
+ * `full` when not provided. */
17469
+ projection: _enum(["full", "slim"]).optional()
17470
+ });
17471
+ var ObjectEventQueryInput = DeviceEventQueryInput.extend({ classFilter: string().optional() });
17472
+ var RecentTracksQueryInput = object({
17473
+ /** Devices to merge. An empty array yields `{ tracks: [], nextCursor: null }`. */
17474
+ deviceIds: array(number()),
17475
+ /** Window lower bound on `lastSeen` (inclusive). */
17476
+ since: number().optional(),
17477
+ /** Window upper bound on `lastSeen` (inclusive). */
17478
+ until: number().optional(),
17479
+ /** Page size. Default 200, max 1000. */
17480
+ limit: number().int().min(1).max(1e3).default(200),
17481
+ /** Opaque continuation cursor from a previous page's `nextCursor`.
17482
+ * Encodes the (lastSeen, trackId) sort position — treat as opaque. */
17483
+ cursor: string().optional(),
17484
+ /** See {@link TrackProjectionSchema}. Default `full`. */
17485
+ projection: TrackProjectionSchema.optional(),
17486
+ /** Include stationary-promoted rows (parked objects). Default false: the
17487
+ * feed lists passages; parking records live on the stationary registry. */
17488
+ includeStationary: boolean().optional()
17489
+ });
17490
+ var RecentTracksPageSchema = object({
17491
+ /** Merged page, ordered by (`lastSeen` DESC, `trackId` DESC). */
17492
+ tracks: array(TrackSchema).readonly(),
17493
+ /** Cursor for the next page, or null when this page is the last. */
17494
+ nextCursor: string().nullable()
17495
+ });
17496
+ var LIST_GROUPS_DEFAULT_LIMIT = 40;
17497
+ var LIST_GROUPS_MAX_LIMIT = 100;
17498
+ var AnalyticsGroupRecordSchema = object({
17499
+ id: string(),
17500
+ deviceId: number().int(),
17501
+ openedAt: number().int(),
17502
+ closedAt: number().int(),
17503
+ timestamp: number().int(),
17504
+ memberCount: number().int(),
17505
+ memberTrackIds: array(string()).readonly(),
17506
+ className: string(),
17507
+ classes: array(string()).readonly(),
17508
+ /** Relative event-media path, or null when the group has no picture yet. */
17509
+ mediaUrl: string().nullable(),
17510
+ singleton: boolean()
17511
+ });
17512
+ var AnalyticsGroupMemberSchema = object({
17513
+ trackId: string(),
17514
+ deviceId: number().int(),
17515
+ className: string(),
17516
+ firstSeen: number().int(),
17517
+ lastSeen: number().int(),
17518
+ mediaUrl: string().nullable()
17519
+ });
17520
+ var AnalyticsGroupDetailSchema = AnalyticsGroupRecordSchema.extend({ members: array(AnalyticsGroupMemberSchema).readonly() });
17521
+ var ListGroupsQueryInput = object({
17522
+ /** Devices to merge. An empty array yields `{ groups: [], nextCursor: null }`. */
17523
+ deviceIds: array(number()),
17524
+ /** Window lower bound on `closedAt` (inclusive). */
17525
+ since: number().optional(),
17526
+ /** Window upper bound on `openedAt` (inclusive). */
17527
+ until: number().optional(),
17528
+ limit: number().int().min(1).max(LIST_GROUPS_MAX_LIMIT).default(LIST_GROUPS_DEFAULT_LIMIT),
17529
+ /** Opaque continuation cursor from a previous page's `nextCursor`. */
17530
+ cursor: string().optional()
17531
+ });
17532
+ var ListGroupsPageSchema = object({
17533
+ groups: array(AnalyticsGroupRecordSchema).readonly(),
17534
+ nextCursor: string().nullable()
17535
+ });
17536
+ var KeyEventQueryInput = object({
17537
+ deviceId: number(),
17538
+ /** Window lower bound (track firstSeen ≥ since). */
17539
+ since: number(),
17540
+ /** Window upper bound (track firstSeen ≤ until). */
16925
17541
  until: number(),
16926
17542
  limit: number().int().min(1).max(200).default(50),
16927
17543
  /** Drop tracks scoring below this importance. */
@@ -17120,6 +17736,24 @@ var RebuildStatusSchema = object({
17120
17736
  /** Present when the pass ended by throwing. */
17121
17737
  error: string().nullable()
17122
17738
  });
17739
+ var ReplayFrameInputSchema = object({
17740
+ timestamp: number(),
17741
+ frame: PipelineRunResultBridge
17742
+ });
17743
+ var RunReplayFrameProcessorResultSchema = object({ tracks: array(object({
17744
+ className: string(),
17745
+ firstSeenMs: number(),
17746
+ lastSeenMs: number(),
17747
+ /** Bbox of the track's FIRST matched detection, pixel-space in the clip's
17748
+ * frame — a representative box for the diff's `(className, window, IoU)`
17749
+ * pairing (`replay-diff.ts`). A replay does not need the full per-frame
17750
+ * trajectory production's `Track.positions` keeps. */
17751
+ bbox: BoundingBoxSchema,
17752
+ /** How many of the input frames this track matched a real detection on
17753
+ * (never a coasted/extrapolated frame) — the replay's own signal for "how
17754
+ * solid is this track", cheaper than re-deriving it from a trajectory. */
17755
+ framesMatched: number().int()
17756
+ })).readonly() });
17123
17757
  DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).readonly()), method(object({
17124
17758
  deviceId: number(),
17125
17759
  trackId: string()
@@ -17290,502 +17924,80 @@ DeviceType.Camera, method(object({ deviceId: number() }), array(TrackSchema).rea
17290
17924
  }), RetrainAssistResultSchema, {
17291
17925
  kind: "mutation",
17292
17926
  auth: "admin"
17293
- }), method(object({ trackId: string() }), array(RetrainAnnotationSchema).readonly(), {
17294
- kind: "query",
17295
- auth: "admin"
17296
- }), method(object({
17297
- deviceId: number(),
17298
- trackId: string(),
17299
- frameId: string(),
17300
- annotations: array(RetrainAnnotationDraftSchema)
17301
- }), array(RetrainAnnotationSchema).readonly(), {
17302
- kind: "mutation",
17303
- auth: "admin"
17304
- }), method(object({
17305
- deviceId: number(),
17306
- trackId: string()
17307
- }), RetrainTransitionResultSchema, {
17308
- kind: "mutation",
17309
- auth: "admin"
17310
17927
  }), method(object({
17311
17928
  deviceId: number(),
17312
- trackId: string()
17313
- }), RetrainTransitionResultSchema, {
17929
+ source: DetectionSourceSchema,
17930
+ zones: array(ZoneSchema).readonly().optional(),
17931
+ detectionRules: array(ZoneRuleSchema).readonly().optional(),
17932
+ zoneMembershipMinOverlap: number().min(0).max(1).optional(),
17933
+ frames: array(ReplayFrameInputSchema).min(1)
17934
+ }), RunReplayFrameProcessorResultSchema, {
17314
17935
  kind: "mutation",
17315
17936
  auth: "admin"
17316
- }), method(object({ deviceIds: array(number()).optional() }), object({ url: string() }), {
17937
+ }), method(object({ trackId: string() }), array(RetrainAnnotationSchema).readonly(), {
17317
17938
  kind: "query",
17318
17939
  auth: "admin"
17319
17940
  }), method(object({
17320
- eventId: string(),
17321
- kind: MediaFileKindEnum.optional(),
17322
- deviceId: number()
17323
- }), array(MediaFileSchema).readonly()), method(object({
17324
- trackId: string(),
17325
- kinds: array(MediaFileKindEnum).optional(),
17326
- deviceId: number()
17327
- }), array(MediaFileSchema).readonly()), method(object({
17328
- trackId: string(),
17329
- deviceId: number()
17330
- }), array(MediaFileInfoSchema).readonly()), method(SearchObjectEventsInput, array(ScoredObjectEventSchema).readonly()), method(object({}), WipeObjectEmbeddingsResultSchema, {
17331
- kind: "mutation",
17332
- auth: "admin"
17333
- }), method(RebuildObjectEmbeddingsInput, RebuildObjectEmbeddingsResultSchema, {
17334
- kind: "mutation",
17335
- auth: "admin"
17336
- }), method(object({}), RebuildStatusSchema), object({
17337
- deviceId: number(),
17338
- timestamp: number(),
17339
- frameWidth: number(),
17340
- frameHeight: number(),
17341
- detections: array(OverlayDetectionSchema).readonly()
17342
- }), object({
17343
- deviceId: number(),
17344
- trackId: string(),
17345
- className: string()
17346
- }), object({
17347
17941
  deviceId: number(),
17348
17942
  trackId: string(),
17349
- className: string(),
17350
- durationMs: number()
17351
- }), object({
17352
- deviceId: number(),
17353
- kind: EventKindSchema,
17354
- eventId: string(),
17355
- timestamp: number()
17356
- });
17357
- /**
17358
- * Reference to the frame's retained NATIVE surface + the parent crop's placement
17359
- * within the frame, so the executor can re-cut a leaf child ROI at native
17360
- * resolution on the detail plane. See the `runPipeline` `nativeCropRef` field.
17361
- */
17362
- var NativeCropRefSchema = object({
17363
- /** Handle keying the retained native surface (node-pinned to its owner). */
17364
- handle: FrameHandleSchema,
17365
- /** The parent crop's padded/clamped rectangle in FRAME-space pixels. */
17366
- cropFrameSpace: object({
17367
- x: number(),
17368
- y: number(),
17369
- w: number(),
17370
- h: number()
17371
- })
17372
- });
17373
- object({
17374
- crop: object({
17375
- left: number(),
17376
- top: number(),
17377
- width: number().positive(),
17378
- height: number().positive()
17379
- }).optional(),
17380
- content: object({
17381
- width: number().int().positive(),
17382
- height: number().int().positive()
17383
- }),
17384
- fit: _enum(["stretch", "contain"]),
17385
- format: _enum([
17386
- "rgb",
17387
- "gray",
17388
- "jpeg"
17389
- ])
17390
- });
17391
- /**
17392
- * Process-local frame identity. It is serializable so it can ride an in-process
17393
- * capability call, but `registryId` deliberately prevents resolution in any
17394
- * other process or execution group.
17395
- */
17396
- var FrameRefSchema = object({
17397
- registryId: string().min(1),
17398
- id: string().min(1),
17399
- width: number().int().positive(),
17400
- height: number().int().positive(),
17401
- format: _enum(["rgb", "gray"]),
17402
- timestamp: number(),
17403
- capturedAt: number().optional()
17404
- });
17405
- var ModelFormatSchema$1 = _enum([
17406
- "onnx",
17407
- "coreml",
17408
- "openvino",
17409
- "tflite",
17410
- "pt",
17411
- "gguf"
17412
- ]);
17413
- var PipelineSlotSchema = _enum([
17414
- "detector",
17415
- "cropper",
17416
- "classifier",
17417
- "refiner",
17418
- "audio-classifier"
17419
- ]);
17420
- var PipelineEngineChoiceSchema = object({
17421
- runtime: _enum(["node", "python"]),
17422
- backend: string(),
17423
- format: ModelFormatSchema$1,
17424
- device: string().optional()
17425
- });
17426
- var AvailableEngineSchema = object({
17427
- engine: PipelineEngineChoiceSchema,
17428
- devices: array(object({
17429
- id: string(),
17430
- label: string(),
17431
- description: string().optional()
17432
- })).readonly(),
17433
- defaultDevice: string()
17434
- });
17435
- var PipelineDefaultStepSchema = lazy(() => object({
17436
- addonId: string(),
17437
- addonName: string(),
17438
- slot: PipelineSlotSchema,
17439
- inputClasses: array(string()).readonly(),
17440
- outputClasses: array(string()).readonly(),
17441
- enabled: boolean(),
17442
- modelId: string(),
17443
- children: array(PipelineDefaultStepSchema).readonly(),
17444
- group: string().optional(),
17445
- settings: record(string(), unknown()).optional()
17446
- }));
17447
- var PipelineTemplateStepSchema = lazy(() => object({
17448
- addonId: string(),
17449
- enabled: boolean(),
17450
- modelId: string(),
17451
- children: array(PipelineTemplateStepSchema).readonly(),
17452
- settings: record(string(), unknown()).optional()
17453
- }));
17454
- var PipelineTemplateSchema$1 = object({
17455
- id: string(),
17456
- name: string(),
17457
- createdAt: string(),
17458
- updatedAt: string(),
17459
- engine: PipelineEngineChoiceSchema,
17460
- steps: array(PipelineTemplateStepSchema).readonly()
17461
- });
17462
- var PipelineModelOptionSchema = object({
17463
- id: string(),
17464
- name: string(),
17465
- formats: record(string(), object({
17466
- downloaded: boolean(),
17467
- sizeMB: number()
17468
- })),
17469
- group: ModelVariantGroupSchema.optional(),
17470
- legacy: boolean().optional(),
17471
- provider: ModelProviderIdSchema.optional()
17472
- });
17473
- var ConfigFieldBridge = custom();
17474
- var PipelineAddonSchemaSchema = object({
17475
- id: string(),
17476
- name: string(),
17477
- slot: PipelineSlotSchema,
17478
- inputClasses: array(string()).readonly(),
17479
- outputClasses: array(string()).readonly(),
17480
- childSlots: array(PipelineSlotSchema).readonly(),
17481
- models: array(PipelineModelOptionSchema).readonly(),
17482
- defaultModelId: string(),
17483
- defaultModelIdByFormat: record(string(), string()).optional(),
17484
- enabledByDefault: boolean().optional(),
17485
- backfillIntoExistingOverrides: boolean().optional(),
17486
- defaultConfidence: number(),
17487
- group: string().optional(),
17488
- configSchema: array(ConfigFieldBridge).readonly().optional()
17489
- });
17490
- var PipelineSlotSchemaSchema = object({
17491
- id: PipelineSlotSchema,
17492
- label: string(),
17493
- priority: number(),
17494
- parentSlot: PipelineSlotSchema.nullable(),
17495
- addons: array(PipelineAddonSchemaSchema).readonly()
17496
- });
17497
- var PipelineSchemaSchema = object({
17498
- availableEngines: array(AvailableEngineSchema).readonly(),
17499
- selectedEngine: PipelineEngineChoiceSchema,
17500
- slots: array(PipelineSlotSchemaSchema).readonly()
17501
- });
17502
- var EngineProvisioningSchema = object({
17503
- runtimeId: _enum([
17504
- "onnx",
17505
- "openvino",
17506
- "coreml",
17507
- "edgetpu"
17508
- ]).nullable(),
17509
- device: string().nullable(),
17510
- state: _enum([
17511
- "idle",
17512
- "installing",
17513
- "verifying",
17514
- "ready",
17515
- "failed"
17516
- ]),
17517
- progress: number().optional(),
17518
- error: string().optional(),
17519
- nextRetryAt: number().optional(),
17520
- /**
17521
- * Gate A (config-correctness gate at engine change): human-readable
17522
- * config issues surfaced EAGERLY when the node's engine changes — model
17523
- * substitutions ("chose X, running Y") and zero-build steps ("no model
17524
- * has a <format> build"). Additive/optional: informational only, never
17525
- * enforced here — `assertEngineReady` (readiness) still gates inference.
17526
- * Absent/empty when the node-default tree resolves cleanly.
17527
- */
17528
- configIssues: array(string()).optional()
17529
- });
17530
- var PipelineStepInputSchema = lazy(() => object({
17531
- addonId: string(),
17532
- modelId: string().optional(),
17533
- enabled: boolean().default(true),
17534
- children: array(PipelineStepInputSchema).optional(),
17535
- settings: record(string(), unknown()).optional(),
17536
- jumpDeviceKey: string().optional()
17537
- }));
17538
- var ModelSubstitutionSchema = object({
17539
- addonId: string(),
17540
- chosen: string(),
17541
- running: string(),
17542
- format: string()
17543
- });
17544
- var PipelineValidationIssueSchema = object({
17545
- addonId: string(),
17546
- kind: _enum(["unknown-addon", "no-format-build"]),
17547
- detail: string()
17548
- });
17549
- var PipelineValidationResultSchema = object({
17550
- ok: boolean(),
17551
- issues: array(PipelineValidationIssueSchema).readonly(),
17552
- substitutions: array(ModelSubstitutionSchema).readonly(),
17553
- /** The node's `currentEngine.format` this validation ran against. */
17554
- format: string()
17555
- });
17556
- var ReferenceImageEntrySchema = object({
17557
- filename: string(),
17558
- stepIds: array(string()).readonly().optional()
17559
- });
17560
- var ReferenceImageBodySchema = object({
17561
- base64: string(),
17562
- filename: string()
17563
- });
17564
- var ReferenceAudioEntrySchema = object({
17565
- filename: string(),
17566
- sizeKb: number()
17567
- });
17568
- var ReferenceAudioBodySchema = object({ base64: string() });
17569
- var AudioBackendSchema = object({
17570
- id: string(),
17571
- name: string(),
17572
- description: string(),
17573
- available: boolean(),
17574
- /**
17575
- * Raw classifier labels this backend can emit (e.g. YAMNet's
17576
- * 521-class set or Apple SoundAnalysis's 303-class set). Used by
17577
- * the benchmark UI to populate the `enabledMicroClasses` filter
17578
- * specific to the selected backend without a separate fetch.
17579
- */
17580
- rawLabels: array(string()).readonly().optional()
17581
- });
17582
- var AudioCapabilitiesSchema = object({
17583
- activeBackend: string(),
17584
- availableBackends: array(AudioBackendSchema).readonly(),
17585
- sampleRate: number(),
17586
- chunkDurationMs: number()
17587
- });
17588
- var DownloadModelResultSchema = object({
17589
- filePath: string(),
17590
- sizeMB: number(),
17591
- durationMs: number()
17592
- });
17593
- /**
17594
- * Wrapper carrying a single test run's result. Replaces the legacy
17595
- * ad-hoc `{labels: [{className, originalClass, score}]}` shape with the
17596
- * canonical `AudioResult` from the Phase 6 output rework: one
17597
- * `AudioDetection` per class above `minScore`, top-N candidates in
17598
- * `debug.alternateLabels['audio-classifier']`, per-source timings in
17599
- * `debug.stepTimings`. The outer `success`/`error` fields stay so the
17600
- * benchmark UI can still report a clean failure when the classifier
17601
- * cap isn't available.
17602
- */
17603
- var AudioTestResultSchema = object({
17604
- success: boolean(),
17605
- error: string().optional(),
17606
- frame: custom().optional()
17607
- });
17608
- var PipelineConfigBridge = custom();
17609
- var ConfigUISchemaBridge = custom();
17610
- var ConfigUISchemaNullableBridge = custom();
17611
- var InferenceCapabilitiesBridge = custom();
17612
- var ModelAvailabilityListBridge = custom();
17613
- var PipelineRunResultBridge = custom();
17614
- method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngineChoiceSchema), method(PipelineEngineChoiceSchema, array(PipelineDefaultStepSchema)), method(object({ nodeId: string() }), EngineProvisioningSchema), method(_void(), record(string(), object({
17615
- modelId: string(),
17616
- settings: record(string(), unknown()).readonly()
17617
- }))), method(object({ steps: record(string(), object({
17618
- modelId: string(),
17619
- settings: record(string(), unknown()).readonly()
17620
- })) }), object({ success: literal(true) }), {
17621
- kind: "mutation",
17622
- auth: "admin"
17623
- }), method(object({ nodeId: string() }), object({
17624
- success: literal(true),
17625
- clearedDevices: number()
17626
- }), {
17627
- kind: "mutation",
17628
- auth: "admin"
17629
- }), 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({
17630
- name: string(),
17631
- steps: array(PipelineTemplateStepSchema).readonly(),
17632
- engine: PipelineEngineChoiceSchema
17633
- }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({
17634
- id: string(),
17635
- name: string().optional(),
17636
- steps: array(PipelineTemplateStepSchema).readonly().optional()
17637
- }), PipelineTemplateSchema$1, { kind: "mutation" }), method(object({ id: string() }), _void(), { kind: "mutation" }), method(_void(), InferenceCapabilitiesBridge), method(object({ addonId: string() }), ModelAvailabilityListBridge), method(object({
17638
- addonId: string(),
17639
- modelId: string(),
17640
- format: ModelFormatSchema$1
17641
- }), DownloadModelResultSchema, { kind: "mutation" }), method(object({
17642
- addonId: string(),
17643
- modelId: string(),
17644
- format: ModelFormatSchema$1
17645
- }), object({ success: literal(true) }), { kind: "mutation" }), method(object({
17646
- engine: PipelineEngineChoiceSchema.optional(),
17647
- steps: array(PipelineStepInputSchema).min(1),
17648
- frame: FrameInputSchema.optional(),
17649
- /**
17650
- * Process-local lazy frame. Valid only when caller and provider resolve
17651
- * in the same execution-group process; split/cross-node callers use
17652
- * `frame`/`image` inline compatibility instead.
17653
- */
17654
- frameRef: FrameRefSchema.optional(),
17655
- /**
17656
- * CB5 shm passthrough — a `FrameHandle` naming the same ring slot
17657
- * the decoded pixels live in. One more member of the one-of
17658
- * frame/frameHandle/image/imageBase64/referenceImage group.
17659
- */
17660
- frameHandle: FrameHandleSchema.optional(),
17661
- imageBase64: string().optional(),
17662
- /**
17663
- * Binary JPEG bytes — preferred over `imageBase64` on internal
17664
- * hops (hub → forked worker via Moleculer MsgPack) because it
17665
- * skips the 33% base64 overhead + the per-call base64 decode on
17666
- * the detection-pipeline worker. Callers can pass either; exactly
17667
- * one of `frame`/`image`/`imageBase64`/`referenceImage` is required.
17668
- */
17669
- image: _instanceof(Uint8Array).optional(),
17670
- referenceImage: string().optional(),
17671
- deviceId: number().optional(),
17672
- sessionId: string().optional(),
17673
- /**
17674
- * Execution plane. 'full' (default) runs the whole tree — benchmark,
17675
- * reference-image, and detail-subtree calls. 'frame' is the live
17676
- * per-frame dispatch: ONLY root-plane steps run; crop children
17677
- * (inputClasses ≠ null) are skipped and served per-track via
17678
- * pipelineRunner.runDetailSubtree (two-plane design).
17679
- */
17680
- plane: _enum(["full", "frame"]).optional(),
17681
- /**
17682
- * Inference-device selector (Phase 2 multi-device). Format
17683
- * `<backend>:<device>` (e.g. `openvino:gpu`, `edgetpu:usb`, `cpu`).
17684
- * Omitted ⇒ the runner's default device (current single-engine
17685
- * behaviour). Selects WHICH device pool of the node runs the call.
17686
- */
17687
- deviceKey: string().optional(),
17688
- /**
17689
- * Two-plane NATIVE child-crop reference. Set by `runDetailSubtree` ONLY
17690
- * when the parent crop was resolved from the frame's retained NATIVE
17691
- * surface (a frameHandle HIT). Lets the executor re-cut a LEAF crop
17692
- * child's ROI (plate-ocr, face-embedding, leaf classifiers) at native
17693
- * resolution from that surface — the SAME quality path faces already
17694
- * had — instead of the downscaled parent tile. `handle` keys the native
17695
- * surface (node-pinned to its owner); `cropFrameSpace` is the parent
17696
- * crop's padded/clamped rectangle in FRAME-space pixels, used to compose
17697
- * the executor's crop-normalized child ROI back into frame-normalized
17698
- * coordinates. Auxiliary to the image source (`image`/`frame`/…), NOT one
17699
- * of the mutually-exclusive image inputs. Absent ⇒ tile-crop children
17700
- * (today's behaviour on the fallback path).
17701
- */
17702
- nativeCropRef: NativeCropRefSchema.optional()
17703
- }), PipelineRunResultBridge, { kind: "mutation" }), method(object({
17704
- engine: PipelineEngineChoiceSchema.optional(),
17705
- steps: array(PipelineStepInputSchema).min(1),
17706
- frames: array(FrameInputSchema).min(1).max(255),
17707
- deviceId: number().optional(),
17708
- sessionId: string().optional(),
17709
- /**
17710
- * Pure-inference benchmark hint. A NONZERO uint32 pins every frame in
17711
- * the batch to the Python pool's bench preprocess cache
17712
- * (`_bench_frame_id`) so a REPEATED benchmark frame is decoded +
17713
- * preprocessed ONCE and every later inference is a pure-inference cache
17714
- * hit — the sustained-throughput run measures inference, not
17715
- * decode+preprocess+infer. Omitted/0 for live frames (all different →
17716
- * full preprocess every call, correct). Fresh per sustained run;
17717
- * released via `uncacheFrame`.
17718
- */
17719
- frameId: number().int().nonnegative().optional(),
17720
- /** Inference-device selector (Phase 2 multi-device); see runPipeline. */
17721
- deviceKey: string().optional()
17722
- }), object({ results: array(PipelineRunResultBridge).readonly() }), { kind: "mutation" }), method(object({
17723
- data: _instanceof(Uint8Array),
17724
- width: number().int().positive(),
17725
- height: number().int().positive(),
17726
- format: _enum([
17727
- "rgb",
17728
- "bgr",
17729
- "gray"
17730
- ])
17731
- }), object({
17732
- frameId: number(),
17733
- width: number(),
17734
- height: number()
17735
- }), { kind: "mutation" }), method(object({
17736
- stepId: string(),
17737
- frameId: number().int()
17738
- }), record(string(), unknown()), { kind: "mutation" }), method(object({ frameId: number().int() }), _void(), { kind: "mutation" }), method(_void(), object({
17739
- batchMode: string(),
17740
- windowMs: number(),
17741
- maxBatchSize: number(),
17742
- concurrency: number()
17743
- })), method(_void(), array(object({
17744
- engineKey: string(),
17745
- engine: PipelineEngineChoiceSchema,
17746
- modelsLoaded: array(string()).readonly(),
17747
- inUseByCameras: array(number()).readonly(),
17748
- /**
17749
- * Origin of this resident factory.
17750
- * - `runtime` — main camera-serving engine (no idle TTL).
17751
- * - `warm-override` — benchmark/test override held in the warm
17752
- * cache; auto-disposed after the idle TTL.
17753
- * - `device-pool` — a concurrent per-device pool (Phase 2
17754
- * multi-device, keyed by `deviceKey`) resolved
17755
- * via `resolveDeviceFactory`. Runs alongside the
17756
- * `runtime` engine on a DIFFERENT accelerator
17757
- * (NPU / iGPU / Coral) — this is how the
17758
- * Engines tab shows all pools running at once.
17759
- */
17760
- kind: _enum([
17761
- "runtime",
17762
- "warm-override",
17763
- "device-pool"
17764
- ]),
17765
- /** Native pid of the underlying Python pool (null when no pool). */
17766
- poolPid: number().nullable(),
17767
- /** ms since this factory was last used (null when not warm-tracked). */
17768
- idleMs: number().nullable(),
17769
- /** Idle TTL after which `warm-override` factories self-evict (null when not applicable). */
17770
- idleTtlMs: number().nullable()
17771
- })).readonly()), method(object({ engine: PipelineEngineChoiceSchema }), object({ success: literal(true) }), {
17943
+ frameId: string(),
17944
+ annotations: array(RetrainAnnotationDraftSchema)
17945
+ }), array(RetrainAnnotationSchema).readonly(), {
17772
17946
  kind: "mutation",
17773
17947
  auth: "admin"
17774
17948
  }), method(object({
17775
- engine: PipelineEngineChoiceSchema,
17776
- force: boolean().optional()
17777
- }), object({
17778
- success: boolean(),
17779
- reason: string().optional()
17780
- }), {
17949
+ deviceId: number(),
17950
+ trackId: string()
17951
+ }), RetrainTransitionResultSchema, {
17781
17952
  kind: "mutation",
17782
17953
  auth: "admin"
17783
- }), 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({
17784
- addonId: string(),
17785
- modelId: string(),
17786
- filename: string().optional(),
17787
- settings: record(string(), unknown()).optional()
17788
- }), AudioTestResultSchema, { kind: "mutation" }), method(_void(), ConfigUISchemaNullableBridge);
17954
+ }), method(object({
17955
+ deviceId: number(),
17956
+ trackId: string()
17957
+ }), RetrainTransitionResultSchema, {
17958
+ kind: "mutation",
17959
+ auth: "admin"
17960
+ }), method(object({ deviceIds: array(number()).optional() }), object({ url: string() }), {
17961
+ kind: "query",
17962
+ auth: "admin"
17963
+ }), method(object({
17964
+ eventId: string(),
17965
+ kind: MediaFileKindEnum.optional(),
17966
+ deviceId: number()
17967
+ }), array(MediaFileSchema).readonly()), method(object({
17968
+ trackId: string(),
17969
+ kinds: array(MediaFileKindEnum).optional(),
17970
+ deviceId: number()
17971
+ }), array(MediaFileSchema).readonly()), method(object({
17972
+ trackId: string(),
17973
+ deviceId: number()
17974
+ }), array(MediaFileInfoSchema).readonly()), method(SearchObjectEventsInput, array(ScoredObjectEventSchema).readonly()), method(object({}), WipeObjectEmbeddingsResultSchema, {
17975
+ kind: "mutation",
17976
+ auth: "admin"
17977
+ }), method(RebuildObjectEmbeddingsInput, RebuildObjectEmbeddingsResultSchema, {
17978
+ kind: "mutation",
17979
+ auth: "admin"
17980
+ }), method(object({}), RebuildStatusSchema), object({
17981
+ deviceId: number(),
17982
+ timestamp: number(),
17983
+ frameWidth: number(),
17984
+ frameHeight: number(),
17985
+ detections: array(OverlayDetectionSchema).readonly()
17986
+ }), object({
17987
+ deviceId: number(),
17988
+ trackId: string(),
17989
+ className: string()
17990
+ }), object({
17991
+ deviceId: number(),
17992
+ trackId: string(),
17993
+ className: string(),
17994
+ durationMs: number()
17995
+ }), object({
17996
+ deviceId: number(),
17997
+ kind: EventKindSchema,
17998
+ eventId: string(),
17999
+ timestamp: number()
18000
+ });
17789
18001
  object({
17790
18002
  activeCameras: number(),
17791
18003
  throttledCameras: number(),
@@ -17811,66 +18023,6 @@ var CameraMetricsSchema = object({
17811
18023
  });
17812
18024
  var CameraMetricsWithDeviceIdSchema = CameraMetricsSchema.extend({ deviceId: number() });
17813
18025
  /**
17814
- * Zone — pure geometry + identity. NO filtering behaviour.
17815
- *
17816
- * Zones describe **where** in the frame the operator wants to flag
17817
- * something; consumer-owned {@link ZoneRule} arrays describe **how**
17818
- * each pipeline stage uses them. Splitting the two means a single
17819
- * polygon "Driveway" can simultaneously back a motion-exclude rule,
17820
- * a detection-include rule on `['car']`, and an occupancy aggregate
17821
- * — without three duplicated polygons.
17822
- *
17823
- * Owned by the orchestrator addon (provider) and mirrored into the
17824
- * `zones` device-state slice on every mutation. Consumers
17825
- * (motion-wasm, pipeline-executor, analytics, admin UI) read either
17826
- * via `api.zones.listZones` (one-shot) or via `dev.state.zones` (live
17827
- * mirror with `onChanged`).
17828
- *
17829
- * Coordinates are normalised fractions of the frame (0–1) so zones
17830
- * survive resolution changes and stream profile switches.
17831
- *
17832
- * `kind` discriminates between full polygons (closed regions used
17833
- * for intrusion / occupancy filters) and tripwires (open 2-point
17834
- * line segments used for cross events). Onboard / firmware-reported
17835
- * zones (Reolink, ONVIF) are out of scope for now — see the deferred
17836
- * task list.
17837
- */
17838
- var ZoneKindEnum = _enum(["polygon", "tripwire"]);
17839
- /** Polygon vertex in fraction-of-frame coordinates (0–1). */
17840
- var PolygonPointSchema = object({
17841
- x: number(),
17842
- y: number()
17843
- });
17844
- /** A camera detection zone — pure geometry/identity. */
17845
- var ZoneSchema = object({
17846
- id: string(),
17847
- name: string(),
17848
- kind: ZoneKindEnum.default("polygon"),
17849
- /** Polygon vertices, fraction of frame (0–1). */
17850
- polygon: array(PolygonPointSchema).readonly(),
17851
- /** Visual color for UI rendering. */
17852
- color: string().default("#3b82f6")
17853
- });
17854
- DeviceType.Camera, method(object({ deviceId: number() }), array(ZoneSchema).readonly()), method(object({
17855
- deviceId: number(),
17856
- zone: ZoneSchema
17857
- }), _void(), {
17858
- kind: "mutation",
17859
- auth: "admin"
17860
- }), method(object({
17861
- deviceId: number(),
17862
- zoneId: string()
17863
- }), _void(), {
17864
- kind: "mutation",
17865
- auth: "admin"
17866
- }), method(object({
17867
- deviceId: number(),
17868
- zone: ZoneSchema
17869
- }), _void(), {
17870
- kind: "mutation",
17871
- auth: "admin"
17872
- }), object({ zones: array(ZoneSchema).readonly() });
17873
- /**
17874
18026
  * A bounding box in NORMALIZED [0,1] frame coordinates for `getNativeCrop`. The
17875
18027
  * decode worker resolves it against the RETAINED native frame's real pixel dims,
17876
18028
  * so the caller supplies only the detection-res bbox divided by the detection
@@ -24908,6 +25060,39 @@ var ReadGopBytesResultSchema = object({
24908
25060
  /** Media ms the returned fragment covers. */
24909
25061
  gopDurMs: number()
24910
25062
  });
25063
+ /**
25064
+ * A time WINDOW of one finalized segment, cut by byte range — the multi-GOP
25065
+ * twin of {@link ReadGopBytesResultSchema}'s single instant. Built for the
25066
+ * replay clip's `recording` source (`docs/design/plans/2026-08-26-replay-clip-su-pipeline.md`):
25067
+ * a replay needs several seconds of native pixels, not one frame.
25068
+ *
25069
+ * `ok.data` is standalone-demuxable, same as a GOP read. `ok.reachesRequestedEnd`
25070
+ * is `false` when the returned bytes were cut short by the read's own safety
25071
+ * byte cap before covering `[fromMs, toMs)` — a truncation, reported, not a
25072
+ * silently shorter answer. `spans-multiple-segments` is a REFUSAL, not a
25073
+ * degradation: a window whose end falls past the covering segment would need
25074
+ * bytes stitched from a second segment file (its own `ftyp`+`moov`), which is
25075
+ * not one standalone-demuxable stream — the caller's answer is to request a
25076
+ * shorter window or one aligned to a single segment, not to receive spliced
25077
+ * bytes nothing has proven decodable.
25078
+ */
25079
+ var ReadWindowBytesResultSchema = discriminatedUnion("kind", [object({
25080
+ kind: literal("ok"),
25081
+ data: _instanceof(Uint8Array),
25082
+ /** Absolute epoch ms of the returned bytes' first sample — at or before
25083
+ * the requested `fromMs` (anchored on the nearest keyframe). */
25084
+ gopStartMs: number(),
25085
+ /** Media ms the returned bytes cover, from `gopStartMs`. */
25086
+ gopDurMs: number(),
25087
+ /** `false` ⇒ the safety byte cap cut the read short before it reached
25088
+ * the requested `toMs`; the caller got fewer frames than asked for. */
25089
+ reachesRequestedEnd: boolean()
25090
+ }), object({
25091
+ kind: literal("spans-multiple-segments"),
25092
+ /** Where the covering segment's own footage runs out — informational,
25093
+ * not a retry hint (retrying the same window would refuse again). */
25094
+ segmentEndMs: number()
25095
+ })]);
24911
25096
  method(object({
24912
25097
  deviceId: number(),
24913
25098
  fromMs: number(),
@@ -24958,6 +25143,15 @@ method(object({
24958
25143
  }), ReadGopBytesResultSchema, {
24959
25144
  kind: "query",
24960
25145
  auth: "admin"
25146
+ }), method(object({
25147
+ deviceId: number(),
25148
+ profile: string(),
25149
+ startMs: number(),
25150
+ fromMs: number(),
25151
+ toMs: number()
25152
+ }), ReadWindowBytesResultSchema, {
25153
+ kind: "query",
25154
+ auth: "admin"
24961
25155
  }), method(object({
24962
25156
  deviceId: number(),
24963
25157
  config: RecordingConfigSchema
@@ -25512,92 +25706,6 @@ DeviceType.Camera, method(object({ deviceId: number() }), SceneMonitorStatusSche
25512
25706
  kind: "mutation",
25513
25707
  auth: "admin"
25514
25708
  });
25515
- /**
25516
- * Per-stage gating mode applied to the zones a rule references.
25517
- *
25518
- * - `include`: the rule contributes to a **whitelist** for its stage.
25519
- * When at least one `include` rule fires for a stage, only entities
25520
- * inside one of those zones pass that stage.
25521
- * - `exclude`: the rule contributes to a **blacklist** for its stage.
25522
- * Entities inside one of those zones are dropped at that stage.
25523
- *
25524
- * `monitor`-style observation (count without filtering) is not a rule
25525
- * mode — zones without any matching rule are observed naturally by
25526
- * `zone-analytics` (live snapshot + history), so an "I just want to
25527
- * count, not filter" use case needs no rule at all.
25528
- */
25529
- var ZoneRuleModeEnum = _enum(["include", "exclude"]);
25530
- /**
25531
- * Per-consumer rule that references existing zones (geometry) and
25532
- * defines how a specific pipeline stage should treat them. Each
25533
- * consumer addon owns its own `ZoneRule[]` array in its per-device
25534
- * settings:
25535
- *
25536
- * - `addon-motion-wasm` → `motionZoneRules: ZoneRule[]` (motion stage)
25537
- * - `addon-detection-pipeline` → `detectionZoneRules: ZoneRule[]` (detection stage)
25538
- * - future: notification rules, audio gating, etc.
25539
- *
25540
- * One rule applies to N zones (`zoneIds[]`) so the operator can
25541
- * express "ignore motion in ALL of {garden, street}" with a single
25542
- * rule. `classFilter` narrows the rule to specific object classes —
25543
- * "drop person detections in the street, but keep cars" is one
25544
- * `exclude` rule with `classFilter: ['person']`.
25545
- *
25546
- * `enabled` is a soft toggle — the operator can keep the rule
25547
- * configured but inert without deleting it.
25548
- */
25549
- var ZoneRuleSchema = object({
25550
- /** Stable rule id — survives edits, used by the UI for diffing. */
25551
- id: string(),
25552
- /** Optional human-readable label rendered in the rule editor. */
25553
- name: string().optional(),
25554
- /** Zones this rule targets. The rule's `mode` applies to ALL
25555
- * listed zones (OR-set: a detection in any one of them counts).
25556
- * At least one zone id required — a rule with no targets is a
25557
- * configuration mistake and the form validator rejects it. */
25558
- zoneIds: array(string()).min(1).readonly(),
25559
- mode: ZoneRuleModeEnum,
25560
- /**
25561
- * Class names this rule applies to. Empty / undefined ⇒ rule
25562
- * applies to every class. Class strings match the `macroClass`
25563
- * field on detections (e.g. `person`, `car`, `dog`).
25564
- */
25565
- classFilter: array(string()).readonly().optional(),
25566
- /**
25567
- * Minimum bbox/mask overlap (0–1) with any of the rule's zones
25568
- * required to consider an entity "in the zone". Defaults to the
25569
- * consumer's stage default when omitted. Kept for back-compat with
25570
- * existing per-rule overrides; new operators pick the value via
25571
- * `bboxInclusionPct` (operator-friendly 0–100). Whichever field is
25572
- * set, the lower-level engine reads it as a 0–1 fraction.
25573
- */
25574
- overlapThreshold: number().min(0).max(1).optional(),
25575
- /**
25576
- * Operator-friendly version of `overlapThreshold` — the percentage
25577
- * of the detection's bbox that must lie inside the zone for the
25578
- * rule to match. Documented default is 85%; the engine substitutes
25579
- * that when the field is omitted (kept optional so existing rules
25580
- * stored without it stay valid).
25581
- *
25582
- * When BOTH `overlapThreshold` and `bboxInclusionPct` are set on a
25583
- * rule, the engine prefers `bboxInclusionPct` because it's the
25584
- * field exposed in the UI. Internally both feed the same gate.
25585
- */
25586
- bboxInclusionPct: number().min(0).max(100).optional(),
25587
- /**
25588
- * When `true` and a detection has a segmentation mask, use the
25589
- * mask for overlap instead of the bbox. Detection-stage only;
25590
- * motion rules ignore this field.
25591
- */
25592
- preferMask: boolean().optional(),
25593
- /**
25594
- * Soft-toggle: `false` disables the rule without deleting it.
25595
- * Defaults to `true` so operators creating a rule via the UI
25596
- * see it active immediately.
25597
- */
25598
- enabled: boolean().default(true)
25599
- });
25600
- array(ZoneRuleSchema).readonly();
25601
25709
  object({
25602
25710
  /** Whether the script is currently executing. */
25603
25711
  isRunning: boolean(),
@@ -29462,6 +29570,12 @@ Object.freeze({
29462
29570
  addonId: null,
29463
29571
  access: "view"
29464
29572
  },
29573
+ "notificationRules.resolveArtifactUrl": {
29574
+ capName: "notification-rules",
29575
+ capScope: "system",
29576
+ addonId: null,
29577
+ access: "view"
29578
+ },
29465
29579
  "notificationRules.setAlarmConfig": {
29466
29580
  capName: "notification-rules",
29467
29581
  capScope: "system",
@@ -29906,6 +30020,12 @@ Object.freeze({
29906
30020
  addonId: null,
29907
30021
  access: "create"
29908
30022
  },
30023
+ "pipelineAnalytics.runReplayFrameProcessor": {
30024
+ capName: "pipeline-analytics",
30025
+ capScope: "device",
30026
+ addonId: null,
30027
+ access: "create"
30028
+ },
29909
30029
  "pipelineAnalytics.saveRetrainAnnotations": {
29910
30030
  capName: "pipeline-analytics",
29911
30031
  capScope: "device",
@@ -30038,6 +30158,12 @@ Object.freeze({
30038
30158
  addonId: null,
30039
30159
  access: "view"
30040
30160
  },
30161
+ "pipelineExecutor.getInferenceDeviceHealth": {
30162
+ capName: "pipeline-executor",
30163
+ capScope: "system",
30164
+ addonId: null,
30165
+ access: "view"
30166
+ },
30041
30167
  "pipelineExecutor.getOrchestratorConfigSchema": {
30042
30168
  capName: "pipeline-executor",
30043
30169
  capScope: "system",
@@ -30110,6 +30236,12 @@ Object.freeze({
30110
30236
  addonId: null,
30111
30237
  access: "view"
30112
30238
  },
30239
+ "pipelineExecutor.rearmInferenceDevice": {
30240
+ capName: "pipeline-executor",
30241
+ capScope: "system",
30242
+ addonId: null,
30243
+ access: "create"
30244
+ },
30113
30245
  "pipelineExecutor.runAudioTest": {
30114
30246
  capName: "pipeline-executor",
30115
30247
  capScope: "system",
@@ -30848,6 +30980,12 @@ Object.freeze({
30848
30980
  addonId: null,
30849
30981
  access: "view"
30850
30982
  },
30983
+ "recording.readWindowBytes": {
30984
+ capName: "recording",
30985
+ capScope: "system",
30986
+ addonId: null,
30987
+ access: "view"
30988
+ },
30851
30989
  "recording.refreshStorageLocationsForMigration": {
30852
30990
  capName: "recording",
30853
30991
  capScope: "system",
@@ -33358,6 +33496,11 @@ Object.freeze({
33358
33496
  form: "single",
33359
33497
  optional: false
33360
33498
  }],
33499
+ "pipelineAnalytics.runReplayFrameProcessor": [{
33500
+ name: "deviceId",
33501
+ form: "single",
33502
+ optional: false
33503
+ }],
33361
33504
  "pipelineAnalytics.saveRetrainAnnotations": [{
33362
33505
  name: "deviceId",
33363
33506
  form: "single",
@@ -33673,6 +33816,11 @@ Object.freeze({
33673
33816
  form: "single",
33674
33817
  optional: false
33675
33818
  }],
33819
+ "recording.readWindowBytes": [{
33820
+ name: "deviceId",
33821
+ form: "single",
33822
+ optional: false
33823
+ }],
33676
33824
  "recording.relocateFootage": [{
33677
33825
  name: "deviceId",
33678
33826
  form: "single",