@camstack/addon-admin-ui 1.2.119 → 1.2.121

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 (110) hide show
  1. package/dist/assets/AddLocationWizard--mkj3ETu.js +1 -0
  2. package/dist/assets/{AddonCollectionPage-B03rWwOK.js → AddonCollectionPage-CqgSQxQ5.js} +1 -1
  3. package/dist/assets/Addons-Bf2kB7FO.js +1 -0
  4. package/dist/assets/{AdminTabs-BhVFfu-V.js → AdminTabs-Bnpekf9L.js} +1 -1
  5. package/dist/assets/{AiProfiles-CmIRcCjv.js → AiProfiles-Dx9QzfkB.js} +1 -1
  6. package/dist/assets/{BrokerForm-CGbxdxp0.js → BrokerForm-Cp-QCiwW.js} +1 -1
  7. package/dist/assets/{Build-Bneqa83Z.js → Build-DK4nAd1G.js} +3 -3
  8. package/dist/assets/{Capabilities-Bd7XskC7.js → Capabilities-DjmiW556.js} +1 -1
  9. package/dist/assets/{CapabilityBadges-KMhMCn1k.js → CapabilityBadges-CjczBoDi.js} +1 -1
  10. package/dist/assets/Cluster-CWDTyv3x.js +11 -0
  11. package/dist/assets/{Data-Dr3p27zg.js → Data-CC__xt_7.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-BziKZgjR.js → DetectionIntelligence-DOLcWM0z.js} +1 -1
  13. package/dist/assets/{DeviceAggregateSection-CheBdbsr.js → DeviceAggregateSection-CtNus-Z9.js} +1 -1
  14. package/dist/assets/DeviceDetail-BBK_biJu.js +2 -0
  15. package/dist/assets/{Devices-BV1t7-g5.js → Devices-C9AhNeGU.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-n4oktMWk.js → EmbedPlayerPage-gbryRNIt.js} +1 -1
  17. package/dist/assets/Events-zTFK1o8o.js +1 -0
  18. package/dist/assets/{FormBuilder-D7eVmgZJ.js → FormBuilder-C_1-Y69Y.js} +1 -1
  19. package/dist/assets/Identity-CVqxKTJo.js +1 -0
  20. package/dist/assets/{IntegrationDetail-B4uov2Kt.js → IntegrationDetail-CnTI0i1_.js} +1 -1
  21. package/dist/assets/{Integrations-_7bjpG_5.js → Integrations-1V80f5GH.js} +1 -1
  22. package/dist/assets/{Integrations-SNPkOFhA.js → Integrations-CWQzB2G-.js} +1 -1
  23. package/dist/assets/{Logs-pNO26-_g.js → Logs-DAI2eKrC.js} +1 -1
  24. package/dist/assets/{MotionZonesSettings-DikN9JEQ.js → MotionZonesSettings-Cx8Fgga9.js} +1 -1
  25. package/dist/assets/{MyAccess-BnULhZgR.js → MyAccess-lmd0GUa4.js} +1 -1
  26. package/dist/assets/Network-DL7vgvPz.js +1 -0
  27. package/dist/assets/{NodeAddonsSettingsPanel-DvTRBvQl.js → NodeAddonsSettingsPanel-CF38Xfjd.js} +1 -1
  28. package/dist/assets/{NodeInferenceDevices-BaRmgURr.js → NodeInferenceDevices-DEeOhTqE.js} +1 -1
  29. package/dist/assets/{Notifications-DXzfB7Iv.js → Notifications-DyHxI0OV.js} +1 -1
  30. package/dist/assets/Pipeline-D2AK3bq-.js +1 -0
  31. package/dist/assets/Plates-FJGFRHwS.js +1 -0
  32. package/dist/assets/{PrivacyMaskSettings-CZLQzQgv.js → PrivacyMaskSettings--DN9Cj1J.js} +1 -1
  33. package/dist/assets/{ProviderIcon-aFjOxP4_.js → ProviderIcon-B7xnPSGY.js} +1 -1
  34. package/dist/assets/Recordings-DuMD9mO7.js +1 -0
  35. package/dist/assets/{ScanNetworkModal-DFZ9sM0F.js → ScanNetworkModal-BkuLL5Hb.js} +1 -1
  36. package/dist/assets/{SceneMonitorEditor-BN655weg.js → SceneMonitorEditor-CKZcEP_n.js} +1 -1
  37. package/dist/assets/{Scenes-C0y2uk0j.js → Scenes-UJ6HwN5-.js} +1 -1
  38. package/dist/assets/{Settings-DpIKYRlm.js → Settings-Bsfr9POB.js} +1 -1
  39. package/dist/assets/{Showroom-CWbwspFj.js → Showroom-D134TM7C.js} +1 -1
  40. package/dist/assets/{Terminal-ykBOga6k.js → Terminal-DaXvlDS6.js} +5 -5
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BYhH6kE0.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-7GR589xa.js} +1 -1
  42. package/dist/assets/{bell-ring-CXoCKJnn.js → bell-ring-6mWtb-XF.js} +1 -1
  43. package/dist/assets/{boxes-Bw4b1Wc1.js → boxes-C5NTL0ET.js} +1 -1
  44. package/dist/assets/circle-check-big-DADKFm5x.js +1 -0
  45. package/dist/assets/{circle-x-DDabN2KD.js → circle-x-CFWnmyvU.js} +1 -1
  46. package/dist/assets/clock-Cl7hHyqW.js +1 -0
  47. package/dist/assets/{copy-C-EqjmDP.js → copy-tqbIiAtY.js} +1 -1
  48. package/dist/assets/{debounced-invalidate-Bfd2Qzzn.js → debounced-invalidate-BvbZ9j3z.js} +1 -1
  49. package/dist/assets/{dist-D_lTK4xz.js → dist-D-XW9v3T.js} +1 -1
  50. package/dist/assets/dist-DYkLn2xO.js +349 -0
  51. package/dist/assets/{download-Cuj1maBm.js → download-CBTHh5Td.js} +1 -1
  52. package/dist/assets/{face-bbox-y-km4dI8.js → face-bbox-DK3crsBr.js} +1 -1
  53. package/dist/assets/{hostInit-Cym8Rr5d.js → hostInit-uOc4KuW6.js} +1 -1
  54. package/dist/assets/{index-BTGQKEEA.js → index-D-9Wyuju.js} +3 -3
  55. package/dist/assets/{key-round-DvhPSBSH.js → key-round-Cp0w9XS6.js} +1 -1
  56. package/dist/assets/{layers-B7No2bw_.js → layers-R56RBx5J.js} +1 -1
  57. package/dist/assets/{mf-entry-bootstrap-0-ae9b3119.js → mf-entry-bootstrap-0-3f5d688b.js} +2 -2
  58. package/dist/assets/{pencil-BJxboIbx.js → pencil-Dppq_R1x.js} +1 -1
  59. package/dist/assets/play-CRkSis2D.js +1 -0
  60. package/dist/assets/{player-overlays-RwoCa548.js → player-overlays-MJd9eRlM.js} +1 -1
  61. package/dist/assets/plus-BgigjkU9.js +1 -0
  62. package/dist/assets/power-BCS2t-Wx.js +1 -0
  63. package/dist/assets/{radio-klp_ubdd.js → radio-Den8nSQU.js} +1 -1
  64. package/dist/assets/{refresh-cw-OR1QZ198.js → refresh-cw-Budztdr-.js} +1 -1
  65. package/dist/assets/remoteEntry-DdFdvgxU.js +1 -0
  66. package/dist/assets/rotate-ccw-C_FPsgtu.js +1 -0
  67. package/dist/assets/rotate-cw-Ci2EV6Gc.js +1 -0
  68. package/dist/assets/{send-vc4Psyt4.js → send-BZ9zOH2R.js} +1 -1
  69. package/dist/assets/{server-BXgYajYr.js → server-DhDeuLAj.js} +1 -1
  70. package/dist/assets/{shield-Y4WSkvsK.js → shield-CDajPz7k.js} +1 -1
  71. package/dist/assets/square-BVwnxCbL.js +1 -0
  72. package/dist/assets/{square-check-big-hQzwD37R.js → square-check-big-B9gVi10Z.js} +1 -1
  73. package/dist/assets/src-0iNMzZ2l.js +349 -0
  74. package/dist/assets/src-DwTflGqD.js +67 -0
  75. package/dist/assets/{star-BM5cPk35.js → star-B4ylQ-n9.js} +1 -1
  76. package/dist/assets/{undo-2-C4NHExfy.js → undo-2-3EmEvFIS.js} +1 -1
  77. package/dist/assets/use-scenes-feed-julJoDvZ.js +1 -0
  78. package/dist/assets/useEventInvalidation-DSpypyuO.js +1 -0
  79. package/dist/assets/{useNodeUrlSelection-DbuPo174.js → useNodeUrlSelection-Dsk2NydD.js} +1 -1
  80. package/dist/assets/{video-DIbJOXgM.js → video-BlZPfhfO.js} +1 -1
  81. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DbvhoXKV.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CokdarDJ.js} +2 -2
  82. package/dist/assets/{wifi-CMg5tM5x.js → wifi-obpV41fJ.js} +1 -1
  83. package/dist/assets/{zap-Dnw48_IY.js → zap-B8NXR1Yj.js} +1 -1
  84. package/dist/index.html +5 -5
  85. package/dist/server/addon.js +291 -5
  86. package/package.json +1 -1
  87. package/dist/assets/AddLocationWizard-BcscyeiT.js +0 -1
  88. package/dist/assets/Addons-BDWcu7bj.js +0 -1
  89. package/dist/assets/Cluster-CS-NJ6OS.js +0 -11
  90. package/dist/assets/DeviceDetail-Br1qPJ6r.js +0 -2
  91. package/dist/assets/Events-CkGijCDG.js +0 -1
  92. package/dist/assets/Identity-Cb2GAD5w.js +0 -1
  93. package/dist/assets/Network-Bv3jrJ1-.js +0 -1
  94. package/dist/assets/Pipeline-DCSX_1o6.js +0 -1
  95. package/dist/assets/Plates-BEU4sAqP.js +0 -1
  96. package/dist/assets/Recordings-b6zC1cWE.js +0 -1
  97. package/dist/assets/circle-check-big-D_Kt6W2W.js +0 -1
  98. package/dist/assets/clock-BeIF3nWG.js +0 -1
  99. package/dist/assets/dist-D-Tiwsk7.js +0 -349
  100. package/dist/assets/play-CeohfaKf.js +0 -1
  101. package/dist/assets/plus-Brv4i72u.js +0 -1
  102. package/dist/assets/power-DmJawhTF.js +0 -1
  103. package/dist/assets/remoteEntry-CRo49mol.js +0 -1
  104. package/dist/assets/rotate-ccw-Dzp5z5a_.js +0 -1
  105. package/dist/assets/rotate-cw-6dMVo8-E.js +0 -1
  106. package/dist/assets/square-Dd2LMGtj.js +0 -1
  107. package/dist/assets/src-CDVm70oc.js +0 -67
  108. package/dist/assets/src-ijaeX4aR.js +0 -349
  109. package/dist/assets/use-scenes-feed-BsYnn_Rq.js +0 -1
  110. package/dist/assets/useEventInvalidation-D4KUD_Rr.js +0 -1
