@camstack/addon-admin-ui 1.2.690 → 1.2.692

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 (133) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/dist/assets/AccessSection-IxFRkyj7.js +1 -0
  3. package/dist/assets/Addons-7QqgosGD.js +5 -0
  4. package/dist/assets/{AdminPage-z8USGyNk.js → AdminPage-C-qoUzpo.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-CtcZ5jHa.js → AdminSectionedPage--IV15Z0K.js} +1 -1
  6. package/dist/assets/AiProfiles-QN2g9jqO.js +3 -0
  7. package/dist/assets/Archive-WrESxjJy.js +1 -0
  8. package/dist/assets/BootstrapSettingsForm-weEVSaW9.js +1 -0
  9. package/dist/assets/Build-CpaKZqNA.js +40 -0
  10. package/dist/assets/{Calendars-DeXYk6f7.js → Calendars-BnNXx7uH.js} +1 -1
  11. package/dist/assets/Cluster-MRRnaFRU.js +1 -0
  12. package/dist/assets/CompositionBlockEditor-xLxzSrPy.js +2 -0
  13. package/dist/assets/CompositionEditorPage-CZWH0-Z7.js +1 -0
  14. package/dist/assets/Data-Dgw2QoiR.js +2 -0
  15. package/dist/assets/DeviceDetail-DKsu3T6J.js +1 -0
  16. package/dist/assets/{Devices-3Lm2uV9o.js → Devices-BfI-sOWA.js} +1 -1
  17. package/dist/assets/{EmbedDevicePage-BgNfY1Ap.js → EmbedDevicePage-CiYM6Lwi.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-BFXQpQxb.js → EmbedPlayerPage-BlLAhiWe.js} +1 -1
  19. package/dist/assets/History-DdOqdVgE.js +1 -0
  20. package/dist/assets/Identity-BEZM1NwE.js +1 -0
  21. package/dist/assets/InstancesTable-ifaZoA3R.js +1 -0
  22. package/dist/assets/IntegrationDetail-CUFODYnA.js +1 -0
  23. package/dist/assets/Integrations-BkVNfR-7.js +1 -0
  24. package/dist/assets/{Integrations-CldsYVl0.js → Integrations-Bt2T0de9.js} +2 -2
  25. package/dist/assets/Library-C8Nqeb04.js +1 -0
  26. package/dist/assets/Locations-DNX7SZA-.js +3 -0
  27. package/dist/assets/{Logs-DSr8wCY-.js → Logs-D-XjeX6Q.js} +1 -1
  28. package/dist/assets/{MaskShapeCanvas-_BFcQxc-.js → MaskShapeCanvas-DIwpaQeo.js} +1 -1
  29. package/dist/assets/{MotionZonesSettings-DJDcu3fl.js → MotionZonesSettings-CSbx0QDE.js} +1 -1
  30. package/dist/assets/MyAccess-DY-Mr8w0.js +2 -0
  31. package/dist/assets/Network-CBlY8YKh.js +1 -0
  32. package/dist/assets/NewExportModal-DQeqPWZf.js +1 -0
  33. package/dist/assets/NodeAddonsSettingsPanel-CR7F2HPi.js +1 -0
  34. package/dist/assets/Notifications-BLVeFuqL.js +1 -0
  35. package/dist/assets/{PanelContent-DJ8p-hQ1.js → PanelContent-_b3IZ4jp.js} +2 -2
  36. package/dist/assets/Pipeline-BH757Q4y.js +1 -0
  37. package/dist/assets/{PrivacyMaskSettings-Dx5nRU-t.js → PrivacyMaskSettings-wIoHPyAB.js} +1 -1
  38. package/dist/assets/{SceneMonitorEditor-DFZ94G-a.js → SceneMonitorEditor-CgSpBLHL.js} +1 -1
  39. package/dist/assets/SessionsList-DAl5HWdR.js +2 -0
  40. package/dist/assets/{Showroom-DO1bQcNO.js → Showroom-CLeEbai0.js} +1 -1
  41. package/dist/assets/{StorageLocationsTable-BymZx5tG.js → StorageLocationsTable-Dm85ve5F.js} +1 -1
  42. package/dist/assets/System-BHnJ7qym.js +1 -0
  43. package/dist/assets/TemplateEditorDialog-D6yiZOgv.js +1 -0
  44. package/dist/assets/{TerminalPanel-BeJx-I2E.js → Terminal-BBmwTJmz.js} +5 -3
  45. package/dist/assets/{TrainingProviders-CPV9_SJC.js → TrainingProviders-ZSQkR2BW.js} +1 -1
  46. package/dist/assets/{Viewer-BN42pCqQ.js → Viewer-C4Ae2Vsy.js} +1 -1
  47. package/dist/assets/{__vite-browser-external-B6QEsNSJ.js → __vite-browser-external-DIbVKiho.js} +1 -1
  48. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DQNUYumg.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-UPf5SCPP.js} +1 -1
  49. package/dist/assets/{action-draft-BBdPH6FV.js → action-draft-R9VQXuuL.js} +1 -1
  50. package/dist/assets/{ai-page.helpers-ChgVcsV9.js → ai-page.helpers-DDnyI4U7.js} +1 -1
  51. package/dist/assets/{assignment-candidates-Bs3KAjz2.js → assignment-candidates-CuwMc1Y3.js} +1 -1
  52. package/dist/assets/{authed-media-BK50tJc4.js → authed-media-Yoylp29g.js} +1 -1
  53. package/dist/assets/{board-model-CWzkqJEj.js → board-model-D56hE08L.js} +1 -1
  54. package/dist/assets/camera-block-model-B87eQSrS.js +1 -0
  55. package/dist/assets/client-C--uWl5x.js +1120 -0
  56. package/dist/assets/{command-vocab-B3pUOKtp.js → command-vocab-CUgG-vto.js} +1 -1
  57. package/dist/assets/{device-detail-B0RHrAPi.js → device-detail-CTwVaaMw.js} +1 -1
  58. package/dist/assets/{device-integration-icon-JcMIVFtX.js → device-integration-icon-BMAR8TfE.js} +1 -1
  59. package/dist/assets/device-picker-model-BGR7et-m.js +1 -0
  60. package/dist/assets/dist-BjwNxivB.js +1 -0
  61. package/dist/assets/dist-r6ocATFb.js +1120 -0
  62. package/dist/assets/{format-iFFzavy7.js → format-BkMEj2-U.js} +1 -1
  63. package/dist/assets/{hostInit-CzaZPFle.js → hostInit-BII8RP3f.js} +1 -1
  64. package/dist/assets/i18n-BwW8nRaE.js +1 -0
  65. package/dist/assets/icons-D5Ap2eA5.js +1 -0
  66. package/dist/assets/index-Bz3Pl5tG.css +2 -0
  67. package/dist/assets/index-CCTNwAi2.js +6 -0
  68. package/dist/assets/{linked-devices-model-CuXMtCW5.js → linked-devices-model-DbsUI34s.js} +1 -1
  69. package/dist/assets/{mf-entry-bootstrap-0-02bb2c8e.js → mf-entry-bootstrap-0-83a08d0a.js} +2 -2
  70. package/dist/assets/mount-BGR7et-m.js +1 -0
  71. package/dist/assets/{notification-rule-status-zg20pl7f.js → notification-rule-status-CObTJD-i.js} +1 -1
  72. package/dist/assets/player-overlays-DKhojv7W.js +1 -0
  73. package/dist/assets/remoteEntry-BVF2kCJK.js +1 -0
  74. package/dist/assets/{circle-play-BxUrE_Qy.js → scissors-DpiKUioV.js} +1 -1
  75. package/dist/assets/settings-section-shape-DbQZZpNL.js +1 -0
  76. package/dist/assets/src-BpSavQVe.js +279 -0
  77. package/dist/assets/{sso-popup-CdVjmZ9n.js → sso-popup-BRNSJ3u5.js} +1 -1
  78. package/dist/assets/{step-inspector-model-CxSQZZiN.js → step-inspector-model-vNRpA1zj.js} +1 -1
  79. package/dist/assets/{terminal-Dgb4lrgM.js → terminal-DZ5OZpgC.js} +1 -1
  80. package/dist/assets/{use-scenes-feed-BW5wMevx.js → use-scenes-feed-B5mMm_aS.js} +1 -1
  81. package/dist/assets/{useAdminDeviceRemoval-kU8epr6n.js → useAdminDeviceRemoval-D14n1vjW.js} +1 -1
  82. package/dist/assets/useEventInvalidation-BGR7et-m.js +1 -0
  83. package/dist/assets/{useNodeUrlSelection-CfN-OrGq.js → useNodeUrlSelection-BYENLdUH.js} +1 -1
  84. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D3AQM66O.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BccQkG1p.js} +2 -2
  85. package/dist/index.html +11 -11
  86. package/dist/server/addon.js +1333 -181
  87. package/package.json +2 -2
  88. package/dist/assets/Addons-Ckr6vlsW.js +0 -5
  89. package/dist/assets/AiProfiles-DZj0TWuh.js +0 -3
  90. package/dist/assets/Archive-B0FJwta9.js +0 -1
  91. package/dist/assets/ArchiveCamera-DdovP4ro.js +0 -1
  92. package/dist/assets/BootstrapSettingsForm-CKBDm4C-.js +0 -1
  93. package/dist/assets/Build-B3CB1er7.js +0 -40
  94. package/dist/assets/CameraGrids-A_aGLmzE.js +0 -1
  95. package/dist/assets/Cluster-D2auKPXI.js +0 -1
  96. package/dist/assets/CompositionBlockEditor-DtVxeX5F.js +0 -2
  97. package/dist/assets/CompositionEditorPage-BvetDCib.js +0 -1
  98. package/dist/assets/Data-oQJyojZK.js +0 -2
  99. package/dist/assets/DeviceDetail-DPxmWhcP.js +0 -1
  100. package/dist/assets/History-jl2iyeKb.js +0 -1
  101. package/dist/assets/Identity-BpPWgRxJ.js +0 -1
  102. package/dist/assets/InstancesTable-DIKWKA5W.js +0 -1
  103. package/dist/assets/IntegrationDetail-ClVirS0M.js +0 -1
  104. package/dist/assets/Integrations-CprYyiDb.js +0 -1
  105. package/dist/assets/Library-B86tjZ0-.js +0 -1
  106. package/dist/assets/Locations-CpNbotTl.js +0 -3
  107. package/dist/assets/MyAccess-DqKyBAxI.js +0 -2
  108. package/dist/assets/Network-Csm4YFXB.js +0 -1
  109. package/dist/assets/NodeAddonsSettingsPanel-FjpwQjGM.js +0 -2
  110. package/dist/assets/Notifications-B-JLj82A.js +0 -1
  111. package/dist/assets/Pipeline-DIXgco7S.js +0 -1
  112. package/dist/assets/ServerShell-BYRylYTw.js +0 -1
  113. package/dist/assets/SessionsList-BcO2x9OZ.js +0 -2
  114. package/dist/assets/System-dsyXpTx9.js +0 -1
  115. package/dist/assets/TemplateEditorDialog-DJIaNKn3.js +0 -1
  116. package/dist/assets/Terminal-BiXbwaPr.js +0 -3
  117. package/dist/assets/client-DhfZUoXe.js +0 -1120
  118. package/dist/assets/device-picker-model-B2oUIKRS.js +0 -1
  119. package/dist/assets/dist-BNuE6NKf.js +0 -1
  120. package/dist/assets/dist-CyFeeFb8.js +0 -1120
  121. package/dist/assets/i18n-DCYaeyv_.js +0 -1
  122. package/dist/assets/icons-CXirq6Hu.js +0 -1
  123. package/dist/assets/index-CpurjMmX.css +0 -2
  124. package/dist/assets/index-DPyWa2vo.js +0 -6
  125. package/dist/assets/mount-B2oUIKRS.js +0 -1
  126. package/dist/assets/player-overlays-BF9w4QU-.js +0 -1
  127. package/dist/assets/remoteEntry-ZZWQQQTl.js +0 -1
  128. package/dist/assets/scissors-Bbq6WhOK.js +0 -1
  129. package/dist/assets/src-D9hgltMI.js +0 -279
  130. package/dist/assets/use-archive-data-D7nUbRKv.js +0 -1
  131. package/dist/assets/use-paged-list-DTJY2xpg.js +0 -1
  132. package/dist/assets/useEventInvalidation-B2oUIKRS.js +0 -1
  133. /package/dist/assets/{TerminalPanel-kHJ-D0s7.css → Terminal-kHJ-D0s7.css} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.2.690",
3
+ "version": "1.2.692",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Admin UI — Vite frontend build and server-side addon",
@@ -50,7 +50,7 @@
50
50
  }
51
51
  ],
52
52
  "requires": {
53
- "server": ">=1.2.890"
53
+ "server": ">=1.2.892"
54
54
  }
55
55
  },
