@camstack/addon-admin-ui 1.2.189 → 1.2.192

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 (83) hide show
  1. package/dist/assets/{AddonCollectionPage-CiLs8Eor.js → AddonCollectionPage-DWEXHO7f.js} +1 -1
  2. package/dist/assets/{Addons-CwPhKZVw.js → Addons-C7j8tjcS.js} +1 -1
  3. package/dist/assets/{AdminTabs-Djv_JeIl.js → AdminTabs-Btn7AKWC.js} +1 -1
  4. package/dist/assets/{AiProfiles-CPZ2_J-A.js → AiProfiles-WMvkhu7r.js} +1 -1
  5. package/dist/assets/{BrokerForm-BrGhAAyC.js → BrokerForm-DGbxEcrt.js} +1 -1
  6. package/dist/assets/{Build-CHs706WH.js → Build-9Bl8OttD.js} +1 -1
  7. package/dist/assets/{Capabilities-BWqXKfKr.js → Capabilities-ComsXtBs.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-4zjiiw18.js → CapabilityBadges-BjHnL8Vv.js} +1 -1
  9. package/dist/assets/{Cluster-BvL1h_jg.js → Cluster-LjFUT5rY.js} +1 -1
  10. package/dist/assets/{Data-B5WrQ62C.js → Data-BbIziXcO.js} +1 -1
  11. package/dist/assets/{DetectionIntelligence-DYfB6Pc9.js → DetectionIntelligence-DsmMS7QD.js} +1 -1
  12. package/dist/assets/{DeviceAggregateSection-UIrhbL6N.js → DeviceAggregateSection-DBLh1Gpo.js} +1 -1
  13. package/dist/assets/{DeviceDetail-D8kiKdo3.js → DeviceDetail-CA1EMNzh.js} +1 -1
  14. package/dist/assets/{Devices-B1Ep2QX0.js → Devices-gLMpRIM6.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-4SDui4XL.js → EmbedPlayerPage-ByAAT5Jw.js} +1 -1
  16. package/dist/assets/Events-DJs-6KWx.js +1 -0
  17. package/dist/assets/{FormBuilder-O5L0t5Y9.js → FormBuilder-Cxc7I_se.js} +1 -1
  18. package/dist/assets/{Identity-DC_vxjWx.js → Identity-CdANMP3y.js} +1 -1
  19. package/dist/assets/{IntegrationDetail-e8MUxXOE.js → IntegrationDetail-Cgn0xVXn.js} +1 -1
  20. package/dist/assets/{Integrations-DAFITgCb.js → Integrations-D5G_o7NY.js} +1 -1
  21. package/dist/assets/{Integrations-ygadhkEK.js → Integrations-UaVA7nxI.js} +1 -1
  22. package/dist/assets/{Locations-Dgr4R29R.js → Locations-C9oGPRUR.js} +1 -1
  23. package/dist/assets/{Logs-BcxufpDI.js → Logs-83SiLwwo.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-Bh3ATmRU.js → MotionZonesSettings-C5-a5xsA.js} +1 -1
  25. package/dist/assets/{MyAccess-DuUovcBE.js → MyAccess-Cqru81yg.js} +1 -1
  26. package/dist/assets/{Network-Alv3x71v.js → Network-Cw2nm4zw.js} +1 -1
  27. package/dist/assets/{NodeAddonsSettingsPanel-IyS3g4ZJ.js → NodeAddonsSettingsPanel-ByJnLrGD.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-BUFBkUGK.js → NodeInferenceDevices-BIe_geP6.js} +1 -1
  29. package/dist/assets/Notifications-CbebsuWo.js +1 -0
  30. package/dist/assets/{Pipeline-DiRJyJgw.js → Pipeline-ByqUhA2i.js} +1 -1
  31. package/dist/assets/{Plates-DD1QjzOj.js → Plates-DxeW22pV.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-DX7-NfKq.js → PrivacyMaskSettings-BOX8TWYI.js} +1 -1
  33. package/dist/assets/{ProviderIcon-BLTK1B8B.js → ProviderIcon-DK02T3wV.js} +1 -1
  34. package/dist/assets/{Recordings-DWXREKE8.js → Recordings-rc4lfUD4.js} +1 -1
  35. package/dist/assets/{ScanNetworkModal-vnC2iQN6.js → ScanNetworkModal-_a9lt4NM.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-CbX9Eg5T.js → SceneMonitorEditor-CCZXAnuz.js} +1 -1
  37. package/dist/assets/{Scenes-6e3ksayO.js → Scenes-CHsuehnu.js} +1 -1
  38. package/dist/assets/{Settings-Ch71zfUE.js → Settings-BoQDlLHU.js} +1 -1
  39. package/dist/assets/{Showroom-CE6cZ6AE.js → Showroom-B-oLY6H9.js} +1 -1
  40. package/dist/assets/{StorageLocationsPanel-C844QQmH.js → StorageLocationsPanel-Co1NFEEG.js} +1 -1
  41. package/dist/assets/{Terminal-BdSW59EU.js → Terminal-BYG6Xf_7.js} +1 -1
  42. package/dist/assets/{Viewer-Bqu49Eyz.js → Viewer-Cib8pLtK.js} +1 -1
  43. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Dq9tCMBi.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BmM57Kh5.js} +1 -1
  44. package/dist/assets/{authed-media-CDRD3foD.js → authed-media-flayQst-.js} +1 -1
  45. package/dist/assets/{bell-off-Chy85tHo.js → bell-off-BYhY4dUE.js} +1 -1
  46. package/dist/assets/{boxes-CznuBfjY.js → boxes-BbrJnaEC.js} +1 -1
  47. package/dist/assets/circle-slash-DQ3qAn74.js +1 -0
  48. package/dist/assets/{debounced-invalidate-B55iwL8l.js → debounced-invalidate-DOruFsCC.js} +1 -1
  49. package/dist/assets/dist-BuEmSPML.js +349 -0
  50. package/dist/assets/{dist-B60VFPwg.js → dist-M2vP64mZ.js} +1 -1
  51. package/dist/assets/{face-bbox-On0PoHCg.js → face-bbox-fQdb3tI5.js} +1 -1
  52. package/dist/assets/{format-size-VQj7Uf9V.js → format-size-Du1oQs5g.js} +1 -1
  53. package/dist/assets/{grid-2x2--Hq82a4m.js → grid-2x2-liGzuGdl.js} +1 -1
  54. package/dist/assets/{hostInit-CdN_1LQT.js → hostInit-Cg1ikQOj.js} +1 -1
  55. package/dist/assets/{index-Df4gVeaw.js → index-TVYrzAyG.js} +3 -3
  56. package/dist/assets/{key-round-BTF6tJu7.js → key-round-CmhHfS76.js} +1 -1
  57. package/dist/assets/{layers-DXNPk6e2.js → layers-CcUa4Myc.js} +1 -1
  58. package/dist/assets/{location-owned-usage-BLRqPnsy.js → location-owned-usage-BaRb96LF.js} +1 -1
  59. package/dist/assets/{mf-entry-bootstrap-0-71dcf977.js → mf-entry-bootstrap-0-216d9d19.js} +2 -2
  60. package/dist/assets/{player-overlays-DCSz50mz.js → player-overlays-ChOaOu5c.js} +1 -1
  61. package/dist/assets/remoteEntry-DaWsNuMY.js +1 -0
  62. package/dist/assets/{send-bY8LGnoD.js → send-DeN8TTRw.js} +1 -1
  63. package/dist/assets/{settings-2-D8bbsBcp.js → settings-2-BNxcUWs7.js} +1 -1
  64. package/dist/assets/{square-check-big-CbsgEUec.js → square-check-big-FnMaHhaj.js} +1 -1
  65. package/dist/assets/src-3Tpsw-oI.js +349 -0
  66. package/dist/assets/{src-WaCIZdBp.js → src-DQplLwvx.js} +17 -17
  67. package/dist/assets/{use-scenes-feed-CcFn_NQd.js → use-scenes-feed-BL4aSMBu.js} +1 -1
  68. package/dist/assets/useEventInvalidation-DU5PhlZm.js +1 -0
  69. package/dist/assets/{useNodeUrlSelection-DBsQ7_NO.js → useNodeUrlSelection-0H6DetN0.js} +1 -1
  70. package/dist/assets/user-round-CzkfJzas.js +1 -0
  71. package/dist/assets/{video-DzU1mMEQ.js → video-C0zp850m.js} +1 -1
  72. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B9c84MAY.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-l4YwL-5U.js} +2 -2
  73. package/dist/index.html +5 -5
  74. package/dist/server/addon.js +174 -9
  75. package/package.json +1 -1
  76. package/dist/assets/Events-CKM3esa-.js +0 -1
  77. package/dist/assets/Notifications-DN9EzK2h.js +0 -1
  78. package/dist/assets/circle-slash-BK7bCfOq.js +0 -1
  79. package/dist/assets/dist-Djqty8fE.js +0 -349
  80. package/dist/assets/remoteEntry-VvG6xC2J.js +0 -1
  81. package/dist/assets/src-DN3-m3xa.js +0 -349
  82. package/dist/assets/useEventInvalidation-DMEb9YU8.js +0 -1
  83. package/dist/assets/user-round-OZiVNoNN.js +0 -1
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
- //#region ../types/dist/event-category-ZyX6jcse.mjs
3
+ //#region ../types/dist/event-category-BVDXG4tB.mjs
4
4
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
5
5
  EventCategory["SystemBoot"] = "system.boot";
