@camstack/addon-admin-ui 1.2.180 → 1.2.182

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/assets/{AddonCollectionPage-YWSS97Ay.js → AddonCollectionPage-ClRQxGHN.js} +1 -1
  2. package/dist/assets/{Addons-BZtKYLdQ.js → Addons-Bv7_AT7a.js} +1 -1
  3. package/dist/assets/{AdminTabs-CvzQqvQ2.js → AdminTabs-CFFk8Gq2.js} +1 -1
  4. package/dist/assets/{AiProfiles-DPIY6pXE.js → AiProfiles-BkVvZjBt.js} +1 -1
  5. package/dist/assets/{BrokerForm-CSWSM5E3.js → BrokerForm-CnbMKye3.js} +1 -1
  6. package/dist/assets/{Build-B5e3d9OE.js → Build-LHUANBaC.js} +4 -4
  7. package/dist/assets/{Capabilities-BhX7H7A3.js → Capabilities-CQyVFXwc.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-C6J6DUiF.js → CapabilityBadges-BVl3DqAY.js} +1 -1
  9. package/dist/assets/{Cluster-D4vC3LDb.js → Cluster-BVyTdAw9.js} +1 -1
  10. package/dist/assets/{Data-AWkktSkO.js → Data-IQvWpvwm.js} +1 -1
  11. package/dist/assets/{DetectionIntelligence-BulJ1PR6.js → DetectionIntelligence-DYxoWljf.js} +1 -1
  12. package/dist/assets/{DeviceAggregateSection-CxK7LKD7.js → DeviceAggregateSection-BkJvTv6R.js} +1 -1
  13. package/dist/assets/{DeviceDetail-CvD1gXWg.js → DeviceDetail-B4CDw_uE.js} +2 -2
  14. package/dist/assets/{Devices-BrnhG2yA.js → Devices-Da6lCmM1.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-Bx_3MKA_.js → EmbedPlayerPage-BrlPmwQN.js} +1 -1
  16. package/dist/assets/Events-XqdJMMnc.js +1 -0
  17. package/dist/assets/{FormBuilder-CeJriJnB.js → FormBuilder-BHMEtnu5.js} +1 -1
  18. package/dist/assets/{Identity-CbcWeh3q.js → Identity-BML0YvY7.js} +1 -1
  19. package/dist/assets/{IntegrationDetail-BucwfXdG.js → IntegrationDetail-D98ibjds.js} +1 -1
  20. package/dist/assets/{Integrations-CMytenco.js → Integrations-CBGusDGc.js} +1 -1
  21. package/dist/assets/{Integrations-CRQESrDA.js → Integrations-jy5wlUOd.js} +1 -1
  22. package/dist/assets/{Locations-C8gFThSR.js → Locations-B5NgeJWC.js} +1 -1
  23. package/dist/assets/{Logs-CWjWt9q0.js → Logs-DCvmzvJM.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-D8VKOXWT.js → MotionZonesSettings-DqnH_Gs6.js} +1 -1
  25. package/dist/assets/{MyAccess-3MVtgu4Y.js → MyAccess-BDptJLtf.js} +1 -1
  26. package/dist/assets/{Network-CH_-1dg3.js → Network-CYtzk3zV.js} +1 -1
  27. package/dist/assets/{NodeAddonsSettingsPanel-CAgPuUXP.js → NodeAddonsSettingsPanel-BGgUY4XE.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-DwKyjZtD.js → NodeInferenceDevices-D3A4x8bv.js} +1 -1
  29. package/dist/assets/Notifications-BEmMmODG.js +1 -0
  30. package/dist/assets/{Pipeline-uUq4eaJx.js → Pipeline-CG87k4Oa.js} +1 -1
  31. package/dist/assets/{Plates-Cvn0qzNl.js → Plates-BTLd8fUg.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-DJOVa6ie.js → PrivacyMaskSettings-CbfH0ERf.js} +1 -1
  33. package/dist/assets/{ProviderIcon-BtV-sntq.js → ProviderIcon-O8r_QNGL.js} +1 -1
  34. package/dist/assets/{Recordings-Dm93cVox.js → Recordings-d0qBQcso.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-DERxYp4p.js → ScanNetworkModal-CtmBxzX9.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-Nj4V9mEW.js → SceneMonitorEditor-BT0zgTYN.js} +1 -1
  37. package/dist/assets/{Scenes-DrYeEAQr.js → Scenes-NHLxYc_S.js} +1 -1
  38. package/dist/assets/{Settings-D69aa5g2.js → Settings-CK6wx_0Y.js} +1 -1
  39. package/dist/assets/{Showroom-MQJ0VJvL.js → Showroom-BKUzFfAO.js} +1 -1
  40. package/dist/assets/{StorageLocationsPanel-DMMtPiIw.js → StorageLocationsPanel-69SpAdoc.js} +1 -1
  41. package/dist/assets/{Terminal-D2__NuTD.js → Terminal-CZexyI6Z.js} +1 -1
  42. package/dist/assets/{Viewer-D3jGCzRF.js → Viewer-APDxxm2p.js} +1 -1
  43. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BAkTiR-X.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-VrbJl3Qd.js} +1 -1
  44. package/dist/assets/{authed-media-D1kJQtIT.js → authed-media-Cg9pZxod.js} +1 -1
  45. package/dist/assets/{bell-off-CMQECrEv.js → bell-off-DVh1wvB6.js} +1 -1
  46. package/dist/assets/{bell-ring-DeD2zNEz.js → bell-ring-C6dXgglD.js} +1 -1
  47. package/dist/assets/{boxes-BOblQ-ls.js → boxes-B2bGIv3Y.js} +1 -1
  48. package/dist/assets/circle-check-big-D7yIDwoW.js +1 -0
  49. package/dist/assets/circle-dot-C3ZiQ9_N.js +1 -0
  50. package/dist/assets/circle-slash-BLDy7CCl.js +1 -0
  51. package/dist/assets/{circle-x-C_rGRhdN.js → circle-x-DVtn0byc.js} +1 -1
  52. package/dist/assets/clock-Cps8N7BK.js +1 -0
  53. package/dist/assets/{copy-BZuCtI3O.js → copy-BCOqkIux.js} +1 -1
  54. package/dist/assets/{debounced-invalidate-BgiZ3c7w.js → debounced-invalidate-DbvO3iHu.js} +1 -1
  55. package/dist/assets/dist--2HmeXG6.js +349 -0
  56. package/dist/assets/{dist-Cjqh0Wan.js → dist-Cq7gfGRn.js} +1 -1
  57. package/dist/assets/{download-C6xLIiU_.js → download-Dt_BbY-T.js} +1 -1
  58. package/dist/assets/{face-bbox-X2c2pZhf.js → face-bbox-wpEQBKoF.js} +1 -1
  59. package/dist/assets/{flame-BhIbsH2x.js → flame-DB_pOs8X.js} +1 -1
  60. package/dist/assets/{format-size-k04xOT1z.js → format-size-BB-Sd9ut.js} +1 -1
  61. package/dist/assets/{hard-drive-rdkKraiy.js → hard-drive-BWmfHlkd.js} +1 -1
  62. package/dist/assets/{hostInit-I7x5oehb.js → hostInit-DoXLTGfC.js} +1 -1
  63. package/dist/assets/{index-C8HFXQxE.js → index-BCxSnXqL.js} +3 -3
  64. package/dist/assets/{key-round-COOgqcTh.js → key-round-BqkosmYw.js} +1 -1
  65. package/dist/assets/{layers-lue4_9YZ.js → layers-Lhlv5z1U.js} +1 -1
  66. package/dist/assets/{location-owned-usage-DVWSFdep.js → location-owned-usage-D1xSRh8g.js} +1 -1
  67. package/dist/assets/{mf-entry-bootstrap-0-79ff0e6c.js → mf-entry-bootstrap-0-f8898cd2.js} +2 -2
  68. package/dist/assets/{pencil-5Cn86bl9.js → pencil-M7v7qavP.js} +1 -1
  69. package/dist/assets/play-CpJXJ88m.js +1 -0
  70. package/dist/assets/{player-overlays-CoerrptV.js → player-overlays-DbFWkG_Z.js} +1 -1
  71. package/dist/assets/plus-Cpe6mmKM.js +1 -0
  72. package/dist/assets/power-uas7CntH.js +1 -0
  73. package/dist/assets/{radio-CU9ZnR4Z.js → radio-CV4hi-g1.js} +1 -1
  74. package/dist/assets/{refresh-cw-B-P_o53G.js → refresh-cw-Deiyupek.js} +1 -1
  75. package/dist/assets/remoteEntry-I8A6vOgw.js +1 -0
  76. package/dist/assets/rotate-ccw-BftMdgSU.js +1 -0
  77. package/dist/assets/rotate-cw-BObSYKb8.js +1 -0
  78. package/dist/assets/{send-XDAKixAc.js → send-Clr6PN4I.js} +1 -1
  79. package/dist/assets/{server-C427hfGt.js → server-BE9Zw1mn.js} +1 -1
  80. package/dist/assets/{shield-BWCmH1kT.js → shield-CZC9yz_v.js} +1 -1
  81. package/dist/assets/{shield-alert-DTXVS-Ta.js → shield-alert-Ca4rdJui.js} +1 -1
  82. package/dist/assets/square-DSQ5ASQ3.js +1 -0
  83. package/dist/assets/{square-check-big-BCxzVNZx.js → square-check-big-DMuUREuL.js} +1 -1
  84. package/dist/assets/src-CHoZc4cE.js +349 -0
  85. package/dist/assets/src-CTrNqyF8.js +67 -0
  86. package/dist/assets/{undo-2-B3te1nYu.js → undo-2-uDFd438J.js} +1 -1
  87. package/dist/assets/{use-scenes-feed-C4_7pwbO.js → use-scenes-feed-CWs5G4Fz.js} +1 -1
  88. package/dist/assets/useEventInvalidation-C9rmpIc-.js +1 -0
  89. package/dist/assets/{useNodeUrlSelection-BYezMUac.js → useNodeUrlSelection-C-RIZqAN.js} +1 -1
  90. package/dist/assets/user-round-CIt8A80d.js +1 -0
  91. package/dist/assets/{video-B3YII17O.js → video-DiXIeNMQ.js} +1 -1
  92. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BSnk8W8e.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-8goUeGfT.js} +2 -2
  93. package/dist/assets/{wifi-UK98YB3i.js → wifi-DvjdHQli.js} +1 -1
  94. package/dist/assets/{zap-Dzo7ItBz.js → zap-BoQkEUB5.js} +1 -1
  95. package/dist/index.html +5 -5
  96. package/dist/server/addon.js +219 -6
  97. package/package.json +1 -1
  98. package/dist/assets/Events-D7Mv3ryu.js +0 -1
  99. package/dist/assets/Notifications-C89fuBIK.js +0 -1
  100. package/dist/assets/circle-check-big-gFn2KRua.js +0 -1
  101. package/dist/assets/circle-dot-DkhFtw9d.js +0 -1
  102. package/dist/assets/circle-slash-Cxgp0h3p.js +0 -1
  103. package/dist/assets/clock-Cd5wZEYk.js +0 -1
  104. package/dist/assets/dist-BPfNrxiG.js +0 -349
  105. package/dist/assets/play-DfalhZZ_.js +0 -1
  106. package/dist/assets/plus-CcspwfVs.js +0 -1
  107. package/dist/assets/power-DyRoEcfz.js +0 -1
  108. package/dist/assets/remoteEntry-DeAlYwDc.js +0 -1
  109. package/dist/assets/rotate-ccw-DAf8VwGq.js +0 -1
  110. package/dist/assets/rotate-cw-C91Jaxpm.js +0 -1
  111. package/dist/assets/square-bC5Wc9VY.js +0 -1
  112. package/dist/assets/src-71h6VhtY.js +0 -349
  113. package/dist/assets/src-jkGuV7J0.js +0 -67
  114. package/dist/assets/useEventInvalidation-rcKOAt1n.js +0 -1
  115. package/dist/assets/user-round-DxDGNxWB.js +0 -1
