@camstack/addon-admin-ui 1.2.428 → 1.2.429

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 (167) hide show
  1. package/dist/assets/{AddonAssetIcon-Cs_blBpK.js → AddonAssetIcon-DR35yt0E.js} +1 -1
  2. package/dist/assets/Addons-gkGgGpTC.js +4 -0
  3. package/dist/assets/{AdminPage-DuuyDIsY.js → AdminPage-DAO24U0w.js} +1 -1
  4. package/dist/assets/AdminSectionedPage-B-qoE6ra.js +1 -0
  5. package/dist/assets/AiProfiles-BXcreqZP.js +3 -0
  6. package/dist/assets/BrokerForm-B3xs9aBj.js +1 -0
  7. package/dist/assets/Build-DeMAJfjN.js +40 -0
  8. package/dist/assets/Calendars-VPH-vy-o.js +1 -0
  9. package/dist/assets/Cluster-B-k0M79z.js +1 -0
  10. package/dist/assets/ClusterStepModel-DaAc_6nI.js +1 -0
  11. package/dist/assets/CompositionEditor-BrtLjoSu.js +1 -0
  12. package/dist/assets/{CompositionEditorPage-Acq7iapA.js → CompositionEditorPage-D51jS9td.js} +1 -1
  13. package/dist/assets/Data-IfJuKcwc.js +2 -0
  14. package/dist/assets/DeviceDetail-D1qU_p1k.js +2 -0
  15. package/dist/assets/DeviceDoActionFields-B62Nv4K7.js +1 -0
  16. package/dist/assets/Devices-Cf5Exjsk.js +1 -0
  17. package/dist/assets/{EmbedPlayerPage-RXOmf2F3.js → EmbedPlayerPage-CnEcSJ8D.js} +1 -1
  18. package/dist/assets/Identity-DNE80jdX.js +1 -0
  19. package/dist/assets/IntegrationDetail-LKbiJFU3.js +1 -0
  20. package/dist/assets/IntegrationHub-DdjWEObX.js +1 -0
  21. package/dist/assets/Integrations-CU7Ll9U_.js +1 -0
  22. package/dist/assets/Integrations-uZB2ozhn.js +1 -0
  23. package/dist/assets/Library-DSuCaXt6.js +1 -0
  24. package/dist/assets/Locations-BeaznsZS.js +3 -0
  25. package/dist/assets/{Logs-DIeXeCqI.js → Logs-cm-1R2Z4.js} +1 -1
  26. package/dist/assets/MaskShapeCanvas-CM9D4FOf.js +1 -0
  27. package/dist/assets/MotionZonesSettings-DqS8ndiK.js +1 -0
  28. package/dist/assets/MyAccess-Dxb11B6h.js +2 -0
  29. package/dist/assets/Network-BCDUHSB0.js +1 -0
  30. package/dist/assets/NodeAddonsSettingsPanel-BMat4ckt.js +1 -0
  31. package/dist/assets/Notifications-EPQiEZ1t.js +1 -0
  32. package/dist/assets/PrivacyMaskSettings-Bis0PO01.js +1 -0
  33. package/dist/assets/Recordings-BCeoXxL4.js +1 -0
  34. package/dist/assets/ScanNetworkModal-dHWFmbFe.js +1 -0
  35. package/dist/assets/SceneMonitorEditor-SFMMIopn.js +1 -0
  36. package/dist/assets/SessionsList-BRTwG3uv.js +2 -0
  37. package/dist/assets/{Showroom-W2yJvb8s.js → Showroom-Er-hes9K.js} +1 -1
  38. package/dist/assets/System-BDXxfgsq.js +1 -0
  39. package/dist/assets/{Terminal-CrFum1tE.js → Terminal-B70jnm8e.js} +4 -4
  40. package/dist/assets/{Viewer-YBzeS3RA.js → Viewer-BsGL5Dfa.js} +1 -1
  41. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-C7iEnSHU.js +1 -0
  42. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js +1 -0
  43. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DdJYWyu3.js +1 -0
  44. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-BsvPG3BX.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-DPkvGqVU.js} +1 -1
  45. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-DtoGixA1.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-Cb2QlpvS.js} +1 -1
  46. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-PmiLsYEK.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-Cyj0Xie_.js} +4 -4
  47. package/dist/assets/{addon-icons-context-D6glxUQF.js → addon-icons-context--6Hi3qRW.js} +1 -1
  48. package/dist/assets/{archive-kvflMCgL.js → archive-DtcjevJM.js} +1 -1
  49. package/dist/assets/{authed-media-CSlndmzS.js → authed-media-LCmlAEZ5.js} +1 -1
  50. package/dist/assets/{bell-off-BYnwGeiH.js → bell-off-eQBpwamg.js} +1 -1
  51. package/dist/assets/board-model-wzCmdEKJ.js +1 -0
  52. package/dist/assets/{boxes-Dx4USyB3.js → boxes-DikDfAoo.js} +1 -1
  53. package/dist/assets/circle-slash-YVgGJTpJ.js +1 -0
  54. package/dist/assets/client-DYbvGOid.js +358 -0
  55. package/dist/assets/{cloud-upload-82x5w5u8.js → cloud-upload-DI9XunFf.js} +1 -1
  56. package/dist/assets/crop-CxZbpOyK.js +1 -0
  57. package/dist/assets/{device-integration-icon-bTnWrYe0.js → device-integration-icon-D2lWVDM2.js} +1 -1
  58. package/dist/assets/device-picker-model-C4w1vbly.js +1 -0
  59. package/dist/assets/dist-CPO0KWoy.js +358 -0
  60. package/dist/assets/dist-ChQzskeX.js +1 -0
  61. package/dist/assets/{eraser-B8Awx5Sj.js → eraser-Dl5ROV0l.js} +1 -1
  62. package/dist/assets/{file-up-LqDVgVVa.js → file-up-WS3s_T9x.js} +1 -1
  63. package/dist/assets/{hard-drive-download-C24D80x2.js → hard-drive-download-B1ard6ym.js} +1 -1
  64. package/dist/assets/{history-DZsORyBG.js → history-BMhP0SFG.js} +1 -1
  65. package/dist/assets/{hostInit-D2EmEDvv.js → hostInit-FCvre9AW.js} +1 -1
  66. package/dist/assets/i18n-Vb3uBp7P.js +1 -0
  67. package/dist/assets/{icons-D5RaCH1q.js → icons-DocdgFuy.js} +1 -1
  68. package/dist/assets/index-DKqvG7BE.css +2 -0
  69. package/dist/assets/index-DvOECbab.js +4 -0
  70. package/dist/assets/{key-DLwSBrPM.js → key-B1M6i1mf.js} +1 -1
  71. package/dist/assets/{key-round-CYflkUyd.js → key-round-yCDTbIQb.js} +1 -1
  72. package/dist/assets/{layers-C1wzFfr1.js → layers-c960YTPf.js} +1 -1
  73. package/dist/assets/linked-devices-model-CB7qgVjI.js +1 -0
  74. package/dist/assets/{list-ordered-CFeS9o_w.js → list-ordered-C7hEwAd1.js} +1 -1
  75. package/dist/assets/location-owned-usage-D28vwYJT.js +1 -0
  76. package/dist/assets/{log-in-Be_RcxDr.js → log-in-DFfxcqYz.js} +1 -1
  77. package/dist/assets/{memory-stick-4BwYEagi.js → memory-stick-BBfIGrWx.js} +1 -1
  78. package/dist/assets/{message-square-plus-D7BNG3h7.js → message-square-plus-D8ZUT6rz.js} +1 -1
  79. package/dist/assets/{mf-entry-bootstrap-0-9df0d08c.js → mf-entry-bootstrap-0-3035e647.js} +2 -2
  80. package/dist/assets/{mic-off-e162Bcfu.js → mic-off-w2mFOBi3.js} +1 -1
  81. package/dist/assets/{monitor-off-CARYfHC4.js → monitor-off-DPi_gm_c.js} +1 -1
  82. package/dist/assets/{monitor-smartphone-lsNgnRRZ.js → monitor-smartphone-9Ife1Trw.js} +1 -1
  83. package/dist/assets/mount-C4w1vbly.js +1 -0
  84. package/dist/assets/notification-schedule-field-BuLfSYLZ.js +1 -0
  85. package/dist/assets/{octagon-alert-h80nyWRM.js → octagon-alert-C-jH7VH_.js} +1 -1
  86. package/dist/assets/player-overlays-D0U2dNvn.js +1 -0
  87. package/dist/assets/{recycle-0MLWppmT.js → recycle-Bbki65G2.js} +1 -1
  88. package/dist/assets/remoteEntry-DYVoozgD.js +1 -0
  89. package/dist/assets/{scan-eye-DVK8MF3K.js → scan-eye-AfIM_Dlr.js} +1 -1
  90. package/dist/assets/{scissors-Cz3GoeOd.js → scissors-CnL6g0BO.js} +1 -1
  91. package/dist/assets/{search-x-i_A-Upbe.js → search-x-eqJd3G8u.js} +1 -1
  92. package/dist/assets/{send-B5VKcNUH.js → send-B72RQ9UL.js} +1 -1
  93. package/dist/assets/{settings-2-ZQsYJ0Zb.js → settings-2-CXZ6DVRg.js} +1 -1
  94. package/dist/assets/{speaker-Cl8DZGk_.js → speaker-CcCWWecW.js} +1 -1
  95. package/dist/assets/src-CGxdJN_f.js +67 -0
  96. package/dist/assets/{timer-reset-A5ofAkBW.js → timer-reset-B9Lihcw9.js} +1 -1
  97. package/dist/assets/{ungroup-t0yDnzVf.js → ungroup-D753owNE.js} +1 -1
  98. package/dist/assets/{unlink-C1ZpCxl3.js → unlink-DzoLNfsq.js} +1 -1
  99. package/dist/assets/{usb-DmUPajSy.js → usb-CuSU-_EY.js} +1 -1
  100. package/dist/assets/{use-scenes-feed-BQlYhRMq.js → use-scenes-feed-CZjJNxfD.js} +1 -1
  101. package/dist/assets/{use-stationary-objects-BWM4vE0E.js → use-stationary-objects-BoGqWyLV.js} +1 -1
  102. package/dist/assets/useEventInvalidation-C4w1vbly.js +1 -0
  103. package/dist/assets/useNodeUrlSelection-BA6CgjTU.js +1 -0
  104. package/dist/assets/useTranslation-D3Is_4B6.js +1 -0
  105. package/dist/assets/user-round-CMg3Ndlt.js +1 -0
  106. package/dist/assets/{user-x-DRcPeM9C.js → user-x-PK8sSsso.js} +1 -1
  107. package/dist/assets/{video-tLHyNE3q.js → video-BBtESt54.js} +1 -1
  108. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DOOXjnRq.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BKfTL-9e.js} +2 -2
  109. package/dist/index.html +12 -12
  110. package/dist/server/addon.js +174 -5
  111. package/package.json +1 -1
  112. package/dist/assets/Addons-2xWF73cR.js +0 -4
  113. package/dist/assets/AdminSectionedPage-C3VHg80L.js +0 -1
  114. package/dist/assets/AiProfiles-DmHcVlS2.js +0 -3
  115. package/dist/assets/BrokerForm-Dqhjsi3Y.js +0 -1
  116. package/dist/assets/Build-CBYP1fT5.js +0 -40
  117. package/dist/assets/Calendars-C926x7b_.js +0 -1
  118. package/dist/assets/Cluster-OZlA14uV.js +0 -1
  119. package/dist/assets/ClusterStepModel-DHbwIGAW.js +0 -1
  120. package/dist/assets/CompositionEditor-vP3JcV2R.js +0 -1
  121. package/dist/assets/Data-7BoejvKA.js +0 -1
  122. package/dist/assets/DeviceDetail-ByM0856T.js +0 -2
  123. package/dist/assets/DeviceDoActionFields-BDJsvRNX.js +0 -1
  124. package/dist/assets/Devices-PIrWjfhq.js +0 -1
  125. package/dist/assets/Identity-C-tztwfa.js +0 -1
  126. package/dist/assets/IntegrationDetail-DugB7cv6.js +0 -1
  127. package/dist/assets/IntegrationHub-BePMbmC5.js +0 -1
  128. package/dist/assets/Integrations-Dj3nT9ZT.js +0 -1
  129. package/dist/assets/Integrations-OH5z-t03.js +0 -1
  130. package/dist/assets/Library-DDNti2te.js +0 -1
  131. package/dist/assets/Locations-OL9_NoSi.js +0 -3
  132. package/dist/assets/MaskShapeCanvas-Dcpby34M.js +0 -1
  133. package/dist/assets/MotionZonesSettings-CfTOerul.js +0 -1
  134. package/dist/assets/MyAccess-iJP3JQIS.js +0 -2
  135. package/dist/assets/Network-DYssxNiN.js +0 -1
  136. package/dist/assets/NodeAddonsSettingsPanel-mmtEgDbu.js +0 -1
  137. package/dist/assets/Notifications-DEcxFWp3.js +0 -1
  138. package/dist/assets/PrivacyMaskSettings-CJUKFEIs.js +0 -1
  139. package/dist/assets/Recordings-lygSYEJj.js +0 -1
  140. package/dist/assets/ScanNetworkModal-C2oJlLfj.js +0 -1
  141. package/dist/assets/SceneMonitorEditor-D1S-D2V9.js +0 -1
  142. package/dist/assets/SessionsList-CIN4GdSm.js +0 -2
  143. package/dist/assets/System-ChWpOOqN.js +0 -1
  144. package/dist/assets/_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CE2IIKhe.js +0 -1
  145. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js +0 -1
  146. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js +0 -1
  147. package/dist/assets/board-model-Bmts6hrg.js +0 -1
  148. package/dist/assets/circle-slash-D5mo-8G0.js +0 -1
  149. package/dist/assets/client-CMlUvfoK.js +0 -358
  150. package/dist/assets/crop-Dev61hIh.js +0 -1
  151. package/dist/assets/device-picker-model-DlnG_8P7.js +0 -1
  152. package/dist/assets/dist--5X8Gy0U.js +0 -1
  153. package/dist/assets/dist-Dod19ois.js +0 -358
  154. package/dist/assets/i18n-vggiB6gm.js +0 -1
  155. package/dist/assets/index-BgQGn3LX.js +0 -4
  156. package/dist/assets/index-BndCgmxf.css +0 -2
  157. package/dist/assets/linked-devices-model-CCTQ_gka.js +0 -1
  158. package/dist/assets/location-owned-usage-DSLiI6RY.js +0 -1
  159. package/dist/assets/mount-DlnG_8P7.js +0 -1
  160. package/dist/assets/notification-schedule-field-DWpT_5Vh.js +0 -1
  161. package/dist/assets/player-overlays-Cda8wso6.js +0 -1
  162. package/dist/assets/remoteEntry-V_83-NrI.js +0 -1
  163. package/dist/assets/src-eoSUZcV-.js +0 -67
  164. package/dist/assets/useEventInvalidation-DlnG_8P7.js +0 -1
  165. package/dist/assets/useNodeUrlSelection-CTxv9Em7.js +0 -1
  166. package/dist/assets/useTranslation-Bc5yH9V9.js +0 -1
  167. package/dist/assets/user-round-BTaID248.js +0 -1
