@camstack/addon-post-analysis 1.1.34 → 1.1.36

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.
@@ -7704,6 +7704,178 @@ function cosineSimilarity(a, b) {
7704
7704
  const denom = Math.sqrt(normA) * Math.sqrt(normB);
7705
7705
  return denom === 0 ? 0 : dotProduct / denom;
7706
7706
  }
7707
+ var MACRO_LABELS = [
7708
+ {
7709
+ id: "person",
7710
+ name: "Person"
7711
+ },
7712
+ {
7713
+ id: "vehicle",
7714
+ name: "Vehicle"
7715
+ },
7716
+ {
7717
+ id: "animal",
7718
+ name: "Animal"
7719
+ },
7720
+ {
7721
+ id: "package",
7722
+ name: "Package"
7723
+ }
7724
+ ];
7725
+ var COCO_TO_MACRO = {
7726
+ mapping: {
7727
+ person: "person",
7728
+ bicycle: "vehicle",
7729
+ car: "vehicle",
7730
+ motorcycle: "vehicle",
7731
+ airplane: "vehicle",
7732
+ bus: "vehicle",
7733
+ train: "vehicle",
7734
+ truck: "vehicle",
7735
+ boat: "vehicle",
7736
+ bird: "animal",
7737
+ cat: "animal",
7738
+ dog: "animal",
7739
+ horse: "animal",
7740
+ sheep: "animal",
7741
+ cow: "animal",
7742
+ elephant: "animal",
7743
+ bear: "animal",
7744
+ zebra: "animal",
7745
+ giraffe: "animal",
7746
+ suitcase: "package",
7747
+ backpack: "package",
7748
+ handbag: "package"
7749
+ },
7750
+ preserveOriginal: false
7751
+ };
7752
+ var AUDIO_MACRO_LABELS = [
7753
+ {
7754
+ id: "speech",
7755
+ name: "Speech",
7756
+ icon: "🗣️"
7757
+ },
7758
+ {
7759
+ id: "scream",
7760
+ name: "Scream / Shout",
7761
+ icon: "😱"
7762
+ },
7763
+ {
7764
+ id: "crying",
7765
+ name: "Crying / Baby",
7766
+ icon: "😢"
7767
+ },
7768
+ {
7769
+ id: "laughter",
7770
+ name: "Laughter",
7771
+ icon: "😂"
7772
+ },
7773
+ {
7774
+ id: "music",
7775
+ name: "Music",
7776
+ icon: "🎵"
7777
+ },
7778
+ {
7779
+ id: "dog",
7780
+ name: "Dog",
7781
+ icon: "🐕"
7782
+ },
7783
+ {
7784
+ id: "cat",
7785
+ name: "Cat",
7786
+ icon: "🐈"
7787
+ },
7788
+ {
7789
+ id: "bird",
7790
+ name: "Bird",
7791
+ icon: "🐦"
7792
+ },
7793
+ {
7794
+ id: "animal",
7795
+ name: "Animal (other)",
7796
+ icon: "🐾"
7797
+ },
7798
+ {
7799
+ id: "alarm",
7800
+ name: "Alarm / Siren",
7801
+ icon: "🚨"
7802
+ },
7803
+ {
7804
+ id: "doorbell",
7805
+ name: "Doorbell / Knock",
7806
+ icon: "🔔"
7807
+ },
7808
+ {
7809
+ id: "glass_breaking",
7810
+ name: "Glass Breaking",
7811
+ icon: "💥"
7812
+ },
7813
+ {
7814
+ id: "gunshot",
7815
+ name: "Gunshot / Explosion",
7816
+ icon: "💣"
7817
+ },
7818
+ {
7819
+ id: "vehicle",
7820
+ name: "Vehicle",
7821
+ icon: "🚗"
7822
+ },
7823
+ {
7824
+ id: "siren",
7825
+ name: "Emergency Siren",
7826
+ icon: "🚑"
7827
+ },
7828
+ {
7829
+ id: "fire",
7830
+ name: "Fire / Smoke",
7831
+ icon: "🔥"
7832
+ },
7833
+ {
7834
+ id: "water",
7835
+ name: "Water",
7836
+ icon: "💧"
7837
+ },
7838
+ {
7839
+ id: "wind",
7840
+ name: "Wind / Weather",
7841
+ icon: "🌬️"
7842
+ },
7843
+ {
7844
+ id: "door",
7845
+ name: "Door",
7846
+ icon: "🚪"
7847
+ },
7848
+ {
7849
+ id: "footsteps",
7850
+ name: "Footsteps",
7851
+ icon: "👣"
7852
+ },
7853
+ {
7854
+ id: "crowd",
7855
+ name: "Crowd / Chatter",
7856
+ icon: "👥"
7857
+ },
7858
+ {
7859
+ id: "telephone",
7860
+ name: "Telephone",
7861
+ icon: "📞"
7862
+ },
7863
+ {
7864
+ id: "engine",
7865
+ name: "Engine / Motor",
7866
+ icon: "⚙️"
7867
+ },
7868
+ {
7869
+ id: "tools",
7870
+ name: "Tools / Construction",
7871
+ icon: "🔨"
7872
+ },
7873
+ {
7874
+ id: "silence",
7875
+ name: "Silence",
7876
+ icon: "🤫"
7877
+ }
7878
+ ];
7707
7879
  var YAMNET_TO_MACRO = {
7708
7880
  mapping: {
7709
7881
  Speech: "speech",
@@ -7970,6 +8142,133 @@ var _macroLookup = /* @__PURE__ */ new Map();
7970
8142
  for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
7971
8143
  for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
7972
8144
  /**
8145
+ * Unified event-kind taxonomy — THE single source of truth for
8146
+ * `kind → { parentKind, category, level, color, iconId, labelKey, label,
8147
+ * icon }`.
8148
+ *
8149
+ * This dictionary folds together what used to be scattered across four
8150
+ * copies:
8151
+ * - `capabilities/sensor-event-kinds.ts` (sensor cap colors)
8152
+ * - `addon-post-analysis/.../services/event-kinds.ts`
8153
+ * (MOTION/PERSON/VEHICLE… _COLOR constants)
8154
+ * - `ui-library/composites/detection-colors.ts` (CLASS_COLORS)
8155
+ * - `addon-post-analysis/shared/frame/box-drawer.ts` (DEFAULT_COLOR)
8156
+ * - the COCO / audio class maps (macro ↔ sub relationships)
8157
+ *
8158
+ * The DATA (serializable — color/iconId/labelKey/parentKind) lives here in
8159
+ * `@camstack/types`. The UI-side mapping `iconId → lucide component` and
8160
+ * `labelKey → t()` lives in `@camstack/ui-library`. UIs never hardcode a
8161
+ * color or an icon: they read this dictionary (server descriptors carry the
8162
+ * fields inline; the client resolves color/icon/label from `iconId`/`kind`).
8163
+ *
8164
+ * Two levels only (v1 YAGNI): macro → sub. `person` is a leaf macro.
8165
+ */
8166
+ var TAXONOMY_COLORS = {
8167
+ motion: "#f59e0b",
8168
+ audio: "#06b6d4",
8169
+ person: "#22c55e",
8170
+ vehicle: "#3b82f6",
8171
+ animal: "#f97316",
8172
+ package: "#a855f7",
8173
+ sensor: "#8b5cf6",
8174
+ control: "#10b981",
8175
+ genericDetection: "#64748b"
8176
+ };
8177
+ /** Global default color when a kind is unknown (matches legacy box-drawer). */
8178
+ var DEFAULT_EVENT_COLOR = "#22ff55";
8179
+ var DETECTION_SUB_COLORS = {
8180
+ car: "#f59e0b",
8181
+ truck: "#d97706",
8182
+ bus: "#b45309",
8183
+ motorcycle: "#eab308",
8184
+ bicycle: "#ca8a04",
8185
+ airplane: "#60a5fa",
8186
+ boat: "#2563eb",
8187
+ train: "#1d4ed8",
8188
+ bird: "#14b8a6",
8189
+ dog: "#84cc16",
8190
+ cat: "#f97316",
8191
+ horse: "#a16207",
8192
+ sheep: "#a3a3a3",
8193
+ cow: "#78716c",
8194
+ elephant: "#6b7280",
8195
+ bear: "#7c2d12",
8196
+ zebra: "#404040",
8197
+ giraffe: "#d4a373"
8198
+ };
8199
+ function titleCase(id) {
8200
+ return id.split(/[-_ ]/).filter((p) => p.length > 0).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join(" ");
8201
+ }
8202
+ var entries = /* @__PURE__ */ new Map();
8203
+ function macro(kind, category, color, iconId, label) {
8204
+ entries.set(kind, {
8205
+ kind,
8206
+ parentKind: null,
8207
+ level: "macro",
8208
+ category,
8209
+ color,
8210
+ iconId,
8211
+ labelKey: `eventKind.${kind}`,
8212
+ label
8213
+ });
8214
+ }
8215
+ function sub(kind, parentKind, category, color, iconId, label) {
8216
+ entries.set(kind, {
8217
+ kind,
8218
+ parentKind,
8219
+ level: "sub",
8220
+ category,
8221
+ color,
8222
+ iconId,
8223
+ labelKey: `eventKind.${kind}`,
8224
+ label
8225
+ });
8226
+ }
8227
+ macro("motion", "motion", TAXONOMY_COLORS.motion, "motion", "Motion");
8228
+ macro("audio", "audio", TAXONOMY_COLORS.audio, "audio", "Audio");
8229
+ macro("person", "detection", TAXONOMY_COLORS.person, "person", "Person");
8230
+ macro("vehicle", "detection", TAXONOMY_COLORS.vehicle, "vehicle", "Vehicle");
8231
+ macro("animal", "detection", TAXONOMY_COLORS.animal, "animal", "Animal");
8232
+ macro("package", "package", TAXONOMY_COLORS.package, "package", "Package");
8233
+ macro("sensor", "sensor", TAXONOMY_COLORS.sensor, "sensor", "Sensor");
8234
+ macro("control", "control", TAXONOMY_COLORS.control, "control", "Control");
8235
+ for (const [cocoClass, macroClass] of Object.entries(COCO_TO_MACRO.mapping)) {
8236
+ if (macroClass !== "vehicle" && macroClass !== "animal") continue;
8237
+ if (entries.has(cocoClass)) continue;
8238
+ sub(cocoClass, macroClass, "detection", DETECTION_SUB_COLORS[cocoClass] ?? TAXONOMY_COLORS.genericDetection, cocoClass, titleCase(cocoClass));
8239
+ }
8240
+ sub("package-delivered", "package", "package", TAXONOMY_COLORS.package, "package", "Package delivered");
8241
+ sub("package-picked-up", "package", "package", TAXONOMY_COLORS.package, "package", "Package picked up");
8242
+ sub("contact", "sensor", "sensor", "#f59e0b", "door", "Contact");
8243
+ sub("motion-sensor", "sensor", "sensor", TAXONOMY_COLORS.sensor, "pir", "Motion sensor");
8244
+ sub("smoke", "sensor", "sensor", "#ef4444", "smoke", "Smoke");
8245
+ sub("flood", "sensor", "sensor", "#3b82f6", "water", "Water leak");
8246
+ sub("gas", "sensor", "sensor", "#ef4444", "gas", "Gas");
8247
+ sub("carbon-monoxide", "sensor", "sensor", "#dc2626", "smoke", "Carbon monoxide");
8248
+ sub("vibration", "sensor", "sensor", "#eab308", "vibration", "Vibration");
8249
+ sub("tamper", "sensor", "sensor", "#f97316", "tamper", "Tamper");
8250
+ sub("presence", "sensor", "sensor", "#22c55e", "presence", "Presence");
8251
+ sub("enum-sensor", "sensor", "sensor", TAXONOMY_COLORS.sensor, "generic", "Sensor state");
8252
+ sub("device-event", "sensor", "sensor", "#10b981", "button", "Device event");
8253
+ sub("lock", "control", "control", "#0ea5e9", "lock", "Lock");
8254
+ sub("switch", "control", "control", TAXONOMY_COLORS.control, "switch", "Switch");
8255
+ sub("siren", "control", "control", "#dc2626", "siren", "Siren");
8256
+ sub("button", "control", "control", "#10b981", "button", "Button");
8257
+ sub("doorbell", "control", "control", "#a855f7", "doorbell", "Doorbell");
8258
+ for (const l of AUDIO_MACRO_LABELS) {
8259
+ const kind = `audio-${l.id}`;
8260
+ if (entries.has(kind)) continue;
8261
+ sub(kind, "audio", "audio", TAXONOMY_COLORS.audio, kind, l.name);
8262
+ }
8263
+ /** The complete taxonomy dictionary, keyed by kind. */
8264
+ var EVENT_TAXONOMY = Object.freeze(Object.fromEntries(entries));
8265
+ /** The sub kinds whose `parentKind` is `macro` (empty for a leaf macro). */
8266
+ function subKindsOf(macro) {
8267
+ const out = [];
8268
+ for (const e of Object.values(EVENT_TAXONOMY)) if (e.parentKind === macro) out.push(e);
8269
+ return out;
8270
+ }
8271
+ /**
7973
8272
  * Error types for the safe expression engine. Two distinct classes so callers
7974
8273
  * can tell a compile-time (grammar) failure from a runtime (evaluation)
7975
8274
  * failure — both are non-fatal to the host: read paths degrade to "skip link".
@@ -16013,17 +16312,30 @@ var EventKindCategorySchema = _enum([
16013
16312
  "audio",
16014
16313
  "detection",
16015
16314
  "sensor",
16315
+ "control",
16016
16316
  "custom",
16017
16317
  "package"
16018
16318
  ]);
16319
+ /** Taxonomy level — macro (timeline lane) vs sub (events-page leaf). */
16320
+ var EventKindLevelSchema = _enum(["macro", "sub"]);
16019
16321
  var EventKindDescriptorSchema = object({
16020
- /** Stable kind id (e.g. 'motion', 'person', 'contact'). */
16322
+ /** Stable kind id (e.g. 'motion', 'vehicle', 'car', 'lock'). */
16021
16323
  kind: string(),
16324
+ /** i18n key resolved on the UI side; `label` is the English fallback. */
16325
+ labelKey: string(),
16326
+ /** English fallback label (kept for clients that don't translate). */
16022
16327
  label: string(),
16023
16328
  /** Hex color for timeline/legend rendering. */
16024
16329
  color: string(),
16330
+ /** Dictionary id → lucide component on the UI side. */
16331
+ iconId: string(),
16332
+ /** Legacy closed-vocab glyph — fallback for `iconId`. */
16025
16333
  icon: EventKindIconSchema,
16026
16334
  category: EventKindCategorySchema,
16335
+ /** Macro parent for this kind ('car' → 'vehicle'); null for a macro. */
16336
+ parentKind: string().nullable(),
16337
+ /** Derived from `parentKind`, explicit for the client tree. */
16338
+ level: EventKindLevelSchema,
16027
16339
  /** Which cap + device contributes this kind. For built-ins the camera
16028
16340
  * itself; for sensor kinds the LINKED source device. */
16029
16341
  source: object({
@@ -16096,11 +16408,21 @@ var TrackAudioLabelSchema = object({
16096
16408
  firstAt: number(),
16097
16409
  lastAt: number()
16098
16410
  });
16411
+ /**
16412
+ * How a track was produced. `pipeline` (default / absent) = the spatial
16413
+ * detection+tracking pipeline. `sensor` = a SYNTHETIC track projected from a
16414
+ * linked sensor/control state change (no positions; carries a snapshot). The
16415
+ * spatial subsystems (tracker association, occupancy count, re-id/embedding,
16416
+ * resurrection) MUST skip `sensor` tracks — they have no bbox trajectory.
16417
+ */
16418
+ var TrackSourceSchema = _enum(["pipeline", "sensor"]);
16099
16419
  var TrackSchema = object({
16100
16420
  trackId: string(),
16101
16421
  deviceId: number(),
16102
16422
  className: string(),
16103
16423
  label: string().optional(),
16424
+ /** Track provenance. Absent ⇒ `pipeline` (legacy rows). */
16425
+ source: TrackSourceSchema.optional(),
16104
16426
  firstSeen: number(),
16105
16427
  lastSeen: number(),
16106
16428
  /** Frame-rate position history (subject to maxPositionHistory cap). */
@@ -16629,53 +16951,105 @@ var pipelineAnalyticsCapability = {
16629
16951
  }
16630
16952
  };
16631
16953
  /**
16632
- * Sensor cap name static event-kind descriptor. A linked device
16633
- * contributes one entry per bound cap present in this map.
16954
+ * Cap → event-kind mapping for the SENSOR / CONTROL cap families — the table
16955
+ * `pipeline-analytics.listEventKinds` uses to turn a linked device's bound
16956
+ * caps into per-camera event-kind descriptors.
16957
+ *
16958
+ * The descriptor DATA (color / iconId / labelKey / parentKind / category)
16959
+ * is NOT duplicated here — every entry is derived from the single
16960
+ * `EVENT_TAXONOMY` dictionary (`catalogs/event-taxonomy.ts`). This file owns
16961
+ * ONLY the cap-name → taxonomy-kind mapping. Adding a new eventful sensor /
16962
+ * control cap means adding one line here (and a taxonomy entry); the anti-
16963
+ * drift guard `scripts/check-event-kind-coverage.ts` fails the build if an
16964
+ * eventful cap is missing.
16634
16965
  */
16635
- var EVENT_KIND_BY_CAP = {
16636
- contact: {
16637
- kind: "contact",
16638
- label: "Contact",
16639
- color: "#f59e0b",
16640
- icon: "door",
16641
- category: "sensor"
16642
- },
16643
- flood: {
16644
- kind: "flood",
16645
- label: "Water leak",
16646
- color: "#3b82f6",
16647
- icon: "water",
16648
- category: "sensor"
16649
- },
16650
- gas: {
16651
- kind: "gas",
16652
- label: "Gas",
16653
- color: "#ef4444",
16654
- icon: "smoke",
16655
- category: "sensor"
16656
- },
16657
- "carbon-monoxide": {
16658
- kind: "carbon-monoxide",
16659
- label: "Carbon monoxide",
16660
- color: "#dc2626",
16661
- icon: "smoke",
16662
- category: "sensor"
16663
- },
16664
- "enum-sensor": {
16665
- kind: "enum-sensor",
16666
- label: "Sensor state",
16667
- color: "#8b5cf6",
16668
- icon: "generic",
16669
- category: "sensor"
16670
- },
16671
- "event-emitter": {
16672
- kind: "device-event",
16673
- label: "Device event",
16674
- color: "#10b981",
16675
- icon: "button",
16676
- category: "sensor"
16677
- }
16966
+ /** Map a taxonomy `iconId` onto the legacy closed `EventKindIcon` enum. */
16967
+ var LEGACY_ICON = {
16968
+ motion: "motion",
16969
+ audio: "audio",
16970
+ person: "person",
16971
+ vehicle: "vehicle",
16972
+ animal: "animal",
16973
+ package: "package",
16974
+ door: "door",
16975
+ pir: "pir",
16976
+ smoke: "smoke",
16977
+ water: "water",
16978
+ button: "button",
16979
+ generic: "generic",
16980
+ gas: "smoke",
16981
+ vibration: "generic",
16982
+ tamper: "generic",
16983
+ presence: "person",
16984
+ lock: "generic",
16985
+ siren: "generic",
16986
+ switch: "generic",
16987
+ doorbell: "button"
16678
16988
  };
16989
+ function legacyIcon(iconId) {
16990
+ return LEGACY_ICON[iconId] ?? "generic";
16991
+ }
16992
+ /**
16993
+ * Cap name → taxonomy kind id. Covers EVERY eventful sensor / control cap.
16994
+ * The anti-drift guard cross-checks this against the eventful caps declared
16995
+ * in `packages/types/src/capabilities/*.cap.ts`.
16996
+ */
16997
+ var CAP_TO_KIND = {
16998
+ contact: "contact",
16999
+ motion: "motion-sensor",
17000
+ smoke: "smoke",
17001
+ flood: "flood",
17002
+ gas: "gas",
17003
+ "carbon-monoxide": "carbon-monoxide",
17004
+ vibration: "vibration",
17005
+ tamper: "tamper",
17006
+ presence: "presence",
17007
+ "enum-sensor": "enum-sensor",
17008
+ "event-emitter": "device-event",
17009
+ "lock-control": "lock",
17010
+ switch: "switch",
17011
+ button: "button",
17012
+ doorbell: "doorbell"
17013
+ };
17014
+ function buildDescriptor(capName, kind) {
17015
+ const t = EVENT_TAXONOMY[kind];
17016
+ if (t === void 0) throw new Error(`EVENT_KIND_BY_CAP: cap '${capName}' maps to unknown taxonomy kind '${kind}'`);
17017
+ return {
17018
+ ...t,
17019
+ icon: legacyIcon(t.iconId)
17020
+ };
17021
+ }
17022
+ /**
17023
+ * Sensor / control cap name → static event-kind descriptor. A linked device
17024
+ * contributes one entry per bound cap present in this map.
17025
+ */
17026
+ var EVENT_KIND_BY_CAP = Object.freeze(Object.fromEntries(Object.entries(CAP_TO_KIND).map(([capName, kind]) => [capName, buildDescriptor(capName, kind)])));
17027
+ /**
17028
+ * Build a full `EventKindDescriptor` for a taxonomy `kind`, stamping the
17029
+ * per-device `source`. Returns null when `kind` is not in the taxonomy.
17030
+ * This is THE bridge from the serializable taxonomy dictionary to the cap
17031
+ * wire shape — every event-kind descriptor the server emits goes through it,
17032
+ * so color/iconId/labelKey are never re-declared at a call site.
17033
+ */
17034
+ function buildEventKindDescriptor(kind, source) {
17035
+ const t = EVENT_TAXONOMY[kind];
17036
+ if (t === void 0) return null;
17037
+ return {
17038
+ kind: t.kind,
17039
+ labelKey: t.labelKey,
17040
+ label: t.label,
17041
+ color: t.color,
17042
+ iconId: t.iconId,
17043
+ icon: legacyIcon(t.iconId),
17044
+ category: t.category,
17045
+ parentKind: t.parentKind,
17046
+ level: t.level,
17047
+ source: {
17048
+ capName: source.capName,
17049
+ deviceId: source.deviceId
17050
+ }
17051
+ };
17052
+ }
16679
17053
  var CameraPipelineConfigSchema = object({
16680
17054
  engine: PipelineEngineChoiceSchema.optional(),
16681
17055
  steps: array(PipelineStepInputSchema).readonly(),
@@ -25236,4 +25610,4 @@ object({
25236
25610
  schemaVersion: literal(1)
25237
25611
  });
25238
25612
  //#endregion
25239
- export { object as C, number as S, EventCategory as T, DeviceType as _, audioMetricsCapability as a, array as b, faceGalleryCapability as c, pipelineAnalyticsCapability as d, plateGalleryCapability as f, BaseAddon as g, errMsg as h, addonWidgetsSourceCapability as i, hfModelUrl as l, zoneAnalyticsCapability as m, EVENT_PAD_MS as n, cosineSimilarity as o, videoclipsCapability as p, OpsLogEntrySchema as r, embeddingEncoderCapability as s, EVENT_KIND_BY_CAP as t, nodePin as u, createEvent as v, string as w, boolean as x, hydrateSchema as y };
25613
+ export { hydrateSchema as C, object as D, number as E, string as O, createEvent as S, boolean as T, videoclipsCapability as _, OpsLogEntrySchema as a, BaseAddon as b, buildEventKindDescriptor as c, faceGalleryCapability as d, hfModelUrl as f, subKindsOf as g, plateGalleryCapability as h, MACRO_LABELS as i, EventCategory as k, cosineSimilarity as l, pipelineAnalyticsCapability as m, EVENT_KIND_BY_CAP as n, addonWidgetsSourceCapability as o, nodePin as p, EVENT_PAD_MS as r, audioMetricsCapability as s, DEFAULT_EVENT_COLOR as t, embeddingEncoderCapability as u, zoneAnalyticsCapability as v, array as w, DeviceType as x, errMsg as y };