@camstack/addon-admin-ui 1.2.424 → 1.2.426

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 (123) hide show
  1. package/dist/assets/{AddonAssetIcon-DpRGr6eL.js → AddonAssetIcon-1n6JfETw.js} +1 -1
  2. package/dist/assets/Addons-DcQF2HWV.js +4 -0
  3. package/dist/assets/{AdminPage-3IR6Hk67.js → AdminPage-BayHfBSO.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-4SkTwpI5.js → AdminSectionedPage-9IY48UKI.js} +1 -1
  5. package/dist/assets/{AiProfiles-CCMhrKGR.js → AiProfiles-CP8RCOWa.js} +1 -1
  6. package/dist/assets/{BrokerForm-knwGVvlP.js → BrokerForm-CVQRFpTU.js} +1 -1
  7. package/dist/assets/Build-mKTtALNy.js +40 -0
  8. package/dist/assets/{Calendars-sN0mcmx8.js → Calendars-63ZesTzm.js} +1 -1
  9. package/dist/assets/{Cluster-B-8RNoJl.js → Cluster-1D-vyKfY.js} +1 -1
  10. package/dist/assets/{ClusterStepModel-B-BZmPhO.js → ClusterStepModel-T7xQsXN8.js} +1 -1
  11. package/dist/assets/CompositionEditor-BRCQx5kS.js +1 -0
  12. package/dist/assets/{CompositionEditorPage-DGyqKaco.js → CompositionEditorPage-BrPXl60f.js} +1 -1
  13. package/dist/assets/{Data-BTU_oZFA.js → Data-CuarRBth.js} +1 -1
  14. package/dist/assets/{DeviceDetail-Cfj4KCjC.js → DeviceDetail-I4ZB53GH.js} +2 -2
  15. package/dist/assets/{DeviceDoActionFields-BKCPjNdJ.js → DeviceDoActionFields-crgCrJSp.js} +1 -1
  16. package/dist/assets/{Devices-Co8gpzOv.js → Devices-BGcheInk.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-BycHbxaz.js → EmbedPlayerPage-DZve5q4n.js} +1 -1
  18. package/dist/assets/Identity-OZbZYHE_.js +1 -0
  19. package/dist/assets/{IntegrationDetail-Dh95e-ov.js → IntegrationDetail-wgO85DgR.js} +1 -1
  20. package/dist/assets/IntegrationHub-B1IIsNvb.js +1 -0
  21. package/dist/assets/{Integrations-BIRnKHr_.js → Integrations-BJ8YilHM.js} +1 -1
  22. package/dist/assets/Integrations-D1TLRWe3.js +1 -0
  23. package/dist/assets/{Library-BjmrQqUX.js → Library-BB99yEEE.js} +1 -1
  24. package/dist/assets/Locations-qkPy4yUO.js +3 -0
  25. package/dist/assets/Logs-kaf6YI9u.js +1 -0
  26. package/dist/assets/{MotionZonesSettings-ChKtiEGg.js → MotionZonesSettings-ZKRlA5gv.js} +1 -1
  27. package/dist/assets/MyAccess-DJMmxXtZ.js +2 -0
  28. package/dist/assets/Network-CpWThxQe.js +1 -0
  29. package/dist/assets/NodeAddonsSettingsPanel-D4T6WpHA.js +1 -0
  30. package/dist/assets/Notifications-B4AABX6U.js +1 -0
  31. package/dist/assets/{PrivacyMaskSettings-Cpbt8TIJ.js → PrivacyMaskSettings-DzwxrD1B.js} +1 -1
  32. package/dist/assets/{Recordings-YZtEVeYP.js → Recordings-BGHR8x4_.js} +1 -1
  33. package/dist/assets/{ScanNetworkModal-CYyrjEsB.js → ScanNetworkModal-BBFG95i_.js} +1 -1
  34. package/dist/assets/{SceneMonitorEditor-CaUk0FYV.js → SceneMonitorEditor-MMVFnPh6.js} +1 -1
  35. package/dist/assets/SessionsList-B-ST9nsT.js +2 -0
  36. package/dist/assets/{Showroom-BIRKF0dk.js → Showroom-D3SvRPvv.js} +1 -1
  37. package/dist/assets/{System-myhV_MaL.js → System-BjDn5cIv.js} +1 -1
  38. package/dist/assets/{Terminal-CZIrea8T.js → Terminal-Cd68HdDW.js} +1 -1
  39. package/dist/assets/{Viewer-CMNSu0lq.js → Viewer-BtdOcDPJ.js} +1 -1
  40. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DtZaYSQH.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-Db4GEmHF.js} +1 -1
  41. package/dist/assets/{addon-icons-context-BavDxTPH.js → addon-icons-context-DeAZhH9N.js} +1 -1
  42. package/dist/assets/{archive-3M3ozcU0.js → archive-CIl2Clyv.js} +1 -1
  43. package/dist/assets/{authed-media-D56U-4qh.js → authed-media-DEosobUG.js} +1 -1
  44. package/dist/assets/{bell-off-5pZv5sKf.js → bell-off-DlTo6h_B.js} +1 -1
  45. package/dist/assets/{boxes-1pLz5hUM.js → boxes-BT3FYBTS.js} +1 -1
  46. package/dist/assets/circle-slash-wO8v909U.js +1 -0
  47. package/dist/assets/client-D-ClAw3a.js +358 -0
  48. package/dist/assets/{cloud-upload-DGbtl7kl.js → cloud-upload-FFgr-Bus.js} +1 -1
  49. package/dist/assets/crop-AF56iSVW.js +1 -0
  50. package/dist/assets/{device-integration-icon-58hSioYq.js → device-integration-icon-DULhoOk4.js} +1 -1
  51. package/dist/assets/device-picker-model-BWYGPnze.js +1 -0
  52. package/dist/assets/dist-BDlPgqtC.js +358 -0
  53. package/dist/assets/{dist-IPJ6n7RQ.js → dist-Kz53UTaO.js} +1 -1
  54. package/dist/assets/{eraser-DTrp1IIZ.js → eraser-B4ziYD-z.js} +1 -1
  55. package/dist/assets/{file-up-_ULNp_05.js → file-up-Dm9E2rU8.js} +1 -1
  56. package/dist/assets/{hard-drive-download-HQkd9SLO.js → hard-drive-download-DmAkyZu-.js} +1 -1
  57. package/dist/assets/{history-DsADJO4y.js → history-B7Br9-pG.js} +1 -1
  58. package/dist/assets/{hostInit-BnVYvsSx.js → hostInit-D2KXxrgo.js} +1 -1
  59. package/dist/assets/{icons-Bxqmmfam.js → icons-CCewF9ms.js} +1 -1
  60. package/dist/assets/index-DFK8wKFu.js +4 -0
  61. package/dist/assets/{key-CA_hxP8X.js → key-ZXEHTEbP.js} +1 -1
  62. package/dist/assets/{key-round-ClhiHwZi.js → key-round-S9D6eShB.js} +1 -1
  63. package/dist/assets/{layers-BGwl7aC_.js → layers-oP1uhEhI.js} +1 -1
  64. package/dist/assets/{list-ordered-DQLdQGqt.js → list-ordered-DIyB2-8L.js} +1 -1
  65. package/dist/assets/{location-owned-usage-C0JfjuuV.js → location-owned-usage-DWEbmaK0.js} +1 -1
  66. package/dist/assets/{log-in-BdBi9Cme.js → log-in-BPdhdZAD.js} +1 -1
  67. package/dist/assets/{memory-stick-bH-Zu951.js → memory-stick-BQg97R_B.js} +1 -1
  68. package/dist/assets/{message-square-plus-DR40ZFS6.js → message-square-plus-BSNGyUpm.js} +1 -1
  69. package/dist/assets/{mf-entry-bootstrap-0-3c4040d4.js → mf-entry-bootstrap-0-96997ff0.js} +2 -2
  70. package/dist/assets/{mic-off-B59TJIsA.js → mic-off-Dzx4N9nb.js} +1 -1
  71. package/dist/assets/{monitor-off-MgjzxGSz.js → monitor-off-Bewl4xJ0.js} +1 -1
  72. package/dist/assets/{monitor-smartphone-DFPo3Yqb.js → monitor-smartphone-BBqLfRLn.js} +1 -1
  73. package/dist/assets/mount-BWYGPnze.js +1 -0
  74. package/dist/assets/{notification-schedule-field-Do5St1AP.js → notification-schedule-field-B_e7occL.js} +1 -1
  75. package/dist/assets/{octagon-alert-CLNUgI7g.js → octagon-alert-CyhdXSRT.js} +1 -1
  76. package/dist/assets/{player-overlays-Bthpd_DK.js → player-overlays-V9UtVzaL.js} +1 -1
  77. package/dist/assets/{recycle-BX6tC5Kj.js → recycle-Bk1hihs6.js} +1 -1
  78. package/dist/assets/remoteEntry-B7VRbZTK.js +1 -0
  79. package/dist/assets/{scan-eye-g_G1zr8C.js → scan-eye-B2rYni8O.js} +1 -1
  80. package/dist/assets/{scissors-DPmzGgFW.js → scissors-CYNXjLiq.js} +1 -1
  81. package/dist/assets/{search-x-CsJ3H_wC.js → search-x-CBruBHBg.js} +1 -1
  82. package/dist/assets/{send-BpC90RvW.js → send-DroR6ITx.js} +1 -1
  83. package/dist/assets/{settings-2-C6pa-cFa.js → settings-2-B61v9YLv.js} +1 -1
  84. package/dist/assets/{speaker-Bm3mNOfG.js → speaker-D-Jov9sv.js} +1 -1
  85. package/dist/assets/{src-ASnW4RHZ.js → src-0C0o0YVH.js} +8 -8
  86. package/dist/assets/{timer-reset-DWjb5kqA.js → timer-reset-C8in2gzS.js} +1 -1
  87. package/dist/assets/{ungroup-CzP2h8wq.js → ungroup-CHnEC_da.js} +1 -1
  88. package/dist/assets/{unlink-BezflwNM.js → unlink-CslfTlgU.js} +1 -1
  89. package/dist/assets/{usb-DxAlRKBK.js → usb-B5CzoN_q.js} +1 -1
  90. package/dist/assets/{use-scenes-feed-CkLZiYoX.js → use-scenes-feed-Dm82V1NT.js} +1 -1
  91. package/dist/assets/{use-stationary-objects-NTMGbBMt.js → use-stationary-objects-CgauQ_lU.js} +1 -1
  92. package/dist/assets/useEventInvalidation-BWYGPnze.js +1 -0
  93. package/dist/assets/{useNodeUrlSelection-Bu7K2QJ7.js → useNodeUrlSelection-gZ1IWqyB.js} +1 -1
  94. package/dist/assets/user-round-B5fwfTG9.js +1 -0
  95. package/dist/assets/{user-x-DRrbPPEj.js → user-x-x2vSZ8z0.js} +1 -1
  96. package/dist/assets/{video-BYsOgJ3d.js → video-pPaTYzzY.js} +1 -1
  97. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-vl-v33Ir.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DOjtJ7CO.js} +2 -2
  98. package/dist/index.html +9 -9
  99. package/dist/server/addon.js +71 -11
  100. package/package.json +1 -1
  101. package/dist/assets/Addons-Cy2vW-GC.js +0 -4
  102. package/dist/assets/Build-PdGYsW_d.js +0 -40
  103. package/dist/assets/CompositionEditor-DPCOBkAG.js +0 -1
  104. package/dist/assets/Identity-Bu6tV79U.js +0 -1
  105. package/dist/assets/IntegrationHub-DA5-5WRz.js +0 -1
  106. package/dist/assets/Integrations-BPYi4NML.js +0 -1
  107. package/dist/assets/Locations-BDXa1xhP.js +0 -3
  108. package/dist/assets/Logs-CmQq6sTE.js +0 -1
  109. package/dist/assets/MyAccess-DNUWFuuc.js +0 -2
  110. package/dist/assets/Network-CON3pH6E.js +0 -1
  111. package/dist/assets/NodeAddonsSettingsPanel-BJZk7zTu.js +0 -1
  112. package/dist/assets/Notifications-CJCLRZ7G.js +0 -1
  113. package/dist/assets/SessionsList-BwcT1neM.js +0 -2
  114. package/dist/assets/circle-slash-DdZfDqQG.js +0 -1
  115. package/dist/assets/client-CPAjuyjS.js +0 -358
  116. package/dist/assets/crop-C8MmVjW3.js +0 -1
  117. package/dist/assets/device-picker-model-BviOkzyX.js +0 -1
  118. package/dist/assets/dist-BNYk89Zc.js +0 -358
  119. package/dist/assets/index-D6a_-apt.js +0 -4
  120. package/dist/assets/mount-BviOkzyX.js +0 -1
  121. package/dist/assets/remoteEntry-DJ-QvmdF.js +0 -1
  122. package/dist/assets/useEventInvalidation-BviOkzyX.js +0 -1
  123. package/dist/assets/user-round-CVUJjDWY.js +0 -1
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-Cyuzqnbw.js";import{I as t,K as n,Q as r,S as i,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{A as p,D as m,It as h,Jr as g,Mn as _,N as v,Nr as y,Nt as b,O as x,Qi as S,T as C,Tr as w,V as T,Xt as E,Yn as D,_i as O,_t as k,ar as A,b as j,bn as M,dt as N,j as P,k as F,lr as I,nr as ee,ot as te,pn as ne,rr as L,sn as R,un as z,ut as re,v as ie,y as ae,yi as oe,yn as se,z as B}from"./player-overlays-Bthpd_DK.js";import{c as ce,l as le,t as ue}from"./video-BYsOgJ3d.js";import{a as de,i as fe,n as pe,r as me,t as he}from"./usb-DxAlRKBK.js";import{t as ge}from"./crop-C8MmVjW3.js";import{t as _e}from"./layers-BGwl7aC_.js";import{An as ve,Ci as ye,Cn as be,Dn as xe,En as Se,On as Ce,Tn as we,Ur as Te,Wr as Ee,c as De,gi as Oe,jn as ke,kn as Ae,l as je,m as Me,wn as Ne}from"./client-CPAjuyjS.js";import{n as Pe}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{An as Fe,As as Ie,Bn as V,C as Le,Cs as Re,Dn as ze,E as Be,En as Ve,Es as He,F as Ue,Fs as We,Gl as H,Gs as Ge,H as Ke,Hs as qe,Ht as Je,J as Ye,Js as Xe,Jt as Ze,Ks as Qe,Ln as $e,Ls as et,Mt as tt,O as nt,On as rt,Ps as it,Rn as at,Rs as ot,S as st,Ss as ct,T as lt,Tn as ut,Ts as dt,Tt as ft,Us as pt,Ut as mt,Vs as ht,Vt as U,W as gt,Xl as _t,Y as vt,Ys as yt,Yt as bt,Zl as xt,Zn as St,_n as W,_r as Ct,ac as wt,an as Tt,ar as G,bs as Et,cc as Dt,cn as Ot,dc as kt,dn as At,du as K,fu as jt,gu as Mt,hn as Nt,hu as Pt,ic as Ft,in as It,iu as Lt,jn as Rt,kn as zt,lc as Bt,ln as Vt,ma as Ht,mn as Ut,mr as Wt,mu as Gt,oc as Kt,pn as qt,pr as Jt,pu as Yt,qs as Xt,qt as Zt,r as Qt,ru as $t,sc as en,sn as tn,un as nn,vn as rn,vs as an,vt as on,w as sn,wn as cn,ws as ln,xs as un,ys as dn,zs as fn}from"./src-ASnW4RHZ.js";import{H as pn,J as mn,Q as hn}from"./index-D6a_-apt.js";import"./useEventInvalidation-BviOkzyX.js";import{t as gn}from"./NodeAddonsSettingsPanel-BJZk7zTu.js";import{a as _n,c as vn,d as yn,g as bn,h as xn,i as Sn,l as Cn,n as wn,o as Tn,p as En,r as Dn,s as On,t as kn}from"./board-model-Bmts6hrg.js";var An=`step`,jn=[An,`acc`];function Mn(e,t){return`${e}/${t}`}function Nn(e,t,n){let r=n.step!==null&&e.includes(n.step),i=n.acc!==null&&t.includes(n.acc);return{stepId:r?n.step:null,acceleratorId:i?n.acc:null,staleStepId:n.step!==null&&n.step!==``&&!r&&e.length>0?n.step:null}}function Pn(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 Fn(e){return e}function In(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Ln(e,t){return typeof e==`boolean`?e:Fn(t)}function Rn(e,t){return{pipeline:Ln(In(e,`detect`),t),audio:Ln(In(e,`audio`),t),ingest:Ln(In(e,`ingest`),t)}}function zn(e,t,n){let r=e?.find(e=>e.nodeId===t);return Rn(r?.settings,n)}function Bn({selectedNodeId:e,onSelect:t,refreshToken:n}){let{nodes:r}=jt(),{data:a}=et(void 0),{data:s}=ht(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=r??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return i(`div`,{className:`flex flex-col h-full`,children:[i(`button`,{type:`button`,onClick:()=>t(Oo),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:[d(ce,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Assignments, load balancing, roles`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let r=e===n.id,a=c.get(n.id)??0,l=n.isHub?z:g,u=zn(s,n.id,n.isHub),f=n.isOnline?null:on(Pn(n.lastSeen));return i(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-danger flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),i(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[i(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(ue,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`text-danger`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(G,{variant:u.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),d(G,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),i(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[i(`span`,{children:[u,` online`]}),f>0&&i(`span`,{className:`text-danger`,children:[f,` offline`]})]})]})}function Vn({nodeId:e,refreshToken:t}){let{nodes:n}=jt(),r=n?.find(t=>t.id===e),a=Yt(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?i(`div`,{className:`px-6 py-4 border-b border-border`,children:[i(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-danger/10 text-danger`,children:`offline`}),r.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:r.cpuModel??`CPU`}),d(`span`,{children:`•`}),i(`span`,{children:[r.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),i(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),i(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&i(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:i(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var Hn=[`assignments`,`tree`,`engines`,`logs`];r();function Un({refreshToken:e,nodeId:t}){let[n,r]=u(new Map),{nodes:o}=K();Pt(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=He(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.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}},[l,o]);if(t){let e=l.get(t);return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(q,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(q,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(q,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(q,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(q,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(q,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),i(`tbody`,{children:[m.map(([e,t])=>i(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}var Wn={active:!1,pinned:!1,nodeId:null,reason:``};function Gn(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function Kn(e,t,n){let r=new Map(t.map(e=>[e.deviceId,e])),i=new Map(n.map(e=>[e.deviceId,e]));return e.map(e=>{let t=r.get(e.id),n=i.get(e.id),a=t?{active:!0,pinned:t.pinned,nodeId:t.agentNodeId,reason:t.reason??``}:Wn,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:Wn;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:Wn,audio:o}}).toSorted(Gn)}function qn(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function Jn(e,t){let n=new Map(t.map(e=>[e.deviceId,e.assignment]));return e.map(e=>{let t=n.get(e.deviceId);return t===void 0?e:{...e,detection:qn(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:qn(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:qn(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function Yn(e,t,n){let r=(t,n,r)=>({active:t!==null&&t===e,pinned:n,nodeId:t,reason:r??``});return t.map(({deviceId:e,assignment:t})=>({deviceId:e,deviceName:n(e),detection:r(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:r(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:r(t.audioNodeId,t.pinned.audio,t.reasons.audio)})).filter(e=>e.detection.active||e.decoder.active||e.audio.active).toSorted(Gn)}function Xn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>{let n=t.get(e);return n!==void 0&&n!==``?n:e}}function Zn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??`Camera ${e}`}function Qn(e,t,n){return[{value:`auto`,label:`Auto`},...[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])].map(e=>({value:e,label:`Pin → ${n(e)}`}))]}function $n({roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:i,emphasizeOnNodeId:a}){if(n.nodeId===null)return null;let o=n.nodeId,s=a===void 0?!1:n.active&&o===a;return d(Zt,{roleId:e,roleLabel:t,nodeName:r(o),colorId:bt(i,o),emphasized:s,pinned:n.pinned})}function er({detection:e,decoder:t,audio:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o}){let s=(e,t,n)=>d($n,{roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o},e);return i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[s(`detection`,`Detection`,e),s(`decode`,`Decode`,t),s(`audio`,`Audio`,n)]})}function tr({snap:e}){if(e===void 0)return d(`div`,{className:`flex h-8 items-center text-[11px] text-foreground-subtle`,title:`No metrics in the last 10 s — the camera has no session running`,children:`no live data`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=tt(t);return i(`div`,{className:`flex h-8 min-w-0 flex-col justify-center font-mono text-[10px] leading-tight tabular-nums`,children:[i(`span`,{className:`inline-flex min-w-0 items-center gap-1 ${c.textColor}`,children:[d(Ue,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate font-semibold uppercase tracking-wider`,children:c.label}),d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[`/`,o.toFixed(0),` fps`]})]}),i(`span`,{className:`truncate text-foreground-subtle`,children:[d(`span`,{className:`text-foreground`,children:r.toFixed(0)}),` ms`,a>0&&i(`span`,{className:`ml-1 text-warning`,children:[`q`,a]}),i(`span`,{className:s>0?`ml-1 text-warning`:`ml-1`,children:[`drops `,s]})]})]})}r();var nr=1e4,rr=5e3;function ir(e){let[t,n]=u(new Map);return Pt(`pipeline.camera-metrics-snapshot`,t=>{let r=t.data;typeof r.deviceId==`number`&&(e!==void 0&&r.nodeId!==e||n(e=>new Map(e).set(r.deviceId,r)))}),f(()=>{if(t.size===0)return;let e=setInterval(()=>{n(e=>{let t=Date.now()-nr,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},rr);return()=>clearInterval(e)},[t.size]),t}var ar=3e5;function or({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:i}){return d(H,{"aria-label":`Node pin`,title:`Auto lets each session pick its node; a pin keeps the camera on one node.`,value:e.pinned&&e.nodeId!==null?e.nodeId:`auto`,disabled:r,options:[...Qn(e,t,n)],onChange:e=>i(e.target.value)})}function sr({deviceId:e,nodeId:t}){let n=c(),{data:r}=ot({deviceId:e},{refetchOnMount:`always`}),{data:i}=We({nodeId:t},{staleTime:ar}),a=wt({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`accelerator: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),l=r?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l),f=o.find(e=>e.key===l),p=[{value:`auto`,label:`Any accelerator`},...u?[{value:l,label:`${f?`${W(f)} (${l})`:l} (not enabled)`}]:[],...s.map(e=>({value:e.key,label:`${W(e)} · ${e.format}`}))];return d(H,{"aria-label":`Inference device pin`,title:`Pin detection to one accelerator of the node, or let each session pick.`,value:l,disabled:a.isPending,options:p,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value})})}r();function cr(e){let t=n(null);return e.nodeId!==null&&(t.current=e),t.current}function lr({deviceId:e,state:t,...n}){let r=cr(t);return i(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[d(or,{state:t,...n}),r?.nodeId==null?d(H,{"aria-label":`Inference device pin (no node yet)`,title:`An accelerator is pinned on the camera's node; this camera has not run on one yet.`,disabled:!0,defaultValue:`auto`,options:[{value:`auto`,label:`Any accelerator`}]}):d(sr,{deviceId:e,nodeId:r.nodeId})]})}function ur({state:e,nameOf:t}){let n=cr(e);if(n?.nodeId==null)return d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`— no session yet`});let r=e.active&&e.nodeId!==null,a=n.pinned?`pinned`:`auto · ${n.reason||`capacity`}`;return i(`div`,{"data-testid":`resolved-placement`,className:`flex w-40 min-w-0 flex-col leading-tight`,title:n.pinned?void 0:`An unpinned camera is placed again at every session start, so this can change between sessions.`,children:[i(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[d(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${r?`bg-success`:`bg-foreground-subtle/40`}`}),d(`span`,{"data-testid":`resolved-placement-node`,className:`truncate font-medium ${r?`text-foreground`:`text-foreground-muted`}`,children:t(n.nodeId)})]}),d(`span`,{className:`truncate pl-3 text-[10px] ${n.pinned?`text-warning`:`text-foreground-subtle`}`,children:r?a:`${a} · idle, last session`})]})}function dr({deviceId:e,deviceName:t}){let[n,r]=u(!1);return i(o,{children:[d(xt,{icon:M,variant:`ghost`,size:`sm`,"aria-label":`Stream brokers of ${t}`,title:`Stream brokers & clients`,onClick:()=>r(!0)}),d(ut,{open:n,onOpenChange:r,children:i(ze,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[d(Fe,{children:i(Rt,{children:[t,` — stream brokers & clients`]})}),d(Ve,{children:n&&d(cn,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e,instanceId:`pipeline-row/${e}`,config:{variant:`compact`}})})]})})]})}function fr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function pr(e,t){return t.size===0?!0:t.has(e)}var mr=[{value:`active`,label:`Active`},{value:`recently-active`,label:`Recently active`},{value:`inactive`,label:`Inactive`}];r();var hr=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function gr(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function _r(){let e=c();Qt([`pipelineOrchestrator`,`getPipelineAssignments`],hr),Qt([`pipelineOrchestrator`,`getAudioAssignments`],hr),Qt([`pipelineOrchestrator`,`getCameraStatuses`],hr);let{data:t}=Ht({isCamera:!0,projection:`slim`}),{data:n}=et(void 0),{data:r}=dt(void 0),{data:o}=Ie({}),{data:s}=ht(void 0),{nodes:l}=K(),f=ir(),p=a(()=>Xn(l),[l]),m=a(()=>Ze(s),[s]),h=a(()=>l.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[l]),g=a(()=>Jn(Kn((t??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),n??[],r??[]),o??[]),[t,n,r,o]),[_,v]=u(()=>new Set),y=a(()=>g.filter(e=>pr(fr({hasPipelineAssignment:e.pipeline.active,hasFreshMetrics:f.has(e.deviceId)}),_)),[g,f,_]),b=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},x=()=>gr(e),S=Re({onSuccess:x}),C=Bt({onSuccess:x}),w=S.isPending||C.isPending,T=[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[d(mn,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName}),e.disabled&&d(G,{variant:`default`,children:`off`})]})},{key:`placement`,header:`Placement`,width:`w-80`,notSortableReason:`A pair of controls — editing one would move the row under the cursor.`,render:e=>d(lr,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:h,nameOf:p,pending:w,onChange:t=>t===`auto`?C.mutate({deviceId:e.deviceId}):S.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:e=>d(er,{detection:e.detection,decoder:e.decoder,audio:e.audio,nameOf:p,colorByNodeId:m})},{key:`resolved`,header:`Running on`,width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:p(e.pipeline.nodeId),render:e=>d(ur,{state:e.pipeline,nameOf:p})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>f.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(tr,{snap:f.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>d(dr,{deviceId:e.deviceId,deviceName:e.deviceName})}],E=t===void 0?`Loading cameras…`:g.length===0?`No cameras`:`No cameras match this activity filter.`;return i(`div`,{className:`flex flex-col gap-2`,children:[d(`nav`,{"aria-label":`Filter by camera activity`,"data-testid":`assignments-activity-filter`,children:d(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:mr.map(e=>{let t=_.has(e.value);return d(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:Lt(ae,t?ie:j),onClick:()=>b(e.value),children:e.label},e.value)})})}),d(Je,{columns:T,rows:y,rowKey:e=>e.deviceId,minWidthPx:920,mobileMode:`scroll`,maxBodyHeight:mt,emptyMessage:E})]})}r();function vr({nodeId:e}){let t=c();Qt([`pipelineOrchestrator`,`getCameraStatuses`],hr);let{data:n}=Ie({}),{data:r}=ht(void 0),{data:i}=Ht({isCamera:!0,projection:`slim`}),{nodes:o}=K(),s=ir(),l=a(()=>Xn(o),[o]),u=a(()=>Ze(r),[r]),f=a(()=>Yn(e,n??[],Zn((i??[]).map(e=>({id:e.id,name:e.name})))),[e,n,i]),p=o.filter(t=>t.isOnline&&t.id!==e),m=()=>gr(t),h=Re({onSuccess:m}),g=Bt({onSuccess:m}),_=ct({onSuccess:m}),v=Dt({onSuccess:m}),y=e=>[...e.detection.active?p.map(t=>({id:`detect-${t.id}`,label:`Move detection to ${t.name}`,onClick:()=>h.mutate({deviceId:e.deviceId,agentNodeId:t.id})})):[],...e.audio.active?p.map(t=>({id:`audio-${t.id}`,label:`Move audio to ${t.name}`,onClick:()=>_.mutate({deviceId:e.deviceId,nodeId:t.id})})):[],{id:`unpin-detect`,label:`Unpin detection`,hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>g.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:`Unpin audio`,hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>v.mutate({deviceId:e.deviceId})}];return d(Je,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>d(mn,{to:`/devices/${String(e.deviceId)}`,className:`block w-44 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:t=>d(er,{detection:t.detection,decoder:t.decoder,audio:t.audio,nameOf:l,colorByNodeId:u,emphasizeOnNodeId:e})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(tr,{snap:s.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>d(gt,{items:y(e),title:`Move ${e.deviceName}`})}],rows:f,rowKey:e=>e.deviceId,minWidthPx:560,mobileMode:`scroll`,maxBodyHeight:mt,emptyMessage:n===void 0?`Loading cameras…`:`No camera runs on this node right now`})}function yr({nodeId:e,refreshToken:t}){let{nodes:n}=K(),r=n.find(t=>t.id===e)?.name??e;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(Un,{refreshToken:t,nodeId:e}),i(`div`,{className:`space-y-2`,children:[i(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:[`Cameras on `,r]}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The roles each camera runs here right now. Move a role or unpin it from the row menu; pins for every camera are on Cluster → Assignments.`})]}),d(vr,{nodeId:e})]})]})}r();function br(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function xr({nodeId:e,refreshToken:t}){let n=c(),r=St(),o=dn({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:s}=Et({nodeId:e}),l=Yt(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??s??null,u=l===null;Qt([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=kt({nodeId:e}),{values:p}=Gt(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=a(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),_=t=>{let n=f??[];if(n.length===0){o.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await r({title:`Kill engine`,message:`${String(n.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:`Kill engine`,variant:`danger`})&&o.mutate({nodeId:e,engine:t,force:!0})})()};return i(`div`,{className:`space-y-6`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(l??[]).length,` engine(s) resident in RAM. `,(f??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),i(`tbody`,{children:[u&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!u&&(l??[]).map(e=>{let t=e.kind===`device-pool`;return i(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[d(t?_e:g,{className:`h-3 w-3`}),t?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(re,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),d(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?d(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>d(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),d(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),d(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?d(`span`,{className:`text-foreground-subtle`,children:br(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(f??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:t?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):i(V,{variant:`ghost`,size:`sm`,disabled:o.isPending,onClick:()=>_(e.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[d(h,{className:`h-3.5 w-3.5`}),`Kill`]})})]},e.engineKey)}),!u&&(l??[]).length===0&&d(`tr`,{children:d(`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.`})})]})]})}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`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.`]}),o.isError&&d($e,{message:`Kill failed: ${o.error instanceof Error?o.error.message:`unknown error`}`})]})}var Sr=`pipeline-runner`,Cr=200;function wr({nodeId:e}){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),i(`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.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(ft,{agentId:e,addonId:Sr,limit:Cr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}r();function Tr({nodeId:e,title:t}){let{data:n}=pn(),{data:r}=et(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),c=ir(e),l=a(()=>{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 l.length===0?i(`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`]}):i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[i(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=tt(e.metrics.phase);return i(`div`,{title:`${t} · ${n.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] ${n.badgeClass}`,children:[d(Ue,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}function Er(e,t,n){return e.map(e=>{if(e.key===t)return e;let r=e.steps[n];if(!r||r.settings===void 0)return e;let{settings:i,...a}=r,o={...e.steps};return Object.keys(a).length>0?o[n]=a:delete o[n],{...e,steps:o}})}function Dr(e,t,n){let r=e.filter(e=>e.key!==t).toSorted((e,t)=>e.key.localeCompare(t.key)),i=[...r.filter(e=>!e.enabled),...r.filter(e=>e.enabled),...e.filter(e=>e.key===t)],a;for(let e of i){let t=e.steps?.[n]?.settings;!t||Object.keys(t).length===0||(a={...a,...t})}return a}function Or(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}var kr=`pipeline-orchestrator`;function Ar({addonId:e,highlightLabel:t}){let n=xe(e),{data:r}=Wt({addonId:kr});if(n.length===0)return null;let a=ve(r??null)[e]??{};return i(`section`,{className:`space-y-1.5 border-t border-border/60 pt-3`,"aria-label":`Cluster-wide settings`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:T,children:`Cluster-wide settings`}),d(mn,{to:Fo(e),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Edit in Cluster → Settings ›`})]}),n.map(e=>i(`div`,{className:`${p} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[d(`span`,{className:P,children:e.label}),d(`span`,{className:v,children:d(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),d(`p`,{className:B,children:`One value for every node and camera — this step writes into a shared index.`})]})}function jr({rows:e}){return i(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>i(`li`,{className:`${C} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-foreground-muted`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:e.modelId??`—`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.sourceLabel})]},e.id))}),d(`p`,{className:B,children:`To change a model, open that accelerator's cell in the table.`})]})}r();function Mr(e,n){let[r,i]=hn(),o=r.get(An),s=r.get(`acc`),c=a(()=>Nn(e,n,{step:o,acc:s}),[e,n,o,s]),l=t(e=>{i(t=>{let n=new URLSearchParams(t);return e(n),n},{replace:!0})},[i]);return{selection:c,open:t(e=>l(t=>{t.set(An,e.stepId),e.acceleratorId===void 0?t.delete(`acc`):t.set(`acc`,e.acceleratorId)}),[l]),close:t(()=>l(e=>{e.delete(An),e.delete(`acc`)}),[l])}}function Nr(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function Pr(e){return e.split(`.`)[0]??e}function Fr(e,t,n){return{id:Mn(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${Pr(t)} · ${W(n)}`,shortLabel:`${Pr(t)} · ${rn(n)}`,nodeLabel:Pr(t),disabled:!n.enabled}}function Ir(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>Fr(e,t,n))}function Lr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>Fr(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>Fr(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[Fr(e.id,e.name,a)]})}function Rr(e,t,n){return{modelId:qt({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function zr(e,t,n){let r=Nr(e,`object-detection`);if(r===null)return;let i=qt({catalog:r,device:t.device,base:t.device.steps?.[`object-detection`]?.modelId,override:n});if(i===void 0)return;let a=r.models.find(e=>e.id===i);return{modelId:i,name:a?.name??i,supplies:a?.suppliesSteps??[]}}function Br(e,t,n){return!Te(e)||n===void 0?!1:Ee(e,t,n.supplies).effective}function Vr(e,t){return e!==null&&Ut(e.models,t.device.format)}function Hr(e){return Vr(e.addon,e.acc)?e.clusterModelId===void 0?{kind:`enabled`,modelId:e.model.modelId??`Auto`,overridden:e.model.source===`camera`,...e.rootName===void 0?{}:{suppliedByRoot:e.rootName},...e.jumpTo===void 0?{}:{jumpTo:e.jumpTo}}:{kind:`enabled`,modelId:e.clusterModelId,clusterWide:!0}:e.gatedOn?e.jumpTo===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:e.jumpTo}:{kind:`na`}}function Ur(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function Wr(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=xe(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function Gr(e){return e.flatMap(e=>[{node:e,depth:0},...Gr(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function Kr(e,t){return e.flatMap(e=>{let n=Kr(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}r();function qr(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:W(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Jr({tree:e,searchRows:r,accelerators:o,cellState:s,stepBadge:c,disabledCount:l,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:y}){let b=St(),x=$t(),{selection:S,open:C,close:w}=Mr(a(()=>Gr(e).map(e=>e.node.addonId),[e]),a(()=>o.map(e=>e.id),[o])),[T,E]=u(``),[D,O]=u(null),[k,A]=u(null),j=n(null),M=n(null),P=n(null),F=n(null),I=a(()=>Le(r,T),[r,T]),ee=a(()=>T.trim()===``?e:Kr(e,new Set(I.map(e=>e.addonId))),[e,I,T]),te=e=>I.find(t=>t.addonId===e)?.matchedField??null,ne=a(()=>o.map(qr),[o]),L=e=>o.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),R=o.find(e=>e.id===S.acceleratorId)??null,z=S.stepId!==null,re=t(async e=>{if(m){if(!await b({title:`Discard unsaved changes?`,message:`This step has changes that are not saved yet.`,confirmLabel:`Discard`,variant:`danger`}))return;h()}e()},[b,m,h]),ie=()=>{requestAnimationFrame(()=>F.current?.focus())},ae=(e,t,n=!1)=>{if(e===S.stepId&&(t?.id??null)===S.acceleratorId){n&&ie();return}let r=()=>{O(te(e)),C({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&ie()};e===S.stepId?r():re(r)},oe=()=>{let e=S.stepId;re(()=>{if(w(),e!==null){let t=R===null?null:vt({agentNodeId:R.nodeId,deviceKey:R.deviceKey});requestAnimationFrame(()=>j.current?.focusCell(e,t))}})},se=e=>{if(e.key===`Enter`){let t=I[0];if(t===void 0)return;e.preventDefault(),ae(t.addonId,void 0,!0)}else e.key===`Escape`&&E(``)},ce=x?d(Be,{onClick:oe}):d(xt,{icon:N,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:oe});return i(`div`,{ref:M,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),P.current?.focus()),e.key===`Escape`&&t&&z&&(e.preventDefault(),oe())},children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),d(`input`,{ref:P,type:`search`,value:T,onChange:e=>E(e.target.value),onKeyDown:se,placeholder:`Filter steps or settings /`,"aria-label":`Filter steps or settings`,className:`h-9 w-56 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30 md:h-7`}),l>0&&i(`label`,{className:`inline-flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(Tt,{checked:f,onChange:e=>p(e.target.checked)}),`Show disabled accelerators (`,l,`)`]}),_]}),S.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:[`The link names a step this pipeline does not have (`,S.staleStepId,`).`]}),ee.length===0?i(`p`,{className:`${B} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:[`No step matches “`,T,`”.`]}):d(Ye,{ref:j,tree:ee,agents:ne,label:v,getCellState:(e,t)=>{let n=L(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>ae(e,L(t),n),onStepClick:(e,t)=>ae(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:z&&S.stepId!==null&&R!==null?{addonId:S.stepId,agentNodeId:R.nodeId,deviceKey:R.deviceKey}:null,fallbackNodeId:k,onFallbackNodeChange:A,reserveRightPx:z&&!x?432:0}),d(nt,{open:z,anchor:M,onClose:oe,label:`Step settings`,children:S.stepId!==null&&y({stepId:S.stepId,accelerator:R,matchedField:D,closeButton:ce,onEscape:oe,headingRef:e=>{F.current=e}})})]})}r();function Yr(e){f(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}r();function Xr(e,t){let n=e.filter(e=>e.steps?.[t]?.settings!==void 0),r=e=>e.toSorted((e,t)=>e.key.localeCompare(t.key));return r(n.filter(e=>e.enabled))[0]?.key??r(n)[0]?.key??r(e.filter(e=>e.enabled))[0]?.key??e[0]?.key}function Zr(e,t){let n=t.settings===void 0?void 0:Xr(e,t.stepId),r=e.map(e=>{let r={...e.steps},i=r[t.stepId]??{},a=t.models[e.key],o=t.jumps[e.key],s=e.key===n&&t.settings!==void 0?Object.keys(t.settings).length>0?t.settings:void 0:i.settings,c=a===void 0?i.modelId:a??void 0,l=o===void 0?i.jumpDeviceKey:o||void 0,u={...c===void 0?{}:{modelId:c},...s===void 0?{}:{settings:s},...l===void 0?{}:{jumpDeviceKey:l}};return Object.keys(u).length>0?r[t.stepId]=u:delete r[t.stepId],{key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:r}});return n===void 0?r:Er(r,n,t.stepId)}function Qr(e,t,n){if(t===null)return 0;let r=Object.entries(t.models).filter(([n,r])=>(r??void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.modelId).length,i=Object.entries(t.jumps).filter(([n,r])=>(r||void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.jumpDeviceKey).length,a=new Set([...Object.keys(n),...Object.keys(t.settings??{})]),o=t.settings===void 0?0:[...a].filter(e=>!Me(n[e],t.settings?.[e])).length;return r+i+o}function $r({nodeId:e,nodeName:t,toolbar:n}){let r=c(),s=We({nodeId:e},{refetchOnMount:`always`}),l=an({nodeId:e},{refetchOnMount:`always`}),f=Ae(Wt({addonId:`pipeline-orchestrator`}).data??null),p=s.data?.devices??[],m=l.data??null,[h,g]=u(null),[_,v]=u(null),[y,b]=u(null),x=Xe({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),S=a(()=>m?st(m):[],[m]),C=a(()=>Gr(S),[S]),[w,E]=u(!1),D=a(()=>Ir(e,t,p,w),[e,t,p,w]),O=a(()=>Ir(e,t,p),[e,t,p]),k=O.length>=2,A=(e,t)=>(t===void 0?void 0:Dr(p,t.deviceKey,e))??{},j=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return O.find(e=>e.deviceKey===r);if(!Vr(e,t))return O.filter(n=>n.id!==t.id&&Vr(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},M=(e,t)=>{let n=Nr(m,e),r=Ro(e),i=zr(m,t),a=A(e,t),o=j(n,t);return Hr({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?Rr(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...Br(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:f[e]??r.defaultModelId}:{},...o?{jumpTo:rn(o.device)}:{}})},N=C.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Wr(Nr(m,e.addonId))}));if(s.isLoading||l.isLoading)return d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`});if(m===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`});let P=i(`span`,{className:B,children:[`Accelerators:`,` `,d(`span`,{className:`text-foreground`,children:O.length>0?O.map(e=>rn(e.device)).join(` · `):`none enabled`}),p.some(e=>!e.enabled)&&i(o,{children:[` `,`— off:`,` `,p.filter(e=>!e.enabled).map(rn).join(`, `)]}),` `,`·`,` `,d(mn,{to:Io(),className:`text-primary hover:underline`,children:`Cluster → Load balancing ›`})]});return d(Jr,{tree:S,searchRows:N,accelerators:D,cellState:M,disabledCount:p.filter(e=>!e.enabled).length,showDisabled:w,onShowDisabledChange:E,dirty:h!==null&&Qr(p,h,A(h.stepId,D[0]))>0,onDiscard:()=>g(null),summary:P,...n===void 0?{}:{toolbar:n},label:`Detection steps`,renderDetail:({stepId:n,accelerator:r,matchedField:a,closeButton:s,onEscape:c,headingRef:l})=>{let u=Nr(m,n);if(u===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let f=h?.stepId===n?h:null,S=r??O[0]??D[0],C=A(n,S),w=f?.settings??C,E=Qr(p,f,C),M=e=>{b(null),g(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},N=Ro(n),P=Vt(u),F=S===void 0?void 0:zr(m,S),I=e=>{let t=f?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},ee=S===void 0?void 0:Rr(u,S,{nodePin:I(S)}).modelId,te=D.length>1&&D.some(e=>!Me(A(n,e),C)),ne=e=>{let t=I(e),r=Rr(u,e,{nodePin:t}),a=zr(m,e),s=Br(n,f?.settings??A(n,e),a),c=f?.jumps[e.deviceKey],l=j(u,e,c),p=Vr(u,e)?s&&a?d(tn,{rootModel:a,stepModelId:r.modelId}):void 0:i(o,{children:[`No `,e.device.format,` build of this step.`,` `,l?`It runs on ${l.shortLabel} instead.`:`It does not run here.`]}),h=k?i(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Run on`}),d(H,{"aria-label":`Run on`,value:c??e.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:`Auto (this accelerator, or the next one that can run it)`},...O.filter(t=>t.id!==e.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:t=>M({jumps:{...f?.jumps,[e.deviceKey]:t.target.value}})}),d(`span`,{className:B,children:`Routes this step (and its child steps) to another accelerator of this node.`})]}):void 0;return{label:e.label,format:e.device.format,modelId:r.modelId,source:r.source===`node`?`node`:`default`,sourceLabel:r.source===`node`?`node pin`:`hardware default`,models:Nt(u.models??[],e.device.format),defaultModelId:u.defaultModelIdByFormat?.[e.device.format]??u.defaultModelId,expanded:_===e.id,onToggle:()=>v(t=>t===e.id?null:e.id),onChangeModel:t=>M({models:{...f?.models,[e.deviceKey]:t}}),...t===void 0?{}:{onReset:()=>M({models:{...f?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...p===void 0?{}:{note:p},...h===void 0?{}:{extra:h},changed:f?.models[e.deviceKey]!==void 0||c!==void 0}},L=()=>{f!==null&&x.mutate({agentNodeId:e,inferenceDevices:Or(Zr(p,f))},{onSuccess:()=>{g(null),b({kind:`saved`})},onError:e=>b({kind:`error`,error:e.message})})};return d(lt,{ref:l,title:r===null?`${u.name} · ${t}`:`${u.name} · ${r.label}`,subtitle:r===null?`${u.slot} · every accelerator of ${t}`:`${u.slot} · ${r.device.format} · base for every camera that lands here`,leading:s,onEscape:c,saveBar:{dirtyCount:E,saving:x.isPending,status:y?.kind??null,...y?.error===void 0?{}:{error:y.error},onSave:L,onDiscard:()=>g(null)},children:i(`div`,{className:`space-y-3`,children:[i(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[d(`h3`,{className:T,children:`Model`}),N!==null&&S!==void 0?d(zo,{step:N,engineFormat:S.device.format,runnableModelIds:Nt(u.models??[],S.device.format).map(e=>e.id)}):D.length===0?i(`p`,{className:B,children:[`No accelerator is enabled on this node —`,` `,d(mn,{to:Io(),className:`text-primary hover:underline`,children:`enable one in Cluster → Load balancing`}),`.`]}):r===null?d(jr,{rows:D.map(e=>{let t=Rr(u,e,{nodePin:I(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):d(sn,{...ne(r)},r.id)]}),(P.length>0||F!==void 0)&&N===null&&i(`section`,{"aria-label":`Settings`,className:`space-y-2 border-t border-border/60 pt-2`,children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`settings-scope`,children:[`Node-wide: these settings apply on every accelerator of `,t,`.`]}),te&&d(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2 py-1 text-[11px] text-warning`,children:`This step's settings differ between this node's accelerators. Saving makes the values shown here node-wide.`}),d(ei,{addon:u,fields:P,settings:w,modelId:Ot(u,ee,w,F),root:F,highlight:a,onChange:e=>M({settings:e})})]}),d(Ar,{addonId:n,highlightLabel:a})]})})}})}function ei({addon:e,fields:t,settings:n,modelId:r,root:i,highlight:a,onChange:o}){let s=t.find(e=>`label`in e&&e.label===a)?.key??null;return Yr(s===null?null:At(s)),d(nn,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:`Node`},modelId:r,...i===void 0?{}:{rootModel:i},highlightKey:s,onChangeLayer:o})}r();function ti({nodeId:e,refreshToken:t}){let n=St(),[r,a]=u(null),{nodes:s}=K(),c=s.find(t=>t.id===e)?.name??e,l=Ge({onSuccess:e=>{a(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${c} 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`})&&(a(null),l.mutate({agentNodeId:e}))};return i(`div`,{className:`space-y-2`,children:[d(Tr,{nodeId:e}),d($r,{nodeId:e,nodeName:c,toolbar:i(o,{children:[r&&d(`span`,{className:`text-[11px] text-success`,children:r}),l.isError&&d(`span`,{className:`text-[11px] text-danger`,children:l.error instanceof Error?l.error.message:`Reset failed`}),d(V,{variant:`outline`,size:`sm`,onClick:()=>{f()},disabled:l.isPending,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:l.isPending?`Resetting…`:`Reset to default`})]})})]})}var ni=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],ri=`decoder-nodeav`,ii=`ntab`,ai={decoder:`engine`},oi={engine:`Engine & decoder`},si=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function ci({nodeId:e,refreshToken:t}){let[n,r]=hn(),{nodes:a}=K(),o=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??ri,s=[...ni,o],c=n.get(ii),l={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:d(yr,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:d(ti,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:d(xr,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:d(wr,{nodeId:e})}},u=Hn.map(e=>l[e]);return i(`div`,{className:`flex flex-col h-full`,children:[d(Vn,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:d(gn,{nodeId:e,addonIds:s,level:`global`,fieldScope:`perNode`,emptyMessage:si,tabAliases:ai,tabLabelOverrides:oi,extraTabs:u,activeTab:c===null?null:ai[c]??c,onActiveTabChange:e=>r(t=>{let n=new URLSearchParams(t);n.set(ii,e);for(let e of jn)n.delete(e);return n},{replace:!0})})})]})}function li(){return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Camera placement`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pin a camera to a node, or to one accelerator of its node; Auto lets each session pick. Decode always runs with detection. Load, shares and caps are on Load balancing.`})]}),d(_r,{})]})}function ui(e){return`${Math.round(e*100)}%`}function di(e){return`${e} session${e===1?``:`s`}`}var fi={"intel-npu":`Intel NPU`,"intel-igpu":`Intel iGPU`,"amd-igpu":`AMD iGPU (WebGPU)`,"amd-npu":`AMD XDNA NPU`,"x86-cpu":`CPU`,"arm-cpu":`CPU`,"apple-ane":`Apple Neural Engine`,coral:`Coral Edge TPU`},pi={"intel-core-ultra":`Intel Core Ultra`,"intel-n-series":`Intel N-series`,"apple-m-base":`Apple M (base)`,"apple-m-pro":`Apple M Pro / Max / Ultra`,"amd-phoenix":`AMD Ryzen Phoenix / Hawk Point`,unknown:`Not measured`};function mi(e){return e===null?`—`:fi[e]??e}function hi(e){return e===null?`—`:pi[e]??e}function gi(e){switch(e.kind){case`capacity`:return`Capacity ${di(e.sessions)} ≥ min ${e.minSessions}.`;case`tie-faster`:return`As accurate as ${e.over} (within ${ui(e.recallDelta)} recall) and faster.`;case`stepped-down`:return`${e.from} would not fit the load on ${e.limitedBy}; ${e.to} is the most accurate that does.`;case`no-fit-lightest`:return`No model reaches ${di(e.minSessions)} per device; the one with the most capacity (${di(e.sessions)}) is used.`;case`derived-latency`:return`${e.modelId}: latency estimated from a similar chip, not measured on this one.`;case`cpu-device`:return`CPU fallback device: picked on its own.`;case`coral-untouched`:return`Coral: left as is (no YOLOv9 build exists for it).`;case`device-disabled`:return`Disabled: not changed.`;case`device-unavailable`:return`Not available on the node right now: not changed.`;case`node-offline`:return`Node offline: nothing on it will change.`;case`no-hardware-facts`:return`Hardware could not be read: nothing on this node will change.`;case`no-measured-data`:return`This hardware has no measured data: nothing on this node will change.`;case`no-family-build`:return`No YOLOv9 build for the ${e.format} format: not changed.`;case`kept-custom-pin`:return`Custom model ${e.modelId} is pinned on ${e.deviceKey}: Auto tune skips this device.`}}function _i(e,t){switch(e.kind){case`detector-store-cluster-wide`:return`Per-camera detector thresholds are not tied to a node, so they are cleared for every camera — including cameras that run on skipped nodes (${e.skippedNodes.map(t).join(`, `)}).`;case`detector-store-unreadable`:return`Per-camera detector thresholds could not be read (${e.error}); those will not be cleared.`;case`coral-enabled`:return`${t(e.nodeId)}: the Coral (${e.deviceKey}) is enabled and keeps running its SSD model, which finds far fewer people than YOLOv9. Consider disabling it.`;case`custom-pin-kept`:return e.deviceId===null?`${t(e.nodeId)}: custom model ${e.modelId} pinned on ${e.deviceKey??`—`} — Auto tune skips this node device.`:`Camera ${e.deviceId} pins custom model ${e.modelId} on ${t(e.nodeId)} — Auto tune keeps that override and its thresholds.`;case`custom-registry-unreadable`:return`The custom-model registry could not be read (${e.error}): every pin to a model outside the measured catalog is kept.`}}function vi(e){let t=e.nodeChanges.reduce((e,t)=>e+t.modelPins.length,0),n=e.nodeChanges.reduce((e,t)=>e+t.thresholds.length,0),r=new Set([...e.cameraClears.map(e=>e.deviceId),...e.detectorStoreClears.map(e=>e.deviceId)]);return{modelChanges:t,thresholdClears:n,cameraOverrideClears:e.cameraClears.length,detectorStoreClears:e.detectorStoreClears.length,camerasTouched:r.size}}function yi(e){let t=vi(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function bi(e,t,n){let r=e.nodeChanges.find(e=>e.nodeId===t&&e.deviceKey===n)?.modelPins.find(e=>e.stepId===`object-detection`);return r===void 0?null:{before:r.before,after:r.after}}function xi(e,t){return e?.kind===`node-benchmark`?`measured on this node, ${new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}`:`from the latency table — benchmark this node to measure it`}r();var Si=[.3,.4,.5];function Ci(e){return Si.some(t=>t===e)}var wi=[1,2,3,4,6,8];function Ti({plan:e,node:t,nodeName:n}){return i(`section`,{className:x,"data-testid":`auto-tune-node-${t.nodeId}`,children:[i(`header`,{className:`${F} flex flex-wrap items-center gap-2`,children:[d(g,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${T} min-w-0 flex-1`,children:n(t.nodeId)}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[hi(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?d(G,{variant:`warning`,children:`Not changed`}):t.acceleratorModelId!==null&&d(G,{variant:`info`,children:t.acceleratorModelId})]}),t.reasons.length>0&&d(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:t.reasons.map((e,t)=>d(`li`,{children:gi(e)},t))}),d(`div`,{className:`overflow-x-auto`,children:i(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:i(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Device`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Capacity`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Detector`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Why`})]})}),d(`tbody`,{children:t.devices.map(n=>{let r=bi(e,t.nodeId,n.deviceKey);return i(`tr`,{className:`border-t border-border align-top`,children:[i(`td`,{className:`px-3 py-1.5`,children:[d(`div`,{className:`font-mono text-foreground`,children:n.deviceKey}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:mi(n.accelerator)})]}),i(`td`,{className:`px-3 py-1.5 text-foreground-muted`,children:[n.chosen===null?`—`:`${n.chosen.capacitySessions} session${n.chosen.capacitySessions===1?``:`s`} at ${e.cameraFps} fps`,n.chosen!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n.chosen.fps,` fps, `,Math.round(e.headroom*100),`% kept free`,d(`div`,{children:xi(n.chosen.source)})]})]}),d(`td`,{className:`px-3 py-1.5`,children:n.chosen===null?d(`span`,{className:`text-foreground-subtle`,children:`unchanged`}):r!==null&&r.before!==r.after?i(`span`,{children:[d(`span`,{className:`text-foreground-subtle`,children:r.before??`default`}),` → `,d(`span`,{className:`font-medium text-foreground`,children:r.after})]}):d(`span`,{className:`text-foreground`,children:n.chosen.modelId})}),d(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>d(`div`,{children:gi(e)},t))})]},n.deviceKey)})})]})})]})}function Ei({plan:e,nameOf:t,nodeName:n}){return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[i(`div`,{children:[d(`div`,{className:T,children:`Node settings`}),e.nodeChanges.length===0?d(`div`,{className:`text-foreground-subtle`,children:`No change.`}):d(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.nodeChanges.flatMap(e=>[...e.modelPins.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: `,t.before??`default`,` → `,t.after??`step default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/pin`)),...e.thresholds.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: reset `,t.keys.join(`, `),` to the model default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),i(`div`,{children:[d(`div`,{className:T,children:`Camera overrides cleared`}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?d(`div`,{className:`text-foreground-subtle`,children:`None.`}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,r)=>i(`li`,{children:[t(e.deviceId),` — `,n(e.nodeId),e.deviceKey===null?` (whole pipeline)`:` · ${e.deviceKey}`,` — `,e.stepId,e.modelIdBefore===null?``:`: model ${e.modelIdBefore} removed`,e.keys.length>0?`; ${e.keys.join(`, `)} reset`:``]},`c${r}`)),e.detectorStoreClears.map(e=>i(`li`,{children:[t(e.deviceId),` — detector thresholds: `,e.keys.join(`, `),` reset`]},`d${e.deviceId}`))]})]})]})}function Di({result:e}){return e.kind===`refused`?d(`div`,{className:`text-xs text-warning`,children:`Another apply is already running.`}):e.kind===`stale`?d(`div`,{className:`text-xs text-warning`,children:`The configuration changed since the plan was shown. Review the updated plan below and apply again.`}):i(`ul`,{className:`text-xs`,"data-testid":`auto-tune-result`,children:[e.kind===`aborted`&&d(`li`,{className:`text-danger`,children:`A model could not be downloaded: nothing was changed.`}),e.phases.map(e=>i(`li`,{className:e.ok?`text-foreground-muted`:`text-danger`,children:[e.ok?`✓`:`✗`,` `,e.phase,`: `,e.detail]},e.phase))]})}function Oi(){let e=c(),[t,n]=u(.4),[r,o]=u(2),[s,l]=u(!1),[f,p]=u(!1),[m,h]=u(null),{data:g}=pn(),_=a(()=>new Map((g??[]).map(e=>[e.id,e.name])),[g]),v=e=>_.get(e)??`Camera ${e}`,{nodes:y}=K(),b=a(()=>Xn(y),[y]),S=qe({headroom:t,minSessionsPerDevice:r},{enabled:s,refetchOnWindowFocus:!1}),C=un({onSuccess:t=>{h(t),p(!1),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.kind===`applied`&&S.refetch()}}),w=m?.kind===`stale`?m.plan:S.data,D=w===void 0?null:vi(w);return i(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[i(`section`,{className:x,children:[i(`header`,{className:`${F} flex flex-wrap items-center gap-2`,children:[d(E,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${T} min-w-0 flex-1`,children:`Auto tune`})]}),i(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[d(`p`,{children:`Picks, for every accelerator, the most accurate YOLOv9 detector that still carries at least the chosen number of cameras at once, from the node's hardware and measured speeds. Nothing is measured or estimated about your cameras' activity. Applying it sets those models and clears every model and threshold override — node level and per camera — so each model runs its own default thresholds. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`Keep free`}),d(H,{"aria-label":`Share of each accelerator kept free`,value:String(t),options:Si.map(e=>({value:String(e),label:`${Math.round(e*100)}% of each accelerator`})),onChange:e=>{let t=Number(e.target.value);Ci(t)&&n(t)}})]}),i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`At least`}),d(H,{"aria-label":`Minimum parallel sessions per device`,value:String(r),options:wi.map(e=>({value:String(e),label:`${e} camera${e===1?``:`s`} at once per accelerator`})),onChange:e=>{let t=Number(e.target.value);wi.some(e=>e===t)&&o(t)}})]}),d(V,{size:`sm`,variant:`secondary`,onClick:()=>{h(null),l(!0),s&&S.refetch()},children:S.isFetching?`Computing…`:w===void 0?`Compute plan`:`Recompute`}),w!==void 0&&d(V,{size:`sm`,disabled:yi(w),onClick:()=>p(!0),children:`Apply…`})]}),S.error!==null&&d(`div`,{className:`text-danger`,children:S.error.message}),m!==null&&d(Di,{result:m}),D!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[D.modelChanges,` model change(s), `,D.thresholdClears,` node threshold reset(s), `,D.cameraOverrideClears+D.detectorStoreClears,` camera override(s) on `,D.camerasTouched,` camera(s).`]})]})]}),w?.warnings.map((e,t)=>d(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:_i(e,b)},t)),w?.nodes.map(e=>d(Ti,{plan:w,node:e,nodeName:b},e.nodeId)),w!==void 0&&d(ut,{open:f,onOpenChange:p,children:i(ze,{width:`lg`,scroll:`body`,children:[i(Fe,{children:[d(Rt,{children:`Apply auto tune?`}),d(rt,{children:`These are all the changes. Every override listed is removed and cannot be restored.`})]}),d(Ve,{children:d(Ei,{plan:w,nameOf:v,nodeName:b})}),i(zt,{children:[d(V,{variant:`ghost`,onClick:()=>p(!1),children:`Cancel`}),d(V,{variant:`danger`,disabled:C.isPending,onClick:()=>C.mutate({planHash:w.planHash,headroom:t,minSessionsPerDevice:r}),children:C.isPending?`Applying…`:`Apply`})]})]})})]})}var ki={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 Ai(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function ji(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function Mi(e,t,n){let r=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let i=t.get(e.key)??(n?0:null),a=e.weight>0?e.weight:1;return{key:e.key,label:W(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?Ai(a,r):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i!==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 Ni(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);return e.nodes.map(r=>{let i=t.get(r.id),a=Mi(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),ji(i)),o=r.isOnline&&r.detectEnabled,s=r.weight>0?r.weight:1,c=i?.load.attachedCameras??null;return{nodeId:r.id,name:r.name,isOnline:r.isOnline,detectEnabled:r.detectEnabled,reported:i!==void 0,attachedCameras:c,activeCameras:i?.load.activeCameras??null,maxCameras:r.maxCameras,capacityPct:c!==null&&r.maxCameras!==null&&r.maxCameras>0?Ai(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?Ai(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}r();var Pi=2e4,Fi=3e5;function Ii({stats:e,targetWeights:t}){let{nodes:n}=K(),r=te().trpcClient,o=ln(void 0,{placeholderData:l,staleTime:Pi,refetchInterval:Pi,refetchOnWindowFocus:!0}),c=ht(void 0,{staleTime:Fi}),u=a(()=>n.map(e=>e.id),[n]),f=s({queries:u.map(e=>({queryKey:Pe(Mt.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Fi,refetchOnWindowFocus:!1,placeholderData:l}))}),p=a(()=>{let e={};return u.forEach((t,n)=>{let r=f[n]?.data;r&&(e[t]=r.devices)}),e},[u,f.map(e=>e.dataUpdatedAt).join(`|`)]),h=a(()=>{let e=new Map;for(let t of c.data??[])e.set(t.nodeId,t.settings);return e},[c.data]),g=a(()=>n.map(e=>{let n=h.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:Rn(n,e.isHub).pipeline,weight:t?.[e.id]??yn(n,`detectWeight`)??1,maxCameras:yn(n,`maxCameras`)}}),[n,h,t]),_=o.data??[],v=a(()=>Ni({nodes:g,loads:_,devicesByNode:p}),[g,_,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),x=o.dataUpdatedAt>0?Date.now()-o.dataUpdatedAt:null,C=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return d(U,{headingId:`load-balancing-node-load`,title:`Node load`,icon:S,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[b,` running · `,y,` attached ·`,` `,o.data===void 0?`reading…`:`${x===null?`—`:`${Math.round(x/1e3)}s`} old`]}),children:d(`div`,{className:m,children:v.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>d(Li,{row:e,placed:C.get(e.nodeId)},e.nodeId))})})})}function Li({row:e,placed:t}){let n=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`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&&i(`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:[d(b,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(k,{className:`h-2.5 w-2.5`}),` offline`]})]}),i(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:n,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share (1 h)`,value:t?.observedShare===null||t===void 0?`—`:`${Math.round(t.observedShare*100)}%`,title:`Time-weighted share of the cluster's PARALLEL detection sessions this node carried over the last hour — the quantity a share holds. '—' = no session ran here in the window.`}),d(J,{label:`Peak · yields`,value:t===void 0?`—`:`${t.peakSessions} · ${t.yieldsAway}`,title:`Most sessions this node ran at once in the last hour, and how many share turns it handed to another node because it was full or drowning.`}),d(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&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(Ri,{row:e})]})}function Ri({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):i(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[i(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(w,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`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`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(zi,{device:e},e.key))})]})}function zi({device:e}){let t=e.exclusion;return i(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(g,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?i(o,{children:[i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,title:e.sessions===null?`Not known: the node did not report, or runs a session no device accounts for.`:void 0,children:[`· `,e.sessions??`—`,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):i(`span`,{className:`truncate text-foreground-subtle/80`,title:ki[t],children:[`excluded — `,ki[t]]})]})}function J({label:e,value:t,title:n}){return i(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Bi(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Vi(e){let t={},n={};for(let r of e.nodes){if(r.share===null||r.share<=0)continue;t[r.nodeId]=r.share;let e=Object.fromEntries(r.devices.filter(e=>e.share>0).map(e=>[e.deviceKey,e.share]));Object.keys(e).length>0&&(n[r.nodeId]=e)}return{nodes:t,devices:n}}function Hi(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Ui(e){return e.reason===`disabled`?`${e.deviceKey} is not enabled on any node — sessions ignore this pin`:`no node offers ${e.deviceKey} — sessions ignore this pin`}function Wi(e,t){if(t===void 0||t.source===`manual`||t.autoPending)return{nodes:e,readOnly:t!==void 0&&t.source!==`manual`};let n=new Map(t.nodes.map(e=>[e.nodeId,e.configuredPct]));return{nodes:e.map(e=>({...e,weight:Math.round(n.get(e.id)??e.weight)})),readOnly:!0}}function Gi(e,t){let n=e.nodes.filter(e=>!e.eligible);if(n.length===0)return null;let r=e.nodes.filter(e=>e.eligible).map(e=>`${t(e.nodeId)} ${Math.round(e.effectivePct)}%`).join(`, `);return`${n.map(e=>t(e.nodeId)).join(`, `)} cannot take sessions — ${n.length===1?`its share goes`:`their shares go`} to the others: ${r}`}var Ki=[{value:`hardware`,label:`Hardware`,hint:`Each node’s share follows what its accelerators can carry at their Auto tune models, from the measured speed of its hardware. No load is measured or estimated.`},{value:`benchmark`,label:`Benchmark`,hint:`Each node’s share follows its own node-benchmark results. A node without results uses its hardware capacity instead, and says so.`},{value:`manual`,label:`Manual`,hint:`The sliders below, as you set them.`}];function qi(e){return e===`no-benchmark-results`?`no benchmark results yet — sized from hardware`:e===`partial-benchmark-results`?`benchmark results miss some of its accelerators — sized from hardware`:null}function Ji(e,t){if(e.source!==`benchmark`)return null;let n=e.nodes.filter(e=>e.capacityFallback!==null);return n.length===0?null:n.map(e=>`${t(e.nodeId)}: ${qi(e.capacityFallback)??``}`).join(` · `)}r();function Yi(e,t,n){return Math.min(Math.max(e,t),n)}function Xi(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function Zi(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:Yi(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function Qi(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function $i({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:a,footnote:s,readOnly:c=!1}){let[l,p]=u(()=>Xi(e)),[m,h]=u(new Set);f(()=>{p(Xi(e)),h(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let g=e.map(e=>e.id),_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=(e,t)=>{p(n=>Zi(n,e,t,m,g))},y=()=>{let t=Qi(l,g,m),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...m]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:a??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let b=e.length===1;return i(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=l[e.id]??0,a=m.has(e.id);return i(`div`,{className:`flex items-center gap-3`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),d(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:c||t||a||b,onChange:t=>v(e.id,Number(t.target.value)),onPointerUp:()=>y(),onKeyUp:()=>y(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),i(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),!c&&d(`button`,{type:`button`,onClick:()=>_(e.id),disabled:t||b,"aria-pressed":a,title:a?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${a?`text-amber-400`:`text-foreground-subtle`}`,children:d(a?ee:L,{className:`h-3.5 w-3.5`})})]},e.id)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:s??d(o,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}function ea(e){let t=e.steps?.[`object-detection`]?.modelId;return typeof t==`string`&&t.length>0?t:typeof e.defaultModelId==`string`&&e.defaultModelId.length>0?e.defaultModelId:null}r();function ta(e){let t=W(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:g,hue:`slate`}:r===`npu`?{label:t,Icon:re,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:de,hue:`violet`}:n===`edgetpu`?{label:t,Icon:he,hue:`emerald`}:{label:t,Icon:g,hue:`slate`}}var na={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function ra({nodeId:e,nodeName:t,isOnline:n,suggestedMaxSessions:r,autoDeviceShares:s}){let l=c(),{data:p,isLoading:m}=We({nodeId:e},{refetchInterval:15e3}),h=Xe({onSettled:()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),g=p?.devices??[],_=p?.reachable??n,[v,y]=u({});f(()=>{y(Object.fromEntries(g.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[g.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let b=a(()=>g.filter(e=>v[e.key]?.enabled??e.enabled).length,[g,v]),[x,S]=u(null),C=x??b>0,w=t=>{let n=g.map(e=>{let n=t[e.key]??T(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});h.mutate({agentNodeId:e,inferenceDevices:Or(n)})},T=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),E=e=>{if(!e.available)return;let t=v[e.key]??T(e),n={...v,[e.key]:{...t,enabled:!t.enabled}};y(n),w(n)},D=(e,t)=>{let n=v[e.key]??T(e),r={...v,[e.key]:{...n,maxSessions:t}};y(r),w(r)},A=a(()=>g.filter(e=>(v[e.key]?.enabled??e.enabled)&&e.available),[g,v]),j=a(()=>A.map(e=>({id:e.key,name:ta(e).label,weight:s===void 0?v[e.key]?.weight??e.weight:Math.round(s[e.key]??0)})),[A,v,s]);return i(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[i(`button`,{type:`button`,onClick:()=>S(!C),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":C,children:[d(O,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${C?`rotate-90`:``}`}),d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),d(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:_?b>=2?i(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[d(_e,{className:`h-3.5 w-3.5`}),b,` accelerators`]}):b===1?d(`span`,{className:`text-foreground-subtle`,children:`single default`}):d(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):i(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[d(k,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),C&&i(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[_?m&&g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):g.length===0?d(`p`,{className:`rounded-lg 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.`}):d(`ul`,{className:`space-y-2`,children:g.map(e=>{let t=ta(e),n=v[e.key]??T(e),a=n.enabled&&e.available,s=ea({defaultModelId:e.defaultModelId,steps:n.steps});return i(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[d(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${na[t.hue]}`,children:d(t.Icon,{className:`h-4.5 w-4.5`})}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),d(G,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&d(G,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`font-mono`,children:e.key}),s!==null&&i(o,{children:[d(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:[`root model`,` `,d(`span`,{className:`font-mono text-foreground/80`,children:s})]})]})]})]}),a&&i(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),d(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);D(e,r!=null&&r>0?r:null)},disabled:h.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),a&&d(ia,{suggested:r?.[e.key]??null,current:n.maxSessions,pending:h.isPending,onApply:t=>D(e,t)}),d(It,{checked:a,onCheckedChange:()=>E(e),disabled:!e.available||h.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):d(aa,{}),_&&A.length>=2&&i(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[i(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[d(pe,{className:`h-3.5 w-3.5`}),`Accelerator share`]}),d($i,{nodes:j,pending:h.isPending,onCommitWeights:e=>{let t={...v};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}y(t),w(t)},weightLabel:`Accelerator share`,readOnly:s!==void 0,footnote:s===void 0?d(o,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`}):d(o,{children:`Automatic: each accelerator's share follows its measured throughput at its model. Switch the node shares to manual to set them yourself.`})})]}),h.isError&&i(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,h.error instanceof Error?h.error.message:`unknown error`]})]})]})}function ia({suggested:e,current:t,pending:n,onApply:r}){return e===null||e<1||e===t?null:i(V,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`,children:[`use `,e]})}function aa(){return i(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[d(k,{className:`h-6 w-6 text-foreground-subtle/60`}),d(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),d(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}r();var oa=3600*1e3,sa=2e4,ca=.4;function la({refreshToken:e,onOpenAutoTune:t}){let n=c(),{nodes:r}=K(),s=ht(void 0),f=Ht({isCamera:!0,projection:`slim`}),p=fn({windowMs:oa},{refetchInterval:sa,placeholderData:l}).data,h=it(void 0,{refetchInterval:sa,placeholderData:l}).data,_=()=>{Cn(n),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},v=Ft({onSuccess:_}),y=Kt({onSuccess:()=>{_(),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),b=yt({onSuccess:_}),x=pt(),[S,w]=u(!1),T=h?.source,D=T===`benchmark`?`benchmark`:`hardware`,O=en({headroom:ca,source:D},{enabled:S,staleTime:1/0}),k=O.data,A=a(()=>{let e=new Map((s.data??[]).map(e=>[e.nodeId,e.settings]));return r.filter(t=>Rn(e.get(t.id),t.isHub).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:yn(n,`detectWeight`)??1,maxCameras:yn(n,`maxCameras`)}})},[r,s.data]),j=e=>r.find(t=>t.id===e)?.name??e,M=Zn((f.data??[]).map(e=>({id:e.id,name:e.name}))),N=k?Hi(k):void 0,P=Wi(A,h),F=T!==`manual`,ee=e=>{if(h===void 0||h.source===`manual`||h.autoPending)return;let t=h.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},te=h?Gi(h,j):null,ne=h?Ji(h,j):null,L=Ki.find(e=>e.value===T)?.hint;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(gn,{nodeId:`hub`,addonIds:[Dn],level:`global`,sectionIds:[`load`],title:`Placement policy`,description:`How a new detection session picks its node and device, and what happens when a node falls behind. 'Honour shares' (default) holds the shares below for PARALLEL sessions.`}),d(Un,{refreshToken:e}),d(Ii,{stats:p,...h!==void 0&&h.source!==`manual`&&!h.autoPending?{targetWeights:Object.fromEntries(h.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),d(U,{headingId:`load-balancing-node-shares`,title:`Node shares`,icon:pe,actions:i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{role:`radiogroup`,"aria-label":`Share source`,className:`flex items-center gap-1`,children:Ki.map(e=>d(V,{role:`radio`,"aria-checked":T===e.value,variant:T===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:y.isPending||h===void 0,onClick:()=>{T!==e.value&&y.mutate({source:e.value})},children:e.label},e.value))}),i(V,{variant:`outline`,size:`sm`,onClick:()=>{w(!0),S&&O.refetch()},disabled:O.isFetching,children:[d(I,{className:`h-3.5 w-3.5`}),O.isFetching?`Suggesting…`:D===`benchmark`?`Suggest from benchmark`:`Suggest from hardware`]}),i(V,{variant:`ghost`,size:`sm`,onClick:t,children:[d(E,{className:`h-3.5 w-3.5`}),`Auto tune`]}),i(V,{variant:`outline`,size:`sm`,onClick:()=>x.mutate(void 0),disabled:x.isPending,title:`Move standing (always-on) cameras that are no longer on their best node. Pinned cameras never move; on-motion sessions are placed per session anyway.`,children:[d(re,{className:`h-3.5 w-3.5`}),x.isPending?`Rebalancing…`:`Rebalance`]})]}),children:i(`div`,{className:`${m} space-y-3`,children:[L!==void 0&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:L}),p&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Policy:`,` `,d(G,{variant:p.policy===`share`?`info`:`default`,children:p.policy===`share`?`honour shares`:`least-loaded`}),` `,`· cluster peak `,p.clusterPeakSessions,` parallel sessions in the last hour`,p.policy===`least-loaded`&&` · under least-loaded an idle node always wins, so shares only bite once nodes are busy`]}),d($i,{nodes:P.nodes,pending:v.isPending,readOnly:P.readOnly,onCommitWeights:e=>v.mutate(Bi(e)),weightLabel:`Node share`,...P.readOnly?{footnote:h?.autoPending?d(o,{children:`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`}):i(o,{children:[T===`benchmark`?`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`:`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`,h?.computedAt==null?``:` — last at ${new Date(h.computedAt).toLocaleTimeString()}${h.trigger===null?``:` (${h.trigger})`}`,`.`]})}:{}}),te!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:te}),ne!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:ne}),y.isError&&d($e,{message:`Failed to switch shares: ${y.error instanceof Error?y.error.message:`unknown error`}`}),v.isError&&d($e,{message:`Failed to save shares: ${v.error instanceof Error?v.error.message:`unknown error`}`}),i(`details`,{className:`rounded-md border border-border`,children:[d(`summary`,{className:`${C} cursor-pointer text-xs text-foreground`,children:`Max concurrent sessions (advanced)`}),d(`ul`,{className:`divide-y divide-border border-t border-border`,children:A.map(e=>i(`li`,{className:`${C} flex items-center gap-2`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),d(_t,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":`Max concurrent sessions for ${e.name}`,className:`w-20 text-right`,disabled:b.isPending,onBlur:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==e.maxCameras&&b.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),d(`p`,{className:`${C} ${B} border-t border-border`,children:`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`})]})]})}),O.isError&&d($e,{message:`Suggestion failed: ${O.error instanceof Error?O.error.message:`unknown error`}`}),k&&d(ua,{suggestion:k,nameOf:j,pending:v.isPending,...F?{}:{onApply:()=>v.mutate(Vi(k))}}),d(U,{headingId:`load-balancing-accelerators`,title:`Accelerators`,icon:g,children:d(`div`,{className:`${m} space-y-2`,children:A.length===0?d(at,{title:`No detect-capable nodes`,description:`Enable detection on a node in Roles & nodes to configure its accelerators.`}):A.map(e=>d(ra,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...N?.[e.id]===void 0?{}:{suggestedMaxSessions:N[e.id]},...ee(e.id)===void 0?{}:{autoDeviceShares:ee(e.id)}},e.id))})}),p!==void 0&&p.stalePins.length>0&&d(da,{stats:p,cameraName:M})]})}function ua({suggestion:e,nameOf:t,pending:n,onApply:r}){return i(U,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?`Suggested from benchmark`:`Suggested from hardware`,icon:I,...r===void 0?{}:{actions:d(V,{size:`sm`,onClick:r,disabled:n,children:`Apply suggested shares`})},children:[d(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>i(`li`,{className:`${C} space-y-0.5`,children:[i(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),d(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?`skipped`:`${e.share}%`})]}),i(`p`,{className:B,children:[qi(e.capacityFallback)===null?``:`${qi(e.capacityFallback)} · `,e.skippedReason===null?`≈ ${e.capacitySessions} parallel sessions · ${e.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}`:`not part of the suggestion — ${e.skippedReason}`]})]},e.nodeId))}),i(`p`,{className:`${C} ${B} border-t border-border`,children:[`Shares in proportion to each node's capacity in parallel sessions —`,` `,e.source===`benchmark`?`measured by node benchmarks, or from the hardware table where a node has no results`:`at the models Auto tune picks (at least ${e.minSessionsPerDevice} per accelerator), from the measured speed of each node's hardware`,`, counted in `,e.cameraFps,` fps sessions with`,` `,Math.round(e.headroom*100),`% kept free. No load is measured or estimated.`,r===void 0?`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`:`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`]})]})}function da({stats:e,cameraName:t}){let n=c(),r=wt({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return d(U,{headingId:`load-balancing-stale-pins`,title:`Stale device pins`,icon:me,children:d(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>i(`li`,{className:`${C} flex items-center gap-2`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[d(`p`,{className:`truncate text-xs text-foreground`,title:t(e.deviceId),children:t(e.deviceId)}),d(`p`,{className:B,children:Ui(e)})]}),d(V,{variant:`outline`,size:`sm`,disabled:r.isPending,onClick:()=>r.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:`Clear pin`})]},e.deviceId))})})}function fa({node:e,emphasis:t=!1}){let n=e.isHub?z:g;return i(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),i(`div`,{className:`min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(G,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(G,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}function pa({nodes:e,actions:t}){return d(Je,{columns:[{key:`node`,header:`Node`,sortValue:e=>e.name,render:e=>d(fa,{node:e})},...wn.map(e=>({key:e.key,header:e.label,align:`center`,notSortableReason:`A switch — sorting would move the row while it is being changed.`,render:n=>d(It,{"aria-label":`${e.label} on ${n.name}`,title:e.hint,checked:vn(n.effective,e.key),disabled:t.capabilityPending,onCheckedChange:r=>t.onToggleCapability(n.id,e.key,r)})}))],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,mobileMode:`scroll`,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:`No cluster nodes reporting yet.`})}function ma({roleValues:e,options:t,pending:n,onRoleChange:r}){let a=t.map(e=>({value:e.id,label:e.id===`hub`?`${e.name} (default)`:e.name}));return d(`ul`,{className:`divide-y divide-border`,children:On.map(t=>i(`li`,{className:`${C} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[i(`div`,{className:`min-w-0 flex-1 basis-56`,children:[d(`div`,{className:`text-xs font-medium text-foreground`,children:bn(t)}),d(`p`,{className:B,children:xn(t)})]}),d(`div`,{className:`w-full sm:w-48`,children:d(H,{"aria-label":`${bn(t)} node`,value:e[t],disabled:n,options:a,onChange:e=>r(t,e.target.value)})})]},t))})}r();function ha(){let e=c(),{nodes:t}=K(),n=ht(void 0),r=Wt({addonId:Dn}),o=Wt({addonId:_n}),s=Wt({addonId:kn}),l=()=>Cn(e),u=Xt({onSuccess:l}),f=Ct({onSuccess:l}),p=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),m=a(()=>t.map(e=>{let t=p.get(e.id),n=Rn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[t,p]),h={ingestNode:En(r.data,`ingestNode`,`hub`),recordingNode:En(o.data,Tn,`hub`),audioNode:En(r.data,`audioNode`,`hub`),motionNode:En(r.data,`motionNode`,`hub`),postProcessingNode:En(s.data,Sn,`hub`)},g=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id),n=e=>t.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,...On.map(e=>h[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:n(e)}))},[t,h]),_=n.isLoading||r.isLoading||o.isLoading||s.isLoading,v=(e,t,n)=>{u.mutate({agentNodeId:e,[t]:n})},y=(e,t)=>{if(e===`recordingNode`){f.mutate({addonId:_n,patch:{[Tn]:t}});return}if(e===`postProcessingNode`){f.mutate({addonId:kn,patch:{[Sn]:t}});return}f.mutate({addonId:Dn,patch:{[e]:t}})},b={capabilityPending:u.isPending,onToggleCapability:v};return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(U,{headingId:`roles-nodes-cluster-roles`,title:`Cluster roles`,icon:fe,actions:_?d(A,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":`Loading`}):null,children:[d(`p`,{className:`${B} border-b border-border px-3 py-1.5 sm:px-4`,children:`One node holds each role for every camera. Detection shares and caps are on Load balancing.`}),d(ma,{roleValues:h,options:g,pending:f.isPending,onRoleChange:y})]}),d(U,{headingId:`roles-nodes-node-capabilities`,title:`Node capabilities`,icon:z,children:d(pa,{nodes:m,actions:b})})]})}var ga=`pipeline-analytics`,_a=`face-gallery`,va=`pipeline-orchestrator`,ya=`pipeline-runner`,ba=`audio-analyzer`;function xa(e){return[...Ne.filter(t=>t.stepId===e).map(e=>Se(e.stepId)),...we.filter(t=>t.stepId===e).map(e=>Ce(e.stepId,e.key))]}var Sa=`faces`,Ca=`semantic-search`,wa=[{id:Sa,title:`Faces & recognition`,hint:`The face encoder for every node, the smallest faces worth embedding, keeping and auto-assigning, and how a face is matched to a person.`,panels:[{addonId:va,fieldKeys:xa(`face-embedding`)},{addonId:ga,capability:_a}]},{id:Ca,title:`Semantic search`,hint:`The image encoder behind "search by description". One for the whole cluster: changing it hides existing results until the index is rebuilt.`,panels:[{addonId:va,fieldKeys:xa(`clip-embedding`)}]},{id:je,title:`Enrichment crop`,hint:`How the crop handed to face, plate and search models is cut from the frame.`,panels:[{addonId:va,sectionIds:[je]}]},{id:De,title:`Full-resolution crops`,hint:`How long each camera keeps full-resolution pixels so a late crop (snapshot, face, plate) is sharp instead of cut from the small detection frame.`,panels:[{addonId:va,sectionIds:[De]}]},{id:`runner-defaults`,title:`Runner defaults`,hint:`Values every node's detection runner and audio analyzer use. A node's own decode limits (Engine & decoder) take precedence.`,panels:[{addonId:ya,fieldScope:`cluster`},{addonId:ba,fieldScope:`cluster`}]},{id:`failover`,title:`Failover`,hint:`What happens to cameras when a node disconnects and comes back.`,panels:[{addonId:va,sectionIds:[`failover`]}]}],Ta={"cluster-step-models":Sa};function Ea(e){return e===`clip-embedding`?Ca:Sa}r();var Da=2500,Oa={faces:ne,"semantic-search":E,"detail-crop":ge,"native-lease":_e,"runner-defaults":g,failover:R};function ka(e){f(()=>{if(e===null)return;let t=Ta[e]??e,n=`[data-cluster-settings-card="${CSS.escape(t)}"]`,r=()=>{let e=document.querySelector(n);return e===null?!1:(e.scrollIntoView({block:`start`,behavior:`smooth`}),e.classList.add(`ring-2`,`ring-primary/60`),setTimeout(()=>e.classList.remove(`ring-2`,`ring-primary/60`),Da),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function Aa({section:e}){return d(`div`,{"data-cluster-settings-card":e.id,className:`rounded-lg`,children:d(U,{headingId:`cluster-settings-${e.id}`,title:e.title,...Oa[e.id]===void 0?{}:{icon:Oa[e.id]},children:i(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:B,children:e.hint}),e.panels.map(e=>d(gn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:[`cluster`,`load`],emptyMessage:`Not available — the addon that owns these settings did not answer.`,...e.capability===void 0?{}:{capability:e.capability},...e.sectionIds===void 0?{}:{sectionIds:e.sectionIds},...e.fieldKeys===void 0?{}:{fieldKeys:e.fieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function ja({refreshToken:e}){let[t]=hn();return ka(t.get(No)),d(`div`,{className:`space-y-3 sm:space-y-4`,children:wa.map(e=>d(Aa,{section:e},e.id))})}var Ma=`pipeline-orchestrator`,Na=200;function Pa(){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`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.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(ft,{addonId:Ma,limit:Na,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}var Fa=[{id:`assignments`,label:`Assignments`},{id:`load-balancing`,label:`Load balancing`},{id:`auto-tune`,label:`Auto tune`},{id:`roles-nodes`,label:`Roles`},{id:`settings`,label:`Settings`},{id:`logs`,label:`Logs`}];function Ia(e){return Fa.some(t=>t.id===e)}function La({refreshToken:e}){let[t,n]=hn(),r=t.get(Mo),a=Ia(r)?r:`assignments`,o=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(Mo,e),n.delete(No),n},{replace:!0})};return i(`div`,{className:`flex flex-col h-full`,children:[i(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Fa.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[a===`assignments`&&d(li,{}),a===`load-balancing`&&d(la,{refreshToken:e,onOpenAutoTune:()=>o(`auto-tune`)}),a===`auto-tune`&&d(Oi,{}),a===`roles-nodes`&&d(ha,{}),a===`settings`&&d(ja,{refreshToken:e}),a===`logs`&&d(Pa,{})]})]})}var Ra=`armed:`;function za(e){return e.assignment.reasons.detection?.startsWith(Ra)===!0}function Ba(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!za(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Va(e){let t=[],n=[],{assignment:r,detection:i,broker:a}=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)`}),r.detectionNodeId===null&&i===null&&!za(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let o=e.degraded??[];if(o.length>0){let e=[...new Set(o.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)`})}n.push(...Wa(e.cameraSensors));for(let e of a?.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 Ha(e){return e.state===`unreadable`&&ke.state===`unreadable`&&e.reason===ke.reason}function Ua(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is missing`};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) is ${e.reason}`};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) cannot drive motion: ${e.reason}`};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is unreadable: ${e.reason}`}}}function Wa(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return Ha(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:`Camera sensors unreadable: ${e.reason}`}];let t=e.sensors.flatMap(e=>{let t=Ua(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[Ga(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:`Confirm / Replace cannot suppress this camera's own motion until its provider is updated`},...n]}function Ga(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?`Camera sensors are attached but never fire: add "Camera sensors" (onboard) to this camera's motion sources`:`Camera sensors are attached but never fire: this camera has no active detection`}}function Ka(e){return e===void 0?`status unavailable from this node`:e.state===`not-configured`?`none attached`:e.state===`unreadable`?`unknown — ${e.reason}`:e.sensors.map(Ja).join(`, `)}function qa(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function Ja(e){return`${Ya(e)}${qa(e)}`}function Ya(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return`${e.name} (#${e.deviceId}) — unsupported`;case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function Xa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Za(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Qa(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function $a(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var eo={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 to(e){if(!Xa(e)||!Array.isArray(e.sections))return eo;let t=Oe(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)$a(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Za(n(`detectionFps`)),motionSources:Qa(n(`motionSources`)),motionFps:Za(n(`motionFps`)),motionCooldownMs:Za(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 no(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(...no(r.children,t+1));return n}function X({title:e,children:t}){return i(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return i(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(ro,{})]})}function ro(){return d(`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 io={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 d(`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 ${io[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function ao({icon:e,label:t,nodeId:n,pinned:r,reason:a,overridden:s}){return i(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):i(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?i(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(_,{className:`h-2.5 w-2.5`}),` manual`]}):i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function oo({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return i(X,{title:`Where it runs`,children:[d(ao,{icon:g,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(ao,{icon:y,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(ao,{icon:D,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(ao,{icon:M,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:i(`select`,{value:o,disabled:r,"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:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>i(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function so(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function co(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function lo(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function uo({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:a,cameraSensors:s}){let c=co(t,n.detectionStreamProfile),l=co(t,n.motionStreamProfile),u=n.motionSources.includes(`analyzer`);return i(X,{title:`Streams & motion`,children:[i(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:lo(n.detectionFps)}),i(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map(be).join(` + `):`none`,r===!1&&` · inactive`]}),d(Z,{label:`Camera sensors`,children:Ka(s)}),u&&i(o,{children:[i(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),i(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[lo(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>i(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,so(e)]},e.camStreamId))})]})}function fo({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return i(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:i(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&i(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:i(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var po={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function mo({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return i(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:r,children:n??`—`}),d($,{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,u=tt(a),f=a===`active`&&o===0;return i(X,{title:`Detection runtime`,children:[i(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[i(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(Ue,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:r,children:n??`—`}),i(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),i(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&i(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&i(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),i(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),i(Z,{label:`Provisioning`,children:[d(Q,{tone:po[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&i(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function ho({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):i(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return i(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),i(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),i(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps===null?`—`:e.inFps.toFixed(0),`fps`]}),i(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),i(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[i(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),i(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function go({decoder:e}){return e===null?d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})}):d(X,{title:`Decoder`,children:d(Z,{label:`Node`,children:e.nodeId})})}r();var _o=`pipeline-orchestrator`,vo={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},yo={healthy:`Healthy`,idle:`Idle`,error:`Error`};function bo({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>i(`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:[d(b,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function xo({deviceId:e,name:t,online:n,status:r,live:o,onlineNodes:s}){let l=c(),{data:u}=Jt({addonId:_o,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=Qe({deviceId:e},{staleTime:3e4}),p=a(()=>to(u),[u]),m=a(()=>f===void 0?void 0:no(f.steps),[f]),h=a(()=>r===void 0?[]:Va(r),[r]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=Re({onSuccess:g}),v=Bt({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=r===void 0?`idle`:Ba(r),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return i(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[i(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:vo[b]}`,title:x?`Error`:yo[b],"aria-label":x?`Error`:yo[b],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),i(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),r?.recording!=null&&(r.recording.active?i(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&i(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),h.length>0&&d(bo,{problems:h}),r===void 0?d(`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.`}):i(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(oo,{assignment:r.assignment,settings:p,onlineNodes:s,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),d(mo,{detection:r.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(fo,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:r.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(uo,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:p,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null,cameraSensors:r.cameraSensors}),d(ho,{broker:r.broker}),d(go,{decoder:r.decoder})]})]})}r();var So=5e3,Co=1e4,wo=5e3;function To(e){let t=c(),{data:n,isLoading:r}=pn(),{data:i,isLoading:o}=Ie({},{refetchInterval:So}),{nodes:s}=K();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);Pt(ye.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(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})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-Co,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},wo);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(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:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}r();function Eo({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:o}=To(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:Va(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=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:i(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[i(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[i(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),i(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),i(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(xo,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}var Do=e({CLUSTER_NODE_ID:()=>Oo,PipelinePage:()=>jo});r();var Oo=`__cluster__`;function ko(e){return e===`cameras`?`cameras`:`nodes`}function Ao({viewMode:e,onNodes:t,onCameras:n}){return i(`div`,{className:`flex items-center gap-1 rounded-lg border border-border bg-surface p-0.5`,role:`tablist`,"aria-label":`Pipeline view`,children:[d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`nodes`,onClick:t,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`cameras`,onClick:n,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]})}function jo(){let[e,t]=hn(),n=ko(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Oo},{replace:!0})},[n,e,t]),i(Ke,{icon:le,title:`Pipeline`,subtitle:`Detection placement, load and per-camera runtime across the cluster.`,actions:i(V,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s(e=>e+1),title:`Refresh`,children:[d(se,{className:`h-3.5 w-3.5`}),`Refresh`]}),nav:d(Ao,{viewMode:n,onNodes:()=>{t({view:`nodes`,node:r},{replace:!0})},onCameras:()=>{t({view:`cameras`},{replace:!0})}}),className:`flex h-full min-h-0 flex-col overflow-hidden`,children:[n===`nodes`&&i(V,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>l(e=>!e),"aria-expanded":c,className:`flex w-full shrink-0 justify-between border-b border-border md:hidden`,children:[i(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(oe,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden md:flex-row`,children:n===`nodes`?i(o,{children:[d(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b border-border md:border-b-0 md:border-r`,`max-h-[60vh] overflow-y-auto md:max-h-none`].join(` `),children:d(Bn,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:r===`__cluster__`?d(La,{refreshToken:a}):d(ci,{nodeId:r,refreshToken:a})})]}):d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:d(Eo,{refreshToken:a})})})]})}var Mo=`ctab`,No=`section`;function Po(e,t){let n=new URLSearchParams({view:`nodes`,node:Oo,[Mo]:e});return t!==void 0&&n.set(No,t),`/system/pipeline?${n.toString()}`}function Fo(e){return Po(`settings`,Ea(e))}function Io(){return Po(`load-balancing`)}var Lo=`pipeline-orchestrator`;function Ro(e){return Ne.find(t=>t.stepId===e)??null}function zo({step:e,engineFormat:t,runnableModelIds:n}){let{data:r}=Wt({addonId:Lo}),a=Ae(r??null)[e.stepId]??e.defaultModelId,o=e.options.find(e=>e.id===a)?.label??a,s=n.length>0&&!n.includes(a);return i(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:o}),d(`span`,{title:`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`}),d(mn,{to:Fo(e.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Change in Cluster → Settings ›`})]}),i(`p`,{className:B,children:[`One model for every node and camera: `,e.indexName,` only matches vectors from the model that made them.`]}),s&&i(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:[`This accelerator's engine (`,t,`) ships no build of `,d(`b`,{children:a}),`. It refuses this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`.`]})]})}export{Ar as _,Jr as a,Nr as c,zr as d,Vr as f,jr as g,Br as h,Yr as i,Gr as l,Rr as m,Ro as n,Lr as o,Wr as p,Do as r,Hr as s,zo as t,Ur as u,Dr as v,jn as y};
1
+ import{r as e}from"./rolldown-runtime-Cyuzqnbw.js";import{I as t,K as n,Q as r,S as i,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{A as p,D as m,It as h,Jr as g,Mn as _,N as v,Nr as y,Nt as b,O as x,Qi as S,T as C,Tr as w,V as T,Xt as E,Yn as D,_i as O,_t as k,ar as A,b as j,bn as M,dt as N,j as P,k as F,lr as I,nr as ee,ot as te,pn as ne,rr as L,sn as R,un as z,ut as re,v as ie,y as ae,yi as oe,yn as se,z as B}from"./player-overlays-V9UtVzaL.js";import{c as ce,l as le,t as ue}from"./video-pPaTYzzY.js";import{a as de,i as fe,n as pe,r as me,t as he}from"./usb-B5CzoN_q.js";import{t as ge}from"./crop-AF56iSVW.js";import{t as _e}from"./layers-oP1uhEhI.js";import{An as ve,Cn as ye,Dn as be,En as xe,Gr as Se,On as Ce,Tn as we,Wr as Te,_i as Ee,c as De,jn as Oe,kn as ke,l as Ae,m as je,wi as Me,wn as Ne}from"./client-D-ClAw3a.js";import{n as Pe}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{An as Fe,As as Ie,Bn as V,C as Le,Cs as Re,Dn as ze,E as Be,En as Ve,Es as He,F as Ue,Fs as We,Gl as H,Gs as Ge,H as Ke,Hs as qe,Ht as Je,J as Ye,Js as Xe,Jt as Ze,Ks as Qe,Ln as $e,Ls as et,Mt as tt,O as nt,On as rt,Ps as it,Rn as at,Rs as ot,S as st,Ss as ct,T as lt,Tn as ut,Ts as dt,Tt as ft,Us as pt,Ut as mt,Vs as ht,Vt as U,W as gt,Xl as _t,Y as vt,Ys as yt,Yt as bt,Zl as xt,Zn as St,_n as W,_r as Ct,ac as wt,an as Tt,ar as G,bs as Et,cc as Dt,cn as Ot,dc as kt,dn as At,du as K,fu as jt,gu as Mt,hn as Nt,hu as Pt,ic as Ft,in as It,iu as Lt,jn as Rt,kn as zt,lc as Bt,ln as Vt,ma as Ht,mn as Ut,mr as Wt,mu as Gt,oc as Kt,pn as qt,pr as Jt,pu as Yt,qs as Xt,qt as Zt,r as Qt,ru as $t,sc as en,sn as tn,un as nn,vn as rn,vs as an,vt as on,w as sn,wn as cn,ws as ln,xs as un,ys as dn,zs as fn}from"./src-0C0o0YVH.js";import{V as pn,Z as mn,q as hn}from"./index-DFK8wKFu.js";import"./useEventInvalidation-BWYGPnze.js";import{t as gn}from"./NodeAddonsSettingsPanel-D4T6WpHA.js";import{a as _n,c as vn,d as yn,g as bn,h as xn,i as Sn,l as Cn,n as wn,o as Tn,p as En,r as Dn,s as On,t as kn}from"./board-model-Bmts6hrg.js";var An=`step`,jn=[An,`acc`];function Mn(e,t){return`${e}/${t}`}function Nn(e,t,n){let r=n.step!==null&&e.includes(n.step),i=n.acc!==null&&t.includes(n.acc);return{stepId:r?n.step:null,acceleratorId:i?n.acc:null,staleStepId:n.step!==null&&n.step!==``&&!r&&e.length>0?n.step:null}}function Pn(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 Fn(e){return e}function In(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Ln(e,t){return typeof e==`boolean`?e:Fn(t)}function Rn(e,t){return{pipeline:Ln(In(e,`detect`),t),audio:Ln(In(e,`audio`),t),ingest:Ln(In(e,`ingest`),t)}}function zn(e,t,n){let r=e?.find(e=>e.nodeId===t);return Rn(r?.settings,n)}function Bn({selectedNodeId:e,onSelect:t,refreshToken:n}){let{nodes:r}=jt(),{data:a}=et(void 0),{data:s}=ht(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=r??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return i(`div`,{className:`flex flex-col h-full`,children:[i(`button`,{type:`button`,onClick:()=>t(Oo),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:[d(ce,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Assignments, load balancing, roles`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let r=e===n.id,a=c.get(n.id)??0,l=n.isHub?z:g,u=zn(s,n.id,n.isHub),f=n.isOnline?null:on(Pn(n.lastSeen));return i(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-danger flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),i(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[i(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(ue,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`text-danger`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(G,{variant:u.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),d(G,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),i(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[i(`span`,{children:[u,` online`]}),f>0&&i(`span`,{className:`text-danger`,children:[f,` offline`]})]})]})}function Vn({nodeId:e,refreshToken:t}){let{nodes:n}=jt(),r=n?.find(t=>t.id===e),a=Yt(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?i(`div`,{className:`px-6 py-4 border-b border-border`,children:[i(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-danger/10 text-danger`,children:`offline`}),r.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:r.cpuModel??`CPU`}),d(`span`,{children:`•`}),i(`span`,{children:[r.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),i(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),i(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&i(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:i(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var Hn=[`assignments`,`tree`,`engines`,`logs`];r();function Un({refreshToken:e,nodeId:t}){let[n,r]=u(new Map),{nodes:o}=K();Pt(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=He(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.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}},[l,o]);if(t){let e=l.get(t);return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(q,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(q,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(q,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(q,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(q,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(q,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),i(`tbody`,{children:[m.map(([e,t])=>i(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}var Wn={active:!1,pinned:!1,nodeId:null,reason:``};function Gn(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function Kn(e,t,n){let r=new Map(t.map(e=>[e.deviceId,e])),i=new Map(n.map(e=>[e.deviceId,e]));return e.map(e=>{let t=r.get(e.id),n=i.get(e.id),a=t?{active:!0,pinned:t.pinned,nodeId:t.agentNodeId,reason:t.reason??``}:Wn,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:Wn;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:Wn,audio:o}}).toSorted(Gn)}function qn(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function Jn(e,t){let n=new Map(t.map(e=>[e.deviceId,e.assignment]));return e.map(e=>{let t=n.get(e.deviceId);return t===void 0?e:{...e,detection:qn(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:qn(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:qn(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function Yn(e,t,n){let r=(t,n,r)=>({active:t!==null&&t===e,pinned:n,nodeId:t,reason:r??``});return t.map(({deviceId:e,assignment:t})=>({deviceId:e,deviceName:n(e),detection:r(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:r(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:r(t.audioNodeId,t.pinned.audio,t.reasons.audio)})).filter(e=>e.detection.active||e.decoder.active||e.audio.active).toSorted(Gn)}function Xn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>{let n=t.get(e);return n!==void 0&&n!==``?n:e}}function Zn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??`Camera ${e}`}function Qn(e,t,n){return[{value:`auto`,label:`Auto`},...[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])].map(e=>({value:e,label:`Pin → ${n(e)}`}))]}function $n({roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:i,emphasizeOnNodeId:a}){if(n.nodeId===null)return null;let o=n.nodeId,s=a===void 0?!1:n.active&&o===a;return d(Zt,{roleId:e,roleLabel:t,nodeName:r(o),colorId:bt(i,o),emphasized:s,pinned:n.pinned})}function er({detection:e,decoder:t,audio:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o}){let s=(e,t,n)=>d($n,{roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o},e);return i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[s(`detection`,`Detection`,e),s(`decode`,`Decode`,t),s(`audio`,`Audio`,n)]})}function tr({snap:e}){if(e===void 0)return d(`div`,{className:`flex h-8 items-center text-[11px] text-foreground-subtle`,title:`No metrics in the last 10 s — the camera has no session running`,children:`no live data`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=tt(t);return i(`div`,{className:`flex h-8 min-w-0 flex-col justify-center font-mono text-[10px] leading-tight tabular-nums`,children:[i(`span`,{className:`inline-flex min-w-0 items-center gap-1 ${c.textColor}`,children:[d(Ue,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate font-semibold uppercase tracking-wider`,children:c.label}),d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[`/`,o.toFixed(0),` fps`]})]}),i(`span`,{className:`truncate text-foreground-subtle`,children:[d(`span`,{className:`text-foreground`,children:r.toFixed(0)}),` ms`,a>0&&i(`span`,{className:`ml-1 text-warning`,children:[`q`,a]}),i(`span`,{className:s>0?`ml-1 text-warning`:`ml-1`,children:[`drops `,s]})]})]})}r();var nr=1e4,rr=5e3;function ir(e){let[t,n]=u(new Map);return Pt(`pipeline.camera-metrics-snapshot`,t=>{let r=t.data;typeof r.deviceId==`number`&&(e!==void 0&&r.nodeId!==e||n(e=>new Map(e).set(r.deviceId,r)))}),f(()=>{if(t.size===0)return;let e=setInterval(()=>{n(e=>{let t=Date.now()-nr,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},rr);return()=>clearInterval(e)},[t.size]),t}var ar=3e5;function or({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:i}){return d(H,{"aria-label":`Node pin`,title:`Auto lets each session pick its node; a pin keeps the camera on one node.`,value:e.pinned&&e.nodeId!==null?e.nodeId:`auto`,disabled:r,options:[...Qn(e,t,n)],onChange:e=>i(e.target.value)})}function sr({deviceId:e,nodeId:t}){let n=c(),{data:r}=ot({deviceId:e},{refetchOnMount:`always`}),{data:i}=We({nodeId:t},{staleTime:ar}),a=wt({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`accelerator: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),l=r?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l),f=o.find(e=>e.key===l),p=[{value:`auto`,label:`Any accelerator`},...u?[{value:l,label:`${f?`${W(f)} (${l})`:l} (not enabled)`}]:[],...s.map(e=>({value:e.key,label:`${W(e)} · ${e.format}`}))];return d(H,{"aria-label":`Inference device pin`,title:`Pin detection to one accelerator of the node, or let each session pick.`,value:l,disabled:a.isPending,options:p,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value})})}r();function cr(e){let t=n(null);return e.nodeId!==null&&(t.current=e),t.current}function lr({deviceId:e,state:t,...n}){let r=cr(t);return i(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[d(or,{state:t,...n}),r?.nodeId==null?d(H,{"aria-label":`Inference device pin (no node yet)`,title:`An accelerator is pinned on the camera's node; this camera has not run on one yet.`,disabled:!0,defaultValue:`auto`,options:[{value:`auto`,label:`Any accelerator`}]}):d(sr,{deviceId:e,nodeId:r.nodeId})]})}function ur({state:e,nameOf:t}){let n=cr(e);if(n?.nodeId==null)return d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`— no session yet`});let r=e.active&&e.nodeId!==null,a=n.pinned?`pinned`:`auto · ${n.reason||`capacity`}`;return i(`div`,{"data-testid":`resolved-placement`,className:`flex w-40 min-w-0 flex-col leading-tight`,title:n.pinned?void 0:`An unpinned camera is placed again at every session start, so this can change between sessions.`,children:[i(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[d(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${r?`bg-success`:`bg-foreground-subtle/40`}`}),d(`span`,{"data-testid":`resolved-placement-node`,className:`truncate font-medium ${r?`text-foreground`:`text-foreground-muted`}`,children:t(n.nodeId)})]}),d(`span`,{className:`truncate pl-3 text-[10px] ${n.pinned?`text-warning`:`text-foreground-subtle`}`,children:r?a:`${a} · idle, last session`})]})}function dr({deviceId:e,deviceName:t}){let[n,r]=u(!1);return i(o,{children:[d(xt,{icon:M,variant:`ghost`,size:`sm`,"aria-label":`Stream brokers of ${t}`,title:`Stream brokers & clients`,onClick:()=>r(!0)}),d(ut,{open:n,onOpenChange:r,children:i(ze,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[d(Fe,{children:i(Rt,{children:[t,` — stream brokers & clients`]})}),d(Ve,{children:n&&d(cn,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e,instanceId:`pipeline-row/${e}`,config:{variant:`compact`}})})]})})]})}function fr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function pr(e,t){return t.size===0?!0:t.has(e)}var mr=[{value:`active`,label:`Active`},{value:`recently-active`,label:`Recently active`},{value:`inactive`,label:`Inactive`}];r();var hr=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function gr(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function _r(){let e=c();Qt([`pipelineOrchestrator`,`getPipelineAssignments`],hr),Qt([`pipelineOrchestrator`,`getAudioAssignments`],hr),Qt([`pipelineOrchestrator`,`getCameraStatuses`],hr);let{data:t}=Ht({isCamera:!0,projection:`slim`}),{data:n}=et(void 0),{data:r}=dt(void 0),{data:o}=Ie({}),{data:s}=ht(void 0),{nodes:l}=K(),f=ir(),p=a(()=>Xn(l),[l]),m=a(()=>Ze(s),[s]),h=a(()=>l.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[l]),g=a(()=>Jn(Kn((t??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),n??[],r??[]),o??[]),[t,n,r,o]),[_,v]=u(()=>new Set),y=a(()=>g.filter(e=>pr(fr({hasPipelineAssignment:e.pipeline.active,hasFreshMetrics:f.has(e.deviceId)}),_)),[g,f,_]),b=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},x=()=>gr(e),S=Re({onSuccess:x}),C=Bt({onSuccess:x}),w=S.isPending||C.isPending,T=[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[d(hn,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName}),e.disabled&&d(G,{variant:`default`,children:`off`})]})},{key:`placement`,header:`Placement`,width:`w-80`,notSortableReason:`A pair of controls — editing one would move the row under the cursor.`,render:e=>d(lr,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:h,nameOf:p,pending:w,onChange:t=>t===`auto`?C.mutate({deviceId:e.deviceId}):S.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:e=>d(er,{detection:e.detection,decoder:e.decoder,audio:e.audio,nameOf:p,colorByNodeId:m})},{key:`resolved`,header:`Running on`,width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:p(e.pipeline.nodeId),render:e=>d(ur,{state:e.pipeline,nameOf:p})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>f.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(tr,{snap:f.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>d(dr,{deviceId:e.deviceId,deviceName:e.deviceName})}],E=t===void 0?`Loading cameras…`:g.length===0?`No cameras`:`No cameras match this activity filter.`;return i(`div`,{className:`flex flex-col gap-2`,children:[d(`nav`,{"aria-label":`Filter by camera activity`,"data-testid":`assignments-activity-filter`,children:d(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:mr.map(e=>{let t=_.has(e.value);return d(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:Lt(ae,t?ie:j),onClick:()=>b(e.value),children:e.label},e.value)})})}),d(Je,{columns:T,rows:y,rowKey:e=>e.deviceId,minWidthPx:920,mobileMode:`scroll`,maxBodyHeight:mt,emptyMessage:E})]})}r();function vr({nodeId:e}){let t=c();Qt([`pipelineOrchestrator`,`getCameraStatuses`],hr);let{data:n}=Ie({}),{data:r}=ht(void 0),{data:i}=Ht({isCamera:!0,projection:`slim`}),{nodes:o}=K(),s=ir(),l=a(()=>Xn(o),[o]),u=a(()=>Ze(r),[r]),f=a(()=>Yn(e,n??[],Zn((i??[]).map(e=>({id:e.id,name:e.name})))),[e,n,i]),p=o.filter(t=>t.isOnline&&t.id!==e),m=()=>gr(t),h=Re({onSuccess:m}),g=Bt({onSuccess:m}),_=ct({onSuccess:m}),v=Dt({onSuccess:m}),y=e=>[...e.detection.active?p.map(t=>({id:`detect-${t.id}`,label:`Move detection to ${t.name}`,onClick:()=>h.mutate({deviceId:e.deviceId,agentNodeId:t.id})})):[],...e.audio.active?p.map(t=>({id:`audio-${t.id}`,label:`Move audio to ${t.name}`,onClick:()=>_.mutate({deviceId:e.deviceId,nodeId:t.id})})):[],{id:`unpin-detect`,label:`Unpin detection`,hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>g.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:`Unpin audio`,hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>v.mutate({deviceId:e.deviceId})}];return d(Je,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>d(hn,{to:`/devices/${String(e.deviceId)}`,className:`block w-44 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:t=>d(er,{detection:t.detection,decoder:t.decoder,audio:t.audio,nameOf:l,colorByNodeId:u,emphasizeOnNodeId:e})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(tr,{snap:s.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>d(gt,{items:y(e),title:`Move ${e.deviceName}`})}],rows:f,rowKey:e=>e.deviceId,minWidthPx:560,mobileMode:`scroll`,maxBodyHeight:mt,emptyMessage:n===void 0?`Loading cameras…`:`No camera runs on this node right now`})}function yr({nodeId:e,refreshToken:t}){let{nodes:n}=K(),r=n.find(t=>t.id===e)?.name??e;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(Un,{refreshToken:t,nodeId:e}),i(`div`,{className:`space-y-2`,children:[i(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:[`Cameras on `,r]}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The roles each camera runs here right now. Move a role or unpin it from the row menu; pins for every camera are on Cluster → Assignments.`})]}),d(vr,{nodeId:e})]})]})}r();function br(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function xr({nodeId:e,refreshToken:t}){let n=c(),r=St(),o=dn({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:s}=Et({nodeId:e}),l=Yt(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??s??null,u=l===null;Qt([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=kt({nodeId:e}),{values:p}=Gt(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=a(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),_=t=>{let n=f??[];if(n.length===0){o.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await r({title:`Kill engine`,message:`${String(n.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:`Kill engine`,variant:`danger`})&&o.mutate({nodeId:e,engine:t,force:!0})})()};return i(`div`,{className:`space-y-6`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(l??[]).length,` engine(s) resident in RAM. `,(f??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),i(`tbody`,{children:[u&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!u&&(l??[]).map(e=>{let t=e.kind===`device-pool`;return i(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[d(t?_e:g,{className:`h-3 w-3`}),t?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(re,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),d(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?d(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>d(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),d(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),d(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?d(`span`,{className:`text-foreground-subtle`,children:br(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(f??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:t?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):i(V,{variant:`ghost`,size:`sm`,disabled:o.isPending,onClick:()=>_(e.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[d(h,{className:`h-3.5 w-3.5`}),`Kill`]})})]},e.engineKey)}),!u&&(l??[]).length===0&&d(`tr`,{children:d(`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.`})})]})]})}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`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.`]}),o.isError&&d($e,{message:`Kill failed: ${o.error instanceof Error?o.error.message:`unknown error`}`})]})}var Sr=`pipeline-runner`,Cr=200;function wr({nodeId:e}){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),i(`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.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(ft,{agentId:e,addonId:Sr,limit:Cr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}r();function Tr({nodeId:e,title:t}){let{data:n}=pn(),{data:r}=et(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),c=ir(e),l=a(()=>{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 l.length===0?i(`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`]}):i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[i(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=tt(e.metrics.phase);return i(`div`,{title:`${t} · ${n.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] ${n.badgeClass}`,children:[d(Ue,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}function Er(e,t,n){return e.map(e=>{if(e.key===t)return e;let r=e.steps[n];if(!r||r.settings===void 0)return e;let{settings:i,...a}=r,o={...e.steps};return Object.keys(a).length>0?o[n]=a:delete o[n],{...e,steps:o}})}function Dr(e,t,n){let r=e.filter(e=>e.key!==t).toSorted((e,t)=>e.key.localeCompare(t.key)),i=[...r.filter(e=>!e.enabled),...r.filter(e=>e.enabled),...e.filter(e=>e.key===t)],a;for(let e of i){let t=e.steps?.[n]?.settings;!t||Object.keys(t).length===0||(a={...a,...t})}return a}function Or(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}var kr=`pipeline-orchestrator`;function Ar({addonId:e,highlightLabel:t}){let n=be(e),{data:r}=Wt({addonId:kr});if(n.length===0)return null;let a=ve(r??null)[e]??{};return i(`section`,{className:`space-y-1.5 border-t border-border/60 pt-3`,"aria-label":`Cluster-wide settings`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:T,children:`Cluster-wide settings`}),d(hn,{to:Fo(e),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Edit in Cluster → Settings ›`})]}),n.map(e=>i(`div`,{className:`${p} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[d(`span`,{className:P,children:e.label}),d(`span`,{className:v,children:d(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),d(`p`,{className:B,children:`One value for every node and camera — this step writes into a shared index.`})]})}function jr({rows:e}){return i(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>i(`li`,{className:`${C} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-foreground-muted`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:e.modelId??`—`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.sourceLabel})]},e.id))}),d(`p`,{className:B,children:`To change a model, open that accelerator's cell in the table.`})]})}r();function Mr(e,n){let[r,i]=mn(),o=r.get(An),s=r.get(`acc`),c=a(()=>Nn(e,n,{step:o,acc:s}),[e,n,o,s]),l=t(e=>{i(t=>{let n=new URLSearchParams(t);return e(n),n},{replace:!0})},[i]);return{selection:c,open:t(e=>l(t=>{t.set(An,e.stepId),e.acceleratorId===void 0?t.delete(`acc`):t.set(`acc`,e.acceleratorId)}),[l]),close:t(()=>l(e=>{e.delete(An),e.delete(`acc`)}),[l])}}function Nr(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function Pr(e){return e.split(`.`)[0]??e}function Fr(e,t,n){return{id:Mn(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${Pr(t)} · ${W(n)}`,shortLabel:`${Pr(t)} · ${rn(n)}`,nodeLabel:Pr(t),disabled:!n.enabled}}function Ir(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>Fr(e,t,n))}function Lr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>Fr(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>Fr(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[Fr(e.id,e.name,a)]})}function Rr(e,t,n){return{modelId:qt({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function zr(e,t,n){let r=Nr(e,`object-detection`);if(r===null)return;let i=qt({catalog:r,device:t.device,base:t.device.steps?.[`object-detection`]?.modelId,override:n});if(i===void 0)return;let a=r.models.find(e=>e.id===i);return{modelId:i,name:a?.name??i,supplies:a?.suppliesSteps??[]}}function Br(e,t,n){return!Te(e)||n===void 0?!1:Se(e,t,n.supplies).effective}function Vr(e,t){return e!==null&&Ut(e.models,t.device.format)}function Hr(e){return Vr(e.addon,e.acc)?e.clusterModelId===void 0?{kind:`enabled`,modelId:e.model.modelId??`Auto`,overridden:e.model.source===`camera`,...e.rootName===void 0?{}:{suppliedByRoot:e.rootName},...e.jumpTo===void 0?{}:{jumpTo:e.jumpTo}}:{kind:`enabled`,modelId:e.clusterModelId,clusterWide:!0}:e.gatedOn?e.jumpTo===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:e.jumpTo}:{kind:`na`}}function Ur(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function Wr(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=be(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function Gr(e){return e.flatMap(e=>[{node:e,depth:0},...Gr(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function Kr(e,t){return e.flatMap(e=>{let n=Kr(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}r();function qr(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:W(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Jr({tree:e,searchRows:r,accelerators:o,cellState:s,stepBadge:c,disabledCount:l,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:y}){let b=St(),x=$t(),{selection:S,open:C,close:w}=Mr(a(()=>Gr(e).map(e=>e.node.addonId),[e]),a(()=>o.map(e=>e.id),[o])),[T,E]=u(``),[D,O]=u(null),[k,A]=u(null),j=n(null),M=n(null),P=n(null),F=n(null),I=a(()=>Le(r,T),[r,T]),ee=a(()=>T.trim()===``?e:Kr(e,new Set(I.map(e=>e.addonId))),[e,I,T]),te=e=>I.find(t=>t.addonId===e)?.matchedField??null,ne=a(()=>o.map(qr),[o]),L=e=>o.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),R=o.find(e=>e.id===S.acceleratorId)??null,z=S.stepId!==null,re=t(async e=>{if(m){if(!await b({title:`Discard unsaved changes?`,message:`This step has changes that are not saved yet.`,confirmLabel:`Discard`,variant:`danger`}))return;h()}e()},[b,m,h]),ie=()=>{requestAnimationFrame(()=>F.current?.focus())},ae=(e,t,n=!1)=>{if(e===S.stepId&&(t?.id??null)===S.acceleratorId){n&&ie();return}let r=()=>{O(te(e)),C({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&ie()};e===S.stepId?r():re(r)},oe=()=>{let e=S.stepId;re(()=>{if(w(),e!==null){let t=R===null?null:vt({agentNodeId:R.nodeId,deviceKey:R.deviceKey});requestAnimationFrame(()=>j.current?.focusCell(e,t))}})},se=e=>{if(e.key===`Enter`){let t=I[0];if(t===void 0)return;e.preventDefault(),ae(t.addonId,void 0,!0)}else e.key===`Escape`&&E(``)},ce=x?d(Be,{onClick:oe}):d(xt,{icon:N,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:oe});return i(`div`,{ref:M,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),P.current?.focus()),e.key===`Escape`&&t&&z&&(e.preventDefault(),oe())},children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),d(`input`,{ref:P,type:`search`,value:T,onChange:e=>E(e.target.value),onKeyDown:se,placeholder:`Filter steps or settings /`,"aria-label":`Filter steps or settings`,className:`h-9 w-56 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30 md:h-7`}),l>0&&i(`label`,{className:`inline-flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(Tt,{checked:f,onChange:e=>p(e.target.checked)}),`Show disabled accelerators (`,l,`)`]}),_]}),S.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:[`The link names a step this pipeline does not have (`,S.staleStepId,`).`]}),ee.length===0?i(`p`,{className:`${B} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:[`No step matches “`,T,`”.`]}):d(Ye,{ref:j,tree:ee,agents:ne,label:v,getCellState:(e,t)=>{let n=L(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>ae(e,L(t),n),onStepClick:(e,t)=>ae(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:z&&S.stepId!==null&&R!==null?{addonId:S.stepId,agentNodeId:R.nodeId,deviceKey:R.deviceKey}:null,fallbackNodeId:k,onFallbackNodeChange:A,reserveRightPx:z&&!x?432:0}),d(nt,{open:z,anchor:M,onClose:oe,label:`Step settings`,children:S.stepId!==null&&y({stepId:S.stepId,accelerator:R,matchedField:D,closeButton:ce,onEscape:oe,headingRef:e=>{F.current=e}})})]})}r();function Yr(e){f(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}r();function Xr(e,t){let n=e.filter(e=>e.steps?.[t]?.settings!==void 0),r=e=>e.toSorted((e,t)=>e.key.localeCompare(t.key));return r(n.filter(e=>e.enabled))[0]?.key??r(n)[0]?.key??r(e.filter(e=>e.enabled))[0]?.key??e[0]?.key}function Zr(e,t){let n=t.settings===void 0?void 0:Xr(e,t.stepId),r=e.map(e=>{let r={...e.steps},i=r[t.stepId]??{},a=t.models[e.key],o=t.jumps[e.key],s=e.key===n&&t.settings!==void 0?Object.keys(t.settings).length>0?t.settings:void 0:i.settings,c=a===void 0?i.modelId:a??void 0,l=o===void 0?i.jumpDeviceKey:o||void 0,u={...c===void 0?{}:{modelId:c},...s===void 0?{}:{settings:s},...l===void 0?{}:{jumpDeviceKey:l}};return Object.keys(u).length>0?r[t.stepId]=u:delete r[t.stepId],{key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:r}});return n===void 0?r:Er(r,n,t.stepId)}function Qr(e,t,n){if(t===null)return 0;let r=Object.entries(t.models).filter(([n,r])=>(r??void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.modelId).length,i=Object.entries(t.jumps).filter(([n,r])=>(r||void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.jumpDeviceKey).length,a=new Set([...Object.keys(n),...Object.keys(t.settings??{})]),o=t.settings===void 0?0:[...a].filter(e=>!je(n[e],t.settings?.[e])).length;return r+i+o}function $r({nodeId:e,nodeName:t,toolbar:n}){let r=c(),s=We({nodeId:e},{refetchOnMount:`always`}),l=an({nodeId:e},{refetchOnMount:`always`}),f=ke(Wt({addonId:`pipeline-orchestrator`}).data??null),p=s.data?.devices??[],m=l.data??null,[h,g]=u(null),[_,v]=u(null),[y,b]=u(null),x=Xe({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),S=a(()=>m?st(m):[],[m]),C=a(()=>Gr(S),[S]),[w,E]=u(!1),D=a(()=>Ir(e,t,p,w),[e,t,p,w]),O=a(()=>Ir(e,t,p),[e,t,p]),k=O.length>=2,A=(e,t)=>(t===void 0?void 0:Dr(p,t.deviceKey,e))??{},j=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return O.find(e=>e.deviceKey===r);if(!Vr(e,t))return O.filter(n=>n.id!==t.id&&Vr(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},M=(e,t)=>{let n=Nr(m,e),r=Ro(e),i=zr(m,t),a=A(e,t),o=j(n,t);return Hr({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?Rr(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...Br(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:f[e]??r.defaultModelId}:{},...o?{jumpTo:rn(o.device)}:{}})},N=C.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Wr(Nr(m,e.addonId))}));if(s.isLoading||l.isLoading)return d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`});if(m===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`});let P=i(`span`,{className:B,children:[`Accelerators:`,` `,d(`span`,{className:`text-foreground`,children:O.length>0?O.map(e=>rn(e.device)).join(` · `):`none enabled`}),p.some(e=>!e.enabled)&&i(o,{children:[` `,`— off:`,` `,p.filter(e=>!e.enabled).map(rn).join(`, `)]}),` `,`·`,` `,d(hn,{to:Io(),className:`text-primary hover:underline`,children:`Cluster → Load balancing ›`})]});return d(Jr,{tree:S,searchRows:N,accelerators:D,cellState:M,disabledCount:p.filter(e=>!e.enabled).length,showDisabled:w,onShowDisabledChange:E,dirty:h!==null&&Qr(p,h,A(h.stepId,D[0]))>0,onDiscard:()=>g(null),summary:P,...n===void 0?{}:{toolbar:n},label:`Detection steps`,renderDetail:({stepId:n,accelerator:r,matchedField:a,closeButton:s,onEscape:c,headingRef:l})=>{let u=Nr(m,n);if(u===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let f=h?.stepId===n?h:null,S=r??O[0]??D[0],C=A(n,S),w=f?.settings??C,E=Qr(p,f,C),M=e=>{b(null),g(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},N=Ro(n),P=Vt(u),F=S===void 0?void 0:zr(m,S),I=e=>{let t=f?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},ee=S===void 0?void 0:Rr(u,S,{nodePin:I(S)}).modelId,te=D.length>1&&D.some(e=>!je(A(n,e),C)),ne=e=>{let t=I(e),r=Rr(u,e,{nodePin:t}),a=zr(m,e),s=Br(n,f?.settings??A(n,e),a),c=f?.jumps[e.deviceKey],l=j(u,e,c),p=Vr(u,e)?s&&a?d(tn,{rootModel:a,stepModelId:r.modelId}):void 0:i(o,{children:[`No `,e.device.format,` build of this step.`,` `,l?`It runs on ${l.shortLabel} instead.`:`It does not run here.`]}),h=k?i(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Run on`}),d(H,{"aria-label":`Run on`,value:c??e.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:`Auto (this accelerator, or the next one that can run it)`},...O.filter(t=>t.id!==e.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:t=>M({jumps:{...f?.jumps,[e.deviceKey]:t.target.value}})}),d(`span`,{className:B,children:`Routes this step (and its child steps) to another accelerator of this node.`})]}):void 0;return{label:e.label,format:e.device.format,modelId:r.modelId,source:r.source===`node`?`node`:`default`,sourceLabel:r.source===`node`?`node pin`:`hardware default`,models:Nt(u.models??[],e.device.format),defaultModelId:u.defaultModelIdByFormat?.[e.device.format]??u.defaultModelId,expanded:_===e.id,onToggle:()=>v(t=>t===e.id?null:e.id),onChangeModel:t=>M({models:{...f?.models,[e.deviceKey]:t}}),...t===void 0?{}:{onReset:()=>M({models:{...f?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...p===void 0?{}:{note:p},...h===void 0?{}:{extra:h},changed:f?.models[e.deviceKey]!==void 0||c!==void 0}},L=()=>{f!==null&&x.mutate({agentNodeId:e,inferenceDevices:Or(Zr(p,f))},{onSuccess:()=>{g(null),b({kind:`saved`})},onError:e=>b({kind:`error`,error:e.message})})};return d(lt,{ref:l,title:r===null?`${u.name} · ${t}`:`${u.name} · ${r.label}`,subtitle:r===null?`${u.slot} · every accelerator of ${t}`:`${u.slot} · ${r.device.format} · base for every camera that lands here`,leading:s,onEscape:c,saveBar:{dirtyCount:E,saving:x.isPending,status:y?.kind??null,...y?.error===void 0?{}:{error:y.error},onSave:L,onDiscard:()=>g(null)},children:i(`div`,{className:`space-y-3`,children:[i(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[d(`h3`,{className:T,children:`Model`}),N!==null&&S!==void 0?d(zo,{step:N,engineFormat:S.device.format,runnableModelIds:Nt(u.models??[],S.device.format).map(e=>e.id)}):D.length===0?i(`p`,{className:B,children:[`No accelerator is enabled on this node —`,` `,d(hn,{to:Io(),className:`text-primary hover:underline`,children:`enable one in Cluster → Load balancing`}),`.`]}):r===null?d(jr,{rows:D.map(e=>{let t=Rr(u,e,{nodePin:I(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):d(sn,{...ne(r)},r.id)]}),(P.length>0||F!==void 0)&&N===null&&i(`section`,{"aria-label":`Settings`,className:`space-y-2 border-t border-border/60 pt-2`,children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`settings-scope`,children:[`Node-wide: these settings apply on every accelerator of `,t,`.`]}),te&&d(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2 py-1 text-[11px] text-warning`,children:`This step's settings differ between this node's accelerators. Saving makes the values shown here node-wide.`}),d(ei,{addon:u,fields:P,settings:w,modelId:Ot(u,ee,w,F),root:F,highlight:a,onChange:e=>M({settings:e})})]}),d(Ar,{addonId:n,highlightLabel:a})]})})}})}function ei({addon:e,fields:t,settings:n,modelId:r,root:i,highlight:a,onChange:o}){let s=t.find(e=>`label`in e&&e.label===a)?.key??null;return Yr(s===null?null:At(s)),d(nn,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:`Node`},modelId:r,...i===void 0?{}:{rootModel:i},highlightKey:s,onChangeLayer:o})}r();function ti({nodeId:e,refreshToken:t}){let n=St(),[r,a]=u(null),{nodes:s}=K(),c=s.find(t=>t.id===e)?.name??e,l=Ge({onSuccess:e=>{a(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${c} 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`})&&(a(null),l.mutate({agentNodeId:e}))};return i(`div`,{className:`space-y-2`,children:[d(Tr,{nodeId:e}),d($r,{nodeId:e,nodeName:c,toolbar:i(o,{children:[r&&d(`span`,{className:`text-[11px] text-success`,children:r}),l.isError&&d(`span`,{className:`text-[11px] text-danger`,children:l.error instanceof Error?l.error.message:`Reset failed`}),d(V,{variant:`outline`,size:`sm`,onClick:()=>{f()},disabled:l.isPending,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:l.isPending?`Resetting…`:`Reset to default`})]})})]})}var ni=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],ri=`decoder-nodeav`,ii=`ntab`,ai={decoder:`engine`},oi={engine:`Engine & decoder`},si=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function ci({nodeId:e,refreshToken:t}){let[n,r]=mn(),{nodes:a}=K(),o=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??ri,s=[...ni,o],c=n.get(ii),l={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:d(yr,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:d(ti,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:d(xr,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:d(wr,{nodeId:e})}},u=Hn.map(e=>l[e]);return i(`div`,{className:`flex flex-col h-full`,children:[d(Vn,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:d(gn,{nodeId:e,addonIds:s,level:`global`,fieldScope:`perNode`,emptyMessage:si,tabAliases:ai,tabLabelOverrides:oi,extraTabs:u,activeTab:c===null?null:ai[c]??c,onActiveTabChange:e=>r(t=>{let n=new URLSearchParams(t);n.set(ii,e);for(let e of jn)n.delete(e);return n},{replace:!0})})})]})}function li(){return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Camera placement`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pin a camera to a node, or to one accelerator of its node; Auto lets each session pick. Decode always runs with detection. Load, shares and caps are on Load balancing.`})]}),d(_r,{})]})}function ui(e){return`${Math.round(e*100)}%`}function di(e){return`${e} session${e===1?``:`s`}`}var fi={"intel-npu":`Intel NPU`,"intel-igpu":`Intel iGPU`,"amd-igpu":`AMD iGPU (WebGPU)`,"amd-npu":`AMD XDNA NPU`,"x86-cpu":`CPU`,"arm-cpu":`CPU`,"apple-ane":`Apple Neural Engine`,coral:`Coral Edge TPU`},pi={"intel-core-ultra":`Intel Core Ultra`,"intel-n-series":`Intel N-series`,"apple-m-base":`Apple M (base)`,"apple-m-pro":`Apple M Pro / Max / Ultra`,"amd-phoenix":`AMD Ryzen Phoenix / Hawk Point`,unknown:`Not measured`};function mi(e){return e===null?`—`:fi[e]??e}function hi(e){return e===null?`—`:pi[e]??e}function gi(e){switch(e.kind){case`capacity`:return`Capacity ${di(e.sessions)} ≥ min ${e.minSessions}.`;case`tie-faster`:return`As accurate as ${e.over} (within ${ui(e.recallDelta)} recall) and faster.`;case`stepped-down`:return`${e.from} would not fit the load on ${e.limitedBy}; ${e.to} is the most accurate that does.`;case`no-fit-lightest`:return`No model reaches ${di(e.minSessions)} per device; the one with the most capacity (${di(e.sessions)}) is used.`;case`derived-latency`:return`${e.modelId}: latency estimated from a similar chip, not measured on this one.`;case`cpu-device`:return`CPU fallback device: picked on its own.`;case`coral-untouched`:return`Coral: left as is (no YOLOv9 build exists for it).`;case`device-disabled`:return`Disabled: not changed.`;case`device-unavailable`:return`Not available on the node right now: not changed.`;case`node-offline`:return`Node offline: nothing on it will change.`;case`no-hardware-facts`:return`Hardware could not be read: nothing on this node will change.`;case`no-measured-data`:return`This hardware has no measured data: nothing on this node will change.`;case`no-family-build`:return`No YOLOv9 build for the ${e.format} format: not changed.`;case`kept-custom-pin`:return`Custom model ${e.modelId} is pinned on ${e.deviceKey}: Auto tune skips this device.`}}function _i(e,t){switch(e.kind){case`detector-store-cluster-wide`:return`Per-camera detector thresholds are not tied to a node, so they are cleared for every camera — including cameras that run on skipped nodes (${e.skippedNodes.map(t).join(`, `)}).`;case`detector-store-unreadable`:return`Per-camera detector thresholds could not be read (${e.error}); those will not be cleared.`;case`coral-enabled`:return`${t(e.nodeId)}: the Coral (${e.deviceKey}) is enabled and keeps running its SSD model, which finds far fewer people than YOLOv9. Consider disabling it.`;case`custom-pin-kept`:return e.deviceId===null?`${t(e.nodeId)}: custom model ${e.modelId} pinned on ${e.deviceKey??`—`} — Auto tune skips this node device.`:`Camera ${e.deviceId} pins custom model ${e.modelId} on ${t(e.nodeId)} — Auto tune keeps that override and its thresholds.`;case`custom-registry-unreadable`:return`The custom-model registry could not be read (${e.error}): every pin to a model outside the measured catalog is kept.`}}function vi(e){let t=e.nodeChanges.reduce((e,t)=>e+t.modelPins.length,0),n=e.nodeChanges.reduce((e,t)=>e+t.thresholds.length,0),r=new Set([...e.cameraClears.map(e=>e.deviceId),...e.detectorStoreClears.map(e=>e.deviceId)]);return{modelChanges:t,thresholdClears:n,cameraOverrideClears:e.cameraClears.length,detectorStoreClears:e.detectorStoreClears.length,camerasTouched:r.size}}function yi(e){let t=vi(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function bi(e,t,n){let r=e.nodeChanges.find(e=>e.nodeId===t&&e.deviceKey===n)?.modelPins.find(e=>e.stepId===`object-detection`);return r===void 0?null:{before:r.before,after:r.after}}function xi(e,t){return e?.kind===`node-benchmark`?`measured on this node, ${new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}`:`from the latency table — benchmark this node to measure it`}r();var Si=[.3,.4,.5];function Ci(e){return Si.some(t=>t===e)}var wi=[1,2,3,4,6,8];function Ti({plan:e,node:t,nodeName:n}){return i(`section`,{className:x,"data-testid":`auto-tune-node-${t.nodeId}`,children:[i(`header`,{className:`${F} flex flex-wrap items-center gap-2`,children:[d(g,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${T} min-w-0 flex-1`,children:n(t.nodeId)}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[hi(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?d(G,{variant:`warning`,children:`Not changed`}):t.acceleratorModelId!==null&&d(G,{variant:`info`,children:t.acceleratorModelId})]}),t.reasons.length>0&&d(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:t.reasons.map((e,t)=>d(`li`,{children:gi(e)},t))}),d(`div`,{className:`overflow-x-auto`,children:i(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:i(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Device`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Capacity`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Detector`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Why`})]})}),d(`tbody`,{children:t.devices.map(n=>{let r=bi(e,t.nodeId,n.deviceKey);return i(`tr`,{className:`border-t border-border align-top`,children:[i(`td`,{className:`px-3 py-1.5`,children:[d(`div`,{className:`font-mono text-foreground`,children:n.deviceKey}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:mi(n.accelerator)})]}),i(`td`,{className:`px-3 py-1.5 text-foreground-muted`,children:[n.chosen===null?`—`:`${n.chosen.capacitySessions} session${n.chosen.capacitySessions===1?``:`s`} at ${e.cameraFps} fps`,n.chosen!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n.chosen.fps,` fps, `,Math.round(e.headroom*100),`% kept free`,d(`div`,{children:xi(n.chosen.source)})]})]}),d(`td`,{className:`px-3 py-1.5`,children:n.chosen===null?d(`span`,{className:`text-foreground-subtle`,children:`unchanged`}):r!==null&&r.before!==r.after?i(`span`,{children:[d(`span`,{className:`text-foreground-subtle`,children:r.before??`default`}),` → `,d(`span`,{className:`font-medium text-foreground`,children:r.after})]}):d(`span`,{className:`text-foreground`,children:n.chosen.modelId})}),d(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>d(`div`,{children:gi(e)},t))})]},n.deviceKey)})})]})})]})}function Ei({plan:e,nameOf:t,nodeName:n}){return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[i(`div`,{children:[d(`div`,{className:T,children:`Node settings`}),e.nodeChanges.length===0?d(`div`,{className:`text-foreground-subtle`,children:`No change.`}):d(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.nodeChanges.flatMap(e=>[...e.modelPins.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: `,t.before??`default`,` → `,t.after??`step default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/pin`)),...e.thresholds.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: reset `,t.keys.join(`, `),` to the model default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),i(`div`,{children:[d(`div`,{className:T,children:`Camera overrides cleared`}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?d(`div`,{className:`text-foreground-subtle`,children:`None.`}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,r)=>i(`li`,{children:[t(e.deviceId),` — `,n(e.nodeId),e.deviceKey===null?` (whole pipeline)`:` · ${e.deviceKey}`,` — `,e.stepId,e.modelIdBefore===null?``:`: model ${e.modelIdBefore} removed`,e.keys.length>0?`; ${e.keys.join(`, `)} reset`:``]},`c${r}`)),e.detectorStoreClears.map(e=>i(`li`,{children:[t(e.deviceId),` — detector thresholds: `,e.keys.join(`, `),` reset`]},`d${e.deviceId}`))]})]})]})}function Di({result:e}){return e.kind===`refused`?d(`div`,{className:`text-xs text-warning`,children:`Another apply is already running.`}):e.kind===`stale`?d(`div`,{className:`text-xs text-warning`,children:`The configuration changed since the plan was shown. Review the updated plan below and apply again.`}):i(`ul`,{className:`text-xs`,"data-testid":`auto-tune-result`,children:[e.kind===`aborted`&&d(`li`,{className:`text-danger`,children:`A model could not be downloaded: nothing was changed.`}),e.phases.map(e=>i(`li`,{className:e.ok?`text-foreground-muted`:`text-danger`,children:[e.ok?`✓`:`✗`,` `,e.phase,`: `,e.detail]},e.phase))]})}function Oi(){let e=c(),[t,n]=u(.4),[r,o]=u(2),[s,l]=u(!1),[f,p]=u(!1),[m,h]=u(null),{data:g}=pn(),_=a(()=>new Map((g??[]).map(e=>[e.id,e.name])),[g]),v=e=>_.get(e)??`Camera ${e}`,{nodes:y}=K(),b=a(()=>Xn(y),[y]),S=qe({headroom:t,minSessionsPerDevice:r},{enabled:s,refetchOnWindowFocus:!1}),C=un({onSuccess:t=>{h(t),p(!1),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.kind===`applied`&&S.refetch()}}),w=m?.kind===`stale`?m.plan:S.data,D=w===void 0?null:vi(w);return i(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[i(`section`,{className:x,children:[i(`header`,{className:`${F} flex flex-wrap items-center gap-2`,children:[d(E,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${T} min-w-0 flex-1`,children:`Auto tune`})]}),i(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[d(`p`,{children:`Picks, for every accelerator, the most accurate YOLOv9 detector that still carries at least the chosen number of cameras at once, from the node's hardware and measured speeds. Nothing is measured or estimated about your cameras' activity. Applying it sets those models and clears every model and threshold override — node level and per camera — so each model runs its own default thresholds. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`Keep free`}),d(H,{"aria-label":`Share of each accelerator kept free`,value:String(t),options:Si.map(e=>({value:String(e),label:`${Math.round(e*100)}% of each accelerator`})),onChange:e=>{let t=Number(e.target.value);Ci(t)&&n(t)}})]}),i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`At least`}),d(H,{"aria-label":`Minimum parallel sessions per device`,value:String(r),options:wi.map(e=>({value:String(e),label:`${e} camera${e===1?``:`s`} at once per accelerator`})),onChange:e=>{let t=Number(e.target.value);wi.some(e=>e===t)&&o(t)}})]}),d(V,{size:`sm`,variant:`secondary`,onClick:()=>{h(null),l(!0),s&&S.refetch()},children:S.isFetching?`Computing…`:w===void 0?`Compute plan`:`Recompute`}),w!==void 0&&d(V,{size:`sm`,disabled:yi(w),onClick:()=>p(!0),children:`Apply…`})]}),S.error!==null&&d(`div`,{className:`text-danger`,children:S.error.message}),m!==null&&d(Di,{result:m}),D!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[D.modelChanges,` model change(s), `,D.thresholdClears,` node threshold reset(s), `,D.cameraOverrideClears+D.detectorStoreClears,` camera override(s) on `,D.camerasTouched,` camera(s).`]})]})]}),w?.warnings.map((e,t)=>d(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:_i(e,b)},t)),w?.nodes.map(e=>d(Ti,{plan:w,node:e,nodeName:b},e.nodeId)),w!==void 0&&d(ut,{open:f,onOpenChange:p,children:i(ze,{width:`lg`,scroll:`body`,children:[i(Fe,{children:[d(Rt,{children:`Apply auto tune?`}),d(rt,{children:`These are all the changes. Every override listed is removed and cannot be restored.`})]}),d(Ve,{children:d(Ei,{plan:w,nameOf:v,nodeName:b})}),i(zt,{children:[d(V,{variant:`ghost`,onClick:()=>p(!1),children:`Cancel`}),d(V,{variant:`danger`,disabled:C.isPending,onClick:()=>C.mutate({planHash:w.planHash,headroom:t,minSessionsPerDevice:r}),children:C.isPending?`Applying…`:`Apply`})]})]})})]})}var ki={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 Ai(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function ji(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function Mi(e,t,n){let r=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let i=t.get(e.key)??(n?0:null),a=e.weight>0?e.weight:1;return{key:e.key,label:W(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?Ai(a,r):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i!==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 Ni(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);return e.nodes.map(r=>{let i=t.get(r.id),a=Mi(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),ji(i)),o=r.isOnline&&r.detectEnabled,s=r.weight>0?r.weight:1,c=i?.load.attachedCameras??null;return{nodeId:r.id,name:r.name,isOnline:r.isOnline,detectEnabled:r.detectEnabled,reported:i!==void 0,attachedCameras:c,activeCameras:i?.load.activeCameras??null,maxCameras:r.maxCameras,capacityPct:c!==null&&r.maxCameras!==null&&r.maxCameras>0?Ai(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?Ai(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}r();var Pi=2e4,Fi=3e5;function Ii({stats:e,targetWeights:t}){let{nodes:n}=K(),r=te().trpcClient,o=ln(void 0,{placeholderData:l,staleTime:Pi,refetchInterval:Pi,refetchOnWindowFocus:!0}),c=ht(void 0,{staleTime:Fi}),u=a(()=>n.map(e=>e.id),[n]),f=s({queries:u.map(e=>({queryKey:Pe(Mt.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Fi,refetchOnWindowFocus:!1,placeholderData:l}))}),p=a(()=>{let e={};return u.forEach((t,n)=>{let r=f[n]?.data;r&&(e[t]=r.devices)}),e},[u,f.map(e=>e.dataUpdatedAt).join(`|`)]),h=a(()=>{let e=new Map;for(let t of c.data??[])e.set(t.nodeId,t.settings);return e},[c.data]),g=a(()=>n.map(e=>{let n=h.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:Rn(n,e.isHub).pipeline,weight:t?.[e.id]??yn(n,`detectWeight`)??1,maxCameras:yn(n,`maxCameras`)}}),[n,h,t]),_=o.data??[],v=a(()=>Ni({nodes:g,loads:_,devicesByNode:p}),[g,_,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),x=o.dataUpdatedAt>0?Date.now()-o.dataUpdatedAt:null,C=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return d(U,{headingId:`load-balancing-node-load`,title:`Node load`,icon:S,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[b,` running · `,y,` attached ·`,` `,o.data===void 0?`reading…`:`${x===null?`—`:`${Math.round(x/1e3)}s`} old`]}),children:d(`div`,{className:m,children:v.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>d(Li,{row:e,placed:C.get(e.nodeId)},e.nodeId))})})})}function Li({row:e,placed:t}){let n=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`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&&i(`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:[d(b,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(k,{className:`h-2.5 w-2.5`}),` offline`]})]}),i(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:n,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share (1 h)`,value:t?.observedShare===null||t===void 0?`—`:`${Math.round(t.observedShare*100)}%`,title:`Time-weighted share of the cluster's PARALLEL detection sessions this node carried over the last hour — the quantity a share holds. '—' = no session ran here in the window.`}),d(J,{label:`Peak · yields`,value:t===void 0?`—`:`${t.peakSessions} · ${t.yieldsAway}`,title:`Most sessions this node ran at once in the last hour, and how many share turns it handed to another node because it was full or drowning.`}),d(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&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(Ri,{row:e})]})}function Ri({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):i(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[i(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(w,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`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`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(zi,{device:e},e.key))})]})}function zi({device:e}){let t=e.exclusion;return i(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(g,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?i(o,{children:[i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,title:e.sessions===null?`Not known: the node did not report, or runs a session no device accounts for.`:void 0,children:[`· `,e.sessions??`—`,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):i(`span`,{className:`truncate text-foreground-subtle/80`,title:ki[t],children:[`excluded — `,ki[t]]})]})}function J({label:e,value:t,title:n}){return i(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Bi(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Vi(e){let t={},n={};for(let r of e.nodes){if(r.share===null||r.share<=0)continue;t[r.nodeId]=r.share;let e=Object.fromEntries(r.devices.filter(e=>e.share>0).map(e=>[e.deviceKey,e.share]));Object.keys(e).length>0&&(n[r.nodeId]=e)}return{nodes:t,devices:n}}function Hi(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Ui(e){return e.reason===`disabled`?`${e.deviceKey} is not enabled on any node — sessions ignore this pin`:`no node offers ${e.deviceKey} — sessions ignore this pin`}function Wi(e,t){if(t===void 0||t.source===`manual`||t.autoPending)return{nodes:e,readOnly:t!==void 0&&t.source!==`manual`};let n=new Map(t.nodes.map(e=>[e.nodeId,e.configuredPct]));return{nodes:e.map(e=>({...e,weight:Math.round(n.get(e.id)??e.weight)})),readOnly:!0}}function Gi(e,t){let n=e.nodes.filter(e=>!e.eligible);if(n.length===0)return null;let r=e.nodes.filter(e=>e.eligible).map(e=>`${t(e.nodeId)} ${Math.round(e.effectivePct)}%`).join(`, `);return`${n.map(e=>t(e.nodeId)).join(`, `)} cannot take sessions — ${n.length===1?`its share goes`:`their shares go`} to the others: ${r}`}var Ki=[{value:`hardware`,label:`Hardware`,hint:`Each node’s share follows what its accelerators can carry at their Auto tune models, from the measured speed of its hardware. No load is measured or estimated.`},{value:`benchmark`,label:`Benchmark`,hint:`Each node’s share follows its own node-benchmark results. A node without results uses its hardware capacity instead, and says so.`},{value:`manual`,label:`Manual`,hint:`The sliders below, as you set them.`}];function qi(e){return e===`no-benchmark-results`?`no benchmark results yet — sized from hardware`:e===`partial-benchmark-results`?`benchmark results miss some of its accelerators — sized from hardware`:null}function Ji(e,t){if(e.source!==`benchmark`)return null;let n=e.nodes.filter(e=>e.capacityFallback!==null);return n.length===0?null:n.map(e=>`${t(e.nodeId)}: ${qi(e.capacityFallback)??``}`).join(` · `)}r();function Yi(e,t,n){return Math.min(Math.max(e,t),n)}function Xi(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function Zi(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:Yi(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function Qi(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function $i({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:a,footnote:s,readOnly:c=!1}){let[l,p]=u(()=>Xi(e)),[m,h]=u(new Set);f(()=>{p(Xi(e)),h(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let g=e.map(e=>e.id),_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=(e,t)=>{p(n=>Zi(n,e,t,m,g))},y=()=>{let t=Qi(l,g,m),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...m]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:a??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let b=e.length===1;return i(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=l[e.id]??0,a=m.has(e.id);return i(`div`,{className:`flex items-center gap-3`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),d(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:c||t||a||b,onChange:t=>v(e.id,Number(t.target.value)),onPointerUp:()=>y(),onKeyUp:()=>y(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),i(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),!c&&d(`button`,{type:`button`,onClick:()=>_(e.id),disabled:t||b,"aria-pressed":a,title:a?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${a?`text-amber-400`:`text-foreground-subtle`}`,children:d(a?ee:L,{className:`h-3.5 w-3.5`})})]},e.id)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:s??d(o,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}function ea(e){let t=e.steps?.[`object-detection`]?.modelId;return typeof t==`string`&&t.length>0?t:typeof e.defaultModelId==`string`&&e.defaultModelId.length>0?e.defaultModelId:null}r();function ta(e){let t=W(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:g,hue:`slate`}:r===`npu`?{label:t,Icon:re,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:de,hue:`violet`}:n===`edgetpu`?{label:t,Icon:he,hue:`emerald`}:{label:t,Icon:g,hue:`slate`}}var na={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function ra({nodeId:e,nodeName:t,isOnline:n,suggestedMaxSessions:r,autoDeviceShares:s}){let l=c(),{data:p,isLoading:m}=We({nodeId:e},{refetchInterval:15e3}),h=Xe({onSettled:()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),g=p?.devices??[],_=p?.reachable??n,[v,y]=u({});f(()=>{y(Object.fromEntries(g.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[g.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let b=a(()=>g.filter(e=>v[e.key]?.enabled??e.enabled).length,[g,v]),[x,S]=u(null),C=x??b>0,w=t=>{let n=g.map(e=>{let n=t[e.key]??T(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});h.mutate({agentNodeId:e,inferenceDevices:Or(n)})},T=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),E=e=>{if(!e.available)return;let t=v[e.key]??T(e),n={...v,[e.key]:{...t,enabled:!t.enabled}};y(n),w(n)},D=(e,t)=>{let n=v[e.key]??T(e),r={...v,[e.key]:{...n,maxSessions:t}};y(r),w(r)},A=a(()=>g.filter(e=>(v[e.key]?.enabled??e.enabled)&&e.available),[g,v]),j=a(()=>A.map(e=>({id:e.key,name:ta(e).label,weight:s===void 0?v[e.key]?.weight??e.weight:Math.round(s[e.key]??0)})),[A,v,s]);return i(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[i(`button`,{type:`button`,onClick:()=>S(!C),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":C,children:[d(O,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${C?`rotate-90`:``}`}),d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),d(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:_?b>=2?i(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[d(_e,{className:`h-3.5 w-3.5`}),b,` accelerators`]}):b===1?d(`span`,{className:`text-foreground-subtle`,children:`single default`}):d(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):i(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[d(k,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),C&&i(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[_?m&&g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):g.length===0?d(`p`,{className:`rounded-lg 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.`}):d(`ul`,{className:`space-y-2`,children:g.map(e=>{let t=ta(e),n=v[e.key]??T(e),a=n.enabled&&e.available,s=ea({defaultModelId:e.defaultModelId,steps:n.steps});return i(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[d(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${na[t.hue]}`,children:d(t.Icon,{className:`h-4.5 w-4.5`})}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),d(G,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&d(G,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`font-mono`,children:e.key}),s!==null&&i(o,{children:[d(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:[`root model`,` `,d(`span`,{className:`font-mono text-foreground/80`,children:s})]})]})]})]}),a&&i(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),d(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);D(e,r!=null&&r>0?r:null)},disabled:h.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),a&&d(ia,{suggested:r?.[e.key]??null,current:n.maxSessions,pending:h.isPending,onApply:t=>D(e,t)}),d(It,{checked:a,onCheckedChange:()=>E(e),disabled:!e.available||h.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):d(aa,{}),_&&A.length>=2&&i(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[i(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[d(pe,{className:`h-3.5 w-3.5`}),`Accelerator share`]}),d($i,{nodes:j,pending:h.isPending,onCommitWeights:e=>{let t={...v};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}y(t),w(t)},weightLabel:`Accelerator share`,readOnly:s!==void 0,footnote:s===void 0?d(o,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`}):d(o,{children:`Automatic: each accelerator's share follows its measured throughput at its model. Switch the node shares to manual to set them yourself.`})})]}),h.isError&&i(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,h.error instanceof Error?h.error.message:`unknown error`]})]})]})}function ia({suggested:e,current:t,pending:n,onApply:r}){return e===null||e<1||e===t?null:i(V,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`,children:[`use `,e]})}function aa(){return i(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[d(k,{className:`h-6 w-6 text-foreground-subtle/60`}),d(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),d(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}r();var oa=3600*1e3,sa=2e4,ca=.4;function la({refreshToken:e,onOpenAutoTune:t}){let n=c(),{nodes:r}=K(),s=ht(void 0),f=Ht({isCamera:!0,projection:`slim`}),p=fn({windowMs:oa},{refetchInterval:sa,placeholderData:l}).data,h=it(void 0,{refetchInterval:sa,placeholderData:l}).data,_=()=>{Cn(n),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},v=Ft({onSuccess:_}),y=Kt({onSuccess:()=>{_(),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),b=yt({onSuccess:_}),x=pt(),[S,w]=u(!1),T=h?.source,D=T===`benchmark`?`benchmark`:`hardware`,O=en({headroom:ca,source:D},{enabled:S,staleTime:1/0}),k=O.data,A=a(()=>{let e=new Map((s.data??[]).map(e=>[e.nodeId,e.settings]));return r.filter(t=>Rn(e.get(t.id),t.isHub).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:yn(n,`detectWeight`)??1,maxCameras:yn(n,`maxCameras`)}})},[r,s.data]),j=e=>r.find(t=>t.id===e)?.name??e,M=Zn((f.data??[]).map(e=>({id:e.id,name:e.name}))),N=k?Hi(k):void 0,P=Wi(A,h),F=T!==`manual`,ee=e=>{if(h===void 0||h.source===`manual`||h.autoPending)return;let t=h.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},te=h?Gi(h,j):null,ne=h?Ji(h,j):null,L=Ki.find(e=>e.value===T)?.hint;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(gn,{nodeId:`hub`,addonIds:[Dn],level:`global`,sectionIds:[`load`],title:`Placement policy`,description:`How a new detection session picks its node and device, and what happens when a node falls behind. 'Honour shares' (default) holds the shares below for PARALLEL sessions.`}),d(Un,{refreshToken:e}),d(Ii,{stats:p,...h!==void 0&&h.source!==`manual`&&!h.autoPending?{targetWeights:Object.fromEntries(h.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),d(U,{headingId:`load-balancing-node-shares`,title:`Node shares`,icon:pe,actions:i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{role:`radiogroup`,"aria-label":`Share source`,className:`flex items-center gap-1`,children:Ki.map(e=>d(V,{role:`radio`,"aria-checked":T===e.value,variant:T===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:y.isPending||h===void 0,onClick:()=>{T!==e.value&&y.mutate({source:e.value})},children:e.label},e.value))}),i(V,{variant:`outline`,size:`sm`,onClick:()=>{w(!0),S&&O.refetch()},disabled:O.isFetching,children:[d(I,{className:`h-3.5 w-3.5`}),O.isFetching?`Suggesting…`:D===`benchmark`?`Suggest from benchmark`:`Suggest from hardware`]}),i(V,{variant:`ghost`,size:`sm`,onClick:t,children:[d(E,{className:`h-3.5 w-3.5`}),`Auto tune`]}),i(V,{variant:`outline`,size:`sm`,onClick:()=>x.mutate(void 0),disabled:x.isPending,title:`Move standing (always-on) cameras that are no longer on their best node. Pinned cameras never move; on-motion sessions are placed per session anyway.`,children:[d(re,{className:`h-3.5 w-3.5`}),x.isPending?`Rebalancing…`:`Rebalance`]})]}),children:i(`div`,{className:`${m} space-y-3`,children:[L!==void 0&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:L}),p&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Policy:`,` `,d(G,{variant:p.policy===`share`?`info`:`default`,children:p.policy===`share`?`honour shares`:`least-loaded`}),` `,`· cluster peak `,p.clusterPeakSessions,` parallel sessions in the last hour`,p.policy===`least-loaded`&&` · under least-loaded an idle node always wins, so shares only bite once nodes are busy`]}),d($i,{nodes:P.nodes,pending:v.isPending,readOnly:P.readOnly,onCommitWeights:e=>v.mutate(Bi(e)),weightLabel:`Node share`,...P.readOnly?{footnote:h?.autoPending?d(o,{children:`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`}):i(o,{children:[T===`benchmark`?`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`:`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`,h?.computedAt==null?``:` — last at ${new Date(h.computedAt).toLocaleTimeString()}${h.trigger===null?``:` (${h.trigger})`}`,`.`]})}:{}}),te!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:te}),ne!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:ne}),y.isError&&d($e,{message:`Failed to switch shares: ${y.error instanceof Error?y.error.message:`unknown error`}`}),v.isError&&d($e,{message:`Failed to save shares: ${v.error instanceof Error?v.error.message:`unknown error`}`}),i(`details`,{className:`rounded-md border border-border`,children:[d(`summary`,{className:`${C} cursor-pointer text-xs text-foreground`,children:`Max concurrent sessions (advanced)`}),d(`ul`,{className:`divide-y divide-border border-t border-border`,children:A.map(e=>i(`li`,{className:`${C} flex items-center gap-2`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),d(_t,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":`Max concurrent sessions for ${e.name}`,className:`w-20 text-right`,disabled:b.isPending,onBlur:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==e.maxCameras&&b.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),d(`p`,{className:`${C} ${B} border-t border-border`,children:`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`})]})]})}),O.isError&&d($e,{message:`Suggestion failed: ${O.error instanceof Error?O.error.message:`unknown error`}`}),k&&d(ua,{suggestion:k,nameOf:j,pending:v.isPending,...F?{}:{onApply:()=>v.mutate(Vi(k))}}),d(U,{headingId:`load-balancing-accelerators`,title:`Accelerators`,icon:g,children:d(`div`,{className:`${m} space-y-2`,children:A.length===0?d(at,{title:`No detect-capable nodes`,description:`Enable detection on a node in Roles & nodes to configure its accelerators.`}):A.map(e=>d(ra,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...N?.[e.id]===void 0?{}:{suggestedMaxSessions:N[e.id]},...ee(e.id)===void 0?{}:{autoDeviceShares:ee(e.id)}},e.id))})}),p!==void 0&&p.stalePins.length>0&&d(da,{stats:p,cameraName:M})]})}function ua({suggestion:e,nameOf:t,pending:n,onApply:r}){return i(U,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?`Suggested from benchmark`:`Suggested from hardware`,icon:I,...r===void 0?{}:{actions:d(V,{size:`sm`,onClick:r,disabled:n,children:`Apply suggested shares`})},children:[d(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>i(`li`,{className:`${C} space-y-0.5`,children:[i(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),d(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?`skipped`:`${e.share}%`})]}),i(`p`,{className:B,children:[qi(e.capacityFallback)===null?``:`${qi(e.capacityFallback)} · `,e.skippedReason===null?`≈ ${e.capacitySessions} parallel sessions · ${e.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}`:`not part of the suggestion — ${e.skippedReason}`]})]},e.nodeId))}),i(`p`,{className:`${C} ${B} border-t border-border`,children:[`Shares in proportion to each node's capacity in parallel sessions —`,` `,e.source===`benchmark`?`measured by node benchmarks, or from the hardware table where a node has no results`:`at the models Auto tune picks (at least ${e.minSessionsPerDevice} per accelerator), from the measured speed of each node's hardware`,`, counted in `,e.cameraFps,` fps sessions with`,` `,Math.round(e.headroom*100),`% kept free. No load is measured or estimated.`,r===void 0?`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`:`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`]})]})}function da({stats:e,cameraName:t}){let n=c(),r=wt({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return d(U,{headingId:`load-balancing-stale-pins`,title:`Stale device pins`,icon:me,children:d(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>i(`li`,{className:`${C} flex items-center gap-2`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[d(`p`,{className:`truncate text-xs text-foreground`,title:t(e.deviceId),children:t(e.deviceId)}),d(`p`,{className:B,children:Ui(e)})]}),d(V,{variant:`outline`,size:`sm`,disabled:r.isPending,onClick:()=>r.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:`Clear pin`})]},e.deviceId))})})}function fa({node:e,emphasis:t=!1}){let n=e.isHub?z:g;return i(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),i(`div`,{className:`min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(G,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(G,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}function pa({nodes:e,actions:t}){return d(Je,{columns:[{key:`node`,header:`Node`,sortValue:e=>e.name,render:e=>d(fa,{node:e})},...wn.map(e=>({key:e.key,header:e.label,align:`center`,notSortableReason:`A switch — sorting would move the row while it is being changed.`,render:n=>d(It,{"aria-label":`${e.label} on ${n.name}`,title:e.hint,checked:vn(n.effective,e.key),disabled:t.capabilityPending,onCheckedChange:r=>t.onToggleCapability(n.id,e.key,r)})}))],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,mobileMode:`scroll`,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:`No cluster nodes reporting yet.`})}function ma({roleValues:e,options:t,pending:n,onRoleChange:r}){let a=t.map(e=>({value:e.id,label:e.id===`hub`?`${e.name} (default)`:e.name}));return d(`ul`,{className:`divide-y divide-border`,children:On.map(t=>i(`li`,{className:`${C} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[i(`div`,{className:`min-w-0 flex-1 basis-56`,children:[d(`div`,{className:`text-xs font-medium text-foreground`,children:bn(t)}),d(`p`,{className:B,children:xn(t)})]}),d(`div`,{className:`w-full sm:w-48`,children:d(H,{"aria-label":`${bn(t)} node`,value:e[t],disabled:n,options:a,onChange:e=>r(t,e.target.value)})})]},t))})}r();function ha(){let e=c(),{nodes:t}=K(),n=ht(void 0),r=Wt({addonId:Dn}),o=Wt({addonId:_n}),s=Wt({addonId:kn}),l=()=>Cn(e),u=Xt({onSuccess:l}),f=Ct({onSuccess:l}),p=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),m=a(()=>t.map(e=>{let t=p.get(e.id),n=Rn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[t,p]),h={ingestNode:En(r.data,`ingestNode`,`hub`),recordingNode:En(o.data,Tn,`hub`),audioNode:En(r.data,`audioNode`,`hub`),motionNode:En(r.data,`motionNode`,`hub`),postProcessingNode:En(s.data,Sn,`hub`)},g=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id),n=e=>t.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,...On.map(e=>h[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:n(e)}))},[t,h]),_=n.isLoading||r.isLoading||o.isLoading||s.isLoading,v=(e,t,n)=>{u.mutate({agentNodeId:e,[t]:n})},y=(e,t)=>{if(e===`recordingNode`){f.mutate({addonId:_n,patch:{[Tn]:t}});return}if(e===`postProcessingNode`){f.mutate({addonId:kn,patch:{[Sn]:t}});return}f.mutate({addonId:Dn,patch:{[e]:t}})},b={capabilityPending:u.isPending,onToggleCapability:v};return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(U,{headingId:`roles-nodes-cluster-roles`,title:`Cluster roles`,icon:fe,actions:_?d(A,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":`Loading`}):null,children:[d(`p`,{className:`${B} border-b border-border px-3 py-1.5 sm:px-4`,children:`One node holds each role for every camera. Detection shares and caps are on Load balancing.`}),d(ma,{roleValues:h,options:g,pending:f.isPending,onRoleChange:y})]}),d(U,{headingId:`roles-nodes-node-capabilities`,title:`Node capabilities`,icon:z,children:d(pa,{nodes:m,actions:b})})]})}var ga=`pipeline-analytics`,_a=`face-gallery`,va=`pipeline-orchestrator`,ya=`pipeline-runner`,ba=`audio-analyzer`;function xa(e){return[...Ne.filter(t=>t.stepId===e).map(e=>xe(e.stepId)),...we.filter(t=>t.stepId===e).map(e=>Ce(e.stepId,e.key))]}var Sa=`faces`,Ca=`semantic-search`,wa=[{id:Sa,title:`Faces & recognition`,hint:`The face encoder for every node, the smallest faces worth embedding, keeping and auto-assigning, and how a face is matched to a person.`,panels:[{addonId:va,fieldKeys:xa(`face-embedding`)},{addonId:ga,capability:_a}]},{id:Ca,title:`Semantic search`,hint:`The image encoder behind "search by description". One for the whole cluster: changing it hides existing results until the index is rebuilt.`,panels:[{addonId:va,fieldKeys:xa(`clip-embedding`)}]},{id:Ae,title:`Enrichment crop`,hint:`How the crop handed to face, plate and search models is cut from the frame.`,panels:[{addonId:va,sectionIds:[Ae]}]},{id:De,title:`Full-resolution crops`,hint:`How long each camera keeps full-resolution pixels so a late crop (snapshot, face, plate) is sharp instead of cut from the small detection frame.`,panels:[{addonId:va,sectionIds:[De]}]},{id:`runner-defaults`,title:`Runner defaults`,hint:`Values every node's detection runner and audio analyzer use. A node's own decode limits (Engine & decoder) take precedence.`,panels:[{addonId:ya,fieldScope:`cluster`},{addonId:ba,fieldScope:`cluster`}]},{id:`failover`,title:`Failover`,hint:`What happens to cameras when a node disconnects and comes back.`,panels:[{addonId:va,sectionIds:[`failover`]}]}],Ta={"cluster-step-models":Sa};function Ea(e){return e===`clip-embedding`?Ca:Sa}r();var Da=2500,Oa={faces:ne,"semantic-search":E,"detail-crop":ge,"native-lease":_e,"runner-defaults":g,failover:R};function ka(e){f(()=>{if(e===null)return;let t=Ta[e]??e,n=`[data-cluster-settings-card="${CSS.escape(t)}"]`,r=()=>{let e=document.querySelector(n);return e===null?!1:(e.scrollIntoView({block:`start`,behavior:`smooth`}),e.classList.add(`ring-2`,`ring-primary/60`),setTimeout(()=>e.classList.remove(`ring-2`,`ring-primary/60`),Da),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function Aa({section:e}){return d(`div`,{"data-cluster-settings-card":e.id,className:`rounded-lg`,children:d(U,{headingId:`cluster-settings-${e.id}`,title:e.title,...Oa[e.id]===void 0?{}:{icon:Oa[e.id]},children:i(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:B,children:e.hint}),e.panels.map(e=>d(gn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:[`cluster`,`load`],emptyMessage:`Not available — the addon that owns these settings did not answer.`,...e.capability===void 0?{}:{capability:e.capability},...e.sectionIds===void 0?{}:{sectionIds:e.sectionIds},...e.fieldKeys===void 0?{}:{fieldKeys:e.fieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function ja({refreshToken:e}){let[t]=mn();return ka(t.get(No)),d(`div`,{className:`space-y-3 sm:space-y-4`,children:wa.map(e=>d(Aa,{section:e},e.id))})}var Ma=`pipeline-orchestrator`,Na=200;function Pa(){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`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.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(ft,{addonId:Ma,limit:Na,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}var Fa=[{id:`assignments`,label:`Assignments`},{id:`load-balancing`,label:`Load balancing`},{id:`auto-tune`,label:`Auto tune`},{id:`roles-nodes`,label:`Roles`},{id:`settings`,label:`Settings`},{id:`logs`,label:`Logs`}];function Ia(e){return Fa.some(t=>t.id===e)}function La({refreshToken:e}){let[t,n]=mn(),r=t.get(Mo),a=Ia(r)?r:`assignments`,o=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(Mo,e),n.delete(No),n},{replace:!0})};return i(`div`,{className:`flex flex-col h-full`,children:[i(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Fa.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[a===`assignments`&&d(li,{}),a===`load-balancing`&&d(la,{refreshToken:e,onOpenAutoTune:()=>o(`auto-tune`)}),a===`auto-tune`&&d(Oi,{}),a===`roles-nodes`&&d(ha,{}),a===`settings`&&d(ja,{refreshToken:e}),a===`logs`&&d(Pa,{})]})]})}var Ra=`armed:`;function za(e){return e.assignment.reasons.detection?.startsWith(Ra)===!0}function Ba(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!za(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Va(e){let t=[],n=[],{assignment:r,detection:i,broker:a}=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)`}),r.detectionNodeId===null&&i===null&&!za(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let o=e.degraded??[];if(o.length>0){let e=[...new Set(o.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)`})}n.push(...Wa(e.cameraSensors));for(let e of a?.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 Ha(e){return e.state===`unreadable`&&Oe.state===`unreadable`&&e.reason===Oe.reason}function Ua(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is missing`};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) is ${e.reason}`};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) cannot drive motion: ${e.reason}`};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is unreadable: ${e.reason}`}}}function Wa(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return Ha(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:`Camera sensors unreadable: ${e.reason}`}];let t=e.sensors.flatMap(e=>{let t=Ua(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[Ga(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:`Confirm / Replace cannot suppress this camera's own motion until its provider is updated`},...n]}function Ga(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?`Camera sensors are attached but never fire: add "Camera sensors" (onboard) to this camera's motion sources`:`Camera sensors are attached but never fire: this camera has no active detection`}}function Ka(e){return e===void 0?`status unavailable from this node`:e.state===`not-configured`?`none attached`:e.state===`unreadable`?`unknown — ${e.reason}`:e.sensors.map(Ja).join(`, `)}function qa(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function Ja(e){return`${Ya(e)}${qa(e)}`}function Ya(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return`${e.name} (#${e.deviceId}) — unsupported`;case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function Xa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Za(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Qa(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function $a(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var eo={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 to(e){if(!Xa(e)||!Array.isArray(e.sections))return eo;let t=Ee(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)$a(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Za(n(`detectionFps`)),motionSources:Qa(n(`motionSources`)),motionFps:Za(n(`motionFps`)),motionCooldownMs:Za(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 no(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(...no(r.children,t+1));return n}function X({title:e,children:t}){return i(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return i(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(ro,{})]})}function ro(){return d(`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 io={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 d(`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 ${io[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function ao({icon:e,label:t,nodeId:n,pinned:r,reason:a,overridden:s}){return i(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):i(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?i(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(_,{className:`h-2.5 w-2.5`}),` manual`]}):i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function oo({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return i(X,{title:`Where it runs`,children:[d(ao,{icon:g,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(ao,{icon:y,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(ao,{icon:D,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(ao,{icon:M,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:i(`select`,{value:o,disabled:r,"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:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>i(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function so(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function co(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function lo(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function uo({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:a,cameraSensors:s}){let c=co(t,n.detectionStreamProfile),l=co(t,n.motionStreamProfile),u=n.motionSources.includes(`analyzer`);return i(X,{title:`Streams & motion`,children:[i(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:lo(n.detectionFps)}),i(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map(ye).join(` + `):`none`,r===!1&&` · inactive`]}),d(Z,{label:`Camera sensors`,children:Ka(s)}),u&&i(o,{children:[i(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),i(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[lo(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>i(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,so(e)]},e.camStreamId))})]})}function fo({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return i(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:i(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&i(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:i(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var po={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function mo({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return i(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:r,children:n??`—`}),d($,{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,u=tt(a),f=a===`active`&&o===0;return i(X,{title:`Detection runtime`,children:[i(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[i(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(Ue,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:r,children:n??`—`}),i(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),i(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&i(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&i(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),i(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),i(Z,{label:`Provisioning`,children:[d(Q,{tone:po[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&i(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function ho({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):i(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return i(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),i(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),i(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps===null?`—`:e.inFps.toFixed(0),`fps`]}),i(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),i(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[i(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),i(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function go({decoder:e}){return e===null?d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})}):d(X,{title:`Decoder`,children:d(Z,{label:`Node`,children:e.nodeId})})}r();var _o=`pipeline-orchestrator`,vo={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},yo={healthy:`Healthy`,idle:`Idle`,error:`Error`};function bo({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>i(`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:[d(b,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function xo({deviceId:e,name:t,online:n,status:r,live:o,onlineNodes:s}){let l=c(),{data:u}=Jt({addonId:_o,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=Qe({deviceId:e},{staleTime:3e4}),p=a(()=>to(u),[u]),m=a(()=>f===void 0?void 0:no(f.steps),[f]),h=a(()=>r===void 0?[]:Va(r),[r]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=Re({onSuccess:g}),v=Bt({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=r===void 0?`idle`:Ba(r),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return i(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[i(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:vo[b]}`,title:x?`Error`:yo[b],"aria-label":x?`Error`:yo[b],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),i(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),r?.recording!=null&&(r.recording.active?i(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&i(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),h.length>0&&d(bo,{problems:h}),r===void 0?d(`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.`}):i(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(oo,{assignment:r.assignment,settings:p,onlineNodes:s,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),d(mo,{detection:r.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(fo,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:r.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(uo,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:p,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null,cameraSensors:r.cameraSensors}),d(ho,{broker:r.broker}),d(go,{decoder:r.decoder})]})]})}r();var So=5e3,Co=1e4,wo=5e3;function To(e){let t=c(),{data:n,isLoading:r}=pn(),{data:i,isLoading:o}=Ie({},{refetchInterval:So}),{nodes:s}=K();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);Pt(Me.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(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})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-Co,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},wo);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(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:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}r();function Eo({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:o}=To(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:Va(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=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:i(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[i(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[i(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),i(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),i(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(xo,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}var Do=e({CLUSTER_NODE_ID:()=>Oo,PipelinePage:()=>jo});r();var Oo=`__cluster__`;function ko(e){return e===`cameras`?`cameras`:`nodes`}function Ao({viewMode:e,onNodes:t,onCameras:n}){return i(`div`,{className:`flex items-center gap-1 rounded-lg border border-border bg-surface p-0.5`,role:`tablist`,"aria-label":`Pipeline view`,children:[d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`nodes`,onClick:t,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`cameras`,onClick:n,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]})}function jo(){let[e,t]=mn(),n=ko(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Oo},{replace:!0})},[n,e,t]),i(Ke,{icon:le,title:`Pipeline`,subtitle:`Detection placement, load and per-camera runtime across the cluster.`,actions:i(V,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s(e=>e+1),title:`Refresh`,children:[d(se,{className:`h-3.5 w-3.5`}),`Refresh`]}),nav:d(Ao,{viewMode:n,onNodes:()=>{t({view:`nodes`,node:r},{replace:!0})},onCameras:()=>{t({view:`cameras`},{replace:!0})}}),className:`flex h-full min-h-0 flex-col overflow-hidden`,children:[n===`nodes`&&i(V,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>l(e=>!e),"aria-expanded":c,className:`flex w-full shrink-0 justify-between border-b border-border md:hidden`,children:[i(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(oe,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden md:flex-row`,children:n===`nodes`?i(o,{children:[d(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b border-border md:border-b-0 md:border-r`,`max-h-[60vh] overflow-y-auto md:max-h-none`].join(` `),children:d(Bn,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:r===`__cluster__`?d(La,{refreshToken:a}):d(ci,{nodeId:r,refreshToken:a})})]}):d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:d(Eo,{refreshToken:a})})})]})}var Mo=`ctab`,No=`section`;function Po(e,t){let n=new URLSearchParams({view:`nodes`,node:Oo,[Mo]:e});return t!==void 0&&n.set(No,t),`/system/pipeline?${n.toString()}`}function Fo(e){return Po(`settings`,Ea(e))}function Io(){return Po(`load-balancing`)}var Lo=`pipeline-orchestrator`;function Ro(e){return Ne.find(t=>t.stepId===e)??null}function zo({step:e,engineFormat:t,runnableModelIds:n}){let{data:r}=Wt({addonId:Lo}),a=ke(r??null)[e.stepId]??e.defaultModelId,o=e.options.find(e=>e.id===a)?.label??a,s=n.length>0&&!n.includes(a);return i(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:o}),d(`span`,{title:`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`}),d(hn,{to:Fo(e.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Change in Cluster → Settings ›`})]}),i(`p`,{className:B,children:[`One model for every node and camera: `,e.indexName,` only matches vectors from the model that made them.`]}),s&&i(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:[`This accelerator's engine (`,t,`) ships no build of `,d(`b`,{children:a}),`. It refuses this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`.`]})]})}export{Ar as _,Jr as a,Nr as c,zr as d,Vr as f,jr as g,Br as h,Yr as i,Gr as l,Rr as m,Ro as n,Lr as o,Wr as p,Do as r,Hr as s,zo as t,Ur as u,Dr as v,jn as y};