@@ -5388,7 +5388,7 @@ var ZodIssueCode = {
5388
5388
  var ZodFirstPartyTypeKind;
5389
5389
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5390
5390
  //#endregion
5391
- //#region ../types/dist/sleep-DAX0-2v9.mjs
5391
+ //#region ../types/dist/sleep-DRqxtc0C.mjs
5392
5392
  /**
5393
5393
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5394
5394
  * window to float samples (D455).
@@ -8174,8 +8174,12 @@ method(object({ deviceId: number() }), array(StreamSourceEntrySchema)), method(o
8174
8174
  kind: "mutation",
8175
8175
  auth: "admin"
8176
8176
  }), method(object({ deviceId: number() }), unknown().nullable()), method(object({ deviceId: number() }), RawStateResultSchema.nullable(), { auth: "protected" });
8177
+ object({
8178
+ code: string().regex(/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/),
8179
+ params: record(string(), union([string(), number()])).optional()
8180
+ });
8177
8181
  //#endregion
8178
- //#region ../types/dist/err-msg-DX6i_MY4.mjs
8182
+ //#region ../types/dist/err-msg-DLerKiVO.mjs
8179
8183
  var DeviceType = /* @__PURE__ */ function(DeviceType) {
8180
8184
  DeviceType["Camera"] = "camera";
8181
8185
  DeviceType["Hub"] = "hub";
@@ -8425,6 +8429,22 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
8425
8429
  DeviceRole["Nightvision"] = "nightvision";
8426
8430
  DeviceRole["PrivacyMask"] = "privacy-mask";
8427
8431
  DeviceRole["Doorbell"] = "doorbell";
8432
+ /** Interior blind / shade / roller blind. HA `device_class: blind|shade`. */
8433
+ DeviceRole["CoverBlind"] = "cover-blind";
8434
+ /** Exterior roller shutter. HA `device_class: shutter`; Homematic BROLL. */
8435
+ DeviceRole["CoverShutter"] = "cover-shutter";
8436
+ /** Exterior awning. HA `device_class: awning`. */
8437
+ DeviceRole["CoverAwning"] = "cover-awning";
8438
+ /** Curtain / drape. HA `device_class: curtain`. */
8439
+ DeviceRole["CoverCurtain"] = "cover-curtain";
8440
+ /** Garage door. HA `device_class: garage`. A security actuator: exports gate it. */
8441
+ DeviceRole["CoverGarage"] = "cover-garage";
8442
+ /** Gate. HA `device_class: gate`. A security actuator: exports gate it. */
8443
+ DeviceRole["CoverGate"] = "cover-gate";
8444
+ /** Door. HA `device_class: door`. A security actuator: exports gate it. */
8445
+ DeviceRole["CoverDoor"] = "cover-door";
8446
+ /** Window. HA `device_class: window`. */
8447
+ DeviceRole["CoverWindow"] = "cover-window";
8428
8448
  /** Virtual HA toggle (input_boolean.*) — distinguishable from a
8429
8449
  * real Switch device for UI rendering / export adapters. */
8430
8450
  DeviceRole["BinaryHelper"] = "binary-helper";
@@ -8495,7 +8515,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
8495
8515
  return DeviceRole;
8496
8516
  }({});
8497
8517
  //#endregion
8498
- //#region ../types/dist/composition-C-WpVYTX.mjs
8518
+ //#region ../types/dist/composition-EQ9Ok0Ee.mjs
8499
8519
  /**
8500
8520
  * The ffmpeg build every CamStack node downloads, per platform and arch.
8501
8521
  *
@@ -12172,7 +12192,8 @@ var ConvertResultSchema = object({
12172
12192
  })).readonly()
12173
12193
  });
12174
12194
  _enum(["new-session", "step-up"]);
12175
- _enum(["en", "it"]);
12195
+ /** The languages the hub's app landing pages are written in (D858). */
12196
+ var AppPageLangSchema = _enum(["en", "it"]);
12176
12197
  /** How a native app starts one login method (D858), as `auth.listLoginMethods` reports it. */
12177
12198
  var AppLoginPathSchema = discriminatedUnion("kind", [object({ kind: literal("native") }), object({
12178
12199
  kind: literal("browser"),
@@ -12669,7 +12690,9 @@ var ConfigTabDeclarationSchema = object({
12669
12690
  var ConfigSectionWithValuesSchema = object({
12670
12691
  id: string(),
12671
12692
  title: string(),
12693
+ titleKey: string().optional(),
12672
12694
  description: string().optional(),
12695
+ descriptionKey: string().optional(),
12673
12696
  style: _enum(["card", "accordion"]).optional(),
12674
12697
  defaultCollapsed: boolean().optional(),
12675
12698
  columns: union([
@@ -15895,6 +15918,9 @@ method(object({
15895
15918
  }), method(object({ refs: RefListSchema }), KeychainResolveResultSchema, { auth: "admin" }), method(object({ refs: RefListSchema }), object({ deleted: number().int() }), {
15896
15919
  kind: "mutation",
15897
15920
  auth: "admin"
15921
+ }), method(object({ deviceId: number().int() }), object({ refs: array(string()).readonly() }), {
15922
+ kind: "mutation",
15923
+ auth: "admin"
15898
15924
  }), method(object({}), array(KeychainSecretMetaSchema).readonly(), { auth: "admin" }), method(object({}), KeychainStateSchema, { auth: "admin" });
15899
15925
  /**
15900
15926
  * device-history — the ONE mechanism for numeric history (D850).
@@ -37298,6 +37324,38 @@ var DeviceRegisterPayloadSchema = object({
37298
37324
  * omits it and the keyword backstop applies. */
37299
37325
  secretConfigPaths: array(string()).optional()
37300
37326
  });
37327
+ /** One deleted device, kept by device-manager so an addon that missed the
37328
+ * deletion can still learn of it (D865). Written by the delete path ONLY. */
37329
+ var DeviceTombstoneSchema = object({
37330
+ deviceId: number().int().positive(),
37331
+ /** Epoch ms the device was deleted. */
37332
+ deletedAt: number(),
37333
+ /** The addon that owned the device when it was deleted. */
37334
+ providerAddonId: string()
37335
+ });
37336
+ /** Data held for one device that device-manager no longer knows. */
37337
+ var OrphanDeviceDataSchema = object({
37338
+ deviceId: number().int().positive(),
37339
+ /** Rows/files per store (`<addonId>:<store>`). */
37340
+ stores: record(string(), number().int().nonnegative())
37341
+ });
37342
+ var CleanupDeletedDevicesResultSchema = object({
37343
+ /**
37344
+ * `skipped` — the absence check could not be trusted (a device-list read
37345
+ * failed or the two reads disagreed); nothing was listed or deleted.
37346
+ * `dry-run` — `devices` is what a confirmed run would delete.
37347
+ * `cleaned` — `devices` is what was deleted.
37348
+ */
37349
+ status: _enum([
37350
+ "skipped",
37351
+ "dry-run",
37352
+ "cleaned"
37353
+ ]),
37354
+ reason: string().nullable(),
37355
+ devices: array(OrphanDeviceDataSchema),
37356
+ /** Implementers that could not be asked (their stores are not in `devices`). */
37357
+ unreachable: array(string())
37358
+ });
37301
37359
  var DeviceRemovePayloadSchema = object({ deviceId: number() });
37302
37360
  var DevicePersistConfigPayloadSchema = object({
37303
37361
  deviceId: number(),
@@ -37536,6 +37594,9 @@ method(object({
37536
37594
  }), method(object({ deviceId: number() }), object({ success: literal(true) }), {
37537
37595
  kind: "mutation",
37538
37596
  auth: "admin"
37597
+ }), method(object({ sinceMs: number() }), array(DeviceTombstoneSchema).readonly(), { auth: "admin" }), method(object({ confirm: boolean() }), CleanupDeletedDevicesResultSchema, {
37598
+ kind: "mutation",
37599
+ auth: "admin"
37539
37600
  }), method(object({ integrationId: string() }), object({ removed: number() }), {
37540
37601
  kind: "mutation",
37541
37602
  auth: "admin"
@@ -37998,6 +38059,72 @@ method(object({
37998
38059
  auth: "admin"
37999
38060
  });
38000
38061
  /**
38062
+ * `device-removal-hook` — the reliable way an addon learns a device was DELETED,
38063
+ * so it can delete what it keeps for that device (D865).
38064
+ *
38065
+ * ## Why an event was not enough
38066
+ *
38067
+ * `DeviceUnregistered` is telemetry and may be dropped (D8, D11). An addon that
38068
+ * hung its per-device clean-up on it left durable garbage whenever the event was
38069
+ * lost, the addon was down, or it was restarting at that moment — footage,
38070
+ * analytics rows and settings of device 4483 outlived the device. Loss of this
38071
+ * signal corrupts durable state, so it travels by RPC with a recorded fact
38072
+ * behind it (D8: "if loss would corrupt durable state, use RPC plus a reconcile").
38073
+ *
38074
+ * ## The three pieces
38075
+ *
38076
+ * 1. device-manager records a TOMBSTONE per deleted device
38077
+ * (`deviceManager.listDeletedSince`). The tombstone is written by the delete
38078
+ * path only — a device that is unregistered, offline or whose provider is
38079
+ * restarting is NOT deleted and gets none.
38080
+ * 2. After a delete, device-manager calls `onDeviceRemoved` on EVERY provider of
38081
+ * this collection, one by one, with bounded retries, logged.
38082
+ * 3. An implementer that was down asks `deviceManager.listDeletedSince` at start
38083
+ * (and periodically) and runs its own `onDeviceRemoved` for each tombstone it
38084
+ * may have missed. Reconcile is driven by tombstones, never by "the device is
38085
+ * not in the current list": a failed or partial list read must not destroy data.
38086
+ *
38087
+ * ## Contract for an implementer
38088
+ *
38089
+ * - **Idempotent.** It is called again by a retry, by a reconcile and by the
38090
+ * admin cleanup of data that predates tombstones. A device with nothing left
38091
+ * answers zero counts.
38092
+ * - **One key per store** in `counts`, deleted rows/files per store, so the log
38093
+ * line and the admin dry run can say where the data was.
38094
+ * - **Training datasets are NOT device data** and are never deleted by a hook.
38095
+ * - **Per-device SETTINGS are not hooked.** Configuration lives in the standard
38096
+ * per-device store (`ctx.settings.*DeviceStore`), which device-manager clears
38097
+ * for every addon centrally at delete time. This hook is for device DATA
38098
+ * that is not settings: footage, event media, analytics rows, history.
38099
+ * - A provider that cannot tell is allowed to throw; the caller retries it.
38100
+ *
38101
+ * `listDeviceData` is the read side of the admin "Clean data of deleted devices"
38102
+ * action: which device ids this addon holds data for, and how much per store. It
38103
+ * never deletes. device-manager decides which of those ids are absent from the
38104
+ * fleet, from TWO consistent reads of the device list (D49).
38105
+ */
38106
+ /** What a hook is told about the deletion. */
38107
+ var DeviceRemovedInputSchema = object({
38108
+ deviceId: number().int().positive(),
38109
+ /** Epoch ms the device was deleted (the tombstone's `deletedAt`). */
38110
+ deletedAt: number(),
38111
+ /** The addon that owned the device, as device-manager last knew it. */
38112
+ providerAddonId: string()
38113
+ });
38114
+ /** Rows/files/refs deleted, per store this implementer owns. */
38115
+ var DeviceRemovedResultSchema = object({ counts: record(string(), number().int().nonnegative()) });
38116
+ /** One (store, device) pair an implementer holds data for. */
38117
+ var DeviceDataEntrySchema = object({
38118
+ store: string(),
38119
+ deviceId: number().int().positive(),
38120
+ /** Rows (or files) held for the device in the store. */
38121
+ count: number().int().nonnegative()
38122
+ });
38123
+ method(DeviceRemovedInputSchema, DeviceRemovedResultSchema, {
38124
+ kind: "mutation",
38125
+ auth: "admin"
38126
+ }), method(_void(), array(DeviceDataEntrySchema).readonly(), { auth: "admin" });
38127
+ /**
38001
38128
  * `failure-contribution` — the capability an addon reports its OWN losses
38002
38129
  * through, per camera, with the denominator attached. It stores nothing.
38003
38130
  *
@@ -62497,6 +62624,12 @@ Object.freeze({
62497
62624
  addonId: null,
62498
62625
  access: "create"
62499
62626
  },
62627
+ "deviceManager.cleanupDeletedDevicesData": {
62628
+ capName: "device-manager",
62629
+ capScope: "system",
62630
+ addonId: null,
62631
+ access: "create"
62632
+ },
62500
62633
  "deviceManager.createDevice": {
62501
62634
  capName: "device-manager",
62502
62635
  capScope: "system",
@@ -62677,6 +62810,12 @@ Object.freeze({
62677
62810
  addonId: null,
62678
62811
  access: "view"
62679
62812
  },
62813
+ "deviceManager.listDeletedSince": {
62814
+ capName: "device-manager",
62815
+ capScope: "system",
62816
+ addonId: null,
62817
+ access: "view"
62818
+ },
62680
62819
  "deviceManager.listDeviceIdsByCaps": {
62681
62820
  capName: "device-manager",
62682
62821
  capScope: "system",
@@ -63085,6 +63224,18 @@ Object.freeze({
63085
63224
  addonId: null,
63086
63225
  access: "create"
63087
63226
  },
63227
+ "deviceRemovalHook.listDeviceData": {
63228
+ capName: "device-removal-hook",
63229
+ capScope: "system",
63230
+ addonId: null,
63231
+ access: "view"
63232
+ },
63233
+ "deviceRemovalHook.onDeviceRemoved": {
63234
+ capName: "device-removal-hook",
63235
+ capScope: "system",
63236
+ addonId: null,
63237
+ access: "create"
63238
+ },
63088
63239
  "deviceState.claimFields": {
63089
63240
  capName: "device-state",
63090
63241
  capScope: "system",
@@ -63517,6 +63668,12 @@ Object.freeze({
63517
63668
  addonId: null,
63518
63669
  access: "delete"
63519
63670
  },
63671
+ "keychain.deleteDeviceScope": {
63672
+ capName: "keychain",
63673
+ capScope: "system",
63674
+ addonId: null,
63675
+ access: "delete"
63676
+ },
63520
63677
  "keychain.getState": {
63521
63678
  capName: "keychain",
63522
63679
  capScope: "system",
@@ -69529,6 +69686,11 @@ Object.freeze({
69529
69686
  form: "single",
69530
69687
  optional: false
69531
69688
  }],
69689
+ "deviceRemovalHook.onDeviceRemoved": [{
69690
+ name: "deviceId",
69691
+ form: "single",
69692
+ optional: false
69693
+ }],
69532
69694
  "deviceState.claimFields": [{
69533
69695
  name: "deviceId",
69534
69696
  form: "single",
@@ -69718,6 +69880,11 @@ Object.freeze({
69718
69880
  form: "single",
69719
69881
  optional: false
69720
69882
  }],
69883
+ "keychain.deleteDeviceScope": [{
69884
+ name: "deviceId",
69885
+ form: "single",
69886
+ optional: false
69887
+ }],
69721
69888
  "lawnMowerControl.dock": [{
69722
69889
  name: "deviceId",
69723
69890
  form: "single",
@@ -72066,6 +72233,8 @@ new Set([
72066
72233
  "audio-tools",
72067
72234
  "audio-silence"
72068
72235
  ]);
72236
+ AppPageLangSchema.options;
72237
+ record(string().min(1), string());
72069
72238
  /**
72070
72239
  * TimelapseRule — the STANDALONE scheduled timelapse producer's rule model.
72071
72240
  *
@@ -72499,7 +72668,7 @@ var AdminUIAddon = class extends BaseAddon {
72499
72668
  capability: adminUiCapability,
72500
72669
  provider: {
72501
72670
  getStaticDir: async () => ({ staticDir: resolveAdminUiDistDir() }),
72502
- getVersion: async () => ({ version: "1.2.428" })
72671
+ getVersion: async () => ({ version: "1.2.429" })
72503
72672
  }
72504
72673
  }];
72505
72674
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.428",
3
+ "version": "1.2.429",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Admin UI — Vite frontend build and server-side addon",
@@ -1,4 +0,0 @@
1
- import{I as e,K as t,Q as n,R as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Hr as d,It as f,Ln as p,Nt as m,On as h,Ot as g,Q as _,ar as v,bi as y,di as b,dn as x,dt as S,en as C,fn as w,gi as ee,ln as T,ri as E,wn as te,yi as ne,yn as D}from"./player-overlays-Cda8wso6.js";import{c as O}from"./video-tLHyNE3q.js";import{t as re}from"./octagon-alert-h80nyWRM.js";import{Ti as ie}from"./client-CMlUvfoK.js";import{An as ae,Ar as k,Bn as oe,Br as se,Cr as ce,Dn as le,En as ue,Er as A,Fr as de,Ir as fe,Lr as pe,Mr as j,Or as M,Pr as me,Q as N,Sr as P,Tn as he,Tr as ge,Tt as F,U as I,Vr as L,Xn as _e,Xo as R,Zl as z,Zn as ve,ar as B,br as V,fu as H,hu as ye,jn as U,jr as W,kn as be,kr as G,vr as xe,wr as Se,wt as Ce,xr as K,zr as q}from"./src-eoSUZcV-.js";import{t as J}from"./useTranslation-Bc5yH9V9.js";import"./mount-DlnG_8P7.js";import{Q as we,X as Y}from"./index-BgQGn3LX.js";import{t as X}from"./AdminPage-DuuyDIsY.js";import{t as Z}from"./NodeAddonsSettingsPanel-mmtEgDbu.js";import{n as Q,t as Te}from"./useNodeUrlSelection-CTxv9Em7.js";n();var Ee={queued:{icon:E,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:v,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:D,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:y,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:re,bg:`bg-danger/10 text-danger`,label:`failed`}};function De({item:e}){let t=Ee[e.status],n=t.icon;return i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}var Oe=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),ke=new Set([`done`,`failed`,`skipped`]);function Ae(e){return!ke.has(e.phase)&&!Oe.has(e.jobState)}function je(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Oe.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function Me(){let{data:e}=G({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=ye(ie.AddonsJobProgress,e=>e.job.jobId);return a(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return je([...n.values()],Date.now())},[e,t])}var Ne={queued:{icon:E,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:v,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:v,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:v,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:v,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:v,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:v,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:y,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:re,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:C,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function Pe({progress:e}){let t=Ne[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return i(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[l(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,i(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function Fe(e,t){return e.filter(e=>e.packageName===t).slice().sort((e,t)=>e.isHub===t.isHub?e.nodeName.localeCompare(t.nodeName):e.isHub?-1:1)}function Ie(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function Le(e,t,n){let r=[`${e} will be uninstalled from ${t.length} node(s). Its runners stop, its capabilities are deregistered and its code is deleted:`,...t.map(Ie)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
2
- `)}function Re(e,t,n){let r=[`${e} will be uninstalled from ${t}: its runners stop and its code is deleted.`];return n.length>0&&r.push(`It stays installed on: ${n.map(e=>e.nodeName).join(`, `)}. Use "Everywhere" to remove it from every node.`),r.push(`This cannot be undone.`),r.join(`
3
- `)}var ze={uninstalled:`uninstalled`,"not-installed":`was not installed`,refused:`REFUSED`,failed:`FAILED`,"pending-reconnect":`offline — removed when it reconnects`};function Be(e,t){let n=[];for(let r of e.results){let e=r.runnersStopped.length>0?` (stopped ${r.runnersStopped.join(`, `)})`:``;n.push(`${t(r.nodeId)}: ${ze[r.outcome]}${e}`),r.error!==void 0&&n.push(` ${r.error}`);for(let e of r.warnings)n.push(` ${e}`)}return n.join(`
4
- `)}var Ve={},He=3e4,Ue=`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`;function We({packageName:e,displayName:t,selectedNode:n,hideNodeAction:r,disabled:a}){let{t:o}=J(),c=s(),u=ve(),d=_e(),p=M(Ve,{staleTime:He}),m=p.data?.installations??[],h=(p.data?.unreachable??[]).map(e=>e.nodeId),g=Fe(m,e),_=e=>g.find(t=>t.nodeId===e)?.nodeName??(e===n.id?n.name:e),v=se({onSettled:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`nodes`]]})}}),y=async e=>{await d({title:e.success?o(`addons.addonUninstallControls.uninstalled`,`{{displayName}} uninstalled`,{displayName:t}):o(`addons.addonUninstallControls.notEveryNodeWasCleaned`,`{{displayName}}: not every node was cleaned`,{displayName:t}),message:Be(e,_),variant:e.success?`default`:`danger`})},b=async n=>{try{await y(await v.mutateAsync({packageName:e,...n}))}catch(e){await d({title:o(`addons.addonUninstallControls.uninstallFailed`,`Uninstall {{displayName}} failed`,{displayName:t}),message:e instanceof Error?e.message:String(e),variant:`danger`})}},x=async()=>{let e=g.filter(e=>e.nodeId!==n.id);await u({title:o(`addons.addonUninstallControls.uninstallFrom`,`Uninstall {{displayName}} from {{name}}?`,{displayName:t,name:n.name}),message:Re(t,n.name,e),confirmLabel:o(`addons.addonUninstallControls.uninstall`,`Uninstall`),variant:`danger`})&&await b(n.isHub?{}:{nodeId:n.id})},S=async()=>{let n=(await p.refetch()).data;if(n===void 0){await d({title:o(`addons.addonUninstallControls.cannotListTheNodes`,`Cannot list the nodes`),message:o(`addons.addonUninstallControls.theHubDidNotAnswer`,`The hub did not answer which nodes have this package — nothing was removed.`),variant:`danger`});return}let r=Fe(n.installations,e);await u({title:o(`addons.addonUninstallControls.uninstallEverywhere`,`Uninstall {{displayName}} everywhere?`,{displayName:t}),message:Le(t,r,n.unreachable.map(e=>e.nodeId)),confirmLabel:o(`addons.addonUninstallControls.uninstallFromNodeS`,`Uninstall from {{length}} node(s)`,{length:r.length}),variant:`danger`})&&await b({everywhere:!0})},C=v.isPending||a===!0;return i(`div`,{className:`flex items-center gap-1.5`,children:[r!==!0&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),x()},disabled:C,className:Ue,title:o(`addons.addonUninstallControls.uninstallFrom2`,`Uninstall from {{name}}`,{name:n.name}),children:[l(f,{className:`h-3 w-3`}),v.isPending?o(`addons.addonUninstallControls.removing`,`Removing...`):o(`addons.addonUninstallControls.uninstall`,`Uninstall`)]}),(g.length>1||r===!0||h.length>0)&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S()},disabled:C,className:Ue,title:o(`addons.addonUninstallControls.uninstallFromEveryNodeThat`,`Uninstall from every node that has it`),children:[l(O,{className:`h-3 w-3`}),`Everywhere`,g.length>0?` (${g.length})`:``]})]})}function Ge({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:a,onSelect:s,selectedVersion:c}){let{t:u}=J(),f=n===`upload`||n===`local`,{data:p,isLoading:m}=Se({name:e});return i(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[i(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:u(`addons.versionPicker.versions`,`Versions`)}),l(`button`,{type:`button`,onClick:a,className:`text-foreground-subtle hover:text-foreground`,children:l(S,{className:`h-3 w-3`})})]}),f&&i(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[l(g,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),i(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[i(`span`,{className:`font-semibold`,children:[n===`upload`?u(`addons.versionPicker.uploadedCopy`,`Uploaded copy`):u(`addons.versionPicker.localCopy`,`Local copy`),` `,`in place.`]}),` `,`Re-install `,l(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),m&&i(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[l(v,{className:`h-3.5 w-3.5 animate-spin`}),u(`addons.versionPicker.loadingVersions`,`Loading versions...`)]}),p&&l(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:p.map(e=>{let n=e.version===t,a=s!==void 0&&e.version===c,f=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),p=i(o,{children:[l(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:f?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&l(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),l(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return s?i(`button`,{type:`button`,"aria-label":u(`addons.versionPicker.select`,`Select {{version}}`,{version:e.version}),onClick:()=>s(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${a?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[p,a?l(y,{className:`h-3 w-3 text-primary shrink-0`}):l(`span`,{className:`w-3 shrink-0`})]},e.version):i(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[p,l(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?u(`addons.versionPicker.reInstallFromNpm`,`Re-install {{version}} from npm`,{version:e.version}):u(`addons.versionPicker.install`,`Install {{version}}`,{version:e.version}),children:l(d,{className:`h-3 w-3`})})]},e.version)})}),p&&p.length===0&&l(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:u(`addons.versionPicker.noVersionsFound`,`No versions found`)})]})}n();var Ke=`device-export`;function qe(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===Ke)}function Je(e){return e!==`local`&&e!==`upload`}function Ye({isBundle:e,installSource:t,addonId:n,iconPath:r,color:a}){let[o,s]=c(!1),u=a?{backgroundColor:`${a.startsWith(`#`)?a:`#${a}`}26`}:void 0,d=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,f=n&&r?_(`/api/addon-assets/${n}/${r}`):null,m=!!f&&!o;return i(`div`,{className:`relative flex-shrink-0`,children:[l(`div`,{className:`h-8 w-8 rounded-md flex items-center justify-center ${u?``:d}`,style:u,children:m?l(`img`,{src:f,alt:n,className:`h-4 w-4`,onError:()=>s(!0)}):l(e?p:te,{className:`h-3.5 w-3.5`})}),t===`local`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),Je(t)&&l(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:l(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:l(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&l(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:l(g,{className:`h-2.5 w-2.5 text-white`})})]})}function Xe({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:a,disabled:o,onUpdate:s,onOpenPicker:c,children:u}){let{t:f}=J();if(r)return i(`span`,{className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[l(v,{className:`h-3 w-3 animate-spin`}),f(`addons.addonCard.updating`,`Updating…`)]});if(t){let r=n??t;return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[s&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:o,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:f(`addons.addonCard.updateTo`,`Update to {{target}}`,{target:r}),children:[l(d,{className:`h-3 w-3`}),f(`addons.addonCard.update`,`Update`)]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,"aria-label":f(`addons.addonCard.selectVersionToInstall`,`Select version to install`),title:f(`addons.addonCard.installedUpdateAvailableSelectedTap`,`Installed {{version}} — update available. Selected {{target}}; tap to choose another version.`,{version:e,target:r}),className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[l(`span`,{className:`font-normal opacity-70`,children:e}),l(`span`,{className:`font-normal opacity-70`,children:`→`}),r,l(ne,{className:`h-3 w-3`})]}),u]})}return i(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:o,className:[`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,a===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:f(`addons.addonCard.versionTapToViewAll`,`Version {{version}} — tap to view all versions`,{version:e}),children:[e,l(ne,{className:`h-3 w-3 opacity-50`})]}),u]})}function Ze({addonId:e}){let t=s(),{data:n=`inherit`}=K({addonId:e}),r=fe({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return l(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>l(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}var Qe={id:`hub`,name:`Hub`,isHub:!0};function $e({addon:e,agents:t=[],clusterStatus:n,hideVersion:r,availableUpdate:a,onUpdate:d,isUpdating:f,jobProgress:m,bundle:g,bulkItem:_,disabledByBulk:v,isSystem:y,selectedNode:b}){let{t:x}=J(),[C,E]=c(!1),[te,O]=c(!1),[ie,k]=c(!1),[se,ce]=c(null);u(()=>{ce(null)},[a]);let A=se??a,[de,fe]=c(!1),[pe,M]=c(!1),[P,I]=c(`logs`),L=s(),_e=Y(),{manifest:R}=e,z=e.installedOn??[],ve=!g&&!R.protected&&R.removable!==!1,B=!!g,V=g?.displayName??R.name,H=g?.packageName??R.packageName,ye=g?.version??R.packageVersion??R.version,W=g?.installSource??e.installSource,G=g?g.bundle?.description??g.addons[0]?.manifest.description:R.description,xe=j({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]})}}),Se=ge({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]}),L.invalidateQueries({queryKey:[[`addonPages`]]}),L.invalidateQueries({queryKey:[[`capabilities`]]}),L.invalidateQueries({queryKey:[[`integrations`]]})}}),K=me({onSuccess:()=>{L.invalidateQueries({queryKey:[[`addons`]]}),L.invalidateQueries({queryKey:[[`alerts`]]})}}),q=e.health,we=q?.phase===`failed`&&!q.inGracePeriod,X=we&&q?.nextRetryAt&&!q.retrying;return i(`div`,{className:`rounded-md border bg-surface overflow-hidden ${we?`border-red-500/50`:`border-border`}`,children:[we&&q&&i(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[l(re,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,q.retryCount,`)`]}),l(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:q.lastError?.message??x(`addons.addonCard.unknownError`,`Unknown error`)}),X&&q.nextRetryAt&&i(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(q.nextRetryAt).toLocaleTimeString()]})]}),i(`button`,{type:`button`,disabled:K.isPending||q.retrying,onClick:e=>{e.stopPropagation(),K.mutate({packageName:H})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:x(`addons.addonCard.resetRetryCounterAndForce`,`Reset retry counter and force immediate reload`),children:[l(D,{className:`h-3 w-3 ${K.isPending||q.retrying?`animate-spin`:``}`}),x(`addons.addonCard.retryNow`,`Retry now`)]})]}),i(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[l(Ye,{isBundle:B||!!R.components&&R.components.length>1,installSource:W,addonId:B?g.addons[0]?.manifest.id:R.id,iconPath:B?g.bundle?.icon??g.addons[0]?.manifest.icon:R.icon,color:B?g.addons[0]?.manifest.color:R.color}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-start justify-between gap-2`,children:[l(`span`,{className:`text-xs font-semibold text-foreground truncate min-w-0`,children:V}),!r&&l(Xe,{version:ye,availableUpdate:a,...A===void 0?{}:{selectedVersion:A},isUpdating:f,installSource:W,disabled:v,...d&&A!==void 0?{onUpdate:()=>d(A)}:{},onOpenPicker:()=>k(e=>!e),children:ie&&l(Ge,{packageName:H,currentVersion:ye,...W?{installSource:W}:{},...a!==void 0&&A!==void 0?{selectedVersion:A,onSelect:e=>{ce(e),k(!1)}}:{},onInstall:e=>{k(!1),Se.mutate({packageName:H,version:e})},onClose:()=>k(!1)})})]}),i(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[H!==V&&l(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:H}),B&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[l(p,{className:`h-3 w-3`}),g.addons.length]}),y&&i(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:x(`addons.addonCard.systemPackageUpdatingRestartsThe`,`System package — updating restarts the hub`),children:[l(D,{className:`h-3 w-3`}),x(`addons.addonCard.system`,`System`)]}),_!=null&&l(De,{item:_}),m!=null&&l(Pe,{progress:m})]}),G&&l(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:G}),!B&&e.process&&i(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&i(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),l(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!B&&i(`div`,{className:`flex items-center gap-1 px-3 py-1 border-t border-border/50 bg-surface-hover/20`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),xe.mutate({addonId:R.id})},disabled:xe.isPending||v,className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[l(D,{className:`h-3 w-3 ${xe.isPending?`animate-spin`:``}`}),x(`addons.addonCard.restart`,`Restart`)]}),i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),fe(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${de?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(w,{className:`h-3 w-3`}),x(`addons.addonCard.logs`,`Logs`)]}),!B&&i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),M(!0)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${pe?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[l(T,{className:`h-3 w-3`}),x(`addons.addonCard.settings`,`Settings`)]}),l(`div`,{className:`flex-1`}),ve&&l(We,{packageName:R.packageName,displayName:R.name,selectedNode:b??Qe,disabled:v})]}),n&&n.nodes.length>1&&!B&&i(`div`,{className:`border-t border-border px-3 py-1.5 bg-muted/10`,children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:x(`addons.addonCard.clusterDeployment`,`Cluster Deployment`)}),l(`div`,{className:`space-y-1`,children:n.nodes.map(e=>i(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),l(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),l(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&l(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),de&&!B&&i(`div`,{className:`border-t border-border`,children:[i(`div`,{className:`flex items-center px-3 py-0.5 bg-surface-hover/20 border-b border-border/50`,children:[i(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[l(`button`,{type:`button`,onClick:()=>I(`logs`),className:`px-2 py-0.5 transition-colors ${P===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:x(`addons.addonCard.logs`,`Logs`)}),l(`button`,{type:`button`,onClick:()=>I(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${P===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:x(`addons.addonCard.events`,`Events`)})]}),l(`div`,{className:`flex-1`}),l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),fe(!1)},className:`text-foreground-subtle hover:text-foreground`,children:l(S,{className:`h-3.5 w-3.5`})})]}),P===`logs`&&l(F,{addonId:R.id,maxHeight:`max-h-64`,showFilters:!1}),P===`events`&&l(Ce,{addonId:R.id,category:`addon.*`,maxHeight:`max-h-64`})]}),B&&i(o,{children:[l(`button`,{type:`button`,onClick:()=>E(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:l(C?ee:ne,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),C&&l(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:g.addons.map(e=>l($e,{addon:e,agents:t,hideVersion:!0},e.manifest.id))})]}),pe&&!B&&l(he,{open:!0,onOpenChange:e=>!e&&M(!1),children:i(le,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[l(ae,{children:i(U,{className:`flex items-center gap-2`,children:[l(T,{className:`h-4 w-4 text-primary`}),V,` Settings`]})}),i(ue,{className:`space-y-4`,children:[l(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:x(`addons.addonCard.clusterWideSettingsOneValue`,`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`)}),l(Z,{nodeId:null,addonIds:[R.id],level:`global`,fieldScope:`cluster`,emptyMessage:x(`addons.addonCard.thisAddonExposesNoCluster`,`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`)}),qe(R)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:x(`addons.addonCard.deviceExport`,`Device export`)}),l(N,{addonId:R.id,onOpenDevice:e=>_e(`/devices/${e}`)})]}),Je(W)&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:x(`addons.addonCard.autoUpdate`,`Auto-Update`)}),l(Ze,{addonId:R.id})]}),R.components&&R.components.length>0&&i(`div`,{children:[i(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,R.components.length,`)`]}),l(`div`,{className:`flex flex-wrap gap-1`,children:R.components.map(e=>l(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),t.length>=2&&i(`div`,{children:[l(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:x(`addons.addonCard.installedOn`,`Installed on`)}),i(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[z.length===0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:x(`addons.addonCard.hubLocal`,`Hub (local)`)}),z.map(e=>l(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),i(`div`,{className:`relative`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),O(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:x(`addons.addonCard.installOnMoreAgents`,`Install on more agents`),children:[l(h,{className:`h-3 w-3`}),x(`addons.addonCard.addAgent`,`Add agent`)]}),te&&i(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[t.filter(e=>!e.isHub&&!z.includes(e.name)).map(e=>l(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),O(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),t.filter(e=>!e.isHub&&!z.includes(e.name)).length===0&&l(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:x(`addons.addonCard.noAvailableAgents`,`No available agents`)})]})]})]})]})]}),l(be,{children:l(oe,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>M(!1),children:x(`common.close`,`Close`)})})]})})]})}n();var et=`.tgz,.tar.gz,.zip`;function tt({onUploadSuccess:n}){let{t:r}=J(),[a,s]=c(!1),u=t(null),d=e(async e=>{s(!0);let t=new FormData;t.append(`file`,e);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(_(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:t})).json()).success&&n()}finally{s(!1)}},[n]);return i(o,{children:[l(`input`,{ref:u,type:`file`,accept:et,onChange:e(e=>{let t=e.target.files?.[0];t&&d(t),e.target.value=``},[d]),className:`hidden`}),i(`button`,{type:`button`,onClick:()=>u.current?.click(),disabled:a,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[a?l(v,{className:`w-3.5 h-3.5 animate-spin`}):l(g,{className:`w-3.5 h-3.5`}),a?r(`addons.addonUploadZone.uploading`,`Uploading...`):r(`addons.addonUploadZone.upload`,`Upload`)]})]})}var nt=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/ui-library`,`@camstack/addon-agent-ui`]);function rt(e,t){let n=new Map;for(let r of e){if(r.isHub||r.onHub||nt.has(r.packageName)||!t.isHub&&r.nodeId!==t.id)continue;let e=n.get(r.packageName)??[];e.push(r),n.set(r.packageName,e)}return[...n].map(([e,t])=>({packageName:e,rows:t})).sort((e,t)=>e.packageName.localeCompare(t.packageName))}function it({selectedNode:e}){let{t}=J(),{data:n}=M(Ve,{staleTime:He});if(n===void 0)return null;let r=rt(n.installations,e),a=n.unreachable.filter(t=>e.isHub||t.nodeId===e.id);return r.length===0&&a.length===0?null:i(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2.5 space-y-2`,children:[i(`div`,{className:`flex items-center gap-2 text-[11px] font-semibold text-foreground`,children:[l(m,{className:`h-3.5 w-3.5 text-warning`}),e.isHub?t(`addons.nodeOnlyPackagesPanel.installedOnAgentsButNot`,`Installed on agents but not on the hub`):t(`addons.nodeOnlyPackagesPanel.installedOnButNotOn`,`Installed on {{name}} but not on the hub`,{name:e.name})]}),a.length>0&&i(`div`,{className:`text-[10px] text-foreground-subtle`,children:[`Could not ask `,a.map(e=>e.nodeId).join(`, `),` — its packages are not listed.`]}),r.map(t=>i(`div`,{className:`flex items-center justify-between gap-3 flex-wrap rounded-md border border-border bg-surface px-3 py-2`,children:[i(`div`,{className:`min-w-0`,children:[l(`div`,{className:`text-xs font-mono text-foreground break-all`,children:t.packageName}),l(`div`,{className:`text-[10px] text-foreground-subtle`,children:t.rows.map(e=>`${e.nodeName}${e.version===null?``:` ${e.version}`}${e.isOnline?``:` (offline)`}`).join(` · `)})]}),l(We,{packageName:t.packageName,displayName:t.packageName,selectedNode:e,hideNodeAction:e.isHub})]},t.packageName))]})}function at({addon:e,installing:t,onInstall:n}){let{t:r}=J();return i(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[l(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),i(`div`,{className:`flex-1 min-w-0`,children:[i(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[l(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),l(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&l(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?l(B,{variant:`success`,icon:l(y,{className:`h-3 w-3`}),children:e.installedVersion??r(`system.capabilityCatalog.installed`,`Installed`)}):i(oe,{size:`sm`,onClick:()=>n(e.name),disabled:t,className:`shrink-0`,children:[t?l(v,{className:`h-3 w-3 animate-spin`}):l(d,{className:`h-3 w-3`}),r(`system.capabilityCatalog.install`,`Install`)]})]})}function ot({capability:e,installing:t,onInstall:n}){let{t:r}=J(),{data:a,isPending:o,isError:s}=de({capability:e}),c;if(s)c=l(`div`,{className:`px-3 py-2 text-xs text-danger`,children:r(`system.capabilityCatalog.couldNotSearchTheNpm`,`Could not search the npm catalog right now. Try again in a moment.`)});else if(o||a===void 0)c=i(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[l(v,{className:`h-3 w-3 animate-spin`}),r(`system.capabilityCatalog.searchingTheNpmCatalog`,`Searching the npm catalog…`)]});else{let i=a.filter(e=>!e.installed);c=i.length===0?l(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:a.length===0?r(`system.capabilityCatalog.noPublishedAddonDeclaresThe`,`No published addon declares the "{{capability}}" capability.`,{capability:e}):r(`system.capabilityCatalog.everyPublishedAddonThatDeclares`,`Every published addon that declares "{{capability}}" is already installed.`,{capability:e})}):l(`div`,{className:`divide-y divide-border`,children:i.map(e=>l(at,{addon:e,installing:t,onInstall:n},e.name))})}return i(`section`,{className:`rounded-md border border-border bg-surface overflow-hidden`,"aria-label":r(`system.capabilityCatalog.availableToInstall`,`Available to install`),children:[l(`h2`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:r(`system.capabilityCatalog.availableToInstall`,`Available to install`)}),c]})}n();function st(e){return e===`npm`||e===`dev`?e:null}var ct=`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`,lt=`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,ut=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],dt=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function ft(e){return e!==void 0&&dt.has(e)}var pt={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function mt(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function ht(e){return e===`local`?`dev`:`npm`}function gt(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function _t(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function vt({addons:n,clusterStatus:o,selectedNode:f,onRefresh:p,isRefreshing:m}){let{t:h}=J(),g=s(),[_,y]=c(``),S=r(_),[C,w]=c(!1),ee=t(null);u(()=>{if(!C)return;let e=e=>{ee.current&&!ee.current.contains(e.target)&&w(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[C]);let{data:T}=k({nodeId:f.id}),E=a(()=>{let e=new Map;for(let t of T??[])e.set(t.name,t.latestVersion);return e},[T]),te=a(()=>(T??[]).filter(e=>!e.isSystem).length,[T]),[ne,O]=c(()=>new Set),[re,ie]=c(()=>new Map),ae=e(e=>{O(t=>new Set(t).add(e))},[]),oe=e(e=>{O(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),se=e((e,t)=>{ie(n=>new Map(n).set(e,t))},[]),le=e(e=>{ie(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),ue=L({onMutate:e=>{ae(e.name),le(e.name)},onSuccess:(e,t)=>{oe(t.name);let n=e;if(n&&n.success===!1){se(t.name,n.error??`Update failed (no error message returned by server)`);return}g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{oe(t.name),se(t.name,e instanceof Error?e.message:String(e))}}),A=Me(),fe=t(new Set);u(()=>{let e=new Set;for(let[t,n]of A)Ae(n)&&e.add(t);let t=[...fe.current].some(t=>!e.has(t));fe.current=e,t&&(g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[A,g]);let{data:j}=P(void 0),M=xe({onSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),me=pe({onSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:N,isFetching:he}=de({query:S||void 0},{enabled:C}),F=q(),{data:I}=ce(void 0),_e=I?.requestedAt,[R,B]=c(null),[V,H]=c(!1);u(()=>{if(I?.kind===`framework-bulk-update`&&I.requestedAt!==R){B(I.requestedAt),H(!0);let e=window.setTimeout(()=>H(!1),6e3);return()=>window.clearTimeout(e)}},[_e,R,I]),ve();let ye=e(async()=>{let e=(T??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!f.isHub){for(let t of e)await ue.mutateAsync({name:t.name,version:t.latestVersion,nodeId:f.id});return}await F.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[f.id]})}},[T,f.id,f.isHub,F,ue]),U=ge({onSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`]]}),g.invalidateQueries({queryKey:[[`addonPages`]]}),g.invalidateQueries({queryKey:[[`capabilities`]]}),g.invalidateQueries({queryKey:[[`integrations`]]})}}),[W,be]=c(`type`),[G,Se]=c(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),Ce=e=>{Se(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[K,Y]=we(),X=K.get(`capability`),Z=K.get(`updatable`)===`1`,Q=st(K.get(`source`)),Te=e(e=>{let t=new URLSearchParams(K);e?t.set(`updatable`,`1`):t.delete(`updatable`),Y(t,{replace:!0})},[K,Y]),Ee=e(e=>{let t=new URLSearchParams(K);e===null?t.delete(`source`):t.set(`source`,e),Y(t,{replace:!0})},[K,Y]),De=a(()=>{let e=n.filter(e=>!ft(e.manifest.packageName));return f.isHub||(e=e.filter(e=>mt(e.placement,f.isHub))),X&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===X))),Z&&(e=e.filter(e=>{let t=e.manifest.packageName;return t!==void 0&&E.has(t)})),Q!==null&&(e=e.filter(e=>ht(e.installSource)===Q)),e},[n,f.isHub,X,Z,Q,E]),Oe=()=>{let e=new URLSearchParams(K);e.delete(`capability`),Y(e,{replace:!0})},ke=G===`flat`?De:_t(De),je=a(()=>{let e=[...ke];switch(W){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[ke,W]);return i(`div`,{className:`space-y-3`,children:[[...re.entries()].map(([e,t])=>l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-2.5 py-1.5 text-[11px]`,children:i(`div`,{className:`flex items-start justify-between gap-3`,children:[i(`div`,{className:`space-y-0.5`,children:[i(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),l(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),l(`button`,{type:`button`,onClick:()=>le(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),i(`div`,{className:`flex items-center gap-x-2 gap-y-1.5 flex-wrap`,children:[i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.sort`,`Sort:`)}),i(`select`,{value:W,onChange:e=>be(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[l(`option`,{value:`type`,children:h(`admin.system.addons.bundlesFirst`,`Bundles first`)}),l(`option`,{value:`name`,children:h(`admin.system.addons.name`,`Name`)}),l(`option`,{value:`source`,children:h(`admin.system.addons.installSource`,`Install source`)})]})]}),i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.view`,`View:`)}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>l(`button`,{type:`button`,onClick:()=>Ce(e),className:`px-2 py-1 transition-colors capitalize ${G===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?h(`admin.system.addons.groupMultiAddonPackagesInto`,`Group multi-addon packages into a bundle card`):h(`admin.system.addons.showEveryAddonAsIts`,`Show every addon as its own card`),children:e},e))})]}),f.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(D,{className:`h-3 w-3 text-foreground-subtle`}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.autoUpdate`,`Auto-Update:`)}),l(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>l(`button`,{type:`button`,onClick:()=>M.mutate({channel:e}),disabled:M.isPending,className:`px-2 py-1 transition-colors capitalize ${j?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),f.isHub&&i(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.checkEvery`,`Check every:`)}),l(`select`,{className:`rounded-md border border-border bg-transparent px-1.5 py-1 text-[10px] font-medium text-foreground-subtle`,value:j?.updateCheckIntervalSeconds??21600,disabled:me.isPending||j===void 0,onChange:e=>{j!==void 0&&me.mutate({channel:j.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:ut.map(e=>l(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),te>0&&i(`button`,{type:`button`,onClick:()=>void ye(),disabled:F.isPending,className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[F.isPending?l(v,{className:`w-3 h-3 animate-spin`}):l(d,{className:`w-3 h-3`}),F.isPending?h(`admin.system.addons.updating`,`Updating…`):h(`admin.system.addons.updateAll`,`Update All ({{nonSystemUpdateCount}})`,{nonSystemUpdateCount:te})]}),i(`button`,{type:`button`,onClick:p,disabled:m||F.isPending,className:`flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[l(D,{className:`w-3 h-3 ${m?`animate-spin`:``}`}),h(`common.refresh`,`Refresh`)]})]}),i(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":h(`admin.system.addons.filterInstalledAddons`,`Filter installed addons`),children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:h(`admin.system.addons.filter`,`Filter:`)}),[{id:`updatable`,label:h(`admin.system.addons.updatable`,`Updatable`),pressed:Z,toggle:()=>Te(!Z)},{id:`npm`,label:`npm`,pressed:Q===`npm`,toggle:()=>Ee(Q===`npm`?null:`npm`)},{id:`dev`,label:h(`admin.system.addons.dev`,`Dev`),pressed:Q===`dev`,toggle:()=>Ee(Q===`dev`?null:`dev`)}].map(e=>l(`button`,{type:`button`,"aria-pressed":e.pressed,onClick:e.toggle,className:e.pressed?ct:lt,children:e.label},e.id))]}),i(`div`,{className:`flex flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-2`,children:[i(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:ee,children:[l(z,{type:`text`,value:_,onChange:e=>{y(e.target.value),w(!0)},onFocus:()=>w(!0),placeholder:h(`admin.system.addons.searchAddonsOnNpm`,`Search addons on npm...`),"aria-label":h(`admin.system.addons.searchAddonsOnNpm2`,`Search addons on npm`),disabled:F.isPending,leftSlot:l(x,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),rightSlot:he?l(v,{className:`h-3 w-3 animate-spin`}):void 0}),C&&N&&N.length>0&&i(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-md border border-border bg-surface shadow-xl overflow-hidden`,children:[N.length>0&&i(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,N.length,`)`]}),N&&N.length>0&&l(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:N.map(e=>l(at,{addon:e,installing:U.isPending,onInstall:e=>U.mutate({packageName:e})},e.name))})]})]}),l(tt,{onUploadSuccess:()=>{g.invalidateQueries({queryKey:[[`addons`]]}),p()}})]}),X&&i(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5 rounded-md bg-primary/10 border border-primary/30 text-xs`,children:[l(`span`,{className:`text-foreground-subtle`,children:h(`admin.system.addons.filteringByCapability`,`Filtering by capability:`)}),l(`span`,{className:`font-mono text-primary font-semibold`,children:X}),l(`button`,{type:`button`,onClick:Oe,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:h(`admin.system.addons.clear`,`Clear`)})]}),X&&l(ot,{capability:X,installing:U.isPending,onInstall:e=>U.mutate({packageName:e})}),X&&De.length>0&&l(`h2`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:h(`admin.system.addons.installed`,`Installed`)}),V&&i(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[l(b,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),i(`div`,{children:[l(`div`,{className:`text-[11px] font-semibold text-foreground`,children:h(`admin.system.addons.bulkUpdateCompleted`,`Bulk update completed`)}),l(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:h(`admin.system.addons.systemPackagesUpdatedHubRestarted`,`System packages updated — hub restarted successfully.`)})]})]}),De.length===0&&l(`div`,{className:`text-xs text-foreground-subtle`,children:n.length===0?h(`admin.system.addons.noAddonsInstalled`,`No addons installed`):X?h(`admin.system.addons.noInstalledAddonDeclaresThe`,`No installed addon declares the "{{capabilityFilter}}" capability. Any addon you can install appears under "Available to install" above.`,{capabilityFilter:X}):h(`admin.system.addons.noAddonsCompatibleWithPlacement`,`No addons compatible with {{name}} (placement filter active)`,{name:f.name})}),l(`div`,{className:`space-y-1.5`,children:je.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=E.get(t),r=$(e)?e.representative:e,i=n?e=>ue.mutate({name:t,version:e,nodeId:f.id}):void 0,a=A.get(t)??null,s=a!==null&&Ae(a);return l($e,{addon:r,clusterStatus:o?.[r.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,isUpdating:ne.has(t)||s,jobProgress:a,onUpdate:i,disabledByBulk:F.isPending,selectedNode:f},$(e)?t:e.manifest.id)})})]})}function yt(){let{t:e}=J(),n=s(),{data:r}=R(void 0),{nodes:a}=H(),{selection:o,selectNode:c,requestedNodeId:d}=Te(a.length>0?a:[pt]),f=o.node??pt,p=f.id,m=a.length>0?o.staleNodeId:null,{data:h,isLoading:g,isError:_}=A({nodeId:p}),v=V(),y=W(),b=v.isPending||y.isPending,x=async()=>{await v.mutateAsync({nodeId:p}),await y.mutateAsync(),n.invalidateQueries({queryKey:[[`addons`]]})},S=t(v);S.current=v;let C=t(d??`hub`);u(()=>{S.current.mutate({nodeId:C.current})},[]);let w=(h??[]).map(gt).filter(e=>e!==null);return i(X,{children:[i(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[l(I,{selectedNodeId:p,onSelect:c}),i(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[!g&&!_&&i(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[w.length,` installed`]}),i(`button`,{type:`button`,onClick:()=>void x(),disabled:b,className:`inline-flex items-center gap-1 px-2 py-1 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:e(`admin.system.addons.reFetchAddonsCheckNpm`,`Re-fetch addons + check npm for new versions`),children:[l(D,{className:`w-3 h-3 ${b?`animate-spin`:``}`}),e(`admin.system.addons.checkForUpdates`,`Check for updates`)]})]})]}),l(Q,{staleNodeId:m,shownNodeName:f.name}),l(it,{selectedNode:f}),g&&l(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:e(`common.loading`,`Loading…`)}),_&&l(`div`,{className:`text-xs text-danger`,children:e(`admin.system.addons.failedToLoadAddons`,`Failed to load addons`)}),!g&&!_&&l(vt,{addons:w,clusterStatus:r,selectedNode:f,onRefresh:()=>void x(),isRefreshing:b})]})}export{yt as AddonsPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,x as n}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{B as r}from"./src-eoSUZcV-.js";import{Q as i}from"./index-BgQGn3LX.js";t();function a({paramName:t=`tab`,defaultSection:a,sections:o,...s}){let[c,l]=i(),u=a??o[0]?.id??``,d=c.get(t),f=o.some(e=>e.id===d)?d??u:u,p=e((e,n)=>{l(r=>{let i=new URLSearchParams(r);for(let e of n)i.delete(e);return i.set(t,e),i},{replace:!0})},[t,l]);return n(r,{...s,paramName:t,defaultSection:a,sections:o,activeSection:f,onSectionChange:p})}export{a as t};
@@ -1,3 +0,0 @@
1
- import{I as e,K as t,Q as n,S as r,W as i,a,b as o,q as s,t as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{D as d,Dn as f,G as p,Hr as m,It as h,Jr as g,Jt as _,Oi as v,On as y,Pn as b,Q as x,Tr as S,Xt as C,Zr as w,ar as T,dn as E,dt as D,kr as ee,ot as O,un as k,wi as A}from"./player-overlays-Cda8wso6.js";import{t as te}from"./message-square-plus-D7BNG3h7.js";import{t as j}from"./send-B5VKcNUH.js";import{Wn as M}from"./client-CMlUvfoK.js";import{Bn as N,Ht as P,Kl as F,L as ne,Ln as re,Pn as ie,U as I,Ut as L,Vt as R,Zl as z,ar as B,bn as V,in as H,ma as U,z as W}from"./src-eoSUZcV-.js";import{t as G}from"./i18n-vggiB6gm.js";import{t as K}from"./useTranslation-Bc5yH9V9.js";import"./mount-DlnG_8P7.js";import{C as q}from"./index-BgQGn3LX.js";import{t as ae}from"./AdminSectionedPage-C3VHg80L.js";import{t as J}from"./AdminPage-DuuyDIsY.js";n();var oe=[`llm`,`listProfiles`],se=[`llm`,`listProfileKinds`],ce=[`llm`,`getDefaults`],Y=[`llm`,`listRuntimeNodes`],le=[`llm`,`listModelCatalog`],ue=[`llm`,`getUsage`],de=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],fe=new Map(Object.entries({openai:w,anthropic:w,google:w,"openai-compatible":f,"managed-local":g,"apple-foundation":g}));function pe(e){return fe.get(e)??null}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function Z(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function Q(e){return e===!0}function me(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,topP:e.topP,topK:e.topK,maxTokens:e.maxTokens,contextLength:e.contextLength,systemPrompt:e.systemPrompt,timeoutMs:e.timeoutMs,connectTimeoutMs:e.connectTimeoutMs,firstTokenTimeoutMs:e.firstTokenTimeoutMs,idleTimeoutMs:e.idleTimeoutMs,retryEnabled:e.retry.enabled,retryMaxAttempts:e.retry.maxAttempts,toolsEnabled:e.toolsEnabled,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes,batchSize:e.runtime?.batchSize,ubatchSize:e.runtime?.ubatchSize,flashAttention:e.runtime?.flashAttention,mlock:e.runtime?.mlock,noMmap:e.runtime?.noMmap,cacheTypeK:e.runtime?.cacheTypeK,cacheTypeV:e.runtime?.cacheTypeV,extraArgs:ve(e.runtime?.extraArgs??[])}}var he=[`f32`,`f16`,`q8_0`,`q5_1`,`q5_0`,`q4_1`,`q4_0`];function ge(e){return typeof e==`string`&&he.includes(e)?e:void 0}function _e(e){let t=[],n=``,r=null;for(let i of e){if(r!==null){i===r?r=null:n+=i;continue}if(i===`"`||i===`'`){r=i;continue}if(/\s/.test(i)){n!==``&&t.push(n),n=``;continue}n+=i}return n!==``&&t.push(n),t}function ve(e){return e.map(e=>/\s/.test(e)?`"${e}"`:e).join(` `)}var ye=[`--jinja`,`--cont-batching`];function be(e,t,n){let r=Z(e.threads),i=Z(e.batchSize),a=Z(e.ubatchSize),o=ge(e.cacheTypeK),s=ge(e.cacheTypeV);return{nodeId:t,engine:`llama-cpp`,model:n,extraArgs:[..._e(X(e.extraArgs)??``)],contextSize:Z(e.contextSize)??4096,gpuLayers:Z(e.gpuLayers)??0,...r===void 0?{}:{threads:r},parallel:Z(e.parallel)??1,...i===void 0?{}:{batchSize:i},...a===void 0?{}:{ubatchSize:a},flashAttention:Q(e.flashAttention),mlock:Q(e.mlock),noMmap:Q(e.noMmap),...o===void 0?{}:{cacheTypeK:o},...s===void 0?{}:{cacheTypeV:s},autoStart:Q(e.autoStart),idleStopMinutes:Z(e.idleStopMinutes)??30}}function xe(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:`ai`,enabled:n?.enabled??!0,model:X(r.model)??n?.model??``,supportsVision:i?.supportsVision??Q(r.supportsVision),timeoutMs:Z(r.timeoutMs)??M.totalMs,connectTimeoutMs:Z(r.connectTimeoutMs)??M.connectMs,firstTokenTimeoutMs:Z(r.firstTokenTimeoutMs)??M.firstTokenMs,idleTimeoutMs:Z(r.idleTimeoutMs)??M.idleMs,retry:{enabled:Q(r.retryEnabled),maxAttempts:Z(r.retryMaxAttempts)??1},toolsEnabled:Q(r.toolsEnabled)},o=X(r.baseUrl),s=X(r.apiKey),c=Z(r.temperature),l=Z(r.topP),u=Z(r.topK),d=Z(r.maxTokens),f=Z(r.contextLength),p=X(r.systemPrompt);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{topP:l},...u===void 0?{}:{topK:u},...d===void 0?{}:{maxTokens:d},...f===void 0?{}:{contextLength:f},...p===void 0?{}:{systemPrompt:p},...i===void 0?{}:{model:i.modelId,runtime:be(r,i.nodeId,i.model)}}}function Se(e){let t=new Map;for(let n of e){let e=t.get(n.addonId)??[];e.push(n),t.set(n.addonId,e)}return[...t.entries()].map(([e,t])=>({addonId:e,kinds:t}))}var Ce=`apple-system`;function we(e,t,n,r){return{...xe(`apple-foundation`,e,t,n),model:Ce,supportsVision:!1,appleFoundation:{nodeId:r}}}var Te={deviceNotEligible:{key:`ai.appleNotEligible`,text:`not eligible`,tone:`default`},appleIntelligenceNotEnabled:{key:`ai.appleIntelligenceOff`,text:`Apple Intelligence off`,tone:`warning`},modelNotReady:{key:`ai.appleModelNotReady`,text:`model downloading`,tone:`warning`},osTooOld:{key:`ai.appleOsTooOld`,text:`macOS too old`,tone:`default`},helperMissing:{key:`ai.appleHelperMissing`,text:`helper missing`,tone:`danger`},helperCrashed:{key:`ai.appleHelperCrashed`,text:`helper crashed`,tone:`danger`}};function Ee(e){let t=t=>({nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleUnknown`,labelDefault:`unknown`,detail:t,tone:`default`});if(!e.reachable)return t(e.error??null);let n=e.apple;if(n===void 0)return t(null);switch(n.state){case`available`:return{nodeId:e.nodeId,selectable:!0,labelKey:`ai.appleAvailable`,labelDefault:`available`,detail:`macOS ${n.osVersion} · ${n.imageInput?`text + images`:`text only`}`,tone:`success`};case`unavailable`:{let t=Te[n.reason];return{nodeId:e.nodeId,selectable:!1,labelKey:t.key,labelDefault:t.text,detail:n.detail,tone:t.tone}}case`unsupported-platform`:return{nodeId:e.nodeId,selectable:!1,labelKey:`ai.appleNotMac`,labelDefault:`not a Mac`,detail:n.platform,tone:`default`};case`unknown`:return t(n.error)}}var De=2e3;function $(e){return`${(e/1e9).toFixed(2)} GB`}function Oe(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function ke({nodeId:e,value:t,onChange:n}){let{t:o}=K(),u=O(),[d,f]=s(``),[p,h]=s(null),[g,_]=s(!1),v=a({queryKey:le,queryFn:()=>u.trpcClient.llm.listModelCatalog.query({})}),y=a({queryKey:[`llm`,`listNodeModels`,e],queryFn:()=>u.trpcClient.llm.listNodeModels.query({nodeId:e})}),b=c({mutationFn:e=>u.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{h(e),_(!1),e.ok&&n({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),x=c({mutationFn:t=>u.trpcClient.llm.installModel.mutate({nodeId:e,model:t}),onSuccess:()=>{_(!0),y.refetch()}}),S=a({queryKey:Y,enabled:x.isPending,refetchInterval:x.isPending?De:!1,queryFn:()=>u.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(t=>t.nodeId===e)?.status?.download,C=i(()=>{let t=(v.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${$(e.sizeBytes)}`})),n=(y.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(t=>({value:`node:${t.file}`,label:o(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:t.file,size:$(t.sizeBytes),node:e})})),r=p?.ok===!0?[{value:`custom`,label:`${p.label} · ${$(p.totalBytes)}`}]:[];return[{value:``,label:o(`ai.selectModel`,`Select a model…`)},...t,...n,...r]},[v.data,y.data,p,e,o]),w=e=>{if(e===``){n(null);return}if(e===`custom`){if(p?.ok!==!0)return;n({model:p.model,modelId:p.label,supportsVision:p.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),r=v.data?.find(e=>e.id===t);n({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:r?.purpose===`vision`});return}let t=e.slice(5),r=y.data?.find(e=>e.file===t);r?.path!==void 0&&n({model:{kind:`path`,path:r.path},modelId:t,supportsVision:!1})},D=e=>{d.trim()!==``&&b.mutate({ref:d.trim(),...e===void 0?{}:{maxBytes:e}})};return r(`div`,{className:`space-y-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-model`,children:o(`ai.model`,`Model`)}),l(F,{id:`ai-model`,value:Oe(t),options:C,onChange:e=>w(e.target.value)})]}),r(`div`,{className:`rounded-md border border-border bg-surface-subtle px-3 py-2.5`,children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:o(`ai.hfTitle`,`Add a model from Hugging Face`)}),l(`p`,{className:`mb-2 text-[10px] leading-relaxed text-foreground-subtle`,children:o(`ai.hfHint`,`Paste a GGUF file URL, or type org/repo — add :QUANT (e.g. unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M) when the repo publishes more than one quantization.`)}),r(`div`,{className:`flex gap-2`,children:[l(z,{value:d,onChange:e=>f(e.target.value),placeholder:o(`system.aiModelPicker.unslothQwen3635bA3b`,`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),D())}}),r(N,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.trim()===``||b.isPending,onClick:()=>D(),children:[b.isPending?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(E,{className:`h-3.5 w-3.5`}),o(`ai.hfCheck`,`Check`)]})]}),b.isError&&l(`p`,{className:`mt-2 text-[11px] text-danger`,children:b.error instanceof Error?b.error.message:o(`common.error`,`Error`)}),p?.ok===!1&&r(`div`,{className:`mt-2 rounded-md border border-danger/40 bg-danger/10 px-2.5 py-2`,children:[l(`p`,{className:`text-[11px] text-danger`,children:p.message}),p.candidates!==void 0&&p.candidates.length>0&&l(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:p.candidates.map(e=>l(`button`,{type:`button`,className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] text-foreground hover:border-primary/50`,onClick:()=>{let t=`${d.trim().split(`:`)[0]??``}:${e}`;f(t),b.mutate({ref:t})},children:e},e))}),p.requiredBytes!==void 0&&l(N,{size:`sm`,variant:`secondary`,type:`button`,className:`mt-2`,onClick:()=>D(p.requiredBytes),children:o(`ai.hfOverride`,`Install anyway ({{size}})`,{size:$(p.requiredBytes)})})]}),p?.ok===!0&&r(`div`,{className:`mt-2 rounded-md border border-border bg-surface px-2.5 py-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[l(`span`,{className:`text-[11px] font-medium text-foreground`,children:p.label}),l(B,{variant:p.purpose===`vision`?`info`:`default`,children:p.purpose}),l(B,{variant:`default`,children:$(p.totalBytes)})]}),p.extraFilenames.length>0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:o(`ai.hfExtras`,`Also downloads: {{files}}`,{files:p.extraFilenames.join(`, `)})}),r(`div`,{className:`mt-2 flex items-center gap-2`,children:[r(N,{size:`sm`,type:`button`,disabled:x.isPending||g,onClick:()=>x.mutate(p.model),children:[x.isPending?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(m,{className:`h-3.5 w-3.5`}),g?o(`ai.hfInstalled`,`Downloaded`):o(`ai.hfInstall`,`Download to {{node}}`,{node:e})]}),S!==void 0&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:S.phase===`verifying`?o(`ai.hfVerifying`,`verifying {{file}}…`,{file:S.file}):o(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:S.file,index:S.fileIndex,count:S.fileCount,done:$(S.downloadedBytes),total:S.totalBytes===void 0?``:` / ${$(S.totalBytes)}`})})]}),x.isError&&l(`p`,{className:`mt-1.5 text-[11px] text-danger`,children:x.error instanceof Error?x.error.message:o(`common.error`,`Error`)})]})]})]})}function Ae({value:e,onChange:t}){let{t:n}=K(),i=O(),o=a({queryKey:Y,queryFn:()=>i.trpcClient.llm.listRuntimeNodes.query({})});return r(`div`,{children:[l(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:n(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&r(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(T,{className:`h-3.5 w-3.5 animate-spin`}),n(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&l(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:n(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&l(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&l(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(i=>{let a=Ee(i),o=a.nodeId===e;return r(`button`,{type:`button`,role:`radio`,"aria-checked":o,disabled:!a.selectable&&!o,onClick:()=>t(a.nodeId),className:`flex w-full items-center justify-between gap-2 rounded-md border px-3 py-2 text-left text-xs transition-colors disabled:cursor-not-allowed disabled:opacity-60 ${o?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block font-medium text-foreground`,children:a.nodeId}),a.detail!==null&&l(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:a.detail})]}),l(B,{variant:a.tone,children:n(a.labelKey,a.labelDefault)})]},a.nodeId)})}),l(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:n(`ai.appleHint`,`Text only for now — notification titles and summaries. Apple refuses prompts framed as surveillance; when it does, the next profile in the chain answers instead.`)})]})}n();function je({kind:e,className:t}){let n=pe(e.kind);return n===null?l(`span`,{className:t,children:e.icon}):l(n,{className:t})}function Me({kinds:e,onPick:t,onCancel:n}){let{t:a}=K(),o=i(()=>Se(e),[e]);return l(W,{open:!0,onClose:n,title:a(`ai.chooseKind`,`Choose a profile type`),width:`lg`,testId:`ai-kind-picker`,children:r(`div`,{className:`space-y-4`,children:[o.length===0&&l(`p`,{className:`text-xs text-foreground-subtle`,children:a(`ai.noKinds`,`No AI provider is installed.`)}),o.map(e=>r(`div`,{children:[l(`div`,{className:`mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e.addonId}),l(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.kinds.map(n=>r(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[l(je,{kind:n,className:`h-5 w-5 text-foreground-subtle`}),l(`span`,{className:`font-medium text-foreground`,children:n.label})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})})}function Ne({kind:e,existing:t,onSave:n,onCancel:a,saving:c,error:u}){let{t:d}=K(),f=e.kind===`managed-local`,p=e.kind===`apple-foundation`,[m,h]=s(t?.appleFoundation?.nodeId??null),[g,_]=s(t?.name??e.label),[v,y]=s(()=>t===null?{}:me(t)),[b,x]=s(t?.runtime?.nodeId??`hub`),[S,C]=s(()=>t?.runtime===void 0?null:{model:t.runtime.model,modelId:t.model,supportsVision:t.supportsVision}),w=i(()=>_e(X(v.extraArgs)??``),[v.extraArgs]),E=()=>{if(p){if(m===null)return;n(we(g,t,v,m));return}if(!f){n(xe(e.kind,g,t,v));return}S!==null&&n(xe(e.kind,g,t,v,{nodeId:b,model:S.model,modelId:S.modelId,supportsVision:S.supportsVision}))},D=c||g.trim()===``||f&&S===null||p&&m===null;return l(W,{open:!0,onClose:a,title:t===null?d(`ai.newProfile`,`New {{kind}} profile`,{kind:e.label}):d(`ai.editProfile`,`Edit {{name}}`,{name:t.name}),error:u,width:`lg`,testId:`ai-profile-editor`,footer:r(o,{children:[f&&S===null&&l(B,{variant:`warning`,children:d(`ai.pickModelFirst`,`pick a model`)}),p&&m===null&&l(B,{variant:`warning`,children:d(`ai.pickAppleNodeFirst`,`pick a Mac`)}),r(N,{size:`sm`,type:`button`,disabled:D,onClick:E,children:[c&&l(T,{className:`h-3.5 w-3.5 animate-spin`}),t===null?d(`ai.createProfile`,`Create profile`):d(`ai.saveChanges`,`Save changes`)]})]}),children:r(`div`,{className:`space-y-3`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-name`,children:d(`ai.name`,`Name`)}),l(z,{id:`ai-profile-name`,value:g,onChange:e=>_(e.target.value),placeholder:e.label})]}),f&&r(o,{children:[l(I,{selectedNodeId:b,onSelect:x,label:d(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),l(ke,{nodeId:b,value:S,onChange:C}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-extra-args`,children:d(`ai.extraArgs`,`Additional llama-server arguments`)}),l(z,{id:`ai-extra-args`,value:X(v.extraArgs)??``,onChange:e=>y({...v,extraArgs:e.target.value}),placeholder:ye.join(` `)}),w.length>0&&l(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:w.map((e,t)=>l(B,{variant:`default`,children:e},`${e}-${String(t)}`))}),l(`p`,{className:`mt-1 text-[10px] leading-relaxed text-foreground-subtle`,children:d(`ai.extraArgsHint`,`Flags this form does not already own. Vision models generally need --jinja; some language-only models do not like it. Context size, GPU layers, parallel slots, flash attention and the KV-cache types are set in the fields below — repeating one here is rejected at start.`)})]})]}),p&&l(Ae,{value:m,onChange:h}),l(V,{schema:e.configSchema,values:v,onChange:y}),t!==null&&l(`p`,{className:`text-[10px] text-foreground-subtle`,children:d(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)})]})})}n();function Pe(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return r(`span`,{className:`flex items-center gap-2`,children:[l(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:n?.label??t.kind,children:n===void 0?l(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):l(je,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),r(`span`,{className:`min-w-0`,children:[l(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&l(`span`,{className:`block truncate text-[10px] ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?l(B,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>e.runtime===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(B,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>l(H,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":G.t(`system.aiProfilesTab.toggle`,`toggle {{name}}`,{name:t.name})})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>r(`span`,{className:`flex items-center justify-end gap-1`,children:[l(N,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?l(T,{className:`h-3.5 w-3.5 animate-spin`}):l(j,{className:`h-3.5 w-3.5`})}),l(N,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:l(b,{className:`h-3.5 w-3.5`})}),l(N,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:e.t(`common.delete`,`Delete`),children:l(h,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function Fe(){let{t}=K(),n=O(),{state:o,openNew:d,openEdit:f,close:p}=ne(),[m,h]=s(null),[g,_]=s(null),[v,b]=s(null),x=a({queryKey:oe,queryFn:()=>n.trpcClient.llm.listProfiles.query({})}),S=a({queryKey:se,queryFn:async()=>(await n.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),w=()=>{x.refetch()},E=e(()=>{h(null),b(null),p()},[p]);u(()=>{o.mode===`closed`&&h(null)},[o.mode]);let D=c({mutationFn:e=>n.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{E(),w()},onError:e=>b(e instanceof Error?e.message:t(`ai.saveFailed`,`Save failed`))}),ee=c({mutationFn:e=>n.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:w}),k=c({mutationFn:e=>n.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>_({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${String(e.usage.outputTokens)} tok, ${String(e.latencyMs)}ms)`:`${e.code}: ${e.message}`})}),A=x.data??[],te=i(()=>S.data??[],[S.data]),j=i(()=>{let e=new Map;for(let t of te)e.set(t.kind,t);return e},[te]),M=o.mode===`edit`?A.find(e=>e.id===o.id)??null:null,F=M===null?null:j.get(M.kind)??null,ie=o.mode===`new`&&m===null,I=o.mode===`new`?m:F,L=o.mode===`edit`?M:null,z=I!==null&&(o.mode===`new`||L!==null);return r(J,{embedded:!0,icon:C,title:t(`ai.profilesTitle`,`AI profiles`),subtitle:t(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),children:[l(`div`,{className:`flex justify-end`,children:r(N,{size:`sm`,type:`button`,onClick:()=>{b(null),h(null),d()},children:[l(y,{className:`h-3.5 w-3.5`}),t(`ai.addProfile`,`Add profile`)]})}),x.isError&&l(re,{title:t(`ai.loadFailed`,`Failed to load profiles`),message:x.error instanceof Error?x.error.message:t(`common.error`,`Error`),onRetry:()=>void x.refetch()}),l(Ie,{profiles:A}),x.isLoading&&l(`div`,{className:`flex items-center justify-center py-16`,children:l(T,{className:`h-6 w-6 animate-spin text-primary`})}),!x.isLoading&&A.length===0&&l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:t(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}),A.length>0&&l(R,{headingId:`ai-profiles-list`,title:t(`ai.profilesList`,`Profiles`),children:l(P,{columns:Pe({kindByName:j,testResult:g,testingId:k.isPending?k.variables?.id??null:null,t,onToggle:e=>D.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>k.mutate(e),onEdit:e=>{j.has(e.kind)&&(b(null),h(null),f(e.id))},onDelete:e=>ee.mutate(e)}),rows:A,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),ie&&l(Me,{kinds:te,onCancel:E,onPick:e=>{b(null),h(e)}}),z&&I!==null&&l(Ne,{kind:I,existing:L,saving:D.isPending,error:v,onSave:e=>D.mutate(e),onCancel:E})]})}function Ie({profiles:e}){let{t}=K(),n=O(),i=a({queryKey:ce,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=c({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{i.refetch()}}),s=e=>(i.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,u=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return l(R,{headingId:`ai-profiles-defaults`,title:t(`ai.defaultsTitle`,`Defaults`),children:l(`div`,{className:`${d} grid gap-4 sm:grid-cols-2`,children:de.map(({purpose:n,visionOnly:i})=>{let a=i?e.filter(e=>e.supportsVision):e,c=s(n),d=e.find(e=>e.id===c);return r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`llm-default-${n}`,children:u(n)}),l(F,{id:`llm-default-${n}`,"aria-label":u(n),className:`h-7 text-xs`,value:c,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:t(`ai.none`,`None`)},...c!==``&&!a.some(e=>e.id===c)?[{value:c,label:d?.name??c}]:[],...a.map(e=>({value:e.id,label:`${e.name} · ${e.model}`}))]}),c!==``&&d===void 0&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&l(`p`,{className:`mt-1 text-[10px] text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&l(`p`,{className:`mt-1 text-[10px] text-danger`,children:String(o.error)})]},n)})})})}n();var Le=5e3;function Re(e){return`${(e/1e9).toFixed(1)} GB`}function ze(){let{t:e}=K(),t=O(),n=a({queryKey:Y,refetchInterval:Le,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),o=i(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>l(`span`,{className:`text-sm font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>r(`span`,{className:`flex items-center gap-1.5`,children:[l(B,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&l(B,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.disk===void 0?`—`:Re(e.disk.modelsBytes)})},{key:`apple`,header:e(`ai.colApple`,`Apple on-device`),render:t=>{let n=Ee(t);return r(`span`,{className:`flex flex-col items-start gap-0.5`,children:[l(B,{variant:n.tone,children:e(n.labelKey,n.labelDefault)}),n.detail!==null&&l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n.detail})]})}},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?l(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):l(`span`,{className:`text-[11px] text-danger`,children:e.error})}],[e]),s=n.data??[];return r(J,{embedded:!0,icon:k,title:e(`ai.runtimesTitle`,`Managed runtimes`),subtitle:e(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),children:[n.isError&&l(re,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:n.error instanceof Error?n.error.message:e(`common.error`,`Error`),onRetry:()=>void n.refetch()}),s.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):l(R,{headingId:`ai-runtimes-list`,title:e(`ai.runtimesList`,`Nodes`),children:l(P,{columns:o,rows:s,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:L})})]})}var Be=x(`/addon/ai/test-chat`),Ve=x(`/addon/ai/test-chat/chats`),He=6e5;function Ue(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),He)}function We(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ge(e){if(!We(e))return null;let t=e.kind;return t!==`snapshot`&&t!==`track`||typeof e.mimeType!=`string`||typeof e.sizeBytes!=`number`?null:{kind:t,mimeType:e.mimeType,sizeBytes:e.sizeBytes,...typeof e.mediaKind==`string`?{mediaKind:e.mediaKind}:{},...typeof e.capturedAt==`number`?{capturedAt:e.capturedAt}:{},...typeof e.thumbnailBase64==`string`?{thumbnailBase64:e.thumbnailBase64}:{}}}var Ke=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function qe(e){let t;try{t=JSON.parse(e)}catch{return null}if(!We(t))return null;switch(t.kind){case`status`:{let e=Ke.find(e=>e===t.phase);return e===void 0?null:{kind:`status`,phase:e}}case`meta`:return typeof t.profileName!=`string`||typeof t.model!=`string`?null:{kind:`meta`,profileName:t.profileName,model:t.model,mediaSent:Ge(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0,...typeof t.conversationId==`string`?{conversationId:t.conversationId}:{}};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:`the provider returned an error`};default:return null}}async function*Je(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
2
- `);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=qe(e);t!==null&&(yield t)}a=r.indexOf(`
3
- `)}}let e=r.trim();if(e.length>0){let t=qe(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function Ye(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Xe(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function Ze(e){return e.messages.map((t,n)=>{let r=t.mediaSent??void 0;return{id:`${e.id}-${String(n)}`,role:t.role,content:t.content,...t.attachment===void 0?{}:{attachmentRef:t.attachment,attachmentKind:t.attachment.kind},...r===void 0?{}:{attachment:r}}})}function Qe(e){let t=e.sizeBytes<1024*1024?`${(e.sizeBytes/1024).toFixed(0)} KB`:`${(e.sizeBytes/(1024*1024)).toFixed(1)} MB`,n=[e.kind===`snapshot`?`camera snapshot`:`track best-shot`,t];return e.mediaKind!==void 0&&n.push(e.mediaKind),e.capturedAt!==void 0&&n.push(new Date(e.capturedAt).toLocaleTimeString()),n.join(` · `)}function $e(e,t){switch(e){case`resolving-image`:return`fetching the picture…`;case`connecting`:return`connecting to the provider…`;case`first-token-wait`:return t>0?`the model is loading / thinking — a cold load can take minutes (up to ${String(Math.round(t/1e3))}s)`:`the model is loading / thinking — a cold load can take minutes`;case`streaming`:return`answering…`}}n();var et=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],tt=360*60*1e3,nt=40,rt=160,it={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function at(){let{t:n}=K(),o=O(),[c,d]=s(``),[f,p]=s(``),[m,g]=s(``),[y,b]=s([]),[x,S]=s(null),[C,w]=s(`none`),[T,E]=s(`throwaway`),[k,M]=s(null),[P,ne]=s([]),[I,L]=s(null),[R,B]=s(null),V=t(null);u(()=>()=>V.current?.abort(),[]);let H=e(async()=>{let e=await fetch(Ve,{credentials:`same-origin`});e.ok&&ne((await e.json()).chats??[])},[]);u(()=>{T===`persistent`&&H()},[T,H]);let U=a({queryKey:oe,queryFn:()=>o.trpcClient.llm.listProfiles.query({})}),W=i(()=>(U.data??[]).filter(e=>e.enabled),[U.data]),G=W.find(e=>e.id===c)??null,q=R!==null,ae=e(async(e,t)=>{let r=new AbortController;V.current=r,L(null);let i=Ue(G??{});B({...it,firstTokenTimeoutMs:i??0});let a=``,o=null,s,l=null,u=null,d;try{let n=await fetch(Be,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:r.signal,body:JSON.stringify({profileId:c,messages:e,...f.trim()===``?{}:{system:f.trim()},...t===void 0?{}:{attachment:t},...i===void 0?{}:{firstTokenTimeoutMs:i},...T===`persistent`?{persist:!0,...k===null?{}:{conversationId:k}}:{}})});if(!n.ok||n.body===null){let e=await n.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(n.status)}`)}for await(let e of Je(n.body))switch(e.kind){case`status`:B(t=>({...t??it,phase:e.phase}));break;case`meta`:o=e.mediaSent,s=e.model,B(t=>({...t??it,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:a+=e.text,B(e=>({...e??it,text:a}));break;case`done`:u={outputTokens:e.outputTokens,latencyMs:e.latencyMs},d=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){r.signal.aborted||L(e instanceof Error?e.message:n(`common.error`,`Error`))}finally{V.current=null,B(null)}d!==void 0&&(M(d),H());let p=r.signal.aborted&&a.length>0;l===null&&a.length===0&&!p||b(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??a,...l===null?{}:{failed:!0},...o===null?{}:{attachment:o},...s!==void 0&&l===null?{model:s}:{},...u===null?{}:u}])},[T,k,G,c,H,f,n]),se=e(()=>{let e=m.trim();if(e===``||c===``||q)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...x===null?{}:{attachmentLabel:x.label,attachmentKind:x.ref.kind}},n=[...y,t];b(n),g(``);let r=x?.ref;S(null),w(`none`),ae(T===`persistent`&&k!==null?[{role:`user`,content:e}]:Ye(n),r)},[T,k,m,x,c,ae,q,y]),ce=()=>V.current?.abort(),Y=()=>{V.current?.abort(),b([]),S(null),g(``),L(null),B(null),M(null)},le=async e=>{V.current?.abort();let t=await fetch(`${Ve}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();M(e),b(Ze(n)),B(null),L(null)};return r(J,{embedded:!0,icon:ee,title:n(`ai.testTitle`,`Test chat`),subtitle:n(T===`persistent`?`ai.testSubtitlePersistent`:`ai.testSubtitle`,T===`persistent`?`Conversations are saved for you and can be reopened. Throwaway mode is still available.`:`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`),children:[l(`div`,{className:`flex justify-end`,children:r(N,{size:`sm`,variant:`secondary`,type:`button`,disabled:y.length===0&&x===null,onClick:Y,children:[l(h,{className:`h-3.5 w-3.5`}),n(`ai.clearChat`,`Clear`)]})}),r(ie,{className:`space-y-3 p-4`,children:[r(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-profile`,children:n(`ai.profile`,`Profile`)}),l(F,{id:`ai-test-profile`,value:c,onChange:e=>d(e.target.value),options:[{value:``,label:n(`ai.selectProfile`,`Select a profile…`)},...W.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),W.length===0&&!U.isLoading&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),r(`div`,{children:[l(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-system`,children:n(`ai.systemPrompt`,`System prompt (optional)`)}),l(z,{id:`ai-test-system`,value:f,onChange:e=>p(e.target.value),placeholder:n(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[l(N,{size:`sm`,variant:T===`throwaway`?`primary`:`outline`,type:`button`,onClick:()=>{E(`throwaway`),M(null)},children:n(`ai.throwawayMode`,`Throwaway`)}),l(N,{size:`sm`,variant:T===`persistent`?`primary`:`outline`,type:`button`,onClick:()=>E(`persistent`),children:n(`ai.saveConversation`,`Save conversation`)})]}),T===`persistent`&&r(`div`,{className:`space-y-2`,children:[l(`div`,{className:`flex items-center gap-2`,children:r(N,{size:`sm`,variant:`secondary`,type:`button`,onClick:Y,children:[l(te,{className:`h-3.5 w-3.5`}),n(`ai.newChat`,`New chat`)]})}),P.length>0&&l(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:P.map(e=>l(`button`,{type:`button`,onClick:()=>void le(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover ${e.id===k?`bg-primary/10`:``}`,children:l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),l(`p`,{className:`text-[10px] text-foreground-subtle`,children:n(`ai.streamNote`,`The answer streams as the model produces it. A cold model can take a while to load — the status line says which phase it is in.`)}),G!==null&&!G.supportsVision&&l(`p`,{className:`text-[10px] text-warning`,children:n(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]}),I!==null&&l(re,{title:n(`ai.chatFailed`,`The test call failed`),message:I}),l(ot,{turns:y,live:R}),r(ie,{className:`space-y-2 p-3`,children:[x!==null&&r(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[x.ref.kind===`snapshot`?l(A,{className:`h-3.5 w-3.5 text-foreground-subtle`}):l(v,{className:`h-3.5 w-3.5 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:x.label}),l(N,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>S(null),children:l(D,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(N,{size:`sm`,variant:C===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>w(C===`snapshot`?`none`:`snapshot`),children:[l(A,{className:`h-3.5 w-3.5`}),n(`ai.attachSnapshot`,`Camera snapshot`)]}),r(N,{size:`sm`,variant:C===`track`?`primary`:`outline`,type:`button`,onClick:()=>w(C===`track`?`none`:`track`),children:[l(v,{className:`h-3.5 w-3.5`}),n(`ai.attachTrack`,`Recent track`)]})]}),C===`snapshot`&&l(lt,{onPick:e=>{S({ref:{kind:`snapshot`,deviceId:e.id},label:n(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:e.name})}),w(`none`)}}),C===`track`&&l(dt,{onPick:(e,t)=>{S({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:n(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),w(`none`)}}),r(`div`,{className:`flex items-center gap-2`,children:[l(z,{value:m,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),se())},placeholder:n(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":n(`ai.message`,`Message`)}),q?r(N,{size:`sm`,variant:`secondary`,type:`button`,onClick:ce,children:[l(_,{className:`h-3.5 w-3.5`}),n(`ai.stop`,`Stop`)]}):r(N,{size:`sm`,type:`button`,disabled:m.trim()===``||c===``,onClick:se,children:[l(j,{className:`h-3.5 w-3.5`}),n(`ai.send`,`Send`)]})]})]})]})}function ot({turns:e,live:t}){let{t:n}=K();return e.length===0&&t===null?l(`div`,{className:`py-12 text-center text-xs text-foreground-subtle`,children:n(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):l(ie,{children:r(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto p-3`,children:[e.map(e=>l(st,{turn:e},e.id)),t!==null&&r(`div`,{className:`space-y-1`,children:[t.mediaSent!==null&&l(ct,{attachment:t.mediaSent}),t.text.length>0&&l(st,{turn:{id:`live`,role:`assistant`,content:t.text},streaming:!0}),r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[l(T,{className:`h-3.5 w-3.5 animate-spin`}),$e(t.phase,t.firstTokenTimeoutMs)]})]})]})})}function st({turn:e,streaming:t=!1}){let{t:n}=K(),i=e.role===`user`,a=e.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return l(`div`,{className:`flex ${i?`justify-end`:`justify-start`}`,children:r(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${i?`border-primary/40 bg-primary/10`:a}`,children:[r(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[e.content,t&&l(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),e.attachment!==void 0&&l(ct,{attachment:e.attachment}),e.attachmentLabel!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachmentKind===`track`?l(v,{className:`h-3 w-3`}):l(A,{className:`h-3 w-3`}),e.attachmentLabel]}),e.attachment!==void 0&&r(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachment.kind===`snapshot`?l(A,{className:`h-3 w-3`}):l(v,{className:`h-3 w-3`}),Qe(e.attachment)]}),e.model!==void 0&&l(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`system.aiTestChat.tokMs`,`{{model}} · {{value2}} tok · {{value3}} ms`,{model:e.model,value2:String(e.outputTokens??0),value3:String(e.latencyMs??0)})})]})})}function ct({attachment:e}){let{t}=K(),n=Xe(e);return n===null?null:l(`img`,{src:n,alt:t(`system.aiTestChat.sentToTheModel`,`sent to the model`),className:`mt-1 max-h-32 rounded-md border border-border object-contain`})}function lt({onPick:e}){let{t}=K(),n=U({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?l(T,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):l(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>l(ut,{device:t,onPick:e},t.id))})}function ut({device:e,onPick:t}){let{src:n}=p(e.id,{width:rt});return r(`button`,{type:`button`,onClick:()=>t(e),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[l(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:n!==null&&l(`img`,{src:n,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),r(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!e.online&&l(B,{variant:`warning`,children:`off`}),l(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function dt({onPick:e}){let{t}=K(),n=O(),o=U({isCamera:!0,projection:`slim`}),s=i(()=>(o.data??[]).map(e=>e.id),[o.data]),c=i(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=a({queryKey:[...et,s.length],enabled:s.length>0,queryFn:()=>n.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...s],since:Date.now()-tt,limit:nt,projection:`slim`})});if(o.isLoading||u.isLoading)return l(T,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?l(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noTracks`,`No track in the last 6 hours.`)}):l(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(t=>r(`button`,{type:`button`,onClick:()=>e(t,c.get(t.deviceId)??String(t.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[l(v,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),l(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:t.label??t.className}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:c.get(t.deviceId)??t.deviceId}),l(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(t.lastSeen).toLocaleTimeString()})]},t.trackId))})}n();var ft=1440*60*1e3,pt=[1,7,30,90];function mt(){let{t:e}=K(),t=O(),[n,o]=s(7),c=i(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(n-1)*ft},[n]),u=a({queryKey:oe,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),d=a({queryKey:[...ue,n],queryFn:()=>t.trpcClient.llm.getUsage.query({since:c})}),f=i(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),p=i(()=>[{key:`day`,header:e(`ai.colDay`,`Day`),nowrap:!0,render:e=>e.day},{key:`consumer`,header:e(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:e.consumer})},{key:`profile`,header:e(`ai.colProfile`,`Profile`),render:e=>l(`span`,{className:`text-[11px] text-foreground`,children:f.get(e.profileId)??e.profileId})},{key:`calls`,header:e(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>String(e.calls)},{key:`okErr`,header:e(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>l(`span`,{className:e.errorCalls>0?`text-danger`:void 0,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:e(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>`${String(e.inputTokens)} / ${String(e.outputTokens)}`},{key:`latency`,header:e(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>String(Math.round(e.avgLatencyMs))}],[f,e]),m=d.data??[];return r(J,{embedded:!0,icon:S,title:e(`ai.usageTitle`,`Usage`),subtitle:e(`ai.usageSubtitle`,`Server-side rollup per day, consumer and profile — never raw call rows. Errors are counted, so a profile that always fails is visible here before a feature reports it.`),actions:l(`div`,{className:`w-40`,children:l(F,{"aria-label":e(`ai.window`,`Window`),value:String(n),options:pt.map(t=>({value:String(t),label:e(`ai.lastDays`,`Last {{days}} days`,{days:t})})),onChange:e=>o(Number(e.target.value))})}),children:[d.isError&&l(re,{title:e(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:e(`common.error`,`Error`),onRetry:()=>void d.refetch()}),m.length===0?l(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noUsage`,`No AI calls in this window.`)}):l(R,{headingId:`ai-usage-list`,title:e(`ai.usageList`,`Rollup`),children:l(P,{columns:p,rows:m,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:L})})]})}function ht(){let{t:e}=K(),t=q(`/system/ai`,{t:e,isAdmin:!0})??{icon:C,title:e(`system.ai`,`AI`)};return l(ae,{icon:t.icon,title:t.title,defaultSection:`profiles`,sectionsLabel:`${t.title} sections`,sections:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),content:l(Fe,{})},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),content:l(ze,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),content:l(mt,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),content:l(at,{})}]})}export{ht as AiProfilesPage,ht as default};
@@ -1 +0,0 @@
1
- import{Q as e,S as t,W as n,q as r,x as i,z as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{ar as o}from"./player-overlays-Cda8wso6.js";import{yi as s}from"./client-CMlUvfoK.js";import{Bn as c,Sn as l,bi as u,pi as d}from"./src-eoSUZcV-.js";import{t as f}from"./useTranslation-Bc5yH9V9.js";import{I as p}from"./index-BgQGn3LX.js";e();function m(e,t){let n=e=>e.map(e=>e.type===`group`?{...e,fields:n(e.fields)}:e.type===`sub-tabs`?{...e,tabs:e.tabs.map(e=>({...e,fields:n(e.fields)}))}:e.type===`info`&&typeof e.content==`string`?{...e,content:e.content.split(`{{brokerId}}`).join(t)}:e);return{...e,sections:e.sections.map(e=>({...e,fields:n(e.fields)}))}}function h(e,t){if(!e)return t;let n=new Set;for(let r of e.sections){let e=r.fields;for(let r of e)!(`key`in r)||typeof r.key!=`string`||l(r,t,e)&&n.add(r.key)}let r={};for(let[e,i]of Object.entries(t))n.has(e)&&(r[e]=i);return r}function g({kind:e,addonId:l,brokerId:g,initialValues:_,onSubmit:v,onCancel:y,submitLabel:b,disabled:x}){let{t:S}=f(),[C,w]=r(_??{}),[T,E]=r(null),D=d({kind:e,...l===void 0?{}:{addonId:l}}),O=n(()=>{let e=D.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections)){let t=e;return s(g===void 0?t:m(t,g),C)}},[D.data,g,C]);a(()=>{_!==void 0&&w(_)},[_]);let k=u(),A=async()=>{E(null);let t=h(O,C);try{let n=await k.mutateAsync({kind:e,settings:t,...l===void 0?{}:{addonId:l}});E(n.ok?{ok:!0}:{ok:!1,error:n.error})}catch(e){E({ok:!1,error:e instanceof Error?e.message:String(e)})}};return t(`div`,{className:`space-y-3`,children:[D.isLoading&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(o,{className:`h-3.5 w-3.5 animate-spin`}),` Loading schema…`]}),O&&i(p,{schema:O,values:C,onChange:w}),D.isError&&t(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[S(`brokers.brokerForm.failedToLoadSettingsSchema`,`Failed to load settings schema:`),` `,D.error instanceof Error?D.error.message:S(`brokers.brokerForm.unknownError`,`Unknown error`)]}),!O&&!D.isLoading&&!D.isError&&t(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:[`No settings schema available for kind `,i(`code`,{className:`font-mono`,children:e}),`. Its broker addon may not be installed or running.`]}),T&&i(`div`,{className:`rounded border px-3 py-2 text-[11px] ${T.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:T.ok?S(`brokers.brokerForm.connectionOk`,`Connection OK.`):S(`brokers.brokerForm.testFailed`,`Test failed: {{value1}}`,{value1:T.error??`unknown error`})}),t(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[i(c,{variant:`outline`,size:`sm`,onClick:y,children:S(`common.cancel`,`Cancel`)}),t(`div`,{className:`flex items-center gap-2`,children:[i(c,{variant:`outline`,size:`sm`,onClick:()=>{A()},disabled:k.isPending||!O,children:k.isPending?S(`brokers.brokerForm.testing`,`Testing…`):S(`brokers.brokerForm.testConnection`,`Test connection`)}),i(c,{variant:`primary`,size:`sm`,onClick:()=>{let{_calendarCatalog:e,...t}=h(O,C);v(t)},disabled:!O||x,children:b??S(`common.save`,`Save`)})]})]})]})}export{g as t};