@@ -5346,6 +5346,86 @@ var ZodIssueCode = {
5346
5346
  /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
5347
5347
  var ZodFirstPartyTypeKind;
5348
5348
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5349
+ //#endregion
5350
+ //#region ../types/dist/sleep-BnujYGPe.mjs
5351
+ /**
5352
+ * The audio chunk plane's byte format, and the ONE expansion from a coded
5353
+ * window to float samples (D455).
5354
+ *
5355
+ * ## Why a format at all
5356
+ *
5357
+ * D450 took the plane off its 8 → 16 kHz upsample: it carries the SOURCE
5358
+ * RATE, and the one consumer that needs 16 kHz resamples next to the model.
5359
+ * It left the FORMAT alone — the broker still turned each G.711 byte into a
5360
+ * 4-byte f32le sample before the bytes entered the transport, so every leg of
5361
+ * the plane carried four times the source. The plane crosses hub-main twice on
5362
+ * the way to the analyzer, and the fleet's G.711 cameras are ~79 % of it.
5363
+ *
5364
+ * So the plane carries the source BYTES too, and whoever needs floats expands
5365
+ * them where it needs them. That is the same argument D450 made for the rate,
5366
+ * one step further along the same wire.
5367
+ *
5368
+ * ## Why the expansion lives here
5369
+ *
5370
+ * Two packages need it and they must never disagree: `addon-pipeline`'s broker
5371
+ * (which still has to serve a subscriber that did NOT ask for coded bytes —
5372
+ * `AudioChunkPlane` expands per subscription) and
5373
+ * `addon-pipeline-orchestrator`'s `AudioWindowAccumulator` (which flushes an
5374
+ * f32le window to the analyzer cap, whose `AudioChunkInput` contract is
5375
+ * unchanged and stays f32le). Both bundle the bare `@camstack/types` entry
5376
+ * into their own dist (`self-contained` externals), so this travels with a
5377
+ * `camstack deploy` and needs no published server.
5378
+ *
5379
+ * A second μ-law table anywhere else is the defect this module exists to
5380
+ * prevent. (`stream-broker.ts`'s `mulawToPcm` / `alawToPcm` are the ENCODE
5381
+ * direction for the WebRTC egress — a different transform, not a copy.)
5382
+ *
5383
+ * ## Absent means f32le
5384
+ *
5385
+ * `format` is optional on the wire and its absence means `f32le` — today's
5386
+ * bytes, byte for byte. A peer that never heard of the field is served what it
5387
+ * has always been served, because the broker only emits a coded window to a
5388
+ * subscription that DECLARED it accepts one (`AudioSubscribeOptions.accept`).
5389
+ * That is the D448 `rawForward` negotiation, and it is what makes this
5390
+ * deployable one addon at a time across three nodes.
5391
+ */
5392
+ /** Every byte format the audio chunk plane can carry. `f32le` is the default. */
5393
+ var AUDIO_CHUNK_FORMATS = [
5394
+ "f32le",
5395
+ "pcmu",
5396
+ "pcma"
5397
+ ];
5398
+ /**
5399
+ * Build the μ-law decode table (ITU-T G.711). Each of the 256 byte values maps
5400
+ * to a 16-bit PCM sample, normalised to [-1.0, 1.0] for f32le output.
5401
+ *
5402
+ * Moved here verbatim from `audio-rtp-decoder.ts`, which no longer decodes:
5403
+ * it buffers the coded bytes and the plane's consumers expand.
5404
+ */
5405
+ function buildUlawTable() {
5406
+ const table = new Float32Array(256);
5407
+ for (let i = 0; i < 256; i++) {
5408
+ const complemented = ~i & 255;
5409
+ const sign = (complemented & 128) !== 0 ? -1 : 1;
5410
+ const exponent = complemented >> 4 & 7;
5411
+ table[i] = sign * ((8 * (complemented & 15) + 132 << exponent) - 132) / 32768;
5412
+ }
5413
+ return table;
5414
+ }
5415
+ /** Build the A-law decode table (ITU-T G.711). */
5416
+ function buildAlawTable() {
5417
+ const table = new Float32Array(256);
5418
+ for (let i = 0; i < 256; i++) {
5419
+ const xored = i ^ 85;
5420
+ const sign = (xored & 128) !== 0 ? 1 : -1;
5421
+ const exponent = xored >> 4 & 7;
5422
+ const mantissa = xored & 15;
5423
+ table[i] = sign * (exponent === 0 ? 16 * mantissa + 8 : 16 * mantissa + 264 << exponent - 1) / 32768;
5424
+ }
5425
+ return table;
5426
+ }
5427
+ buildUlawTable();
5428
+ buildAlawTable();
5349
5429
  Object.fromEntries([
5350
5430
  {
5351
5431
  id: "overview",
@@ -6638,11 +6718,20 @@ var SubscribeFramesResultSchema = object({
6638
6718
  * (the wire-serialisable supertype of `Buffer`) to match `DecodedFrameSchema`
6639
6719
  * / `EncodedPacketSchema`'s precedent; a `Buffer` is assignable to it.
6640
6720
  */
6721
+ var AudioChunkFormatSchema = _enum(AUDIO_CHUNK_FORMATS);
6641
6722
  var DecodedAudioChunkSchema = object({
6642
6723
  data: _instanceof(Uint8Array),
6643
6724
  sampleRate: number().int().positive(),
6644
6725
  channels: number().int().positive(),
6645
- timestamp: number()
6726
+ timestamp: number(),
6727
+ /**
6728
+ * Byte format of `data`. ABSENT MEANS `f32le` — today's bytes, byte for
6729
+ * byte, for any peer that never heard of this field. A coded window
6730
+ * (`pcmu` / `pcma`, one byte per sample) is only ever emitted to a
6731
+ * subscription that DECLARED it accepts one, so absence can never mean
6732
+ * "coded bytes a consumer will read as floats" (D455).
6733
+ */
6734
+ format: AudioChunkFormatSchema.optional()
6646
6735
  });
6647
6736
  /**
6648
6737
  * Input for `stream-broker.subscribeAudioChunks` (Phase 5 / D9). The
@@ -6654,7 +6743,18 @@ var DecodedAudioChunkSchema = object({
6654
6743
  var SubscribeAudioChunksInputSchema = object({
6655
6744
  brokerId: string(),
6656
6745
  /** Short caller-identity tag (`audio-analyzer`, …) for `listClients`. */
6657
- tag: string().optional()
6746
+ tag: string().optional(),
6747
+ /**
6748
+ * Byte formats this subscriber can READ, best first. The broker serves the
6749
+ * chunk's own format when it is in this list and expands to `f32le`
6750
+ * otherwise, so a subscriber is never handed bytes it cannot interpret.
6751
+ *
6752
+ * Absent (or without the source format) means `f32le` — the behaviour every
6753
+ * subscriber had before D455, unchanged. This is the negotiation half of
6754
+ * the source-bytes lever: it is what lets the broker and its consumers
6755
+ * deploy one at a time across three nodes.
6756
+ */
6757
+ accept: array(AudioChunkFormatSchema).readonly().optional()
6658
6758
  });
6659
6759
  /** Result of `stream-broker.subscribeAudioChunks`. */
6660
6760
  var SubscribeAudioChunksResultSchema = object({
@@ -10644,6 +10744,51 @@ var AudioAnalysisSettingsSchema = object({
10644
10744
  minConfidence: number().min(0).max(1).default(.3),
10645
10745
  allowedClasses: array(string()).default([])
10646
10746
  });
10747
+ /**
10748
+ * `attachDevice` — the analyzer PULLS a camera's audio from the broker (D461).
10749
+ *
10750
+ * Until D461 the orchestrator drained the broker's chunk plane, accumulated
10751
+ * ~1 s windows and pushed them back out as `analyseChunk`. It neither produced
10752
+ * nor consumed the audio: the PCM crossed hub-main twice for a process that
10753
+ * only buffered it. `attachDevice` inverts the direction — the analyzer opens
10754
+ * its own `subscribeAudioChunks` against the broker and the subscriber IS the
10755
+ * decoder, so the coded G.711 bytes D455 put on the plane stay coded all the
10756
+ * way to the one expansion that feeds the model.
10757
+ *
10758
+ * The orchestrator still owns the POLICY (the `audioMode` gate, the on-motion
10759
+ * window, the per-device node assignment, the settings read) and therefore
10760
+ * still owns the attach/detach pair. It no longer owns the bytes.
10761
+ */
10762
+ var AudioAttachDeviceInputSchema = object({
10763
+ deviceId: number(),
10764
+ /** Broker id (`<deviceId>/<camStreamId>`) carrying this camera's audio. */
10765
+ brokerId: string(),
10766
+ /**
10767
+ * `clusterRoles.ingestNode` — the node whose broker owns the source dial.
10768
+ * Every `streamBroker` call the attachment makes is pinned to it, exactly as
10769
+ * the orchestrator's poller pinned them before the move.
10770
+ */
10771
+ ingestNodeId: string(),
10772
+ /**
10773
+ * Resolved once by the orchestrator at attach time, exactly as it was read
10774
+ * once per subscription before D461. The analyzer does NOT re-resolve per
10775
+ * window: a settings change re-attaches, which is what always happened.
10776
+ */
10777
+ settings: AudioAnalysisSettingsSchema
10778
+ });
10779
+ var AudioAttachDeviceResultSchema = object({
10780
+ /** False only when the analyzer is shutting down and refused to attach. */
10781
+ attached: boolean(),
10782
+ /**
10783
+ * True when the attachment replaced a live one for the same device. An
10784
+ * attach is idempotent by REPLACEMENT — two pollers on one camera would
10785
+ * double the broker's fanout and neither would know about the other.
10786
+ */
10787
+ replaced: boolean()
10788
+ });
10789
+ var AudioDetachDeviceResultSchema = object({
10790
+ /** False when no attachment existed — detach is idempotent. */
10791
+ detached: boolean() });
10647
10792
  var AudioClassificationResultSchema = object({
10648
10793
  labels: array(AudioClassificationLabelSchema).readonly(),
10649
10794
  rawLabels: array(AudioClassificationLabelSchema).readonly().optional(),
@@ -10652,7 +10797,7 @@ var AudioClassificationResultSchema = object({
10652
10797
  method(object({
10653
10798
  chunk: AudioChunkInputSchema,
10654
10799
  settings: AudioAnalysisSettingsSchema
10655
- }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }), method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }), method(_void(), boolean()), method(_void(), _void(), { kind: "mutation" }), method(_void(), object({ backend: string() }), {
10800
+ }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }), method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }), method(AudioAttachDeviceInputSchema, AudioAttachDeviceResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), AudioDetachDeviceResultSchema, { kind: "mutation" }), method(_void(), boolean()), method(_void(), _void(), { kind: "mutation" }), method(_void(), object({ backend: string() }), {
10656
10801
  kind: "mutation",
10657
10802
  auth: "admin"
10658
10803
  });
@@ -24778,8 +24923,8 @@ includeCrops: boolean().optional() }).optional(), array(IdentitySchema).readonly
24778
24923
  *
24779
24924
  * An **empty array reads NOTHING** — `[]` is an empty page, never
24780
24925
  * "every camera". A request for no devices is a request, not an
24781
- * omission; same contract as `deviceManager.listFleet` and
24782
- * `pipelineAnalytics.listRecentTracks`.
24926
+ * omission; same contract as `deviceManager.listAll`'s `deviceIds`
24927
+ * and `pipelineAnalytics.listRecentTracks`.
24783
24928
  *
24784
24929
  * Absent (`undefined`) is the omission, and keeps the cluster-wide view.
24785
24930
  */
@@ -30547,12 +30692,24 @@ Object.freeze({
30547
30692
  addonId: null,
30548
30693
  access: "create"
30549
30694
  },
30695
+ "audioAnalyzer.attachDevice": {
30696
+ capName: "audio-analyzer",
30697
+ capScope: "system",
30698
+ addonId: null,
30699
+ access: "create"
30700
+ },
30550
30701
  "audioAnalyzer.classify": {
30551
30702
  capName: "audio-analyzer",
30552
30703
  capScope: "system",
30553
30704
  addonId: null,
30554
30705
  access: "view"
30555
30706
  },
30707
+ "audioAnalyzer.detachDevice": {
30708
+ capName: "audio-analyzer",
30709
+ capScope: "system",
30710
+ addonId: null,
30711
+ access: "create"
30712
+ },
30556
30713
  "audioAnalyzer.dispose": {
30557
30714
  capName: "audio-analyzer",
30558
30715
  capScope: "system",
@@ -36396,11 +36553,21 @@ Object.freeze({
36396
36553
  form: "single",
36397
36554
  optional: false
36398
36555
  }],
36556
+ "audioAnalyzer.attachDevice": [{
36557
+ name: "deviceId",
36558
+ form: "single",
36559
+ optional: false
36560
+ }],
36399
36561
  "audioAnalyzer.classify": [{
36400
36562
  name: "deviceId",
36401
36563
  form: "single",
36402
36564
  optional: true
36403
36565
  }],
36566
+ "audioAnalyzer.detachDevice": [{
36567
+ name: "deviceId",
36568
+ form: "single",
36569
+ optional: false
36570
+ }],
36404
36571
  "audioMetrics.getCurrentSnapshot": [{
36405
36572
  name: "deviceId",
36406
36573
  form: "single",
@@ -38252,6 +38419,52 @@ Object.freeze({
38252
38419
  "network-access": "ingress",
38253
38420
  "smtp-provider": "email"
38254
38421
  });
38422
+ var G711_SCALE_CORRECTION_DB = {
38423
+ PCMU: 20 * Math.log10(4),
38424
+ PCMA: 20 * Math.log10(8)
38425
+ };
38426
+ /**
38427
+ * Restate a dBFS number that was MEASURED through the pre-epoch decoder as the
38428
+ * same intent on the ITU-T scale (D460).
38429
+ *
38430
+ * ## When this applies, and when it is the wrong thing to reach for
38431
+ *
38432
+ * An absolute-dBFS number in this repo is one of two things, and only one of
38433
+ * them converts:
38434
+ *
38435
+ * - **A statement about the scale** — "-55 dBFS is near silence", "-25 dBFS
38436
+ * is loud". It was true on the ITU-T scale before the epoch and it is true
38437
+ * after. The defect was never in the number; it was that 19 of this hub's
38438
+ * 25 cameras did not obey it. Converting such a number takes something
38439
+ * correct and makes it wrong, in order to preserve a bug.
38440
+ * - **A measurement taken through the old decoder** — a value someone read
38441
+ * off a meter that under-reported by exactly 4× (PCMU) or 8× (PCMA). It
38442
+ * describes a sound that was really {@link G711_SCALE_CORRECTION_DB} dB
38443
+ * louder. That is what this function is for.
38444
+ *
38445
+ * Telling the two apart is a question about PROVENANCE, not about arithmetic,
38446
+ * and it cannot be answered from the number. It is answered by the comment the
38447
+ * author left — which is why `scripts/check-dbfs-era.mts` makes leaving one
38448
+ * mandatory.
38449
+ *
38450
+ * ## Why a function and not a typed-in number
38451
+ *
38452
+ * `-55 + 12.04` written into a source file is, six months later, completely
38453
+ * indistinguishable from a threshold somebody simply preferred. Calling this
38454
+ * keeps the derivation, the law, and the original measurement all visible at
38455
+ * the call site, so a future reader can disagree with the *premise* instead of
38456
+ * having to reverse-engineer the sum.
38457
+ *
38458
+ * **This is not a runtime gain.** It converts an authored CONSTANT once, where
38459
+ * it is declared. It must never be applied to a live sample or a stored
38460
+ * `AudioEvent.dbfs`: the decoder is correct now, and a second authority
38461
+ * adjusting numbers the decoder already got right is the original defect with
38462
+ * an extra place to argue with (D459).
38463
+ */
38464
+ function ituDbfsFromPreEpoch(law, authoredDbfs) {
38465
+ return authoredDbfs + G711_SCALE_CORRECTION_DB[law];
38466
+ }
38467
+ Math.round(ituDbfsFromPreEpoch("PCMU", -55));
38255
38468
  /** Schema defaults — an untouched sub-field must author exactly these. */
38256
38469
  var NC_AUDIO_DEFAULTS = {
38257
38470
  hitPercent: 60,
@@ -38753,7 +38966,7 @@ var AdminUIAddon = class extends BaseAddon {
38753
38966
  capability: adminUiCapability,
38754
38967
  provider: {
38755
38968
  getStaticDir: async () => ({ staticDir: resolveAdminUiDistDir() }),
38756
- getVersion: async () => ({ version: "1.2.180" })
38969
+ getVersion: async () => ({ version: "1.2.182" })
38757
38970
  }
38758
38971
  }];
38759
38972
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.180",
3
+ "version": "1.2.182",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Admin UI — Vite frontend build and server-side addon",
@@ -1 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,U as i,W as a,a as o,b as s,o as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{X as f,Z as p,at as m}from"./player-overlays-CoerrptV.js";import{Ca as h,Ct as g,Da as _,Ea as v,Fa as y,Ft as b,It as x,Jr as S,Jt as C,M as w,Ma as T,Mn as E,Mt as D,Na as O,Nt as k,Oa as A,Pa as j,Pt as M,Sa as N,Ta as P,Tt as F,Zs as I,_a as L,ba as R,ha as z,ia as B,ja as V,ka as H,ln as U,nc as W,un as G,va as ee,xa as te}from"./src-jkGuV7J0.js";import{Kt as K,ct as ne}from"./src-71h6VhtY.js";import{t as re}from"./clock-Cd5wZEYk.js";import{t as ie}from"./copy-BZuCtI3O.js";import{t as ae}from"./download-C6xLIiU_.js";import{a as oe,c as se,d as ce,f as le,i as ue,m as de,n as fe,o as pe,p as me,r as he,s as ge,t as _e}from"./debounced-invalidate-BgiZ3c7w.js";import{t as ve}from"./refresh-cw-B-P_o53G.js";import{t as ye}from"./square-check-big-BCxzVNZx.js";import{t as be}from"./square-bC5Wc9VY.js";import{t as xe}from"./undo-2-B3te1nYu.js";import{B as Se,F as Ce,J as q,L as we,c as Te,k as Ee,o as De,p as Oe,q as ke,r as Ae,t as je,w as J,z as Me}from"./index-C8HFXQxE.js";import{t as Ne}from"./AdminPage-CiKtOLQm.js";import{a as Pe,n as Fe,r as Ie,t as Le}from"./authed-media-D1kJQtIT.js";import{t as Re}from"./AdminTabs-CvzQqvQ2.js";var ze=q(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),Be=q(`bug`,[[`path`,{d:`m8 2 1.88 1.88`,key:`fmnt4t`}],[`path`,{d:`M14.12 3.88 16 2`,key:`qol33r`}],[`path`,{d:`M9 7.13v-1a3.003 3.003 0 1 1 6 0v1`,key:`d7y7pr`}],[`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`,key:`xs1cw7`}],[`path`,{d:`M12 20v-9`,key:`1qisl0`}],[`path`,{d:`M6.53 9C4.6 8.8 3 7.1 3 5`,key:`32zzws`}],[`path`,{d:`M6 13H2`,key:`82j7cp`}],[`path`,{d:`M3 21c0-2.1 1.7-3.9 3.8-4`,key:`4p0ekp`}],[`path`,{d:`M20.97 5c0 2.1-1.6 3.8-3.5 4`,key:`18gb23`}],[`path`,{d:`M22 13h-4`,key:`1jl80f`}],[`path`,{d:`M17.2 17c2.1.1 3.8 1.9 3.8 4`,key:`k3fwyw`}]]),Ve=q(`circle-dashed`,[[`path`,{d:`M10.1 2.182a10 10 0 0 1 3.8 0`,key:`5ilxe3`}],[`path`,{d:`M13.9 21.818a10 10 0 0 1-3.8 0`,key:`11zvb9`}],[`path`,{d:`M17.609 3.721a10 10 0 0 1 2.69 2.7`,key:`1iw5b2`}],[`path`,{d:`M2.182 13.9a10 10 0 0 1 0-3.8`,key:`c0bmvh`}],[`path`,{d:`M20.279 17.609a10 10 0 0 1-2.7 2.69`,key:`1ruxm7`}],[`path`,{d:`M21.818 10.1a10 10 0 0 1 0 3.8`,key:`qkgqxc`}],[`path`,{d:`M3.721 6.391a10 10 0 0 1 2.7-2.69`,key:`1mcia2`}],[`path`,{d:`M6.391 20.279a10 10 0 0 1-2.69-2.7`,key:`1fvljs`}]]),He=q(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Ue=q(`copy-plus`,[[`line`,{x1:`15`,x2:`15`,y1:`12`,y2:`18`,key:`1p7wdc`}],[`line`,{x1:`12`,x2:`18`,y1:`15`,y2:`15`,key:`1nscbv`}],[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),We=q(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),Ge=q(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),Ke=q(`star`,[[`path`,{d:`M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z`,key:`r04s7s`}]]),qe=q(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);n();function Je(e){return e.subLabel??e.label}var Ye=720*60*60*1e3;function Xe(e){let t=[];for(let n of e)t.push(...n);return t}function Ze(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Qe(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function $e(e,t){return`${String(e)}:${t}`}function et(e,t){let n=new Map,r=new Set;for(let i of e){let e=$e(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function tt(e,t){return{since:e.fromMs??t-Ye,until:e.toMs??t}}var nt=[`native`,`raster`,`standin`];function rt(e){return nt.some(t=>t===e)}var it={standin:{label:`stand-in`,title:`Stand-in: this tile is a face or plate detail crop copied in because no frame of the subject was captured. It is not a best shot.`,tone:`warning`},raster:{label:`low-res`,title:`Raster crop: a sub-native cut of the subject, not a native capture. Honest, but lower resolution than a best shot.`,tone:`info`}};function at(e){return e===`standin`?it.standin:e===`raster`?it.raster:null}var ot={"no-key-frame":`No key frame existed at close, so no native tile could be cut.`,"no-best-seen-bbox":`No subject box was ever recorded, so there was nothing to cut around.`,"derive-returned-null":`The close-time crop was attempted and produced nothing.`,"derive-threw":`The close-time crop failed with an error.`,"derive-not-wired":`No close-time crop was wired on this node.`,"no-media-store":`The node was shutting down mid-close.`,"no-thumbnail":`The track closed with no tile of any kind.`,"standin-tile":`The track closed with a detail crop standing in for the subject.`,"raster-tile":`The track closed with a sub-native raster crop of the subject.`,"native-tile":`The track closed with a native tile.`};function st(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}return{sentence:ot[r]??r,detail:i,raw:t}}function ct(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function lt({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=Pe(e.bestEventId?`${Le}/${e.bestEventId}`:void 0),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=ct(e.windowMs),h=()=>i(e),g=at(c);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${a?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[d.src?u(`img`,{src:d.src,alt:`Event from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:d.failed?`Key-event media unavailable`:`No key-event media`,children:u(de,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o($e(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":a?`Deselect`:`Select`,children:a?u(ye,{className:`h-4 w-4 text-primary`}):u(be,{className:`h-4 w-4`})}),p!==void 0&&r(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(p),`%`]}),f>0&&u(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(f)}),g!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${g.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:g.title,children:g.label}),(e.markForTrain===!0||e.debug===!0||e.favourited===!0)&&r(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[e.markForTrain===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Marked for training`,"aria-label":`Marked for training`,children:u(We,{className:`h-3 w-3`})}),e.debug===!0&&u(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:`Flagged for debug`,"aria-label":`Flagged for debug`,children:u(Be,{className:`h-3 w-3`})}),e.favourited===!0&&u(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:`Favourited`,"aria-label":`Favourited`,children:u(Ke,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:h,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[r(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,Je(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Je(e)]}):null]}),u(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),r(`div`,{className:`flex items-center justify-between gap-2`,children:[u(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:le(e.timestamp,n)}),m&&u(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:m})]})]}),l!==void 0&&u(`div`,{className:`px-2 pb-1.5`,children:l})]})}var ut=1400,dt=`Admin-gated URL — opens only inside an authenticated session`;function ft({label:t,value:n,title:i}){let[a,o]=l(!1);return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),ut);return()=>clearTimeout(e)},[a]),r(`button`,{type:`button`,onClick:e(()=>{(async()=>{try{await navigator.clipboard.writeText(n),o(!0)}catch{window.prompt(`Copy the media URL:`,n)}})()},[n]),title:i,"aria-label":`Copy ${t} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${a?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[u(a?Se:ie,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function pt({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(ft,{label:`Local`,value:e,title:`Copy LAN URL — ${dt}`}),t&&u(ft,{label:`Public`,value:t,title:`Copy public URL — ${dt}`})]})}var mt={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`,sceneFrame:`Scene frame (clean, retired)`};function ht(e){return e in mt}function gt(e){return ht(e)?mt[e]:e}function _t(e,t){return`${e}${Fe}/${encodeURIComponent(t)}`}n();var vt=3e4;function yt(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(bt,{onOrigin:i}):null}}function bt({onOrigin:e}){let{data:t}=E({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(xt,{addonId:t.addonId,onOrigin:e},t.addonId))})}function xt({addonId:e,onOrigin:t}){let{data:n}=B({addonId:e},{refetchInterval:vt,retry:!1});return d(()=>{let e=n?ne.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var Y=typeof y==`function`,St=`Track flags arrive with the next server update`;function Ct(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var wt=Y?y:Ct;function Tt(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}n();function Et({label:e,hint:t,checked:n,disabled:i,title:a,icon:o,onToggle:s}){return r(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":e,disabled:i,title:a,onClick:s,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${n?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[u(`span`,{className:n?`text-primary`:`text-foreground-subtle`,children:o}),r(`span`,{className:`min-w-0 flex-1`,children:[u(`span`,{className:`block text-[11px] font-medium text-foreground`,children:e}),u(`span`,{className:`block text-[10px] text-foreground-subtle`,children:t})]}),u(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${n?`bg-primary`:`bg-border`}`,children:u(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${n?`translate-x-3`:``}`})})]})}function Dt({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=wt(),[c,d]=l(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!Y||s.isPending,g=Y?void 0:St,_=n=>{h||(async()=>{try{let r=Tt(await s.mutateAsync({deviceId:e,trackId:t,flags:n}));if(!r)return;d(r),o?.(r)}catch(e){let t=e instanceof Error?e.message:``;window.alert(t===``?`Could not update this track. Check the server logs.`:`Could not update this track — ${t}`)}})()};return r(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[u(Et,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:u(We,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),u(Et,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:u(Be,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),u(Et,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:m,disabled:h,...g===void 0?{}:{title:g},icon:u(Ke,{className:`h-4 w-4`}),onToggle:()=>_({favourited:!m})})]})}var X=100,Ot=120,kt={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function At(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function jt(e,t,n){if(e.length===0||t===null)return kt;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return kt;let a=At(e,n?.maxPoints??Ot).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}var Mt=typeof L==`function`,Nt=`Track deletion arrives with the next server update`;function Pt(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Ft=Mt?L:Pt;n();var It=15e3;function Lt(e){return`${Le}/${encodeURIComponent(e)}`}var Rt=f();function zt({mediaKey:e,label:t}){let{src:n,failed:r}=Pe(Lt(e));return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(de,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(J,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):u(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Bt=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Vt=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function Ht(e){let[t,n]=l(null);return d(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function Ut({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:r(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&u(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&u(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>u(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>u(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:u(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&u(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&u(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return r(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[u(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function Wt({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=m(),_=Ft(),v=t!==null,y=t?.deviceId??0,b=t?.trackId??``,S=t?.bestEventId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=te({deviceId:y,trackId:b},{enabled:v}),{data:E}=A({trackId:b,deviceId:y},{enabled:v}),{data:D}=h({eventId:S,deviceId:y},{enabled:v&&S!==``}),{data:O}=I({deviceId:y,since:C-It,until:C+w+It},{enabled:v}),[k,j]=l(null),[M,N]=l(!1),{publicOrigin:P,probes:L}=yt(v);d(()=>{j(null)},[y,b]);let R=a(()=>{let e=E??[],t=D??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,D]),z=k??R,B=Pe(z?Lt(z.key):void 0),V=a(()=>{let e=new Set,t=[];for(let n of[...D??[],...E??[]])n.key===``||e.has(n.key)||(e.add(n.key),t.push(n));return t},[D,E]),H=a(()=>V.find(e=>Bt.has(e.kind))??null,[V]),U=Ht(Pe(H?Lt(H.key):void 0).src),W=a(()=>jt(T?.positions??[],U,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[T?.positions,T?.snapshots,U]),G=e(e=>{let t=V.find(t=>t.key===e);t&&j(t)},[V]);if(t===null)return null;let ee=B.src,K=z?.kind,ne=K!==void 0&&Vt.has(K)&&U!==null&&(T?.positions.length??0)>=2,re=O&&O.length>0?O[0]:null,ie=()=>{re&&(N(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:re.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{N(!1)}})())},ae=()=>{!i||_.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await _.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},oe=Math.round(t.importance*100),se=T?.importanceReason?`${String(oe)}% · ${T.importanceReason}`:`${String(oe)}%`,le=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,ue=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,pe=T?T.totalDistance.toFixed(2):`—`,he=st(T?.previewMissReason),ge=me(T?T.firstSeen:C),_e=T?me(T.lastSeen):`—`;return u(g,{open:!0,onOpenChange:e=>!e&&o(),children:r(F,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,Je(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Je(t)]}):null]}),u(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:n})]}),u(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:u(Ae,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[ee?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(fe,{src:ee,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:ne?u(Ut,{overlay:W,onPickSnapshot:G}):void 0})}):u(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:B.failed?r(s,{children:[u(de,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(J,{className:`h-6 w-6 animate-spin opacity-70`})}),V.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:V.map(e=>{let t=gt(e.kind),n=_t(Rt,e.key),i=P?_t(P,e.key):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>j(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${me(e.timestamp)}`,children:u(zt,{mediaKey:e.key,label:t})}),r(`figcaption`,{className:`min-w-0 px-0.5`,children:[u(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:t,children:t}),u(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:me(e.timestamp),children:ce(e.timestamp)})]}),u(pt,{localUrl:n,publicUrl:i})]},e.key)})}),L,re&&r(x,{variant:`secondary`,onClick:ie,disabled:M,children:[M?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(Ee,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(Dt,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),he!==null&&r(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[u(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Best shot`}),u(`p`,{className:`mt-0.5 text-xs text-foreground`,children:he.sentence}),u(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:he.raw})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[u($,{label:`Camera`,value:n}),u($,{label:`Class`,value:t.className}),u($,{label:`Label`,value:t.label??`—`}),u($,{label:`Sub-label`,value:t.subLabel??`—`}),u($,{label:`Importance`,value:se}),u($,{label:`Zones visited`,value:le}),u($,{label:`Audio heard`,value:ue}),u($,{label:`Total distance`,value:pe}),u($,{label:`First seen`,value:ge}),u($,{label:`Last seen`,value:_e}),u($,{label:`Track`,value:t.trackId,mono:!0})]})]}),u(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:u(`span`,{title:i?void 0:Nt,children:r(x,{variant:`secondary`,onClick:ae,disabled:!i||_.isPending,children:[_.isPending?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(De,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var Gt=`pipeline-analytics`,Kt=`debug.listTracks`,qt=`debug.analyze`,Jt=p(`/addon/pipeline-analytics/debug-export`);function Yt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Xt(e,t){let n=e[t];return typeof n==`string`?n:null}function Zt(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Qt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function $t(e){return e===`error`||e===`warn`||e===`info`}function en(e){if(!Yt(e))return null;let t=Xt(e,`code`),n=Xt(e,`detail`),r=e.severity;return t===null||n===null||!$t(r)?null:{code:t,severity:r,detail:n}}function tn(e){if(!Yt(e))return null;let t=Xt(e,`trackId`),n=Zt(e,`deviceId`),r=Xt(e,`className`),i=Zt(e,`firstSeen`),a=Zt(e,`lastSeen`),o=Zt(e,`durationMs`),s=Qt(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Xt(e,`label`),l=Xt(e,`subLabel`),u=Xt(e,`previewMissReason`),d=Qt(e,`markForTrain`),f=Qt(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:Zt(e,`importance`)??0,bestEventId:Xt(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function nn(e){let t=tn(e);if(t===null||!Yt(e))return null;let n=Zt(e,`mediaCount`),r=Zt(e,`eventCount`),i=Zt(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=en(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...rt(l)?{thumbnailProvenance:l}:{}}}function rn(e){if(!Yt(e))return null;let t=Qt(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=tn(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function an(e){if(!Yt(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=nn(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var on={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function sn(e){return on[e]??e}var cn={error:0,warn:1,info:2};function ln(e){return e.toSorted((e,t)=>cn[e.severity]-cn[t.severity]||e.code.localeCompare(t.code))}function un(e){return e.length===0?Jt:`${Jt}?deviceIds=${e.join(`,`)}`}function dn(e,t){return`${String(e)}:${t}`}function fn(e,t){let n=[],r=new Set;for(let i of e){let e=dn(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}n();var pn=`all`,mn=`The server answered in a shape this build does not understand.`,hn={error:`danger`,warn:`warning`,info:`info`};function gn({findings:e}){return e.length===0?u(b,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:ln(e).map(e=>u(b,{variant:hn[e.severity],title:e.detail,children:sn(e.code)},e.code))})}function _n({track:e,report:t,analyzing:n}){let i=st(t?.previewMissReason??e.previewMissReason);return r(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[t===void 0?u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n?`analysing…`:`not analysed`}):r(s,{children:[u(gn,{findings:t.findings}),r(`p`,{className:`text-[10px] text-foreground-subtle`,title:t.mediaKinds.length>0?t.mediaKinds.join(`, `):`no media of any kind`,children:[String(t.mediaCount),` media · `,String(t.eventCount),` events ·`,` `,String(t.positionCount),` positions`]})]}),i!==null&&u(`p`,{className:`text-[10px] text-foreground-subtle`,title:i.raw,children:i.sentence})]})}function vn(){let e=m(),[t,n]=l(pn),[i,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[h,g]=l(null),[_,v]=l(null),[y,b]=l(null),[w,T]=l([]),E=wt(),O=S({isCamera:!0,projection:`slim`}),k=a(()=>[{value:pn,label:`All cameras`},...(O.data??[]).map(e=>({value:String(e.id),label:e.name}))],[O.data]),A=a(()=>{let e=new Map;for(let t of O.data??[])e.set(t.id,t.name);return e},[O.data]),j=e=>A.get(e)??`Camera ${String(e)}`,N=a(()=>t===pn?[]:[Number.parseInt(t,10)],[t]),P=o({queryKey:[`events-debug`,`list`,N],queryFn:async()=>rn(await e.trpcClient.addons.custom.mutate({addonId:Gt,action:Kt,input:N.length===0?{}:{deviceIds:N}}))}),F=a(()=>(P.data?.tracks??[]).map(e=>e.trackId),[P.data]),I=o({queryKey:[`events-debug`,`analyze`,F],enabled:F.length>0,queryFn:async()=>an(await e.trpcClient.addons.custom.mutate({addonId:Gt,action:qt,input:{trackIds:F}}))}),L=a(()=>{let e=new Map;for(let t of I.data?.reports??[])e.set(t.trackId,t);return e},[I.data]),R=P.data?.tracks??[],z=P.data===null||I.data===null,B=()=>{P.refetch(),I.refetch()},V=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},H=()=>{p(new Set(R.map(e=>dn(e.deviceId,e.trackId))))},U=()=>p(new Set),W=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await E.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},G=e=>{if(!Y||_!==null)return;let t=fn(R,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await W(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>dn(e.deviceId,e.trackId)))),e===`analyzed`&&T(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&b(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),P.refetch()})())},ee=()=>{let e=w;e.length===0||_!==null||(v(`analyzed`),b(null),(async()=>{for(let t of e)try{await E.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{b(`Some tracks could not be re-marked. Refresh and try again.`)}v(null),T([]),P.refetch()})())},te=async()=>{s(!0),d(null);try{await Ie(un(N),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},K=_!==null;return u(Ne,{children:r(`section`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[u(`div`,{className:`w-44`,children:u(D,{value:t,options:k,onChange:e=>n(e.target.value)})}),r(x,{variant:`secondary`,onClick:B,disabled:P.isFetching,children:[P.isFetching?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(ve,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(x,{onClick:()=>void te(),disabled:i||R.length===0,children:[i?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(ae,{className:`h-3.5 w-3.5`}),`Export all (`,String(R.length),`)`]}),R.length>0&&f.size<R.length&&u(x,{variant:`ghost`,onClick:H,children:`Select all`})]}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`A `,u(`code`,{children:`debug`}),` mark does not pin retention — this lists the marked tracks that still exist. A track whose media was evicted shows as missing media. Use `,u(`strong`,{children:`Keep`}),` `,`to hold a selection against pruning while you investigate, and `,u(`strong`,{children:`Analyzed`}),` `,`to un-mark the ones you are finished with.`]}),P.isError&&u(C,{message:`Could not load the marked tracks.`}),z&&!P.isError&&u(C,{message:mn}),c!==null&&u(C,{message:c}),y!==null&&u(C,{message:y}),P.data?.truncated===!0&&u(C,{message:`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`}),(I.data?.vanished.length??0)>0&&r(`p`,{className:`text-xs text-foreground-subtle`,children:[String(I.data?.vanished.length),` marked track(s) were evicted between the list and the analysis.`]}),f.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[String(f.size),` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:Y?void 0:`Track flags arrive with the next server update`,children:r(x,{variant:`secondary`,onClick:()=>G(`keep`),disabled:!Y||K,children:[_===`keep`?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(Ke,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:Y?void 0:`Track flags arrive with the next server update`,children:r(x,{onClick:()=>G(`analyzed`),disabled:!Y||K,children:[_===`analyzed`?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(Se,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(x,{variant:`ghost`,onClick:U,disabled:K,children:u(Ae,{className:`h-3.5 w-3.5`})})]})]}),w.length>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[r(`span`,{className:`text-xs text-foreground`,children:[String(w.length),` track(s) marked analyzed and removed from this list.`]}),r(x,{variant:`ghost`,onClick:ee,disabled:K,children:[u(xe,{className:`h-3.5 w-3.5`}),` Undo`]}),u(x,{variant:`ghost`,onClick:()=>T([]),disabled:K,children:u(Ae,{className:`h-3.5 w-3.5`})})]}),P.isLoading?u(M,{children:u(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):R.length===0?u(M,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(Be,{className:`h-5 w-5 text-foreground-subtle`}),u(`p`,{className:`text-xs text-foreground-subtle`,children:`No track is marked for debug. Mark one from a track's actions to see it here.`})]})}):u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:R.map(e=>{let t=L.get(e.trackId);return u(lt,{row:e,cameraName:j(e.deviceId),nowMs:e.lastSeen,selected:f.has(dn(e.deviceId,e.trackId)),onToggleSelect:V,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(_n,{track:e,report:t,analyzing:I.isFetching})},dn(e.deviceId,e.trackId))})}),h&&u(Wt,{row:h,cameraName:j(h.deviceId),deleteAvailable:Mt,onClose:()=>g(null),onDeleted:()=>{g(null),P.refetch()},onFlagsChanged:e=>{e.debug||(g(null),P.refetch())}})]})})}var yn=200,bn=3e4,xn=[];function Sn(e){let t=m(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:bn,refetchInterval:bn,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:yn,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:Ze(Xe(i??xn),`importance`),isLoading:n&&a}}n();var Cn=[`events-feed`],wn=2e3;function Tn(n){let r=c(),i=n?.paused===!0,a=t(r);a.current=r;let o=t(i);o.current=i;let[s,u]=l(!1),f=e(()=>{a.current.invalidateQueries({queryKey:Cn})},[]),p=t(void 0);p.current||=_e({delayMs:wn,invalidate:()=>{o.current?u(!0):f()}}),d(()=>()=>p.current?.cancel(),[]),d(()=>{i||!s||(u(!1),f())},[i,s,f]);let m=e(()=>{u(!1),f()},[f]);return W(K.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),W(K.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function En({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=je(),[s,c]=l(!1),[d,f]=l(``),[p,m]=l(new Set),h=d.trim().toLowerCase(),g=e=>h.length===0||U(e,o).toLowerCase().includes(h),_=a(()=>e.map(e=>({macro:e.macro,subs:e.subs.filter(t=>g(t)||g(e.macro))})).filter(e=>g(e.macro)||e.subs.length>0),[e,h]),v=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),y=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},b=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},x=()=>n(new Set),S=t.size;return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${S>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(qe,{className:`h-3.5 w-3.5`}),S>0?`Kinds (${String(S)})`:`Kinds`,u(Me,{className:`h-3 w-3`})]}),s&&r(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[r(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[u(Oe,{className:`h-3.5 w-3.5 text-foreground-subtle`}),u(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),S>0&&u(`button`,{type:`button`,onClick:x,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),_.length===0&&u(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:i?`Loading kinds…`:h.length>0?`No kind matches that search.`:`These cameras advertise no event kinds.`}),_.map(e=>{let n=G(e.macro.iconId),i=p.has(e.macro.kind)||h.length>0,a=t.has(e.macro.kind);return r(`div`,{className:`mb-0.5`,children:[r(`div`,{className:`flex items-center gap-1`,children:[e.subs.length>0?u(`button`,{type:`button`,onClick:()=>v(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?Me:we,{className:`h-3 w-3`})}):u(`span`,{className:`w-3`}),r(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:a,onChange:()=>y(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:U(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=G(e.iconId);return r(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[u(`input`,{type:`checkbox`,checked:t.has(e.kind),onChange:()=>b(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:U(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function Dn(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function On(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var kn=new Set([`detection`,`package`]);function An(e,t){return[...Dn(e,t).values()].filter(e=>e.parentKind===null&&kn.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function jn(e,t){let n=Dn(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,On(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}n();function Mn(){let[n,r]=l(!1),i=t(null),[a,o]=l(0),s=e(e=>{i.current!==e&&(i.current=e,o(e=>e+1))},[]);return d(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){r(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&r(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[a]),{ref:s,scrolledPast:n}}n();var Nn=[`events-feed`],Pn=60,Fn=[{value:`importance`,label:`Importance`,icon:ze},{value:`time`,label:`Recent`,icon:re}];function In(){let e=c(),[t,n]=l(ge),[i,o]=l(new Set),[f,p]=l(new Set),[m,h]=l(0),[g,_]=l(`time`),[v,y]=l(new Set),[b,C]=l(null),[w,T]=l(()=>Date.now());d(()=>{let e=setInterval(()=>T(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:E,until:D}=a(()=>tt({fromMs:t.fromMs,toMs:t.toMs},w),[t.fromMs,t.toMs,w]),O=Mn(),{pending:k,refreshNow:A}=Tn({paused:b!==null||v.size>0||O.scrolledPast}),{data:j=[]}=S({isCamera:!0,projection:`slim`}),M=a(()=>j.map(e=>e.id),[j]),{data:P,isLoading:F}=N({deviceIds:M},{enabled:M.length>0,staleTime:5*6e4}),I=a(()=>jn(P??[],i),[P,i]),L=Ft(),R=L.isPending,{rows:z,isLoading:B}=Sn({deviceIds:M,since:E,until:D,minImportance:m>0?m:void 0,classFilter:f.size===1?[...f][0]:void 0}),V=a(()=>{let e=new Map;for(let t of j??[])e.set(t.id,t.name);return e},[j]),H=e=>V.get(e)??`Camera #${String(e)}`,U=a(()=>se(z).map(e=>({id:e,name:H(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,V]),W=a(()=>Ze(Qe(z,{cameras:i,classes:f,minImportance:m}),g),[z,i,f,m,g]),G=pe(W,Pn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...f].sort(),m,g,E,D]),[i,f,m,g,E,D])),ee=()=>{e.invalidateQueries({queryKey:Nn})},te=()=>y(new Set);function K(e){y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ne(){if(v.size===0||!Mt)return;let e=et(z,v),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>L.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ee();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add($e(o,e));else t.push(o)}),y(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>H(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let re=W.length!==z.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(he,{onChange:n}),u(ue,{cameras:U,selected:i,onChange:o}),u(En,{groups:I,selected:f,onChange:p,loading:F}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Min score`}),u(`input`,{type:`range`,min:0,max:1,step:.05,value:m,onChange:e=>h(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),u(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(m*100)})]}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:Fn.map(e=>{let t=e.icon;return r(`button`,{type:`button`,onClick:()=>_(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${g===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!B&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:re?`${String(W.length)} of ${String(z.length)} events`:`${String(W.length)} event${W.length===1?``:`s`}`})]}),v.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[v.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[u(`span`,{title:Mt?void 0:`Track deletion arrives with the next server update`,children:r(x,{variant:`secondary`,onClick:ne,disabled:!Mt||R,children:[R?u(J,{className:`h-3.5 w-3.5 animate-spin`}):u(De,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(x,{variant:`ghost`,onClick:te,disabled:R,children:u(Ae,{className:`h-3.5 w-3.5`})})]})]}),B&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(J,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!B&&W.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),k&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:A,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:`New events — refresh`})}),!B&&W.length>0&&r(s,{children:[u(`div`,{ref:O.ref,"aria-hidden":!0,className:`h-0`}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:G.pageItems.map(e=>u(lt,{row:e,cameraName:H(e.deviceId),nowMs:w,selected:v.has($e(e.deviceId,e.trackId)),onToggleSelect:K,onOpenDetail:C},$e(e.deviceId,e.trackId)))}),u(oe,{currentPage:G.page,totalItems:G.totalItems,pageSize:G.pageSize,onPageChange:G.setPage,itemNoun:`events`})]}),b&&u(Wt,{row:b,cameraName:H(b.deviceId),deleteAvailable:Mt,onClose:()=>C(null),onDeleted:()=>{ee(),C(null)},onFlagsChanged:e=>{C(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var Ln=50,Rn=350,zn=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function Bn(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function Vn({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(.2),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=w(t,Rn).trim(),_=g.length>0;d(()=>{e(_)},[_,e]);let[v,y]=l(()=>Date.now());d(()=>{let e=setInterval(()=>y(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:b=[]}=S({isCamera:!0,projection:`slim`}),x=a(()=>{let e=new Map;for(let t of b)e.set(t.id,t.name);return e},[b]),C=e=>x.get(e)??`Camera #${String(e)}`,T=a(()=>b.map(e=>e.id),[b]),{data:E}=N({deviceIds:T},{enabled:T.length>0,staleTime:5*6e4}),D=a(()=>An(E??[],new Set(f===null?[]:[f])),[E,f]);d(()=>{s!==null&&(D.some(e=>e.kind===s)||c(null))},[D,s]);let{data:k,isFetching:A,isError:j,error:M}=O({text:g,minScore:i,limit:Ln,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),P=a(()=>[...k??[]].sort((e,t)=>t.score-e.score).map(e=>({...Bn(e),score:e.score})),[k]);function F(e){c(t=>t===e?null:e)}return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`div`,{className:`relative min-w-[16rem] flex-1`,children:[u(Oe,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),u(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&u(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:u(Ae,{className:`h-3.5 w-3.5`})})]}),A&&_&&u(J,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[u(`div`,{className:`flex items-center gap-1`,children:D.map(e=>u(`button`,{type:`button`,onClick:()=>F(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${s===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:U(e)},e.kind))}),r(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Camera`}),r(`select`,{value:f===null?``:String(f),onChange:e=>p(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[u(`option`,{value:``,children:`All`}),b.map(e=>u(`option`,{value:String(e.id),children:e.name},e.id))]})]}),r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(`span`,{children:`Match`}),u(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:zn.map(e=>u(`button`,{type:`button`,onClick:()=>o(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${i===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),_&&!A&&!j&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[P.length,` match`,P.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[j&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,M instanceof Error?M.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!j&&A&&P.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(J,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!j&&!A&&P.length===0&&r(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,g,`”. Try a looser match threshold or a different phrasing.`]}),!j&&P.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:P.map(e=>u(lt,{row:e,cameraName:C(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(Wt,{row:m,cameraName:C(m.deviceId),deleteAvailable:Mt,onClose:()=>h(null),onDeleted:()=>h(null)})]})}var Hn=15e3,Un={rows:[],unreadableCount:0};function Wn(e){let t=m(),n=e.length>0,r=[...e].sort((e,t)=>e-t),{data:i,isLoading:a}=o({queryKey:[`stationary-objects`,r],enabled:n,staleTime:Hn,refetchInterval:Hn,queryFn:async()=>{let e=await t.trpcClient.zoneAnalytics.getCurrentSnapshotBatch.query({deviceIds:r}),n=[],i=0;for(let t of e){if(t.read===`unreadable`){i++;continue}for(let e of t.snapshot?.stationaryObjects??[])n.push({...e,deviceId:t.deviceId})}return{rows:n,unreadableCount:i}}}),s=i??Un;return{rows:s.rows.toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n&&a,unreadableCount:s.unreadableCount}}n();function Gn(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function Kn({row:e,cameraName:t,nowMs:n}){let i=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,a=Pe(i?`${Le}/${i}`:void 0);return r(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[r(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[a.src?u(`img`,{src:a.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):u(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:u(Ge,{className:`h-6 w-6`})}),u(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),r(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[u(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,Gn(n,e.becameStationaryAt)]})]})]})}function qn(){let[e,t]=l(!1),n=Date.now(),{data:i=[]}=S({isCamera:!0,projection:`slim`}),o=a(()=>i.map(e=>e.id),[i]),s=a(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:c,unreadableCount:d}=Wn(o);return c.length===0&&d===0?null:r(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[r(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[u(e?Me:we,{className:`h-4 w-4 text-foreground-subtle`}),u(Ge,{className:`h-4 w-4 text-foreground-subtle`}),u(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),u(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:c.length}),u(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`}),d>0?r(`span`,{className:`ml-2 text-[11px] text-warning`,children:[d,` camera`,d===1?``:`s`,` could not be read`]}):null]}),e&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:c.map(e=>u(Kn,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function Jn(){let[e,t]=l(!1);return u(Ne,{children:r(`section`,{className:`space-y-3`,children:[u(Vn,{onActiveChange:t}),!e&&u(qn,{}),!e&&u(In,{})]})})}var Yn=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Xn=new Set(Yn);function Zn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Xn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Qn({annotations:e,selectedIndex:t,onSelect:n,onChange:i,onDelete:a}){return e.length===0?r(`p`,{className:`text-[11px] text-foreground-subtle p-3`,children:[`No subject on this frame yet. Drag on the image to draw one, or ask the pipeline for a proposal. Annotate `,u(`strong`,{children:`every`}),` subject — a frame with one box and three unlabelled people teaches the model that two thirds of the people in it are background.`]}):u(`ul`,{className:`divide-y divide-border`,children:e.map((e,o)=>{let s=o===t,c=Zn(e.label),l=Zn(e.subLabel);return r(`li`,{className:`p-2.5 space-y-1.5 ${s?`bg-surface-hover`:``}`,onFocus:()=>{n(o)},children:[r(`div`,{className:`flex items-center gap-2`,children:[u(D,{className:`w-28`,value:e.macroClass,options:Yn.map(e=>({value:e,label:e})),onChange:e=>{let t=Yn.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),u(D,{className:`w-32`,value:e.kind,options:[{value:`subject`,label:`subject`},{value:`model_error`,label:`model error`}],onChange:e=>{i(o,{kind:e.target.value===`model_error`?`model_error`:`subject`})}}),e.source===`assist`&&r(b,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),u(x,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:u(De,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(k,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),u(k,{className:`flex-1`,placeholder:`sub-label (a name, a plate…)`,value:e.subLabel??``,onChange:e=>{i(o,{subLabel:e.target.value})}})]}),c!==null&&u(`p`,{className:`text-[11px] text-danger`,children:c}),l!==null&&u(`p`,{className:`text-[11px] text-danger`,children:l})]},`${String(o)}-${String(e.bbox.x)}`)})})}function $n(e){return e.every(e=>Zn(e.label)===null&&Zn(e.subLabel)===null&&Xn.has(e.macroClass))}function er(e){return e<0?0:e>1?1:e}function tr(e,t,n,r){if(!(e>0)||!(t>0)||!(n>0)||!(r>0))return null;let i=Math.min(e/n,t/r),a=n*i,o=r*i;return{left:(e-a)/2,top:(t-o)/2,width:a,height:o}}function nr(e,t,n){return{x:er((e-n.left)/n.width),y:er((t-n.top)/n.height)}}function rr(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function ir(e){return e.w>=.01&&e.h>=.01}function ar(e,t){return{left:t.left+e.x*t.width,top:t.top+e.y*t.height,width:e.w*t.width,height:e.h*t.height}}function or(e,t){let n=-1,r=1/0;return e.forEach((e,i)=>{if(!(t.x>=e.x&&t.x<=e.x+e.w&&t.y>=e.y&&t.y<=e.y+e.h))return;let a=e.w*e.h;a<r&&(n=i,r=a)}),n}n();function sr({imageSrc:n,imageWidth:a,imageHeight:o,boxes:s,selectedIndex:c,onSelect:d,onDraw:f}){let p=t(null),[m,h]=l({w:0,h:0}),[g,_]=l(null);i(()=>{let e=p.current;if(e===null)return;let t=new ResizeObserver(()=>{h({w:e.clientWidth,h:e.clientHeight})});return t.observe(e),h({w:e.clientWidth,h:e.clientHeight}),()=>{t.disconnect()}},[]);let v=tr(m.w,m.h,a,o),y=e(e=>{let t=p.current;if(t===null||v===null)return null;let n=t.getBoundingClientRect();return nr(e.clientX-n.left,e.clientY-n.top,v)},[v]);return r(`div`,{ref:p,className:`relative w-full h-full min-h-[280px] bg-surface-sunken select-none touch-none`,onPointerDown:e=>{let t=y(e);t!==null&&(e.currentTarget.setPointerCapture(e.pointerId),_({start:t,current:rr(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:rr(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),ir(e)?f(e):d(or(s.map(e=>e.bbox),g.start))},children:[u(`img`,{src:n,alt:`Frame being annotated`,className:`absolute inset-0 w-full h-full object-contain pointer-events-none`}),v!==null&&s.map((e,t)=>{let n=ar(e.bbox,v),i=e.kind===`model_error`,a=t===c,o=i?`#ef4444`:a?`#22c55e`:`#3b82f6`;return u(`div`,{className:`absolute pointer-events-none`,style:{left:n.left,top:n.top,width:n.width,height:n.height,border:`${a?`2px`:`1px`} ${i?`dashed`:`solid`} ${o}`,opacity:e.source===`assist`&&!a?.65:1},children:r(`span`,{className:`absolute -top-4 left-0 text-[10px] px-1 rounded`,style:{background:o,color:`#08121f`},children:[e.label??e.macroClass,i?` ✕`:``]})},`${String(t)}-${String(e.bbox.x)}-${String(e.bbox.y)}`)}),g!==null&&v!==null&&u(`div`,{className:`absolute border border-dashed border-primary pointer-events-none`,style:ar(g.current,v)})]})}function cr(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function lr({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaKey)),d=e.filter(e=>!l.has(e.mediaKey));return r(`div`,{className:`space-y-3`,children:[r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`In the dataset (`,t.length,`)`]}),t.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No frame copied yet. Selecting a frame copies it into retrain storage immediately — the dataset stops depending on the track's own media from that moment.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:t.map(e=>u(`li`,{children:r(`div`,{className:`rounded-md border px-2 py-1.5 text-[11px] ${e.frameId===n?`border-primary bg-surface-hover`:`border-border`}`,children:[r(`button`,{type:`button`,className:`flex items-center gap-1.5 text-left`,onClick:()=>{s(e.frameId)},children:[u(Se,{className:`h-3 w-3 text-success`}),u(`span`,{className:`font-medium text-foreground`,children:e.sourceKind}),r(`span`,{className:`text-foreground-subtle`,children:[e.width,`×`,e.height,` · `,cr(e.sizeBytes)]})]}),r(`button`,{type:`button`,"aria-label":`Remove this frame from the dataset`,className:`mt-1 flex items-center gap-1 text-foreground-muted hover:text-danger`,onClick:()=>{c(e.frameId)},children:[u(De,{className:`h-3 w-3`}),`remove`]})]})},e.frameId))})]}),r(`section`,{children:[r(`h3`,{className:`text-xs font-semibold text-foreground mb-1.5`,children:[`Available frames (`,d.length,`)`]}),d.length===0?u(`p`,{className:`text-[11px] text-foreground-subtle`,children:e.length===0?`This track has no whole, unannotated frame left — its media aged out before it was marked. Anything already copied above is still usable.`:`Every available frame is already in the dataset.`}):u(`ul`,{className:`flex flex-wrap gap-2`,children:d.map(e=>{let t=i.get(e.mediaKey);return r(`li`,{children:[r(x,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaKey)},children:[a?u(J,{className:`h-3 w-3 animate-spin`}):u(t===void 0?Ue:de,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:e.kind}),u(`span`,{className:`ml-1 text-foreground-subtle`,children:cr(e.sizeBytes)})]}),t!==void 0&&u(b,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaKey)})})]})]})}function ur(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var dr={untouched:{icon:He,label:`to do`,variant:`default`},started:{icon:Ve,label:`frames only`,variant:`info`},ready:{icon:Ce,label:`annotated`,variant:`success`}};function fr(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function pr({tracks:e,isLoading:t,selectedTrackId:n,deviceNames:i,onSelect:a}){return t?r(`div`,{className:`flex items-center gap-2 p-4 text-xs text-foreground-subtle`,children:[u(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading staging tracks…`]}):e.length===0?u(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Nothing in staging. Mark a track for training from the viewer or the Events grid and it appears here.`}):u(`ul`,{className:`divide-y divide-border`,children:e.map(e=>{let t=dr[ur(e)],o=t.icon;return u(`li`,{children:r(`button`,{type:`button`,onClick:()=>{a(e)},className:`w-full text-left px-3 py-2 flex items-start gap-2 hover:bg-surface-hover ${e.trackId===n?`bg-surface-hover`:``}`,children:[u(o,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 text-foreground-subtle`}),r(`span`,{className:`min-w-0 flex-1`,children:[r(`span`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label??e.className}),u(b,{variant:t.variant,children:t.label})]}),r(`span`,{className:`block text-[11px] text-foreground-subtle truncate`,children:[i.get(e.deviceId)??`Camera ${String(e.deviceId)}`,` ·`,` `,fr(e.lastSeen)]}),r(`span`,{className:`block text-[11px] text-foreground-muted`,children:[e.frameCount,` frame`,e.frameCount===1?``:`s`,` ·`,` `,e.annotationCount,` subject`,e.annotationCount===1?``:`s`]})]})]})},e.trackId)})})}n();var mr=`person`;function hr(){let[t,n]=l(null),[i,o]=l(null),[c,f]=l([]),[p,m]=l(-1),[h,g]=l(new Map),[y,C]=l(null),w=S({projection:`slim`,isCamera:!0}),E=a(()=>{let e=new Map;for(let t of w.data??[])e.set(t.id,t.name);return e},[w.data]),D=_({}),O=v({trackId:t?.trackId??``},{enabled:t!==null}),k=P({trackId:t?.trackId??``},{enabled:t!==null}),A=R({frameId:i??``},{enabled:i!==null}),M=j(),N=ee(),F=H(),I=T(),L=z(),B=V();d(()=>{if(i===null){f([]);return}f((k.data??[]).filter(e=>e.mediaKey===i).map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},...e.subLabel===void 0?{}:{subLabel:e.subLabel},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))),m(-1)},[i,k.data]),d(()=>{let e=O.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[O.data,i]);let U=e(e=>{n(e),o(null),f([]),g(new Map),C(null)},[]),W=e(async e=>{if(t===null)return;let n=await M.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaKeys:[e]});if(n.refused.length>0){let e=new Map(h);for(let t of n.refused)e.set(t.sourceMediaKey,t.reason);g(e)}n.copied.length>0&&o(n.copied[0].frameId),await O.refetch(),await D.refetch()},[t,M,h,O,D]),G=e(async e=>{t!==null&&(await N.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await O.refetch(),await k.refetch(),await D.refetch())},[t,N,i,O,k,D]),te=e(async e=>{if(t===null||i===null)return;C(null);let n=await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){C(n.reason===`no-zone`?`A package proposal runs on the zone crop only — this camera has no zone, and running the detector on the whole frame at 0.35 proposes furniture.`:`The pipeline refused: ${n.reason}${n.detail===void 0?``:` — ${n.detail}`}`);return}f(e=>[...e,...n.proposals.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label===void 0?{}:{label:e.label},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))]),C(`${n.proposals.length} proposal${n.proposals.length===1?``:`s`} from ${n.modelId}`+(n.belowThreshold>0?` — ${n.belowThreshold} more were below ${n.minScore.toFixed(2)}`:``))},[t,i,F]),K=e(e=>{f(t=>[...t,{bbox:e,macroClass:mr,kind:`subject`,source:`operator`}]),m(c.length)},[c.length]),ne=e((e,t)=>{f(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),re=e(e=>{f(t=>t.filter((t,n)=>n!==e)),m(-1)},[]),ie=e(async()=>{t===null||i===null||(await I.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,annotations:c.map(e=>({bbox:e.bbox,macroClass:e.macroClass,...e.label!==void 0&&e.label!==``?{label:e.label}:{},...e.subLabel!==void 0&&e.subLabel!==``?{subLabel:e.subLabel}:{},kind:e.kind,source:e.source,...e.assistModelId===void 0?{}:{assistModelId:e.assistModelId},...e.assistScore===void 0?{}:{assistScore:e.assistScore}}))}),await k.refetch(),await D.refetch(),C(`Annotations saved.`))},[t,i,c,I,k,D]),ae=e(async()=>{if(t===null)return;let e=await L.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});C(e.changed?`Track completed — it is now trained, and its own media is evictable again.`:e.reason===`no-frames-copied`?`Refused: no frame was ever copied into the dataset. Completing would let retention delete material nothing was extracted from.`:`Refused: ${e.reason??`unknown`}`),await D.refetch(),e.changed&&n(null)},[t,L,D]),oe=e(async()=>{if(t===null)return;let e=await B.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});C(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await D.refetch()},[t,B,D]),se=A.data,ce=$n(c)&&i!==null;return r(Ne,{subtitle:`Turn the tracks you marked for training into an annotated dataset. Selecting a frame copies it — the dataset never depends on media that can be swept.`,actions:t===null?null:r(`div`,{className:`flex items-center gap-2`,children:[r(x,{variant:`secondary`,size:`sm`,onClick:()=>void oe(),children:[u(xe,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(x,{size:`sm`,onClick:()=>void ae(),children:[u(We,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[y!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:y}),r(`div`,{className:`grid grid-cols-1 lg:grid-cols-[minmax(0,260px)_minmax(0,1fr)] gap-4`,children:[r(`aside`,{className:`rounded-md border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center justify-between`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Staging`}),u(b,{children:D.data?.length??0})]}),u(pr,{tracks:D.data??[],isLoading:D.isLoading,selectedTrackId:t?.trackId??null,deviceNames:E,onSelect:U})]}),u(`section`,{className:`space-y-3 min-w-0`,children:t===null?u(`p`,{className:`text-xs text-foreground-subtle`,children:`Pick a track from the staging list to start annotating it.`}):r(s,{children:[u(`div`,{className:`rounded-md border border-border bg-surface p-3`,children:u(lr,{candidates:O.data?.candidates??[],copies:O.data?.copies??[],activeFrameId:i,refusals:h,isSelecting:M.isPending,onSelectCandidate:e=>void W(e),onOpenCopy:o,onRemoveCopy:e=>void G(e)})}),i!==null&&r(`div`,{className:`grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_minmax(0,380px)] gap-3`,children:[u(`div`,{className:`rounded-md border border-border overflow-hidden`,children:se===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(J,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(sr,{imageSrc:`data:image/jpeg;base64,${se.base64}`,imageWidth:se.width,imageHeight:se.height,boxes:c,selectedIndex:p,onSelect:m,onDraw:K})}),r(`div`,{className:`rounded-md border border-border bg-surface flex flex-col min-h-0`,children:[r(`div`,{className:`px-3 py-2 border-b border-border flex items-center gap-2`,children:[u(`h2`,{className:`text-xs font-semibold text-foreground flex-1`,children:`Subjects`}),r(x,{variant:`secondary`,size:`sm`,disabled:F.isPending,onClick:()=>void te(`objects`),children:[u(Te,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(x,{variant:`secondary`,size:`sm`,disabled:F.isPending,onClick:()=>void te(`package`),children:[u(Te,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Packages`})]})]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(Qn,{annotations:c,selectedIndex:p,onSelect:m,onChange:ne,onDelete:re})}),r(`div`,{className:`px-3 py-2 border-t border-border flex items-center justify-between`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:[c.filter(e=>e.kind===`model_error`).length,` marked as model errors`]}),u(x,{size:`sm`,disabled:!ce||I.isPending,onClick:()=>void ie(),children:`Save frame`})]})]})]})]})})]})]})}function gr(){return u(`div`,{className:`flex flex-col p-4`,children:u(Re,{tabs:[{id:`feed`,label:`Feed`,icon:ke,content:u(Jn,{})},{id:`retrain`,label:`Retrain`,icon:We,content:u(hr,{})},{id:`debug`,label:`Debug`,icon:Be,content:u(vn,{})}]})})}export{gr as EventsPage};