6
6
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -617,6 +617,20 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
617
617
  * pull-reconcile from the provider's `getStatus` on reconnect. */
618
618
  EventCategory["MeshNetworkChanged"] = "network.mesh.changed";
619
619
  EventCategory["BackupCompleted"] = "backup.completed";
620
+ /**
621
+ * A whole backup RUN finished — every destination attempted, win or lose.
622
+ *
623
+ * `backup.completed` fires once per DESTINATION, which is the right grain for
624
+ * a progress UI and the wrong one for a notification: an operator with three
625
+ * destinations would be told three times. And a run where two of three
626
+ * destinations succeeded is not a clean success — a single "backup
627
+ * completed" that hid the failed one would be a lie, so the count of each is
628
+ * carried here and the message says both.
629
+ *
630
+ * Emitted by the backup orchestrator only after the destination loop, so a
631
+ * run that dies during the BUILD phase produces no completion at all.
632
+ */
633
+ EventCategory["BackupRunCompleted"] = "backup.run-completed";
620
634
  EventCategory["BackupRestored"] = "backup.restored";
621
635
  EventCategory["NotificationDispatched"] = "notification.dispatched";
622
636
  EventCategory["NotificationFailed"] = "notification.failed";
@@ -5347,7 +5361,7 @@ var ZodIssueCode = {
5347
5361
  var ZodFirstPartyTypeKind;
5348
5362
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5349
5363
  //#endregion
5350
- //#region ../types/dist/sleep-DBKu2-U5.mjs
5364
+ //#region ../types/dist/sleep-DEuj7E3j.mjs
5351
5365
  /**
5352
5366
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5353
5367
  * window to float samples (D455).
@@ -11493,6 +11507,58 @@ method(ListInputSchema, array(BrokerInfoSchema$1)), method(GetInputSchema, Broke
11493
11507
  auth: "admin"
11494
11508
  }), method(GetStateInputSchema, unknown().nullable()), method(_void(), RegistryStatusSchema);
11495
11509
  DeviceType.Camera;
11510
+ /**
11511
+ * The signals a device can emit to WAKE its own stream.
11512
+ *
11513
+ * A camera whose stream is built on demand sleeps until something asks for it,
11514
+ * and "something" cannot be a consumer that is merely attached — a Frigate-style
11515
+ * puller holds a session open for ever, and treating that as demand would keep
11516
+ * a battery camera awake for ever, which is the whole thing the battery is for
11517
+ * (D173). So the wake has to come from the CAMERA: an event it noticed by
11518
+ * itself, with no stream running.
11519
+ *
11520
+ * ## The vocabulary is the PROVIDER'S, not ours
11521
+ *
11522
+ * Like `consumables`, this cap declares no vocabulary of its own. A provider
11523
+ * names each signal with a `code` it chooses and a `label` an operator reads.
11524
+ * Reolink offers motion and camera-native detection; another provider may offer
11525
+ * a tamper, a doorbell press, a PIR, or something no camera in this fleet has
11526
+ * yet. A fixed enum here would mean every new signal is a framework release.
11527
+ *
11528
+ * It is deliberately NOT derived from the caps a device already binds. Whether
11529
+ * a camera CAN push firmware motion is expressed by `motionSources` containing
11530
+ * `'onboard'`, and whether it does AI on-camera by the `native-object-detection`
11531
+ * binding — but both answer "what drives the detection pipeline", which is a
11532
+ * different question from "what may wake a sleeping stream". A camera can do
11533
+ * the first and not be trusted with the second, and the operator picks per
11534
+ * camera. Two questions, two authorities.
11535
+ *
11536
+ * ## Availability is not permission
11537
+ *
11538
+ * `listSignals` says what the device CAN emit. Whether a given signal actually
11539
+ * wakes the stream is the operator's per-camera choice, held by the broker
11540
+ * alongside the cooldown — see the stream-broker cap's wake settings. A
11541
+ * provider declaring a signal is not a provider enabling it.
11542
+ */
11543
+ /** One signal a device can emit. */
11544
+ var StreamSignalSchema = object({
11545
+ /** Stable id chosen by the provider, e.g. `'motion'`, `'person'`, `'tamper'`. */
11546
+ code: string().min(1),
11547
+ /** What an operator reads in the picker. The provider's own wording. */
11548
+ label: string().min(1),
11549
+ /**
11550
+ * Whether the provider recommends this signal ON when a camera is first set
11551
+ * up. A provider knows which of its signals are cheap and reliable; an
11552
+ * operator should not have to discover that by trial. Reolink recommends
11553
+ * both of its own.
11554
+ */
11555
+ recommended: boolean()
11556
+ });
11557
+ object({
11558
+ signals: array(StreamSignalSchema),
11559
+ lastFetchedAt: number()
11560
+ });
11561
+ Object.values(DeviceType), method(_void(), array(StreamSignalSchema).readonly());
11496
11562
  /** Stream delivery format. (Relocated from the retired `streaming-engine` cap.) */
11497
11563
  var StreamFormatSchema = _enum([
11498
11564
  "webrtc",
@@ -11889,6 +11955,22 @@ var EgressTranscodeSchema = object({
11889
11955
  camStreamId: string().nullable()
11890
11956
  });
11891
11957
  method(object({
11958
+ deviceId: number().int().nonnegative(),
11959
+ /** The provider's signal code. */
11960
+ code: string().min(1),
11961
+ /** Ms epoch. Absent ⇒ now. */
11962
+ at: number().optional()
11963
+ }), object({
11964
+ /** Whether the broker acted on it, and if not, why. */
11965
+ accepted: boolean(),
11966
+ reason: _enum([
11967
+ "woke",
11968
+ "hold-extended",
11969
+ "not-enabled",
11970
+ "no-consumer",
11971
+ "unknown-code"
11972
+ ])
11973
+ }), { kind: "mutation" }), method(object({
11892
11974
  deviceId: number().int().nonnegative(),
11893
11975
  camStreamId: string().min(1),
11894
11976
  kind: CamStreamKindSchema,
@@ -12143,6 +12225,16 @@ var PickStreamRequirementsSchema = object({
12143
12225
  acceptCodecs: array(StreamCodecSchema).readonly().optional(),
12144
12226
  /** Minimum vertical resolution. Streams shorter than this are dropped. */
12145
12227
  minHeight: number().int().positive().optional(),
12228
+ /**
12229
+ * Maximum vertical resolution. Streams TALLER than this are dropped.
12230
+ *
12231
+ * A consumer can have a ceiling as real as its floor: Alexa documents
12232
+ * 480p to 1080p, and a 4K stream is as unusable to an Echo as a 360p one.
12233
+ * Without this the ceiling had to be re-implemented by every caller — and
12234
+ * one caller implementing it privately is how a second scoring authority
12235
+ * gets born.
12236
+ */
12237
+ maxHeight: number().int().positive().optional(),
12146
12238
  /** Minimum horizontal resolution. */
12147
12239
  minWidth: number().int().positive().optional(),
12148
12240
  /**
@@ -12159,7 +12251,22 @@ var PickStreamRequirementsSchema = object({
12159
12251
  * transcoded" guard: if the device is already serving the consumer's
12160
12252
  * codec end-to-end, there's nothing to optimise.
12161
12253
  */
12162
- requireSiblingCodec: array(StreamCodecSchema).readonly().optional()
12254
+ requireSiblingCodec: array(StreamCodecSchema).readonly().optional(),
12255
+ /**
12256
+ * Whether a stream the consumer CANNOT decode may still be picked, on the
12257
+ * understanding that it will be transcoded.
12258
+ *
12259
+ * Default `false` — today's behaviour, and the right one for a bypass
12260
+ * question ("is there a stream I can forward untouched?"). Set `true` to
12261
+ * ask the larger question: "what is the best stream for me, transcoding if
12262
+ * I must?" A stream that satisfies `acceptCodecs` always outranks one that
12263
+ * does not, so a passthrough is never lost to a transcode; the answer says
12264
+ * which it is in {@link PickedCamStreamSchema.transcodes}.
12265
+ *
12266
+ * This is what lets one picker serve both the bypass and the full source
12267
+ * choice, instead of a consumer scoring privately when the bypass misses.
12268
+ */
12269
+ allowTranscode: boolean().optional()
12163
12270
  }).readonly();
12164
12271
  var PickStreamPreferencesSchema = object({
12165
12272
  /**
@@ -12173,12 +12280,32 @@ var PickStreamPreferencesSchema = object({
12173
12280
  * picks the tallest stream; `'lowest'` picks the shortest (used by
12174
12281
  * memory-constrained consumers / Apple Home guest sessions).
12175
12282
  */
12176
- resolutionPreference: _enum(["highest", "lowest"]).optional()
12283
+ resolutionPreference: _enum(["highest", "lowest"]).optional(),
12284
+ /**
12285
+ * The height the consumer actually wants to DELIVER.
12286
+ *
12287
+ * Not a constraint — an ordering. With it set, the SMALLEST stream at or
12288
+ * above the target wins, and only if nothing reaches it does the tallest
12289
+ * take over. Pulling 1296 lines to draw 720 on a 1280x800 Echo panel costs
12290
+ * a decode and buys nothing, and `resolutionPreference: 'highest'` cannot
12291
+ * express that: it says "as big as possible", which is a different wish.
12292
+ *
12293
+ * Ignored when absent, so every existing caller keeps its ordering.
12294
+ */
12295
+ targetHeight: number().int().positive().optional()
12177
12296
  }).readonly();
12178
12297
  var PickedCamStreamSchema = object({
12179
12298
  camStreamId: string(),
12180
12299
  codec: string().optional(),
12181
12300
  resolution: CamStreamResolutionSchema.optional(),
12301
+ /**
12302
+ * Whether serving this stream requires a decode + re-encode.
12303
+ *
12304
+ * `false` is a stream the consumer can take as it stands. Only ever `true`
12305
+ * when the caller asked for it with `allowTranscode`, so a caller that did
12306
+ * not ask cannot be handed a cost it never agreed to pay.
12307
+ */
12308
+ transcodes: boolean(),
12182
12309
  /** One-line explanation of why this stream won — for logs / debug UI. */
12183
12310
  reason: string()
12184
12311
  });
@@ -16367,6 +16494,8 @@ var NcSystemEventKindSchema = _enum([
16367
16494
  "device-enabled",
16368
16495
  "device-battery-low",
16369
16496
  "device-battery-normal",
16497
+ "device-consumable-low",
16498
+ "device-consumable-normal",
16370
16499
  "stream-online",
16371
16500
  "stream-offline",
16372
16501
  "node-online",
@@ -16385,6 +16514,7 @@ var NcSystemEventKindSchema = _enum([
16385
16514
  "addon-updated",
16386
16515
  "server-updated",
16387
16516
  "export-completed",
16517
+ "backup-completed",
16388
16518
  "camera-online",
16389
16519
  "camera-offline",
16390
16520
  "camera-disabled",
@@ -23626,10 +23756,28 @@ DeviceType.Camera, method(object({ deviceId: number().int().nonnegative() }), ar
23626
23756
  }), boolean()), method(object({
23627
23757
  deviceId: number().int().nonnegative(),
23628
23758
  sessionId: string()
23629
- }), object({ pendingRenegotiation: object({
23630
- target: WebrtcStreamTargetSchema,
23631
- epoch: number()
23632
- }).nullable() }));
23759
+ }), object({
23760
+ pendingRenegotiation: object({
23761
+ target: WebrtcStreamTargetSchema,
23762
+ epoch: number()
23763
+ }).nullable(),
23764
+ /**
23765
+ * Whether the session still EXISTS.
23766
+ *
23767
+ * A consumer that holds a resource for the life of a session needs to
23768
+ * be able to ask, because a session does not always end the way it
23769
+ * began. Measured on this hub 2026-09-13: an Echo that got stuck never
23770
+ * sent `SessionDisconnected`, so the Alexa exporter's
23771
+ * `releaseEgressTranscode` never ran, and a 2304x1296 HEVC to 720p
23772
+ * H.264 transcode kept running for NOBODY for more than twenty
23773
+ * minutes. The WebRTC session had logged `WebRTC session closed`
23774
+ * minutes earlier — the broker knew; the holder had no way to ask.
23775
+ *
23776
+ * `false` for a session id the provider has never heard of, which is
23777
+ * the same answer as "it ended": either way nothing is holding it up.
23778
+ */
23779
+ alive: boolean()
23780
+ }));
23633
23781
  object({
23634
23782
  /** All accessory children of the parent. */
23635
23783
  childDeviceIds: array(number()).readonly(),
@@ -36133,6 +36281,12 @@ Object.freeze({
36133
36281
  addonId: null,
36134
36282
  access: "create"
36135
36283
  },
36284
+ "streamBroker.reportStreamSignal": {
36285
+ capName: "stream-broker",
36286
+ capScope: "system",
36287
+ addonId: null,
36288
+ access: "create"
36289
+ },
36136
36290
  "streamBroker.restartProfile": {
36137
36291
  capName: "stream-broker",
36138
36292
  capScope: "system",
@@ -36217,6 +36371,12 @@ Object.freeze({
36217
36371
  addonId: null,
36218
36372
  access: "create"
36219
36373
  },
36374
+ "streamSignals.listSignals": {
36375
+ capName: "stream-signals",
36376
+ capScope: "device",
36377
+ addonId: null,
36378
+ access: "view"
36379
+ },
36220
36380
  "switch.setState": {
36221
36381
  capName: "switch",
36222
36382
  capScope: "device",
@@ -38589,6 +38749,11 @@ Object.freeze({
38589
38749
  form: "single",
38590
38750
  optional: false
38591
38751
  }],
38752
+ "streamBroker.reportStreamSignal": [{
38753
+ name: "deviceId",
38754
+ form: "single",
38755
+ optional: false
38756
+ }],
38592
38757
  "streamBroker.restartProfile": [{
38593
38758
  name: "deviceId",
38594
38759
  form: "single",
@@ -39366,7 +39531,7 @@ var AdminUIAddon = class extends BaseAddon {
39366
39531
  capability: adminUiCapability,
39367
39532
  provider: {
39368
39533
  getStaticDir: async () => ({ staticDir: resolveAdminUiDistDir() }),
39369
- getVersion: async () => ({ version: "1.2.189" })
39534
+ getVersion: async () => ({ version: "1.2.192" })
39370
39535
  }
39371
39536
  }];
39372
39537
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.189",
3
+ "version": "1.2.192",
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,ct as h,dt as g,gt as _,mt as v,pt as y,st as b}from"./player-overlays-DCSz50mz.js";import{Bl as x,Ca as S,Ct as C,Da as w,Ea as T,El as E,Fa as D,Ft as O,It as k,Jr as A,Jt as j,M,Ma as N,Mn as P,Mt as F,Na as I,Nl as ee,Nt as L,Oa as R,Pa as z,Pc as B,Pt as V,Rl as H,Sa as te,Sc as U,Sl as W,Ta as ne,Tl as re,Tt as ie,Zs as ae,_a as G,ac as oe,ba as se,ha as ce,hl as le,ia as ue,ja as de,ka as fe,kl as pe,ln as me,mc as he,nc as ge,rl as K,tu as _e,un as ve,va as ye,xa as be,xc as xe,yc as Se,zc as Ce}from"./src-WaCIZdBp.js";import{t as we}from"./square-check-big-CbsgEUec.js";import{lt as Te,qt as Ee}from"./src-DN3-m3xa.js";import{t as De}from"./index-Df4gVeaw.js";import{t as Oe}from"./AdminPage-CiKtOLQm.js";import{a as ke,i as Ae,r as je,t as Me}from"./authed-media-CDRD3foD.js";import{a as Ne,c as Pe,d as Fe,f as Ie,i as Le,n as Re,o as ze,p as Be,r as Ve,s as He,t as Ue}from"./debounced-invalidate-B55iwL8l.js";import{t as We}from"./AdminTabs-Djv_JeIl.js";var Ge=_(`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`}]]),Ke=_(`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`}]]),qe=_(`circle`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),Je=_(`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`}]]),Ye=_(`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`}]]);n();function Xe(e){return e.subLabel??e.label}var Ze=720*60*60*1e3;function Qe(e){let t=[];for(let n of e)t.push(...n);return t}function $e(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function et(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 tt(e,t){return`${String(e)}:${t}`}function nt(e,t){let n=new Map,r=new Set;for(let i of e){let e=tt(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 rt(e,t){return{since:e.fromMs??t-Ze,until:e.toMs??t}}var it=[`native`,`raster`,`standin`];function at(e){return it.some(t=>t===e)}var ot={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 st(e){return e===`standin`?ot.standin:e===`raster`?ot.raster:null}var ct={"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 lt(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:ct[r]??r,detail:i,raw:t}}function ut(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 dt({row:e,cameraName:t,nowMs:n,onOpenDetail:i,selected:a=!1,onToggleSelect:o,score:s,provenance:c,footer:l}){let d=ke(e.mediaId===void 0?Ae(`track`,e.trackId):je(e.mediaId)),f=Math.round(e.importance*100),p=s===void 0?void 0:Math.round(s*100),m=ut(e.windowMs),_=()=>i(e),v=st(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:_,className:`h-full w-full cursor-zoom-in object-cover`}):u(`button`,{type:`button`,onClick:_,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(g,{className:`h-6 w-6 opacity-60`})}),o&&u(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(tt(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(we,{className:`h-4 w-4 text-primary`}):u(h,{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)}),v!==null&&u(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.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(Je,{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(x,{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(xe,{className:`h-3 w-3`})})]})]}),r(`button`,{type:`button`,onClick:_,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,Xe(e)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Xe(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:Ie(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 ft=1400,pt=`Admin-gated URL — opens only inside an authenticated session`;function mt({label:t,value:n,title:i}){let[a,o]=l(!1);return d(()=>{if(!a)return;let e=setTimeout(()=>o(!1),ft);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?H:re,{className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`truncate`,children:a?`Copied`:t})]})}function ht({localUrl:e,publicUrl:t}){return r(`div`,{className:`flex flex-wrap gap-1`,children:[u(mt,{label:`Local`,value:e,title:`Copy LAN URL — ${pt}`}),t&&u(mt,{label:`Public`,value:t,title:`Copy public URL — ${pt}`})]})}var gt={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 _t(e){return e in gt}function vt(e){return _t(e)?gt[e]:e}function yt(e,t){return`${e}${t}`}n();var bt=3e4;function xt(t){let[n,r]=l(null),i=e(e=>{r(t=>t??e)},[]);return d(()=>{t||r(null)},[t]),{publicOrigin:n,probes:t?u(St,{onOrigin:i}):null}}function St({onOrigin:e}){let{data:t}=P({capName:`network-access`});return u(s,{children:(t??[]).map(t=>u(Ct,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Ct({addonId:e,onOrigin:t}){let{data:n}=ue({addonId:e},{refetchInterval:bt,retry:!1});return d(()=>{let e=n?Te.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 q=typeof D==`function`,wt=`Track flags arrive with the next server update`;function Tt(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Et=q?D:Tt;function Dt(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 Ot({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 kt({deviceId:e,trackId:t,markForTrain:n,debug:i,favourited:a,onChange:o}){let s=Et(),[c,d]=l(null),f=c?.markForTrain??n===!0,p=c?.debug??i===!0,m=c?.favourited??a===!0,h=!q||s.isPending,g=q?void 0:wt,_=n=>{h||(async()=>{try{let r=Dt(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(Ot,{label:`Mark for training`,hint:`Keeps this track and its media past retention`,checked:f,disabled:h,...g===void 0?{}:{title:g},icon:u(Je,{className:`h-4 w-4`}),onToggle:()=>_({markForTrain:!f})}),u(Ot,{label:`Debug`,hint:`Flag this track for diagnostic attention`,checked:p,disabled:h,...g===void 0?{}:{title:g},icon:u(x,{className:`h-4 w-4`}),onToggle:()=>_({debug:!p})}),u(Ot,{label:`Favourited`,hint:`Keeps this track and its media past retention`,checked:m,disabled:h,...g===void 0?{}:{title:g},icon:u(xe,{className:`h-4 w-4`}),onToggle:()=>_({favourited:!m})})]})}var J=100,At=120,jt={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Y=e=>e<0?0:e>1?1:e,X=e=>Math.round(e*100)/100;function Mt(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 Nt(e,t,n){if(e.length===0||t===null)return jt;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return jt;let a=Mt(e,n?.maxPoints??At).map(e=>({x:X(Y(e.x/r)*J),y:X(Y(e.y/i)*J)})),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:X(Y(e.x/r)*J),y:X(Y(e.y/i)*J),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Y(t.bbox.w/r)*Y(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:X(Y(u.bbox.x/r)*J),y:X(Y(u.bbox.y/i)*J),w:X(Y(u.bbox.w/r)*J),h:X(Y(u.bbox.h/i)*J)}:null}}var Pt=typeof G==`function`,Ft=`Track deletion arrives with the next server update`;function It(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Lt=Pt?G:It;n();var Rt=15e3,zt=f();function Bt({url:e,label:t}){let{src:n,failed:r}=ke(e);return n===null?u(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?u(g,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):u(K,{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 Vt=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Ht=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function Ut(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 Wt({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.mediaId)}:void 0,children:u(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${String(e.mediaId)}-${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 Z({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 Gt({row:t,cameraName:n,deleteAvailable:i,onClose:o,onDeleted:c,onFlagsChanged:f}){let p=m(),h=Lt(),_=t!==null,v=t?.deviceId??0,y=t?.trackId??``,x=t?.timestamp??0,w=t?.windowMs??0,{data:T}=be({deviceId:v,trackId:y},{enabled:_}),{data:E}=R({trackId:y,deviceId:v},{enabled:_}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=S({ownerType:`object`,eventId:D??0,deviceId:v},{enabled:_&&D!==void 0&&Number.isFinite(D)}),{data:A}=ae({deviceId:v,since:x-Rt,until:x+w+Rt},{enabled:_}),[j,M]=l(null),[N,P]=l(!1),{publicOrigin:F,probes:I}=xt(_);d(()=>{M(null)},[v,y]);let ee=a(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),L=j??ee,z=ke(L?L.url:void 0),B=a(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),V=a(()=>B.find(e=>Vt.has(e.kind))??null,[B]),H=Ut(ke(V?V.url:void 0).src),te=a(()=>Nt(T?.positions??[],H,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,H]),U=e(e=>{let t=B.find(t=>t.mediaId===e);t&&M(t)},[B]);if(t===null)return null;let W=z.src,ne=L?.kind,re=ne!==void 0&&Ht.has(ne)&&H!==null&&(T?.positions.length??0)>=2,G=A&&A.length>0?A[0]:null,se=()=>{G&&(P(!0),(async()=>{try{let e=await p.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:G.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{P(!1)}})())},ce=()=>{!i||h.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await h.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),c()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},ue=Math.round(t.importance*100),de=T?.importanceReason?`${String(ue)}% · ${T.importanceReason}`:`${String(ue)}%`,fe=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,pe=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,me=T?T.totalDistance.toFixed(2):`—`,he=lt(T?.previewMissReason),ge=Be(T?T.firstSeen:x),_e=T?Be(T.lastSeen):`—`;return u(C,{open:!0,onOpenChange:e=>!e&&o(),children:r(ie,{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,Xe(t)?r(`span`,{className:`text-foreground-subtle`,children:[` · `,Xe(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(oe,{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:[W?u(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:u(Re,{src:W,alt:`Key frame from ${n}`,fit:`natural`,className:`w-full`,overlay:re?u(Wt,{overlay:te,onPickSnapshot:U}):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:z.failed?r(s,{children:[u(g,{className:`h-8 w-8 opacity-60`}),u(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):u(K,{className:`h-6 w-6 animate-spin opacity-70`})}),B.length>0&&u(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:B.map(e=>{let t=vt(e.kind),n=yt(zt,e.url),i=F?yt(F,e.url):null;return r(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[u(`button`,{type:`button`,onClick:()=>M(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${t} · ${Be(e.timestamp)}`,children:u(Bt,{url:e.url,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:Be(e.timestamp),children:Fe(e.timestamp)})]}),u(ht,{localUrl:n,publicUrl:i})]},e.mediaId)})}),I,G&&r(k,{variant:`secondary`,onClick:se,disabled:N,children:[N?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(le,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),u(kt,{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(Z,{label:`Camera`,value:n}),u(Z,{label:`Class`,value:t.className}),u(Z,{label:`Label`,value:t.label??`—`}),u(Z,{label:`Sub-label`,value:t.subLabel??`—`}),u(Z,{label:`Importance`,value:de}),u(Z,{label:`Zones visited`,value:fe}),u(Z,{label:`Audio heard`,value:pe}),u(Z,{label:`Total distance`,value:me}),u(Z,{label:`First seen`,value:ge}),u(Z,{label:`Last seen`,value:_e}),u(Z,{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:Ft,children:r(k,{variant:`secondary`,onClick:ce,disabled:!i||h.isPending,children:[h.isPending?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(b,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}var Kt=`pipeline-analytics`,qt=`debug.listTracks`,Jt=`debug.analyze`,Yt=p(`/addon/pipeline-analytics/debug-export`);function Xt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Zt(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Qt(e){return e===`error`||e===`warn`||e===`info`}function $t(e){if(!Xt(e))return null;let t=Q(e,`code`),n=Q(e,`detail`),r=e.severity;return t===null||n===null||!Qt(r)?null:{code:t,severity:r,detail:n}}function en(e){if(!Xt(e))return null;let t=Q(e,`trackId`),n=$(e,`deviceId`),r=Q(e,`className`),i=$(e,`firstSeen`),a=$(e,`lastSeen`),o=$(e,`durationMs`),s=Zt(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=Q(e,`label`),l=Q(e,`subLabel`),u=Q(e,`previewMissReason`),d=Zt(e,`markForTrain`),f=Zt(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:$(e,`importance`)??0,bestEventId:Q(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function tn(e){let t=en(e);if(t===null||!Xt(e))return null;let n=$(e,`mediaCount`),r=$(e,`eventCount`),i=$(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=$t(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...at(l)?{thumbnailProvenance:l}:{}}}function nn(e){if(!Xt(e))return null;let t=Zt(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=en(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function rn(e){if(!Xt(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=tn(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var an={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 on(e){return an[e]??e}var sn={error:0,warn:1,info:2};function cn(e){return e.toSorted((e,t)=>sn[e.severity]-sn[t.severity]||e.code.localeCompare(t.code))}function ln(e){return e.length===0?Yt:`${Yt}?deviceIds=${e.join(`,`)}`}function un(e,t){return`${String(e)}:${t}`}function dn(e,t){let n=[],r=new Set;for(let i of e){let e=un(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 fn=`all`,pn=`The server answered in a shape this build does not understand.`,mn={error:`danger`,warn:`warning`,info:`info`};function hn({findings:e}){return e.length===0?u(O,{variant:`success`,children:`no anomaly found`}):u(`div`,{className:`flex flex-wrap gap-1`,children:cn(e).map(e=>u(O,{variant:mn[e.severity],title:e.detail,children:on(e.code)},e.code))})}function gn({track:e,report:t,analyzing:n}){let i=lt(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(hn,{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 _n(){let e=m(),[t,n]=l(fn),[i,s]=l(!1),[c,d]=l(null),[f,p]=l(new Set),[h,g]=l(null),[_,v]=l(null),[y,b]=l(null),[S,C]=l([]),w=Et(),T=A({isCamera:!0,projection:`slim`}),E=a(()=>[{value:fn,label:`All cameras`},...(T.data??[]).map(e=>({value:String(e.id),label:e.name}))],[T.data]),D=a(()=>{let e=new Map;for(let t of T.data??[])e.set(t.id,t.name);return e},[T.data]),O=e=>D.get(e)??`Camera ${String(e)}`,M=a(()=>t===fn?[]:[Number.parseInt(t,10)],[t]),N=o({queryKey:[`events-debug`,`list`,M],queryFn:async()=>nn(await e.trpcClient.addons.custom.mutate({addonId:Kt,action:qt,input:M.length===0?{}:{deviceIds:M}}))}),P=a(()=>(N.data?.tracks??[]).map(e=>e.trackId),[N.data]),I=o({queryKey:[`events-debug`,`analyze`,P],enabled:P.length>0,queryFn:async()=>rn(await e.trpcClient.addons.custom.mutate({addonId:Kt,action:Jt,input:{trackIds:P}}))}),ee=a(()=>{let e=new Map;for(let t of I.data?.reports??[])e.set(t.trackId,t);return e},[I.data]),L=N.data?.tracks??[],R=N.data===null||I.data===null,z=()=>{N.refetch(),I.refetch()},B=e=>{p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},te=()=>{p(new Set(L.map(e=>un(e.deviceId,e.trackId))))},U=()=>p(new Set),ne=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await w.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},re=e=>{if(!q||_!==null)return;let t=dn(L,f);t.length!==0&&(v(e),b(null),(async()=>{let n=await ne(e,t);v(null);let r=new Set(n.refused);p(new Set(t.filter(e=>r.has(e.trackId)).map(e=>un(e.deviceId,e.trackId)))),e===`analyzed`&&C(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.`),N.refetch()})())},ie=()=>{let e=S;e.length===0||_!==null||(v(`analyzed`),b(null),(async()=>{for(let t of e)try{await w.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),C([]),N.refetch()})())},ae=async()=>{s(!0),d(null);try{await Me(ln(M),`camstack-debug.zip`)}catch(e){d(e instanceof Error?e.message:`Export failed.`)}finally{s(!1)}},G=_!==null;return u(Oe,{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(F,{value:t,options:E,onChange:e=>n(e.target.value)})}),r(k,{variant:`secondary`,onClick:z,disabled:N.isFetching,children:[N.isFetching?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(Ce,{className:`h-3.5 w-3.5`}),`Refresh`]}),r(k,{onClick:()=>void ae(),disabled:i||L.length===0,children:[i?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(W,{className:`h-3.5 w-3.5`}),`Export all (`,String(L.length),`)`]}),L.length>0&&f.size<L.length&&u(k,{variant:`ghost`,onClick:te,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.`]}),N.isError&&u(j,{message:`Could not load the marked tracks.`}),R&&!N.isError&&u(j,{message:pn}),c!==null&&u(j,{message:c}),y!==null&&u(j,{message:y}),N.data?.truncated===!0&&u(j,{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:q?void 0:`Track flags arrive with the next server update`,children:r(k,{variant:`secondary`,onClick:()=>re(`keep`),disabled:!q||G,children:[_===`keep`?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(xe,{className:`h-3.5 w-3.5`}),` `,`Keep`]})}),u(`span`,{title:q?void 0:`Track flags arrive with the next server update`,children:r(k,{onClick:()=>re(`analyzed`),disabled:!q||G,children:[_===`analyzed`?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(H,{className:`h-3.5 w-3.5`}),` `,`Analyzed`]})}),u(k,{variant:`ghost`,onClick:U,disabled:G,children:u(oe,{className:`h-3.5 w-3.5`})})]})]}),S.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(S.length),` track(s) marked analyzed and removed from this list.`]}),r(k,{variant:`ghost`,onClick:ie,disabled:G,children:[u(he,{className:`h-3.5 w-3.5`}),` Undo`]}),u(k,{variant:`ghost`,onClick:()=>C([]),disabled:G,children:u(oe,{className:`h-3.5 w-3.5`})})]}),N.isLoading?u(V,{children:u(`div`,{className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:`Loading…`})}):L.length===0?u(V,{children:r(`div`,{className:`flex flex-col items-center gap-2 px-3 py-8 text-center`,children:[u(x,{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:L.map(e=>{let t=ee.get(e.trackId);return u(dt,{row:e,cameraName:O(e.deviceId),nowMs:e.lastSeen,selected:f.has(un(e.deviceId,e.trackId)),onToggleSelect:B,onOpenDetail:g,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:u(gn,{track:e,report:t,analyzing:I.isFetching})},un(e.deviceId,e.trackId))})}),h&&u(Gt,{row:h,cameraName:O(h.deviceId),deleteAvailable:Pt,onClose:()=>g(null),onDeleted:()=>{g(null),N.refetch()},onFlagsChanged:e=>{e.debug||(g(null),N.refetch())}})]})})}var vn=200,yn=3e4,bn=[];function xn(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:yn,refetchInterval:yn,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:vn,...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:$e(Qe(i??bn),`importance`),isLoading:n&&a}}n();var Sn=[`events-feed`],Cn=2e3;function wn(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:Sn})},[]),p=t(void 0);p.current||=Ue({delayMs:Cn,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 ge(Ee.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),ge(Ee.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:s,refreshNow:m}}n();function Tn({groups:e,selected:t,onChange:n,loading:i=!1}){let{t:o}=De(),[s,c]=l(!1),[d,f]=l(``),[p,m]=l(new Set),h=d.trim().toLowerCase(),g=e=>h.length===0||me(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]),b=e=>m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),x=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)},S=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},C=()=>n(new Set),w=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 ${w>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(Se,{className:`h-3.5 w-3.5`}),w>0?`Kinds (${String(w)})`:`Kinds`,u(v,{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(B,{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`}),w>0&&u(`button`,{type:`button`,onClick:C,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=ve(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:()=>b(e.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:u(i?v:y,{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:()=>x(e),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.macro.color}}),u(`span`,{className:`font-medium`,children:me(e.macro,o)})]})]}),i&&e.subs.map(e=>{let n=ve(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:()=>S(e.kind),className:`accent-primary`}),u(n,{className:`h-3.5 w-3.5`,style:{color:e.color}}),u(`span`,{children:me(e,o)})]},e.kind)})]},e.macro.kind)})]})]})}function En(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 Dn(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var On=new Set([`detection`,`package`]);function kn(e,t){return[...En(e,t).values()].filter(e=>e.parentKind===null&&On.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function An(e,t){let n=En(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,Dn(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 jn(){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 Mn=[`events-feed`],Nn=60,Pn=[{value:`importance`,label:`Importance`,icon:Ge},{value:`time`,label:`Recent`,icon:pe}];function Fn(){let e=c(),[t,n]=l(He),[i,o]=l(new Set),[f,p]=l(new Set),[m,h]=l(0),[g,_]=l(`time`),[v,y]=l(new Set),[x,S]=l(null),[C,w]=l(()=>Date.now());d(()=>{let e=setInterval(()=>w(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:T,until:E}=a(()=>rt({fromMs:t.fromMs,toMs:t.toMs},C),[t.fromMs,t.toMs,C]),D=jn(),{pending:O,refreshNow:j}=wn({paused:x!==null||v.size>0||D.scrolledPast}),{data:M=[]}=A({isCamera:!0,projection:`slim`}),N=a(()=>M.map(e=>e.id),[M]),{data:P,isLoading:F}=te({deviceIds:N},{enabled:N.length>0,staleTime:5*6e4}),I=a(()=>An(P??[],i),[P,i]),ee=Lt(),L=ee.isPending,{rows:R,isLoading:z}=xn({deviceIds:N,since:T,until:E,minImportance:m>0?m:void 0,classFilter:f.size===1?[...f][0]:void 0}),B=a(()=>{let e=new Map;for(let t of M??[])e.set(t.id,t.name);return e},[M]),V=e=>B.get(e)??`Camera #${String(e)}`,H=a(()=>Pe(R).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[R,B]),U=a(()=>$e(et(R,{cameras:i,classes:f,minImportance:m}),g),[R,i,f,m,g]),W=ze(U,Nn,a(()=>JSON.stringify([[...i].sort((e,t)=>e-t),[...f].sort(),m,g,T,E]),[i,f,m,g,T,E])),ne=()=>{e.invalidateQueries({queryKey:Mn})},re=()=>y(new Set);function ie(e){y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ae(){if(v.size===0||!Pt)return;let e=nt(R,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])=>ee.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{ne();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(tt(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=>V(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let G=U.length!==R.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(Ve,{onChange:n}),u(Le,{cameras:H,selected:i,onChange:o}),u(Tn,{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:Pn.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)})}),!z&&u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:G?`${String(U.length)} of ${String(R.length)} events`:`${String(U.length)} event${U.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:Pt?void 0:`Track deletion arrives with the next server update`,children:r(k,{variant:`secondary`,onClick:ae,disabled:!Pt||L,children:[L?u(K,{className:`h-3.5 w-3.5 animate-spin`}):u(b,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),u(k,{variant:`ghost`,onClick:re,disabled:L,children:u(oe,{className:`h-3.5 w-3.5`})})]})]}),z&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!z&&U.length===0&&u(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),O&&u(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:u(`button`,{type:`button`,onClick:j,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`})}),!z&&U.length>0&&r(s,{children:[u(`div`,{ref:D.ref,"aria-hidden":!0,className:`h-0`}),u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:W.pageItems.map(e=>u(dt,{row:e,cameraName:V(e.deviceId),nowMs:C,selected:v.has(tt(e.deviceId,e.trackId)),onToggleSelect:ie,onOpenDetail:S},tt(e.deviceId,e.trackId)))}),u(Ne,{currentPage:W.page,totalItems:W.totalItems,pageSize:W.pageSize,onPageChange:W.setPage,itemNoun:`events`})]}),x&&u(Gt,{row:x,cameraName:V(x.deviceId),deleteAvailable:Pt,onClose:()=>S(null),onDeleted:()=>{ne(),S(null)},onFlagsChanged:e=>{S(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}n();var In=50,Ln=350,Rn=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function zn(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function Bn({onActiveChange:e}){let[t,n]=l(``),[i,o]=l(.2),[s,c]=l(null),[f,p]=l(null),[m,h]=l(null),g=M(t,Ln).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=[]}=A({isCamera:!0,projection:`slim`}),x=a(()=>{let e=new Map;for(let t of b)e.set(t.id,t.name);return e},[b]),S=e=>x.get(e)??`Camera #${String(e)}`,C=a(()=>b.map(e=>e.id),[b]),{data:w}=te({deviceIds:C},{enabled:C.length>0,staleTime:5*6e4}),T=a(()=>kn(w??[],new Set(f===null?[]:[f])),[w,f]);d(()=>{s!==null&&(T.some(e=>e.kind===s)||c(null))},[T,s]);let{data:E,isFetching:D,isError:O,error:k}=I({text:g,minScore:i,limit:In,classFilter:s??void 0,deviceId:f??void 0},{enabled:_}),j=a(()=>[...E??[]].sort((e,t)=>t.score-e.score).map(e=>({...zn(e),score:e.score})),[E]);function N(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(B,{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(oe,{className:`h-3.5 w-3.5`})})]}),D&&_&&u(K,{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:T.map(e=>u(`button`,{type:`button`,onClick:()=>N(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:me(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:Rn.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))})]}),_&&!D&&!O&&r(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[j.length,` match`,j.length===1?``:`es`]})]})]}),_&&r(`div`,{className:`space-y-3`,children:[O&&r(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,k instanceof Error?k.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!O&&D&&j.length===0&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[u(K,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!O&&!D&&j.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.`]}),!O&&j.length>0&&u(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:j.map(e=>u(dt,{row:e,cameraName:S(e.deviceId),nowMs:v,score:e.score,onOpenDetail:h},e.id))})]}),m&&u(Gt,{row:m,cameraName:S(m.deviceId),deleteAvailable:Pt,onClose:()=>h(null),onDeleted:()=>h(null)})]})}var Vn=15e3,Hn={rows:[],unreadableCount:0};function Un(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:Vn,refetchInterval:Vn,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??Hn;return{rows:s.rows.toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n&&a,unreadableCount:s.unreadableCount}}n();function Wn(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 Gn({row:e,cameraName:t,nowMs:n}){let i=ke(e.keyFrameMediaId===void 0?void 0:je(e.keyFrameMediaId));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:[i.src?u(`img`,{src:i.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(Ye,{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 `,Wn(n,e.becameStationaryAt)]})]})]})}function Kn(){let[e,t]=l(!1),n=Date.now(),{data:i=[]}=A({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}=Un(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?v:y,{className:`h-4 w-4 text-foreground-subtle`}),u(Ye,{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(Gn,{row:e,cameraName:s.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}n();function qn(){let[e,t]=l(!1);return u(Oe,{children:r(`section`,{className:`space-y-3`,children:[u(Bn,{onActiveChange:t}),!e&&u(Kn,{}),!e&&u(Fn,{})]})})}var Jn=[`person`,`vehicle`,`animal`,`package`,`face`,`plate`],Yn=new Set(Jn);function Xn(e){let t=e?.trim().toLowerCase();return t===void 0||t===``?null:Yn.has(t)?`"${t}" is a macro class, not a label — person / postman / Marco are three different tiers`:null}function Zn({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=Xn(e.label),l=Xn(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(F,{className:`w-28`,value:e.macroClass,options:Jn.map(e=>({value:e,label:e})),onChange:e=>{let t=Jn.find(t=>t===e.target.value);t!==void 0&&i(o,{macroClass:t})}}),u(F,{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(O,{variant:`info`,children:[e.assistModelId??`assist`,e.assistScore===void 0?``:` ${e.assistScore.toFixed(2)}`]}),u(k,{variant:`ghost`,size:`sm`,"aria-label":`Delete this subject`,onClick:()=>{a(o)},children:u(b,{className:`h-3 w-3`})})]}),r(`div`,{className:`flex items-center gap-2`,children:[u(L,{className:`flex-1`,placeholder:`label (postman, van, cat…)`,value:e.label??``,onChange:e=>{i(o,{label:e.target.value})}}),u(L,{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 Qn(e){return e.every(e=>Xn(e.label)===null&&Xn(e.subLabel)===null&&Yn.has(e.macroClass))}function $n(e){return e<0?0:e>1?1:e}function er(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 tr(e,t,n){return{x:$n((e-n.left)/n.width),y:$n((t-n.top)/n.height)}}function nr(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 rr(e){return e.w>=.01&&e.h>=.01}function ir(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 ar(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 or({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=er(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 tr(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:nr(t,t)}))},onPointerMove:e=>{if(g===null)return;let t=y(e);t!==null&&_({start:g.start,current:nr(g.start,t)})},onPointerUp:()=>{if(g===null)return;let e=g.current;_(null),rr(e)?f(e):d(ar(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=ir(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:ir(g.current,v)})]})}function sr(e){return e>=1e6?`${(e/1e6).toFixed(1)} MB`:`${Math.round(e/1e3)} KB`}function cr({candidates:e,copies:t,activeFrameId:n,refusals:i,isSelecting:a,onSelectCandidate:o,onOpenCopy:s,onRemoveCopy:c}){let l=new Set(t.map(e=>e.sourceMediaId)),d=e.filter(e=>!l.has(e.mediaId));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(H,{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,` · `,sr(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(b,{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.mediaId);return r(`li`,{children:[r(k,{variant:`secondary`,size:`sm`,disabled:a||t!==void 0,onClick:()=>{o(e.mediaId)},children:[a?u(K,{className:`h-3 w-3 animate-spin`}):u(t===void 0?E:g,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:e.kind}),u(`span`,{className:`ml-1 text-foreground-subtle`,children:sr(e.sizeBytes)})]}),t!==void 0&&u(O,{variant:`danger`,className:`ml-1`,children:t})]},e.mediaId)})})]})]})}function lr(e){return e.frameCount===0?`untouched`:e.annotationCount===0?`started`:`ready`}var ur={untouched:{icon:qe,label:`to do`,variant:`default`},started:{icon:Ke,label:`frames only`,variant:`info`},ready:{icon:ee,label:`annotated`,variant:`success`}};function dr(e){return new Date(e).toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})}function fr({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(K,{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=ur[lr(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(O,{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)}`,` ·`,` `,dr(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 pr=`person`;function mr(){let[t,n]=l(null),[i,o]=l(null),[c,f]=l([]),[p,m]=l(-1),[h,g]=l(new Map),[_,v]=l(null),y=A({projection:`slim`,isCamera:!0}),b=a(()=>{let e=new Map;for(let t of y.data??[])e.set(t.id,t.name);return e},[y.data]),x=w({}),S=T({trackId:t?.trackId??``},{enabled:t!==null}),C=ne({trackId:t?.trackId??``},{enabled:t!==null}),E=se({frameId:i??``},{enabled:i!==null}),D=z(),j=ye(),M=fe(),P=N(),F=ce(),I=de();d(()=>{if(i===null){f([]);return}f((C.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,C.data]),d(()=>{let e=S.data?.copies??[];i===null&&e.length>0&&o(e[0].frameId)},[S.data,i]);let ee=e(e=>{n(e),o(null),f([]),g(new Map),v(null)},[]),L=e(async e=>{if(t===null)return;let n=await D.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,mediaIds:[e]});if(n.refused.length>0){let e=new Map(h);for(let t of n.refused)e.set(t.sourceMediaId,t.reason);g(e)}n.copied.length>0&&o(n.copied[0].frameId),await S.refetch(),await x.refetch()},[t,D,h,S,x]),R=e(async e=>{t!==null&&(await j.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:e}),i===e&&o(null),await S.refetch(),await C.refetch(),await x.refetch())},[t,j,i,S,C,x]),B=e(async e=>{if(t===null||i===null)return;v(null);let n=await M.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,frameId:i,subject:e===`package`?{kind:`package`}:{kind:`objects`,modelId:`yolo26n`,minScore:.3}});if(n.kind===`refused`){v(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}}))]),v(`${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,M]),V=e(e=>{f(t=>[...t,{bbox:e,macroClass:pr,kind:`subject`,source:`operator`}]),m(c.length)},[c.length]),H=e((e,t)=>{f(n=>n.map((n,r)=>r===e?{...n,...t}:n))},[]),te=e(e=>{f(t=>t.filter((t,n)=>n!==e)),m(-1)},[]),W=e(async()=>{t===null||i===null||(await P.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 C.refetch(),await x.refetch(),v(`Annotations saved.`))},[t,i,c,P,C,x]),re=e(async()=>{if(t===null)return;let e=await F.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});v(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 x.refetch(),e.changed&&n(null)},[t,F,x]),ie=e(async()=>{if(t===null)return;let e=await I.mutateAsync({deviceId:t.deviceId,trackId:t.trackId});v(e.changed?`Track returned to staging. Its copies and annotations were left alone.`:`Refused: ${e.reason??`unknown`}`),await x.refetch()},[t,I,x]),ae=E.data,G=Qn(c)&&i!==null;return r(Oe,{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(k,{variant:`secondary`,size:`sm`,onClick:()=>void ie(),children:[u(he,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Back to staging`})]}),r(k,{size:`sm`,onClick:()=>void re(),children:[u(Je,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Complete track`})]})]}),children:[_!==null&&u(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-xs text-foreground`,children:_}),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(O,{children:x.data?.length??0})]}),u(fr,{tracks:x.data??[],isLoading:x.isLoading,selectedTrackId:t?.trackId??null,deviceNames:b,onSelect:ee})]}),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(cr,{candidates:S.data?.candidates??[],copies:S.data?.copies??[],activeFrameId:i,refusals:h,isSelecting:D.isPending,onSelectCandidate:e=>void L(e),onOpenCopy:o,onRemoveCopy:e=>void R(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:ae===void 0?r(`div`,{className:`flex items-center gap-2 p-6 text-xs text-foreground-subtle`,children:[u(K,{className:`h-3.5 w-3.5 animate-spin`}),`Loading the frame…`]}):u(or,{imageSrc:`data:image/jpeg;base64,${ae.base64}`,imageWidth:ae.width,imageHeight:ae.height,boxes:c,selectedIndex:p,onSelect:m,onDraw:V})}),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(k,{variant:`secondary`,size:`sm`,disabled:M.isPending,onClick:()=>void B(`objects`),children:[u(U,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Propose`})]}),r(k,{variant:`secondary`,size:`sm`,disabled:M.isPending,onClick:()=>void B(`package`),children:[u(U,{className:`h-3 w-3`}),u(`span`,{className:`ml-1`,children:`Packages`})]})]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:u(Zn,{annotations:c,selectedIndex:p,onSelect:m,onChange:H,onDelete:te})}),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(k,{size:`sm`,disabled:!G||P.isPending,onClick:()=>void W(),children:`Save frame`})]})]})]})]})})]})]})}function hr(){return u(`div`,{className:`flex flex-col p-4`,children:u(We,{tabs:[{id:`feed`,label:`Feed`,icon:_e,content:u(qn,{})},{id:`retrain`,label:`Retrain`,icon:Je,content:u(mr,{})},{id:`debug`,label:`Debug`,icon:x,content:u(_n,{})}]})})}export{hr as EventsPage};