@@ -1 +0,0 @@
1
- import{Q as e,S as t,W as n,a as r,b as i,o as a,q as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as c}from"./player-overlays-RwoCa548.js";import{As as l,Cs as u,Ds as d,Es as f,Fs as p,Hr as m,Is as h,Ms as g,Ns as _,On as v,Os as y,Ps as b,Rt as x,S,Ss as C,Ts as w,f as T,js as E,kn as D,ks as O,p as k,tt as ee,un as A,ws as te,x as j}from"./src-CDVm70oc.js";import{c as M,d as N,l as P,u as F}from"./src-ijaeX4aR.js";import{t as I}from"./circle-check-big-D_Kt6W2W.js";import{t as ne}from"./copy-C-EqjmDP.js";import{t as re}from"./key-round-DvhPSBSH.js";import{t as ie}from"./pencil-BJxboIbx.js";import{t as ae}from"./plus-Brv4i72u.js";import{C as L,E as R,I as oe,K as z,R as se,d as B,k as ce,l as V,n as H,o as U,r as W,w as G,z as le}from"./index-BTGQKEEA.js";import{t as K}from"./AdminPage-CCD07UMs.js";import{t as ue}from"./AdminTabs-BhVFfu-V.js";import{t as de}from"./AddonCollectionPage-B03rWwOK.js";import{t as fe}from"./addon-display-names-DvSEQty-.js";var pe=z(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),me=z(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),he=z(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),ge=z(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),_e=z(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),ve=z(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);e();function ye({userId:e,username:n,onClose:r}){let o=a(),c=A(),l=f({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),p=w({onSuccess:()=>{d(),r()}}),m=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(V,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(W,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[m===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(L,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),m===`not_enrolled`&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[s(G,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),m===`enrolled`&&u&&t(i,{children:[t(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[s(I,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(x,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&p.mutate({userId:e})},disabled:p.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[p.isPending?s(L,{className:`h-3 w-3 animate-spin`}):s(W,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function q({icon:e,label:n,count:r,all:i,total:a}){return t(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[s(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:n}),s(`span`,{className:r===0?`text-foreground-subtle`:`font-medium text-foreground`,children:r===0?`none`:i?`all ${a}`:`${r} of ${a}`})]})}function be({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=m({projection:`slim`}),d=u?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(_e,{className:`h-3 w-3 shrink-0`}),a]})});if(l.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(L,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let f=l.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:f.isAdmin?t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):t(i,{children:[s(q,{icon:ce,label:`Devices they can see`,count:f.device.view.deviceCount,all:f.device.view.all,total:d}),s(q,{icon:ie,label:`Devices they can operate`,count:f.device.create.deviceCount,all:f.device.create.all,total:d}),s(q,{icon:U,label:`Devices they can delete`,count:f.device.delete.deviceCount,all:f.device.delete.all,total:d}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,f.system.length===0?`none`:f.system.join(`, `),f.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,f.capabilities.map(e=>e.name).join(`, `)]}),f.addons.length>0&&t(i,{children:[` · Addons: `,f.addons.map(e=>e.name).join(`, `)]})]}),f.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}function xe(e){let t=F(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function Se(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:P({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Ce({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:l}){let u=n(()=>xe(e.scopes??[]),[e.scopes]),[d,f]=o(u),[p,m]=o(u.mode===`advanced`),h=n(()=>Se(d),[d]),g=!e.isAdmin&&d.mode===`role`&&d.roleId===null,_=n(()=>e.isAdmin?null:d.mode===`role`&&d.roleId===null?`Pick what this user can do to see the result.`:k(h),[e.isAdmin,d.mode,d.roleId,h]),v=e=>f({...d,...e});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 pt-[calc(1rem+env(safe-area-inset-top))] pb-[calc(1rem+env(safe-area-inset-bottom))]`,children:t(`div`,{className:`flex max-h-full w-full max-w-2xl flex-col rounded-lg border border-border bg-surface shadow-xl`,children:[t(`div`,{className:`flex shrink-0 items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Access — `,e.username]}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),s(`button`,{onClick:r,className:`shrink-0 text-foreground-subtle hover:text-foreground`,title:`Close`,children:s(W,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[g&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(_e,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`No access.`}),` `,t(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),s(`div`,{className:`space-y-1.5`,children:M.map(e=>{let n=d.mode===`role`&&d.roleId===e.id;return t(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[s(`input`,{type:`radio`,name:`access-role`,checked:n,onChange:()=>v({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),t(`span`,{className:`min-w-0`,children:[s(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),s(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),t(`button`,{type:`button`,onClick:()=>{if(!p){f({...d,mode:`advanced`,advancedScopes:h}),m(!0);return}m(!1),f(xe(d.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[s(p?se:oe,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),p&&t(`div`,{className:`rounded-lg border border-border p-2`,children:[s(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),s(T,{value:d.advancedScopes,onChange:e=>v({mode:`advanced`,advancedScopes:e}),clampToParent:l,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),d.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(j,{value:d.selector,onChange:e=>v({selector:e}),includeLinked:d.includeLinked,onIncludeLinkedChange:e=>v({includeLinked:e}),clampToDeviceIds:null})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:d.mode===`role`?`3 · Result`:`2 · Result`}),s(be,{scopes:h,isAdmin:e.isAdmin,invalidReason:_})]})]}),t(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:r,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>a([...h]),disabled:c||_!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:c?s(L,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();function we(){let e=a(),{user:n}=H(),[r,i]=o(!1),[c,d]=o(``),[f,m]=o(``),[g,_]=o(!1),[v,y]=o(null),{data:b,isLoading:x,isError:S}=l(),C=A(),w=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),T=u({onSuccess:()=>{w(),i(!1),d(``),m(``),_(!1),y(null)},onError:e=>{y(e instanceof Error?e.message:`Failed to create user`)}}),D=te({onSuccess:w}),O=h({onSuccess:w}),k=E({onSuccess:w}),j=p({onSuccess:()=>{w(),N(null)}}),[M,N]=o(null),[P,F]=o(null),I=b??[];async function ne(e){await C({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&D.mutate({id:e.id})}async function re(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await C({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&k.mutate({id:e.id,newPassword:t})}}function ie(e,t){t!==e.isAdmin&&O.mutate({id:e.id,isAdmin:t})}function R(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(K,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[s(ae,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(W,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`input`,{type:`text`,value:c,onChange:e=>d(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`input`,{type:`password`,value:f,onChange:e=>m(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),v&&s(`p`,{className:`text-[10px] text-danger`,children:v}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>T.mutate({username:c,password:f,isAdmin:g}),disabled:T.isPending||!c||!f,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:T.isPending?`Creating...`:`Create`})]})]}),x&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!x&&!S&&I.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>D.isPending&&D.variables?.id===e.id||O.isPending&&O.variables?.id===e.id||k.isPending&&k.variables?.id===e.id;return s(ee,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>ie(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>N(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(B,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Te,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:R(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>F(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(V,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>re(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[s(he,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>ne(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[i?s(L,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:I,rowKey:e=>e.id,minWidthPx:560})})(),P&&s(ye,{userId:P.id,username:P.username,onClose:()=>F(null)}),M&&s(Ee,{user:M,onClose:()=>N(null),onSubmit:e=>j.mutate({userId:M.id,scopes:e}),submitting:j.isPending})]})}function Te({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=F(e);return n===null?t(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):t(`span`,{className:`text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:N(n.roleId).label}),` ·`,` `,S(n.selector)]})}function Ee(e){let{user:t}=H(),n=t?.isAdmin===!0;return s(Ce,{...e,callerScopes:n?null:t?.scopes??[]})}e();var De=`bg-primary/10 text-primary`,Oe=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ke(e){return e?e===`*`?`*`:e.join(`, `):``}function Ae(){let e=a(),r=A(),{data:i,isLoading:c}=d(),{data:u}=l(),f=n(()=>i??[],[i]),p=n(()=>u??[],[u]),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),h=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[_,v]=o(!1),[y,x]=o(null),S=g({onSuccess:m}),w=C({onSuccess:({token:e,record:t})=>{h(),v(!1),x({token:e,label:t.name})}}),T=b({onSuccess:h}),E=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&S.mutate({id:e})},D=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&T.mutate({id:e})};return t(K,{children:[t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),t(`button`,{onClick:()=>v(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:p.length===0,title:p.length===0?`Create a user first`:`Issue a scoped token`,children:[s(B,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(je,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[p.length===0&&s(Ne,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),p.map(e=>s(Fe,{userId:e.id,username:e.username,onRevoke:(e,t)=>{D(e,t)},revokePending:T.isPending,revokeId:T.variables?.id},e.id))]}),f.length>0&&s(je,{title:`Legacy API keys`,subtitle:`${f.length} pre-existing — revoke only`,children:s(Pe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:f.map(e=>{let n=!!e.isAdmin,r=S.isPending&&S.variables?.id===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${n?De:Oe}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ke(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{E(e.id,e.label)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(L,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Me,{}),_&&s(Ie,{users:p.map(e=>({id:e.id,username:e.username})),onClose:()=>v(!1),onSubmit:e=>w.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:w.isPending}),y&&s(Le,{token:y.token,label:y.label,onClose:()=>x(null)})]})}function je({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Me(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ne({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Pe({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function Fe({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=O({userId:e}),l=o??[];return c||l.length===0?null:t(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),s(Pe,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:l.map(e=>{let n=i&&a===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,n)=>t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${S(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>r(e.id,e.name),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[n?s(L,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Ie({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=H(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,m]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[h,g]=o(``),_=k(p),v=l!==``&&d.trim().length>0&&p.length>0&&_===null&&!i;return t(Re,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(Y,{label:`On behalf of user`,children:s(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>s(`option`,{value:e.id,children:e.username},e.id))})}),s(Y,{label:`Name`,children:s(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),t(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[s(T,{value:p,onChange:m,clampToParent:c}),_&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:_})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),t(ze,{children:[s(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`button`,{onClick:()=>{let e=parseInt(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!v,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?s(L,{className:`h-3.5 w-3.5 animate-spin`}):s(B,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function Le({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(Re,{title:`Token: ${n}`,onClose:r,children:[t(`div`,{className:`space-y-3`,children:[s(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),s(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),t(ze,{children:[t(`button`,{onClick:()=>{c()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[i?s(le,{className:`h-3.5 w-3.5 text-primary`}):s(ne,{className:`h-3.5 w-3.5`}),i?`Copied`:`Copy`]}),s(`button`,{onClick:r,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function Re({title:e,onClose:n,children:r}){return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),s(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:s(W,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function ze({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:n,children:r}){return t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),r,n&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:n})]})}e();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function Be(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Ve(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function He({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Ue({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function We(){let e=a(),r=A(),{data:i,isLoading:o}=y(),c=n(()=>i??[],[i]),l=_({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(K,{icon:ge,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&s(Ve,{}),!o&&c.length===0&&s(He,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(Ue,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:c.map(e=>{let n=e.revokedAt!==null,r=(l.isPending?l.variables?.id:void 0)===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>s(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:Be(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border`,children:n?t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):s(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!n&&t(`button`,{onClick:()=>{u(e.id,e.integrationId)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(L,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ge(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:me,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:R,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:R,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:V,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:V,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:B,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Ke(){let e=D({capName:Q[0].capName},{refetchInterval:Z}),t=D({capName:Q[1].capName},{refetchInterval:Z}),r=v(void 0,{refetchInterval:Z}),i=n(()=>fe(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of r[e]??[])n.push({addonId:a.addonId,displayName:i.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,i]);return s(de,{title:$.title,subtitle:$.subtitle,pageIcon:B,itemIcon:B,capability:Q[0].capName,installButtonLabel:$.installLabel,items:a,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:s(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>s(qe,{addonId:e.addonId})})}function qe({addonId:e}){let n=Ge(e),r=n.icon;return t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-start gap-2.5`,children:[s(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),s(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),s(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>s(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[t(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[s(pe,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[s(G,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function Je(){return s(`div`,{className:`flex flex-col p-4`,children:s(ue,{tabs:[{id:`users`,label:`Users`,icon:ve,content:s(we,{})},{id:`api-keys`,label:`Tokens`,icon:re,content:s(Ae,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:ge,content:s(We,{})},{id:`authentication`,label:`Authentication`,icon:B,content:s(Ke,{})}]})})}export{Je as IdentityPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as l}from"./player-overlays-RwoCa548.js";import{Ai as u,Bi as d,Fi as f,Gi as p,Hi as m,Ii as h,It as g,Ki as _,Li as v,Lt as y,Mi as b,Ni as x,Nt as S,On as C,Pi as ee,Ri as te,Rt as w,Ui as ne,Vi as T,Wi as E,Xi as D,Xt as O,Yi as re,Zi as ie,ji as ae,ki as oe,kn as k,rt as A,tt as j,xs as M,zi as se}from"./src-CDVm70oc.js";import{at as N,et as P}from"./src-ijaeX4aR.js";import{t as F}from"./boxes-Bw4b1Wc1.js";import{t as I}from"./copy-C-EqjmDP.js";import{t as L}from"./play-CeohfaKf.js";import{t as ce}from"./refresh-cw-OR1QZ198.js";import{t as le}from"./rotate-ccw-Dzp5z5a_.js";import{t as R}from"./server-BXgYajYr.js";import{t as z}from"./shield-Y4WSkvsK.js";import{t as B}from"./square-Dd2LMGtj.js";import{t as V}from"./wifi-CMg5tM5x.js";import{C as H,E as U,K as W,S as G,a as K,c as ue,j as de,r as fe,x as pe,y as q,z as me}from"./index-BTGQKEEA.js";import{t as he}from"./AdminPage-CCD07UMs.js";import{t as ge}from"./AdminTabs-BhVFfu-V.js";import{t as _e}from"./NodeAddonsSettingsPanel-DvTRBvQl.js";import{t as J}from"./AddonCollectionPage-B03rWwOK.js";import{t as Y}from"./addon-display-names-DvSEQty-.js";var ve=W(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),ye=W(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),be=W(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);t();var X=5e3,xe={connected:!1,endpoint:null};function Se(){let e=a(),t=k({capName:`network-access`},{refetchInterval:X}),n=C(void 0,{refetchInterval:X}),i=r(()=>Y(n.data??[]),[n.data]),c=r(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,i]),[l,u]=o(null),[d,f]=o({}),p=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),u(null),f(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},m=(e,t)=>{u(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);f(e=>({...e,[n]:r}))},h=D({onSuccess:p,onError:m}),g=ie({onSuccess:p,onError:m});return s(J,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:U,itemIcon:U,capability:`network-access`,installButtonLabel:`Add tunnel`,items:c,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>s(we,{addonId:e.addonId}),itemError:e=>d[e.addonId]??null,renderPrimaryAction:e=>s(Te,{addonId:e.addonId,busyId:l,onStart:e=>{u(e),h.mutate({addonId:e})},onStop:e=>{u(e),g.mutate({addonId:e})}})})}function Ce(e){let{data:t}=re({addonId:e},{refetchInterval:X,retry:!1}),n=t?N.safeParse(t):null;return n?.success?n.data:xe}function we({addonId:e}){let t=Ce(e);return n(i,{children:[s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&n(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[s(de,{className:`h-3 w-3`}),t.endpoint.url]})]})}function Te({addonId:e,busyId:t,onStart:r,onStop:i}){let a=Ce(e),o=t===e;return a.connected?n(w,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?s(H,{className:`h-3 w-3 animate-spin`}):s(B,{className:`h-3 w-3`}),`Stop`]}):n(w,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?s(H,{className:`h-3 w-3 animate-spin`}):s(L,{className:`h-3 w-3`}),`Start`]})}t();var Ee=3e4;function De(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function Oe(){let e=k({capName:`turn-provider`},{refetchInterval:Ee}),t=C(void 0,{refetchInterval:Ee}),i=M(),a=i.data??[],o=r(()=>Y(t.data??[]),[t.data]);return s(J,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:q,itemIcon:q,capability:`turn-provider`,installButtonLabel:`Add provider`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:o.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,o]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>s(ke,{addonId:e.addonId,enabled:e.isActive}),trailing:n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),s(w,{size:`sm`,variant:`secondary`,onClick:()=>i.refetch(),disabled:i.isFetching,children:`Refresh`})]}),s(`div`,{className:`p-4`,children:a.length===0?s(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):s(`div`,{className:`flex flex-col gap-3`,children:a.map((e,t)=>{let r=Array.isArray(e.urls)?e.urls:[e.urls];return n(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&n(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,s(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&n(`span`,{children:[s(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,s(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(e=>s(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function ke({addonId:e,enabled:t}){let i=M({addonId:e},{enabled:t,retry:!1}),a=r(()=>De(i.data??[]),[i.data]);return!t||a.length===0?null:n(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[n(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,a.length,`)`]}),s(`div`,{className:`flex flex-wrap gap-1`,children:a.map(e=>s(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}t();var Ae={lan:q,wifi:V,docker:F,vpn:G,loopback:R,other:R},je={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Me=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ne(e){let{interfaces:t,disabled:i,hideLoopback:a,ipv4Only:o,emptyMessage:c}=e,l=r(()=>t.filter(e=>!(a&&e.kind===`loopback`||o&&e.family!==`IPv4`)),[t,a,o]),u=r(()=>{let e=new Map;for(let t of l){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Me.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[l]),d=t=>e.mode===`single`?e.value===t:e.value.includes(t),f=t=>{if(i||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let n=new Set(e.value);n.has(t.address)?n.delete(t.address):n.add(t.address),e.onChange([...n])};return l.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic`,children:c??`No addresses available.`}):s(`div`,{className:`flex flex-col gap-3`,children:u.map(({kind:t,items:r})=>n(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[s(Ae[t]??R,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:je[t]??t}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),s(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=d(t.address),a=t.kind===`loopback`,o=!t.plausible&&!a;return n(`li`,{className:`flex items-center gap-3 px-3 py-2 ${a?`opacity-60 cursor-not-allowed`:i?`opacity-60`:o?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>f(t),children:[s(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&s(me,{className:`h-3 w-3`})}),n(`div`,{className:`flex-1 min-w-0 ${o?`text-foreground-subtle`:``}`,children:[n(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[s(`span`,{className:`font-mono text-xs font-semibold ${o?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),s(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),a&&s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),n(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}t();var Pe={"lan-ipv4":{label:`IPv4`,className:`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`},"lan-ipv6":{label:`IPv6`,className:`bg-violet-500/15 text-violet-700 dark:text-violet-300`},public:{label:`Public`,className:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},loopback:{label:`Loopback`,className:`bg-foreground-subtle/15 text-foreground-subtle`}};function Z(e){return e.kind!==`loopback`}function Fe(e){return e.kind!==`loopback`}function Ie(){let e=a(),t=l(),i=ee(void 0,{refetchInterval:3e4}),f=oe(void 0),p=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),m=h({onSuccess:t=>{b(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),_=r(()=>i.data?.interfaces??[],[i.data]),v=u({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[y,b]=o([]),[C,ne]=o(!1);c(()=>{!C&&f.data&&(b(f.data.addresses),ne(!0))},[f.data,C]);let T=f.data?.addresses??[],E=r(()=>{if(y.length!==T.length)return!0;let e=[...y].toSorted(),t=[...T].toSorted();return e.some((e,n)=>e!==t[n])},[y,T]),D=()=>{p.mutate({addresses:[...y]})},O=()=>{b(T)},re=()=>{b([])},ie=()=>{i.refetch(),v.refetch(),f.refetch(),A.refetch(),N.refetch()},k=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=ae(),M=se({onSuccess:()=>void A.refetch()}),N=x(),P=d({onSuccess:()=>void N.refetch()}),F=v.data?.endpoints??[],I=A.data?.baseUrl??null,L=A.data?.resolved??null,R=N.data?.baseUrls??[],z=R.length===0,B=I===null,V=e=>z?e.kind===`lan-ipv4`||e.kind===`public`&&e.interfaceKind===`public`:R.includes(e.baseUrl),H=e=>I===null?L===e.baseUrl:I===e.baseUrl,U=e=>{if(!Z(e))return;let t=z?F.filter(e=>Z(e)&&V(e)).map(e=>e.baseUrl):[...R],n=t.includes(e.baseUrl)?t.filter(t=>t!==e.baseUrl):[...t,e.baseUrl];P.mutate({baseUrls:n})},W=e=>{if(Fe(e)){if(H(e)){B||M.mutate({baseUrl:null});return}M.mutate({baseUrl:e.baseUrl})}},G=r(()=>[{key:`url`,header:`Endpoint`,render:e=>n(`div`,{className:`min-w-0 py-0.5`,children:[s(`div`,{className:`font-mono text-[12px] break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),n(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[s(`span`,{children:e.label}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&s(`span`,{className:`uppercase tracking-wide`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&n(`span`,{className:`inline-flex items-center gap-1 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[s(K,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]})]})},{key:`kind`,header:`Kind`,nowrap:!0,render:e=>{let t=Pe[e.kind]??Pe.loopback;return s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.className}`,children:t.label})}},{key:`viewer`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Viewer`,z?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-24`,render:e=>{let t=Z(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:e.kind===`loopback`?`Loopback is not a client route.`:`Use this URL in the API / viewer race.`,children:s(S,{checked:t&&V(e),disabled:!t||P.isPending,onChange:()=>U(e),"aria-label":`Viewer: ${e.baseUrl}`})})}},{key:`notifications`,headerRender:()=>n(`span`,{className:`inline-flex items-center gap-1`,children:[`Notifications`,B?s(`span`,{className:`text-[10px] font-normal normal-case text-foreground-subtle`,children:`auto`}):null]}),align:`center`,nowrap:!0,width:`w-28`,render:e=>{let t=Fe(e);return s(`label`,{className:`inline-flex justify-center ${t?`cursor-pointer`:`cursor-not-allowed opacity-40`}`,title:t?`Notification links and deep links use this address.`:`Loopback is not a client route.`,children:s(S,{checked:t&&H(e),disabled:!t||M.isPending,onChange:()=>W(e),"aria-label":`Notifications: ${e.baseUrl}`})})}}],[z,B,R,I,L,P.isPending,M.isPending,F]);return n(he,{children:[n(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pin which host addresses exist, then tick the destinations each URL should serve. Viewer auto is IPv4 + public; every other row (including IPv6) can be ticked on.`}),n(`div`,{className:`flex items-center gap-2 shrink-0`,children:[n(w,{size:`sm`,variant:`secondary`,onClick:ie,disabled:i.isLoading,children:[s(ce,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),s(w,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:y.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${y.length} pinned`})]}),n(`div`,{className:`flex items-center gap-1`,children:[n(w,{size:`sm`,variant:`secondary`,onClick:()=>m.mutate(void 0),disabled:m.isPending||p.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[s(ue,{className:`h-3 w-3`}),m.isPending?`Detecting…`:`Best match`]}),n(w,{size:`sm`,variant:`secondary`,onClick:re,disabled:y.length===0||p.isPending,children:[s(le,{className:`h-3 w-3`}),`Clear`]}),E&&s(w,{size:`sm`,variant:`secondary`,onClick:O,disabled:p.isPending,children:`Discard`}),n(w,{size:`sm`,variant:`primary`,onClick:D,disabled:!E||p.isPending,children:[s(ye,{className:`h-3 w-3`}),p.isPending?`Saving…`:`Save`]})]})]}),s(`div`,{className:`p-4`,children:s(Ne,{mode:`multiple`,interfaces:_,value:y,onChange:b,disabled:p.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),n(g,{children:[n(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between gap-3 flex-wrap`,children:[n(`div`,{children:[s(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints`}),s(`div`,{className:`text-xs text-foreground-subtle`,children:`Ranked URLs this hub advertises. Tick Viewer (many) and Notifications (one).`})]}),n(`div`,{className:`flex items-center gap-1`,children:[!z&&s(w,{size:`sm`,variant:`secondary`,disabled:P.isPending,onClick:()=>P.mutate({baseUrls:[]}),children:`Viewer → auto`}),!B&&s(w,{size:`sm`,variant:`secondary`,disabled:M.isPending,onClick:()=>M.mutate({baseUrl:null}),children:`Notifications → auto`})]})]}),B&&L===null&&s(`p`,{className:`px-4 pt-3 text-[11px] text-amber-600 dark:text-amber-400`,children:`No public address is reachable, so notification media ships as bytes only — a backend that can only take links (WhatsApp, gotify) receives none.`}),s(j,{columns:G,rows:F,rowKey:e=>`${e.priority}-${e.baseUrl}`,minWidthPx:640,bordered:!1,mobileMode:`scroll`,emptyMessage:v.isLoading?`Loading…`:`No endpoints available.`,rowClassName:e=>e.plausible?void 0:`opacity-80`})]})]})}t();var Le={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Q=5e3,Re=3e4,ze={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Be(){let e=k({capName:`mesh-network`},{refetchInterval:Q}),t=C(void 0,{refetchInterval:Q}),n=r(()=>Y(t.data??[]),[t.data]);return s(J,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:F,itemIcon:q,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:r(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>s(Ve,{addonId:e.addonId}),renderPrimaryAction:e=>s(He,{addonId:e.addonId}),renderExpandedPanel:e=>s(Ue,{addonId:e.addonId})})}function $(e){let{data:t,isLoading:n}=m({addonId:e},{refetchInterval:Q,retry:!1}),r=t?P.safeParse(t):null;return{status:r?.success?r.data:ze,isLoading:n}}function Ve({addonId:e}){let{status:t}=$(e);return n(i,{children:[s(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function He({addonId:t}){let r=a(),[c,u]=o(!1),[d,f]=o(null),m=l(),{status:h}=$(t),g=e(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),v=_(),y=ne({onSuccess:g}),b=p({onSuccess:g}),x=e(async()=>{u(!0);let e={cancelled:!1};f(e);try{let n=await v.mutateAsync({addonId:t});if(e.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!e.cancelled&&(await Xe(2e3),!e.cancelled);){let e=await m.trpcClient.meshNetwork.getStatus.query({addonId:t}).catch(()=>null),n=e?P.safeParse(e):null;if(n?.success&&n.data.joined){g();break}if(Date.now()-r>6e5)break}}finally{u(!1),f(null)}},[t,g,v,m]),S=e(()=>{d&&(d.cancelled=!0),u(!1),f(null)},[d]);return s(i,{children:h.joined?n(i,{children:[n(w,{size:`sm`,variant:`secondary`,disabled:y.isPending,onClick:()=>y.mutate({addonId:t}),children:[y.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(pe,{className:`h-3 w-3`}),`Disconnect`]}),n(w,{size:`sm`,variant:`ghost`,disabled:b.isPending,onClick:()=>b.mutate({addonId:t}),children:[b.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]}):c?n(w,{size:`sm`,variant:`ghost`,onClick:S,children:[s(fe,{className:`h-3 w-3 mr-1`}),` Cancel`]}):n(i,{children:[n(w,{size:`sm`,variant:`primary`,onClick:()=>void x(),children:[s(ve,{className:`h-3 w-3`}),`Connect`]}),n(w,{size:`sm`,variant:`ghost`,disabled:b.isPending,onClick:()=>b.mutate({addonId:t}),children:[b.isPending?s(H,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Log out`]})]})})}function Ue({addonId:e}){let{status:t}=$(e),r=E({addonId:e},{refetchInterval:Re,retry:!1});return n(`div`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`p-4 space-y-4`,children:[t.error&&s(O,{message:t.error}),s(We,{status:t}),t.endpoints.length>0&&n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>n(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[n(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Le[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?s(U,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),n(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[s(de,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),s(`div`,{className:`border-t border-border`,children:s(Ke,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function We({status:e}){return s(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ge(e.keyExpiry):`—`}].map(e=>n(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[s(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),s(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ge(e){let t=e-Date.now();if(t<0)return`Expired ${Ye(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Ke({peers:t,loading:i}){let a=r(()=>t.map(e=>({...e,_id:e.id})),[t]),o=e(e=>{e&&navigator.clipboard?.writeText(e)},[]),c=r(()=>[{key:`hostname`,header:`Hostname`,render:e=>n(`div`,{className:`flex flex-col`,children:[n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&s(y,{variant:`info`,children:`self`}),e.exitNodeOption&&s(y,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&s(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),s(`button`,{onClick:()=>o(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:s(I,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?n(`div`,{className:`flex items-center gap-1`,children:[s(`span`,{className:`font-mono text-xs`,children:t}),s(`button`,{onClick:()=>o(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:s(I,{className:`h-3 w-3 text-foreground-subtle`})})]}):s(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>n(`div`,{className:`flex items-center gap-1.5`,children:[s(y,{variant:qe(e.connection),children:e.connection}),e.relay&&s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?s(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):s(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>n(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Je(e.txBytes),` · ↓ `,Je(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>s(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Ye(e.lastSeenMs):`—`})}],[o]);return i&&t.length===0?n(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[s(H,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.length===0?s(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):s(`div`,{className:`p-4`,children:s(j,{columns:c,rows:a,rowKey:e=>e._id,minWidthPx:820})})}function qe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Je(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function Ye(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Xe(e){return new Promise(t=>setTimeout(t,e))}t();function Ze(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Qe(){let e=a(),t=b(void 0,{refetchInterval:15e3}),r=f({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),i=v({onSuccess:()=>void e.invalidateQueries({queryKey:[[`localNetwork`]]})}),c=T({onSuccess:()=>{d(!1),m(``),_(``),x(``),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=t.data,[u,d]=o(!1),[p,m]=o(``),[h,_]=o(``),[y,x]=o(``),S=()=>{if(!l?.caCertPem)return;let e=new Blob([l.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=l?.mode===`uploaded`?`Uploaded`:l?.mode===`generated`?`Generated local CA`:`TLS disabled`;return n(`div`,{className:`flex flex-col gap-4`,children:[s(_e,{nodeId:`hub`,addonIds:[`local-network`],level:`global`,title:`LAN HTTP`,description:`Native apps on this Wi-Fi use http:// and skip the private certificate. The tunnel and this admin UI stay on HTTPS.`}),n(g,{className:`p-4 space-y-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(z,{className:`h-4 w-4 text-foreground-subtle`}),s(`h3`,{className:`text-sm font-semibold`,children:`Certificate`})]}),t.isError&&s(`p`,{className:`text-xs text-danger`,children:`Could not read TLS status.`}),l?.reissueError&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:l.reissueError}),l?.restartRequired&&s(`p`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Restart the hub to apply the new certificate.`}),n(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Mode`}),s(`dd`,{className:`font-medium`,children:C})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Valid to`}),s(`dd`,{className:`font-mono`,children:l?.validTo?new Date(l.validTo).toLocaleString():`—`})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`Leaf SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.leafFingerprintSha256??void 0,children:Ze(l?.leafFingerprintSha256??null)})]}),n(`div`,{children:[s(`dt`,{className:`text-foreground-subtle`,children:`CA SHA-256`}),s(`dd`,{className:`font-mono`,title:l?.caFingerprintSha256??void 0,children:Ze(l?.caFingerprintSha256??null)})]})]}),l&&l.sans.length>0&&s(`div`,{className:`flex flex-wrap gap-1`,children:l.sans.map(e=>s(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),n(`div`,{className:`flex flex-wrap gap-2`,children:[s(A,{label:`Regenerate`,title:`Issue a new leaf?`,description:`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`,confirmLabel:`Regenerate`,disabled:l?.mode===`uploaded`||r.isPending,action:()=>r.mutateAsync({})}),s(w,{size:`sm`,variant:`outline`,onClick:()=>d(e=>!e),children:`Upload`}),l?.caCertPem&&s(w,{size:`sm`,variant:`outline`,onClick:S,children:`Download CA`}),l?.mode===`uploaded`&&s(A,{label:`Revert to generated`,title:`Drop the uploaded certificate?`,description:`Deletes the uploaded pair and returns to the generated local CA.`,confirmLabel:`Revert`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({})})]}),u&&n(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Certificate PEM`,s(`textarea`,{value:p,onChange:e=>m(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`Private key PEM`,s(`textarea`,{value:h,onChange:e=>_(e.target.value),rows:6,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),n(`label`,{className:`block text-[11px] text-foreground-subtle`,children:[`CA PEM (optional)`,s(`textarea`,{value:y,onChange:e=>x(e.target.value),rows:4,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`})]}),s(w,{size:`sm`,disabled:!p.trim()||!h.trim()||c.isPending,onClick:()=>c.mutate({certPem:p,keyPem:h,...y.trim()?{caPem:y}:{}}),children:`Save certificate`}),c.isError&&s(`p`,{className:`text-xs text-danger`,children:c.error instanceof Error?c.error.message:`Upload failed`})]})]})]})}function $e(){return s(`div`,{className:`flex flex-col p-4`,children:s(ge,{defaultTab:`addresses`,tabs:[{id:`local-access`,label:`Local access`,icon:V,content:s(Qe,{})},{id:`addresses`,label:`Network Addresses`,icon:R,content:s(Ie,{})},{id:`remote-access`,label:`Remote Access`,icon:U,content:s(Se,{})},{id:`mesh`,label:`Mesh Networks`,icon:F,content:s(Be,{})},{id:`turn`,label:`TURN Servers`,icon:q,content:s(Oe,{})}]})})}export{$e as NetworkPage};
@@ -1 +0,0 @@
1
- import{K as e,Q as t,S as n,T as r,W as i,b as a,i as o,o as s,p as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Q as f}from"./player-overlays-RwoCa548.js";import{$a as p,Aa as m,Bs as h,Bt as g,Fa as _,Hs as v,Ht as y,Ia as b,J as x,Ja as S,Ka as C,Lt as w,Ma as T,Na as E,Oa as D,Pa as O,Qa as ee,Ra as te,Rs as k,Ua as A,Ut as j,V as M,Va as N,Vs as P,Vt as ne,Wa as F,Xa as I,Yt as L,Za as re,_n as ie,b as ae,bn as oe,co as R,d as se,do as ce,eo as le,et as z,gn as ue,h as de,ia as B,ja as fe,ka as pe,lo as me,oo as he,qa as ge,r as _e,so as ve,to as ye,u as be,un as xe,zs as Se,zt as Ce}from"./src-CDVm70oc.js";import{n as we}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{Bt as Te,Vt as Ee,f as De,h as Oe,p as ke}from"./src-ijaeX4aR.js";import{a as Ae,i as je,l as Me,n as V,o as Ne,r as Pe,t as Fe,u as Ie}from"./NodeInferenceDevices-BaRmgURr.js";import{t as Le}from"./layers-B7No2bw_.js";import{n as Re,t as ze}from"./video-DIbJOXgM.js";import{t as Be}from"./pencil-BJxboIbx.js";import{t as Ve}from"./plus-Brv4i72u.js";import{t as He}from"./radio-klp_ubdd.js";import{t as Ue}from"./refresh-cw-OR1QZ198.js";import{t as We}from"./server-BXgYajYr.js";import{t as Ge}from"./square-check-big-hQzwD37R.js";import{t as Ke}from"./square-Dd2LMGtj.js";import{t as qe}from"./zap-Dnw48_IY.js";import{C as Je,D as Ye,E as Xe,F as Ze,I as Qe,K as $e,N as H,O as et,R as tt,X as nt,a as rt,i as it,o as at,r as ot,z as st}from"./index-BTGQKEEA.js";import"./useEventInvalidation-D4KUD_Rr.js";import{t as ct}from"./NodeAddonsSettingsPanel-DvTRBvQl.js";var lt=$e(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ut=$e(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),dt=$e(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);t();function ft(e){return e}function pt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function mt(e,t){return typeof e==`boolean`?e:ft(t)}function ht(e,t){return{pipeline:mt(pt(e,`detect`),t),audio:mt(pt(e,`audio`),t),ingest:mt(pt(e,`ingest`),t)}}function gt(e,t,n){let r=e?.find(e=>e.nodeId===t);return ht(r?.settings,n)}function _t(e){if(e==null)return null;if(typeof e==`number`)return e>0?e:null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function vt({selectedNodeId:e,onSelect:t,refreshToken:r}){let{data:i}=B(void 0),{data:o}=A(void 0),{data:s}=C(void 0),c=new Map;for(let e of o??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],d=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return n(`div`,{className:`flex flex-col h-full`,children:[n(`button`,{type:`button`,onClick:()=>t(Fr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[u(Xe,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[u(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(r=>{let i=e===r.id,o=c.get(r.id)??0,l=r.isHub?We:H,d=gt(s,r.id,r.isHub),f=r.isOnline?null:M(_t(r.lastSeen));return n(`button`,{type:`button`,onClick:()=>t(r.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${r.isOnline?``:` opacity-60`}`,children:[u(l,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),n(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[n(`span`,{children:[r.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),o>0&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[u(ze,{className:`h-2.5 w-2.5`}),o]})]}),!r.isOnline&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`text-destructive`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),n(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[u(w,{variant:d.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),u(w,{variant:d.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},r.id)})}),n(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[n(`span`,{children:[d,` online`]}),f>0&&n(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function yt({nodeId:e,refreshToken:t}){let{data:r}=B(void 0),i=r?.find(t=>t.id===e),o=Se(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?n(`div`,{className:`px-6 py-4 border-b border-border`,children:[n(`div`,{className:`flex items-center gap-2 mb-1`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),i.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[u(`span`,{children:i.cpuModel??`CPU`}),u(`span`,{children:`•`}),n(`span`,{children:[i.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),o&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{children:[o.attachedCameras,` cameras (`,o.activeCameras,` active)`]}),u(`span`,{children:`•`}),n(`span`,{children:[o.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),u(`span`,{children:`•`}),n(`span`,{children:[`queue `,o.queueDepthTotal]}),o.hardware.hasGpu&&n(a,{children:[u(`span`,{children:`•`}),u(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):u(`div`,{className:`px-6 py-4 border-b border-border`,children:n(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function bt({refreshToken:e,nodeId:t}){let[r,a]=l(new Map),{nodes:o}=k();P(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&a(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=b(void 0),c=i(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),d=i(()=>{let e=new Map,t=Date.now()-3e4;for(let n of r.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[r]),f=i(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=i(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of d.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[d,o]);if(t){let e=d.get(t);return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[u(U,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),u(U,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),u(U,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),u(U,{label:`Queue`,value:e?String(e.queueDepth):`—`}),u(U,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...d.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[u(U,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),u(U,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),u(U,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),u(U,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),u(U,{label:`Queue depth`,value:String(p.queueDepth)})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[480px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),u(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),u(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),u(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),u(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),u(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),n(`tbody`,{children:[m.map(([e,t])=>n(`tr`,{className:`border-t border-border`,children:[u(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&u(`tr`,{children:u(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function U({label:e,value:t}){return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[u(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),u(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}t();var xt={active:!1,pinned:!1,nodeId:null,reason:``},St=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],Ct=3e5,wt={pipeline:H,decoder:et,audio:Re},Tt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function Et({mode:e,nodeId:t,compact:o=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let c=s(),[f,p]=l(null),[m,h]=l(null),[g,v]=l(new Map);_e([`pipelineOrchestrator`,`getPipelineAssignments`],St),_e([`pipelineOrchestrator`,`getAudioAssignments`],St),_e([`pipelineOrchestrator`,`getCameraStatuses`],St);let{data:y}=A(void 0),{data:b}=_(void 0),{data:x}=te({},{enabled:e===`agent`}),{nodes:S}=k(),{data:C}=Me();P(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&v(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),d(()=>{if(g.size===0)return;let e=setInterval(()=>{v(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[g.size]);let w=i(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),E=i(()=>{if(e===`agent`){let e=[];for(let n of x??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:w.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:w.get(e)??`Device ${e}`,pipeline:xt,decoder:xt,audio:xt};return n.set(e,r),r};for(let i of y??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of b??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[y,b,x,w,e,t]),D=i(()=>(S??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[S]),O=()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},ee=T({onSuccess:O}),j=R({onSuccess:O}),M=fe({onSuccess:O}),N=ve({onSuccess:O}),ne=(e,t,n)=>{t===`pipeline`?ee.mutate({deviceId:e,agentNodeId:n}):M.mutate({deviceId:e,nodeId:n}),p(null)},F=(e,t)=>{t===`pipeline`?j.mutate({deviceId:e}):N.mutate({deviceId:e}),p(null)};return u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!o&&u(`th`,{className:`w-10`}),u(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?n(a,{children:[u(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),u(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):n(a,{children:[u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),u(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),n(`tbody`,{children:[E.map(t=>{let i=g.get(t.deviceId),s=m===t.deviceId;return n(r.Fragment,{children:[n(`tr`,{className:`border-t border-border align-middle relative`,children:[!o&&u(`td`,{className:`px-2 py-2 align-middle`,children:u(`button`,{type:`button`,onClick:()=>h(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:u(s?tt:Qe,{className:`h-3.5 w-3.5`})})}),n(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[u(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?n(a,{children:[u(`td`,{className:`px-3 py-2 align-middle`,children:u(Ot,{state:t.pipeline,onlineNodes:D,pending:ee.isPending||j.isPending,onChange:e=>{e===`auto`?F(t.deviceId,`pipeline`):ne(t.deviceId,`pipeline`,e)}})}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(At,{state:t.pipeline,deviceId:t.deviceId})})]}):n(a,{children:[u(Mt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`pipeline`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>p(null),onMove:e=>ne(t.deviceId,`pipeline`,e),onUnpin:()=>F(t.deviceId,`pipeline`)}),u(Mt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:D,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),u(Mt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`audio`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>p(null),onMove:e=>ne(t.deviceId,`audio`,e),onUnpin:()=>F(t.deviceId,`audio`)})]}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(It,{snap:i})})]}),s&&!o&&n(`tr`,{className:`bg-surface/50`,children:[u(`td`,{}),n(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&u(Dt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),u(L,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),E.length===0&&u(`tr`,{children:u(`td`,{colSpan:o?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function Dt({deviceId:e,nodeId:t}){let r=s(),{data:i}=N({nodeId:t}),{data:a}=F({deviceId:e}),o=he({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),c=i?.devices??[],l=a?.deviceKey??`auto`,d=l!==`auto`&&!c.some(e=>e.key===l);return n(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),n(`select`,{value:l,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),d&&n(`option`,{value:l,children:[`Pin → `,l,` (not on this node)`]}),c.map(e=>n(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&u(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function Ot({state:e,onlineNodes:t,pending:r,onChange:i}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return n(`select`,{value:a,disabled:r,"aria-label":`Pipeline placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[u(`option`,{value:`auto`,children:`Auto`}),o.map(e=>n(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function kt(t){let n=e(null);return t.nodeId!==null&&(n.current=t),n.current}function At({state:e,deviceId:t}){let r=kt(e),i=e.active&&e.nodeId!==null;if(r===null||r.nodeId===null)return u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`— · no session yet`});let a=r.pinned?`pinned · manual`:`auto · ${r.reason||`capacity`}`;return n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] truncate ${i?`text-foreground`:`text-foreground-subtle`}`,title:r.pinned?r.nodeId:`${r.nodeId} — an unpinned camera is re-elected per on-motion session, so this can change between sessions`,children:r.nodeId}),u(`span`,{className:`truncate ${r.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:a,children:a}),u(`span`,{className:`truncate text-[10px] ${i?`text-emerald-400`:`text-foreground-subtle/70`}`,children:i?`● running here`:`○ idle · last session here`}),u(jt,{deviceId:t,nodeId:r.nodeId})]})}function jt({deviceId:e,nodeId:t}){let r=s(),{data:i}=F({deviceId:e},{refetchOnMount:`always`}),{data:a}=N({nodeId:t},{staleTime:Ct}),o=he({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return u(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let c=a.devices??[],l=c.filter(e=>e.enabled),d=i.deviceKey??`auto`,f=d!==`auto`&&!l.some(e=>e.key===d),p=c.find(e=>e.key===d);return n(`select`,{value:d,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),f&&n(`option`,{value:d,children:[p?`${V(p).label} (${d})`:d,` (not enabled)`]}),l.map(e=>n(`option`,{value:e.key,children:[V(e).label,` · `,e.format]},e.key))]})}function Mt({role:e,state:t,mode:r,onlineNodes:i,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:l,onUnpin:d}){let f=wt[e],p=i.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||r===`cluster`)&&(p.length>0||t.pinned);return n(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[u(r===`agent`?Nt:Pt,{state:t,Icon:f}),u(`div`,{className:`ml-auto shrink-0`,children:m&&u(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${Tt[e]} actions`,children:u(lt,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&u(Lt,{title:Tt[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:d,onClose:c})]})}function Nt({state:e,Icon:t}){return n(`div`,{className:`flex items-center gap-1.5`,children:[u(e.active?Ge:Ke,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),u(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&u(dt,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Pt({state:e,Icon:t}){return!e.active||!e.nodeId?n(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[u(t,{className:`h-3 w-3`}),u(`span`,{className:`text-[10px] italic`,children:`—`})]}):n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),u(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?n(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[u(dt,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Ft=`min-h-[3.25rem]`;function It({snap:e}){if(!e)return u(`div`,{className:`flex items-center ${Ft}`,children:u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:r,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=z(t);return n(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Ft}`,children:[n(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[u(de,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:r.toFixed(1)}),n(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:i.toFixed(0)}),u(`span`,{children:` ms`}),a>0&&n(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),n(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,u(`span`,{className:`text-foreground`,children:s})]})]})}function Lt({title:t,targets:r,pinned:i,onMove:a,onUnpin:o,onClose:s}){let c=e(null);return d(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),n(`div`,{ref:c,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[u(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:t}),r.length>0&&u(`div`,{className:`py-1`,children:r.map(e=>n(`button`,{type:`button`,onClick:()=>a(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),i&&n(`button`,{type:`button`,onClick:o,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,t.toLowerCase()]}),r.length===0&&!i&&u(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Rt({nodeId:e,refreshToken:t}){return n(`div`,{className:`space-y-6`,children:[u(bt,{refreshToken:t,nodeId:e}),n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),u(Et,{mode:`agent`,nodeId:e,compact:!0})]})}t();function zt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Bt({nodeId:e,refreshToken:t}){let r=s(),a=pe({onSettled:()=>{r.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=m({nodeId:e}),c=Se(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,l=c===null;_e([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:d}=ce({nodeId:e}),{values:f}=h(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),p=i(()=>f.filter(e=>e.metrics.phase===`active`).length,[f]),g=t=>{let n=d??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||a.mutate({nodeId:e,engine:t,force:n.length>0})};return n(`div`,{className:`space-y-6`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(c??[]).length,` engine(s) resident in RAM. `,(d??[]).length,` `,`camera(s) attached, `,p,` actively dispatching frames. Refreshes every 5s.`]})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),u(`th`,{className:`text-left px-3 py-2`,children:`Models`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),u(`th`,{className:`w-20`})]})}),n(`tbody`,{children:[l&&u(`tr`,{children:u(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!l&&(c??[]).map(e=>{let t=e.kind===`warm-override`,r=e.kind===`device-pool`;return n(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:r?`bg-primary/[0.05]`:``}`,children:[u(`td`,{className:`px-3 py-2`,children:n(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:r?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[u(t?ut:r?Le:H,{className:`h-3 w-3`}),t?`warm`:r?`pool`:`runtime`]})}),u(`td`,{className:`px-3 py-2`,children:n(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[u(qe,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),u(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?u(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>u(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),u(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),u(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?u(`span`,{className:`text-foreground-subtle`,children:zt(e.idleMs,e.idleTtlMs)}):u(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(d??[]).length}),u(`td`,{className:`px-3 py-2 text-right`,children:r?u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):n(`button`,{type:`button`,disabled:a.isPending,onClick:()=>g(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[u(at,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!l&&(c??[]).length===0&&u(`tr`,{children:u(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[u(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,u(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,u(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),a.isError&&n(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,a.error instanceof Error?a.error.message:`unknown`]})]})}var Vt=`pipeline-runner`,Ht=200;function Ut({nodeId:e}){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(x,{agentId:e,addonId:Vt,limit:Ht,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t(),t();function Wt({nodeId:e,title:t}){let{data:r}=Me(),{data:a}=A(void 0),o=i(()=>{let e=new Map;for(let t of r??[])e.set(t.id,t.name);return e},[r]),s=i(()=>{if(!e)return null;let t=new Set;for(let n of a??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,a]),[c,f]=l(new Map);P(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||f(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),d(()=>{if(c.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let p=i(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return p.length===0?n(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):n(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[n(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:p.length})]}),u(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,r=z(e.metrics.phase);return n(`div`,{title:`${t} · ${r.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${r.badgeClass}`,children:[u(de,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),u(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),u(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),u(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var Gt=`pipeline-orchestrator`;function Kt(e){return De.find(t=>t.stepId===e)??null}function qt({title:e}){return u(`span`,{title:e??`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`ml-1 rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`})}function Jt({step:e,engineFormat:t,runnableModelIds:r}){let i=s(),{data:a,isLoading:o}=ie({addonId:Gt}),c=oe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),l=Oe(a??null)[e.stepId]??e.defaultModelId,d=r.length>0&&!r.includes(l);return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[n(`div`,{className:`flex items-center text-[11px] font-medium text-foreground`,children:[e.label,u(qt,{})]}),n(`p`,{className:`mt-1 text-[10px] leading-snug text-foreground-subtle`,children:[`Applies to every node. Changing it does not corrupt `,e.indexName,` — every vector carries the model that produced it and only matches its own — but it STRANDS it: the existing vectors stay readable and match nothing until a re-embed pass has run.`]})]}),o?u(Je,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):u(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,disabled:c.isPending,onChange:t=>{t.target.value!==l&&c.mutate({addonId:Gt,patch:{[ke(e.stepId)]:t.target.value}})},children:e.options.map(t=>n(`option`,{value:t.id,children:[t.label,t.id===e.defaultModelId?` (default)`:``]},t.id))}),d&&n(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[10px] leading-snug text-amber-300`,children:[`This node's engine (`,t,`) ships no build of `,u(`b`,{children:l}),`. It will REFUSE this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`. Either pick a model with a `,t,` build, or accept that this node contributes nothing to that index.`]}),u(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Stored once, in Pipeline → Cluster → Settings → Enrichment models. This editor writes that same row — there is no per-node copy of this value. Step knobs for this encoder (minimum face size, …) live on that same settings page.`})]})}t();function W(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Yt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function Xt({nodeId:e,refreshToken:t}){let r=s(),[o,c]=l(null),[d,f]=l(null),[p,m]=l(``),[h,_]=l(null),v=N({nodeId:e},{refetchOnMount:`always`}),b=D({nodeId:e},{refetchOnMount:`always`}),x=Oe(ie({addonId:`pipeline-orchestrator`}).data??null),S=v.data?.devices??[],C=le({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),w=i(()=>b.data?be(b.data):[],[b.data]),T=i(()=>S.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:V(t).label})),[S,e]),E=e=>S.find(t=>t.key===e)??null,O=i(()=>S.filter(e=>e.enabled),[S]),ee=O.length>=2,te=(e,t)=>y(W(b.data??null,e)?.models??[],t?.format),k=e=>{let t=E(e);return t?V(t).label:e},A=(e,t)=>O.filter(n=>n.key!==t&&te(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,M=e=>{let t=W(b.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},P=(e,t)=>{let n=W(b.data??null,e);if(n)return g(n,t)},F=(e,t)=>{let n=M(e),r=n.kind===`gate`?n.effectiveOn:!1,i=W(b.data??null,e),a=t.deviceKey===void 0?null:E(t.deviceKey),o=y(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&O.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:A(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:k(i)}}let c=Kt(e);return c?{kind:`enabled`,modelId:x[e]??c.defaultModelId,clusterWide:!0}:{kind:`enabled`,modelId:(i?ne({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&O.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:k(s.jumpDeviceKey)}:{}}},I=o&&b.data?W(b.data,o.addonId):null,L=o?E(o.deviceKey):null,re=L?.format??`coreml`,oe=o?P(o.addonId,L):void 0,R=()=>{c(null),f(null),m(``)},ce=(e,t)=>{if(t.deviceKey===void 0)return;let n=E(t.deviceKey)?.steps?.[e];c({addonId:e,deviceKey:t.deviceKey});let r=n?.settings??Ae(S.map(e=>({key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}})),t.deviceKey,e)??{};f({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:r}),m(n?.jumpDeviceKey??``)},z=()=>{if(!o)return;let t=Yt(d),n=p!==``&&p!==o.deviceKey?p:void 0,r=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,i=S.map(e=>{let t={...e.steps};return e.key===o.deviceKey&&(r?t[o.addonId]=r:delete t[o.addonId]),{key:e.key,enabled:e.key===o.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}}),a=r?.settings!==void 0&&Object.keys(r.settings).length>0?Ne(i,o.deviceKey,o.addonId):i;C.mutate({agentNodeId:e,inferenceDevices:je(a)},{onSuccess:R})};if(v.isLoading||b.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(S.length===0)return u(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!b.data)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ue=o!==null&&I!==null&&L!==null;return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,u(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),u(`div`,{className:ue?`md:pr-[360px]`:``,children:w.length>0?u(ae,{tree:w,agents:T,gateFor:M,getCellState:F,onCellClick:ce,selectedCell:o?{addonId:o.addonId,agentNodeId:e,deviceKey:o.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:h,onFallbackNodeChange:_,hideGate:!0}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(se,{open:ue,onClose:R,title:I?.name??``,subtitle:o&&L?`${e} · ${V(L).label} · ${L.format}`:``,footer:n(a,{children:[u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:R,children:`Cancel`}),u(`button`,{type:`button`,disabled:!o||!d||C.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:z,children:C.isPending?`Saving…`:`Save`})]}),children:I&&o&&Kt(o.addonId)?u(Jt,{step:Kt(o.addonId),engineFormat:re,runnableModelIds:j(I.models??[],re).map(e=>e.id)}):I&&o&&d?n(`div`,{className:`space-y-3`,children:[ee&&n(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[u(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),n(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:p,onChange:e=>m(e.target.value),children:[u(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),O.filter(e=>e.key!==o.deviceKey).map(e=>n(`option`,{value:e.key,children:[V(e).label,` · `,e.format]},e.key))]}),u(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),u(Ce,{mode:`agent`,addon:I,agentDefault:d,agentNodeId:e,engineFormat:re,effectiveModelId:oe,onChangeAgentConfig:f})]}):u(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}t();var Zt=!1;function Qt({nodeId:e,refreshToken:t}){let r=xe(),[i,a]=l(null),[o,s]=l(null),c=(B(void 0).data??[]).find(t=>t.id===e),d=c?.name??e,f=c?.isOnline??!1,p=I({onSuccess:e=>{s(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),m=async()=>{await r({title:`Reset ${d} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(s(null),p.mutate({agentNodeId:e}))};return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&u(`span`,{className:`text-emerald-400`,children:o}),p.isError&&u(`span`,{className:`text-red-400`,children:p.error instanceof Error?p.error.message:`Reset failed`}),u(`button`,{type:`button`,onClick:()=>{m()},disabled:p.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:p.isPending?`Resetting…`:`Reset to default`})]}),u(Wt,{nodeId:e}),Zt,Zt,n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),u(Fe,{nodeId:e,nodeName:d,isOnline:f})]}),n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),u(Xt,{nodeId:e,refreshToken:t})]})]})}var $t=[`assignments`,`tree`,`engines`,`logs`],en=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],tn=`decoder-nodeav`;function nn({nodeId:e,refreshToken:t}){let{data:r}=B(void 0),i=r?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??tn,a=[...en,i],o={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:u(Rt,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:u(Qt,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:u(Bt,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:u(Ut,{nodeId:e})}},s=$t.map(e=>o[e]);return n(`div`,{className:`flex flex-col h-full`,children:[u(yt,{nodeId:e,refreshToken:t}),u(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:u(ct,{nodeId:e,addonIds:a,level:`global`,extraTabs:s})})]})}function rn(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?`CPU`:t===`openvino`&&n===`npu`?`Intel NPU`:t===`openvino`&&(n===`gpu`||n===`igpu`)?`Intel iGPU`:t===`edgetpu`?`Coral Edge TPU`:t===`coreml`?`Apple ANE`:`${e.backend} ${e.device}`.trim()}var an={disabled:`switched off — not a dispatch target`,unavailable:`the node probe does not see it (unplugged or still provisioning)`,"cannot-host-camera-root":`its engine format has no object-detection root model`,"accelerator-preferred":`CPU fallback — it never competes while an accelerator is serving`};function G(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function on(e,t){let n=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let r=t.get(e.key),i=r?.sessions??0,a=e.weight>0?e.weight:1;return{key:e.key,label:rn(e),format:e.format,sessions:i,queueDepth:r?.queueDepth??0,weight:a,weightSharePct:e.exclusion===null?G(a,n):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function sn(e){let t=new Map(e.loads.map(e=>[e.nodeId,e])),n=e.nodes.filter(e=>e.isOnline&&e.detectEnabled).reduce((e,t)=>e+(t.weight>0?t.weight:1),0),r=e.loads.reduce((e,t)=>e+t.load.attachedCameras,0);return e.nodes.map(i=>{let a=t.get(i.id),o=on(e.devicesByNode[i.id]??[],new Map((a?.load.devices??[]).map(e=>[e.deviceKey,{sessions:e.attachedCameras,queueDepth:e.queueDepthTotal}]))),s=i.isOnline&&i.detectEnabled,c=i.weight>0?i.weight:1,l=a?.load.attachedCameras??null;return{nodeId:i.id,name:i.name,isOnline:i.isOnline,detectEnabled:i.detectEnabled,reported:a!==void 0,attachedCameras:l,activeCameras:a?.load.activeCameras??null,maxCameras:i.maxCameras,capacityPct:l!==null&&i.maxCameras!==null&&i.maxCameras>0?G(l,i.maxCameras):null,queueDepthTotal:a?.load.queueDepthTotal??null,avgInferenceTimeMs:a?.load.avgInferenceTimeMs??null,score:a?.score??null,weight:c,weightSharePct:s?G(c,n):null,cameraSharePct:l===null?null:G(l,r),decodeHwaccel:a?.decodeHwaccel??null,devices:o,eligibleDeviceCount:o.filter(e=>e.exclusion===null).length}})}var cn=`pipeline-orchestrator`,ln=`recorder`,un=`recordingNodeId`,dn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],fn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function pn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function mn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function K(e,t,n){let r=pn(e,t);return typeof r==`string`&&r.length>0?r:n}function hn(e,t,n){let r=pn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function q(e,t){let n=mn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function gn(e,t){let n=mn(e,t);return typeof n==`string`&&n.length>0?n:null}function _n(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function vn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function yn(e,t){switch(t){case`detect`:return e.pipeline}}function bn(e){return e instanceof Error?e.message:`Failed to save`}function xn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}t();var Sn=2e4,Cn=3e5;function wn(){let{nodes:e}=k(),t=f().trpcClient,r=O(void 0,{placeholderData:c,staleTime:Sn,refetchInterval:Sn,refetchOnWindowFocus:!0}),a=C(void 0,{staleTime:Cn}),s=i(()=>e.map(e=>e.id),[e]),l=o({queries:s.map(e=>({queryKey:we(v.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>t.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Cn,refetchOnWindowFocus:!1,placeholderData:c}))}),d=i(()=>{let e={};return s.forEach((t,n)=>{let r=l[n]?.data;r&&(e[t]=r.devices)}),e},[s,l.map(e=>e.dataUpdatedAt).join(`|`)]),p=i(()=>{let e=new Map;for(let t of a.data??[])e.set(t.nodeId,t.settings);return e},[a.data]),m=i(()=>e.map(e=>{let t=p.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:ht(t,e.isHub).pipeline,weight:q(t,`detectWeight`)??1,maxCameras:q(t,`maxCameras`)}}),[e,p]),h=r.data??[],g=i(()=>sn({nodes:m,loads:h,devicesByNode:d}),[m,h,d]),_=g.reduce((e,t)=>e+(t.attachedCameras??0),0),y=g.reduce((e,t)=>e+(t.activeCameras??0),0),b=r.dataUpdatedAt>0?Date.now()-r.dataUpdatedAt:null;return n(`section`,{className:`rounded-md border border-border bg-surface px-3 py-2.5`,children:[n(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 mb-2`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Node load`}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[y,` running · `,_,` attached across `,g.length,` `,g.length===1?`node`:`nodes`]}),u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle/70 tabular-nums`,children:r.data===void 0?`reading…`:`reading ${b===null?`—`:`${Math.round(b/1e3)}s`} old · every ${Sn/1e3}s`})]}),g.length===0?u(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):u(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:g.map(e=>u(Tn,{row:e},e.nodeId))})]})}function Tn({row:e}){let t=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),u(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&u(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&n(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[u(rt,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&n(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[u(it,{className:`h-2.5 w-2.5`}),` offline`]})]}),n(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[u(J,{label:`Running / attached`,value:t,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),u(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`detectWeight normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),u(J,{label:`Actual share`,value:e.cameraSharePct===null?`—`:`${e.cameraSharePct}%`,title:`Share of the cluster's attached cameras this node carries right now.`}),u(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&u(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&u(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&u(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),u(En,{row:e})]})}function En({row:e}){return e.devices.length===0?u(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):n(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[n(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[u(Ye,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&u(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),u(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>u(Dn,{device:e},e.key))})]})}function Dn({device:e}){let t=e.exclusion;return n(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[u(H,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),u(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?n(a,{children:[n(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),n(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[`· `,e.sessions,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.queueDepth>0&&n(`span`,{className:`shrink-0 tabular-nums text-amber-400`,children:[`· q`,e.queueDepth]}),e.atCap&&u(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):n(`span`,{className:`truncate text-foreground-subtle/80`,title:an[t],children:[`excluded — `,an[t]]})]})}function J({label:e,value:t,title:r}){return n(`div`,{className:`min-w-0`,title:r,children:[u(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function On(){return n(`div`,{className:`space-y-6`,children:[u(Wt,{title:`Cluster cameras`}),u(wn,{}),n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),u(Et,{mode:`cluster`})]})}function kn({capability:e,label:t,hint:r,nodeId:i,active:a,pending:o,layout:s,onToggle:c}){let l=a?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,d=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,f=a?st:Ie;return n(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${i}`,title:`${t} — ${r}`,disabled:o,onClick:()=>c(e,!a),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${l} ${d}`,children:[u(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),u(`span`,{children:t})]})}function An({node:e,emphasis:t=!1}){let r=e.isHub?We:H;return n(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[u(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),u(r,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[u(`span`,{className:`truncate`,children:e.name}),e.isHub&&u(w,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&u(w,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),u(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}t();function jn({nodeId:e,value:t,detectedHosts:r,status:i,errorMessage:a,onCommit:o}){let[s,c]=l(t??``);d(()=>{c(t??``)},[t]);let f=r[0],p=f===void 0?`auto-detect`:`auto: ${f}`,m=i===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return n(`div`,{className:`flex items-center gap-1.5`,children:[u(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:p,value:s,disabled:m,onChange:e=>c(e.target.value),onBlur:v,onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&c(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),n(`button`,{type:`button`,onClick:v,disabled:!_,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[m?u(Je,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(st,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&i===`success`&&u(st,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&u(`span`,{title:a??`Failed to save reachable host`,children:u(Ze,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}function Mn({label:e,children:t}){return n(`div`,{className:`flex items-center justify-between gap-3`,children:[u(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Nn({node:e,actions:t}){return n(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[u(An,{node:e,emphasis:!0}),u(`div`,{className:`grid grid-cols-2 gap-2`,children:fn.map(n=>u(kn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:yn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),u(`div`,{className:`space-y-3 border-t border-border pt-3`,children:u(Mn,{label:`Reachable host`,children:u(jn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function Pn(){return n(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Fn({nodes:e,actions:t}){return u(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:n(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[u(`thead`,{children:n(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),fn.map(e=>u(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),u(`tbody`,{children:e.map(e=>n(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[u(`td`,{className:`px-4 py-3 align-middle`,children:u(An,{node:e})}),fn.map(n=>u(`td`,{className:`px-3 py-3 text-center align-middle`,children:u(kn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:yn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),u(`td`,{className:`px-4 py-3 align-middle`,children:u(jn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function In({role:e,value:t,options:r,pending:i,onChange:a}){return n(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[u(`span`,{className:`text-xs font-semibold text-foreground`,children:_n(e)}),u(`select`,{value:t,disabled:i,onChange:t=>a(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:r.map(e=>u(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),u(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:vn(e)})]})}function Ln({roleValues:e,options:t,pending:r,lowFpsEnabled:i,fpsMinThreshold:a,onRoleChange:o,onLowFpsToggle:s}){return n(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[dn.map(n=>u(In,{role:n,value:e[n],options:t,pending:r,onChange:o},n)),n(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[u(`input`,{type:`checkbox`,checked:i,disabled:r,onChange:e=>s(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),n(`span`,{className:`flex flex-col gap-0.5`,children:[u(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),n(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,i?`${a} fps`:`disabled`]})]})]})]})}t();function Rn(){let e=s(),{nodes:t}=k(),r=C(void 0),o=ie({addonId:cn}),c=ie({addonId:ln}),d=()=>xn(e),f=ee({onSuccess:d}),m=p(),h=ye({onSuccess:d}),g=oe({onSuccess:d}),[_,v]=l(!1),y=i(()=>{let e=new Map;for(let t of r.data??[])e.set(t.nodeId,t.settings);return e},[r.data]),b=i(()=>t.map(e=>{let t=y.get(e.id),n=ht(t,e.isHub),r=q(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:q(t,`maxCameras`),reachableHost:gn(t,`reachableHost`),detectedHosts:e.localIps}}),[t,y]),x=b.filter(e=>e.effective.pipeline),S={ingestNode:K(o.data,`ingestNode`,`hub`),recordingNode:K(c.data,un,`hub`),audioNode:K(o.data,`audioNode`,`hub`),motionNode:K(o.data,`motionNode`,`hub`)},w=i(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...dn.map(e=>S[e]),...e])].filter(e=>e.length>0)},[t,S]),T=hn(o.data,`fpsMinThreshold`,0),E=T>0,D=r.isLoading||o.isLoading||c.isLoading,O=(e,t,n)=>{f.mutate({agentNodeId:e,[t]:n})},te=(e,t)=>{if(e===`recordingNode`){g.mutate({addonId:ln,patch:{[un]:t}});return}g.mutate({addonId:cn,patch:{[e]:t}})},A=e=>{g.mutate({addonId:cn,patch:{fpsMinThreshold:e?Math.max(1,T):0}})},j=e=>h.variables?.agentNodeId===e?h.isPending?`pending`:h.isError?`error`:h.isSuccess?`success`:`idle`:`idle`,M=e=>j(e)===`error`?bn(h.error):null,N=async e=>{v(!0);try{for(let t of e)await m.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{v(!1),d()}},P={capabilityPending:f.isPending,onToggleCapability:O,onCommitReachableHost:(e,t)=>h.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:j,reachableHostErrorMessage:M};return n(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[n(`header`,{className:`flex items-start justify-between gap-4`,children:[n(`div`,{className:`space-y-1`,children:[u(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),u(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),D&&u(Je,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),u(Ln,{roleValues:S,options:w,pending:g.isPending,lowFpsEnabled:E,fpsMinThreshold:T,onRoleChange:te,onLowFpsToggle:A})]}),n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),u(Pn,{})]}),b.length===0?u(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):n(a,{children:[u(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:b.map(e=>u(Nn,{node:e,actions:P},e.id))}),u(`div`,{className:`hidden @3xl/clustertab:block`,children:u(Fn,{nodes:b,actions:P})})]})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),u(Pe,{nodes:x,pending:_,onCommitWeights:e=>void N(e)})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),x.length===0?u(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):u(`div`,{className:`space-y-2`,children:x.map(e=>u(Fe,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}t(),t(),t(),t();function zn(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Bn(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:zn(t)}}function Vn(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,lastSeen:e.lastSeen,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Bn)}}function Hn(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Vn),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}t();var Un=!1;function Wn({refreshToken:e}){let t=s(),{data:r}=B(void 0);i(()=>Hn(r??[]),[r]);let a=S({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return n(`div`,{className:`space-y-6`,children:[u(bt,{refreshToken:e}),u(Rn,{}),Un,n(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),n(`button`,{type:`button`,onClick:()=>a.mutate(void 0),disabled:a.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[u(qe,{className:`h-3.5 w-3.5`}),a.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var Gn=[`pipeline-orchestrator`],Kn=`pipeline-analytics`,qn=`face-gallery`;function Jn({refreshToken:e}){return n(`div`,{className:`space-y-4 max-w-3xl`,children:[u(ct,{nodeId:`hub`,addonIds:Gn,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer, failover, enrichment models, and the admission settings those models share. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`}),u(ct,{nodeId:`hub`,addonIds:[Kn],level:`global`,capability:qn,title:`Face recognition`,description:`Match threshold, ambiguity margin, and auto-assign floors. Same settings as System → Settings → pipeline-analytics — this page asks the face-gallery cap, it does not store a second copy.`})]})}t();function Yn({refreshToken:e}){let t=s(),{data:r,isLoading:i}=ge(),[o,c]=l(null),[d,f]=l(``),[p,m]=l(``),h=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},g=me({onSuccess:()=>{c(null),h()}}),_=E({onSuccess:h}),v=e=>{c(e.id),f(e.name),m(e.description??``)},y=()=>{c(null),f(``),m(``)},b=()=>{if(!o)return;let e=p.trim();g.mutate({id:o,name:d.trim()||`Untitled`,...e?{description:e}:{}})};if(i)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let x=[...r??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return u(`div`,{className:`space-y-6 max-w-4xl`,children:n(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),u(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[x.length,` template`,x.length===1?``:`s`]})]}),x.length===0?n(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[u(Ve,{className:`h-6 w-6 opacity-40`}),u(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):u(`ul`,{className:`divide-y divide-border`,children:x.map(e=>{let t=o===e.id;return u(`li`,{className:`px-4 py-3 text-xs`,children:n(`div`,{className:`flex items-start gap-3`,children:[u(`div`,{className:`flex-1 min-w-0`,children:t?n(`div`,{className:`space-y-2`,children:[u(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:d,onChange:e=>f(e.target.value),placeholder:`Template name`,autoFocus:!0}),u(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:p,onChange:e=>m(e.target.value),placeholder:`Description (optional)`})]}):n(a,{children:[u(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&u(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),n(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,n(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),u(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?n(a,{children:[n(`button`,{type:`button`,onClick:b,disabled:g.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[u(st,{className:`h-3 w-3`}),`Save`]}),n(`button`,{type:`button`,onClick:y,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[u(ot,{className:`h-3 w-3`}),`Cancel`]})]}):n(a,{children:[u(`button`,{type:`button`,onClick:()=>v(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:u(Be,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&_.mutate({id:e.id})},disabled:_.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:u(at,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var Xn=`pipeline-orchestrator`,Zn=200;function Qn(){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(x,{addonId:Xn,limit:Zn,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t();var $n=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function er({refreshToken:e}){let[t,r]=l(`assignments`);return n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),u(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),u(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:$n.map(e=>u(`button`,{type:`button`,onClick:()=>r(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),n(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&u(On,{}),t===`balancer`&&u(Wn,{refreshToken:e}),t===`settings`&&u(Jn,{refreshToken:e}),t===`templates`&&u(Yn,{refreshToken:e}),t===`logs`&&u(Qn,{})]})]})}var tr=`armed:`;function nr(e){return e.assignment.reasons.detection?.startsWith(tr)===!0}function rr(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!nr(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function ir(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&!nr(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let s=e.degraded??[];if(s.length>0){let e=[...new Set(s.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function ar(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function or(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function sr(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function cr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var lr={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function ur(e){if(!ar(e)||!Array.isArray(e.sections))return lr;let t=Te(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)cr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:or(n(`detectionFps`)),motionSources:sr(n(`motionSources`)),motionFps:or(n(`motionFps`)),motionCooldownMs:or(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function dr(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...dr(r.children,t+1));return n}function X({title:e,children:t}){return n(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[u(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),u(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:r=!1}){return n(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[u(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),u(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),r&&u(fr,{})]})}function fr(){return u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var pr={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return u(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${pr[e]}`,children:t})}function $({children:e}){return u(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function mr({icon:e,label:t,nodeId:r,pinned:i,reason:o,overridden:s}){return n(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[u(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),u(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),r===null?u(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):n(a,{children:[u(`span`,{className:`font-mono text-foreground truncate`,title:r,children:r}),i?n(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[u(dt,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,o!==void 0&&o.length>0?o:`capacity`]}),s&&u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function hr({assignment:e,settings:t,onlineNodes:r,pinPending:i,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...r.map(e=>e.id)])];return n(X,{title:`Where it runs`,children:[u(mr,{icon:H,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),u(mr,{icon:et,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),u(mr,{icon:Re,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),u(mr,{icon:He,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),u(`div`,{className:`mt-1.5`,children:n(`select`,{value:o,disabled:i,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[u(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>n(`option`,{value:e,children:[`Pin detection → `,r.find(t=>t.id===e)?.name??e]},e))]})})]})}function gr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function _r(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function vr(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function yr({streams:e,brokerProfiles:t,settings:r,motionEnabled:i,motionFpsLive:o}){let s=_r(t,r.detectionStreamProfile),c=_r(t,r.motionStreamProfile),l=r.motionSources.includes(`analyzer`);return n(X,{title:`Streams & motion`,children:[n(Z,{label:`Detect stream`,overridden:r.overriddenKeys.has(`detectionStreamProfile`),children:[r.detectionStreamProfile??`—`,s!==void 0&&` · ${s.width}×${s.height} ${s.codec}`]}),u(Z,{label:`Detect FPS`,overridden:r.overriddenKeys.has(`detectionFps`),children:vr(r.detectionFps)}),n(Z,{label:`Motion src`,overridden:r.overriddenKeys.has(`motionSources`),children:[r.motionSources.length>0?r.motionSources.join(` + `):`none`,i===!1&&` · inactive`]}),l&&n(a,{children:[n(Z,{label:`Motion stream`,overridden:r.overriddenKeys.has(`motionStreamProfile`),children:[r.motionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),n(Z,{label:`Motion FPS`,overridden:r.overriddenKeys.has(`motionFps`),children:[vr(r.motionFps),o!==null&&` · live ${o.toFixed(1)}`]})]}),u(Z,{label:`Cooldown`,overridden:r.overriddenKeys.has(`motionCooldownMs`),children:r.motionCooldownMs===null?`default`:`${r.motionCooldownMs/1e3}s`}),u(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?u($,{children:`No streams registered`}):e.map(e=>n(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[u(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,gr(e)]},e.camStreamId))})]})}function br({steps:e,audioModelId:t,audioEnabled:r,audioMode:i}){return n(X,{title:`Pipeline steps`,children:[e===void 0?u($,{children:`Resolving…`}):e.length===0?u($,{children:`No steps configured`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>u(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:n(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&u(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&n(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),u(`div`,{className:`mt-1`,children:n(Z,{label:`Audio class.`,children:[i??`—`,r!==null&&(r?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var xr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Sr({detection:e,live:t,detectionMode:r,modeOverridden:i}){if(e===null)return n(X,{title:`Detection runtime`,children:[u(Z,{label:`Mode`,overridden:i,children:r??`—`}),u($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,d=z(a),f=a===`active`&&o===0;return n(X,{title:`Detection runtime`,children:[n(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[n(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${d.badgeClass}`,children:[u(de,{phase:a,className:`h-2.5 w-2.5`}),d.label]}),t!==void 0&&u(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),u(Z,{label:`Mode`,overridden:i,children:r??`—`}),n(Z,{label:`FPS`,children:[u(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),n(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),n(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&n(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&n(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),n(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),n(Z,{label:`Provisioning`,children:[u(Q,{tone:xr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&n(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function Cr({broker:e}){return e===null?u(X,{title:`Stream broker`,children:u($,{children:`Broker stage inactive or unreachable`})}):n(X,{title:`Stream broker`,children:[e.profiles.length===0?u($,{children:`No broker profiles`}):u(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,r=t&&e.inFps===0;return n(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${r?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),u(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),n(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),n(`span`,{className:`ml-auto shrink-0 ${r?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),n(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),n(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[n(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),n(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function wr({decoder:e,detectionActive:t}){if(e===null)return u(X,{title:`Decoder`,children:u($,{children:`Decoder stage inactive or unreachable`})});let r=t&&e.shm.framesWritten===0;return n(X,{title:`Decoder`,children:[u(Z,{label:`Node`,children:e.nodeId}),u(Z,{label:`Sessions`,children:e.sessionCount}),n(Z,{label:`SHM frames`,children:[u(`span`,{className:r?`text-danger font-semibold`:``,children:e.shm.framesWritten}),u(`span`,{className:`text-foreground-subtle`,children:` written`})]}),n(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&n(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),n(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&u(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}t();var Tr=`pipeline-orchestrator`,Er={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Dr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Or({problems:e}){return u(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>n(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[u(rt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),u(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function kr({deviceId:e,name:t,online:r,status:a,live:o,onlineNodes:c}){let l=s(),{data:d}=ue({addonId:Tr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=re({deviceId:e},{staleTime:3e4}),p=i(()=>ur(d),[d]),m=i(()=>f===void 0?void 0:dr(f.steps),[f]),h=i(()=>a===void 0?[]:ir(a),[a]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=T({onSuccess:g}),v=R({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=a===void 0?`idle`:rr(a),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return n(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[n(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[u(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:Er[b]}`,title:x?`Error`:Dr[b],"aria-label":x?`Error`:Dr[b],role:`img`}),u(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!r&&u(Q,{tone:`danger`,children:`offline`}),n(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&u(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),a?.recording!=null&&(a.recording.active?n(Q,{tone:`danger`,title:`Recording (${a.recording.mode})`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):a.recording.mode!==`off`&&n(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,a.recording.mode]}))]})]}),h.length>0&&u(Or,{problems:h}),a===void 0?u(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):n(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[u(hr,{assignment:a.assignment,settings:p,onlineNodes:c,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),u(Sr,{detection:a.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),u(br,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:a.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),u(yr,{streams:a.source.streams,brokerProfiles:a.broker?.profiles,settings:p,motionEnabled:a.motion?.enabled??null,motionFpsLive:a.motion?.fps??null}),u(Cr,{broker:a.broker}),u(wr,{decoder:a.decoder,detectionActive:a.detection?.phase===`active`})]})]})}t();var Ar=5e3,jr=1e4,Mr=5e3;function Nr(e){let t=s(),{data:n,isLoading:r}=Me(),{data:a,isLoading:o}=te({},{refetchInterval:Ar}),{nodes:c}=k();d(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[u,f]=l(new Map);P(Ee.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&f(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),d(()=>{if(u.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-jr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Mr);return()=>clearInterval(e)},[u.size]);let p=i(()=>{let e=new Map;for(let t of a??[])e.set(t.deviceId,t);return e},[a]);return{rows:i(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:u,onlineNodes:i(()=>(c??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[c]),isLoading:r||o}}t();function Pr({refreshToken:e}){let{rows:t,liveMetrics:r,onlineNodes:a,isLoading:o}=Nr(e),s=i(()=>[...t.map(e=>{let t=e.status===void 0?[]:ir(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=i(()=>{let e=0,t=0;for(let n of s)(n.errorCount>0||n.warningCount>0)&&(t+=1),(r.get(n.row.deviceId)?.phase??n.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,r]);return o&&t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):u(`div`,{className:`h-full overflow-y-auto`,children:n(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[n(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[n(`span`,{children:[u(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),n(`span`,{children:[u(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),n(`span`,{children:[u(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),u(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>u(kr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:r.get(e.deviceId),onlineNodes:a},e.deviceId))]})})}t();var Fr=`__cluster__`;function Ir(e){return e===`cameras`?`cameras`:`nodes`}function Lr(){let[e,t]=nt(),r=Ir(e.get(`view`)),i=e.get(`node`)??`__cluster__`,[o,s]=l(0),[c,f]=l(!1);return d(()=>{r===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Fr},{replace:!0})},[r,e,t]),n(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[n(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[u(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:i},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),u(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),u(`div`,{className:`flex items-center gap-2`,children:n(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:`Refresh`,className:`inline-flex 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`,children:[u(Ue,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),r===`nodes`&&n(`button`,{type:`button`,onClick:()=>f(e=>!e),"aria-expanded":c,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[n(`span`,{children:[c?`Hide`:`Show`,` node list`]}),u(tt,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),u(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:r===`nodes`?n(a,{children:[u(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:u(vt,{selectedNodeId:i,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),f(!1)},refreshToken:o})}),u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:i===`__cluster__`?u(er,{refreshToken:o}):u(nn,{nodeId:i,refreshToken:o})})]}):u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:u(Pr,{refreshToken:o})})})]})}export{Lr as PipelinePage};
@@ -1 +0,0 @@
1
- import{K as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{At as l,Co as u,Dt as d,Ft as f,Hr as p,Lt as m,Ot as h,Rt as g,So as _,Tt as v,Vs as y,_o as b,bo as x,fo as S,go as C,ho as w,jt as T,kt as E,mo as D,po as O,vo as k,wo as A,xo as j,yo as M}from"./src-CDVm70oc.js";import{Vt as N}from"./src-ijaeX4aR.js";import{a as P,i as F,n as I,o as L,r as R,t as ee}from"./face-bbox-y-km4dI8.js";import{a as te,c as ne,f as z,i as re,l as ie,m as B,n as V,o as H,p as U,r as ae,s as oe,t as W,u as se}from"./debounced-invalidate-Bfd2Qzzn.js";import{t as G}from"./pencil-BJxboIbx.js";import{t as ce}from"./plus-Brv4i72u.js";import{t as K}from"./square-check-big-hQzwD37R.js";import{t as q}from"./square-Dd2LMGtj.js";import{B as J,C as Y,I as le,K as ue,R as de,o as X,r as Z,z as fe}from"./index-BTGQKEEA.js";import{t as pe}from"./AdminPage-CCD07UMs.js";import{r as me,t as he}from"./authed-media-BPd_L9jr.js";var ge=ue(`badge-check`,[[`path`,{d:`M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z`,key:`3c2336`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]);t();var Q=[[`plateGallery`]];function _e({vehicleId:e}){let t=a(),{data:r,isLoading:i}=M({vehicleId:e}),o=j();function c(n){o.mutate({vehicleId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:Q})}})}return i?n(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[s(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Loading plates…`]}):!r||r.length===0?s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No plates yet.`}):s(`div`,{className:`mt-2 grid grid-cols-3 gap-2 sm:grid-cols-4 md:grid-cols-6`,children:r.map(e=>n(`div`,{className:`group relative overflow-hidden rounded-md border border-border bg-surface`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[e.base64?s(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:e.text,className:`h-full w-full object-cover`}):s(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:s(J,{className:`h-6 w-6`})}),s(`button`,{type:`button`,onClick:()=>c(e),disabled:o.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove plate sample`,children:s(Z,{className:`h-4 w-4 text-white`})})]}),s(`p`,{className:`truncate px-1.5 py-1 text-center font-mono text-[11px] font-semibold tracking-wide text-foreground`,title:e.text,children:e.text})]},e.id))})}function ve({vehicle:e,expanded:t,onToggle:r}){let c=a(),[u,p]=o(``),[y,b]=o(!1),[x,S]=o(!1),w=_(),D=C();function O(){p(e.name),b(!0)}function k(){b(!1),p(``)}function A(){let t=u.trim();if(!t||t===e.name){k();return}w.mutate({id:e.id,name:t},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),k()}})}function j(){D.mutate({id:e.id},{onSettled:()=>{c.invalidateQueries({queryKey:Q}),S(!1)}})}return n(`div`,{className:`rounded-md border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[s(`div`,{className:`h-8 w-12 shrink-0 overflow-hidden rounded border border-border bg-surface-hover`,children:s(I,{mediaKey:e.coverMediaKey,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:s(`div`,{className:`flex h-full w-full items-center justify-center`,children:s(J,{className:`h-4 w-4 text-foreground-subtle`})})})}),s(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:y?n(i,{children:[s(f,{value:u,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&A(),e.key===`Escape`&&k()},className:`h-6 text-xs`,autoFocus:!0}),s(`button`,{type:`button`,onClick:A,disabled:w.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:s(fe,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:k,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:s(Z,{className:`h-3.5 w-3.5`})})]}):s(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),s(m,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!y&&n(`div`,{className:`flex items-center gap-1`,children:[s(`button`,{type:`button`,onClick:O,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:s(G,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>S(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:s(X,{className:`h-3.5 w-3.5`})})]}),s(`button`,{type:`button`,onClick:r,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:s(t?de:le,{className:`h-3.5 w-3.5`})})]}),t&&s(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:s(_e,{vehicleId:e.id})}),s(v,{open:x,onOpenChange:e=>!e&&S(!1),children:n(d,{children:[n(l,{children:[s(T,{children:`Delete vehicle`}),n(h,{children:[`Delete `,s(`strong`,{children:e.name}),` and all its plate samples? This cannot be undone.`]})]}),n(E,{children:[s(g,{variant:`secondary`,onClick:()=>S(!1),children:`Cancel`}),n(g,{variant:`danger`,onClick:j,disabled:D.isPending,children:[D.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ye(){let e=a(),[t,r]=o(``),i=D();function c(){let n=t.trim();n&&i.mutate({name:n},{onSettled:()=>{e.invalidateQueries({queryKey:Q}),r(``)}})}return n(`div`,{className:`flex items-center gap-2 pt-2`,children:[s(f,{placeholder:`New vehicle name…`,value:t,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},className:`h-7 text-xs flex-1`}),n(g,{variant:`primary`,size:`sm`,onClick:c,disabled:i.isPending||!t.trim(),children:[i.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):s(ce,{className:`h-3.5 w-3.5`}),`Add`]})]})}function be(){let{data:e,isLoading:t}=x(),[r,i]=o(null);function a(e){i(t=>t===e?null:e)}return t?n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(Y,{className:`h-4 w-4 animate-spin`}),`Loading vehicles…`]}):n(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&s(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No vehicles enrolled yet. Add one below.`}),e?.map(e=>s(ve,{vehicle:e,expanded:r===e.id,onToggle:()=>a(e.id)},e.id)),s(ye,{})]})}function xe(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}t();var Se=[[`plateGallery`]];function Ce({plateIds:e,vehicles:t,onDone:r}){let i=a(),c=S(),u=D(),[p,m]=o(``),[_,y]=o(!1),[b,x]=o(null),C=e!==null&&e.length>0,w=e?.length??0;function O(){y(!1),m(``),x(null)}function k(){O(),r()}function A(t){!e||e.length===0||c.mutate({plateIds:[...e],vehicleId:t},{onSettled:()=>{i.invalidateQueries({queryKey:Se}),k()}})}function j(){!e||!p.trim()||u.mutate({name:p.trim()},{onSuccess:e=>{e?.id&&A(e.id)},onError:()=>{i.invalidateQueries({queryKey:Se}),k()}})}let M=c.isPending||u.isPending;return s(v,{open:C,onOpenChange:e=>!e&&k(),children:n(d,{children:[n(l,{children:[s(T,{children:w>1?`Assign ${String(w)} plates to vehicle`:`Assign plate to vehicle`}),s(h,{children:`Select an existing vehicle or create a new one.`})]}),s(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>n(`button`,{type:`button`,onClick:()=>x(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${b===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[s(`span`,{className:`font-medium`,children:e.name}),n(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` plates`]})]},e.id))}),_?s(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:s(f,{placeholder:`New vehicle name…`,value:p,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&j()},autoFocus:!0,className:`flex-1`})}):s(`button`,{type:`button`,onClick:()=>{x(null),y(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New vehicle…`}),n(E,{children:[s(g,{variant:`secondary`,onClick:k,disabled:M,children:`Cancel`}),_?n(g,{variant:`primary`,onClick:j,disabled:M||!p.trim(),children:[M&&s(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):n(g,{variant:`primary`,onClick:()=>b&&A(b),disabled:M||!b,children:[M&&s(Y,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,w>1?` ${String(w)}`:``]})]})]})})}t();var we=[[`plateGallery`]];function Te(e){let[t,n]=o(null),[r,i]=o(null),[a,s]=o(!1);return c(()=>{if(n(null),i(null),s(!1),!e)return;let t=!1,r=null;return(async()=>{try{let i=await me(`${he}/${encodeURIComponent(e)}`);if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||s(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),c(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>s(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function Ee(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|plate/i.test(e.kind))??t[0]}function $({label:e,value:t,mono:r}){return n(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),s(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${r?`font-mono`:``}`,title:t,children:t})]})}function De({box:e}){return s(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:s(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Plate`})})}function Oe({plate:e,cameraName:t,onClose:i,onAssign:l,onUnassign:u,onDelete:p,actionsPending:m}){let h=a(),{data:_,isFetching:y}=b({plateId:e?.plateId??``},{enabled:e!==null}),x=O(),[S,C]=o(`frame`),[w,T]=o(!1),[E,D]=o(``),{frameSrc:k,naturalWidth:A,naturalHeight:j,failed:M}=Te(e?.keyFrameMediaKey);c(()=>{T(!1),D(``),C(`frame`)},[e?.plateId]);let N=r(()=>{let t=Ee(_??[]);return t?t.url:xe(e)},[_,e]),I=r(()=>!e?.plateBbox||A===null||j===null?null:ee(e.plateBbox,A,j),[e?.plateBbox,A,j]);if(e===null)return null;let te=typeof e.keyFrameMediaKey==`string`&&e.keyFrameMediaKey.length>0&&!M,ne=te&&S===`frame`,z=e.assigned?e.vehicleName??`Assigned`:e.recognizedVehicleId?`${e.vehicleName??`Recognized`} (suggested)`:`Unassigned`,re=`${String(Math.round(e.score*100))}%${e.corrected?` · corrected`:``}`;function ie(){e&&(D(e.text),T(!0))}function H(){if(!e)return;let t=E.trim().toUpperCase();if(!t||t===e.text){T(!1);return}x.mutate({plateId:e.plateId,text:t},{onSettled:()=>{h.invalidateQueries({queryKey:we}),T(!1)}})}return s(v,{open:!0,onOpenChange:e=>!e&&i(),children:n(d,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Plate 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:[n(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[n(`div`,{className:`min-w-0`,children:[s(`div`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`Plate detail`}),s(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),s(`button`,{type:`button`,onClick:i,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:s(Z,{className:`h-4 w-4`})})]}),n(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[te&&n(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[n(`button`,{type:`button`,onClick:()=>C(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(P,{className:`h-3.5 w-3.5`}),` Full frame`]}),n(`button`,{type:`button`,onClick:()=>C(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${S===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[s(L,{className:`h-3.5 w-3.5`}),` Crop`]})]}),ne&&k?s(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:s(V,{src:k,alt:`Full frame with detected plate`,fit:`natural`,className:`w-full`,overlay:I?s(De,{box:I}):void 0})}):N?n(`div`,{className:`relative aspect-[2/1] w-full overflow-hidden rounded-lg border border-border bg-background`,children:[s(V,{src:N,alt:`Detected plate`,className:`h-full w-full`}),y&&s(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:s(Y,{className:`h-3.5 w-3.5 animate-spin`})})]}):n(`div`,{className:`flex aspect-[2/1] w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[s(B,{className:`h-8 w-8 text-warning/70`}),s(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),s(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this plate could not be resolved. Safe to delete.`})]}),s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-2`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[s(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:`Plate text`}),w?n(`div`,{className:`flex min-w-0 flex-1 items-center justify-end gap-1.5`,children:[s(f,{value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&H(),e.key===`Escape`&&T(!1)},className:`h-7 max-w-[10rem] text-right font-mono text-xs uppercase`,autoFocus:!0}),s(`button`,{type:`button`,onClick:H,disabled:x.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Save corrected text`,children:x.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):s(fe,{className:`h-3.5 w-3.5`})}),s(`button`,{type:`button`,onClick:()=>T(!1),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel`,children:s(Z,{className:`h-3.5 w-3.5`})})]}):n(`button`,{type:`button`,onClick:ie,className:`group flex min-w-0 items-center gap-1.5`,title:`Correct the OCR reading`,children:[s(`span`,{className:`truncate font-mono text-sm font-semibold tracking-wide text-foreground`,children:e.text||`—`}),s(G,{className:`h-3 w-3 shrink-0 text-foreground-subtle group-hover:text-foreground`})]})]})}),n(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[s($,{label:`Camera`,value:t}),s($,{label:`Captured`,value:U(e.timestamp)}),s($,{label:`Confidence`,value:re}),s($,{label:`Vehicle`,value:z}),s($,{label:`Track`,value:e.trackId,mono:!0})]})]}),n(`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:[e.assigned?n(g,{variant:`secondary`,onClick:()=>u(e.plateId),disabled:m,children:[s(R,{className:`h-3.5 w-3.5`}),` Detach`]}):n(g,{variant:`primary`,onClick:()=>l(e.plateId),disabled:m,children:[s(F,{className:`h-3.5 w-3.5`}),` Assign`]}),n(g,{variant:`secondary`,onClick:()=>p(e.plateId),disabled:m,children:[s(X,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}t();var ke=[[`plateGallery`]],Ae=500,je=120;function Me({plate:e,cameraName:t,nowMs:r,selected:i,onToggleSelect:o,onAssign:c,onOpenDetail:l}){let d=a(),f=u(),p=w(),m=()=>{d.invalidateQueries({queryKey:ke})},h=()=>l(e.plateId),g=xe(e);return n(`div`,{className:`relative flex flex-col overflow-hidden rounded-md border bg-surface ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[n(`div`,{className:`relative aspect-[2/1] overflow-hidden bg-surface-hover`,children:[g===null?n(`button`,{type:`button`,onClick:h,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the plate's crop media is missing. Safe to delete.`,children:[s(B,{className:`h-7 w-7 text-warning/70`}),s(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):s(`img`,{src:g,alt:`Plate ${e.text} from ${t}`,onClick:h,className:`h-full w-full cursor-zoom-in object-cover`}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.plateId)},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":i?`Deselect`:`Select`,children:i?s(K,{className:`h-4 w-4 text-primary`}):s(q,{className:`h-4 w-4`})}),e.corrected&&n(`span`,{className:`absolute right-0 top-0 z-10 flex items-center gap-0.5 rounded-bl-md bg-primary/80 px-1 py-0.5 text-[8px] font-semibold uppercase tracking-wide text-white`,title:`Manually corrected`,children:[s(ge,{className:`h-3 w-3`}),` Fixed`]})]}),n(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[s(`p`,{className:`truncate font-mono text-xs font-bold tracking-wide text-foreground`,title:e.text,children:e.text||`—`}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,title:t,children:t}),s(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:z(e.timestamp,r)}),e.vehicleName&&s(`p`,{className:`truncate text-[10px] font-medium text-primary`,title:e.vehicleName,children:e.vehicleName})]}),n(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),f.mutate({plateId:e.plateId},{onSettled:m})},disabled:f.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach plate`,title:`Detach`,children:f.isPending?s(Y,{className:`h-4 w-4 animate-spin`}):s(R,{className:`h-4 w-4`})}):s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),c(e.plateId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign plate to vehicle`,title:`Assign to vehicle`,children:s(F,{className:`h-4 w-4`})}),s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({plateId:e.plateId},{onSettled:m})},disabled:p.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete plate`,title:`Delete plate`,children:p.isPending?s(Y,{className:`h-4 w-4 animate-spin`}):s(X,{className:`h-4 w-4`})})]})]})}var Ne=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Assigned`,value:`assigned`}];function Pe(e,t){return t===`unassigned`?e.filter(e=>!e.assigned):t===`assigned`?e.filter(e=>e.assigned):e}function Fe(){let e=a(),[t,c]=o(`all`),[l,d]=o(oe),[f,m]=o(new Set),[h,_]=o(new Set),[v,y]=o(null),[b,S]=o(null),{data:C,isLoading:T}=k({limit:Ae,includeCrops:!1},{refetchInterval:3e4}),{data:E=[]}=x(),{data:D}=p({isCamera:!0,projection:`slim`}),O=u(),j=A(),M=w(),N=Date.now(),P=C??[],I=r(()=>{let e=new Map;for(let t of D??[])e.set(t.id,t.name);return e},[D]),L=e=>I.get(e)??`Camera #${String(e)}`,ee=r(()=>ne(P).map(e=>({id:e,name:L(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,I]),z=r(()=>ie(se(Pe(P,t),l),f),[P,t,l,f]),B=H(z,je,r(()=>JSON.stringify([t,l.fromMs,l.toMs,[...f].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,f])),V=r(()=>new Map(P.map(e=>[e.plateId,e])),[P]),U=b===null?null:V.get(b)??null,W=()=>{e.invalidateQueries({queryKey:ke})},G=()=>_(new Set);function ce(e){_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}let K=[...h],q=j.isPending||M.isPending,J=O.isPending||M.isPending;function le(){K.length!==0&&j.mutate({plateIds:K},{onSettled:()=>{W(),G()}})}function ue(){K.length!==0&&Promise.allSettled(K.map(e=>M.mutateAsync({plateId:e}))).then(()=>{W(),G()})}function de(e){S(null),y([e])}function fe(e){O.mutate({plateId:e},{onSettled:W}),S(null)}function pe(e){M.mutate({plateId:e},{onSettled:W}),S(null)}let me=z.length!==P.length;return n(`div`,{className:`relative space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[s(`div`,{className:`flex items-center gap-1`,children:Ne.map(e=>s(`button`,{type:`button`,onClick:()=>c(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),s(ae,{onChange:d}),s(re,{cameras:ee,selected:f,onChange:m}),!T&&s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:me?`${String(z.length)} of ${String(P.length)} plates`:`${String(z.length)} plate${z.length===1?``:`s`}`})]}),h.size>0&&n(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[n(`span`,{className:`text-xs font-medium text-foreground`,children:[h.size,` selected`]}),n(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[n(g,{variant:`primary`,onClick:()=>y(K),disabled:q,children:[s(F,{className:`h-3.5 w-3.5`}),` Assign`]}),n(g,{variant:`secondary`,onClick:le,disabled:q,children:[j.isPending?s(Y,{className:`h-3.5 w-3.5 animate-spin`}):s(R,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),n(g,{variant:`secondary`,onClick:ue,disabled:q,children:[s(X,{className:`h-3.5 w-3.5`}),` Delete`]}),s(g,{variant:`ghost`,onClick:G,disabled:q,children:s(Z,{className:`h-3.5 w-3.5`})})]})]}),T&&n(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[s(Y,{className:`h-4 w-4 animate-spin`}),` Loading plates…`]}),!T&&z.length===0&&s(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:P.length>0?`No plates match the current filters.`:`No plates recognized yet.`}),!T&&z.length>0&&n(i,{children:[s(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2`,children:B.pageItems.map(e=>s(Me,{plate:e,cameraName:L(e.deviceId),nowMs:N,selected:h.has(e.plateId),onToggleSelect:ce,onAssign:e=>y([e]),onOpenDetail:S},e.plateId))}),s(te,{currentPage:B.page,totalItems:B.totalItems,pageSize:B.pageSize,onPageChange:B.setPage,itemNoun:`plates`})]}),s(Oe,{plate:U,cameraName:U?L(U.deviceId):``,onClose:()=>S(null),onAssign:de,onUnassign:fe,onDelete:pe,actionsPending:J}),s(Ce,{plateIds:v,vehicles:E,onDone:()=>{y(null),G()}})]})}t();var Ie=[[`plateGallery`]],Le=2e3;function Re(){let t=a(),n=e(t);n.current=t;let r=e(void 0);r.current||=W({delayMs:Le,invalidate:()=>{n.current.invalidateQueries({queryKey:Ie})}}),c(()=>()=>r.current?.cancel(),[]),y(N.PipelineAnalyticsPlateGalleryChanged,()=>{r.current?.trigger()})}function ze(){return Re(),s(pe,{icon:J,title:`Plates`,subtitle:`Manage enrolled vehicles and assign recognized license plates to them.`,children:n(`section`,{className:`space-y-3`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Vehicles`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled vehicle identities used for plate recognition. Expand a row to view or remove plate samples.`}),s(be,{})]}),n(`div`,{className:`pt-4 border-t border-border`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent recognized plates`}),s(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`License plates read by the detection pipeline. Assign them to a vehicle, correct the OCR text, or delete.`}),s(Fe,{})]})]})})}export{ze as PlatesPage};
@@ -1 +0,0 @@
1
- import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{J as l,Q as u}from"./player-overlays-RwoCa548.js";import{Ao as d,Bo as f,Bs as p,Do as m,Eo as h,Ga as g,Go as _,Ho as v,Hr as y,Jo as b,Ko as x,Mo as S,No as C,Oo as w,Po as T,Sa as E,Vo as D,Wo as O,Xo as k,Ya as A,Yo as j,Zo as M,Zt as N,_n as ee,bn as te,ca as ne,da as re,ga as ie,ia as P,ko as ae,nt as oe,on as se,qo as ce,tt as F,un as I}from"./src-CDVm70oc.js";import{Vt as L}from"./src-ijaeX4aR.js";import{t as le}from"./circle-x-DDabN2KD.js";import{t as ue}from"./download-Cuj1maBm.js";import{a as R,i as de,n as fe,r as pe,t as me}from"./AddLocationWizard-BcscyeiT.js";import{C as z,G as B,K as V,M as H,O as U,V as W,a as he,o as G,r as ge}from"./index-BTGQKEEA.js";import{t as _e}from"./AdminPage-CCD07UMs.js";import{r as ve}from"./authed-media-BPd_L9jr.js";import{t as ye}from"./DeviceAggregateSection-CheBdbsr.js";import{t as be}from"./AdminTabs-BhVFfu-V.js";import{t as K}from"./format-size-DIxKXxtj.js";var xe=V(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),Se=V(`scissors`,[[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M8.12 8.12 12 12`,key:`1alkpv`}],[`path`,{d:`M20 4 8.12 15.88`,key:`xgtan2`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}],[`path`,{d:`M14.8 14.8 20 20`,key:`ptml3r`}]]),Ce=V(`settings-2`,[[`path`,{d:`M20 7h-9`,key:`3s1dr2`}],[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]);t();var we=[{value:`all`,label:`All`},{value:`recording`,label:`Recordings`},{value:`events`,label:`Events`}],Te={recording:`bg-primary/10 text-primary`,events:`bg-violet-500/10 text-violet-400`},Ee={columnKey:`at`,dir:`desc`};function De(e){return new Date(e).toLocaleString()}function Oe(){let[e,t]=o(`all`),{data:a,isLoading:c,isError:l}=C({},{refetchOnWindowFocus:!1}),{data:u,isLoading:d,isError:f}=ie({},{refetchOnWindowFocus:!1}),{data:p}=y({isCamera:!0,projection:`slim`}),m=r(()=>{let e=new Map;for(let t of p??[])e.set(t.id,t.name);return e},[p]),h=r(()=>{let t=[...a??[],...u??[]];return(e===`all`?t:t.filter(t=>t.domain===e)).toSorted((e,t)=>t.at-e.at)},[a,u,e]),g=r(()=>{let t=[];return l&&e!==`events`&&t.push(`Recordings`),f&&e!==`recording`&&t.push(`Events`),t},[l,f,e]),_=r(()=>[{key:`at`,header:`When`,nowrap:!0,sortValue:e=>e.at,render:e=>s(`span`,{className:`text-foreground-subtle tabular-nums`,children:De(e.at)})},{key:`domain`,header:`Domain`,sortValue:e=>e.domain,render:e=>s(`span`,{className:`inline-flex rounded px-1.5 py-0.5 text-[10px] font-medium ${Te[e.domain]}`,children:e.domain})},{key:`op`,header:`Operation`,sortValue:e=>e.op,render:e=>s(`span`,{className:`text-foreground`,children:e.op})},{key:`reason`,header:`Reason`,sortValue:e=>e.reason,render:e=>s(`span`,{className:`text-foreground-subtle`,children:e.reason})},{key:`device`,header:`Camera`,sortValue:e=>e.deviceId===null?`cluster`:m.get(e.deviceId)??`#${String(e.deviceId)}`,render:e=>e.deviceId===null?s(`span`,{className:`text-foreground-subtle`,children:`cluster`}):s(`span`,{className:`text-foreground`,children:m.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`items`,header:`Items`,align:`right`,nowrap:!0,sortValue:e=>e.itemsAffected,render:e=>s(`span`,{className:`tabular-nums`,children:e.itemsAffected.toLocaleString()})},{key:`bytes`,header:`Reclaimed`,align:`right`,nowrap:!0,sortValue:e=>e.bytesReclaimed,render:e=>s(`span`,{className:`tabular-nums`,children:e.bytesReclaimed>0?K(e.bytesReclaimed):`—`})}],[m]),v=c||d;return n(`div`,{className:`flex flex-col gap-4`,children:[s(`div`,{className:`flex items-center gap-1`,children:we.map(n=>s(`button`,{onClick:()=>t(n.value),className:`rounded px-2 py-1 text-xs font-medium ${e===n.value?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-muted`}`,children:n.label},n.value))}),v&&h.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(z,{className:`h-4 w-4 animate-spin`}),`Loading activity…`]}):h.length===0?g.length>0?s(N,{icon:he,title:`Activity could not be read`,description:`The ${g.join(` and `)} ops log did not answer. This is not "nothing happened" — retry, or check the node that owns it.`}):s(N,{icon:B,title:`No activity yet`,description:`Prune, delete and rescan operations across recordings and events show up here.`}):n(i,{children:[g.length>0&&n(`p`,{className:`flex items-center gap-1.5 text-[11px] text-amber-500`,children:[s(he,{className:`h-3 w-3 shrink-0`}),g.join(` and `),` did not answer — rows from`,` `,g.length===1?`that domain`:`those domains`,` are missing below.`]}),s(F,{columns:_,rows:h,rowKey:e=>e.id,minWidthPx:720,mobileMode:`scroll`,maxBodyHeight:oe,defaultSort:Ee})]})]})}t();function ke(){let e=y({isCamera:!0,projection:`slim`}),t=r(()=>(e.data??[]).toSorted((e,t)=>e.name.localeCompare(t.name)),[e.data]),[i,a]=o(null),c=i??t[0]?.id??null;return!e.isLoading&&t.length===0?s(N,{icon:W,title:`No cameras`,description:`Add a camera first.`}):n(`div`,{className:`space-y-3`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Per-camera recording & retention`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Recording mode, schedule bands and the retention policy for one camera — the same controls as the camera's own Recording tab. Retention is one policy over footage and analytics; per-camera event deletion lives on the Events tab.`})]}),n(`div`,{className:`flex items-center gap-2`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),s(`select`,{value:c??``,onChange:e=>a(Number(e.target.value)),className:`rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:t.map(e=>s(`option`,{value:e.id,children:e.name},e.id))})]}),c!==null&&s(se,{deviceId:c,children:s(ye,{deviceId:c,sectionFilter:e=>e.location===`top-tab`&&e.tab===`recording`})},c)]})}t();function Ae({types:e}){let t=a(),i=I(),{data:c}=v({}),l=D(),u=r(()=>l.data??[],[l.data]),[d,p]=o(null),[m,h]=o(null),g=()=>{t.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})},_=M({onSuccess:g}),y=f({onSuccess:g}),b=r(()=>{let e=new Map;for(let t of c??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[c]),x=e=>{e.isDefault||_.mutate(de(e,{isDefault:!0}))},S=(e,t)=>{_.mutate(de(e,{enabled:t}))},C=async e=>{if(e.isDefault){await i({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another as default first.`,confirmLabel:`OK`,variant:`warning`});return}if(await i({title:`Delete location "${e.displayName}"?`,message:`Removes the record; files on disk are untouched.`,confirmLabel:`Delete`,variant:`danger`}))try{await y.mutateAsync({id:e.id})}catch(t){await i({title:`Delete anyway?`,message:`${t instanceof Error?t.message:String(t)}\n\nForcing removes the record only. Anything still on that location becomes unreachable.`,confirmLabel:`Force delete`,variant:`danger`})&&y.mutate({id:e.id,force:!0})}},w=e.map(e=>u.find(t=>t.id===e)).filter(e=>e!==void 0);return n(`div`,{className:`space-y-3`,children:[w.length===0?s(`p`,{className:`text-[11px] text-foreground-subtle italic`,children:`No storage locations declared for this purpose.`}):w.map(e=>s(pe,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:b.get(e.id)??[],onAdd:e=>p(e),onEdit:e=>h(e),onDelete:e=>{C(e)},onSetDefault:e=>x(e),onToggleEnabled:(e,t)=>S(e,t)},e.id)),d!==null&&s(me,{initialType:d,onClose:()=>p(null),onCreated:()=>{g(),p(null)}}),m!==null&&s(fe,{location:m,onClose:()=>h(null),onSaved:()=>{g(),h(null)}})]})}t();var je=`pipeline-analytics`;function Me(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Ne(){let e=a(),{data:t}=P(void 0),{data:i,isLoading:o}=ee({addonId:je}),c=Me(i),l=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),u=r(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,c,...e])].filter(Boolean)},[t,c]);return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[o?s(z,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):s(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:je,patch:{postProcessingNodeId:e.target.value}})},disabled:l.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:u.map(e=>s(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&s(z,{className:`h-4 w-4 animate-spin text-primary`})]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),s(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),s(Ae,{types:[`eventMedia`]})]})]})}t();var Pe=[[`pipelineAnalytics`]],Fe=1440*60*1e3,Ie=[{days:1,label:`1 day`},{days:7,label:`7 days`},{days:30,label:`30 days`},{days:90,label:`90 days`}];function Le(){let t=a(),i=I(),[c,u]=o(30),{data:d,isLoading:f}=re({},{refetchOnWindowFocus:!1}),{data:p}=y({isCamera:!0,projection:`slim`}),m=r(()=>{let e=new Map;for(let t of p??[])e.set(t.id,t.name);return e},[p]),h=e(()=>{t.invalidateQueries({queryKey:Pe})},[t]),g=E({onSuccess:h}),_=ne({onSuccess:h}),v=e(async()=>{await i({title:`Prune events older than ${String(c)} day${c===1?``:`s`}?`,message:`Permanently deletes every event (motion / object / audio) older than the cutoff across all cameras, and their media. This cannot be undone.`,confirmLabel:`Prune events`,variant:`danger`})&&g.mutate({olderThanMs:Date.now()-c*Fe,reason:`retention`})},[i,g,c]),b=e(async e=>{await i({title:`Delete all events for ${m.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${String(e.rows)} event${e.rows===1?``:`s`} (${K(e.bytes)} of media) for this camera. This cannot be undone.`,confirmLabel:`Delete events`,variant:`danger`})&&_.mutate({deviceId:e.deviceId})},[i,_,m]),x=r(()=>[{key:`camera`,header:`Camera`,render:e=>s(`span`,{className:`text-foreground`,children:m.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`rows`,header:`Events`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:e.rows.toLocaleString()})},{key:`bytes`,header:`Media`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:K(e.bytes)})},{key:`actions`,header:``,align:`right`,render:e=>n(`button`,{onClick:()=>{b(e)},disabled:_.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete all events for this camera`,children:[s(G,{className:`h-3 w-3`}),`Delete`]})}],[m,b,_.isPending]);return f&&!d?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(z,{className:`h-4 w-4 animate-spin`}),`Loading event-store footprint…`]}):d?n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[s(l,{label:`Total events`,icon:s(H,{className:`h-3 w-3`}),footer:`across ${String(d.devices.length)} camera${d.devices.length===1?``:`s`}`,children:d.totalRows.toLocaleString()}),s(l,{label:`Event media on disk`,children:K(d.totalBytes)})]}),n(`section`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[s(`span`,{className:`text-foreground-subtle`,children:`Prune events older than`}),s(`select`,{value:c,onChange:e=>u(Number(e.target.value)),className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:Ie.map(e=>s(`option`,{value:e.days,children:e.label},e.days))}),n(`button`,{onClick:()=>{v()},disabled:g.isPending,className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,children:[g.isPending?s(z,{className:`h-3 w-3 animate-spin`}):s(Se,{className:`h-3 w-3`}),`Prune now`]})]}),d.devices.length===0?s(N,{icon:H,title:`No stored events`,description:`No camera has persisted events yet.`}):s(F,{columns:x,rows:[...d.devices],rowKey:e=>e.deviceId,minWidthPx:480})]}):s(N,{icon:H,title:`No event data`,description:`Pipeline analytics has not reported any event-store footprint yet.`})}function Re(){return n(`div`,{className:`flex flex-col gap-8`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Event store`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`What the durable event store occupies, per camera, with fleet-wide prune-by-age and delete-all-events.`}),s(`div`,{className:`mt-3`,children:s(Le,{})})]}),n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node & folder`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that generates events, media, audio and motion, and the storage location event media is written to.`}),s(`div`,{className:`mt-3`,children:s(Ne,{})})]})]})}t();var ze=[`high`,`mid`,`low`],Be=[{value:1,label:`Real time (1×)`},{value:2,label:`2×`},{value:4,label:`4×`},{value:8,label:`8×`},{value:16,label:`16×`}],Ve=10080*60*1e3;function He(e){let t=new Date(Date.now()-e*6e4),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function Ue({onClose:e,onCreated:t}){let i=y({isCamera:!0,projection:`slim`}),a=r(()=>(i.data??[]).toSorted((e,t)=>e.name.localeCompare(t.name)),[i.data]),[c,l]=o(``),[u,d]=o(`high`),[f,p]=o(He(60)),[m,h]=o(He(0)),[g,_]=o(1),[v,b]=o(!0),[x,S]=o(``),[C,T]=o(null),E=c===``?a[0]?.id??null:c,D=new Date(f).getTime(),O=new Date(m).getTime(),k=Number.isFinite(D)&&Number.isFinite(O)&&D<O,A=w({onSuccess:()=>{t(),e()},onError:e=>T(e instanceof Error?e.message:String(e))});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:e,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`h2`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[s(U,{className:`h-3.5 w-3.5`}),`New export`]}),s(`button`,{onClick:e,className:`text-foreground-subtle hover:text-foreground`,children:s(ge,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Camera`}),s(`select`,{value:E??``,onChange:e=>l(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:a.map(e=>s(`option`,{value:e.id,children:e.name},e.id))})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Profile`}),s(`select`,{value:u,onChange:e=>d(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:ze.map(e=>s(`option`,{value:e,children:e},e))})]})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`From`}),s(`input`,{type:`datetime-local`,value:f,onChange:e=>p(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`To`}),s(`input`,{type:`datetime-local`,value:m,onChange:e=>h(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`})]})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Speed`}),s(`select`,{value:g,onChange:e=>_(Number(e.target.value)),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground`,children:Be.map(e=>s(`option`,{value:e.value,children:e.label},e.value))})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Title (optional)`}),s(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`e.g. courier at the gate`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle`})]})]}),n(`label`,{className:`flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:v,disabled:g!==1,onChange:e=>b(e.target.checked),className:`accent-primary`}),`Include audio`,g===1?``:` (real-time only)`]}),!k&&s(`p`,{className:`text-[11px] text-danger`,children:`"From" must be before "To".`}),C&&s(`p`,{className:`text-[11px] text-danger`,children:C})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:e,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>{if(E===null||!k)return;T(null);let e=x.trim();A.mutate({deviceId:E,profile:u,fromMs:D,toMs:O,options:{includeAudio:v,maxLifeMs:Ve,deleteAfterDownload:!1,...g===1?{}:{speed:g},...e.length>0?{title:e}:{}}})},disabled:E===null||!k||A.isPending,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:A.isPending?`Queuing…`:`Create export`})]})]})})}function We(e){let t=[];return e.timelapse?t.push(`timelapse ${String(e.timelapse.everyMs/1e3)}s`):(t.push(`${String(e.speed??1)}×`),e.includeAudio&&t.push(`+ audio`)),t.join(` `)}function Ge(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function Ke(e,t){let n=Math.max(0,Math.round((t-e)/1e3)),r=Math.floor(n/3600),i=Math.floor(n%3600/60),a=n%60,o=r>0?`${String(r)}:${String(i).padStart(2,`0`)}:${String(a).padStart(2,`0`)}`:`${String(i)}:${String(a).padStart(2,`0`)}`;return`${Ge(e)} · ${o}`}function qe(e,t){let n=e-t;if(n<=0)return`expired`;let r=Math.floor(n/6e4);if(r<60)return`in ${String(r)}m`;let i=Math.floor(r/60);return i<24?`in ${String(i)}h`:`in ${String(Math.floor(i/24))}d`}function Je(e,t,n,r){return e.map(e=>{if(e.state===`expired`||e.state===`deleted`)return e;let i=r.get(e.id);if(i)return{...e,state:`failed`,error:i.error,progressPct:null};let a=n.get(e.id);if(a)return{...e,state:`ready`,fileBytes:a.fileBytes,progressPct:100};let o=t.get(e.id);return o&&(e.state===`queued`||e.state===`rendering`)?{...e,state:`rendering`,progressPct:o.progressPct}:e})}t();var Ye=[[`recordingExport`]],Xe={queued:{cls:`bg-muted text-foreground-subtle`,label:`queued`},rendering:{cls:`bg-primary/10 text-primary`,label:`rendering`,spin:!0},ready:{cls:`bg-success/10 text-success`,label:`ready`},failed:{cls:`bg-danger/10 text-danger`,label:`failed`},expired:{cls:`bg-muted text-foreground-subtle`,label:`expired`},deleted:{cls:`bg-muted text-foreground-subtle`,label:`deleted`}};function Ze(){let{data:e,isLoading:t}=d({},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`queued`||e.state===`rendering`)?3e3:!1}),{map:n}=p(L.RecordingExportProgress,e=>e.exportId),{map:i}=p(L.RecordingExportCompleted,e=>e.exportId),{map:a}=p(L.RecordingExportFailed,e=>e.exportId);return{rows:r(()=>Je(e??[],n,i,a),[e,n,i,a]),isLoading:t}}function Qe(e){let[t,n]=o(()=>Date.now());return c(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function $e(){let t=a(),[i,c]=o(!1),l=()=>{t.invalidateQueries({queryKey:[[`recordingExport`,`listExports`]]})},d=I(),f=u().trpcClient,p=Qe(6e4),{rows:h,isLoading:g}=Ze(),{data:_}=y({isCamera:!0,projection:`slim`}),v=r(()=>{let e=new Map;for(let t of _??[])e.set(t.id,t.name);return e},[_]),b=e(()=>{t.invalidateQueries({queryKey:Ye})},[t]),x=m({onSuccess:b}),S=ae({onSuccess:b}),[C,w]=o(null),T=e(async e=>{w(e.id);try{let{url:t}=await f.recordingExport.getDownloadUrl.query({exportId:e.id}),n=await ve(t),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.options.title??e.id}.mp4`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r),b()}finally{w(null)}},[f,b]),E=e(async e=>{await d({title:`Cancel this export?`,message:`Stops the render. The partial file is discarded.`,confirmLabel:`Cancel export`,variant:`danger`})&&x.mutate({exportId:e.id})},[d,x]),D=e(async e=>{await d({title:`Delete this export?`,message:`Permanently removes the rendered file and its history row.`,confirmLabel:`Delete`,variant:`danger`})&&S.mutate({exportId:e.id})},[d,S]),O=r(()=>[{key:`camera`,header:`Camera`,render:e=>s(`span`,{className:`text-foreground`,children:v.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`range`,header:`Range`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:Ke(e.fromMs,e.toMs)})},{key:`variant`,header:`Variant`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:We(e.options)})},{key:`state`,header:`State`,render:e=>{let t=Xe[e.state];return n(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium ${t.cls}`,children:[t.spin&&s(z,{className:`h-2.5 w-2.5 animate-spin`}),t.label,e.state===`rendering`&&e.progressPct!==null&&n(`span`,{className:`tabular-nums`,children:[e.progressPct,`%`]})]})}},{key:`expiry`,header:`Expires`,nowrap:!0,render:e=>e.state===`deleted`?s(`span`,{className:`text-foreground-subtle`,children:`—`}):s(`span`,{className:`text-foreground-subtle tabular-nums`,children:qe(e.expiresAt,p)})},{key:`size`,header:`Size`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:e.fileBytes===null?`—`:K(e.fileBytes)})},{key:`actions`,header:``,align:`right`,render:e=>{let t=e.state===`ready`,r=e.state===`queued`||e.state===`rendering`,i=e.state!==`deleted`;return n(`div`,{className:`flex items-center justify-end gap-1`,children:[t&&n(`button`,{onClick:()=>{T(e)},disabled:C===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-primary/10 hover:text-foreground disabled:opacity-50`,title:`Download MP4`,children:[C===e.id?s(z,{className:`h-3 w-3 animate-spin`}):s(ue,{className:`h-3 w-3`}),`Download`]}),r&&n(`button`,{onClick:()=>{E(e)},disabled:x.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Cancel render`,children:[s(le,{className:`h-3 w-3`}),`Cancel`]}),i&&s(`button`,{onClick:()=>{D(e)},disabled:S.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete export`,children:s(G,{className:`h-3 w-3`})})]})}}],[v,p,C,x.isPending,S.isPending,T,E,D]);return g&&h.length===0?n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(z,{className:`h-4 w-4 animate-spin`}),`Loading exports…`]}):n(`div`,{className:`space-y-3`,children:[s(`div`,{className:`flex justify-end`,children:n(`button`,{onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[s(U,{className:`h-3.5 w-3.5`}),`New export`]})}),h.length===0?s(N,{icon:U,title:`No exports yet`,description:`Create one here (New export) or from a camera's timeline in the viewer. Rendered clips show up here to download or manage.`}):s(F,{columns:O,rows:h,rowKey:e=>e.id,minWidthPx:720}),i&&s(Ue,{onClose:()=>c(!1),onCreated:l})]})}t();var et=2e3;function tt(){let e=I(),t=a(),r=A(),i=g(void 0,{refetchInterval:e=>e.state.data?.state===`running`?et:!1}),o=i.data,l=o?.state===`running`,u=l||r.isPending;c(()=>{o?.state!==`done`||o.finishedAtMs===null||(t.invalidateQueries({queryKey:[[`recording`]]}),t.invalidateQueries({queryKey:[[`pipelineAnalytics`]]}))},[o?.state,o?.finishedAtMs,t]);let d=async()=>{await e({title:`Reconcile storage from disk?`,message:`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:`Reconcile`,variant:`warning`})&&(await r.mutateAsync(),await i.refetch())},f=l?o.total>0?`Reconciling ${String(o.completed)}/${String(o.total)}…`:`Reconciling…`:r.isPending?`Reconciling…`:`Reconcile from disk`;return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Disk reconcile`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Makes the database match the filesystem for recordings, tracks, events and media. Rows whose files are gone are deleted, including snapshot-less motion events. Enrolled identities stay. The walk runs on the hub; you can leave this page.`}),n(`div`,{className:`mt-3 flex flex-col gap-2`,children:[n(`button`,{type:`button`,onClick:()=>void d(),disabled:u,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:[u?s(z,{className:`h-3.5 w-3.5 animate-spin`}):s(R,{className:`h-3.5 w-3.5`}),f]}),o?.state===`done`?n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Last run: `,String(o.completed),` camera(s) — dropped `,String(o.tracks),` tracks,`,` `,String(o.events),` events, `,String(o.mediaDropped),` media`,o.failed.length>0?`, ${String(o.failed.length)} failed (${o.failed.join(`, `)})`:``,`.`]}):null,o?.state===`error`&&o.error!==null?n(`p`,{className:`text-[11px] text-destructive`,children:[`Reconcile failed: `,o.error]}):null]})]})}var q=1e3,J=60*q,Y=60*J;function X(e){return e.toLocaleString(`en-US`)}function nt(e){if(!Number.isFinite(e)||e<0)return`—`;if(e>=Y){let t=Math.floor(e/Y),n=Math.round(e%Y/J);return`${t.toString()}h ${n.toString()}m`}if(e>=J){let t=Math.floor(e/J),n=Math.round(e%J/q);return`${t.toString()}m ${n.toString()}s`}return`${Math.max(0,Math.round(e/q)).toString()}s`}function rt(e){let t=Math.max(0,e.observedAt-e.startedAt),n=e.filesTotal===null?`${X(e.filesMoved)} files`:`${X(e.filesMoved)} / ${X(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?`${K(e.bytesMoved/t*q)}/s`:null,o=e.filesTotal===null?null:e.filesTotal-e.filesMoved,s=!i||o===null||o<=0?null:`~${nt(o*t/e.filesMoved)} left`;return{counted:n,fraction:r,moved:`${K(e.bytesMoved)} moved`,rate:a,eta:s}}function it(e){let t=rt(e);return[t.counted,t.moved,t.rate,t.eta].filter(e=>e!==null).join(` · `)}t();var at=`storage-migration`;function ot(){let{data:e}=P(void 0);return(e??[]).some(e=>e.addons.some(e=>e.capabilities.includes(at)))}var st=[{id:`recordings`,label:`Recordings`,locationType:`recordings`},{id:`recordingsLow`,label:`Low-res recordings`,locationType:`recordingsLow`},{id:`eventMedia`,label:`Event media`,locationType:`eventMedia`}],ct=new Set([`planning`,`sealing`,`pausing`,`moving`,`draining`,`verifying`,`repointing`,`refreshing`,`resuming`]);function lt(){return ot()?s(ut,{}):s(N,{icon:xe,title:`Storage migration not installed`,description:`This system doesn't advertise the storage-migration capability yet. Once it's deployed, this panel moves recordings, low-res recordings and event media to new storage locations in one coordinated, verified operation.`})}function ut(){let e=I(),{data:t}=v({}),[i,a]=o({}),[c,l]=o(null),[u,d]=o(null),f=r(()=>{let e=new Map;for(let n of t??[]){let t=e.get(n.type);t?t.push(n):e.set(n.type,[n])}return e},[t]),p=k({},{refetchInterval:2e3}),m=p.data??null,h=m!==null&&ct.has(m.phase),g=r(()=>{let e={};for(let t of st){let n=i[t.id];n&&(e[t.id]=n)}return Object.keys(e).length>0?e:void 0},[i]),_=ce({destinations:g??{}},{enabled:!1,retry:!1}),y=j(),b=O(),x=async()=>{if(!g)return;d(null);let e=await _.refetch();if(e.error){d(e.error instanceof Error?e.error.message:String(e.error));return}l(e.data??null)},S=async()=>{if(g&&await e({title:`Start storage migration?`,message:`Pauses the affected writers, copies the data to the new locations, verifies it, then repoints the defaults. Safe to re-run if interrupted.`,confirmLabel:`Start migration`,variant:`danger`})){d(null);try{await y.mutateAsync({destinations:g}),l(null),await p.refetch()}catch(e){d(e instanceof Error?e.message:String(e))}}},C=async()=>{if(m&&await e({title:`Cancel migration?`,message:`Stops the in-progress migration. Data already moved and verified stays at the destination; anything already repointed is not reverted.`,confirmLabel:`Cancel migration`,variant:`danger`}))try{await b.mutateAsync({jobId:m.jobId}),await p.refetch()}catch{}};return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[n(`h3`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[s(xe,{className:`h-3.5 w-3.5`}),`Storage migration`]}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Move recordings, low-res recordings and/or event media to new storage locations in one coordinated operation: pauses the writers, copies via the recorder / pipeline-analytics movers, verifies, then repoints the defaults. Always applies to every camera — destinations are global defaults per storage class, so migration can't be scoped to a subset of cameras. This is the only supported way to move a storage location's data — the Storage tab no longer offers a per-location "Relocate" action.`}),s(`div`,{className:`mt-3 grid grid-cols-1 gap-3 sm:grid-cols-3`,children:st.map(e=>{let t=f.get(e.locationType)??[];return n(`div`,{className:`space-y-1`,children:[s(`label`,{htmlFor:`migration-dest-${e.id}`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.label}),n(`select`,{id:`migration-dest-${e.id}`,value:i[e.id]??``,onChange:t=>{let n=t.target.value;a(t=>({...t,[e.id]:n}))},disabled:h,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground disabled:opacity-50`,children:[s(`option`,{value:``,children:`— unchanged —`}),t.map(e=>s(`option`,{value:e.id,children:e.displayName},e.id))]})]},e.id)})}),u&&s(`p`,{className:`mt-2 text-[11px] text-danger`,children:u}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[n(`button`,{type:`button`,onClick:()=>{x()},disabled:!g||_.isFetching||h,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:[_.isFetching&&s(z,{className:`h-3 w-3 animate-spin`}),`Plan`]}),n(`button`,{type:`button`,onClick:()=>{S()},disabled:!g||y.isPending||h,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:[y.isPending&&s(z,{className:`h-3 w-3 animate-spin`}),`Start migration`]})]}),c&&s(`div`,{className:`mt-3 divide-y divide-border rounded-md border border-border`,children:c.moves.length===0?s(`p`,{className:`px-2.5 py-1.5 text-[11px] text-foreground-subtle`,children:`Nothing to move — selected destinations match the current defaults.`}):c.moves.map(e=>n(`div`,{className:`px-2.5 py-1.5 text-[11px] text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]},`${e.storageClass}-${e.toLocationId}`))})]}),m&&n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[n(`div`,{className:`flex items-center justify-between`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Migration status`}),h&&n(`button`,{type:`button`,onClick:()=>{C()},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:[s(ge,{className:`h-3 w-3`}),`Cancel`]})]}),n(`p`,{className:`mt-1 text-xs text-foreground`,children:[`Phase: `,s(`span`,{className:`font-medium`,children:m.phase}),h&&s(z,{className:`ml-2 inline h-3 w-3 animate-spin text-primary`})]}),m.error&&s(`p`,{className:`mt-1 text-[11px] text-danger`,children:m.error}),m.pausedParticipants.length>0&&n(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:[`Paused: `,m.pausedParticipants.join(`, `)]}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:m.moves.map(e=>s(dt,{move:e},`${e.storageClass}-${e.fromLocationId}`))})]}),s(ft,{running:h}),s(mt,{})]})}function dt({move:e}){let t=e.progress===null?null:rt(e.progress);return n(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[n(`div`,{className:`flex items-center justify-between`,children:[n(`span`,{className:`text-foreground`,children:[e.storageClass,`: `,e.fromLocationId,` → `,e.toLocationId]}),n(`span`,{className:`text-foreground-subtle`,children:[e.state??`pending`,e.error?` (${e.error})`:``]})]}),e.progress!==null&&n(`div`,{className:`mt-1 space-y-1`,children:[t!==null&&t.fraction!==null&&s(`div`,{className:`h-1 w-full overflow-hidden rounded bg-border`,children:s(`div`,{className:`h-full bg-primary`,style:{width:`${(t.fraction*100).toFixed(1)}%`}})}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:it(e.progress)})]})]})}function ft({running:e}){let t=I(),r=b({},{refetchInterval:1e4}),i=_(),[a,c]=o(null),l=r.data??[];if(l.length===0)return null;let u=async e=>{if(await t({title:`Drain remaining ${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:`Drain remaining`,variant:`danger`})){c(null);try{await i.mutateAsync({classes:[e.storageClass]}),await r.refetch()}catch(e){c(e instanceof Error?e.message:String(e))}}};return n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Left on the old location`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`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.`}),a&&s(`p`,{className:`mt-2 text-[11px] text-danger`,children:a}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:l.map(t=>n(`div`,{className:`flex items-center justify-between gap-2 px-2.5 py-1.5 text-[11px]`,children:[n(`span`,{className:`text-foreground`,children:[t.storageClass,`: `,t.fromLocationId,` → `,t.toLocationId,s(`span`,{className:`ml-2 text-foreground-subtle`,children:pt(t)})]}),s(`button`,{type:`button`,onClick:()=>{u(t)},disabled:e||i.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:`Drain remaining`})]},`${t.storageClass}-${t.fromLocationId}`))})]})}function pt(e){if(e.items===null)return`amount unknown — the archive could not be read`;let t=e.items.toLocaleString(`en-US`);return e.bytes===null?`${t} rows`:`${t} segments · ${K(e.bytes)}`}function mt(){let{data:e}=x({},{refetchInterval:2e3}),t=(e??[]).filter(e=>e.migrationJobId===null&&e.job.state===`running`);return t.length===0?null:n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Movers running outside a migration`}),s(`div`,{className:`mt-2 divide-y divide-border rounded-md border border-border`,children:t.map(e=>n(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:[n(`div`,{className:`text-foreground`,children:[e.lane,`: `,e.job.fromLocationId,` → `,e.job.toLocationId]}),s(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:it({filesMoved:e.job.filesMoved,filesTotal:e.job.filesTotal,bytesMoved:e.job.bytesMoved,startedAt:e.job.startedAt,observedAt:e.observedAt})})]},e.job.jobId))})]})}function ht(){return n(`div`,{className:`flex flex-col gap-8`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Reconcile`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Make the database match the filesystem — recordings index, tracks, events and media in one walk.`}),s(`div`,{className:`mt-3`,children:s(tt,{})})]}),n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Migration`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`Move footage and event media to new storage locations as one verified job, then repoint both defaults.`}),s(`div`,{className:`mt-3`,children:s(lt,{})})]})]})}t();var gt=`recorder`;function _t(e,t,n){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t&&typeof e.value==`string`)return e.value;return n}function vt(){let e=a(),{data:t}=P(void 0),{data:i,isLoading:o}=ee({addonId:gt}),c=_t(i,`recordingNodeId`,`hub`),l=te({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),u=r(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,c,...e])].filter(Boolean)},[t,c]);return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Recording node`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records (continuous & events) and serves playback. Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),n(`div`,{className:`mt-3 flex items-center gap-2`,children:[o?s(z,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):s(`select`,{value:c,onChange:e=>{e.target.value!==c&&l.mutate({addonId:gt,patch:{recordingNodeId:e.target.value}})},disabled:l.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:u.map(e=>s(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),l.isPending&&s(z,{className:`h-4 w-4 animate-spin text-primary`})]}),c!==`hub`&&n(`p`,{className:`mt-2 text-[11px] text-amber-500`,children:[`The stream-broker is hub-only — an agent recorder pulls streams from the hub over the network. The hub's RTSP restream port must be reachable from`,` `,s(`span`,{className:`font-medium`,children:c}),`. If the auto-derived host doesn't work, set the recorder's`,s(`span`,{className:`font-medium`,children:` recordingHubHostname`}),` global setting.`]})]}),n(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[s(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Recordings folders`}),s(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where recordings are stored. Multi-location collections — segments are split across the locations of a type. Add a location to grow capacity; mark one default per type.`}),s(Ae,{types:[`recordings`,`recordingsLow`]})]})]})}function yt(e){return e.locationIds!==void 0&&e.locationIds.length>0?e.locationIds:e.locationId===null?[]:[e.locationId]}function bt(e,t){let n=yt(e);return n.length===0?`default root`:n.map(e=>t.get(e)??e).join(` + `)}function xt(e,t,n){if(e.length===0)return null;let r=e[0];if(e.length===1&&r!==void 0)return{label:bt(r,t),exact:!0};if(n===null)return null;let i=e.find(e=>yt(e).includes(n));return i===void 0?null:{label:bt(i,t),exact:!1}}var Z=[`ok`,`warn`,`critical`];function St(e){return e>=.95?`critical`:e>=.85?`warn`:`ok`}function Ct(e){return Math.min(1,Math.max(0,e))}function wt(e){let{availableBytes:t,totalBytes:n}=e;if(n===null||n<=0||t===null)return null;let r=Ct((n-t)/n);return{fraction:r,severity:St(r),recordingsFraction:Ct(e.usedBytes/n),freeBytes:t,totalBytes:n}}function Tt(e){if(e.length===0)return null;let t=0,n=0,r=0,i=0,a=null;for(let o of e){let e=wt(o);if(e===null){n+=1;continue}t+=1,r+=e.totalBytes,i+=e.freeBytes,(a===null||Z.indexOf(e.severity)>Z.indexOf(a))&&(a=e.severity)}return{knownVolumes:t,unknownVolumes:n,totalBytes:r,freeBytes:i,severity:a}}t();var Et=[[`recording`]],Dt=[{value:`retention`,label:`Retention policy`},{value:`quota`,label:`Quota / disk pressure`},{value:`operator`,label:`Operator`}],Ot={ok:`bg-primary`,warn:`bg-amber-500`,critical:`bg-danger`},Q={ok:`text-foreground-subtle`,warn:`text-amber-500`,critical:`text-danger`};function $(e){return`${String(Math.round(e*100))}%`}function kt(e,t){let n=e.locationIds??(e.locationId===null?[]:[e.locationId]),r=n.map(e=>t.get(e)).filter(e=>e!==void 0);return r.length>0?r.join(` + `):e.root===void 0?n.length>0?n.join(` + `):`default root`:e.root}function At(){let t=a(),i=I(),[c,u]=o(`retention`),{data:d,isLoading:f}=S({},{refetchOnWindowFocus:!1}),{data:p}=y({isCamera:!0,projection:`slim`}),{data:m}=v({}),g=r(()=>{let e=new Map;for(let t of p??[])e.set(t.id,t.name);return e},[p]),_=r(()=>{let e=new Map;for(let t of m??[])e.set(t.id,t.displayName);return e},[m]),b=r(()=>(m??[]).find(e=>e.type===`recordings`&&e.isDefault)?.id??null,[m]),x=r(()=>d?.locations??[],[d?.locations]),C=r(()=>xt(x,_,b),[x,_,b]),w=r(()=>Tt(x),[x]),E=e(()=>{t.invalidateQueries({queryKey:Et})},[t]),D=T({onSuccess:E}),O=h({onSuccess:E}),k=e(async e=>{await i({title:`Prune ${g.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Applies the retention policy now (reason: ${c}). Footage beyond the policy is permanently deleted.`,confirmLabel:`Prune now`,variant:`danger`})&&D.mutate({deviceId:e.deviceId,reason:c})},[i,D,c,g]),A=e(async e=>{await i({title:`Delete all footage for ${g.get(e.deviceId)??`#${String(e.deviceId)}`}?`,message:`Permanently deletes ${K(e.usedBytes)} of recorded footage for this camera. This cannot be undone.`,confirmLabel:`Delete ${K(e.usedBytes)}`,variant:`danger`})&&O.mutate({deviceId:e.deviceId})},[i,O,g]),j=r(()=>[{key:`camera`,header:`Camera`,render:e=>s(`span`,{className:`text-foreground`,children:g.get(e.deviceId)??`#${String(e.deviceId)}`})},{key:`disk`,header:`Disk`,nowrap:!0,render:()=>C===null?s(`span`,{className:`text-foreground-subtle`,children:`—`}):n(`span`,{className:C.exact?`text-foreground`:`text-foreground-subtle`,title:C.exact?`The only recordings volume on this node — this camera can only be here.`:`The recordings DEFAULT. This node has several recordings volumes and the per-camera placement is not reported by recording.getStorageUsage, so this is where footage lands by default rather than a per-camera fact.`,children:[C.label,!C.exact&&s(`span`,{className:`ml-1 text-foreground-subtle`,children:`(default)`})]})},{key:`used`,header:`Used`,align:`right`,nowrap:!0,render:e=>s(`span`,{className:`tabular-nums`,children:K(e.usedBytes)})},{key:`actions`,header:``,align:`right`,render:e=>n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{k(e)},disabled:D.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:bg-amber-500/10 hover:text-amber-500 disabled:opacity-50`,title:`Apply retention policy now`,children:[s(Se,{className:`h-3 w-3`}),`Prune`]}),n(`button`,{onClick:()=>{A(e)},disabled:O.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete all footage`,children:[s(G,{className:`h-3 w-3`}),`Delete`]})]})}],[g,C,k,A,D.isPending,O.isPending]);if(f&&!d)return n(`div`,{className:`flex items-center gap-2 py-8 text-xs text-foreground-subtle`,children:[s(z,{className:`h-4 w-4 animate-spin`}),`Loading storage usage…`]});if(!d)return s(N,{icon:R,title:`No storage data`,description:`The recording node has not reported any storage usage yet.`});let M=d.devices.length;return n(`div`,{className:`flex flex-col gap-6`,children:[n(`section`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[s(l,{label:`Total used`,icon:s(R,{className:`h-3 w-3`}),footer:`${String(M)} camera${M===1?``:`s`} on ${d.nodeId}`,children:K(d.totalUsedBytes)}),w!==null&&w.severity!==null&&s(l,{label:`Free on recordings volumes`,icon:s(R,{className:`h-3 w-3`}),footer:`across ${String(w.knownVolumes)} volume${w.knownVolumes===1?``:`s`} of ${K(w.totalBytes)}`+(w.unknownVolumes>0?` · ${String(w.unknownVolumes)} did not report capacity`:``),children:s(`span`,{className:`tabular-nums ${Q[w.severity]}`,children:K(w.freeBytes)})}),x.map(e=>{let t=wt(e),r=e.locationId??e.root??`default`;return s(l,{label:`Disk: ${kt(e,_)}`,footer:t===null?`${K(e.usedBytes)} of recordings · volume capacity unknown`:`${K(t.freeBytes)} free of ${K(t.totalBytes)} · ${K(e.usedBytes)} recordings (${$(t.recordingsFraction)})`,children:t===null?s(`span`,{className:`tabular-nums`,children:K(e.usedBytes)}):n(`div`,{className:`flex items-center gap-2`,title:`Volume fill — everything on the disk, not only recordings. Warn at 85%, critical at 95%.`,children:[s(`div`,{className:`h-2 flex-1 overflow-hidden rounded bg-muted`,children:s(`div`,{className:`h-full rounded ${Ot[t.severity]}`,style:{width:$(t.fraction)}})}),s(`span`,{className:`tabular-nums text-xs ${Q[t.severity]}`,children:$(t.fraction)})]})},r)})]}),n(`section`,{className:`flex items-center gap-2 text-xs`,children:[s(`label`,{htmlFor:`prune-reason`,className:`text-foreground-subtle`,children:`Prune reason`}),s(`select`,{id:`prune-reason`,value:c,onChange:e=>{let t=Dt.find(t=>t.value===e.target.value);t&&u(t.value)},className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:Dt.map(e=>s(`option`,{value:e.value,children:e.label},e.value))})]}),M===0?s(N,{icon:R,title:`No recorded footage`,description:`No camera has recorded footage on this node yet.`}):s(F,{columns:j,rows:[...d.devices],rowKey:e=>e.deviceId,minWidthPx:480})]})}function jt(){return n(`div`,{className:`flex flex-col gap-8`,children:[n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Footage on disk`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`What recorded footage occupies, per camera and per volume, with prune-by-policy and delete-all-footage.`}),s(`div`,{className:`mt-3`,children:s(At,{})})]}),n(`div`,{children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Recording node & folders`}),s(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that records and serves playback, and the storage locations footage is written to.`}),s(`div`,{className:`mt-3`,children:s(vt,{})})]})]})}function Mt(){return s(_e,{icon:U,title:`Recordings`,subtitle:`Recorded footage and the durable event store — what each occupies, where it is written, and the operations that move or reconcile both.`,children:s(be,{tabs:[{id:`storage`,label:`Recordings`,icon:R,content:s(jt,{})},{id:`cameras`,label:`Cameras`,icon:W,content:s(ke,{})},{id:`exports`,label:`Export`,icon:U,content:s($e,{})},{id:`events`,label:`Events`,icon:H,content:s(Re,{})},{id:`activity`,label:`Activity`,icon:B,content:s(Oe,{})},{id:`management`,label:`Management`,icon:Ce,content:s(ht,{})}]})})}export{Mt as RecordingsPage};