56
56
  "scripts": {
@@ -1,5 +0,0 @@
1
- import{B as e,C as t,J as n,K as r,R as i,S as a,V as o,Y as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as d,Gt as f,In as p,Ki as m,Lr as h,Q as g,Ri as _,Tn as v,Tt as y,Vn as b,Yn as x,Zt as S,ct as ee,ea as te,er as C,ft as w,hr as T,ot as ne,ra as E,tn as D,xi as re}from"./player-overlays-BF9w4QU-.js";import{Zc as O}from"./client-DhfZUoXe.js";import{t as ie}from"./chevron-down-CBb-F8DT.js";import{d as k,i as ae}from"./terminal-Dgb4lrgM.js";import{$a as A,$f as j,Bi as oe,Fp as M,Hi as se,Ja as ce,Ka as le,Mp as N,Qa as ue,Ri as de,Ui as fe,Vl as P,Wi as F,Xa as pe,Ya as I,Za as me,ao as L,ct as R,do as z,ei as he,eo as ge,fo as B,fr as V,go as _e,ho as H,io as ve,li as U,lo as ye,mo as W,ni as be,oo as xe,pr as Se,qc as G,ri as Ce,ro as we,so as Te,sp as Ee,ti as De,to as Oe,uo as ke,vt as K,ya as Ae,zi as je}from"./src-D9hgltMI.js";import{t as q}from"./useTranslation-BJr-n0es.js";import"./mount-B2oUIKRS.js";import{_i as Me,dt as Ne,pi as Pe,ut as Fe,yi as Ie}from"./index-DPyWa2vo.js";import{t as J}from"./AdminPage-z8USGyNk.js";import{t as Y}from"./NodeAddonsSettingsPanel-FjpwQjGM.js";import{i as Le,r as Re,t as ze}from"./addon-kind-filter-CEGKkC1O.js";import{n as X,r as Be,t as Ve}from"./useNodeUrlSelection-CfN-OrGq.js";function He(e){if(e===void 0)return null;switch(e.state){case`failed`:case`refused`:case`missing`:case`crashed`:return{kind:e.state,...e.reason===void 0?{}:{reason:e.reason}};default:return null}}c();var Ue={queued:{icon:_,bg:`bg-muted text-foreground-subtle`,labelKey:`addons.addonRowBadge.queued`},updating:{icon:h,bg:`bg-primary/10 text-primary`,labelKey:`addons.addonRowBadge.updating`,spin:!0},"done-pending-restart":{icon:x,bg:`bg-amber-500/10 text-amber-700`,labelKey:`addons.addonRowBadge.pendingRestart`},done:{icon:E,bg:`bg-success/10 text-success`,labelKey:`addons.addonRowBadge.done`},failed:{icon:ae,bg:`bg-danger/10 text-danger`,labelKey:`addons.addonRowBadge.failed`}};function Z({item:e}){let{t:n}=q(),r=Ue[e.status],i=r.icon;return t(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${r.bg}`,title:e.error,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey)]})}var Q=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),We=new Set([`done`,`failed`,`skipped`]);function Ge(e){return!We.has(e.phase)&&!Q.has(e.jobState)}function Ke(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=Q.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 qe(){let{data:e}=ve({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=M(O.AddonsJobProgress,e=>e.job.jobId);return r(()=>{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 Ke([...n.values()],Date.now())},[e,t])}var Je={queued:{icon:_,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.queued`},fetching:{icon:h,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.fetching`,spin:!0},staged:{icon:h,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.staged`,spin:!0},validating:{icon:h,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.validating`,spin:!0},applying:{icon:h,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.applying`,spin:!0},restarting:{icon:h,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,labelKey:`addons.jobProgress.restarting`,spin:!0},applied:{icon:h,cls:`bg-primary/10 text-primary`,labelKey:`addons.jobProgress.finalizing`,spin:!0},done:{icon:E,cls:`bg-success/10 text-success`,labelKey:`addons.jobProgress.updated`},failed:{icon:ae,cls:`bg-danger/10 text-danger`,labelKey:`addons.jobProgress.failed`},skipped:{icon:v,cls:`bg-muted text-foreground-subtle`,labelKey:`addons.jobProgress.skipped`}};function Ye({progress:e}){let{t:n}=q(),r=Je[e.phase],i=r.icon,o=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return t(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${r.cls}`,title:o,children:[a(i,{className:`w-2.5 h-2.5 ${r.spin?`animate-spin`:``}`}),n(r.labelKey),t(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function Xe(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 Ze(e){let t=e.version===null?``:` ${e.version}`,n=e.isOnline?``:` (offline: removed when it reconnects)`;return`- ${e.nodeName}${t}${n}`}function Qe(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(Ze)];return n.length>0&&r.push(`Could not ask: ${n.join(`, `)} — not included.`),r.push(`This cannot be undone.`),r.join(`
2
- `)}function $e(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 et={uninstalled:`uninstalled`,"not-installed":`was not installed`,refused:`REFUSED`,failed:`FAILED`,"pending-reconnect":`offline — removed when it reconnects`};function tt(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)}: ${et[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 nt={},rt=3e4,it=`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 at({packageName:e,displayName:n,selectedNode:r,hideNodeAction:i,disabled:o}){let{t:s}=q(),c=l(),u=ee(),d=ne(),f=we(nt,{staleTime:rt}),p=f.data?.installations??[],m=(f.data?.unreachable??[]).map(e=>e.nodeId),h=Xe(p,e),g=e=>h.find(t=>t.nodeId===e)?.nodeName??(e===r.id?r.name:e),_=H({onSettled:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`nodes`]]})}}),v=async e=>{await d({title:e.success?s(`addons.addonUninstallControls.uninstalled`,`{{displayName}} uninstalled`,{displayName:n}):s(`addons.addonUninstallControls.notEveryNodeWasCleaned`,`{{displayName}}: not every node was cleaned`,{displayName:n}),message:tt(e,g),variant:e.success?`default`:`danger`})},y=async t=>{try{await v(await _.mutateAsync({packageName:e,...t}))}catch(e){await d({title:s(`addons.addonUninstallControls.uninstallFailed`,`Uninstall {{displayName}} failed`,{displayName:n}),message:e instanceof Error?e.message:String(e),variant:`danger`})}},b=async()=>{let e=h.filter(e=>e.nodeId!==r.id);await u({title:s(`addons.addonUninstallControls.uninstallFrom`,`Uninstall {{displayName}} from {{name}}?`,{displayName:n,name:r.name}),message:$e(n,r.name,e),confirmLabel:s(`addons.addonUninstallControls.uninstall`,`Uninstall`),variant:`danger`})&&await y(r.isHub?{}:{nodeId:r.id})},x=async()=>{let t=(await f.refetch()).data;if(t===void 0){await d({title:s(`addons.addonUninstallControls.cannotListTheNodes`,`Cannot list the nodes`),message:s(`addons.addonUninstallControls.theHubDidNotAnswer`,`The hub did not answer which nodes have this package — nothing was removed.`),variant:`danger`});return}let r=Xe(t.installations,e);await u({title:s(`addons.addonUninstallControls.uninstallEverywhere`,`Uninstall {{displayName}} everywhere?`,{displayName:n}),message:Qe(n,r,t.unreachable.map(e=>e.nodeId)),confirmLabel:s(`addons.addonUninstallControls.uninstallFromNodeS`,`Uninstall from {{length}} node(s)`,{length:r.length}),variant:`danger`})&&await y({everywhere:!0})},S=_.isPending||o===!0;return t(`div`,{className:`flex items-center gap-1.5`,children:[i!==!0&&t(j,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),b()},disabled:S,className:it,title:s(`addons.addonUninstallControls.uninstallFrom2`,`Uninstall from {{name}}`,{name:r.name}),children:[a(D,{className:`h-3 w-3`}),_.isPending?s(`addons.addonUninstallControls.removing`,`Removing...`):s(`addons.addonUninstallControls.uninstall`,`Uninstall`)]}),(h.length>1||i===!0||m.length>0)&&t(j,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),x()},disabled:S,className:it,title:s(`addons.addonUninstallControls.uninstallFromEveryNodeThat`,`Uninstall from every node that has it`),children:[a(k,{className:`h-3 w-3`}),h.length>0?s(`addons.uninstallControls.everywhereCount`,{count:h.length}):s(`addons.uninstallControls.everywhere`)]})]})}function ot(e){return typeof e.deprecated==`string`&&e.deprecated.length>0}function st(e,t){return t?e:e.filter(e=>e.distTags.includes(`latest`)||!ot(e))}function ct(e){return e.length-st(e,!1).length}c();function lt({packageName:e,currentVersion:n,installSource:r,onInstall:i,onClose:o,onSelect:c,selectedVersion:l}){let{t:d}=q(),p=r===`upload`||r===`local`,[m,g]=s(!1),{data:_,isLoading:v,isError:b}=A({name:e}),x=_?st(_,m):[],S=_?ct(_):0;return t(`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:[t(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[a(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:d(`addons.versionPicker.versions`,`Versions`)}),a(j,{variant:`unstyled`,type:`button`,onClick:o,className:`text-foreground-subtle hover:text-foreground`,children:a(y,{className:`h-3 w-3`})})]}),p&&t(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[a(f,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),t(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[a(`span`,{className:`font-semibold`,children:d(`addons.versionPicker.inPlace`,{kind:r===`upload`?d(`addons.versionPicker.uploadedCopy`,`Uploaded copy`):d(`addons.versionPicker.localCopy`,`Local copy`)})}),` `,a(Pe,{i18nKey:`addons.versionPicker.reinstall`,values:{version:n},components:{mono:a(`span`,{className:`font-mono`})}})]})]}),v&&t(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[a(h,{className:`h-3.5 w-3.5 animate-spin`}),d(`addons.versionPicker.loadingVersions`,`Loading versions...`)]}),b&&a(`div`,{className:`px-3 py-4 text-center text-[10px] text-danger`,children:d(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),x.length>0&&a(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:x.map(e=>{let r=e.version===n,o=c!==void 0&&e.version===l,s=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),f=t(u,{children:[a(`span`,{className:`font-mono flex-1 text-left ${r?`text-primary font-semibold`:s?`text-amber-400`:`text-foreground`}`,children:e.version}),r&&a(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:d(`common.current`)}),e.distTags.map(e=>a(`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)),ot(e)&&a(`span`,{className:`text-[9px] text-red-400 line-through`,children:d(`common.deprecated`)}),a(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return c?t(j,{variant:`unstyled`,type:`button`,"aria-label":d(`addons.versionPicker.select`,`Select {{version}}`,{version:e.version}),onClick:()=>c(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${o?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,o?a(E,{className:`h-3 w-3 text-primary shrink-0`}):a(`span`,{className:`w-3 shrink-0`})]},e.version):t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${r?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[f,a(j,{variant:`unstyled`,type:`button`,onClick:()=>i(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:r?d(`addons.versionPicker.reInstallFromNpm`,`Re-install {{version}} from npm`,{version:e.version}):d(`addons.versionPicker.install`,`Install {{version}}`,{version:e.version}),children:a(re,{className:`h-3 w-3`})})]},e.version)})}),!v&&!b&&_&&_.length===0&&a(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:d(`addons.versionPicker.noVersionsFound`,`No versions found`)}),S>0&&a(j,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto w-full justify-start rounded-none border-t border-border px-3 py-2 text-left text-[10px] font-normal text-foreground-subtle`,onClick:()=>g(e=>!e),children:m?d(`addons.versionPicker.hideOlder`,`Hide older versions`):d(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:S})})]})}c();var ut=`device-export`;function dt(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===ut)}function ft(e){return e!==`local`&&e!==`upload`}function pt({isBundle:e,installSource:n,addonId:r,iconPath:i,color:o}){let[c,l]=s(!1),u=o?{backgroundColor:`${o.startsWith(`#`)?o:`#${o}`}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`,p=r&&i?g(`/api/addon-assets/${r}/${i}`):null,m=!!p&&!c;return t(`div`,{className:`relative flex-shrink-0`,children:[a(`div`,{className:`h-8 w-8 rounded-md flex items-center justify-center ${u?``:d}`,style:u,children:m?a(`img`,{src:p,alt:r,className:`h-4 w-4`,onError:()=>l(!0)}):a(e?T:C,{className:`h-3.5 w-3.5`})}),n===`local`&&a(`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`}),ft(n)&&a(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:a(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:a(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),n===`upload`&&a(`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:a(f,{className:`h-2.5 w-2.5 text-white`})})]})}function mt({version:e,availableUpdate:n,selectedVersion:r,isUpdating:i,installSource:o,disabled:s,onUpdate:c,onOpenPicker:l,children:u}){let{t:d}=q();if(i)return t(`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:[a(h,{className:`h-3 w-3 animate-spin`}),d(`addons.addonCard.updating`,`Updating…`)]});if(n){let i=r??n;return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[c&&t(j,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:s,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:d(`addons.addonCard.updateTo`,`Update to {{target}}`,{target:i}),children:[a(re,{className:`h-3 w-3`}),d(`addons.addonCard.update`,`Update`)]}),t(j,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,"aria-label":d(`addons.addonCard.selectVersionToInstall`,`Select version to install`),title:d(`addons.addonCard.installedUpdateAvailableSelectedTap`,`Installed {{version}} — update available. Selected {{target}}; tap to choose another version.`,{version:e,target:i}),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:[a(`span`,{className:`font-normal opacity-70`,children:e}),a(`span`,{className:`font-normal opacity-70`,children:`→`}),i,a(ie,{className:`h-3 w-3`})]}),u]})}return t(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[t(j,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),l()},disabled:s,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`,o===`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:d(`addons.addonCard.versionTapToViewAll`,`Version {{version}} — tap to view all versions`,{version:e}),children:[e,a(ie,{className:`h-3 w-3 opacity-50`})]}),u]})}function ht({addonId:e}){let t=l(),{data:n=`inherit`}=I({addonId:e}),r=z({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return a(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>a(j,{variant:`unstyled`,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 gt={id:`hub`,name:`Hub`,isHub:!0};function _t({addon:e,clusterStatus:n,hideVersion:r,availableUpdate:i,blockedUpdate:c,onUpdateServer:d,onUpdate:f,isUpdating:m,jobProgress:h,bundle:g,bulkItem:_,disabledByBulk:v,isSystem:S,selectedNode:ee}){let{t:C}=q(),[w,ne]=s(!1),[E,D]=s(!1),[re,O]=s(null);o(()=>{O(null)},[i]);let k=re??i,[A,M]=s(!1),[ce,le]=s(!1),[N,ue]=s(`logs`),P=l(),pe=Me(),{manifest:I}=e,me=!g&&!I.protected&&I.removable!==!1,L=!!g,R=g?.displayName??I.name,z=g?.packageName??I.packageName,he=g?.version??I.packageVersion??I.version,B=g?.installSource??e.installSource,_e=g?g.bundle?.description??g.addons[0]?.manifest.description:I.description,H=Te({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]})}}),ve=ge({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]}),P.invalidateQueries({queryKey:[[`integrations`]]})}}),U=ye({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`alerts`]]})}}),W=e.health,be=W?.phase===`failed`&&!W.inGracePeriod,xe=be&&W?.nextRetryAt&&!W.retrying,G=He(e.process);return t(`div`,{className:`rounded-md border bg-surface overflow-hidden ${be?`border-red-500/50`:`border-border`}`,children:[be&&W&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(ae,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:C(`addons.addonCard.failedToLoad`,{attempt:W.retryCount})}),a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:W.lastError?.message??C(`addons.addonCard.unknownError`,`Unknown error`)}),xe&&W.nextRetryAt&&a(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:C(`addons.addonCard.autoRetryAt`,{time:new Date(W.nextRetryAt).toLocaleTimeString()})})]}),t(j,{variant:`unstyled`,type:`button`,disabled:U.isPending||W.retrying,onClick:e=>{e.stopPropagation(),U.mutate({packageName:z})},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:C(`addons.addonCard.resetRetryCounterAndForce`,`Reset retry counter and force immediate reload`),children:[a(x,{className:`h-3 w-3 ${U.isPending||W.retrying?`animate-spin`:``}`}),C(`addons.addonCard.retryNow`,`Retry now`)]})]}),G!==null&&t(`div`,{className:`bg-danger/10 border-b border-danger/30 px-3 py-2 flex items-start gap-2`,children:[a(ae,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),t(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`text-xs font-semibold text-danger`,children:C(`addons.addonCard.processProblem.${G.kind}`)}),G.reason!==void 0&&a(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:G.reason})]})]}),t(`div`,{className:`flex items-start gap-2.5 px-3 py-2`,children:[a(pt,{isBundle:L||!!I.components&&I.components.length>1,installSource:B,addonId:L?g.addons[0]?.manifest.id:I.id,iconPath:L?g.bundle?.icon??g.addons[0]?.manifest.icon:I.icon,color:L?g.addons[0]?.manifest.color:I.color}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-start justify-between gap-2`,children:[a(`span`,{className:`text-xs font-semibold text-foreground truncate min-w-0`,children:R}),!r&&a(mt,{version:he,availableUpdate:i,...k===void 0?{}:{selectedVersion:k},isUpdating:m,installSource:B,disabled:v,...f&&k!==void 0?{onUpdate:()=>f(k)}:{},onOpenPicker:()=>D(e=>!e),children:E&&a(lt,{packageName:z,currentVersion:he,...B?{installSource:B}:{},...i!==void 0&&k!==void 0?{selectedVersion:k,onSelect:e=>{O(e),D(!1)}}:{},onInstall:e=>{D(!1),ve.mutate({packageName:z,version:e})},onClose:()=>D(!1)})})]}),t(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[z!==R&&a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:z}),L&&t(`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:[a(T,{className:`h-3 w-3`}),g.addons.length]}),S&&t(`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:C(`addons.addonCard.systemPackageUpdatingRestartsThe`,`System package — updating restarts the hub`),children:[a(x,{className:`h-3 w-3`}),C(`addons.addonCard.system`,`System`)]}),_!=null&&a(Z,{item:_}),c!==void 0&&a(Ae,{variant:`warning`,title:C(`addons.addonCard.updateHeldTitle`,{defaultValue:`{{latest}} is held until the server is {{required}} or newer`,latest:c.latestVersion,required:c.requiredServer}),children:C(`addons.addonCard.requiresServer`,{defaultValue:`requires server ≥ {{version}}`,version:c.requiredServer})}),c!==void 0&&d!==void 0&&a(j,{type:`button`,size:`sm`,variant:`secondary`,onClick:d,children:C(`clusterUpdate.updateServer`,`Update server`)}),h!=null&&a(Ye,{progress:h})]}),_e&&a(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:_e}),!L&&e.process&&t(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a(`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`?C(`addons.addonCard.forked`):C(`addons.addonCard.inProcess`)}),e.process.pid!=null&&t(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),a(`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`:G===null?`bg-gray-500/15 text-gray-400`:`bg-red-500/15 text-red-400`}`,children:e.process.state})]})]})]}),!L&&t(`div`,{className:`flex items-center gap-1 px-3 py-1 border-t border-border/50 bg-surface-hover/20`,children:[t(j,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),H.mutate({addonId:I.id})},disabled:H.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:[a(x,{className:`h-3 w-3 ${H.isPending?`animate-spin`:``}`}),C(`addons.addonCard.restart`,`Restart`)]}),t(j,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),M(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${A?`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:[a(b,{className:`h-3 w-3`}),C(`addons.addonCard.logs`,`Logs`)]}),!L&&t(j,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),le(!0)},className:`inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium border transition-colors ${ce?`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:[a(p,{className:`h-3 w-3`}),C(`addons.addonCard.settings`,`Settings`)]}),a(`div`,{className:`flex-1`}),me&&a(at,{packageName:I.packageName,displayName:I.name,selectedNode:ee??gt,disabled:v})]}),n&&n.nodes.length>1&&!L&&t(`div`,{className:`border-t border-border px-3 py-1.5 bg-muted/10`,children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:C(`addons.addonCard.clusterDeployment`,`Cluster Deployment`)}),a(`div`,{className:`space-y-1`,children:n.nodes.map(e=>t(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[a(`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`}`}),a(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),a(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:C(`addons.addonCard.outdated`)}),e.status===`offline`&&a(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:C(`common.offline`)}),e.synced&&e.status!==`offline`&&a(`span`,{className:`text-[9px] text-success`,children:C(`common.synced`)})]},e.nodeId))})]}),A&&!L&&t(`div`,{className:`border-t border-border`,children:[t(`div`,{className:`flex items-center px-3 py-0.5 bg-surface-hover/20 border-b border-border/50`,children:[t(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[a(j,{variant:`unstyled`,type:`button`,onClick:()=>ue(`logs`),className:`px-2 py-0.5 transition-colors ${N===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:C(`addons.addonCard.logs`,`Logs`)}),a(j,{variant:`unstyled`,type:`button`,onClick:()=>ue(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${N===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:C(`addons.addonCard.events`,`Events`)})]}),a(`div`,{className:`flex-1`}),a(j,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),M(!1)},className:`text-foreground-subtle hover:text-foreground`,children:a(y,{className:`h-3.5 w-3.5`})})]}),N===`logs`&&a(Se,{addonId:I.id,maxHeight:`max-h-64`,showFilters:!1}),N===`events`&&a(V,{addonId:I.id,category:`addon.*`,maxHeight:`max-h-64`})]}),L&&t(u,{children:[a(j,{variant:`unstyled`,type:`button`,onClick:()=>ne(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:a(w?te:ie,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),w&&a(`div`,{className:`border-t border-border px-2.5 py-1.5 space-y-1.5`,children:g.addons.map(e=>a(_t,{addon:e,hideVersion:!0},e.manifest.id))})]}),ce&&!L&&a(de,{open:!0,onOpenChange:e=>!e&&le(!1),children:t(oe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(fe,{children:t(F,{className:`flex items-center gap-2`,children:[a(p,{className:`h-4 w-4 text-primary`}),C(`addons.addonCard.settingsTitle`,{name:R})]})}),t(je,{className:`space-y-4`,children:[a(`div`,{className:`text-[10px] text-foreground-subtle mb-2`,children:C(`addons.addonCard.clusterWideSettingsOneValue`,`Cluster-wide settings — one value for every node. Per-node settings live under Cluster → the node → Settings.`)}),a(Y,{nodeId:null,addonIds:[I.id],level:`global`,fieldScope:`cluster`,emptyMessage:C(`addons.addonCard.thisAddonExposesNoCluster`,`This addon exposes no cluster-wide settings. Anything it can configure is per-node — open it from Cluster → the node → Settings.`)}),dt(I)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:C(`addons.addonCard.deviceExport`,`Device export`)}),a(K,{addonId:I.id,onOpenDevice:e=>pe(`/devices/${e}`)})]}),ft(B)&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:C(`addons.addonCard.autoUpdate`,`Auto-Update`)}),a(ht,{addonId:I.id})]}),I.components&&I.components.length>0&&t(`div`,{children:[a(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:C(`addons.addonCard.components`,{count:I.components.length})}),a(`div`,{className:`flex flex-wrap gap-1`,children:I.components.map(e=>a(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]})]}),a(se,{children:a(j,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>le(!1),children:C(`common.close`,`Close`)})})]})})]})}c();var vt=`.tgz,.tar.gz,.zip`;function yt({onUploadSuccess:e}){let{t:r}=q(),[o,c]=s(!1),l=n(null),d=i(async t=>{c(!0);let n=new FormData;n.append(`file`,t);let r=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(g(`/api/addons/upload`),{method:`POST`,headers:{Authorization:`Bearer ${r}`},body:n})).json()).success&&e()}finally{c(!1)}},[e]);return t(u,{children:[a(U,{ref:l,accept:vt,onChange:i(e=>{let t=e.target.files?.[0];t&&d(t),e.target.value=``},[d]),className:`hidden`}),t(j,{variant:`unstyled`,type:`button`,onClick:()=>l.current?.click(),disabled:o,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:[o?a(h,{className:`w-3.5 h-3.5 animate-spin`}):a(f,{className:`w-3.5 h-3.5`}),o?r(`addons.addonUploadZone.uploading`,`Uploading...`):r(`addons.addonUploadZone.upload`,`Upload`)]})]})}var bt=/```[^\n]*\n([\s\S]*?)```/g;function xt(e){let t=[],n=0;for(let r of e.matchAll(bt)){let i=r.index??0;i>n&&t.push({kind:`text`,body:e.slice(n,i)}),t.push({kind:`code`,body:r[1]??``}),n=i+r[0].length}return n<e.length&&t.push({kind:`text`,body:e.slice(n)}),t}function St(e){let t=e.trim();return t.startsWith(`https://`)||t.startsWith(`http://`)?t:null}function Ct(e,t){let n=[],r=/(\*\*[^*]+\*\*|`[^`]+`|\[[^\]]+\]\([^)]+\))/g,i=0,o=0;for(let s of e.matchAll(r)){let r=s.index??0;r>i&&n.push(e.slice(i,r));let c=s[0],l=`${t}-${o}`;if(o+=1,c.startsWith(`**`))n.push(a(`strong`,{children:c.slice(2,-2)},l));else if(c.startsWith("`"))n.push(a(`code`,{className:`font-mono text-[0.9em]`,children:c.slice(1,-1)},l));else{let e=/^\[([^\]]+)\]\(([^)]+)\)$/.exec(c),t=e?.[1]??c,r=e?St(e[2]??``):null;n.push(r?a(`a`,{href:r,target:`_blank`,rel:`noreferrer noopener`,className:`text-primary underline`,children:t},l):a(`span`,{children:t},l))}i=r+c.length}return i<e.length&&n.push(e.slice(i)),n}function wt(e,t){let n=e.split(`
5
- `),r=[],i=[],o=[],s=0,c=()=>{if(i.length===0)return;let e=i.join(` `).trim();i=[],e.length!==0&&(r.push(a(`p`,{className:`mb-2 last:mb-0`,children:Ct(e,`${t}-p-${s}`)},`${t}-p-${s}`)),s+=1)},l=()=>{if(o.length===0)return;let e=o;o=[],r.push(a(`ul`,{className:`mb-2 list-disc pl-4 last:mb-0`,children:e.map((e,n)=>a(`li`,{children:Ct(e,`${t}-li-${s}-${n}`)},`${t}-li-${s}-${n}`))},`${t}-ul-${s}`)),s+=1};for(let e of n){let n=/^(#{1,3})\s+(.*)$/.exec(e),u=/^\s*[-*]\s+(.*)$/.exec(e);if(n){c(),l();let e=n[1]?.length??1,i=Ct(n[2]??``,`${t}-h-${s}`),o=e===1?`text-sm font-semibold mb-2`:`text-xs font-semibold mb-1.5 mt-2`;r.push(a(e===1?`h3`:`h4`,{className:o,children:i},`${t}-h-${s}`)),s+=1;continue}if(u){c(),o=[...o,u[1]??``];continue}if(e.trim().length===0){c(),l();continue}l(),i=[...i,e.trim()]}return c(),l(),r}function Tt({markdown:e}){return a(`div`,{className:`text-xs text-foreground leading-relaxed`,children:xt(e).map((e,t)=>e.kind===`code`?a(`pre`,{className:`mb-2 overflow-auto rounded-md bg-surface-hover p-2 font-mono text-[10px] last:mb-0`,children:e.body.replace(/\n$/,``)},`code-${t}`):a(`div`,{children:wt(e.body,`b${t}`)},`text-${t}`))})}c();function Et(e){return e.replace(/^@camstack\/(addon-)?/,``)}function Dt(e,t,n){let r=st(e,n);return r.some(e=>e.version===t)?r:[{version:t,distTags:[],deprecated:void 0},...r]}function Ot({pending:e,failed:n,body:r,missing:i}){let{t:o}=q();return e?t(`div`,{className:`flex items-center gap-2 py-6 text-xs text-foreground-subtle`,children:[a(h,{className:`h-3.5 w-3.5 animate-spin`}),o(`addons.installDialog.loadingDocument`,`Loading…`)]}):n||r===void 0?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.couldNotLoadDocument`,`Could not load this file from the registry.`)}):r.status===`ok`&&r.markdown!==void 0?a(Tt,{markdown:r.markdown}):r.status===`error`?a(`p`,{className:`py-4 text-xs text-danger`,children:o(`addons.installDialog.documentError`,`Could not load this file. {{message}}`,{message:r.message??``})}):a(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:i})}function kt({target:e,installing:n,installError:r,onClose:i,onInstall:o}){let{t:c}=q(),[l,u]=s(e.version),[d,f]=s(!1),p=A({name:e.name}),m=ue({name:e.name,version:l}),g=p.data??[],_=ct(g),v=Dt(g,l,d),y=m.data;return a(de,{open:!0,onOpenChange:e=>!e&&i(),children:t(oe,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(fe,{children:a(F,{children:c(`addons.installDialog.title`,`Install {{name}}`,{name:Et(e.name)})})}),t(je,{className:`space-y-3`,children:[a(`p`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.name}),e.description.length>0&&a(`p`,{className:`text-xs text-foreground`,children:e.description}),t(`div`,{className:`space-y-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:c(`addons.installDialog.version`,`Version`)}),a(w,{"aria-label":c(`addons.installDialog.version`,`Version`),value:l,options:v.map(e=>({value:e.version,label:ot(e)?c(`addons.installDialog.deprecatedVersion`,`{{version}} (deprecated)`,{version:e.version}):e.version})),onChange:e=>u(e.target.value)}),p.isError&&a(`p`,{className:`text-[10px] text-danger`,children:c(`addons.versionPicker.registryError`,`Could not load versions from the registry.`)}),_>0&&a(j,{type:`button`,variant:`ghost`,size:`sm`,className:`h-auto justify-start px-0 text-[10px] font-normal text-foreground-subtle underline`,onClick:()=>f(e=>!e),children:d?c(`addons.versionPicker.hideOlder`,`Hide older versions`):c(`addons.versionPicker.showOlder`,`Show older versions ({{count}})`,{count:_})})]}),t(he,{defaultValue:`readme`,children:[t(be,{children:[a(Ce,{value:`readme`,children:c(`addons.installDialog.readme`,`README`)}),a(Ce,{value:`changelog`,children:c(`addons.installDialog.changelog`,`CHANGELOG`)})]}),a(De,{value:`readme`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(Ot,{pending:m.isPending,failed:m.isError,body:y?.readme,missing:c(`addons.installDialog.missingReadme`,`This package has no README.`)})})}),a(De,{value:`changelog`,children:a(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border bg-background p-3`,children:a(Ot,{pending:m.isPending,failed:m.isError,body:y?.changelog,missing:c(`addons.installDialog.missingChangelog`,`This package has no CHANGELOG.`)})})})]}),r!=null&&r.length>0&&a(`p`,{className:`text-xs text-danger`,children:r})]}),t(se,{children:[a(j,{type:`button`,variant:`outline`,size:`sm`,onClick:i,children:c(`common.cancel`,`Cancel`)}),a(j,{type:`button`,size:`sm`,disabled:n||l.length===0,onClick:()=>o(e.name,l),children:n?a(h,{className:`h-3.5 w-3.5 animate-spin`}):c(`addons.installDialog.install`,`Install`)})]})]})})}function At(e,t){let n=new Map;for(let r of e){if(r.isHub||r.onHub||Ne(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 jt({selectedNode:e}){let{t:n}=q(),{data:r}=we(nt,{staleTime:rt});if(r===void 0)return null;let i=At(r.installations,e),o=r.unreachable.filter(t=>e.isHub||t.nodeId===e.id);return i.length===0&&o.length===0?null:t(`div`,{className:`rounded-lg border border-warning/30 bg-warning/5 px-3 py-2.5 space-y-2`,children:[t(`div`,{className:`flex items-center gap-2 text-[11px] font-semibold text-foreground`,children:[a(S,{className:`h-3.5 w-3.5 text-warning`}),e.isHub?n(`addons.nodeOnlyPackagesPanel.installedOnAgentsButNot`,`Installed on agents but not on the hub`):n(`addons.nodeOnlyPackagesPanel.installedOnButNotOn`,`Installed on {{name}} but not on the hub`,{name:e.name})]}),o.length>0&&a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n(`addons.nodeOnlyPackagesPanel.unreachable`,{nodes:o.map(e=>e.nodeId).join(`, `)})}),i.map(n=>t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap rounded-md border border-border bg-surface px-3 py-2`,children:[t(`div`,{className:`min-w-0`,children:[a(`div`,{className:`text-xs font-mono text-foreground break-all`,children:n.packageName}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:n.rows.map(e=>`${e.nodeName}${e.version===null?``:` ${e.version}`}${e.isOnline?``:` (offline)`}`).join(` · `)})]}),a(at,{packageName:n.packageName,displayName:n.packageName,selectedNode:e,hideNodeAction:e.isHub})]},n.packageName))]})}function Mt({addon:e,installing:n,onInstall:r}){let{t:i}=q();return t(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[a(`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()}),t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[a(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),t(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),a(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&a(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?a(Ae,{variant:`success`,icon:a(E,{className:`h-3 w-3`}),children:e.installedVersion??i(`system.capabilityCatalog.installed`,`Installed`)}):t(j,{size:`sm`,onClick:()=>r(e),disabled:n,className:`shrink-0`,children:[n?a(h,{className:`h-3 w-3 animate-spin`}):a(re,{className:`h-3 w-3`}),i(`system.capabilityCatalog.install`,`Install`)]})]})}function Nt({capability:e,installing:n,onInstall:r}){let{t:i}=q(),{data:o,isPending:s,isError:c}=ke({capability:e}),l;if(c)l=a(`div`,{className:`px-3 py-2 text-xs text-danger`,children:i(`system.capabilityCatalog.couldNotSearchTheNpm`,`Could not search the npm catalog right now. Try again in a moment.`)});else if(s||o===void 0)l=t(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs text-foreground-subtle`,children:[a(h,{className:`h-3 w-3 animate-spin`}),i(`system.capabilityCatalog.searchingTheNpmCatalog`,`Searching the npm catalog…`)]});else{let t=o.filter(e=>!e.installed);l=t.length===0?a(`div`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:o.length===0?i(`system.capabilityCatalog.noPublishedAddonDeclaresThe`,`No published addon declares the "{{capability}}" capability.`,{capability:e}):i(`system.capabilityCatalog.everyPublishedAddonThatDeclares`,`Every published addon that declares "{{capability}}" is already installed.`,{capability:e})}):a(`div`,{className:`divide-y divide-border`,children:t.map(e=>a(Mt,{addon:e,installing:n,onInstall:r},e.name))})}return t(`section`,{className:`rounded-md border border-border bg-surface overflow-hidden`,"aria-label":i(`system.capabilityCatalog.availableToInstall`,`Available to install`),children:[a(`h2`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:i(`system.capabilityCatalog.availableToInstall`,`Available to install`)}),l]})}c();function Pt(e){return e===`npm`||e===`dev`?e:null}var Ft=`rounded-full border border-primary bg-primary/10 px-2 py-0.5 text-[10px] text-foreground`,It=`rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-muted hover:bg-surface-hover`,Lt=[{seconds:900,label:`15m`},{seconds:3600,label:`1h`},{seconds:21600,label:`6h`},{seconds:43200,label:`12h`},{seconds:86400,label:`24h`}],Rt={id:`hub`,name:`Hub`,isHub:!0,isOnline:!0};function zt(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function Bt(e){return e===`local`?`dev`:`npm`}function Vt(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`,...r.reason===void 0?{}:{reason:r.reason}}: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 Ht(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 Ut({addons:c,clusterStatus:u,selectedNode:f,onRefresh:p,listPhase:g}){let{t:_}=q(),v=l(),[y,b]=s(``),[S,te]=s(!1),C=e(y),[T,ne]=s(!1),E=n(null);o(()=>{if(!T)return;let e=e=>{E.current&&!E.current.contains(e.target)&&ne(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[T]);let{data:D}=L({nodeId:f.id}),O=r(()=>{let e=new Map;for(let t of D??[])t.blockedBy===void 0&&e.set(t.name,t.latestVersion);return e},[D]),ie=r(()=>{let e=new Map;for(let t of D??[]){let n=t.blockedBy?.find(e=>e.kind===`server-too-old`);n!==void 0&&e.set(t.name,{latestVersion:t.latestVersion,requiredServer:n.required})}return e},[D]),k=r(()=>(D??[]).filter(e=>!e.isSystem&&e.blockedBy===void 0).length,[D]),[ae,A]=s(()=>new Set),[oe,M]=s(()=>new Map),se=i(e=>{A(t=>new Set(t).add(e))},[]),ce=i(e=>{A(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),N=i((e,t)=>{M(n=>new Map(n).set(e,t))},[]),ue=i(e=>{M(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),de=_e({onMutate:e=>{se(e.name),ue(e.name)},onSuccess:(e,t)=>{ce(t.name);let n=e;if(n&&n.success===!1){N(t.name,n.error??`Update failed (no error message returned by server)`);return}v.invalidateQueries({queryKey:[[`addons`]]}),v.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{ce(t.name),N(t.name,e instanceof Error?e.message:String(e))}}),fe=qe(),P=n(new Set);o(()=>{let e=new Set;for(let[t,n]of fe)Ge(n)&&e.add(t);let t=[...P.current].some(t=>!e.has(t));P.current=e,t&&(v.invalidateQueries({queryKey:[[`addons`]]}),v.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[fe,v]);let{data:F}=pe(void 0),I=le({onSuccess:()=>{v.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),R=B({onSuccess:()=>{v.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:z,isFetching:he}=ke({query:C||void 0},{enabled:T}),V=W(),{data:H}=me(void 0),ve=H?.requestedAt,[U,ye]=s(null),[be,xe]=s(!1);o(()=>{if(H?.kind===`framework-bulk-update`&&H.requestedAt!==U){ye(H.requestedAt),xe(!0);let e=window.setTimeout(()=>xe(!1),6e3);return()=>window.clearTimeout(e)}},[ve,U,H]),ee();let Se=i(async()=>{let e=(D??[]).filter(e=>!e.isSystem&&e.blockedBy===void 0);if(e.length!==0){if(!f.isHub){for(let t of e)await de.mutateAsync({name:t.name,version:t.latestVersion,nodeId:f.id});return}await V.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[f.id]})}},[D,f.id,f.isHub,V,de]),[Ce,we]=s(null),[Te,De]=s(null),Oe=e=>{De(null),we(e)},K=ge({onSuccess:()=>{we(null),De(null),v.invalidateQueries({queryKey:[[`addons`]]}),v.invalidateQueries({queryKey:[[`addonPages`]]}),v.invalidateQueries({queryKey:[[`capabilities`]]}),v.invalidateQueries({queryKey:[[`integrations`]]})},onError:e=>{De(e instanceof Error?e.message:`Install failed`)}}),[Ae,je]=s(`type`),[Me,Ne]=s(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),Pe=e=>{Ne(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[J,Y]=Ie(),X=J.get(`capability`),Ve=J.get(`updatable`)===`1`,Ue=J.get(`error`)===`1`,Z=Pt(J.get(`source`)),Q=Le(J.get(ze))===`integration`,{data:We}=G(void 0,{enabled:Q}),Ke=r(()=>We===void 0?null:new Set(We.map(e=>e.addonId)),[We]),Je=i(e=>{let t=new URLSearchParams(J);e?t.set(ze,`integration`):t.delete(ze),Y(t,{replace:!0})},[J,Y]),Ye=i(e=>{let t=new URLSearchParams(J);e?t.set(`updatable`,`1`):t.delete(`updatable`),Y(t,{replace:!0})},[J,Y]),Xe=i(e=>{let t=new URLSearchParams(J);e?t.set(`error`,`1`):t.delete(`error`),Y(t,{replace:!0})},[J,Y]),Ze=i(e=>{let t=new URLSearchParams(J);e===null?t.delete(`source`):t.set(`source`,e),Y(t,{replace:!0})},[J,Y]),Qe=r(()=>c.filter(e=>He(e.process)!==null).length,[c]),$e=r(()=>{let e=c.filter(e=>!Fe(e.manifest.packageName));return f.isHub||(e=e.filter(e=>zt(e.placement,f.isHub))),X&&(e=e.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===X))),Q&&(e=[...Re(e,Ke)]),Ve&&(e=e.filter(e=>{let t=e.manifest.packageName;return t!==void 0&&O.has(t)})),Z!==null&&(e=e.filter(e=>Bt(e.installSource)===Z)),Ue&&(e=e.filter(e=>He(e.process)!==null)),e},[c,f.isHub,X,Ve,Z,Ue,Q,Ke,O]),et=()=>{let e=new URLSearchParams(J);e.delete(`capability`),Y(e,{replace:!0})},tt=Me===`flat`?$e:Ht($e),nt=r(()=>{let e=[...tt];switch(Ae){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},[tt,Ae]);return t(`div`,{className:`space-y-3`,children:[a(Be,{open:S,onOpenChange:te}),[...oe.entries()].map(([e,n])=>a(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-2.5 py-1.5 text-[11px]`,children:t(`div`,{className:`flex items-start justify-between gap-3`,children:[t(`div`,{className:`space-y-0.5`,children:[a(`div`,{className:`font-medium text-danger`,children:_(`systemPage.addons.updateFailed`,{name:e})}),a(`div`,{className:`text-foreground-subtle font-mono`,children:n})]}),a(j,{variant:`unstyled`,type:`button`,onClick:()=>ue(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:_(`common.dismiss`)})]})},e)),t(`div`,{className:`flex items-center gap-x-2 gap-y-1.5 flex-wrap`,children:[t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:_(`admin.system.addons.sort`,`Sort:`)}),t(w,{wrapperClassName:`inline-block w-auto`,value:Ae,onChange:e=>je(e.target.value),children:[a(`option`,{value:`type`,children:_(`admin.system.addons.bundlesFirst`,`Bundles first`)}),a(`option`,{value:`name`,children:_(`admin.system.addons.name`,`Name`)}),a(`option`,{value:`source`,children:_(`admin.system.addons.installSource`,`Install source`)})]})]}),t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:_(`admin.system.addons.view`,`View:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>a(j,{variant:`unstyled`,type:`button`,onClick:()=>Pe(e),className:`px-2 py-1 transition-colors capitalize ${Me===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?_(`admin.system.addons.groupMultiAddonPackagesInto`,`Group multi-addon packages into a bundle card`):_(`admin.system.addons.showEveryAddonAsIts`,`Show every addon as its own card`),children:e},e))})]}),f.isHub&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(x,{className:`h-3 w-3 text-foreground-subtle`}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:_(`admin.system.addons.autoUpdate`,`Auto-Update:`)}),a(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>a(j,{variant:`unstyled`,type:`button`,onClick:()=>I.mutate({channel:e}),disabled:I.isPending,className:`px-2 py-1 transition-colors capitalize ${F?.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&&t(`div`,{className:`flex items-center gap-1.5`,children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:_(`admin.system.addons.checkEvery`,`Check every:`)}),a(w,{wrapperClassName:`inline-block w-auto`,className:`font-medium text-foreground-subtle`,value:F?.updateCheckIntervalSeconds??21600,disabled:R.isPending||F===void 0,onChange:e=>{F!==void 0&&R.mutate({channel:F.channel,updateCheckIntervalSeconds:Number(e.target.value)})},children:Lt.map(e=>a(`option`,{value:e.seconds,children:e.label},e.seconds))})]}),k>0&&t(j,{variant:`unstyled`,type:`button`,onClick:()=>void Se(),disabled:V.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:[V.isPending?a(h,{className:`w-3 h-3 animate-spin`}):a(re,{className:`w-3 h-3`}),V.isPending?_(`admin.system.addons.updating`,`Updating…`):_(`admin.system.addons.updateAll`,`Update All ({{nonSystemUpdateCount}})`,{nonSystemUpdateCount:k})]})]}),t(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":_(`admin.system.addons.filterInstalledAddons`,`Filter installed addons`),children:[a(`span`,{className:`text-[10px] text-foreground-subtle`,children:_(`admin.system.addons.filter`,`Filter:`)}),[{id:`integrations`,label:_(`admin.system.addons.integrations`,`Integrations`),pressed:Q,toggle:()=>Je(!Q)},{id:`updatable`,label:_(`admin.system.addons.updatable`,`Updatable`),pressed:Ve,toggle:()=>Ye(!Ve)},{id:`error`,label:_(`admin.system.addons.inError`,`In error ({{count}})`,{count:Qe}),pressed:Ue,toggle:()=>Xe(!Ue)},{id:`npm`,label:`npm`,pressed:Z===`npm`,toggle:()=>Ze(Z===`npm`?null:`npm`)},{id:`dev`,label:_(`admin.system.addons.dev`,`Dev`),pressed:Z===`dev`,toggle:()=>Ze(Z===`dev`?null:`dev`)}].map(e=>a(j,{variant:`unstyled`,type:`button`,"aria-pressed":e.pressed,onClick:e.toggle,className:e.pressed?Ft:It,children:e.label},e.id))]}),t(`div`,{className:`flex flex-col gap-1.5 sm:flex-row sm:items-center sm:gap-2`,children:[t(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:E,children:[a(Ee,{type:`text`,searchHotkey:!0,value:y,onChange:e=>{b(e.target.value),ne(!0)},onFocus:()=>ne(!0),placeholder:_(`admin.system.addons.searchAddonsOnNpm`,`Search addons on npm...`),"aria-label":_(`admin.system.addons.searchAddonsOnNpm2`,`Search addons on npm`),disabled:V.isPending,leftSlot:a(d,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),rightSlot:he?a(h,{className:`h-3 w-3 animate-spin`}):void 0}),T&&z&&z.length>0&&t(`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:[z.length>0&&a(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:_(`systemPage.addons.npmResults`,{count:z.length})}),z&&z.length>0&&a(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:z.map(e=>a(Mt,{addon:e,installing:K.isPending,onInstall:e=>Oe({name:e.name,version:e.version,description:e.description})},e.name))})]})]}),a(yt,{onUploadSuccess:()=>{v.invalidateQueries({queryKey:[[`addons`]]}),p()}})]}),X&&t(`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:[a(`span`,{className:`text-foreground-subtle`,children:_(`admin.system.addons.filteringByCapability`,`Filtering by capability:`)}),a(`span`,{className:`font-mono text-primary font-semibold`,children:X}),a(j,{variant:`unstyled`,type:`button`,onClick:et,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:_(`admin.system.addons.clear`,`Clear`)})]}),X&&a(Nt,{capability:X,installing:K.isPending,onInstall:e=>Oe({name:e.name,version:e.version,description:e.description})}),X&&$e.length>0&&a(`h2`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:_(`admin.system.addons.installed`,`Installed`)}),be&&t(`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 max-w-sm pointer-events-auto`,children:[a(m,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),t(`div`,{children:[a(`div`,{className:`text-[11px] font-semibold text-foreground`,children:_(`admin.system.addons.bulkUpdateCompleted`,`Bulk update completed`)}),a(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:_(`admin.system.addons.systemPackagesUpdatedHubRestarted`,`System packages updated — hub restarted successfully.`)})]})]}),g===`pending`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[a(h,{className:`h-3 w-3 animate-spin`}),_(`admin.system.addons.loadingInstalled`,`Loading installed addons…`)]}),g===`error`&&a(`div`,{className:`text-xs text-danger`,children:_(`admin.system.addons.failedToLoadAddons`,`Failed to load addons`)}),g===`ready`&&$e.length===0&&a(`div`,{className:`text-xs text-foreground-subtle`,children:c.length===0?_(`admin.system.addons.noAddonsInstalled`,`No addons installed`):X?_(`admin.system.addons.noInstalledAddonDeclaresThe`,`No installed addon declares the "{{capabilityFilter}}" capability. Any addon you can install appears under "Available to install" above.`,{capabilityFilter:X}):_(`admin.system.addons.noAddonsCompatibleWithPlacement`,`No addons compatible with {{name}} (placement filter active)`,{name:f.name})}),a(`div`,{className:`space-y-1.5`,children:g===`ready`&&nt.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,n=O.get(t),r=ie.get(t),i=$(e)?e.representative:e,o=n?e=>de.mutate({name:t,version:e,nodeId:f.id}):void 0,s=fe.get(t)??null,c=s!==null&&Ge(s);return a(_t,{addon:i,clusterStatus:u?.[i.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:n,...r===void 0?{}:{blockedUpdate:r},...r===void 0?{}:{onUpdateServer:()=>te(!0)},isUpdating:ae.has(t)||c,jobProgress:s,onUpdate:o,disabledByBulk:V.isPending,selectedNode:f},$(e)?t:e.manifest.id)})}),Ce!==null&&a(kt,{target:Ce,installing:K.isPending,installError:Te,onClose:()=>we(null),onInstall:(e,t)=>K.mutate({packageName:e,version:t})})]})}function Wt(){let{t:e}=q(),r=l(),{data:i}=P(void 0),{nodes:s}=N(),{selection:c,selectNode:u,requestedNodeId:d}=Ve(s.length>0?s:[Rt]),f=c.node??Rt,p=f.id,m=s.length>0?c.staleNodeId:null,{data:h,isLoading:g,isError:_}=Oe({nodeId:p}),v=ce(),y=xe(),b=v.isPending||y.isPending,S=async()=>{await v.mutateAsync({nodeId:p}),await y.mutateAsync(),r.invalidateQueries({queryKey:[[`addons`]]})},ee=n(v);ee.current=v;let te=n(d??`hub`);o(()=>{ee.current.mutate({nodeId:te.current})},[]);let C=(h??[]).map(Vt).filter(e=>e!==null);return t(J,{children:[t(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[a(R,{selectedNodeId:p,onSelect:u}),t(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[!g&&!_&&a(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:e(`systemPage.addons.installedCount`,{count:C.length})}),t(j,{variant:`unstyled`,type:`button`,onClick:()=>void S(),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:[a(x,{className:`w-3 h-3 ${b?`animate-spin`:``}`}),e(`admin.system.addons.checkForUpdates`,`Check for updates`)]})]})]}),a(X,{staleNodeId:m,shownNodeName:f.name}),a(jt,{selectedNode:f}),a(Ut,{addons:C,clusterStatus:i,selectedNode:f,onRefresh:()=>void S(),listPhase:g?`pending`:_?`error`:`ready`})]})}export{Wt as AddonsPage};
@@ -1,3 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as d,D as f,G as p,L as m,Lr as h,Q as g,Rn as _,Tt as v,ca as y,ft as b,ga as x,mn as S,oi as C,tn as w,xi as T,yn as E,yt as D,zn as O}from"./player-overlays-BF9w4QU-.js";import{xi as k}from"./client-DhfZUoXe.js";import{t as A}from"./flask-conical-D7tbJQpj.js";import{t as j}from"./message-square-plus-_aGccjyj.js";import{$f as M,Ea as N,Fr as P,Mr as F,Pr as I,_a as L,ba as R,cp as ee,di as te,ea as z,fa as ne,jp as B,pa as V,q as re,sp as ie,ut as H,ya as U,zs as W}from"./src-D9hgltMI.js";import{t as G}from"./i18n-DCYaeyv_.js";import{t as K}from"./useTranslation-BJr-n0es.js";import"./mount-B2oUIKRS.js";import{_t as q,w as J,yi as Y}from"./index-DPyWa2vo.js";import{t as X}from"./AdminPage-z8USGyNk.js";import{t as ae}from"./InstancesTable-DIKWKA5W.js";import{t as oe}from"./AdminSectionedPage-CtcZ5jHa.js";import{a as se,c as ce,d as le,f as ue,i as de,l as Z,n as fe,o as pe,p as me,r as he,s as ge,t as _e,u as ve}from"./ai-page.helpers-ChgVcsV9.js";c();function ye(){let{t}=K(),n=D(),r=V({functionCap:`llm`}).data??[],a=s({queryKey:fe,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),o=u({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{a.refetch()}}),c=e=>(a.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,l=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return i(F,{headingId:`ai-profiles-defaults`,title:t(`ai.defaultsTitle`,`Defaults`),children:i(`div`,{className:`${f} grid gap-4 sm:grid-cols-2`,children:he.map(({purpose:n,visionOnly:a})=>{let s=a?r.filter(Z):r,u=c(n),d=r.find(e=>e.id===u);return e(`div`,{children:[i(te,{className:`mb-1 block`,htmlFor:`llm-default-${n}`,children:l(n)}),i(b,{id:`llm-default-${n}`,"aria-label":l(n),value:u,onChange:e=>o.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),options:[{value:``,label:t(`ai.none`,`None`)},...u!==``&&!s.some(e=>e.id===u)?[{value:u,label:d?.name??u}]:[],...s.map(e=>({value:e.id,label:ge(e)===``?e.name:`${e.name} · ${ge(e)}`}))]}),u!==``&&d===void 0&&i(`p`,{className:`mt-1 text-xs text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),d!==void 0&&!d.enabled&&i(`p`,{className:`mt-1 text-xs text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),o.error!=null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:String(o.error)})]},n)})})})}var be=2e3;function Q(e){return G.t(`system.aiModelPicker.sizeGb`,{value:(e/1e9).toFixed(2)})}function xe(e){return e===null?``:e.model.kind===`catalog`?`catalog:${e.model.catalogId}`:e.model.kind===`path`?`node:${e.modelId}`:`custom`}function Se({nodeId:t,value:r,onChange:a}){let{t:c}=K(),l=D(),[f,p]=o(``),[m,g]=o(null),[_,v]=o(!1),y=s({queryKey:_e,queryFn:()=>l.trpcClient.llm.listModelCatalog.query({})}),x=s({queryKey:[`llm`,`listNodeModels`,t],queryFn:()=>l.trpcClient.llm.listNodeModels.query({nodeId:t})}),S=u({mutationFn:e=>l.trpcClient.llm.resolveModelRef.mutate(e),onSuccess:e=>{g(e),v(!1),e.ok&&a({model:e.model,modelId:e.label,supportsVision:e.purpose===`vision`})}}),C=u({mutationFn:e=>l.trpcClient.llm.installModel.mutate({nodeId:t,model:e}),onSuccess:()=>{v(!0),x.refetch()}}),w=s({queryKey:de,enabled:C.isPending,refetchInterval:C.isPending?be:!1,queryFn:()=>l.trpcClient.llm.listRuntimeNodes.query({})}).data?.find(e=>e.nodeId===t)?.status?.download,E=n(()=>{let e=(y.data??[]).map(e=>({value:`catalog:${e.id}`,label:`${e.label} · ${e.quantization} · ${Q(e.sizeBytes)}`})),n=(x.data??[]).filter(e=>e.catalogId===void 0&&e.path!==void 0).map(e=>({value:`node:${e.file}`,label:c(`ai.onNode`,`{{file}} · {{size}} · on {{node}}`,{file:e.file,size:Q(e.sizeBytes),node:t})})),r=m?.ok===!0?[{value:`custom`,label:`${m.label} · ${Q(m.totalBytes)}`}]:[];return[{value:``,label:c(`ai.selectModel`,`Select a model…`)},...e,...n,...r]},[y.data,x.data,m,t,c]),O=e=>{if(e===``){a(null);return}if(e===`custom`){if(m?.ok!==!0)return;a({model:m.model,modelId:m.label,supportsVision:m.purpose===`vision`});return}if(e.startsWith(`catalog:`)){let t=e.slice(8),n=y.data?.find(e=>e.id===t);a({model:{kind:`catalog`,catalogId:t},modelId:t,supportsVision:n?.purpose===`vision`});return}let t=e.slice(5),n=x.data?.find(e=>e.file===t);n?.path!==void 0&&a({model:{kind:`path`,path:n.path},modelId:t,supportsVision:!1})},k=e=>{f.trim()!==``&&S.mutate({ref:f.trim(),...e===void 0?{}:{maxBytes:e}})};return e(`div`,{className:`space-y-3`,children:[i(H,{label:c(`ai.model`,`Model`),required:!0,children:i(b,{id:`ai-model`,"aria-label":c(`ai.model`,`Model`),value:xe(r),options:E,onChange:e=>O(e.target.value)})}),i(H,{label:c(`ai.hfTitle`,`Add a model from Hugging Face`),description:c(`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.`),children:e(`div`,{className:`flex gap-2`,children:[i(ie,{"aria-label":c(`ai.hfTitle`,`Add a model from Hugging Face`),value:f,onChange:e=>p(e.target.value),placeholder:c(`system.aiModelPicker.unslothQwen3635bA3b`,`unsloth/Qwen3.6-35B-A3B-GGUF:UD-Q4_K_M`),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),k())}}),e(M,{size:`sm`,variant:`secondary`,type:`button`,disabled:f.trim()===``||S.isPending,onClick:()=>k(),children:[S.isPending?i(h,{className:`h-3.5 w-3.5 animate-spin`}):i(d,{className:`h-3.5 w-3.5`}),c(`ai.hfCheck`,`Check`)]})]})}),S.isError&&i(L,{message:S.error instanceof Error?S.error.message:c(`common.error`,`Error`)}),m?.ok===!1&&i(L,{message:m.message,action:e(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(m.candidates??[]).map(e=>i(M,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{let t=`${f.trim().split(`:`)[0]??``}:${e}`;p(t),S.mutate({ref:t})},children:e},e)),m.requiredBytes!==void 0&&i(M,{size:`sm`,variant:`secondary`,type:`button`,onClick:()=>k(m.requiredBytes),children:c(`ai.hfOverride`,`Install anyway ({{size}})`,{size:Q(m.requiredBytes)})})]})}),m?.ok===!0&&e(`div`,{className:`space-y-2 rounded-md border border-border bg-surface p-2.5`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`span`,{className:`text-[11px] font-medium text-foreground`,children:m.label}),i(U,{variant:m.purpose===`vision`?`info`:`default`,children:m.purpose}),i(U,{variant:`default`,children:Q(m.totalBytes)})]}),m.extraFilenames.length>0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:c(`ai.hfExtras`,`Also downloads: {{files}}`,{files:m.extraFilenames.join(`, `)})}),e(`div`,{className:`flex items-center gap-2`,children:[e(M,{size:`sm`,type:`button`,disabled:C.isPending||_,onClick:()=>C.mutate(m.model),children:[C.isPending?i(h,{className:`h-3.5 w-3.5 animate-spin`}):i(T,{className:`h-3.5 w-3.5`}),_?c(`ai.hfInstalled`,`Downloaded`):c(`ai.hfInstall`,`Download to {{node}}`,{node:t})]}),w!==void 0&&i(`span`,{className:`text-[10px] text-foreground-subtle`,children:w.phase===`verifying`?c(`ai.hfVerifying`,`verifying {{file}}…`,{file:w.file}):c(`ai.hfDownloading`,`{{file}} ({{index}}/{{count}}) — {{done}}{{total}}`,{file:w.file,index:w.fileIndex,count:w.fileCount,done:Q(w.downloadedBytes),total:w.totalBytes===void 0?``:` / ${Q(w.totalBytes)}`})})]}),C.isError&&i(L,{message:C.error instanceof Error?C.error.message:c(`common.error`,`Error`)})]})]})}function Ce({value:t,onChange:n}){let{t:r}=K(),a=D(),o=s({queryKey:de,queryFn:()=>a.trpcClient.llm.listRuntimeNodes.query({})});return e(`div`,{children:[i(`div`,{className:`mb-1 text-[11px] font-medium text-foreground`,children:r(`ai.appleNode`,`Mac that runs it`)}),o.isPending&&e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(h,{className:`h-3.5 w-3.5 animate-spin`}),r(`ai.appleAsking`,`Asking the nodes…`)]}),o.isError&&i(`p`,{className:`text-[11px] text-danger`,children:o.error instanceof Error?o.error.message:r(`ai.runtimesFailed`,`Failed to read runtime nodes`)}),o.isSuccess&&o.data.length===0&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}),o.isSuccess&&o.data.length>0&&i(`div`,{role:`radiogroup`,className:`space-y-1.5`,children:o.data.map(a=>{let o=pe(a),s=o.nodeId===t;return e(M,{variant:`unstyled`,type:`button`,role:`radio`,"aria-checked":s,disabled:!o.selectable&&!s,onClick:()=>n(o.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 ${s?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block font-medium text-foreground`,children:o.nodeId}),o.detail!==null&&i(`span`,{className:`block truncate text-[10px] text-foreground-subtle`,children:o.detail})]}),i(U,{variant:o.tone,children:r(o.labelKey,o.labelDefault)})]},o.nodeId)})}),i(`p`,{className:`mt-1.5 text-[10px] leading-relaxed text-foreground-subtle`,children:r(`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.`)})]})}function we(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Te({providerConfig:e,onProviderConfigChange:t}){return i(Ce,{value:we(e,`nodeId`),onChange:n=>t({...e,nodeId:n})})}function Ee({providerConfig:e,onProviderConfigChange:t,model:n,onModelChange:r}){let a=k.safeParse(e.model),o=a.success?{model:a.data,modelId:n.id,supportsVision:n.supportsVision}:null;return i(Se,{nodeId:we(e,`nodeId`)??`hub`,value:o,onChange:n=>{if(n===null){let{model:n,...i}=e;t(i),r({id:``,supportsVision:!1});return}t({...e,model:n.model}),r({id:n.modelId,supportsVision:n.supportsVision})}})}var De=new Map([[`ai/apple-node`,Te],[`ai/managed-model`,Ee]]);function Oe(e){return De.get(e)??null}c();function $(e,t){let n=e[t];return typeof n==`string`?n:``}function ke({row:a}){let{t:c}=K(),d=D(),f=l(),p=s({queryKey:n(()=>[q,a.addonId,`ai-lead`,a.id],[a]),queryFn:async()=>{let e=d.trpcClient.integrationInstances,[t,n]=await Promise.all([e.describe.query({addonId:a.addonId}),e.getInstance.query({addonId:a.addonId,id:a.id})]);return{description:t,instance:n}}}),[m,g]=o({}),_=t({}),v=t(!1),y=u({mutationFn:e=>d.trpcClient.integrationInstances.updateInstance.mutate({addonId:a.addonId,id:a.id,values:e}),onSuccess:async()=>{await f.invalidateQueries({queryKey:[q]}),await f.invalidateQueries({queryKey:[ne]}),g({})}}),x=r(e=>{_.current={..._.current,...e},g(t=>({...t,...e})),!v.current&&(v.current=!0,queueMicrotask(()=>{let e=_.current;_.current={},v.current=!1,y.mutate(e)}))},[y]),S=p.data?.description.kinds?.find(e=>e.id===a.kindId),C=p.data?.instance?.formValues,w=n(()=>({...C,...m}),[C,m]),T=S?.widgets??[],E=T.some(e=>e.placement===`model`),O=n(()=>({...$(w,`nodeId`)===``?{}:{nodeId:$(w,`nodeId`)},...typeof w.modelRef==`object`&&w.modelRef!==null?{model:w.modelRef}:{}}),[w]),k={id:$(w,`model`),supportsVision:w.supportsVision===!0},A=u({mutationFn:()=>d.trpcClient.llm.listModels.mutate({addonId:a.addonId,kind:a.kindId??``,profileId:a.id})});if(p.isPending)return null;if(p.isError)return i(L,{variant:`warning`,message:p.error.message});let j=A.data?.ok===!0?A.data.models:[],N=A.data?.ok===!1?A.data:null,P=e=>{let t=j.find(t=>t.id===e);x({model:e,...t?.features?.vision===void 0?{}:{supportsVision:t.features.vision}})};return e(`div`,{className:`space-y-3`,"data-testid":`ai-profile-lead`,children:[T.map(({id:e})=>{let t=Oe(e);return t===null?i(L,{variant:`warning`,message:c(`ai.unknownWidget`,`This provider needs an editor part this build does not have ({{id}}).`,{id:e})},e):i(t,{providerConfig:O,onProviderConfigChange:e=>x({...$(e,`nodeId`)===$(O,`nodeId`)?{}:{nodeId:$(e,`nodeId`)},...e.model!==void 0&&e.model!==O.model?{modelRef:e.model}:{}}),model:k,onModelChange:e=>x({model:e.id,supportsVision:e.supportsVision})},e)}),!E&&e(H,{label:c(`ai.model`,`Model`),children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(M,{size:`sm`,variant:`secondary`,type:`button`,disabled:A.isPending,onClick:()=>A.mutate(),children:[A.isPending?i(h,{className:`h-3.5 w-3.5 animate-spin`}):null,c(`ai.loadModels`,`Load models`)]}),j.length>0&&i(b,{"aria-label":c(`ai.model`,`Model`),value:k.id,onChange:e=>P(e.target.value),options:[...j.some(e=>e.id===k.id)||k.id===``?[]:[{value:k.id,label:k.id}],...j.map(e=>({value:e.id,label:e.label??e.id}))]})]}),N!==null&&i(`p`,{className:`mt-1 text-xs text-danger`,children:N.message}),A.isError&&i(`p`,{className:`mt-1 text-xs text-danger`,children:A.error.message})]}),y.isError&&i(L,{variant:`warning`,message:y.error.message})]})}c();var Ae=5e3;function je(e){return G.t(`system.aiRuntimes.sizeGb`,{value:(e/1e9).toFixed(1)})}function Me(){let{t}=K(),r=D(),a=s({queryKey:de,refetchInterval:Ae,queryFn:()=>r.trpcClient.llm.listRuntimeNodes.query({})}),o=n(()=>[{key:`node`,header:t(`ai.colNode`,`Node`),render:e=>i(`span`,{className:`font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:t(`ai.colState`,`State`),nowrap:!0,render:n=>e(`span`,{className:`flex items-center gap-1.5`,children:[i(U,{variant:me(n),children:t(ue(n))}),n.status?.downloadProgress!==void 0&&i(U,{variant:`info`,children:`${String(Math.round(n.status.downloadProgress*100))}%`})]})},{key:`model`,header:t(`ai.colModel`,`Model`),render:e=>i(`span`,{className:`text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:t(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums text-foreground-muted`,children:e.disk===void 0?`—`:je(e.disk.modelsBytes)})},{key:`features`,header:t(`ai.colFeature`,`Feature`),render:n=>{let r=le(n);if(r.length===0)return i(`span`,{className:`text-foreground-subtle`,children:`—`});let a=r.flatMap(e=>e.detail===null?[]:[e.detail]);return e(`span`,{className:`flex flex-col items-start gap-0.5`,children:[i(`span`,{className:`flex flex-wrap gap-1`,children:r.map(e=>i(U,{variant:e.tone,children:t(e.labelKey)},e.id))}),a.length>0&&i(`span`,{className:`text-foreground-subtle`,children:a.join(` · `)})]})}},{key:`error`,header:t(`ai.colError`,`Error`),render:e=>e.error===void 0?i(`span`,{className:`text-foreground-subtle`,children:`—`}):i(`span`,{className:`text-danger`,children:e.error})}],[t]),c=a.data??[];return i(F,{headingId:`ai-runtimes-list`,title:t(`ai.runtimesList`,`Nodes`),children:a.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-runtimes-loading`,children:[i(R,{className:`h-8 w-full`}),i(R,{className:`h-8 w-full`})]}):a.isError?i(`div`,{className:f,children:i(L,{title:t(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:a.error instanceof Error?a.error.message:t(`common.error`,`Error`),onRetry:()=>void a.refetch()})}):c.length===0?i(z,{icon:_,title:t(`ai.noRuntimesTitle`,`No runtime nodes`),description:t(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):i(I,{columns:o,rows:c,rowKey:e=>e.nodeId,minWidthPx:760,bordered:!1,maxBodyHeight:P})})}var Ne=g(`/addon/ai/test-chat`),Pe=g(`/addon/ai/test-chat/chats`),Fe=6e5;function Ie(e){let t=e.firstTokenTimeoutMs;if(!(typeof t!=`number`||!Number.isFinite(t)||t<=0))return Math.min(Math.round(t),Fe)}function Le(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Re(e){if(!Le(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 ze=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function Be(e){let t;try{t=JSON.parse(e)}catch{return null}if(!Le(t))return null;switch(t.kind){case`status`:{let e=ze.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:Re(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:G.t(`helpers.aiTestChat.providerError`)};default:return null}}async function*Ve(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=Be(e);t!==null&&(yield t)}a=r.indexOf(`
3
- `)}}let e=r.trim();if(e.length>0){let t=Be(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function He(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Ue(e){return e.thumbnailBase64===void 0||e.thumbnailBase64.length===0?null:`data:${e.mimeType};base64,${e.thumbnailBase64}`}function We(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 Ge(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 Ke(e,t){switch(e){case`resolving-image`:return G.t(`helpers.aiTestChat.phaseImage`);case`connecting`:return G.t(`helpers.aiTestChat.phaseConnecting`);case`first-token-wait`:return t>0?G.t(`helpers.aiTestChat.phaseWaitUpTo`,{seconds:Math.round(t/1e3)}):G.t(`helpers.aiTestChat.phaseWait`);case`streaming`:return G.t(`helpers.aiTestChat.phaseAnswering`)}}c();var qe=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],Je=360*60*1e3,Ye=40,Xe=160,Ze={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function Qe(){let{t:s}=K();D();let[c,l]=o(``),[u,d]=o(``),[p,h]=o(``),[g,_]=o([]),[C,T]=o(null),[E,k]=o(`none`),[A,N]=o(`throwaway`),[P,I]=o(null),[R,z]=o([]),[ne,B]=o(null),[H,U]=o(null),W=t(null);a(()=>()=>W.current?.abort(),[]);let G=r(async()=>{let e=await fetch(Pe,{credentials:`same-origin`});e.ok&&z((await e.json()).chats??[])},[]);a(()=>{A===`persistent`&&G()},[A,G]);let q=V({functionCap:`llm`}),J=n(()=>(q.data??[]).filter(e=>e.enabled),[q.data]),Y=J.find(e=>e.id===c)??null,X=H!==null,ae=r(async(e,t)=>{let n=new AbortController;W.current=n,B(null);let r=Ie(Y===null?{}:ve(Y));U({...Ze,firstTokenTimeoutMs:r??0});let i=``,a=null,o,l=null,d=null,f;try{let s=await fetch(Ne,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:n.signal,body:JSON.stringify({profileId:c,messages:e,...u.trim()===``?{}:{system:u.trim()},...t===void 0?{}:{attachment:t},...r===void 0?{}:{firstTokenTimeoutMs:r},...A===`persistent`?{persist:!0,...P===null?{}:{conversationId:P}}:{}})});if(!s.ok||s.body===null){let e=await s.text().catch(()=>``);throw Error(e.length>0?e:`HTTP ${String(s.status)}`)}for await(let e of Ve(s.body))switch(e.kind){case`status`:U(t=>({...t??Ze,phase:e.phase}));break;case`meta`:a=e.mediaSent,o=e.model,U(t=>({...t??Ze,firstTokenTimeoutMs:e.firstTokenTimeoutMs,mediaSent:e.mediaSent}));break;case`token`:i+=e.text,U(e=>({...e??Ze,text:i}));break;case`done`:d={outputTokens:e.outputTokens,latencyMs:e.latencyMs},f=e.conversationId;break;case`error`:l=`${e.code}: ${e.message}`;break}}catch(e){n.signal.aborted||B(e instanceof Error?e.message:s(`common.error`,`Error`))}finally{W.current=null,U(null)}f!==void 0&&(I(f),G());let p=n.signal.aborted&&i.length>0;l===null&&i.length===0&&!p||_(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??i,...l===null?{}:{failed:!0},...a===null?{}:{attachment:a},...o!==void 0&&l===null?{model:o}:{},...d===null?{}:d}])},[A,P,Y,c,G,u,s]),oe=r(()=>{let e=p.trim();if(e===``||c===``||X)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...C===null?{}:{attachmentLabel:C.label,attachmentKind:C.ref.kind}},n=[...g,t];_(n),h(``);let r=C?.ref;T(null),k(`none`),ae(A===`persistent`&&P!==null?[{role:`user`,content:e}]:He(n),r)},[A,P,p,C,c,ae,X,g]),se=()=>W.current?.abort(),ce=()=>{W.current?.abort(),_([]),T(null),h(``),B(null),U(null),I(null)},le=async e=>{W.current?.abort();let t=await fetch(`${Pe}/${e}`,{credentials:`same-origin`});if(!t.ok)return;let n=await t.json();I(e),_(We(n)),U(null),B(null)};return e(`div`,{className:m,children:[i(F,{headingId:`ai-test-setup`,title:s(`ai.testSetup`,`Setup`),children:e(`div`,{className:`${f} space-y-3`,children:[e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[e(`div`,{children:[i(te,{className:`mb-1 block`,htmlFor:`ai-test-profile`,children:s(`ai.profile`,`Profile`)}),i(b,{id:`ai-test-profile`,value:c,onChange:e=>l(e.target.value),options:[{value:``,label:s(`ai.selectProfile`,`Select a profile…`)},...J.map(e=>({value:e.id,label:`${e.name} · ${ge(e)}${Z(e)?` · vision`:``}`}))]}),J.length===0&&!q.isLoading&&i(`p`,{className:`mt-1 text-xs text-foreground-subtle`,children:s(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),e(`div`,{children:[i(te,{className:`mb-1 block`,htmlFor:`ai-test-system`,children:s(`ai.systemPrompt`,`System prompt (optional)`)}),i(ie,{id:`ai-test-system`,value:u,onChange:e=>d(e.target.value),placeholder:s(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),i(re,{label:s(`ai.chatMode`,`Conversation mode`),value:A,options:[{value:`throwaway`,label:s(`ai.throwawayMode`,`Throwaway`)},{value:`persistent`,label:s(`ai.saveConversation`,`Save conversation`)}],onChange:e=>{N(e),e===`throwaway`&&I(null)}}),A===`persistent`&&e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:s(`ai.testSubtitlePersistent`,`Conversations are saved for you and can be reopened. Throwaway mode is still available.`)}),e(M,{size:`sm`,variant:`secondary`,type:`button`,onClick:ce,children:[i(j,{className:`h-3.5 w-3.5`}),s(`ai.newChat`,`New chat`)]}),R.length>0&&i(`div`,{className:`max-h-36 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:R.map(e=>i(`button`,{type:`button`,onClick:()=>void le(e.id),className:`flex w-full px-2.5 py-1.5 text-left text-xs hover:bg-surface-hover ${e.id===P?`bg-primary/10`:``}`,children:i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.title})},e.id))})]}),i(`p`,{className:`text-xs text-foreground-subtle`,children:s(`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.`)}),Y!==null&&!Z(Y)&&i(`p`,{className:`text-xs text-warning`,children:s(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]})}),ne!==null&&i(L,{title:s(`ai.chatFailed`,`The test call failed`),message:ne}),e(F,{headingId:`ai-test-conversation`,title:s(`ai.testConversation`,`Conversation`),actions:e(M,{size:`sm`,variant:`ghost`,type:`button`,disabled:g.length===0&&C===null,onClick:ce,children:[i(w,{className:`h-3.5 w-3.5`}),s(`ai.clearChat`,`Clear`)]}),children:[i($e,{turns:g,live:H}),e(`div`,{className:`${f} space-y-2 border-t border-border`,children:[C!==null&&e(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-background px-2.5 py-1.5`,children:[C.ref.kind===`snapshot`?i(y,{className:`h-3.5 w-3.5 text-foreground-subtle`}):i(x,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:C.label}),i(ee,{size:`sm`,variant:`ghost`,type:`button`,icon:v,"aria-label":s(`ai.removeAttachment`,`Remove attachment`),onClick:()=>T(null)})]}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(M,{size:`sm`,variant:E===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>k(E===`snapshot`?`none`:`snapshot`),children:[i(y,{className:`h-3.5 w-3.5`}),s(`ai.attachSnapshot`,`Camera snapshot`)]}),e(M,{size:`sm`,variant:E===`track`?`primary`:`outline`,type:`button`,onClick:()=>k(E===`track`?`none`:`track`),children:[i(x,{className:`h-3.5 w-3.5`}),s(`ai.attachTrack`,`Recent track`)]})]}),E===`snapshot`&&i(nt,{onPick:(e,t)=>{T({ref:{kind:`snapshot`,deviceId:e.id},label:s(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:t})}),k(`none`)}}),E===`track`&&i(it,{onPick:(e,t)=>{T({ref:{kind:`track`,trackId:e.trackId,deviceId:e.deviceId},label:s(`ai.trackOf`,`{{class}} on {{name}}`,{class:e.label??e.className,name:t})}),k(`none`)}}),e(`div`,{className:`flex items-center gap-2`,children:[i(ie,{value:p,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),oe())},placeholder:s(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":s(`ai.message`,`Message`)}),X?e(M,{size:`sm`,variant:`secondary`,type:`button`,onClick:se,children:[i(S,{className:`h-3.5 w-3.5`}),s(`ai.stop`,`Stop`)]}):e(M,{size:`sm`,type:`button`,disabled:p.trim()===``||c===``,onClick:oe,children:[i(O,{className:`h-3.5 w-3.5`}),s(`ai.send`,`Send`)]})]})]})]})]})}function $e({turns:t,live:n}){let{t:r}=K();return t.length===0&&n===null?i(z,{icon:A,title:r(`ai.chatEmptyTitle`,`No messages yet`),description:r(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):e(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto ${f}`,children:[t.map(e=>i(et,{turn:e},e.id)),n!==null&&e(`div`,{className:`space-y-1`,children:[n.mediaSent!==null&&i(tt,{attachment:n.mediaSent}),n.text.length>0&&i(et,{turn:{id:`live`,role:`assistant`,content:n.text},streaming:!0}),e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(h,{className:`h-3.5 w-3.5 animate-spin`}),Ke(n.phase,n.firstTokenTimeoutMs)]})]})]})}function et({turn:t,streaming:n=!1}){let{t:r}=K(),a=t.role===`user`,o=t.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return i(`div`,{className:`flex ${a?`justify-end`:`justify-start`}`,children:e(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${a?`border-primary/40 bg-primary/10`:o}`,children:[e(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[t.content,n&&i(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),t.attachment!==void 0&&i(tt,{attachment:t.attachment}),t.attachmentLabel!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachmentKind===`track`?i(x,{className:`h-3 w-3`}):i(y,{className:`h-3 w-3`}),t.attachmentLabel]}),t.attachment!==void 0&&e(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[t.attachment.kind===`snapshot`?i(y,{className:`h-3 w-3`}):i(x,{className:`h-3 w-3`}),Ge(t.attachment)]}),t.model!==void 0&&i(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:r(`system.aiTestChat.tokMs`,`{{model}} · {{value2}} tok · {{value3}} ms`,{model:t.model,value2:String(t.outputTokens??0),value3:String(t.latencyMs??0)})})]})})}function tt({attachment:e}){let{t}=K(),n=Ue(e);return n===null?null:i(`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 nt({onPick:e}){let{t}=K(),n=W({isCamera:!0,projection:`slim`}),r=(n.data??[]).filter(e=>!e.disabled);return n.isLoading?i(h,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):r.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):i(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:r.map(t=>i(rt,{device:t,onPick:e},t.id))})}function rt({device:t,onPick:n}){let{t:r}=K(),a=N(t,`compact`),{src:o}=p(t.id,{width:Xe});return e(`button`,{type:`button`,onClick:()=>n(t,a),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[i(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:o!==null&&i(`img`,{src:o,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),e(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!t.online&&i(U,{variant:`warning`,children:r(`common.off`)}),i(`span`,{className:`truncate text-[10px] text-foreground`,children:a})]})]})}function it({onPick:t}){let{t:r}=K(),a=D(),o=W({isCamera:!0,projection:`slim`}),c=n(()=>(o.data??[]).map(e=>e.id),[o.data]),l=n(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),u=s({queryKey:[...qe,c.length],enabled:c.length>0,queryFn:()=>a.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...c],since:Date.now()-Je,limit:Ye,projection:`slim`})});if(o.isLoading||u.isLoading)return i(h,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let d=u.data?.tracks??[];return d.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`ai.noTracks`,`No track in the last 6 hours.`)}):i(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:d.map(n=>e(`button`,{type:`button`,onClick:()=>t(n,l.get(n.deviceId)??String(n.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[i(x,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),i(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:n.label??n.className}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:l.get(n.deviceId)??n.deviceId}),i(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(n.lastSeen).toLocaleTimeString()})]},n.trackId))})}c();var at=1440*60*1e3,ot=[1,7,30,90];function st(){let{t}=K(),r=D(),[a,c]=o(7),l=n(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(a-1)*at},[a]),u=V({functionCap:`llm`}),d=s({queryKey:[...se,a],queryFn:()=>r.trpcClient.llm.getUsage.query({since:l})}),p=n(()=>{let e=new Map;for(let t of u.data??[])e.set(t.id,t.name);return e},[u.data]),m=n(()=>[{key:`day`,header:t(`ai.colDay`,`Day`),nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:e.day})},{key:`consumer`,header:t(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>i(`span`,{className:`text-foreground`,children:e.consumer})},{key:`profile`,header:t(`ai.colProfile`,`Profile`),render:e=>i(`span`,{className:`text-foreground`,children:p.get(e.profileId)??e.profileId})},{key:`calls`,header:t(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(e.calls)})},{key:`okErr`,header:t(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums ${e.errorCalls>0?`text-danger`:``}`,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:t(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:`${String(e.inputTokens)} / ${String(e.outputTokens)}`})},{key:`latency`,header:t(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>i(`span`,{className:`tabular-nums`,children:String(Math.round(e.avgLatencyMs))})}],[p,t]),h=d.data??[],g=i(`div`,{className:`w-36`,children:i(b,{"aria-label":t(`ai.window`,`Window`),value:String(a),options:ot.map(e=>({value:String(e),label:t(`ai.lastDays`,`Last {{days}} days`,{days:e})})),onChange:e=>c(Number(e.target.value))})});return i(F,{headingId:`ai-usage-list`,title:t(`ai.usageList`,`Rollup`),actions:g,children:d.isPending?e(`div`,{className:`${f} space-y-2`,"data-testid":`ai-usage-loading`,children:[i(R,{className:`h-8 w-full`}),i(R,{className:`h-8 w-full`}),i(R,{className:`h-8 w-full`})]}):d.isError?i(`div`,{className:f,children:i(L,{title:t(`ai.usageFailed`,`Failed to read usage`),message:d.error instanceof Error?d.error.message:t(`common.error`,`Error`),onRetry:()=>void d.refetch()})}):h.length===0?i(z,{icon:C,title:t(`ai.noUsage`,`No AI calls in this window.`)}):i(I,{columns:m,rows:h,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,maxBodyHeight:P})})}c();var ct=`llm`,lt=[`profiles`,`runtimes`,`usage`,`test`],ut=[`instance`,`instance-new`];function dt(e){return lt.some(t=>t===e)}function ft(){let{t:e}=K(),t=B(ct),[n]=Y(),r=J(`/system/ai`,{t:e,isAdmin:!0})??{icon:E,title:e(`system.ai`,`AI`)};if(t!==`present`)return i(X,{icon:r.icon,title:r.title,children:i(gt,{presence:t})});let a=n.get(`tab`),o=dt(a)?a:`profiles`,s={profiles:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),runtimes: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.`),usage: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.`),test:e(`ai.testSubtitle`,`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.`)};return i(oe,{icon:r.icon,title:r.title,subtitle:s[o],defaultSection:`profiles`,sectionsLabel:`${r.title} sections`,sections:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),content:i(ht,{}),ownedParams:ut},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),content:i(Me,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),content:i(st,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),content:i(Qe,{})}]})}function pt(e,t,n){let r=e.kind===`instance`?t.get(e.id):void 0;return r===void 0?void 0:n(r)}function mt(e,t){let n=t=>pt(t,e,ge)??``,r=t=>pt(t,e,Z)??!1,a=t=>pt(t,e,ce)??``;return[{key:`model`,header:t(`ai.colModel`,`Model`),sortValue:n,render:e=>i(`span`,{className:`font-mono text-xs text-foreground-muted`,children:n(e)||`—`})},{key:`vision`,header:t(`ai.colVision`,`Vision`),sortValue:e=>+!!r(e),render:e=>r(e)?i(U,{variant:`info`,children:t(`ai.vision`,`vision`)}):null},{key:`node`,header:t(`ai.colNode`,`Node`),sortValue:a,render:e=>i(`span`,{className:`text-xs text-foreground-muted`,children:a(e)||`—`})}]}function ht(){let{t}=K(),r=V({functionCap:ct}),a=n(()=>new Map((r.data??[]).map(e=>[e.id,e])),[r.data]),o=n(()=>mt(a,t),[a,t]);return e(`div`,{className:m,children:[i(ye,{}),i(ae,{functionCap:ct,icon:E,title:t(`ai.profilesList`,`Profiles`),subtitle:t(`ai.profilesTableSubtitle`,`Each profile is one model endpoint; switch one off to keep it without using it.`),emptyTitle:t(`ai.noProfilesTitle`,`No AI profiles yet`),emptyDescription:t(`ai.noProfilesDescription`,`Add a profile to give features a model to talk to.`),addLabel:t(`ai.addProfile`,`Add profile`),extraColumns:o,lead:e=>i(ke,{row:e})})]})}function gt({presence:t}){let{t:n}=K();return t===`pending`?e(`div`,{className:`space-y-3`,"data-testid":`ai-presence-pending`,children:[i(R,{className:`h-8 w-64`}),i(R,{className:`h-40 w-full`})]}):t===`unknown`?i(L,{title:n(`ai.presenceUnknownTitle`,`Could not check whether AI is installed`),message:n(`ai.presenceUnknown`,`The hub did not answer the capability check. Reload the page to try again.`)}):i(z,{icon:E,title:n(`ai.absentTitle`,`AI is not installed`),description:n(`ai.absentDescription`,`Install the AI addon from System → Addons to add model profiles.`)})}export{ft as AiProfilesPage,ft as default};
@@ -1 +0,0 @@
1
- import{C as e,K as t,R as n,S as r,V as i,Y as a,et as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$r as l,$t as u,Ei as d,Et as f,Ga as p,Ka as m,La as h,Lr as g,Tt as _,Y as v,Zt as y,ca as b,ct as x,ft as S,tn as C}from"./player-overlays-BF9w4QU-.js";import{_c as w}from"./client-DhfZUoXe.js";import{v as T}from"./terminal-Dgb4lrgM.js";import{t as E}from"./scissors-Bbq6WhOK.js";import{$d as D,$f as O,Au as k,Bi as A,Fr as j,Mr as M,Pr as N,Pu as P,Qd as ee,Ri as F,Ui as te,Wi as ne,Zd as re,af as ie,cf as ae,ea as I,ef as oe,if as se,jp as L,nf as ce,nu as le,of as ue,rf as de,sf as fe,tf as pe,ya as R,yi as me,zi as z}from"./src-D9hgltMI.js";import{t as B}from"./i18n-DCYaeyv_.js";import{t as V}from"./useTranslation-BJr-n0es.js";import{_i as he,gi as ge}from"./index-DPyWa2vo.js";import{t as _e}from"./AdminPage-z8USGyNk.js";import{i as ve,r as ye,t as be}from"./use-archive-data-D7nUbRKv.js";import{t as H}from"./format-size-DIxKXxtj.js";import{a as xe,i as Se,n as Ce,o as we,r as Te,s as Ee,t as De}from"./StorageLocationsTable-BymZx5tG.js";o();var Oe={recording:`success`,off:`default`,degraded:`warning`,unknown:`default`},U=`—`;function ke({rows:n,isLoading:i}){let{t:a}=V(),o=he(),s=t(()=>[{key:`camera`,header:a(`archive.table.camera`,`Camera`),sortValue:e=>e.name,render:e=>r(`span`,{className:`font-medium text-foreground`,children:e.name})},{key:`mode`,header:a(`archive.table.mode`,`Recording`),sortValue:e=>e.mode??``,render:e=>r(`span`,{className:`text-foreground-subtle`,children:e.mode===null?U:a(`archive.mode.${e.mode}`,e.mode)})},{key:`status`,header:a(`archive.table.status`,`Status`),sortValue:e=>e.state,render:t=>e(`span`,{className:`inline-flex items-center gap-1.5`,children:[r(R,{variant:Oe[t.state],children:a(`archive.state.${t.state}`,t.state)}),t.warnings>0&&r(R,{variant:`warning`,children:a(`archive.table.warnings`,`{{count}} warning`,{count:t.warnings})})]})},{key:`footage`,header:a(`archive.table.footage`,`Footage`),align:`right`,nowrap:!0,sortValue:e=>e.footageBytes,render:e=>r(`span`,{className:`tabular-nums`,children:e.footageBytes===null?U:H(e.footageBytes)})},{key:`events`,header:a(`archive.table.events`,`Events`),align:`right`,nowrap:!0,sortValue:e=>e.eventRows,render:e=>r(`span`,{className:`tabular-nums`,children:e.eventRows===null||e.eventBytes===null?U:`${e.eventRows.toLocaleString()} · ${H(e.eventBytes)}`})},{key:`oldest`,header:a(`archive.table.oldest`,`Oldest footage`),align:`right`,nowrap:!0,sortValue:e=>e.oldestMs,render:e=>r(`span`,{className:`tabular-nums text-foreground-subtle`,children:e.oldestMs===null?U:new Date(e.oldestMs).toLocaleDateString()})}],[a]);return!i&&n.length===0?r(I,{icon:b,title:a(`archive.table.noCameras`,`No cameras`),description:a(`archive.table.addACamera`,`Add a camera first.`)}):r(N,{columns:s,rows:n,rowKey:e=>e.deviceId,onRowClick:e=>o(`/archive/${String(e.deviceId)}`),minWidthPx:720,maxBodyHeight:j,defaultSort:{columnKey:`camera`,dir:`asc`}})}var W=1440*60*1e3;function Ae(e){if(e.footageBytes===null||e.oldestMs===null)return null;let t=e.nowMs-e.oldestMs;return t<W?null:e.footageBytes/(t/W)}function je(e,t){return e===null||t===null||t<=0?null:e/t}function Me(e){let t=null;for(let n of e)n.oldestMs!==null&&(t===null||n.oldestMs<t)&&(t=n.oldestMs);return t}o();var G=`—`;function Ne({data:n}){let{t:i}=V(),{usage:a,footprint:o,rows:s,totals:c}=n,f=a!==null&&a.devicesRead!==`unavailable`,p=t(()=>Ae({footageBytes:f?a.totalUsedBytes:null,oldestMs:Me(s),nowMs:Date.now()}),[f,a,s]),m=je(t(()=>{let e=Ee(a?.locations??[]);return e===null||e.knownVolumes===0?null:e.freeBytes},[a?.locations]),p);return e(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-5`,"data-testid":`archive-key-numbers`,children:[r(v,{label:i(`archive.keyNumbers.footage`,`Footage`),icon:r(l,{className:`h-3.5 w-3.5`}),footer:f?void 0:i(`archive.keyNumbers.footageUnread`,`The recorder did not answer`),children:f?H(a.totalUsedBytes):G}),r(v,{label:i(`archive.keyNumbers.eventStorage`,`Event storage`),icon:r(d,{className:`h-3.5 w-3.5`}),footer:o===null?i(`archive.keyNumbers.eventsUnread`,`The event store did not answer`):i(`archive.keyNumbers.eventRows`,`{{count}} events`,{count:o.totalRows}),children:o===null?G:H(o.totalBytes)}),r(v,{label:i(`archive.keyNumbers.growth`,`Growth per day`),icon:r(u,{className:`h-3.5 w-3.5`}),footer:p===null?i(`archive.keyNumbers.growthUnknown`,`Needs a day of footage`):m===null?i(`archive.keyNumbers.daysUnknown`,`Free space unknown`):i(`archive.keyNumbers.daysLeft`,`{{days}} days of space left`,{days:Math.floor(m)}),children:p===null?G:H(p)}),r(v,{label:i(`archive.keyNumbers.cameras`,`Cameras`),icon:r(b,{className:`h-3.5 w-3.5`}),footer:i(`archive.keyNumbers.cameraStates`,`{{degraded}} degraded · {{off}} off`,{degraded:c.degraded,off:c.off}),children:i(`archive.keyNumbers.recordingOf`,`{{recording}} of {{total}} recording`,{recording:c.recording,total:s.length})}),r(v,{label:i(`archive.keyNumbers.warnings`,`Open warnings`),icon:r(y,{className:`h-3.5 w-3.5`}),footer:n.findings===null?i(`archive.keyNumbers.digestPending`,`No health digest yet`):void 0,children:n.findings===null?G:String(c.warnings)})]})}o();var Pe={active:`success`,readonly:`default`,drain:`warning`,disabled:`danger`};function Fe(){let{t}=V(),n=Ce(),[i,o]=a(null);return n.locations.length===0?r(I,{icon:l,title:t(`archive.storage.none`,`No storage locations`),description:t(`archive.storage.noneHint`,`Add a location to start storing footage and events.`)}):e(c,{children:[r(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3`,"data-testid":`archive-storage-cards`,children:n.locations.map(i=>{let a=xe(i);return e(`div`,{className:`flex flex-col gap-2 rounded-lg border border-border bg-surface p-3`,children:[e(`div`,{className:`flex items-start justify-between gap-2`,children:[e(`div`,{className:`min-w-0`,children:[r(`div`,{className:`truncate text-sm font-medium text-foreground`,children:i.displayName}),e(`div`,{className:`text-[11px] text-foreground-subtle`,children:[i.type,i.nodeId===void 0?``:` · ${i.nodeId}`]})]}),r(R,{variant:Pe[a],children:Se(a).label})]}),r(Te,{location:i,ownedBytes:n.ownedBytesById.get(i.id)??null}),r(we,{drain:n.drainOf(i)}),e(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`span`,{className:`text-[11px] text-foreground-subtle`,children:a===`active`?t(`archive.storage.writing`,`Taking new writes`):t(`archive.storage.notWriting`,`Not taking new writes`)}),r(O,{variant:`ghost`,onClick:()=>o(i),children:t(`archive.storage.manage`,`Manage`)})]})]},i.id)})}),i!==null&&r(F,{open:!0,onOpenChange:e=>!e&&o(null),children:e(A,{width:`xl`,placement:`sheet-on-mobile`,scroll:`body`,children:[r(te,{children:r(ne,{children:i.displayName})}),r(z,{children:r(De,{kinds:[i.type]})})]})})]})}o();var Ie=1440*60*1e3,Le=[1,7,30,90],Re=30;function ze(){let{t}=V(),i=x(),o=s(),[c,l]=a(Re),u=le({onSuccess:()=>{o.invalidateQueries({queryKey:[[`pipelineAnalytics`]]})}}),d=n(async()=>{await i({title:t(`recordings.eventsManagementSection.pruneTitle`,{count:c}),message:t(`recordings.eventsManagementSection.permanentlyDeletesEveryEventMotion`,`Permanently deletes every event (motion / object / audio) older than the cutoff across all cameras, and their media. This cannot be undone.`),confirmLabel:t(`recordings.eventsManagementSection.pruneEvents`,`Prune events`),variant:`danger`})&&u.mutate({olderThanMs:Date.now()-c*Ie,reason:`retention`})},[i,u,c,t]);return e(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,"data-testid":`prune-events-by-age`,children:[r(`span`,{className:`text-foreground-subtle`,children:t(`recordings.eventsManagementSection.pruneEventsOlderThan`,`Prune events older than`)}),r(S,{wrapperClassName:`inline-block w-auto`,value:c,onChange:e=>l(Number(e.target.value)),"aria-label":t(`recordings.eventsManagementSection.pruneEventsOlderThan`,`Prune events older than`),children:Le.map(e=>r(`option`,{value:e,children:t(`recordings.eventsManagementSection.ageDays`,{count:e})},e))}),e(O,{variant:`secondary`,onClick:()=>void d(),disabled:u.isPending,children:[u.isPending?r(g,{className:`h-3 w-3 animate-spin`}):r(E,{className:`h-3 w-3`}),t(`recordings.eventsManagementSection.pruneNow`,`Prune now`)]})]})}var Be=`inline-flex w-fit items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`;o();var Ve=`storage-migration`,He=new Set([`orphans`,`debug-media`,`ghost-ledger`]);function Ue(e){return[`${e.orphansReclaimed} orphan rows (${H(e.orphanBytesReclaimed)})`,e.includeDebugMedia?`${e.debugMediaReclaimed} debug files (${H(e.debugMediaBytesReclaimed)})`:null,`${e.ghostsForgotten} ghost rows (${H(e.ghostBytesForgotten)})`].filter(e=>e!==null).join(` · `)}function We(){let{t:e}=V(),t=L(Ve);return t===`pending`?null:t===`unknown`?r(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:e(`recordings.cleanupSection.couldNotCheckWhetherStorage`,`Could not check whether storage cleanup is installed on this hub.`)}):t===`present`?r(Ge,{}):null}function Ge(){let{t}=V(),n=x(),[i,o]=a(!1),[s,c]=a(null),l=pe({},{refetchInterval:2e3}),u=l.data??null,d=u!==null&&He.has(u.phase),f=oe(),p=D(),h=async()=>{if(await n({title:t(`recordings.cleanupSection.runStorageCleanup`,`Run storage cleanup?`),message:i?t(`recordings.cleanupSection.reclaimsLeftoverAnalyticsRowsAnd`,`Reclaims leftover analytics rows and files, debug stills/filmstrips, and ghost footage rows on frozen locations. Safe to re-run.`):t(`recordings.cleanupSection.reclaimsLeftoverAnalyticsRowsAnd2`,`Reclaims leftover analytics rows and files, and ghost footage rows on frozen locations. Debug stills are left alone. Safe to re-run.`),confirmLabel:t(`recordings.cleanupSection.runCleanup`,`Run cleanup`),variant:`danger`})){c(null);try{await f.mutateAsync({includeDebugMedia:i}),await l.refetch()}catch(e){c(e instanceof Error?e.message:String(e))}}},_=async()=>{if(u&&await n({title:t(`recordings.cleanupSection.cancelCleanup`,`Cancel cleanup?`),message:t(`recordings.cleanupSection.stopsAfterTheCurrentStep`,`Stops after the current step. Work already done stays done.`),confirmLabel:t(`recordings.cleanupSection.cancelCleanup2`,`Cancel cleanup`),variant:`danger`}))try{await p.mutateAsync({jobId:u.jobId}),await l.refetch()}catch{}};return e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`recordings.cleanupSection.cleanup`,`Cleanup`)}),r(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`recordings.cleanupSection.onePassOverLeftoverAnalytics`,`One pass over leftover analytics (database + files) and ghost footage rows on frozen locations. Does not time out — progress updates here until it finishes.`)}),e(`label`,{className:`mt-3 flex items-start gap-2 text-[11px] text-foreground`,children:[r(m,{checked:i,disabled:d,onChange:e=>{o(e.target.checked)},className:`mt-0.5 h-3.5 w-3.5 accent-primary`}),r(`span`,{children:t(`recordings.cleanupSection.alsoRemoveDebugMediaMotion`,`Also remove debug media (motion stills and track filmstrips)`)})]}),e(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[e(O,{variant:`unstyled`,type:`button`,disabled:d||f.isPending,onClick:()=>{h()},className:Be,children:[(d||f.isPending)&&r(g,{className:`h-3 w-3 animate-spin`}),r(C,{className:`h-3 w-3`}),t(`recordings.cleanupSection.runCleanup`,`Run cleanup`)]}),d&&r(O,{variant:`unstyled`,type:`button`,onClick:()=>{_()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:t(`common.cancel`,`Cancel`)})]}),s&&r(`p`,{className:`mt-2 text-[11px] text-danger`,children:s}),u&&e(`div`,{className:`mt-3 space-y-1 rounded-md border border-border px-2.5 py-2`,children:[e(`p`,{className:`text-xs text-foreground`,children:[t(`recordings.cleanupSection.phase`,`Phase:`),` `,r(`span`,{className:`font-medium`,children:u.phase}),d&&r(g,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),u.detail&&r(`p`,{className:`text-[11px] text-foreground-subtle`,children:u.detail}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:Ue(u)}),u.error&&r(`p`,{className:`text-[11px] text-danger`,children:u.error})]})]})}o();var Ke=2e3;function qe(){let{t}=V(),n=x(),a=s(),o=P(),c=k(void 0,{refetchInterval:e=>e.state.data?.state===`running`?Ke:!1}),u=c.data,d=u?.state===`running`,f=d||o.isPending;i(()=>{u?.state!==`done`||u.finishedAtMs===null||(a.invalidateQueries({queryKey:[[`recording`]]}),a.invalidateQueries({queryKey:[[`pipelineAnalytics`]]}))},[u?.state,u?.finishedAtMs,a]);let p=async()=>{await n({title:t(`recordings.diskReconcileSection.reconcileStorageFromDisk`,`Reconcile storage from disk?`),message:t(`recordings.diskReconcileSection.makesTheDatabaseMatchThe`,`Makes the database match the filesystem: recordings index, tracks, events and media whose files are gone. Favourited tracks without files are deleted. Snapshot-less motion/audio events are deleted. Enrolled identities stay. This cannot be undone.`),confirmLabel:t(`recordings.diskReconcileSection.reconcile`,`Reconcile`),variant:`warning`})&&(await o.mutateAsync(),await c.refetch())},m=d?u.total>0?`Reconciling ${String(u.completed)}/${String(u.total)}…`:`Reconciling…`:o.isPending?`Reconciling…`:`Reconcile from disk`;return e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[r(`h3`,{className:`text-sm font-semibold text-foreground`,children:t(`recordings.diskReconcileSection.diskReconcile`,`Disk reconcile`)}),r(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`recordings.diskReconcileSection.deletesDatabaseRowsWhoseFiles`,`Deletes database rows whose files are gone. Enrolled identities stay.`)}),e(`div`,{className:`mt-3 flex flex-col gap-2`,children:[e(O,{variant:`unstyled`,type:`button`,onClick:()=>void p(),disabled:f,className:`inline-flex w-fit items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[f?r(g,{className:`h-3.5 w-3.5 animate-spin`}):r(l,{className:`h-3.5 w-3.5`}),m]}),u?.state===`done`?e(`p`,{className:`text-[11px] text-foreground-subtle`,children:[t(`recordings.diskReconcileSection.lastRun`,`Last run:`),` `,t(`recordings.diskReconcileSection.summary`,{completed:String(u.completed),tracks:String(u.tracks),events:String(u.events),media:String(u.mediaDropped)}),u.failed.length>0?t(`recordings.diskReconcileSection.failed`,`, {{value1}} failed ({{value2}})`,{value1:String(u.failed.length),value2:u.failed.join(`, `)}):``,`.`]}):null,u?.state===`error`&&u.error!==null?e(`p`,{className:`text-[11px] text-destructive`,children:[t(`recordings.diskReconcileSection.reconcileFailed`,`Reconcile failed:`),` `,u.error]}):null]})]})}var K=1e3,q=60*K,J=60*q;function Y(e){return e.toLocaleString(`en-US`)}function Je(e){if(!Number.isFinite(e)||e<0)return`—`;if(e>=J){let t=Math.floor(e/J),n=Math.round(e%J/q);return`${t.toString()}h ${n.toString()}m`}if(e>=q){let t=Math.floor(e/q),n=Math.round(e%q/K);return`${t.toString()}m ${n.toString()}s`}return`${Math.max(0,Math.round(e/K)).toString()}s`}function X(e){let t=Math.max(0,e.observedAt-e.startedAt),n=e.filesTotal===null?`${Y(e.filesMoved)} files`:`${Y(e.filesMoved)} / ${Y(e.filesTotal)} files`,r=e.filesTotal===null||e.filesTotal===0?null:Math.min(1,e.filesMoved/e.filesTotal),i=t>0&&e.filesMoved>0,a=i?`${H(e.bytesMoved/t*K)}/s`:null,o=e.filesTotal===null?null:e.filesTotal-e.filesMoved,s=!i||o===null||o<=0?null:`~${Je(o*t/e.filesMoved)} left`;return{counted:n,fraction:r,moved:`${H(e.bytesMoved)} moved`,rate:a,eta:s}}function Z(e){let t=X(e);return[t.counted,t.moved,t.rate,t.eta].filter(e=>e!==null).join(` · `)}o();var Ye=`storage-migration`,Q=[{id:`recordings`,labelKey:`recordings.storageMigrationSection.classRecordings`,locationType:`recordings`},{id:`recordingsLow`,labelKey:`recordings.storageMigrationSection.classRecordingsLow`,locationType:`recordingsLow`},{id:`eventMedia`,labelKey:`recordings.storageMigrationSection.classEventMedia`,locationType:`eventMedia`}],Xe=new Set([`planning`,`sealing`,`pausing`,`moving`,`draining`,`verifying`,`repointing`,`refreshing`,`resuming`]);function Ze(){let{t}=V(),n=L(Ye);return n===`pending`?e(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[r(g,{className:`h-4 w-4 animate-spin`}),t(`migration.storageMigrationSection.checkingWhetherStorageMigrationIs`,`Checking whether storage migration is installed…`)]}):n===`unknown`?r(I,{icon:y,title:t(`migration.storageMigrationSection.couldnTCheckWhetherStorage`,`Couldn't check whether storage migration is installed`),description:t(`migration.storageMigrationSection.theCapabilityRegistryDidNot`,`The capability registry did not answer, so this panel has nothing to report either way — it is not a statement that the capability is missing. Reload to ask again.`)}):n===`absent`?r(I,{icon:h,title:t(`migration.storageMigrationSection.storageMigrationNotInstalled`,`Storage migration not installed`),description:t(`migration.storageMigrationSection.theCapabilityRegistryAnsweredNo`,`The capability registry answered: no addon in this cluster provides storage-migration. Once one is deployed, this panel moves recordings, low-res recordings and event media to new storage locations in one coordinated, verified operation.`)}):r(Qe,{})}function Qe(){let{t:n}=V(),i=x(),{data:o}=re({}),[s,c]=a({}),[l,u]=a({}),[d,f]=a(null),[p,m]=a(null),v=t(()=>{let e=new Map;for(let t of o??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[o]),y=t(()=>{let e=new Map;for(let t of o??[]){if(!w(t))continue;let n=e.get(t.type);n?n.push(t.id):e.set(t.type,[t.id])}let t=new Map;for(let[n,r]of e)r.length===1&&t.set(n,r[0]);return t},[o]),b=ae({},{refetchInterval:2e3}),C=b.data??null,T=C!==null&&Xe.has(C.phase),E=t(()=>{let e={};for(let t of Q){let n=s[t.id];n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[s]),D=t(()=>{let e={};for(let t of Q){if(!s[t.id])continue;let n=l[t.id]??y.get(t.locationType);n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[s,l,y]),k=t(()=>({destinations:E??{},...D?{sources:D}:{}}),[E,D]),A=ie(k,{enabled:!1,retry:!1}),j=fe(),M=ee(),N=async()=>{if(!E)return;m(null);let e=await A.refetch();if(e.error){m(e.error instanceof Error?e.error.message:String(e.error));return}f(e.data??null)},P=async()=>{if(E&&await i({title:n(`migration.storageMigrationSection.startStorageMigration`,`Start storage migration?`),message:n(`migration.storageMigrationSection.copiesTheSelectedClassesFrom`,`Copies the selected classes from the chosen source to the destination, verifies, then either makes the destination the default (if the source was) or disables the source. Safe to re-run if interrupted.`),confirmLabel:n(`migration.storageMigrationSection.startMigration`,`Start migration`),variant:`danger`})){m(null);try{await j.mutateAsync(k),f(null),await b.refetch()}catch(e){m(e instanceof Error?e.message:String(e))}}},F=async()=>{if(C&&await i({title:n(`migration.storageMigrationSection.cancelMigration`,`Cancel migration?`),message:n(`migration.storageMigrationSection.stopsTheInProgressMigration`,`Stops the in-progress migration. Data already moved and verified stays at the destination; anything already repointed is not reverted.`),confirmLabel:n(`migration.storageMigrationSection.cancelMigration2`,`Cancel migration`),variant:`danger`}))try{await M.mutateAsync({jobId:C.jobId}),await b.refetch()}catch{}};return e(`div`,{className:`flex flex-col gap-6`,children:[e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[e(`h3`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[r(h,{className:`h-3.5 w-3.5`}),n(`migration.storageMigrationSection.storageMigration`,`Storage migration`)]}),r(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:n(`migration.storageMigrationSection.moveRecordingsLowResRecordings`,`Move recordings, low-res recordings and/or event media from one location to another: copies via the recorder / pipeline-analytics movers, verifies, then either repoints the default (when the source was the default) or disables the source (when it was not). Skip a class with an empty destination.`)}),r(`div`,{className:`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-3`,children:Q.map(t=>{let i=v.get(t.locationType)??[],a=y.get(t.locationType)??``;return e(`div`,{className:`space-y-2`,children:[r(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:n(t.labelKey)}),e(`div`,{className:`space-y-1`,children:[r(`label`,{htmlFor:`migration-from-${t.id}`,className:`text-[10px] text-foreground-subtle`,children:n(`recordings.storageMigrationSection.classFrom`,{label:n(t.labelKey)})}),r(S,{id:`migration-from-${t.id}`,value:l[t.id]??a,onChange:e=>{let n=e.target.value;u(e=>({...e,[t.id]:n}))},disabled:T,className:`w-full`,children:i.map(t=>e(`option`,{value:t.id,children:[t.displayName,w(t)?``:` (${n(`recordings.storageMigrationSection.readOnly`)})`]},t.id))})]}),e(`div`,{className:`space-y-1`,children:[r(`label`,{htmlFor:`migration-dest-${t.id}`,className:`text-[10px] text-foreground-subtle`,children:n(`recordings.storageMigrationSection.classTo`,{label:n(t.labelKey)})}),e(S,{id:`migration-dest-${t.id}`,value:s[t.id]??``,onChange:e=>{let n=e.target.value;c(e=>({...e,[t.id]:n}))},disabled:T,className:`w-full`,children:[r(`option`,{value:``,children:n(`migration.storageMigrationSection.skip`,`— skip —`)}),i.map(e=>r(`option`,{value:e.id,children:e.displayName},e.id))]})]})]},t.id)})}),p&&r(`p`,{className:`mt-2 text-[11px] text-danger`,children:p}),e(`div`,{className:`mt-3 flex items-center gap-2`,children:[e(O,{variant:`unstyled`,type:`button`,onClick:()=>{N()},disabled:!E||A.isFetching||T,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[A.isFetching&&r(g,{className:`h-3 w-3 animate-spin`}),n(`migration.storageMigrationSection.plan`,`Plan`)]}),e(O,{variant:`unstyled`,type:`button`,onClick:()=>{P()},disabled:!E||j.isPending||T,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[j.isPending&&r(g,{className:`h-3 w-3 animate-spin`}),n(`migration.storageMigrationSection.startMigration`,`Start migration`)]})]}),d&&r(`div`,{className:`mt-3 divide-y divide-border rounded-md border border-border`,children:d.moves.length===0?r(`p`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:n(`migration.storageMigrationSection.nothingToMoveSelectedDestinations`,`Nothing to move — selected destinations match the current defaults.`)}):d.moves.map(t=>e(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground`,children:[t.storageClass,`: `,t.fromLocationId,` → `,t.toLocationId]},`${t.storageClass}-${t.toLocationId}`))}),C&&e(`div`,{className:`mt-4 border-t border-border pt-3`,children:[e(`div`,{className:`flex items-center justify-between`,children:[r(`h4`,{className:`text-xs font-semibold text-foreground`,children:n(`migration.storageMigrationSection.migrationStatus`,`Migration status`)}),T&&e(O,{variant:`unstyled`,type:`button`,onClick:()=>{F()},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10`,children:[r(_,{className:`h-3 w-3`}),n(`common.cancel`,`Cancel`)]})]}),e(`p`,{className:`mt-1 text-xs text-foreground`,children:[n(`migration.storageMigrationSection.phase`,`Phase:`),` `,r(`span`,{className:`font-medium`,children:C.phase}),T&&r(g,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),C.error&&r(`p`,{className:`mt-1 text-[11px] text-danger`,children:C.error}),C.pausedParticipants.length>0&&e(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:[n(`migration.storageMigrationSection.paused`,`Paused:`),` `,C.pausedParticipants.join(`, `)]}),r(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:C.moves.map(e=>r($e,{move:e},`${e.storageClass}-${e.fromLocationId}`))})]}),r($,{})]}),r(et,{running:T}),r(nt,{})]})}function $e({move:t}){let{t:n}=V(),i=t.progress===null?null:X(t.progress);return e(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[e(`div`,{className:`flex items-center justify-between`,children:[e(`span`,{className:`text-foreground`,children:[t.storageClass,`: `,t.fromLocationId,` → `,t.toLocationId]}),e(`span`,{className:`text-foreground-subtle`,children:[t.state??n(`common.pending`),t.error?` (${t.error})`:``]})]}),t.progress!==null&&e(`div`,{className:`mt-1 space-y-1`,children:[i!==null&&i.fraction!==null&&r(`div`,{className:`h-1 w-full overflow-hidden rounded bg-border`,children:r(`div`,{className:`h-full bg-primary`,style:{width:`${(i.fraction*100).toFixed(1)}%`}})}),r(`p`,{className:`text-[10px] text-foreground-subtle`,children:Z(t.progress)})]})]})}function $(){let{t}=V(),{data:n}=de({});return!n||n.length===0?null:e(`div`,{className:`mt-4 border-t border-border pt-3`,children:[r(`h4`,{className:`text-xs font-semibold text-foreground`,children:t(`migration.storageMigrationSection.migrationHistory`,`Migration history`)}),r(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:n.map(t=>e(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:[r(`span`,{className:`font-medium text-foreground`,children:t.phase}),` · `,Object.entries(t.destinations).filter(e=>typeof e[1]==`string`).map(([e,t])=>`${e} → ${t}`).join(`, `),` · `,new Date(t.startedAt).toLocaleString()]},t.jobId))})]})}function et({running:t}){let{t:n}=V(),i=x(),o=ue({},{staleTime:1/0,refetchOnWindowFocus:!1}),s=ce(),[c,l]=a(null),u=o.data??[];if(u.length===0)return null;let d=async e=>{if(await i({title:n(`migration.storageMigrationSection.drainRemaining`,`Drain remaining {{storageClass}}?`,{storageClass:e.storageClass}),message:`Moves what is still on ${e.fromLocationId} to ${e.toLocationId}. Nothing is paused and no default is changed — this is the second half of a migration, run on its own. It is resumable: cancelling leaves everything readable from both locations.`,confirmLabel:n(`migration.storageMigrationSection.drainRemaining2`,`Drain remaining`),variant:`danger`})){l(null);try{await s.mutateAsync({classes:[e.storageClass]}),await o.refetch()}catch(e){l(e instanceof Error?e.message:String(e))}}};return e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[e(`div`,{className:`flex items-start justify-between gap-2`,children:[r(`h3`,{className:`text-sm font-semibold text-foreground`,children:n(`migration.storageMigrationSection.leftOnTheOldLocation`,`Left on the old location`)}),e(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r(`span`,{className:`text-[10px] text-foreground-subtle`,children:o.dataUpdatedAt>0?n(`migration.storageMigrationSection.measured`,`Measured {{value1}}`,{value1:new Date(o.dataUpdatedAt).toLocaleTimeString()}):n(`migration.storageMigrationSection.measuredNever`,`Measured — never`)}),r(O,{variant:`unstyled`,type:`button`,onClick:()=>{o.refetch()},disabled:o.isFetching,className:`rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:o.isFetching?n(`migration.storageMigrationSection.counting`,`Counting…`):n(`common.refresh`,`Refresh`)})]})]}),r(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:n(`migration.storageMigrationSection.aMigrationRepointsFirstAnd`,`A migration repoints first and drains behind. If the drain was cancelled, failed, or was interrupted by a restart, the data below is still on the source — readable, but not where the defaults now point. Draining moves it; it changes no default and pauses nothing.`)}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:n(`migration.storageMigrationSection.thisCountIsTakenOn`,`This count is taken on demand: measuring it walks the whole media collection, so it is not refreshed on a timer. Press Refresh after a drain finishes.`)}),c&&r(`p`,{className:`mt-2 text-[11px] text-danger`,children:c}),r(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:u.map(i=>e(`div`,{className:`flex items-center justify-between gap-2 px-2.5 py-1.5 text-[11px]`,children:[e(`span`,{className:`text-foreground`,children:[i.storageClass,`: `,i.fromLocationId,` → `,i.toLocationId,r(`span`,{className:`ml-2 text-foreground-subtle`,children:tt(i)})]}),r(O,{variant:`unstyled`,type:`button`,onClick:()=>{d(i)},disabled:t||s.isPending,className:`shrink-0 rounded border border-border px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`,children:n(`migration.storageMigrationSection.drainRemaining2`,`Drain remaining`)})]},`${i.storageClass}-${i.fromLocationId}`))})]})}function tt(e){if(e.items===null)return B.t(`recordings.storageMigrationSection.residueUnknown`);let t=e.items.toLocaleString(`en-US`);return e.bytes===null?B.t(`recordings.storageMigrationSection.residueRows`,{count:e.items,items:t}):B.t(`recordings.storageMigrationSection.residueSegments`,{count:e.items,items:t,size:H(e.bytes)})}function nt(){let{t}=V(),{data:n}=se({},{refetchInterval:2e3}),i=(n??[]).filter(e=>e.migrationJobId===null&&e.job.state===`running`);return i.length===0?null:e(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[r(`h3`,{className:`text-sm font-semibold text-foreground`,children:t(`migration.storageMigrationSection.moversRunningOutsideAMigration`,`Movers running outside a migration`)}),r(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:i.map(t=>e(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[e(`div`,{className:`text-foreground`,children:[t.lane,`: `,t.job.fromLocationId,` → `,t.job.toLocationId]}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:Z({filesMoved:t.job.filesMoved,filesTotal:t.job.filesTotal,bytesMoved:t.job.bytesMoved,startedAt:t.job.startedAt,observedAt:t.observedAt})})]},t.job.jobId))})]})}o();function rt({openOnMount:t}){let{t:n}=V(),[o,s]=a(t);return i(()=>{t&&s(!0)},[t]),r(me,{expanded:o,onExpandedChange:s,header:e(`span`,{className:`flex items-center gap-2 text-sm font-medium text-foreground`,children:[r(f,{className:`h-3.5 w-3.5`}),n(`archive.tools.title`,`Tools`),r(`span`,{className:`text-[11px] font-normal text-foreground-subtle`,children:n(`archive.tools.subtitle`,`Storage migration, prune events, cleanup, all exports, reconcile from disk`)})]}),children:e(`div`,{className:`flex flex-col gap-6`,"data-testid":`archive-tools`,children:[e(`section`,{className:`flex flex-col gap-2`,children:[r(`h3`,{className:`text-sm font-semibold text-foreground`,children:n(`archive.tools.migration`,`Move storage`)}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`archive.tools.migrationHint`,`Copy footage, low-res footage or event media to a new location, verify, then repoint the default. Applies to every camera.`)}),r(Ze,{})]}),e(`section`,{className:`flex flex-col gap-2`,children:[r(`h3`,{className:`text-sm font-semibold text-foreground`,children:n(`archive.tools.pruneEvents`,`Prune old events`)}),r(ze,{})]}),r(We,{}),e(`section`,{className:`flex flex-col gap-2`,"data-testid":`archive-all-exports`,children:[r(`h3`,{className:`text-sm font-semibold text-foreground`,children:n(`archive.tools.allExports`,`All exports`)}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`archive.tools.allExportsHint`,`Every export across all cameras, including cameras that were removed.`)}),r(ye,{})]}),r(qe,{})]})})}o();function it(){let{t}=V(),n=be(),{hash:a}=ge();return i(()=>{a.length>1&&document.getElementById(a.slice(1))?.scrollIntoView({block:`start`})},[a]),r(_e,{icon:T,title:t(`nav.archive`,`Archive`),subtitle:t(`archive.subtitle`,`Recorded footage and captured events — what they occupy, where they are written, and how each camera is doing.`),children:e(`div`,{className:`flex flex-col gap-4`,children:[r(Ne,{data:n}),r(M,{headingId:`archive-storage`,title:t(`archive.section.storage`,`Storage`),icon:l,children:r(`div`,{className:`p-3`,children:r(Fe,{})})}),r(M,{headingId:`archive-cameras`,title:t(`archive.section.cameras`,`Cameras`),icon:b,children:r(ke,{rows:n.rows,isLoading:n.isLoading})}),r(`div`,{id:`activity`,children:r(M,{headingId:`archive-activity`,title:t(`archive.section.activity`,`Activity & health`),icon:p,children:r(`div`,{className:`p-3`,children:r(ve,{data:n})})})}),r(`div`,{id:`tools`,children:r(rt,{openOnMount:a===`#tools`})})]})})}export{it as ArchivePage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$r as d,Bn as f,Fr as p,Ga as m,Jr as h,Ka as g,Lr as _,Q as v,Ri as y,Tt as b,Y as x,Yn as S,Z as C,ai as w,ca as T,ct as ee,ft as E,hn as D,ki as O,ln as k,mn as A,ot as te,pa as j,pi as M,pn as N,qa as P,qt as F,ra as I,t as L,ta as R,tn as z,ut as ne,xi as re,yt as ie,z as B}from"./player-overlays-BF9w4QU-.js";import{Zc as V,ai as ae,ht as oe,vc as H}from"./client-DhfZUoXe.js";import{t as se}from"./chevron-down-CBb-F8DT.js";import{v as ce}from"./terminal-Dgb4lrgM.js";import{n as U,t as le}from"./circle-play-BxUrE_Qy.js";import{t as ue}from"./scissors-Bbq6WhOK.js";import{t as W}from"./square-check-big-DAcFGNUN.js";import{$f as G,$l as de,Bi as fe,Cd as pe,Dr as me,Gi as he,Ip as ge,Jl as _e,Kf as ve,Li as ye,Ll as be,Mi as xe,Qf as Se,Ql as Ce,Ri as we,Sr as Te,Xi as Ee,Yi as De,Yl as Oe,Zd as ke,Zf as Ae,Zl as je,_a as K,bd as Me,d as Ne,ea as Pe,gp as Fe,iu as Ie,no as Le,oa as Re,pr as ze,qf as Be,ru as Ve,sp as He,tt as Ue,tu as We,ya as q,yi as Ge,zs as Ke}from"./src-D9hgltMI.js";import{t as J}from"./i18n-DCYaeyv_.js";import{t as Y}from"./useTranslation-BJr-n0es.js";import"./mount-B2oUIKRS.js";import{A as qe,_i as Je,hi as Ye,mi as Xe,pi as Ze,vi as Qe,yi as $e}from"./index-DPyWa2vo.js";import{i as et,n as tt,r as nt,t as rt}from"./use-archive-data-D7nUbRKv.js";import{t as it}from"./format-size-DIxKXxtj.js";import{a as at,i as ot,r as st,t as ct}from"./authed-media-BK50tJc4.js";import{t as lt}from"./AdminSectionedPage-CtcZ5jHa.js";import{a as ut,o as dt}from"./PanelContent-DJ8p-hQ1.js";import{a as ft,d as pt,f as mt,i as ht,l as gt,n as _t,o as vt,p as yt,r as bt,t as xt,u as St}from"./use-paged-list-DTJY2xpg.js";c();var Ct={recording:`recording`,motion:null,detection:`object-detection`,"event-media":`event-saving`},wt={"motion-without-detections":`motion`,"detections-under-floor":`detection`,"inference-too-slow":`detection`,"frames-shed":`detection`,"inference-device-unusable":null},Tt={recording:`recording`,motion:null,detection:`detection`,"event-media":null},Et=[`recording`,`motion`,`detection`,`event-media`];function Dt(e,t){switch(e){case`recording`:return t.recording===null?null:t.recording.active?`ok`:`warning`;case`motion`:return t.motion===null?null:t.motion.enabled?`ok`:`off`;case`detection`:return t.detection===null?null:`ok`;case`event-media`:return`ok`}}function Ot(e){return e.some(e=>e.severity===`critical`)?`critical`:e.some(e=>e.severity===`warning`)?`warning`:`ok`}function kt(e,t){return Et.map(n=>{let r=t.filter(e=>wt[e.kind]===n);if(e===void 0)return{fn:n,state:r.length>0?Ot(r):`unknown`,findings:r};let i=Ct[n];if(i!==null&&e.switchedOff.includes(i))return{fn:n,state:`off`,findings:r};let a=Tt[n];return a!==null&&e.degraded.some(e=>e.stage===a)?{fn:n,state:r.length>0?Ot(r):`unknown`,findings:r}:r.length>0?{fn:n,state:Ot(r),findings:r}:n===`recording`&&e.recording?.mode===`off`?{fn:n,state:`off`,findings:r}:{fn:n,state:Dt(n,e)??`unknown`,findings:r}})}var At={ok:`success`,off:`default`,warning:`warning`,critical:`danger`,unknown:`default`};function jt(e,t){return e.statuses?.find(e=>e.deviceId===t)}function Mt({data:t,deviceId:n}){let{t:r}=Y(),a=kt(jt(t,n),tt(t.findings,n));return e(`div`,{className:`flex flex-col gap-4`,"data-testid":`archive-health`,children:[t.findings===null&&i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`archive.health.noDigest`,`The health digest has not run yet — findings are not available.`)}),i(`ul`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border bg-surface`,children:a.map(t=>e(`li`,{className:`flex flex-col gap-1 p-3`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:r(`archive.function.${t.fn}`,t.fn)}),i(q,{variant:At[t.state],children:r(`archive.functionState.${t.state}`,t.state)})]}),t.findings.map(t=>e(`div`,{className:`text-[11px] text-foreground-subtle`,children:[i(`span`,{className:`text-foreground`,children:t.what}),` — `,t.action]},t.id))]},t.fn))}),e(`div`,{className:`flex flex-col gap-2`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:r(`archive.health.logs`,`Camera log`)}),i(Xe,{className:`text-xs text-primary hover:underline`,to:`/system/logs?deviceId=${String(n)}`,children:r(`archive.health.openLogs`,`Open in Logs`)})]}),i(`div`,{className:`overflow-hidden rounded-lg border border-border bg-surface`,children:i(ze,{deviceId:n,limit:100,maxHeight:`max-h-80`,showFilters:!0})})]})]})}function Nt({deviceId:t,seekTo:n,onExportRange:r}){return i(Re,{deviceId:t,children:i(Ee,{children:i(he,{children:i(L,{children:i(Ne,{children:e(`div`,{className:`flex flex-col gap-3`,"data-testid":`archive-review`,children:[i(`div`,{className:`mx-auto w-full max-w-4xl overflow-hidden rounded-lg border border-border bg-black`,children:i(ut,{deviceId:t})}),i(ye,{deviceId:t,seekTo:n,onExportRange:r})]})})})})})})}function Pt({deviceId:e}){return i(Re,{deviceId:e,children:i(qe,{deviceId:e,sectionFilter:e=>e.location===`top-tab`&&e.tab===`recording`})},e)}function Ft(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function It(e,t){let n=Ft(e);return n.length===0?J.t(`helpers.cameraDisk.defaultRoot`):n.map(e=>t.get(e)??e).join(` + `)}function Lt(e,t,n){if(e.length===0)return null;let r=e[0];if(e.length===1&&r!==void 0)return{label:It(r,t),exact:!0};if(n===null)return null;let i=e.find(e=>Ft(e).includes(n));return i===void 0?null:{label:It(i,t),exact:!1}}var Rt=[{value:`retention`,labelKey:`recordings.storageSection.pruneRetention`},{value:`quota`,labelKey:`recordings.storageSection.pruneQuota`},{value:`operator`,labelKey:`recordings.storageSection.pruneOperator`}],zt=`—`;function Bt({data:t,row:a}){let{t:s}=Y(),c=ee(),u=l(),[f,p]=o(`retention`),m=ke({}).data,h=r(()=>{u.invalidateQueries({queryKey:[[`recording`]]}),u.invalidateQueries({queryKey:[[`recordingArchive`]]}),u.invalidateQueries({queryKey:[[`pipelineAnalytics`]]})},[u]),g=pe({onSuccess:h}),_=Me({onSuccess:h}),v=_e({onSuccess:h}),y=n(()=>{let e=new Map((m??[]).map(e=>[e.id,e.displayName])),n=(m??[]).filter(e=>e.type===`recordings`),r=(n.find(e=>H(e)===`active`)??n[0])?.id??null;return Lt(t.usage?.locations??[],e,r)},[m,t.usage?.locations]),b=r(async(e,t,n)=>c({title:e,message:t,confirmLabel:n,variant:`danger`}),[c]),S=async()=>{await b(s(`archive.space.pruneTitle`,`Apply retention to {{name}}?`,{name:a.name}),s(`archive.space.pruneMessage`,`Footage beyond the retention policy is permanently deleted.`),s(`archive.space.pruneNow`,`Prune now`))&&g.mutate({deviceId:a.deviceId,reason:f})},C=async()=>{await b(s(`archive.space.deleteFootageTitle`,`Delete all footage for {{name}}?`,{name:a.name}),s(`archive.space.deleteFootageMessage`,`Permanently deletes {{size}} of recorded footage. This cannot be undone.`,{size:a.footageBytes===null?zt:it(a.footageBytes)}),s(`archive.space.deleteFootage`,`Delete footage`))&&_.mutate({deviceId:a.deviceId})},w=async()=>{await b(s(`archive.space.deleteEventsTitle`,`Delete all events for {{name}}?`,{name:a.name}),s(`archive.space.deleteEventsMessage`,`Permanently deletes the events and their media. This cannot be undone.`),s(`archive.space.deleteEvents`,`Delete events`))&&v.mutate({deviceId:a.deviceId})};return e(`div`,{className:`flex flex-col gap-4`,"data-testid":`archive-space`,children:[e(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[i(x,{label:s(`archive.space.footage`,`Footage`),icon:i(d,{className:`h-3.5 w-3.5`}),footer:y===null?s(`archive.space.diskUnknown`,`Disk not reported`):y.exact?y.label:s(`archive.space.diskDefault`,`{{label}} (default)`,{label:y.label}),children:a.footageBytes===null?zt:it(a.footageBytes)}),i(x,{label:s(`archive.space.events`,`Event storage`),footer:a.eventRows===null?void 0:s(`archive.space.eventRows`,`{{count}} events`,{count:a.eventRows}),children:a.eventBytes===null?zt:it(a.eventBytes)}),i(x,{label:s(`archive.space.oldest`,`Oldest footage`),children:a.oldestMs===null?zt:new Date(a.oldestMs).toLocaleDateString()})]}),e(`div`,{className:`flex flex-col gap-2 rounded-lg border border-danger/40 p-3`,children:[i(`h3`,{className:`text-sm font-semibold text-danger`,children:s(`archive.space.danger`,`Danger zone`)}),e(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[i(`span`,{className:`text-foreground-subtle`,children:s(`recordings.storageSection.pruneReason`,`Prune reason`)}),i(E,{wrapperClassName:`inline-block w-auto`,value:f,"aria-label":s(`recordings.storageSection.pruneReason`,`Prune reason`),onChange:e=>{let t=Rt.find(t=>t.value===e.target.value);t&&p(t.value)},children:Rt.map(e=>i(`option`,{value:e.value,children:s(e.labelKey)},e.value))})]}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(G,{variant:`secondary`,onClick:()=>void S(),disabled:g.isPending,children:[i(ue,{className:`h-3.5 w-3.5`}),s(`archive.space.applyRetention`,`Apply retention now`)]}),e(G,{variant:`secondary`,onClick:()=>void C(),disabled:_.isPending,children:[i(z,{className:`h-3.5 w-3.5`}),s(`archive.space.deleteFootage`,`Delete footage`)]}),e(G,{variant:`secondary`,onClick:()=>void w(),disabled:v.isPending,children:[i(z,{className:`h-3.5 w-3.5`}),s(`archive.space.deleteEvents`,`Delete events`)]})]})]})]})}function Vt(e){let t=e.subLabel??e.label;if(t!==void 0)return t;let n=e.audioLabels?.[0]?.label;return n!==void 0&&n.length>0?n:void 0}var Ht=720*60*60*1e3;function Ut(e){let t=[];for(let n of e)t.push(...n);return t}function Wt(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function Gt(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function Kt(e,t){return`${String(e)}:${t}`}function qt(e,t){let n=new Map,r=new Set;for(let i of e){let e=Kt(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Jt(e,t){return{since:e.fromMs??t-Ht,until:e.toMs??t}}var Yt=typeof Oe==`function`,Xt=`Track deletion arrives with the next server update`;function Zt(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Qt=Yt?Oe:Zt,$t=200,en=3e4,tn=[];function nn(e){let t=ie(),n=e.deviceIds.length>0,r=[...e.deviceIds].sort((e,t)=>e-t),{data:i,isLoading:a}=s({queryKey:[`events-feed`,r,e.since,e.until,e.minImportance??null,e.classFilter??null],enabled:n,staleTime:en,refetchInterval:en,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEventsBatch.query({deviceIds:r,since:e.since,until:e.until,limit:$t,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>e.events.map(t=>({...t,deviceId:e.deviceId})))});return{rows:Wt(Ut(i??tn),`importance`),isLoading:n&&a}}c();var rn=[`events-feed`],an=2e3;function on(e){let n=l(),i=e?.paused===!0,s=t(n);s.current=n;let c=t(i);c.current=i;let[u,d]=o(!1),f=r(()=>{s.current.invalidateQueries({queryKey:rn})},[]),p=t(void 0);p.current||=yt({delayMs:an,invalidate:()=>{c.current?d(!0):f()}}),a(()=>()=>p.current?.cancel(),[]),a(()=>{i||!u||(d(!1),f())},[i,u,f]);let m=r(()=>{d(!1),f()},[f]);return ge(V.PipelineAnalyticsDetectionEvent,()=>{p.current?.trigger()}),ge(V.PipelineAnalyticsTrackEnded,()=>{p.current?.trigger()}),{pending:u,refreshNow:m}}c();function sn({groups:t,selected:r,onChange:a,loading:s=!1}){let{t:c}=Y(),l=Te(),[u,d]=o(!1),[p,m]=o(``),[h,_]=o(new Set),v=p.trim().toLowerCase(),y=e=>v.length===0||Ae(e,c).toLowerCase().includes(v),b=n(()=>t.map(e=>({macro:e.macro,subs:e.subs.filter(t=>y(t)||y(e.macro))})).filter(e=>y(e.macro)||e.subs.length>0),[t,v]),x=e=>_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),S=e=>{let t=new Set(r),n=r.has(e.macro.kind)&&e.subs.every(e=>r.has(e.kind)),i=[e.macro.kind,...e.subs.map(e=>e.kind)];if(n)for(let e of i)t.delete(e);else for(let e of i)t.add(e);a(t)},C=e=>{let t=new Set(r);t.has(e)?t.delete(e):t.add(e),a(t)},w=()=>a(new Set),T=r.size;return e(`div`,{className:`relative`,children:[e(G,{variant:`unstyled`,type:`button`,onClick:()=>d(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${T>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i(k,{className:`h-3.5 w-3.5`}),T>0?c(`detectionIntelligence.eventKindFilter.kinds`,`Kinds ({{value1}})`,{value1:String(T)}):c(`detectionIntelligence.eventKindFilter.kinds2`,`Kinds`),i(se,{className:`h-3 w-3`})]}),u&&e(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[e(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[i(f,{className:`h-3.5 w-3.5 text-foreground-subtle`}),i(He,{type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:c(`detectionIntelligence.eventKindFilter.searchKinds`,`Search kinds…`),className:`w-full bg-transparent py-1 text-xs outline-none`}),T>0&&i(G,{variant:`unstyled`,type:`button`,onClick:w,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:c(`detectionIntelligence.eventKindFilter.clear`,`Clear`)})]}),b.length===0&&i(`div`,{className:`px-1 py-2 text-[11px] text-foreground-subtle`,children:s?c(`detectionIntelligence.eventKindFilter.loadingKinds`,`Loading kinds…`):v.length>0?c(`detectionIntelligence.eventKindFilter.noKindMatchesThatSearch`,`No kind matches that search.`):c(`detectionIntelligence.eventKindFilter.theseCamerasAdvertiseNoEvent`,`These cameras advertise no event kinds.`)}),b.map(t=>{let n=Se(t.macro.iconId),a=h.has(t.macro.kind)||v.length>0,o=r.has(t.macro.kind);return e(`div`,{className:`mb-0.5`,children:[e(`div`,{className:`flex items-center gap-1`,children:[t.subs.length>0?i(G,{variant:`unstyled`,type:`button`,onClick:()=>x(t.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":c(`detectionIntelligence.eventKindFilter.expand`,`Expand`),children:i(a?se:R,{className:`h-3 w-3`})}):i(`span`,{className:`w-3`}),e(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[i(g,{checked:o,onChange:()=>S(t),className:`accent-primary`}),i(n,{className:`h-3.5 w-3.5`,style:{color:l(t.macro.kind)}}),i(`span`,{className:`font-medium`,children:Ae(t.macro,c)})]})]}),a&&t.subs.map(t=>{let n=Se(t.iconId);return e(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[i(g,{checked:r.has(t.kind),onChange:()=>C(t.kind),className:`accent-primary`}),i(n,{className:`h-3.5 w-3.5`,style:{color:l(t.kind)}}),i(`span`,{children:Ae(t,c)})]},t.kind)})]},t.macro.kind)})]})]})}function cn(e,t){let n=new Map;for(let r of e)if(!(t.size>0&&!t.has(r.deviceId)))for(let e of r.kinds)n.has(e.kind)||n.set(e.kind,e);return n}function ln(e,t){return{...t,kind:e,labelKey:`eventKind.${e}`,label:e.charAt(0).toUpperCase()+e.slice(1),iconId:e,parentKind:null,level:`macro`}}var un=new Set([`detection`,`package`]);function dn(e,t){return[...cn(e,t).values()].filter(e=>e.parentKind===null&&un.has(e.category)).sort((e,t)=>e.label.localeCompare(t.label))}function fn(e,t){let n=cn(e,t),r=new Map,i=new Map;for(let e of n.values()){if(e.parentKind===null){i.set(e.kind,e);continue}let t=r.get(e.parentKind);t===void 0?r.set(e.parentKind,[e]):t.push(e)}for(let[e,t]of r){if(i.has(e))continue;let n=t[0];n!==void 0&&i.set(e,ln(e,n))}return[...i.values()].map(e=>({macro:e,subs:[...r.get(e.kind)??[]].sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}c();var pn=1400,mn=`Admin-gated URL — opens only inside an authenticated session`;function hn({label:t,value:n,title:s}){let{t:c}=Y(),[l,u]=o(!1),d=ne();return a(()=>{if(!l)return;let e=setTimeout(()=>u(!1),pn);return()=>clearTimeout(e)},[l]),e(G,{variant:`unstyled`,type:`button`,onClick:r(()=>{(async()=>{try{await navigator.clipboard.writeText(n),u(!0)}catch{await d({title:c(`detectionIntelligence.copyUrlChips.copyTheMediaUrl`,`Copy the media URL`),message:c(`detectionIntelligence.copyUrlChips.clipboardAccessWasRefusedSelect`,`Clipboard access was refused. Select the URL below and copy it manually.`),label:c(`detectionIntelligence.copyUrlChips.url`,`{{label}} URL`,{label:t}),defaultValue:n,readOnly:!0,cancelLabel:c(`common.close`,`Close`)})}})()},[n,t,d,c]),title:s,"aria-label":c(`detectionIntelligence.copyUrlChips.copyUrl`,`Copy {{label}} URL`,{label:t}),className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${l?`border-success/40 bg-success/10 text-success`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[i(l?I:O,{className:`h-2.5 w-2.5 shrink-0`}),i(`span`,{className:`truncate`,children:l?c(`detectionIntelligence.copyUrlChips.copied`,`Copied`):t})]})}function gn({localUrl:t,publicUrl:n}){let{t:r}=Y();return e(`div`,{className:`flex flex-wrap gap-1`,children:[i(hn,{label:r(`detectionIntelligence.copyUrlChips.local`,`Local`),value:t,title:r(`detectionIntelligence.copyUrlChips.copyLanUrl`,`Copy LAN URL — {{AUTH_HINT}}`,{AUTH_HINT:mn})}),n&&i(hn,{label:r(`detectionIntelligence.copyUrlChips.public`,`Public`),value:n,title:r(`detectionIntelligence.copyUrlChips.copyPublicUrl`,`Copy public URL — {{AUTH_HINT}}`,{AUTH_HINT:mn})})]})}var _n={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`,confirmationCrop:`Confirmation crop (what the gate saw)`,debugCrop:`Debug crop (why this decision)`,sceneFrame:`Scene frame (clean)`,lastSceneFrame:`Last frame (clean)`};function vn(e){return e in _n}function yn(e){return vn(e)?_n[e]:e}function bn(e,t){return`${e}${t}`}var xn=[`native`,`raster`,`standin`];function Sn(e){return xn.some(t=>t===e)}function Cn(e){return e===`standin`?{label:J.t(`helpers.mediaProvenance.standin.label`),title:J.t(`helpers.mediaProvenance.standin.title`),tone:`warning`}:{label:J.t(`helpers.mediaProvenance.raster.label`),title:J.t(`helpers.mediaProvenance.raster.title`),tone:`info`}}function wn(e){return e===`standin`?Cn(`standin`):e===`raster`?Cn(`raster`):null}var Tn={"no-key-frame":`helpers.mediaProvenance.miss.noKeyFrame`,"no-best-seen-bbox":`helpers.mediaProvenance.miss.noBestSeenBbox`,"derive-returned-null":`helpers.mediaProvenance.miss.deriveReturnedNull`,"derive-threw":`helpers.mediaProvenance.miss.deriveThrew`,"derive-not-wired":`helpers.mediaProvenance.miss.deriveNotWired`,"no-media-store":`helpers.mediaProvenance.miss.noMediaStore`,"no-thumbnail":`helpers.mediaProvenance.miss.noThumbnail`,"standin-tile":`helpers.mediaProvenance.miss.standinTile`,"raster-tile":`helpers.mediaProvenance.miss.rasterTile`,"native-tile":`helpers.mediaProvenance.miss.nativeTile`};function En(e){if(e===void 0)return null;let t=e.trim();if(t.length===0)return null;let n=t.split(/\s+/),r=n[0]??t,i=[];for(let e of n.slice(1)){let t=e.indexOf(`=`);t===-1?i.push({key:e,value:null}):i.push({key:e.slice(0,t),value:e.slice(t+1)})}let a=Tn[r];return{sentence:a===void 0?r:J.t(a),detail:i,raw:t}}c();var Dn=3e4;function On(e){let[t,n]=o(null),s=r(e=>{n(t=>t??e)},[]);return a(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?i(kn,{onOrigin:s}):null}}function kn({onOrigin:e}){let{data:t}=Le({capName:`network-access`});return i(u,{children:(t??[]).map(t=>i(An,{addonId:t.addonId,onOrigin:e},t.addonId))})}function An({addonId:e,onOrigin:t}){let{data:n}=be({addonId:e},{refetchInterval:Dn,retry:!1});return a(()=>{let e=n?ae.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}var jn=typeof Ie==`function`,Mn=`Track flags arrive with the next server update`;function Nn(){return{mutateAsync:async()=>{throw Error(`setTrackFlags unavailable`)},isPending:!1}}var Pn=jn?Ie:Nn;function Fn(e){if(typeof e!=`object`||!e||!(`trackId`in e)||!(`markForTrain`in e)||!(`debug`in e)||!(`favourited`in e))return null;let{trackId:t,markForTrain:n,debug:r,favourited:i}=e;return typeof t!=`string`||typeof n!=`boolean`||typeof r!=`boolean`||typeof i!=`boolean`?null:{trackId:t,markForTrain:n,debug:r,favourited:i}}c();function In({label:t,hint:n,checked:r,disabled:a,title:o,icon:s,onToggle:c}){return e(G,{variant:`unstyled`,type:`button`,role:`switch`,"aria-checked":r,"aria-label":t,disabled:a,title:o,onClick:c,className:`flex w-full items-center gap-2 rounded-md border px-2 py-1.5 text-left transition-colors disabled:opacity-50 ${r?`border-primary bg-primary/10`:`border-border bg-surface hover:bg-surface-hover`}`,children:[i(`span`,{className:r?`text-primary`:`text-foreground-subtle`,children:s}),e(`span`,{className:`min-w-0 flex-1`,children:[i(`span`,{className:`block text-[11px] font-medium text-foreground`,children:t}),i(`span`,{className:`block text-[10px] text-foreground-subtle`,children:n})]}),i(`span`,{"aria-hidden":`true`,className:`h-4 w-7 shrink-0 rounded-full p-0.5 transition-colors ${r?`bg-primary`:`bg-border`}`,children:i(`span`,{className:`block h-3 w-3 rounded-full bg-white transition-transform ${r?`translate-x-3`:``}`})})]})}function Ln({deviceId:t,trackId:n,markForTrain:r,debug:a,favourited:s,onChange:c}){let{t:l}=Y(),u=Pn(),d=te(),[f,p]=o(null),m=f?.markForTrain??r===!0,h=f?.debug??a===!0,g=f?.favourited??s===!0,_=!jn||u.isPending,v=jn?void 0:Mn,y=e=>{_||(async()=>{try{let r=Fn(await u.mutateAsync({deviceId:t,trackId:n,flags:e}));if(!r)return;p(r),c?.(r)}catch(e){let t=e instanceof Error?e.message:``;await d({title:l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack`,`Could not update this track`),message:t===``?l(`detectionIntelligence.trackFlagToggles.couldNotUpdateThisTrack2`,`Could not update this track. Check the server logs.`):t,variant:`danger`})}})()};return e(`div`,{className:`grid gap-1.5 sm:grid-cols-2`,children:[i(In,{label:l(`detectionIntelligence.trackFlagToggles.markForTraining`,`Mark for training`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:m,disabled:_,...v===void 0?{}:{title:v},icon:i(w,{className:`h-4 w-4`}),onToggle:()=>y({markForTrain:!m})}),i(In,{label:l(`detectionIntelligence.trackFlagToggles.debug`,`Debug`),hint:l(`detectionIntelligence.trackFlagToggles.flagThisTrackForDiagnostic`,`Flag this track for diagnostic attention`),checked:h,disabled:_,...v===void 0?{}:{title:v},icon:i(j,{className:`h-4 w-4`}),onToggle:()=>y({debug:!h})}),i(In,{label:l(`detectionIntelligence.trackFlagToggles.favourited`,`Favourited`),hint:l(`detectionIntelligence.trackFlagToggles.keepsThisTrackAndIts`,`Keeps this track and its media past retention`),checked:g,disabled:_,...v===void 0?{}:{title:v},icon:i(N,{className:`h-4 w-4`}),onToggle:()=>y({favourited:!g})})]})}function Rn(e){let t=e.deviceKey===void 0?e.nodeId:`${e.nodeId} · ${e.deviceKey}`;return e.modelId===void 0?t:`${t} (${e.modelId})`}function zn(e){let t=e?.openedPlacement,n=e?.closedPlacement;if(t!==void 0&&n!==void 0){let e=Rn(t),r=Rn(n);return e===r?[{kind:`detected`,value:e}]:[{kind:`opened`,value:e},{kind:`closed`,value:r}]}return t===void 0?n===void 0?[]:[{kind:`closed`,value:Rn(n)}]:[{kind:`opened`,value:Rn(t)}]}var Bn=100,Vn={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Hn=e=>e<0?0:e>1?1:e,Un=e=>Math.round(e*100)/100;function Wn(e,t,n){if(e.length===0||t===null)return Vn;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Vn;let a=oe(e.map(e=>({x:e.x/r,y:e.y/i,w:e.bbox.w/r,h:e.bbox.h/i})),n?.maxPoints===void 0?void 0:{maxPoints:n.maxPoints}).nodes.map(e=>({x:Un(e.x*Bn),y:Un(e.y*Bn)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Un(Hn(e.x/r)*Bn),y:Un(Hn(e.y/i)*Bn),mediaId:e.mediaId})),u=null,d=-1;for(let t of e){let e=Hn(t.bbox.w/r)*Hn(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Un(Hn(u.bbox.x/r)*Bn),y:Un(Hn(u.bbox.y/i)*Bn),w:Un(Hn(u.bbox.w/r)*Bn),h:Un(Hn(u.bbox.h/i)*Bn)}:null}}c();var Gn=15e3,Kn=C();function qn({url:e,label:t}){let{src:n,failed:r}=at(e);return n===null?i(`div`,{className:`flex h-full w-full items-center justify-center bg-surface-hover`,children:r?i(h,{className:`h-4 w-4 text-foreground-subtle opacity-60`}):i(_,{className:`h-4 w-4 animate-spin text-foreground-subtle opacity-70`})}):i(`img`,{src:n,alt:t,className:`h-full w-full object-cover`})}var Jn=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),Yn=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`,`sceneFrame`,`lastSceneFrame`]);function Xn(e){let[t,n]=o(null);return a(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function Zn({overlay:t,onPickSnapshot:n}){let{t:r}=Y();return!t.polyline&&!t.peakBox&&t.snapshots.length===0?null:e(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[t.peakBox&&i(`rect`,{x:t.peakBox.x,y:t.peakBox.y,width:t.peakBox.w,height:t.peakBox.h,fill:`none`,stroke:`var(--color-warning)`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),t.polyline&&i(`polyline`,{points:t.polyline,fill:`none`,stroke:`var(--color-info)`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),t.points.map((e,t)=>i(`circle`,{cx:e.x,cy:e.y,r:1,fill:`var(--color-info)`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),t.snapshots.map((e,t)=>i(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`var(--color-info)`,fillOpacity:.95,stroke:`var(--color-background)`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:n?`pointer-events-auto cursor-pointer`:void 0,onClick:n?t=>{t.stopPropagation(),n(e.mediaId)}:void 0,children:i(`title`,{children:r(`detectionIntelligence.eventDetailPanel.snapshotCheckpointClickToView`,`Snapshot checkpoint — click to view this frame`)})},`snap-${String(e.mediaId)}-${String(t)}`)),t.start&&i(`circle`,{cx:t.start.x,cy:t.start.y,r:2.4,fill:`var(--color-success)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),t.end&&i(`circle`,{cx:t.end.x,cy:t.end.y,r:2.4,fill:`var(--color-danger)`,stroke:`var(--color-background)`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function X({label:t,value:n,mono:r,wrap:a}){return e(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[i(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:t}),i(`span`,{className:`min-w-0 ${a?`break-words`:`truncate`} text-right text-xs font-medium text-foreground ${r?`font-mono text-[11px]`:``}`,title:n,children:n})]})}function Qn({row:t,cameraName:s,deleteAvailable:c,onClose:l,onDeleted:d,onFlagsChanged:f}){let{t:p}=Y(),m=ie(),g=te(),v=ee(),y=Qt(),b=t!==null,x=t?.deviceId??0,S=t?.trackId??``,C=t?.timestamp??0,w=t?.windowMs??0,{data:T}=je({deviceId:x,trackId:S},{enabled:b}),{data:E}=We({trackId:S,deviceId:x},{enabled:b}),D=T?.bestEventId===void 0?void 0:Number(T.bestEventId),{data:O}=de({ownerType:`object`,eventId:D??0,deviceId:x},{enabled:b&&D!==void 0&&Number.isFinite(D)}),{data:k}=Be({deviceId:x},{enabled:b}),A=(k??[]).find(e=>e.addonId!==void 0)?.addonId,{data:j}=ve({deviceId:x,since:C-Gn,until:C+w+Gn,provider:A??``},{enabled:b&&A!==void 0}),[N,P]=o(null),[F,I]=o(!1),{publicOrigin:L,probes:R}=On(b);a(()=>{P(null)},[x,S]);let ne=n(()=>{let e=E??[],t=O??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[E,O]),re=N??ne,B=at(re?re.url:void 0),V=n(()=>{let e=new Set,t=[];for(let n of[...O??[],...E??[]])e.has(n.mediaId)||(e.add(n.mediaId),t.push(n));return t},[O,E]),ae=n(()=>V.find(e=>Jn.has(e.kind))??null,[V]),oe=Xn(at(ae?ae.url:void 0).src),H=n(()=>Wn(T?.positions??[],oe,{snapshots:(T?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaId:e.mediaId}))}),[T?.positions,T?.snapshots,oe]),se=r(e=>{let t=V.find(t=>t.mediaId===e);t&&P(t)},[V]);if(t===null)return null;let ce=B.src,U=re?.kind,le=U!==void 0&&Yn.has(U)&&oe!==null&&(T?.positions.length??0)>=2,ue=j&&j.length>0?j[0]:null,W=()=>{ue&&(I(!0),(async()=>{try{let e=await m.trpcClient.videoclips.getClipPlayback.query({deviceId:t.deviceId,clipId:ue.id});window.open(e.playbackUrl,`_blank`,`noopener`)}catch{g({title:p(`detectionIntelligence.eventDetailPanel.clipUnavailable`,`Clip unavailable`),message:p(`detectionIntelligence.eventDetailPanel.couldNotResolveClipPlayback`,`Could not resolve clip playback. Check the server logs.`),variant:`warning`})}finally{I(!1)}})())},pe=()=>{!c||y.isPending||(async()=>{if(await v({title:p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`),message:p(`detectionIntelligence.eventDetailPanel.deleteThisTrackAndEvery`,`Delete this track and every image and clip captured for it? This cannot be undone.`),confirmLabel:p(`common.delete`,`Delete`),variant:`danger`}))try{await y.mutateAsync({deviceId:t.deviceId,trackIds:[t.trackId]}),d()}catch{await g({title:p(`detectionIntelligence.eventDetailPanel.deleteFailed`,`Delete failed`),message:p(`detectionIntelligence.eventDetailPanel.failedToDeleteThisTrack`,`Failed to delete this track. Check the server logs.`),variant:`danger`})}})()},me=Math.round(t.importance*100),he=T?.importanceReason?`${String(me)}% · ${T.importanceReason}`:`${String(me)}%`,ge=T?.zonesVisited&&T.zonesVisited.length>0?T.zonesVisited.join(`, `):`—`,_e=T?.audioLabels&&T.audioLabels.length>0?T.audioLabels:t.audioLabels&&t.audioLabels.length>0?t.audioLabels:void 0,ye=_e===void 0?`—`:_e.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `),be=T?T.totalDistance.toFixed(2):`—`,xe=En(T?.previewMissReason),Se=pt(T?T.firstSeen:C),Ce=T?pt(T.lastSeen):`—`,Te=zn(T),Ee={detected:p(`detectionIntelligence.eventDetailPanel.detectedOn`,`Detected on`),opened:p(`detectionIntelligence.eventDetailPanel.openedOn`,`Opened on`),closed:p(`detectionIntelligence.eventDetailPanel.closedOn`,`Closed on`)};return i(we,{open:!0,onOpenChange:e=>!e&&l(),children:e(fe,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":p(`detectionIntelligence.eventDetailPanel.eventDetail`,`Event detail`),className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[i(`header`,{className:`flex shrink-0 items-start gap-2 border-b border-border py-3 pl-4 pr-10`,children:e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[t.className,Vt(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,Vt(t)]}):null]}),i(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:s})]})}),e(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[ce?i(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:i(bt,{src:ce,alt:p(`detectionIntelligence.eventDetailPanel.keyFrameFrom`,`Key frame from {{cameraName}}`,{cameraName:s}),fit:`natural`,className:`w-full`,overlay:le?i(Zn,{overlay:H,onPickSnapshot:se}):void 0})}):i(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:B.failed?e(u,{children:[i(h,{className:`h-8 w-8 opacity-60`}),i(`span`,{className:`text-[11px]`,children:p(`detectionIntelligence.eventDetailPanel.keyFrameMediaUnavailable`,`Key-frame media unavailable`)})]}):i(_,{className:`h-6 w-6 animate-spin opacity-70`})}),V.length>0&&i(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:V.map(t=>{let n=yn(t.kind),r=bn(Kn,t.url),a=L?bn(L,t.url):null;return e(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[i(G,{variant:`unstyled`,type:`button`,onClick:()=>P(t),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${pt(t.timestamp)}`,children:i(qn,{url:t.url,label:n})}),e(`figcaption`,{className:`min-w-0 px-0.5`,children:[i(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),i(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:pt(t.timestamp),children:gt(t.timestamp)})]}),i(gn,{localUrl:r,publicUrl:a})]},t.mediaId)})}),R,ue&&e(G,{variant:`secondary`,onClick:W,disabled:F,children:[F?i(_,{className:`h-3.5 w-3.5 animate-spin`}):i(M,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.viewClip`,`View clip`)]}),i(Ln,{deviceId:t.deviceId,trackId:t.trackId,...(T?.markForTrain??t.markForTrain)===void 0?{}:{markForTrain:T?.markForTrain??t.markForTrain},...(T?.debug??t.debug)===void 0?{}:{debug:T?.debug??t.debug},...(T?.favourited??t.favourited)===void 0?{}:{favourited:T?.favourited??t.favourited},onChange:f}),xe!==null&&e(`div`,{className:`rounded-lg border border-warning/40 bg-warning/8 px-3 py-2`,children:[i(`p`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p(`detectionIntelligence.eventDetailPanel.bestShot`,`Best shot`)}),i(`p`,{className:`mt-0.5 text-xs text-foreground`,children:xe.sentence}),i(`code`,{className:`mt-1 block break-all font-mono text-[10px] text-foreground-subtle`,children:xe.raw})]}),e(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[i(X,{label:p(`detectionIntelligence.eventDetailPanel.camera`,`Camera`),value:s}),Te.map(e=>i(X,{label:Ee[e.kind],value:e.value,mono:!0,wrap:!0},e.kind)),i(X,{label:p(`detectionIntelligence.eventDetailPanel.class`,`Class`),value:t.className}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.label`,`Label`),value:t.label??`—`}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.subLabel`,`Sub-label`),value:t.subLabel??`—`}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.importance`,`Importance`),value:he}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.zonesVisited`,`Zones visited`),value:ge}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.audioHeard`,`Audio heard`),value:ye}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.totalDistance`,`Total distance`),value:be}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.firstSeen`,`First seen`),value:Se}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.lastSeen`,`Last seen`),value:Ce}),i(X,{label:p(`detectionIntelligence.eventDetailPanel.track`,`Track`),value:t.trackId,mono:!0})]})]}),i(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:i(`span`,{title:c?void 0:Xt,children:e(G,{variant:`secondary`,onClick:pe,disabled:!c||y.isPending,children:[y.isPending?i(_,{className:`h-3.5 w-3.5 animate-spin`}):i(z,{className:`h-3.5 w-3.5`}),` `,p(`detectionIntelligence.eventDetailPanel.deleteTrack`,`Delete track`)]})})})]})})}function $n(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function er({row:t,cameraName:n,nowMs:r,onOpenDetail:a,selected:o=!1,onToggleSelect:s,score:c,provenance:l,footer:u}){let{t:d}=Y(),f=at(t.mediaId===void 0?ot(`track`,t.trackId):st(t.mediaId)),p=Math.round(t.importance*100),m=c===void 0?void 0:Math.round(c*100),g=$n(t.windowMs),_=()=>a(t),v=wn(l);return e(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${o?`border-primary ring-1 ring-primary`:`border-border`}`,children:[e(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[f.src?i(`img`,{src:f.src,alt:d(`detectionIntelligence.eventCard.eventFrom`,`Event from {{cameraName}}`,{cameraName:n}),onClick:_,className:`h-full w-full cursor-zoom-in object-cover`}):i(G,{variant:`unstyled`,type:`button`,onClick:_,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:f.failed?d(`detectionIntelligence.eventCard.keyEventMediaUnavailable`,`Key-event media unavailable`):d(`detectionIntelligence.eventCard.noKeyEventMedia`,`No key-event media`),children:i(h,{className:`h-6 w-6 opacity-60`})}),s&&i(G,{variant:`unstyled`,type:`button`,onClick:e=>{e.stopPropagation(),s(Kt(t.deviceId,t.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":o?d(`detectionIntelligence.eventCard.deselect`,`Deselect`):d(`detectionIntelligence.eventCard.select`,`Select`),children:o?i(W,{className:`h-4 w-4 text-primary`}):i(A,{className:`h-4 w-4`})}),m!==void 0&&e(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:d(`detectionIntelligence.eventCard.clipSemanticMatchScore`,`CLIP semantic-match score`),children:[String(m),`%`]}),p>0&&i(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(p)}),v!==null&&i(`span`,{className:`absolute bottom-1 right-1 z-10 rounded px-1.5 py-0.5 text-[10px] font-semibold text-white ${v.tone===`warning`?`bg-warning/90`:`bg-black/70`}`,title:v.title,children:v.label}),(t.markForTrain===!0||t.retrainStatus===`trained`||t.debug===!0||t.favourited===!0)&&e(`span`,{className:`absolute bottom-1 left-1 z-10 flex gap-1`,children:[t.markForTrain===!0&&i(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),"aria-label":d(`detectionIntelligence.eventCard.markedForTraining`,`Marked for training`),children:i(w,{className:`h-3 w-3`})}),t.retrainStatus===`trained`&&t.markForTrain!==!0&&i(`span`,{className:`rounded bg-success/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"aria-label":d(`detectionIntelligence.eventCard.trainingComplete`,`Training complete`),"data-testid":`retrain-status-trained`,children:i(I,{className:`h-3 w-3`})}),t.debug===!0&&i(`span`,{className:`rounded bg-black/70 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),"aria-label":d(`detectionIntelligence.eventCard.flaggedForDebug`,`Flagged for debug`),children:i(j,{className:`h-3 w-3`})}),t.favourited===!0&&i(`span`,{className:`rounded bg-primary/85 p-0.5 text-white`,title:d(`detectionIntelligence.eventCard.favourited`,`Favourited`),"aria-label":d(`detectionIntelligence.eventCard.favourited`,`Favourited`),children:i(N,{className:`h-3 w-3`})})]})]}),e(G,{variant:`unstyled`,type:`button`,onClick:_,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[e(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:t.className,children:[t.className,Vt(t)?e(`span`,{className:`text-foreground-subtle`,children:[` · `,Vt(t)]}):null]}),i(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:n,children:n}),e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:St(t.timestamp,r)}),g&&i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:g})]})]}),u!==void 0&&i(`div`,{className:`px-2 pb-1.5`,children:u})]})}var tr=120*1e3;function nr(e,t,n=tr){let r=[...e].sort((e,n)=>t(n)-t(e)),i=[];for(let e of r){let r=i[i.length-1],a=t(e);r!==void 0&&r.fromMs-a<=n?(r.events.push(e),r.fromMs=a):i.push({fromMs:a,toMs:a,events:[e]})}return i}c();function rr(){let[e,n]=o(!1),i=t(null),[s,c]=o(0),l=r(e=>{i.current!==e&&(i.current=e,c(e=>e+1))},[]);return a(()=>{let e=i.current;if(!e||typeof IntersectionObserver>`u`){n(!1);return}let t=new IntersectionObserver(e=>{let t=e[e.length-1];t&&n(!t.isIntersecting)},{rootMargin:`64px 0px 0px 0px`,threshold:0});return t.observe(e),()=>t.disconnect()},[s]),{ref:l,scrolledPast:e}}c();var ir=[`events-feed`],ar=60,or=[{value:`importance`,labelKey:`detectionIntelligence.eventsSection.sortImportance`,icon:U},{value:`time`,labelKey:`detectionIntelligence.eventsSection.sortRecent`,icon:y}];function sr({deviceId:t,onSeek:r}={}){let{t:s}=Y(),c=l(),d=te(),f=ee(),[p,h]=o(ft),[g,v]=o(new Set),[y,x]=o(new Set),[S,C]=o(0),[w,T]=o(`time`),[E,D]=o(new Set),[O,k]=o(null),[A,j]=o(()=>Date.now());a(()=>{let e=setInterval(()=>j(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:M,until:N}=n(()=>Jt({fromMs:p.fromMs,toMs:p.toMs},A),[p.fromMs,p.toMs,A]),F=rr(),{pending:I,refreshNow:L}=on({paused:O!==null||E.size>0||F.scrolledPast}),{data:R=[]}=Ke({isCamera:!0,projection:`slim`}),ne=n(()=>t===void 0?R:R.filter(e=>e.id===t),[R,t]),re=n(()=>ne.map(e=>e.id),[ne]),{data:ie,isLoading:B}=Ce({deviceIds:re},{enabled:re.length>0,staleTime:5*6e4}),V=n(()=>fn(ie??[],g),[ie,g]),ae=Qt(),oe=ae.isPending,{rows:H,isLoading:se}=nn({deviceIds:re,since:M,until:N,minImportance:S>0?S:void 0,classFilter:y.size===1?[...y][0]:void 0}),ce=n(()=>{let e=new Map;for(let t of ne??[])e.set(t.id,t.name);return e},[ne]),U=e=>ce.get(e)??s(`detectionIntelligence.cameraFallback`,{id:String(e)}),ue=n(()=>vt(H).map(e=>({id:e,name:U(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[H,ce]),W=n(()=>Wt(Gt(H,{cameras:g,classes:y,minImportance:S}),w),[H,g,y,S,w]),de=xt(W,ar,n(()=>JSON.stringify([[...g].sort((e,t)=>e-t),[...y].sort(),S,w,M,N]),[g,y,S,w,M,N])),fe=()=>{c.invalidateQueries({queryKey:ir})},pe=()=>D(new Set);function me(e){D(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function he(){if(E.size===0||!Yt)return;let e=qt(H,E),t=[...e.values()].reduce((e,t)=>e+t.length,0);t!==0&&(async()=>{await f({title:s(`detectionIntelligence.eventsSection.deleteTitle`,{count:t}),message:s(`detectionIntelligence.eventsSection.deleteMessage`,{count:t}),confirmLabel:s(`common.delete`,`Delete`),variant:`danger`})&&ge(e)})()}function ge(e){let t=[...e];Promise.allSettled(t.map(([e,t])=>ae.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{fe();let n=[],r=new Set;if(e.forEach((e,i)=>{let a=t[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(Kt(o,e));else n.push(o)}),D(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),n.length>0){let e=n.map(e=>U(e)).join(`, `);d({title:s(`detectionIntelligence.eventsSection.someTracksWereNotDeleted`,`Some tracks were not deleted`),message:s(`detectionIntelligence.eventsSection.failedToDeleteTracksOn`,`Failed to delete tracks on: {{names}}. They remain selected — retry, or check the server logs.`,{names:e}),variant:`danger`})}})}let _e=n(()=>nr(de.pageItems,e=>e.timestamp),[de.pageItems]),ve=W.length!==H.length,ye=t=>i(er,{row:t,cameraName:U(t.deviceId),nowMs:A,selected:E.has(Kt(t.deviceId,t.trackId)),onToggleSelect:me,onOpenDetail:k,footer:r===void 0?void 0:e(G,{variant:`ghost`,onClick:()=>r(t.timestamp),children:[i(le,{className:`h-3.5 w-3.5`}),s(`detectionIntelligence.eventsSection.showInReview`,`Show in Review`)]})},Kt(t.deviceId,t.trackId));return e(`div`,{className:`relative space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(ht,{onChange:h}),t===void 0&&i(mt,{cameras:ue,selected:g,onChange:v}),i(sn,{groups:V,selected:y,onChange:x,loading:B}),e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(`span`,{children:s(`detectionIntelligence.eventsSection.minScore`,`Min score`)}),i(P,{min:0,max:1,step:.05,value:S,onChange:e=>C(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":s(`detectionIntelligence.eventsSection.minimumImportance`,`Minimum importance`)}),i(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(S*100)})]}),i(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:or.map(t=>{let n=t.icon;return e(`button`,{type:`button`,onClick:()=>T(t.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${w===t.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[i(n,{className:`h-3.5 w-3.5`}),` `,s(t.labelKey)]},t.value)})}),!se&&i(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:ve?s(`detectionIntelligence.eventsSection.ofEvents`,`{{value1}} of {{value2}} events`,{value1:String(W.length),value2:String(H.length)}):s(`detectionIntelligence.eventsSection.eventCount`,{count:W.length})})]}),E.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[i(`span`,{className:`text-xs font-medium text-foreground`,children:s(`common.selectedCount`,{count:E.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[i(`span`,{title:Yt?void 0:`Track deletion arrives with the next server update`,children:e(G,{variant:`secondary`,onClick:he,disabled:!Yt||oe,children:[oe?i(_,{className:`h-3.5 w-3.5 animate-spin`}):i(z,{className:`h-3.5 w-3.5`}),` `,s(`common.delete`,`Delete`)]})}),i(G,{variant:`ghost`,onClick:pe,disabled:oe,children:i(b,{className:`h-3.5 w-3.5`})})]})]}),I&&i(`div`,{className:`sticky top-2 z-20 flex justify-center`,children:i(`button`,{type:`button`,onClick:L,className:`rounded-full border border-primary/40 bg-surface px-3 py-1 text-[11px] font-medium text-primary shadow-sm hover:bg-primary/10`,children:s(`detectionIntelligence.eventsSection.newEventsRefresh`,`New events — refresh`)})}),se?i(Ue,{status:`pending`,pendingMessage:`Loading events…`,testId:`events-grid`}):W.length===0?i(Pe,{icon:m,title:ve?s(`detectionIntelligence.eventsSection.nothingMatchesTheFilter`,`Nothing matches the filter`):s(`detectionIntelligence.eventsSection.noKeyEventsInThis`,`No key events in this window`),description:ve?s(`detectionIntelligence.eventsSection.widenTheDateRangeClear`,`Widen the date range, clear cameras or kinds, or lower the min score.`):s(`detectionIntelligence.eventsSection.capturedTracksAppearHereWhen`,`Captured tracks appear here when the pipeline scores a key event.`)}):e(u,{children:[i(`div`,{ref:F.ref,"aria-hidden":!0,className:`h-0`}),t!==void 0&&w===`time`?_e.map(t=>e(`div`,{className:`space-y-1.5`,children:[i(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:s(`detectionIntelligence.eventsSection.clusterHeading`,{count:t.events.length,time:new Date(t.toMs).toLocaleString()})}),i(Ue,{status:`ready`,testId:`events-grid`,children:t.events.map(ye)})]},t.toMs)):i(Ue,{status:`ready`,testId:`events-grid`,children:de.pageItems.map(ye)}),i(_t,{currentPage:de.page,totalItems:de.totalItems,pageSize:de.pageSize,onPageChange:de.setPage,itemNoun:`events`})]}),O&&i(Qn,{row:O,cameraName:U(O.deviceId),deleteAvailable:Yt,onClose:()=>k(null),onDeleted:()=>{fe(),k(null)},onFlagsChanged:e=>{k(t=>t&&t.trackId===e.trackId?{...t,markForTrain:e.markForTrain,debug:e.debug,favourited:e.favourited}:t)}})]})}var cr=`/addon/training`;function lr(){let{t}=Y(),n=Je();return e(De,{className:`flex flex-col gap-3 border-border bg-surface p-3 sm:flex-row sm:items-center sm:gap-4`,"data-testid":`events-feed-retrain-cta`,children:[e(`div`,{className:`flex min-w-0 flex-1 items-start gap-2.5`,children:[i(w,{className:`mt-0.5 h-4 w-4 shrink-0 text-primary`,"aria-hidden":!0}),e(`div`,{className:`min-w-0 space-y-0.5`,children:[i(`p`,{className:`text-xs font-medium text-foreground`,children:t(`detectionIntelligence.retrainTabCallout.trainingFromThisFeed`,`Training from this feed`)}),i(`p`,{className:`${B} leading-relaxed`,children:t(`detectionIntelligence.retrainTabCallout.markATrackWithThe`,`Mark a track with the graduation-cap control on its card. On Training you correct frames, build collections, and start cloud fine-tunes.`)})]})]}),i(G,{variant:`outline`,size:`sm`,className:`shrink-0 self-start sm:self-center`,onClick:()=>n(cr),children:t(`detectionIntelligence.retrainTabCallout.openTraining`,`Open Training`)})]})}c();var ur=50,dr=350,fr=[{value:`loose`,labelKey:`detectionIntelligence.semanticEventSearch.looseLabel`,titleKey:`detectionIntelligence.semanticEventSearch.looseTitle`},{value:`balanced`,labelKey:`detectionIntelligence.semanticEventSearch.balancedLabel`,titleKey:`detectionIntelligence.semanticEventSearch.balancedTitle`},{value:`strict`,labelKey:`detectionIntelligence.semanticEventSearch.strictLabel`,titleKey:`detectionIntelligence.semanticEventSearch.strictTitle`}];function pr(e){let t=String(e.id);return{id:t,trackId:e.trackId??t,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,subLabel:e.subLabel,importance:e.importance??0,bestEventId:t,mediaId:e.keyFrameMediaId??e.mediaId,windowMs:void 0}}function mr({onActiveChange:r,deviceId:s}){let c=t(null);Fe(c);let{t:l}=Y(),[u,d]=o(``),[p,m]=o(`loose`),[h,g]=o(null),[v,y]=o(null),x=s??v,[S,C]=o(null),w=xe(u,dr).trim(),T=w.length>0;a(()=>{r(T)},[T,r]);let[ee,D]=o(()=>Date.now());a(()=>{let e=setInterval(()=>D(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:O=[]}=Ke({isCamera:!0,projection:`slim`}),k=n(()=>{let e=new Map;for(let t of O)e.set(t.id,t.name);return e},[O]),A=e=>k.get(e)??l(`detectionIntelligence.cameraFallback`,{id:String(e)}),te=n(()=>O.map(e=>e.id),[O]),{data:j}=Ce({deviceIds:te},{enabled:te.length>0,staleTime:5*6e4}),M=n(()=>dn(j??[],new Set(x===null?[]:[x])),[j,x]);a(()=>{h!==null&&(M.some(e=>e.kind===h)||g(null))},[M,h]);let{data:N,isFetching:P,isError:F,error:I}=Ve({text:w,strictness:p,limit:ur,classFilter:h??void 0,deviceId:x??void 0},{enabled:T}),L=n(()=>[...N??[]].sort((e,t)=>t.score-e.score).map(e=>({...pr(e),score:e.score})),[N]);function R(e){g(t=>t===e?null:e)}return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`div`,{className:`relative min-w-[16rem] flex-1`,children:[i(f,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),i(He,{ref:c,type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:l(`detectionIntelligence.semanticEventSearch.semanticSearchDescribeWhatYou`,`Semantic search — describe what you're looking for…`),className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":l(`detectionIntelligence.semanticEventSearch.semanticEventSearch`,`Semantic event search`)}),u&&i(`button`,{type:`button`,onClick:()=>d(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":l(`detectionIntelligence.semanticEventSearch.clearSearch`,`Clear search`),children:i(b,{className:`h-3.5 w-3.5`})})]}),P&&T&&i(_,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),e(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[i(`div`,{className:`flex items-center gap-1`,children:M.map(e=>i(`button`,{type:`button`,onClick:()=>R(e.kind),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${h===e.kind?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:Ae(e)},e.kind))}),s===void 0&&e(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(`span`,{children:l(`detectionIntelligence.semanticEventSearch.camera`,`Camera`)}),i(E,{value:x===null?``:String(x),onChange:e=>y(e.target.value===``?null:Number(e.target.value)),className:`h-7 text-xs`,"aria-label":l(`detectionIntelligence.semanticEventSearch.filterByCamera`,`Filter by camera`),options:[{value:``,label:l(`detectionIntelligence.semanticEventSearch.all`,`All`)},...O.map(e=>({value:String(e.id),label:e.name}))]})]}),e(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(`span`,{children:l(`detectionIntelligence.semanticEventSearch.match`,`Match`)}),i(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:fr.map(e=>i(`button`,{type:`button`,onClick:()=>m(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${p===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:l(e.titleKey),children:l(e.labelKey)},e.value))})]}),T&&!P&&!F&&i(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:l(`common.matches`,{count:L.length})})]})]}),T&&e(`div`,{className:`space-y-3`,children:[F&&e(`p`,{className:`py-4 text-xs text-danger`,children:[l(`detectionIntelligence.semanticEventSearch.searchFailed`,`Search failed:`),` `,I instanceof Error?I.message:l(`detectionIntelligence.semanticEventSearch.unknownError`,`unknown error`),`. Check that the CLIP embedding step is enabled.`]}),!F&&P&&L.length===0&&i(Ue,{status:`pending`,pendingMessage:`Searching…`,testId:`semantic-events-grid`}),!F&&!P&&L.length===0&&i(Ue,{status:`empty`,emptyMessage:l(`detectionIntelligence.semanticEventSearch.noSemanticMatchesForTry`,`No semantic matches for “{{debounced}}”. Try a looser match threshold or a different phrasing.`,{debounced:w}),testId:`semantic-events-grid`}),!F&&L.length>0&&i(Ue,{status:`ready`,testId:`semantic-events-grid`,children:L.map(e=>i(er,{row:e,cameraName:A(e.deviceId),nowMs:ee,score:e.score,onOpenDetail:C},e.id))})]}),S&&i(Qn,{row:S,cameraName:A(S.deviceId),deleteAvailable:Yt,onClose:()=>C(null),onDeleted:()=>C(null)})]})}c();function hr(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return J.t(`helpers.relativeTime.justNow`);if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function gr({row:t,cameraName:n,nowMs:r}){let{t:a}=Y(),o=at(t.keyFrameMediaId===void 0?void 0:st(t.keyFrameMediaId));return e(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[e(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[o.src?i(`img`,{src:o.src,alt:a(`detectionIntelligence.stationarySection.parkedOn`,`Parked {{className}} on {{cameraName}}`,{className:t.className,cameraName:n}),className:`h-full w-full object-cover`}):i(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:i(D,{className:`h-6 w-6`})}),i(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:t.label??t.className})]}),e(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[i(`span`,{className:`truncate text-[11px] text-foreground`,children:n}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:a(`common.parkedSince`,{since:hr(r,t.becameStationaryAt)})})]})]})}function _r({deviceId:t}={}){let{t:r}=Y(),[a,s]=o(!1),c=Date.now(),{data:l=[]}=Ke({isCamera:!0,projection:`slim`}),u=n(()=>t===void 0?l.map(e=>e.id):[t],[l,t]),d=n(()=>{let e=new Map;for(let t of l)e.set(t.id,t.name);return e},[l]),{rows:f,unreadableCount:p}=dt(u);return f.length===0&&p===0?null:e(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[e(G,{variant:`unstyled`,type:`button`,onClick:()=>s(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[i(a?se:R,{className:`h-4 w-4 text-foreground-subtle`}),i(D,{className:`h-4 w-4 text-foreground-subtle`}),i(`span`,{className:`text-sm font-semibold text-foreground`,children:r(`detectionIntelligence.stationarySection.stationary`,`Stationary`)}),i(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:f.length}),i(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:r(`detectionIntelligence.stationarySection.parkedObjectsKeptOutOf`,`Parked objects — kept out of the event feed`)}),p>0?i(`span`,{className:`ml-2 text-[11px] text-warning`,children:r(`detectionIntelligence.stationarySection.unreadable`,{count:p})}):null]}),a&&i(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:f.map(e=>i(gr,{row:e,cameraName:d.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:c},e.id))})]})}var vr={status:`debug.tape.status`,promote:`debug.tape.promote`,list:`debug.tape.list`,tracks:`debug.tape.tracks`,review:`debug.tape.review`,release:`debug.tape.release`,remove:`debug.tape.delete`},yr={setRelation:`debug.gt.setRelation`,setPurity:`debug.gt.setPurity`,list:`debug.gt.list`},br=v(`/addon/pipeline-analytics/tape-export`),xr=10*6e4;function Sr(e){return`${br}?tapeId=${encodeURIComponent(e)}`}var Cr=`The server answered in a shape this build does not understand.`;function wr(e){return e instanceof Error?e.message:J.t(`helpers.eventsDebugTapes.actionFailed`)}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Tr(e,t){if(!(t in e))return;let n=e[t];return n===null?null:typeof n==`number`&&Number.isFinite(n)?n:void 0}function $(e,t){let n=e[t];return typeof n==`string`?n:null}function Er(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Dr(e,t){if(!Array.isArray(e))return null;let n=[];for(let r of e){let e=t(r);if(e===null)return null;n.push(e)}return n}function Or(e){return e===`off`||e===`recording`||e===`refused`||e===`failing`||e===`unknown`}function kr(e){if(!Z(e))return null;let t=Q(e,`deviceId`),n=e.state,r=Q(e,`gapsSinceArmed`),i=Tr(e,`segmentsHeld`),a=Tr(e,`bytesLastHour`),o=Tr(e,`bytesHeld`);if(t===null||!Or(n)||r===null||i===void 0||a===void 0||o===void 0)return null;let s=$(e,`reason`),c=Q(e,`segmentOriginMs`),l=Q(e,`framesPerMin`),u=Q(e,`heldFromMs`),d=Q(e,`heldToMs`),f=$(e,`shelfError`);return{deviceId:t,state:n,gapsSinceArmed:r,segmentsHeld:i,bytesLastHour:a,bytesHeld:o,...s===null?{}:{reason:s},...c===null?{}:{segmentOriginMs:c},...l===null?{}:{framesPerMin:l},...u===null?{}:{heldFromMs:u},...d===null?{}:{heldToMs:d},...f===null?{}:{shelfError:f}}}function Ar(e){return Z(e)?Dr(e.cameras,kr):null}function jr(e){if(!Z(e))return null;let t=$(e,`id`),n=Q(e,`deviceId`),r=$(e,`scenario`),i=e.lighting,a=Q(e,`fromMs`),o=Q(e,`toMs`),s=e.state,c=Q(e,`frames`),l=Q(e,`gaps`),u=Q(e,`bytes`),d=Er(e,`reviewed`),f=Er(e,`released`),p=Dr(e.tracks,e=>typeof e==`string`?e:null),m=Q(e,`tracksStillStored`);return t===null||n===null||r===null||i!==`day`&&i!==`ir`||a===null||o===null||s!==`complete`&&s!==`incomplete`||c===null||l===null||u===null||d===null||f===null||p===null||m===null?null:{id:t,deviceId:n,scenario:r,note:$(e,`note`),lighting:i,fromMs:a,toMs:o,state:s,frames:c,gaps:l,bytes:u,reviewed:d,released:f,tracks:p,tracksStillStored:m}}function Mr(e){return Z(e)?Dr(e.tapes,jr):null}function Nr(e){if(!Z(e))return null;let t=$(e,`trackId`),n=Q(e,`firstT`),r=Q(e,`lastT`),i=Q(e,`boundFrames`),a=$(e,`cls`),o=Er(e,`stillStored`);return t===null||n===null||r===null||i===null||a===null||o===null?null:{trackId:t,firstT:n,lastT:r,boundFrames:i,cls:a,stillStored:o}}function Pr(e){if(!Z(e))return null;let t=$(e,`tapeId`),n=Q(e,`deviceId`),r=Q(e,`fromMs`),i=Q(e,`toMs`),a=Er(e,`reviewed`),o=Dr(e.lanes,Nr);return t===null||n===null||r===null||i===null||a===null||o===null?null:{tapeId:t,deviceId:n,fromMs:r,toMs:i,reviewed:a,lanes:o}}function Fr(e){if(!Z(e))return null;if(e.ok===!1){let t=$(e,`reason`),n=$(e,`detail`);return t===null||n===null?null:{ok:!1,reason:t,detail:n}}if(e.ok!==!0)return null;let t=$(e,`tapeId`),n=e.state,r=Q(e,`frames`),i=Q(e,`gaps`),a=Q(e,`pinnedTracks`),o=Q(e,`bytes`);return t===null||n!==`complete`&&n!==`incomplete`||r===null||i===null||a===null||o===null?null:{ok:!0,tapeId:t,state:n,frames:r,gaps:i,pinnedTracks:a,bytes:o}}function Ir(e){if(!Z(e))return null;let t=e.status;if(t===`released`){let n=Q(e,`unpinned`),r=Er(e,`pinsSettled`);return n===null||r===null?null:{status:t,unpinned:n,pinsSettled:r}}if(t===`already-released`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function Lr(e){if(!Z(e))return null;let t=e.status;if(t===`deleted`||t===`pins-owed`||t===`not-found`)return{status:t};if(t===`unavailable`){let n=$(e,`reason`);return n===null?null:{status:t,reason:n}}return null}function Rr(e){switch(e.status){case`released`:case`deleted`:return null;case`already-released`:return J.t(`helpers.eventsDebugTapes.alreadyReleased`);case`not-found`:return J.t(`helpers.eventsDebugTapes.notFound`);case`pins-owed`:return J.t(`helpers.eventsDebugTapes.pinsOwed`);case`unavailable`:return J.t(`helpers.eventsDebugTapes.unavailable`,{reason:e.reason})}}function zr(e){if(!Z(e))return null;let t=$(e,`leftTrackId`),n=$(e,`rightTrackId`),r=e.relation,i=e.presence;return t===null||n===null||r!==`same-subject`&&r!==`different-subjects`?null:{leftTrackId:t,rightTrackId:n,relation:r,presence:i===`continuous`?`continuous`:null}}function Br(e){if(!Z(e))return null;let t=$(e,`sourceTrackId`),n=e.purity;return t===null||n!==`mixed`&&n!==`not-a-subject`?null:{sourceTrackId:t,purity:n,switchAtMs:Q(e,`switchAtMs`)}}function Vr(e){if(!Z(e))return null;let t=Dr(e.relations,zr),n=Dr(e.purities,Br),r=Er(e,`truncated`);return t===null||n===null||r===null?null:{relations:t,purities:n,truncated:r}}function Hr(e){if(!e.truncated)return null;let t=e.relations.length+e.purities.length;return J.t(`helpers.eventsDebugTapes.truncatedMarks`,{count:t})}function Ur(e){return e.filter(e=>e.segmentsHeld===null||e.segmentsHeld>0).map(e=>({deviceId:e.deviceId,segmentsUnknown:e.segmentsHeld===null}))}function Wr(e){return e.slice(1).map((t,n)=>({trackId:e[n]??t,otherTrackId:t}))}function Gr(e){return e.flatMap((t,n)=>e.slice(n+1).map(e=>({trackId:t,otherTrackId:e})))}function Kr(e,t){let n=[];for(let r of t.relations){let t=r.leftTrackId===e?r.rightTrackId:r.rightTrackId===e?r.leftTrackId:null;if(t===null)continue;let i=r.relation===`same-subject`?`same as`:`different from`;n.push(`${i} ${t}${r.presence===`continuous`?` (continuous)`:``}`)}for(let r of t.purities)r.sourceTrackId===e&&n.push(r.purity===`not-a-subject`?`not a subject`:r.switchAtMs===null?`mixed`:`mixed at switch`);return n}function qr(e){switch(e.state){case`off`:return J.t(`helpers.eventsDebugTapes.statusOff`);case`recording`:return J.t(`helpers.eventsDebugTapes.statusRecording`);case`refused`:return J.t(`helpers.eventsDebugTapes.statusRefused`,{reason:e.reason??J.t(`helpers.eventsDebugTapes.unknownReason`)});case`failing`:return J.t(`helpers.eventsDebugTapes.statusFailing`,{reason:e.reason??J.t(`helpers.eventsDebugTapes.unknownReason`)});case`unknown`:return J.t(`helpers.eventsDebugTapes.statusUnknown`,{reason:e.reason??J.t(`helpers.eventsDebugTapes.unknownReason`)})}}var Jr={"window-too-long":`A promoted window is at most 30 minutes.`,"window-in-future":`The window ends in the future.`,"window-not-recorded":`No segment covers that window — the camera was not recording then, or it is older than 24 h.`,"invalid-scenario":`The scenario must be a slug: lowercase letters, digits and dashes, 3–64 characters.`,"promotion-budget":`A promotion budget is full (60 tapes, 1 GiB, 3 000 pinned tracks). Release or delete a tape already committed as a case first.`,"empty-window":`No frame was recorded in that window.`,"shelf-unreadable":`The camera's recorded segments could not be listed, so the window cannot be proven whole.`,"not-post-processing-node":`This node does not post-process frames, so it records no tracking tapes.`,"artifacts-elsewhere":`The artifacts storage location is on another node; tapes are recorded only where it lives.`,"tapes-not-started":`The tape recorder has not started on this node (or failed to).`};function Yr(e,t){let n=Jr[e]??`Refused (${e}).`;return t.length>0?`${n} ${t}`:n}function Xr(e){if(e.length===0)return null;let t=new Date(e).getTime();return Number.isFinite(t)?t:null}function Zr(e){return e<1024*1024?J.t(`helpers.eventsDebugTapes.sizeKb`,{value:(e/1024).toFixed(0)}):J.t(`helpers.eventsDebugTapes.sizeMb`,{value:(e/1024/1024).toFixed(1)})}function Qr(e){return e===null?`unknown`:Zr(e)}function $r(e){return e===null?`unknown`:String(e)}function ei(e,t){let n=t.trim();return e===404?J.t(`helpers.eventsDebugTapes.exportUnknown`):e===503?n.length>0?n:J.t(`helpers.eventsDebugTapes.tapesUnavailable`):e===500?n.length>0?n:J.t(`helpers.eventsDebugTapes.exportUnreadable`):J.t(`helpers.eventsDebugTapes.downloadFailed`,{status:e})}c();function ti({cameras:t,call:n,onPromoted:r}){let{t:a}=Y(),[s,c]=o(``),[l,u]=o(``),[d,f]=o(``),[p,m]=o(``),[h,g]=o(``),[v,y]=o(`auto`),[b,x]=o(!1),[S,C]=o(null),w=async()=>{let e=Number.parseInt(s===``?t[0]?.value??``:s,10),i=Xr(l),a=Xr(d);if(!Number.isFinite(e)||i===null||a===null){C(`Pick a camera and both ends of the window.`);return}x(!0),C(null);try{let t=Fr(await n(vr.promote,{deviceId:e,fromMs:i,toMs:a,scenario:p,...h.trim().length>0?{note:h.trim()}:{},...v===`day`||v===`ir`?{lighting:v}:{}}));t===null?C(Cr):t.ok?(C(`Promoted ${t.tapeId}: ${String(t.frames)} frames, ${Zr(t.bytes)}, ${String(t.pinnedTracks)} tracks pinned`+(t.state===`incomplete`?` — incomplete (it has gaps) and cannot become a case.`:`.`)),r()):C(Yr(t.reason,t.detail))}catch(e){C(wr(e))}finally{x(!1)}};return e(`div`,{className:`flex flex-wrap items-end gap-2 rounded-md border border-border px-3 py-2`,children:[i(`div`,{className:`w-40`,children:i(E,{value:s,options:[...t],onChange:e=>c(e.target.value),"aria-label":a(`eventsDebugTapesPromoteForm.camera`,`Camera`)})}),i(He,{type:`datetime-local`,"aria-label":a(`eventsDebugTapesPromoteForm.from`,`From`),value:l,onChange:e=>u(e.target.value),className:`w-48`}),i(He,{type:`datetime-local`,"aria-label":a(`eventsDebugTapesPromoteForm.to`,`To`),value:d,onChange:e=>f(e.target.value),className:`w-48`}),i(He,{"aria-label":a(`eventsDebugTapesPromoteForm.scenario`,`Scenario`),placeholder:`101-door-groups`,value:p,onChange:e=>m(e.target.value),className:`w-44`}),i(He,{"aria-label":a(`eventsDebugTapesPromoteForm.note`,`Note`),placeholder:a(`eventsDebugTapesPromoteForm.optionalNote`,`optional note`),value:h,onChange:e=>g(e.target.value),className:`w-52`}),i(`div`,{className:`w-28`,children:i(E,{value:v,"aria-label":a(`eventsDebugTapesPromoteForm.lighting`,`Lighting`),options:[{value:`auto`,label:a(`eventsDebugTapesPromoteForm.lightingAuto`,`Lighting: auto`)},{value:`day`,label:a(`eventsDebugTapes.dayMode`)},{value:`ir`,label:`IR`}],onChange:e=>y(e.target.value)})}),e(G,{onClick:()=>void w(),disabled:b||t.length===0,children:[b?i(_,{className:`h-3.5 w-3.5 animate-spin`}):null,` `,a(`eventsDebugTapes.promoteWindow`)]}),i(`p`,{className:`w-full text-xs text-foreground-subtle`,children:a(`eventsDebugTapesPromoteForm.aPromotedTapeMayBe`,`A promoted tape may be shared as a test case — keep the scenario slug and note free of names or other personal data.`)}),S!==null&&i(`p`,{className:`w-full text-xs text-foreground`,children:S})]})}var ni=`pipeline-analytics`,ri=`debug.listTracks`,ii=`debug.analyze`,ai=v(`/addon/pipeline-analytics/debug-export`);function oi(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function si(e,t){let n=e[t];return typeof n==`string`?n:null}function ci(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function li(e,t){let n=e[t];return typeof n==`boolean`?n:null}function ui(e){return e===`error`||e===`warn`||e===`info`}function di(e){if(!oi(e))return null;let t=si(e,`code`),n=si(e,`detail`),r=e.severity;return t===null||n===null||!ui(r)?null:{code:t,severity:r,detail:n}}function fi(e){if(!oi(e))return null;let t=si(e,`trackId`),n=ci(e,`deviceId`),r=si(e,`className`),i=ci(e,`firstSeen`),a=ci(e,`lastSeen`),o=ci(e,`durationMs`),s=li(e,`active`);if(t===null||n===null||r===null||i===null||a===null||o===null||s===null)return null;let c=si(e,`label`),l=si(e,`subLabel`),u=si(e,`previewMissReason`),d=li(e,`markForTrain`),f=li(e,`favourited`);return{trackId:t,deviceId:n,className:r,...c===null?{}:{label:c},...l===null?{}:{subLabel:l},firstSeen:i,lastSeen:a,durationMs:o,active:s,timestamp:i,windowMs:o,importance:ci(e,`importance`)??0,bestEventId:si(e,`bestEventId`)??``,...d===null?{}:{markForTrain:d},...f===null?{}:{favourited:f},debug:!0,...u===null||u.length===0?{}:{previewMissReason:u}}}function pi(e){let t=fi(e);if(t===null||!oi(e))return null;let n=ci(e,`mediaCount`),r=ci(e,`eventCount`),i=ci(e,`positionCount`);if(n===null||r===null||i===null)return null;let a=e.mediaKinds,o=e.findings;if(!Array.isArray(a)||!Array.isArray(o))return null;let s=a.filter(e=>typeof e==`string`),c=[];for(let e of o){let t=di(e);t!==null&&c.push(t)}let l=e.thumbnailProvenance;return{...t,mediaCount:n,mediaKinds:s,eventCount:r,positionCount:i,findings:c,...Sn(l)?{thumbnailProvenance:l}:{}}}function mi(e){if(!oi(e))return null;let t=li(e,`truncated`),n=e.tracks;if(t===null||!Array.isArray(n))return null;let r=[];for(let e of n){let t=fi(e);if(t===null)return null;r.push(t)}return{tracks:r,truncated:t}}function hi(e){if(!oi(e))return null;let t=e.reports,n=e.vanished;if(!Array.isArray(t)||!Array.isArray(n))return null;let r=[];for(let e of t){let t=pi(e);if(t===null)return null;r.push(t)}return{reports:r,vanished:n.filter(e=>typeof e==`string`)}}var gi={MEDIA_EVICTED_OR_NEVER:`no media`,MISSING_KEYFRAME:`no keyframe`,MISSING_FIRSTFRAME:`no first frame`,MISSING_LASTFRAME:`no last frame`,MISSING_THUMBNAIL:`no thumbnail`,MISSING_BEST_CROP:`no crop`,SHORT_TRACK:`very short`,ZERO_EVENTS:`no events`,ZERO_POSITIONS:`no trajectory`,NO_PERIODIC_SNAPSHOTS:`no snapshots`,LASTFRAME_STALE:`stale last frame`,MEDIA_STOPPED_EARLY:`media stopped early`,NO_BEST_EVENT:`no best event`,LOW_BEST_SCORE:`low score`,UNSCORED_LABEL:`unscored label`,BEST_SHOT_STANDIN:`stand-in best shot`,BEST_SHOT_RASTER:`low-res best shot`};function _i(e){return gi[e]??e}var vi={error:0,warn:1,info:2};function yi(e){return e.toSorted((e,t)=>vi[e.severity]-vi[t.severity]||e.code.localeCompare(t.code))}function bi(e){return e.length===0?ai:`${ai}?deviceIds=${e.join(`,`)}`}function xi(e){if(e<1e4)return`${(e/1e3).toFixed(1)}s`;let t=Math.round(e/1e3);if(t<60)return`${String(t)}s`;let n=Math.floor(t/60);return`${String(n)}m ${String(t%60).padStart(2,`0`)}s`}function Si(e,t){return`${String(e)}:${t}`}function Ci(e,t){let n=[],r=new Set;for(let i of e){let e=Si(i.deviceId,i.trackId);!t.has(e)||r.has(e)||(r.add(e),n.push({deviceId:i.deviceId,trackId:i.trackId}))}return n}c();function wi({tapeId:t,call:n,onClose:r,onChanged:a}){let{t:c}=Y(),l=s({queryKey:[`events-debug`,`tapes`,`tracks`,t],queryFn:async()=>Pr(await n(vr.tracks,{tapeId:t}))}),u=l.data??null,d=s({queryKey:[`events-debug`,`tapes`,`marks`,t],enabled:u!==null,queryFn:async()=>u===null?null:Vr(await n(yr.list,{deviceId:u.deviceId,since:u.fromMs-xr,until:u.toMs+xr,limit:5e3}))}),[f,p]=o([]),[m,h]=o(``),[g,_]=o(null),v=e=>p(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),y=async e=>{_(null);try{for(let[t,r]of e)await n(t,r);p([]),await d.refetch(),a()}catch(e){_(wr(e))}};if(u===null)return l.isLoading?i(`p`,{className:`text-xs`,children:c(`eventsDebugTapesReview.loadingTheTape`,`Loading the tape…`)}):i(K,{message:Cr});let b=u.deviceId,x=(e,t)=>y(e.map(e=>[yr.setRelation,{deviceId:b,...e,relation:t}])),S=e=>{let t=Number.parseFloat(m),n=e===`mixed`&&Number.isFinite(t)?u.fromMs+t*1e3:void 0;return y(f.map(t=>[yr.setPurity,{deviceId:b,trackId:t,purity:e,...n===void 0?{}:{switchAtMs:Math.round(n)}}]))},C=d.data==null?null:Hr(d.data);return e(`div`,{className:`space-y-2 rounded-md border border-primary/40 px-3 py-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`span`,{className:`text-xs font-medium`,children:c(`eventsDebugTapes.reviewLanes`,{id:u.tapeId,count:u.lanes.length})}),i(G,{disabled:f.length<2,onClick:()=>void x(Wr(f),`same-subject`),children:c(`eventsDebugTapesReview.sameSubject`,`Same subject`)}),i(G,{variant:`secondary`,disabled:f.length<2,onClick:()=>void x(Gr(f),`different-subjects`),children:c(`eventsDebugTapesReview.differentSubjects`,`Different subjects`)}),i(He,{"aria-label":c(`eventsDebugTapesReview.changedAtSFromTape`,`Changed at (s from tape start)`),placeholder:c(`eventsDebugTapesReview.changedAtS`,`changed at s`),value:m,onChange:e=>h(e.target.value),className:`w-28`}),i(G,{variant:`secondary`,disabled:f.length!==1,onClick:()=>void S(`mixed`),children:c(`eventsDebugTapesReview.mixed`,`Mixed`)}),i(G,{variant:`secondary`,disabled:f.length===0,onClick:()=>void S(`not-a-subject`),children:c(`eventsDebugTapesReview.notASubject`,`Not a subject`)}),i(G,{variant:u.reviewed?`secondary`:`primary`,onClick:()=>void y([[vr.review,{tapeId:u.tapeId,reviewed:!u.reviewed}]]).then(()=>l.refetch()),children:u.reviewed?c(`eventsDebugTapesReview.markNotReviewed`,`Mark not reviewed`):c(`eventsDebugTapesReview.markReviewed`,`Mark reviewed`)}),i(G,{variant:`ghost`,onClick:r,children:c(`common.close`,`Close`)})]}),g!==null&&i(K,{message:g}),C!==null&&i(K,{variant:`warning`,message:C}),i(`ul`,{className:`space-y-1`,children:u.lanes.toSorted((e,t)=>e.firstT-t.firstT).map(e=>i(Ti,{lane:e,marks:d.data===null||d.data===void 0?[]:Kr(e.trackId,d.data),selected:f.includes(e.trackId),onToggle:()=>v(e.trackId)},e.trackId))})]})}function Ti({lane:t,marks:n,selected:r,onToggle:a}){let{t:o}=Y(),{src:s}=at(t.stillStored?ot(`track`,t.trackId):void 0);return e(`li`,{className:`flex items-center gap-2 text-xs`,children:[i(g,{"aria-label":o(`eventsDebugTapesReview.select`,`select {{trackId}}`,{trackId:t.trackId}),checked:r,onChange:a}),s===null?i(`div`,{className:`h-10 w-10 rounded bg-surface-hover`}):i(`img`,{src:s,alt:t.trackId,className:`h-10 w-10 rounded object-cover`}),i(`span`,{className:`font-mono`,children:t.trackId}),i(`span`,{children:t.cls}),i(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapes.laneFrames`,{range:`${xi(t.firstT)} → ${xi(t.lastT)}`,count:t.boundFrames})}),!t.stillStored&&i(`span`,{className:`text-foreground-subtle`,children:o(`eventsDebugTapesReview.notStoredMarkedThroughThe`,`not stored — marked through the tape`)}),n.map(e=>i(q,{variant:`info`,children:e},e))]})}c();var Ei=`camstack_admin_token`;function Di(){let e=ie();return(t,n)=>e.trpcClient.addons.custom.mutate({addonId:ni,action:t,input:n})}async function Oi(e,t){let n=localStorage.getItem(Ei),r={};n!==null&&(r.Authorization=`Bearer ${n}`);let i=await fetch(Sr(e),{headers:r});if(!i.ok){let e=await i.text().catch(()=>``);throw Error(ei(i.status,e))}let a=await i.blob(),o=i.headers.get(`content-disposition`),s=(o===null?null:/filename="?([^";]+)"?/i.exec(o))?.[1]?.trim()??t,c=URL.createObjectURL(a),l=document.createElement(`a`);l.href=c,l.download=s,l.click(),setTimeout(()=>URL.revokeObjectURL(c),6e4)}function ki(){let{t:e}=Y(),[t,n]=o(!1);return i(Ge,{expanded:t,onExpandedChange:n,header:i(`span`,{className:`text-sm font-medium text-foreground`,children:e(`eventsDebugTapes.trackingTapes`,`Tracking tapes`)}),children:i(Ai,{})})}function Ai(){let{t}=Y(),r=Di(),a=Ke({isCamera:!0,projection:`slim`}),c=n(()=>{let e=new Map;for(let t of a.data??[])e.set(t.id,t.name);return n=>e.get(n)??t(`cameraLoad.deviceLabel`,{deviceId:n})},[a.data,t]),l=s({queryKey:[`events-debug`,`tapes`,`status`],queryFn:async()=>Ar(await r(vr.status,{}))}),u=s({queryKey:[`events-debug`,`tapes`,`list`],queryFn:async()=>Mr(await r(vr.list,{}))}),[d,f]=o(null),[m,h]=o(null),g=async e=>{h(null);try{await Oi(e.id,`${e.scenario}.tape-bundle.json.gz`)}catch(e){h(wr(e))}},_=async e=>{let t=Ir(await r(vr.release,{tapeId:e.id}));if(t===null)throw Error(Cr);let n=Rr(t);if(n!==null)throw Error(n);await u.refetch()},v=async e=>{let t=Lr(await r(vr.remove,{tapeId:e.id}));if(t===null)throw Error(Cr);let n=Rr(t);if(n!==null)throw Error(n);await u.refetch()};return e(`div`,{className:`space-y-3`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ze,{i18nKey:`eventsDebugTapes.intro`,components:{b:i(`strong`,{}),code:i(`code`,{})}})}),m!==null&&i(K,{message:m}),l.isLoading&&i(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingCameraStatus`,`Loading camera status…`)}),l.data===null&&i(K,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[i(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[i(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),i(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),i(`th`,{children:t(`eventsDebugTapes.framesMin`,`Frames/min`)}),i(`th`,{children:t(`eventsDebugTapes.lastHour`,`Last hour`)}),i(`th`,{children:t(`eventsDebugTapes.held`,`Held`)}),i(`th`,{children:t(`eventsDebugTapes.gaps`,`Gaps`)})]})}),i(`tbody`,{children:(l.data??[]).map(n=>e(`tr`,{children:[i(`td`,{children:c(n.deviceId)}),i(`td`,{children:i(q,{variant:n.state===`recording`?`success`:n.state===`off`?`default`:n.state===`unknown`?`warning`:`danger`,children:qr(n)})}),i(`td`,{children:n.framesPerMin===void 0?`—`:String(Math.round(n.framesPerMin))}),i(`td`,{title:n.shelfError,children:Qr(n.bytesLastHour)}),i(`td`,{title:n.shelfError,children:t(`eventsDebugTapes.segsHeld`,{count:$r(n.segmentsHeld),size:Qr(n.bytesHeld)})}),i(`td`,{children:String(n.gapsSinceArmed)})]},n.deviceId))})]}),i(ti,{cameras:Ur(l.data??[]).map(e=>({value:String(e.deviceId),label:e.segmentsUnknown?t(`eventsDebugTapes.segmentsUnknown`,`{{value1}} (segments unknown)`,{value1:c(e.deviceId)}):c(e.deviceId)})),call:r,onPromoted:()=>void u.refetch()}),u.isLoading&&i(`p`,{className:`text-xs text-foreground-subtle`,children:t(`eventsDebugTapes.loadingPromotedTapes`,`Loading promoted tapes…`)}),u.data===null&&i(K,{message:`The server answered in a shape this build does not understand.`}),e(`table`,{className:`w-full text-xs`,children:[i(`thead`,{children:e(`tr`,{className:`text-left text-foreground-subtle`,children:[i(`th`,{children:t(`eventsDebugTapes.scenario`,`Scenario`)}),i(`th`,{children:t(`eventsDebugTapes.camera`,`Camera`)}),i(`th`,{children:t(`eventsDebugTapes.window`,`Window`)}),i(`th`,{children:t(`eventsDebugTapes.state`,`State`)}),i(`th`,{children:t(`eventsDebugTapes.tracks`,`Tracks`)}),i(`th`,{})]})}),i(`tbody`,{children:(u.data??[]).map(n=>e(`tr`,{children:[i(`td`,{children:n.scenario}),i(`td`,{children:c(n.deviceId)}),e(`td`,{children:[new Date(n.fromMs).toLocaleString(),` · `,xi(n.toMs-n.fromMs),` `,`· `,n.lighting]}),e(`td`,{children:[i(q,{variant:n.state===`complete`?`success`:`warning`,children:n.state}),` `,n.reviewed&&i(q,{variant:`info`,children:t(`eventsDebugTapes.reviewed`)}),` `,n.released&&i(q,{children:t(`eventsDebugTapes.released`)})]}),i(`td`,{children:t(`eventsDebugTapes.storedOf`,{stored:String(n.tracksStillStored),total:String(n.tracks.length)})}),e(`td`,{className:`space-x-1 text-right`,children:[i(G,{variant:`secondary`,"aria-label":t(`eventsDebugTapes.review`,`Review {{scenario}}`,{scenario:n.scenario}),onClick:()=>f(n.id),children:t(`eventsDebugTapes.review2`,`Review`)}),i(G,{variant:`ghost`,"aria-label":t(`eventsDebugTapes.download`,`Download {{scenario}}`,{scenario:n.scenario}),onClick:()=>void g(n),children:i(re,{className:`h-3.5 w-3.5`})}),i(me,{label:t(`eventsDebugTapes.release`,`Release`),icon:p,title:t(`eventsDebugTapes.release2`,`Release {{scenario}}?`,{scenario:n.scenario}),description:t(`eventsDebugTapes.releasingReturnsThisTapeS`,`Releasing returns this tape's pinned tracks to ordinary retention — they can be pruned from then on. The promoted bundle itself is kept until deleted.`),confirmLabel:t(`eventsDebugTapes.release`,`Release`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:n.released,action:()=>_(n)}),i(me,{label:t(`common.delete`,`Delete`),icon:z,title:t(`eventsDebugTapes.delete`,`Delete {{scenario}}?`,{scenario:n.scenario}),description:t(`eventsDebugTapes.deletingRemovesThePromotedBundle`,`Deleting removes the promoted bundle and its index row for good. Its tracks' pins are released first — this cannot be undone.`),confirmLabel:t(`common.delete`,`Delete`),triggerVariant:`ghost`,confirmVariant:`danger`,action:()=>v(n)})]})]},n.id))})]}),d!==null&&i(wi,{tapeId:d,call:r,onClose:()=>f(null),onChanged:()=>void u.refetch()})]})}c();var ji=`all`,Mi=`The server answered in a shape this build does not understand.`,Ni={error:`danger`,warn:`warning`,info:`info`};function Pi({findings:e}){let{t}=Y();return e.length===0?i(q,{variant:`success`,children:t(`eventsDebug.noAnomalyFound`,`no anomaly found`)}):i(`div`,{className:`flex flex-wrap gap-1`,children:yi(e).map(e=>i(q,{variant:Ni[e.severity],title:e.detail,children:_i(e.code)},e.code))})}function Fi({track:t,report:n,analyzing:r}){let{t:a}=Y(),o=En(n?.previewMissReason??t.previewMissReason);return e(`div`,{className:`space-y-1 border-t border-border pt-1.5`,children:[n===void 0?i(`span`,{className:`text-[10px] text-foreground-subtle`,children:r?a(`eventsDebug.analysing`,`analysing…`):a(`eventsDebug.notAnalysed`,`not analysed`)}):e(u,{children:[i(Pi,{findings:n.findings}),i(`p`,{className:`text-[10px] text-foreground-subtle`,title:n.mediaKinds.length>0?n.mediaKinds.join(`, `):a(`eventsDebug.noMediaOfAnyKind`,`no media of any kind`),children:a(`eventsDebug.reportCounts`,{media:String(n.mediaCount),events:String(n.eventCount),positions:String(n.positionCount)})})]}),o!==null&&i(`p`,{className:`text-[10px] text-foreground-subtle`,title:o.raw,children:o.sentence})]})}function Ii({deviceId:t}={}){let{t:r}=Y(),a=ie(),[c,l]=o(ji),u=t===void 0?c:String(t),[d,f]=o(!1),[p,m]=o(null),[h,g]=o(new Set),[v,y]=o(null),[x,C]=o(null),[w,T]=o(null),[ee,D]=o([]),O=Pn(),k=Ke({isCamera:!0,projection:`slim`}),A=n(()=>[{value:ji,label:r(`eventsDebug.allCameras`,`All cameras`)},...(k.data??[]).map(e=>({value:String(e.id),label:e.name}))],[k.data,r]),te=n(()=>{let e=new Map;for(let t of k.data??[])e.set(t.id,t.name);return e},[k.data]),M=e=>te.get(e)??r(`eventsDebug.cameraFallback`,{deviceId:e}),P=n(()=>u===ji?[]:[Number.parseInt(u,10)],[u]),L=s({queryKey:[`events-debug`,`list`,P],queryFn:async()=>mi(await a.trpcClient.addons.custom.mutate({addonId:ni,action:ri,input:P.length===0?{}:{deviceIds:P}}))}),R=n(()=>(L.data?.tracks??[]).map(e=>e.trackId),[L.data]),z=s({queryKey:[`events-debug`,`analyze`,R],enabled:R.length>0,queryFn:async()=>hi(await a.trpcClient.addons.custom.mutate({addonId:ni,action:ii,input:{trackIds:R}}))}),ne=n(()=>{let e=new Map;for(let t of z.data?.reports??[])e.set(t.trackId,t);return e},[z.data]),B=L.data?.tracks??[],V=L.data===null||z.data===null,ae=()=>{L.refetch(),z.refetch()},oe=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},H=()=>{g(new Set(B.map(e=>Si(e.deviceId,e.trackId))))},se=()=>g(new Set),ce=async(e,t)=>{let n=e===`analyzed`?{debug:!1}:{favourited:!0},r=0,i=[];for(let e of t)try{await O.mutateAsync({deviceId:e.deviceId,trackId:e.trackId,flags:n}),r+=1}catch{i.push(e.trackId)}return{applied:r,refused:i}},U=e=>{if(!jn||x!==null)return;let t=Ci(B,h);t.length!==0&&(C(e),T(null),(async()=>{let n=await ce(e,t);C(null);let r=new Set(n.refused);g(new Set(t.filter(e=>r.has(e.trackId)).map(e=>Si(e.deviceId,e.trackId)))),e===`analyzed`&&D(t.filter(e=>!r.has(e.trackId))),n.refused.length>0&&T(`${String(n.refused.length)} of ${String(t.length)} were refused by the server and are still selected. Check the hub log.`),L.refetch()})())},le=()=>{let e=ee;e.length===0||x!==null||(C(`analyzed`),T(null),(async()=>{for(let t of e)try{await O.mutateAsync({deviceId:t.deviceId,trackId:t.trackId,flags:{debug:!0}})}catch{T(`Some tracks could not be re-marked. Refresh and try again.`)}C(null),D([]),L.refetch()})())},ue=async()=>{f(!0),m(null);try{await ct(bi(P),`camstack-debug.zip`)}catch(e){m(e instanceof Error?e.message:`Export failed.`)}finally{f(!1)}},W=x!==null;return e(`section`,{className:`space-y-3`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[t===void 0&&i(`div`,{className:`w-44`,children:i(E,{value:u,options:A,onChange:e=>l(e.target.value)})}),e(G,{variant:`secondary`,onClick:ae,disabled:L.isFetching,children:[L.isFetching?i(_,{className:`h-3.5 w-3.5 animate-spin`}):i(S,{className:`h-3.5 w-3.5`}),r(`common.refresh`,`Refresh`)]}),e(G,{onClick:()=>void ue(),disabled:d||B.length===0,children:[d?i(_,{className:`h-3.5 w-3.5 animate-spin`}):i(re,{className:`h-3.5 w-3.5`}),r(`eventsDebug.exportAll`,{count:String(B.length)})]}),B.length>0&&h.size<B.length&&i(G,{variant:`ghost`,onClick:H,children:r(`eventsDebug.selectAll`,`Select all`)})]}),i(`p`,{className:`text-xs text-foreground-subtle`,children:i(Ze,{i18nKey:`eventsDebug.debugMarkNote`,components:{code:i(`code`,{}),strong:i(`strong`,{})}})}),i(ki,{}),L.isError&&i(K,{message:r(`eventsDebug.couldNotLoadTheMarked`,`Could not load the marked tracks.`)}),V&&!L.isError&&i(K,{message:Mi}),p!==null&&i(K,{message:p}),w!==null&&i(K,{message:w}),L.data?.truncated===!0&&i(K,{message:r(`eventsDebug.aCameraFilledThePer`,`A camera filled the per-camera cap — some marked tracks are not listed. Un-mark a few, or filter to one camera.`)}),(z.data?.vanished.length??0)>0&&i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`eventsDebug.vanished`,{count:String(z.data?.vanished.length)})}),h.size>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[i(`span`,{className:`text-xs font-medium text-foreground`,children:r(`common.selectedCount`,{count:h.size})}),e(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[i(`span`,{title:jn?void 0:`Track flags arrive with the next server update`,children:e(G,{variant:`secondary`,onClick:()=>U(`keep`),disabled:!jn||W,children:[x===`keep`?i(_,{className:`h-3.5 w-3.5 animate-spin`}):i(N,{className:`h-3.5 w-3.5`}),` `,r(`eventsDebug.keep`,`Keep`)]})}),i(`span`,{title:jn?void 0:`Track flags arrive with the next server update`,children:e(G,{onClick:()=>U(`analyzed`),disabled:!jn||W,children:[x===`analyzed`?i(_,{className:`h-3.5 w-3.5 animate-spin`}):i(I,{className:`h-3.5 w-3.5`}),` `,r(`eventsDebug.analyzed`,`Analyzed`)]})}),i(G,{variant:`ghost`,onClick:se,disabled:W,children:i(b,{className:`h-3.5 w-3.5`})})]})]}),ee.length>0&&e(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[i(`span`,{className:`text-xs text-foreground`,children:r(`eventsDebug.markedAnalyzed`,{count:String(ee.length)})}),e(G,{variant:`ghost`,onClick:le,disabled:W,children:[i(F,{className:`h-3.5 w-3.5`}),` `,r(`eventsDebug.undo`)]}),i(G,{variant:`ghost`,onClick:()=>D([]),disabled:W,children:i(b,{className:`h-3.5 w-3.5`})})]}),L.isLoading?i(Ue,{status:`pending`,pendingMessage:`Loading…`,testId:`debug-tracks-grid`}):B.length===0?i(Pe,{icon:j,title:r(`eventsDebug.noTrackIsMarkedFor`,`No track is marked for debug`),description:r(`eventsDebug.markOneFromATrack`,`Mark one from a track's actions on the Feed to see it here.`)}):i(Ue,{status:`ready`,testId:`debug-tracks-grid`,children:B.map(e=>{let t=ne.get(e.trackId);return i(er,{row:e,cameraName:M(e.deviceId),nowMs:e.lastSeen,selected:h.has(Si(e.deviceId,e.trackId)),onToggleSelect:oe,onOpenDetail:y,...t?.thumbnailProvenance===void 0?{}:{provenance:t.thumbnailProvenance},footer:i(Fi,{track:e,report:t,analyzing:z.isFetching})},Si(e.deviceId,e.trackId))})}),v&&i(Qn,{row:v,cameraName:M(v.deviceId),deleteAvailable:Yt,onClose:()=>y(null),onDeleted:()=>{y(null),L.refetch()},onFlagsChanged:e=>{e.debug||(y(null),L.refetch())}})]})}c();var Li=`section`;function Ri(){let{t}=Y(),n=Je(),{deviceId:a}=Qe(),[,s]=$e(),c=rt(),[l,d]=o(void 0),[f,p]=o(null),[m,h]=o(!1),[_,v]=o(!1),y=a===void 0?NaN:Number(a),b=r(e=>{s(t=>{let n=new URLSearchParams(t);return n.set(Li,e),n},{replace:!0})},[s]);if(!Number.isFinite(y))return i(Ye,{to:`/archive`,replace:!0});let x=c.rows.find(e=>e.deviceId===y);if(!c.isLoading&&x===void 0)return i(Pe,{icon:T,title:t(`archive.camera.unknown`,`Camera not found`),description:t(`archive.camera.unknownHint`,`This camera is not in the Archive. Pick one from the overview.`)});let S=kt(jt(c,y),tt(c.findings,y));return i(lt,{icon:ce,title:x?.name??t(`archive.camera.loading`,`Camera`),subtitle:i(`span`,{className:`flex flex-wrap items-center gap-1.5`,children:S.map(n=>e(q,{variant:At[n.state],children:[t(`archive.function.${n.fn}`,n.fn),` ·`,` `,t(`archive.functionState.${n.state}`,n.state)]},n.fn))}),actions:i(E,{wrapperClassName:`inline-block w-auto`,value:y,onChange:e=>n(`/archive/${e.target.value}`),"aria-label":t(`archive.camera.picker`,`Camera`),children:c.cameras.map(e=>i(`option`,{value:e.id,children:e.name},e.id))}),paramName:Li,defaultSection:`review`,sectionsLabel:t(`archive.camera.sections`,`Camera sections`),sections:[{id:`review`,label:t(`archive.camera.review`,`Review`),content:i(Nt,{deviceId:y,seekTo:l,onExportRange:(e,t)=>{p({fromMs:e,toMs:t}),b(`exports`)}})},{id:`events`,label:t(`archive.camera.events`,`Events`),content:e(`div`,{className:`flex flex-col gap-3`,children:[i(lr,{}),i(mr,{deviceId:y,onActiveChange:v}),!_&&e(u,{children:[i(_r,{deviceId:y}),e(`label`,{className:`flex w-fit items-center gap-2 text-xs text-foreground-subtle`,children:[i(g,{checked:m,onChange:e=>h(e.target.checked)}),t(`archive.camera.debugFilter`,`Debug-marked tracks only`)]}),m?i(Ii,{deviceId:y}):i(sr,{deviceId:y,onSeek:e=>{d(t=>({atMs:e,nonce:(t?.nonce??0)+1})),b(`review`)}})]})]})},{id:`exports`,label:t(`archive.camera.exports`,`Exports`),content:i(nt,{deviceId:y,draft:f,onDraftClose:()=>p(null)})},{id:`health`,label:t(`archive.camera.health`,`Health`),content:e(`div`,{className:`flex flex-col gap-6`,children:[i(Mt,{data:c,deviceId:y}),i(et,{data:c,deviceId:y})]})},{id:`space`,label:t(`archive.camera.space`,`Space`),content:x===void 0?null:i(Bt,{data:c,row:x})},{id:`settings`,label:t(`archive.camera.settings`,`Settings`),content:i(Pt,{deviceId:y})}]})}export{Ri as ArchiveCameraPage};
@@ -1 +0,0 @@
1
- import{C as e,K as t,R as n,S as r,Y as i,et as a}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{t as o}from"./useTranslation-BJr-n0es.js";import{It as s,L as c,R as l,f as u,p as d}from"./index-DPyWa2vo.js";import{n as f}from"./NodeAddonsSettingsPanel-FjpwQjGM.js";a();function p(e,t){if(e.type===`group`){for(let n of e.fields)p(n,t);return}if(e.type===`sub-tabs`){for(let n of e.tabs)for(let e of n.fields)p(e,t);return}`value`in e&&(t[e.key]=e.value)}function m(e){let t={};for(let n of e.sections)for(let e of n.fields)p(e,t);return t}var h=`system-config-auth`;function g({sectionIds:e,omitSectionIds:n,hideSectionChrome:i,emptyMessage:a}){let o=u(),s=t(()=>{if(o.data===void 0)return null;let t=o.data.sections.filter(t=>!(e!==void 0&&!e.includes(t.id)||n?.includes(t.id)===!0||e===void 0&&t.id===`system-config-auth`));return{...o.data,sections:f(t,{...i===!0?{hideSectionChrome:i}:{}})}},[o.data,e,n,i]);return o.isPending?null:s===null||o.isError?r(`p`,{className:`text-sm text-foreground-muted`,children:a}):s.sections.length===0?null:r(_,{schema:s})}function _({schema:a}){let{t:u}=o(),f=d(),[p,h]=i(null),g=t(()=>m(a),[a]),_=n(async e=>{h(null);try{await f.mutateAsync({patch:e})}catch(e){throw h(e instanceof Error&&e.message.length>0?e.message:u(`system.bootstrapForm.saveFailed`,`Could not save`)),e}},[f,u]),v=l({schema:a,serverValues:g,onImmediateSave:e=>void _(e).catch(()=>void 0),onDeferredSave:_});return e(`div`,{className:`flex flex-col gap-3`,children:[p!==null&&r(`div`,{role:`alert`,className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:p}),r(s,{schema:a,values:v.values,onChange:v.handleChange,disabled:f.isPending}),r(c,{pendingCount:v.pendingKeys.length,onSave:()=>v.handleSave(v.pendingKeys),onDiscard:()=>v.handleDiscard(v.pendingKeys),saving:f.isPending})]})}export{h as n,g as t};