@camstack/addon-admin-ui 1.2.701 → 1.2.702

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 (105) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/assets/{AccessSection-CmGUVN2c.js → AccessSection-CNgvvC6Q.js} +1 -1
  3. package/dist/assets/Addons-Dtx3xcZ2.js +5 -0
  4. package/dist/assets/{AdminPage-Dvziohv2.js → AdminPage-BkxgjFWW.js} +1 -1
  5. package/dist/assets/{AdminSectionedPage-3F0XiS4h.js → AdminSectionedPage-bGVBepbw.js} +1 -1
  6. package/dist/assets/AiProfiles-BLj-ic5N.js +3 -0
  7. package/dist/assets/Archive-y1aPYCx8.js +1 -0
  8. package/dist/assets/{BootstrapSettingsForm-D5_YCsD2.js → BootstrapSettingsForm-jBRoUiPn.js} +1 -1
  9. package/dist/assets/{Build-DgzW58SZ.js → Build-BoiB-nPA.js} +4 -4
  10. package/dist/assets/{Calendars-BzFF94EV.js → Calendars-BBTnm6OG.js} +1 -1
  11. package/dist/assets/Cluster-DN0Cwciw.js +1 -0
  12. package/dist/assets/{CompositionBlockEditor-BUQTd-UR.js → CompositionBlockEditor-BloGManS.js} +2 -2
  13. package/dist/assets/{CompositionEditorPage-BTvOMFXc.js → CompositionEditorPage-C5pNxu2M.js} +1 -1
  14. package/dist/assets/Data-LT-PQ05n.js +2 -0
  15. package/dist/assets/{DeviceDetail-C09lWDie.js → DeviceDetail-DAvmtNN2.js} +1 -1
  16. package/dist/assets/{Devices-DsS5GkXt.js → Devices-BJRvDHiT.js} +1 -1
  17. package/dist/assets/{EmbedDevicePage-BkW36-q-.js → EmbedDevicePage-CyKS-rmB.js} +1 -1
  18. package/dist/assets/{EmbedPlayerPage-BD43fNk-.js → EmbedPlayerPage-BsxSpEcY.js} +1 -1
  19. package/dist/assets/History-BPF9alct.js +1 -0
  20. package/dist/assets/{Identity-DXfvzQIG.js → Identity-dLFVHYZR.js} +1 -1
  21. package/dist/assets/InstancesTable-LVQWfz07.js +1 -0
  22. package/dist/assets/IntegrationDetail-C_vN9X7q.js +1 -0
  23. package/dist/assets/{Integrations-BOc2LGfc.js → Integrations-BUOpFqfh.js} +1 -1
  24. package/dist/assets/{Integrations-BgRTT3i6.js → Integrations-Dpb2V2yu.js} +1 -1
  25. package/dist/assets/Library-D4-BDy54.js +1 -0
  26. package/dist/assets/Locations-DGZ_lrp3.js +3 -0
  27. package/dist/assets/Logs-CUV00qxb.js +1 -0
  28. package/dist/assets/{MaskShapeCanvas-BwjxoZHj.js → MaskShapeCanvas-D57fCIme.js} +1 -1
  29. package/dist/assets/{MotionZonesSettings-CgruOSjK.js → MotionZonesSettings-w1kFM_O4.js} +1 -1
  30. package/dist/assets/MyAccess-D87gqxHt.js +2 -0
  31. package/dist/assets/{Network-Dxm48n1Y.js → Network-L7e5c9RP.js} +1 -1
  32. package/dist/assets/{NewExportModal-DQLl3C3Q.js → NewExportModal-CHwUJ26P.js} +1 -1
  33. package/dist/assets/{NodeAddonsSettingsPanel-H8ruMWFP.js → NodeAddonsSettingsPanel-Kqe8X8RH.js} +1 -1
  34. package/dist/assets/{Notifications-B44Sd1jg.js → Notifications-CucZNxjj.js} +1 -1
  35. package/dist/assets/{PanelContent-DnT2f8Cc.js → PanelContent-PhbemYUY.js} +2 -2
  36. package/dist/assets/Pipeline-9O3YfaWk.js +1 -0
  37. package/dist/assets/{PrivacyMaskSettings-B6WFh3P4.js → PrivacyMaskSettings-BS29zGkX.js} +1 -1
  38. package/dist/assets/{SceneMonitorEditor-M-wzPHRE.js → SceneMonitorEditor-CosxkmPM.js} +1 -1
  39. package/dist/assets/{SessionsList-D0tv-91a.js → SessionsList-OHo3GJ72.js} +2 -2
  40. package/dist/assets/{Showroom-BlMk46Us.js → Showroom-0iJ0CCe5.js} +1 -1
  41. package/dist/assets/{StorageLocationsTable-13scCxNp.js → StorageLocationsTable-DqTWO4k1.js} +1 -1
  42. package/dist/assets/System-DZXA2QSs.js +2 -0
  43. package/dist/assets/TemplateEditorDialog-8D78AUfO.js +1 -0
  44. package/dist/assets/{Terminal-BwEVkhLM.js → Terminal-Cvw2rPrb.js} +3 -3
  45. package/dist/assets/{TrainingProviders-CPc4S7AF.js → TrainingProviders-DcThiLnE.js} +1 -1
  46. package/dist/assets/{Viewer-B4D9Uq2-.js → Viewer-BUfnqb0c.js} +1 -1
  47. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D6FI5YpS.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CNNET8uz.js} +1 -1
  48. package/dist/assets/{action-draft-BIhSMudC.js → action-draft-BTVZLATm.js} +1 -1
  49. package/dist/assets/{ai-page.helpers-BfJpXMnt.js → ai-page.helpers-qxf7BP-v.js} +1 -1
  50. package/dist/assets/{assignment-candidates-BfJhT0tz.js → assignment-candidates-d-6NU8po.js} +1 -1
  51. package/dist/assets/{authed-media-ChKbSmi3.js → authed-media-Bqh0pB9D.js} +1 -1
  52. package/dist/assets/{board-model-CyseSL_y.js → board-model-CPA2IZpg.js} +1 -1
  53. package/dist/assets/{camera-block-model-BKFq-3HR.js → camera-block-model-CJ0e2m0o.js} +1 -1
  54. package/dist/assets/client-Cng2SeYA.js +1122 -0
  55. package/dist/assets/{command-vocab-CeQ0ypHW.js → command-vocab-BzBhzE7i.js} +1 -1
  56. package/dist/assets/{device-detail-CFJoqbEo.js → device-detail-Cg2Zt8FL.js} +1 -1
  57. package/dist/assets/{device-integration-icon-BwgC8WB_.js → device-integration-icon-VMxiVsqd.js} +1 -1
  58. package/dist/assets/device-picker-model-B-FI9413.js +1 -0
  59. package/dist/assets/dist-CxrdebAP.js +1122 -0
  60. package/dist/assets/{dist-Bgy0yfXq.js → dist-D7Gew3v3.js} +1 -1
  61. package/dist/assets/{format-D9ROMB42.js → format-BopmTOzZ.js} +1 -1
  62. package/dist/assets/{hostInit-DO8vSCT5.js → hostInit-DuH1KOuD.js} +1 -1
  63. package/dist/assets/i18n--GTAj4mB.js +1 -0
  64. package/dist/assets/{icons-DrHUdyj-.js → icons-bi-mcO5N.js} +1 -1
  65. package/dist/assets/index-DbXFHmBJ.js +6 -0
  66. package/dist/assets/{linked-devices-model-bymuMeaF.js → linked-devices-model-Bnz1douR.js} +1 -1
  67. package/dist/assets/{mf-entry-bootstrap-0-dc995488.js → mf-entry-bootstrap-0-ddbe056c.js} +2 -2
  68. package/dist/assets/mount-B-FI9413.js +1 -0
  69. package/dist/assets/{notification-rule-status-CyADOgAm.js → notification-rule-status-ai5zWyzt.js} +1 -1
  70. package/dist/assets/{player-overlays-D546iNTv.js → player-overlays-fpbPSPqT.js} +1 -1
  71. package/dist/assets/remoteEntry-g0NfB_lk.js +1 -0
  72. package/dist/assets/{src-C9_yKHH3.js → src-eL0OacoB.js} +18 -18
  73. package/dist/assets/{sso-popup--gCyd56l.js → sso-popup-Za4GwQBP.js} +1 -1
  74. package/dist/assets/{step-inspector-model-B_OOCp6Z.js → step-inspector-model-BAgxIyNV.js} +1 -1
  75. package/dist/assets/{use-scenes-feed-D9kXSeA2.js → use-scenes-feed-BTNdL7JV.js} +1 -1
  76. package/dist/assets/{useAdminDeviceRemoval-CF8lG06z.js → useAdminDeviceRemoval-COlTnaF7.js} +1 -1
  77. package/dist/assets/useEventInvalidation-B-FI9413.js +1 -0
  78. package/dist/assets/{useNodeUrlSelection-ju70FIba.js → useNodeUrlSelection-DhtJZEtx.js} +1 -1
  79. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BSgZU_Z3.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-R-1W8c6C.js} +2 -2
  80. package/dist/index.html +8 -8
  81. package/dist/server/addon.js +205 -19
  82. package/package.json +2 -2
  83. package/dist/assets/Addons-CgCQDQsS.js +0 -5
  84. package/dist/assets/AiProfiles-BAdfHll3.js +0 -3
  85. package/dist/assets/Archive-tBDnGn2J.js +0 -1
  86. package/dist/assets/Cluster-Chna0Sjs.js +0 -1
  87. package/dist/assets/Data-Ge58RjOD.js +0 -2
  88. package/dist/assets/History-D-ERNFKB.js +0 -1
  89. package/dist/assets/InstancesTable-BzPfQPuA.js +0 -1
  90. package/dist/assets/IntegrationDetail-CEcOLviw.js +0 -1
  91. package/dist/assets/Library-DUI94NI6.js +0 -1
  92. package/dist/assets/Locations-DkcchiHh.js +0 -3
  93. package/dist/assets/Logs-DS49QhkO.js +0 -1
  94. package/dist/assets/MyAccess-TXMLevZM.js +0 -2
  95. package/dist/assets/Pipeline-XpW32I39.js +0 -1
  96. package/dist/assets/System-CkjsA5xm.js +0 -2
  97. package/dist/assets/TemplateEditorDialog-fJjZNx16.js +0 -1
  98. package/dist/assets/client-DQzHwaNb.js +0 -1122
  99. package/dist/assets/device-picker-model-CVOfqhXA.js +0 -1
  100. package/dist/assets/dist-B6zcGpdS.js +0 -1122
  101. package/dist/assets/i18n-HSlX-YO0.js +0 -1
  102. package/dist/assets/index-BN2PojUq.js +0 -6
  103. package/dist/assets/mount-CVOfqhXA.js +0 -1
  104. package/dist/assets/remoteEntry-CeXhbAxp.js +0 -1
  105. package/dist/assets/useEventInvalidation-CVOfqhXA.js +0 -1
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,i as c,o as l,p as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$a as f,A as p,D as m,Dr as h,Hn as g,Ir as _,Lr as v,N as y,O as b,Pn as x,Qa as S,Rn as C,Rt as w,T,Tt as E,Ur as ee,V as D,Xn as O,Yn as k,Za as A,Zt as j,aa as te,b as M,ci as ne,cr as N,ct as P,eo as F,ft as I,hi as L,j as R,ji as z,jt as B,k as V,oo as H,tn as U,v as re,wt as ie,y as ae,yn as oe,yt as se,z as W,zr as ce}from"./player-overlays-D546iNTv.js";import{Gn as le,Ji as ue,Ki as de,Xi as fe,Yi as pe,Zi as me,_ as he,_i as ge,bi as _e,fi as ve,g as ye,gi as be,h as xe,hi as Se,ll as Ce,mi as we,vi as Te,y as Ee,yi as De}from"./client-DQzHwaNb.js";import{t as Oe}from"./chevron-down-CBb-F8DT.js";import{d as ke,u as Ae}from"./terminal-DZ5OZpgC.js";import{a as je,i as Me,n as Ne,r as Pe,t as Fe}from"./usb-P4R9CjYI.js";import{t as Ie}from"./crop-B-t0rzRY.js";import{t as Le}from"./layers-BH9u1mrE.js";import{n as Re}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DzoL8nR8.js";import{$a as ze,$u as Be,Ai as Ve,An as He,Ap as Ue,Au as We,B as Ge,Br as Ke,Bu as qe,Cu as Je,Da as Ye,Di as Xe,Du as Ze,Eu as Qe,Fc as $e,Fu as et,Gi as tt,Gr as nt,H as rt,Hu as it,Ir as G,Ji as at,Jp as ot,Ju as st,K as ct,Ki as lt,Kp as K,Ku as ut,Mn as dt,Nc as ft,Ni as pt,Op as mt,Ou as ht,Pc as gt,Qa as _t,Qu as vt,Ru as yt,Sp as bt,Su as xt,Tu as St,U as Ct,Ui as wt,Ur as Tt,Uu as Et,V as Dt,Vi as Ot,W as kt,Wi as At,Wr as jt,Wu as Mt,Xp as Nt,Xu as Pt,Yi as Ft,Yp as It,Zp as Lt,Zs as Rt,Zu as zt,_i as Bt,a as Vt,ai as Ht,bi as Ut,bu as Wt,cd as Gt,ci as Kt,dd as qt,ed as Jt,et as Yt,fd as Xt,ft as Zt,gd as Qt,ju as $t,ka as q,ki as en,kr as tn,ku as nn,la as rn,ld as an,md as on,mr as sn,pd as cn,pi as ln,pp as J,pt as un,qi as dn,qp as fn,qu as pn,si as mn,st as hn,to as gn,ud as _n,vi as vn,xi as yn,xp as bn,xr as xn,xu as Sn,yi as Cn,zr as wn}from"./src-C9_yKHH3.js";import{t as Y}from"./i18n-HSlX-YO0.js";import{t as X}from"./useTranslation-BJr-n0es.js";import{H as Tn,vi as En,wi as Dn,yi as On}from"./index-BN2PojUq.js";import{t as kn}from"./NodeAddonsSettingsPanel-H8ruMWFP.js";import"./useEventInvalidation-CVOfqhXA.js";import{_ as An,a as jn,b as Mn,c as Nn,d as Pn,f as Fn,g as In,h as Ln,i as Rn,l as zn,m as Bn,n as Vn,p as Hn,r as Un,s as Wn,u as Gn,v as Kn,y as qn}from"./step-inspector-model-B_OOCp6Z.js";import{a as Jn,c as Yn,d as Xn,f as Zn,g as Qn,i as $n,l as er,m as tr,n as nr,o as rr,r as ir,s as ar,t as or,u as sr,v as cr,y as lr}from"./board-model-CyseSL_y.js";s();function ur(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 dr(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function fr(e){return e!==!1}function pr(e){return{pipeline:fr(dr(e,`detect`)),audio:fr(dr(e,`audio`)),ingest:fr(dr(e,`ingest`))}}function mr(e,t){let n=e?.find(e=>e.nodeId===t);return pr(n?.settings)}function hr({selectedNodeId:t,onSelect:n,refreshToken:r}){let a=H(),{t:o}=X(),{nodes:s}=fn(),{data:c}=it(void 0),{data:l}=ut(void 0),u=new Map;for(let e of c??[])u.set(e.agentNodeId,(u.get(e.agentNodeId)??0)+1);let f=s??[],p=f.filter(e=>e.isOnline).length,m=f.filter(e=>!e.isOnline).length;return e(`div`,{className:`flex flex-col h-full`,children:[e(J,{variant:`unstyled`,type:`button`,onClick:()=>n(ss),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${t===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[i(Ae,{className:`h-4 w-4 flex-shrink-0`}),e(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`text-xs font-semibold truncate`,children:o(`pipeline.nodeList.cluster`,`Cluster`)}),i(`div`,{className:`text-[10px] text-foreground-subtle`,children:o(`pipeline.nodeList.assignmentsLoadBalancingRoles`,`Assignments, load balancing, roles`)})]})]}),i(`div`,{className:`flex-1 overflow-y-auto`,children:f.map(r=>{let s=t===r.id,c=u.get(r.id)??0,f=r.isHub?C:z,p=mr(l,r.id),m=r.isOnline?null:dt(ur(r.lastSeen),a);return e(J,{variant:`unstyled`,type:`button`,onClick:()=>n(r.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${s?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${r.isOnline?``:` opacity-60`}`,children:[i(f,{className:`h-4 w-4 flex-shrink-0`}),e(`div`,{className:`min-w-0 flex-1`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&i(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:o(`common.hubWord`)}),!r.isOnline&&i(`span`,{className:`h-1.5 w-1.5 rounded-full bg-danger flex-shrink-0`}),r.isOnline&&i(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),e(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[i(`span`,{children:o(`common.coresCount`,{count:r.cpuCores})}),i(`span`,{children:`•`}),e(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),c>0&&e(d,{children:[i(`span`,{children:`•`}),e(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[i(w,{className:`h-2.5 w-2.5`}),c]})]}),!r.isOnline&&e(d,{children:[i(`span`,{children:`•`}),e(`span`,{className:`text-danger`,children:[o(`common.offline`),m===null?``:` · ${m}`]})]})]}),e(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[i(q,{variant:p.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:p.pipeline?o(`pipeline.nodeList.pipelineEnabled`,`Pipeline: enabled`):o(`pipeline.nodeList.pipelineNotEnabledAgentCapability`,`Pipeline: not enabled (agent capability)`),children:o(`pipeline.nodeList.pipe`,`Pipe`)}),i(q,{variant:p.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:p.audio?o(`pipeline.nodeList.audioEnabled`,`Audio: enabled`):o(`pipeline.nodeList.audioNotEnabledAgentCapability`,`Audio: not enabled (agent capability)`),children:o(`pipeline.nodeList.aud`,`Aud`)})]})]})]},r.id)})}),e(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[i(`span`,{children:o(`common.onlineCount`,{count:p})}),m>0&&i(`span`,{className:`text-danger`,children:o(`common.offlineCount`,{count:m})})]})]})}function gr({nodeId:t,refreshToken:n}){let{t:r}=X(),{nodes:a}=fn(),o=a?.find(e=>e.id===t),s=ot(`pipeline.runner-load-snapshot`,e=>e.nodeId===t)?.load??null;return o?e(`div`,{className:`px-6 py-4 border-b border-border`,children:[e(`div`,{className:`flex items-center gap-2 mb-1`,children:[i(`h2`,{className:`text-base font-semibold text-foreground`,children:o.name}),o.isOnline?i(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:r(`common.online`)}):i(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-danger/10 text-danger`,children:r(`common.offline`)}),o.isHub&&i(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:r(`common.hubWord`)})]}),e(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[i(`span`,{children:o.cpuModel??`CPU`}),i(`span`,{children:`•`}),i(`span`,{children:r(`common.coresCount`,{count:o.cpuCores})}),i(`span`,{children:`•`}),e(`span`,{children:[Math.round(o.memoryMB/1024),` GB`]}),s&&e(d,{children:[i(`span`,{children:`•`}),i(`span`,{children:r(`pipeline.nodeDetailHeader.cameras`,{attached:s.attachedCameras,active:s.activeCameras})}),i(`span`,{children:`•`}),i(`span`,{children:r(`pipeline.nodeDetailHeader.avgInference`,{ms:s.avgInferenceTimeMs.toFixed(0)})}),i(`span`,{children:`•`}),i(`span`,{children:r(`pipeline.nodeDetailHeader.queue`,{depth:s.queueDepthTotal})}),s.hardware.hasGpu&&e(d,{children:[i(`span`,{children:`•`}),i(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):i(`div`,{className:`px-6 py-4 border-b border-border`,children:e(`div`,{className:`text-xs text-foreground-subtle`,children:[r(`pipeline.nodeDetailHeader.nodeNotFound`,`Node not found:`),` `,t]})})}var _r=[`assignments`,`tree`,`engines`,`logs`];function vr({refreshToken:t,nodeId:r}){let{t:a}=X(),[s,c]=o(new Map),{nodes:l}=K();Nt(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&c(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:u}=$t(void 0),d=n(()=>{let e=new Map;for(let t of u??[])e.set(t.nodeId,t.deviceCount);return e},[u]),f=n(()=>{let e=new Map,t=Date.now()-3e4;for(let n of s.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[s]),p=n(()=>{let e=new Map;for(let t of l)e.set(t.id,t.shortName);return e},[l]),m=n(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of f.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:l.length,onlineAgents:l.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[f,l]);if(r){let t=f.get(r);return e(`div`,{className:`@container/liveload`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:a(`pipeline.liveLoadPanel.liveLoad`,`Live load`)}),e(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[i(Z,{label:`FPS`,value:t?t.totalFps.toFixed(1):`—`}),i(Z,{label:a(`pipeline.liveLoadPanel.activeAttached`,`Active / Attached`),value:t?`${t.activeCameras}/${t.attachedCameras}`:`—`}),i(Z,{label:a(`pipeline.liveLoadPanel.avgInferMs`,`Avg infer ms`),value:t&&t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),i(Z,{label:a(`pipeline.liveLoadPanel.queue`,`Queue`),value:t?String(t.queueDepth):`—`}),i(Z,{label:a(`pipeline.liveLoadPanel.audio`,`Audio`),value:String(d.get(r)??`—`)})]})]})}let h=[...f.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return e(`div`,{className:`@container/liveload`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:a(`pipeline.liveLoadPanel.liveLoad`,`Live load`)}),e(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[i(Z,{label:a(`pipeline.liveLoadPanel.totalAgents`,`Total agents`),value:`${m.onlineAgents}/${m.totalAgents}`}),i(Z,{label:a(`pipeline.liveLoadPanel.activeAttached`,`Active / Attached`),value:`${m.activeCameras}/${m.attachedCameras}`}),i(Z,{label:a(`pipeline.liveLoadPanel.totalFps`,`Total FPS`),value:m.totalFps.toFixed(1)}),i(Z,{label:a(`pipeline.liveLoadPanel.avgInferenceMs`,`Avg inference ms`),value:m.avgInferenceTimeMs.toFixed(0)}),i(Z,{label:a(`pipeline.liveLoadPanel.queueDepth`,`Queue depth`),value:String(m.queueDepth)})]}),i(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:e(`table`,{className:`w-full text-xs min-w-[480px]`,children:[i(`thead`,{className:`bg-surface`,children:e(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[i(`th`,{className:`text-left px-3 py-2`,children:a(`pipeline.liveLoadPanel.agent`,`Agent`)}),i(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),i(`th`,{className:`text-right px-3 py-2`,children:a(`pipeline.liveLoadPanel.cameras`,`Cameras`)}),i(`th`,{className:`text-right px-3 py-2`,children:a(`pipeline.liveLoadPanel.inferenceMs`,`Inference ms`)}),i(`th`,{className:`text-right px-3 py-2`,children:a(`pipeline.liveLoadPanel.queue`,`Queue`)}),i(`th`,{className:`text-right px-3 py-2`,children:a(`pipeline.liveLoadPanel.audio`,`Audio`)})]})}),e(`tbody`,{children:[h.map(([t,n])=>e(`tr`,{className:`border-t border-border`,children:[i(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:p.get(t)??t}),i(`td`,{className:`px-3 py-2 text-right text-foreground`,children:n.totalFps.toFixed(1)}),i(`td`,{className:`px-3 py-2 text-right text-foreground`,children:n.attachedCameras}),i(`td`,{className:`px-3 py-2 text-right text-foreground`,children:n.attachedCameras>0?(n.totalInferenceWeighted/n.attachedCameras).toFixed(0):`—`}),i(`td`,{className:`px-3 py-2 text-right text-foreground`,children:n.queueDepth}),i(`td`,{className:`px-3 py-2 text-right text-foreground`,children:d.get(t)??`—`})]},t)),h.length===0&&i(`tr`,{children:i(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:a(`pipeline.liveLoadPanel.noCameraMetricsReceivedYet`,`No camera metrics received yet`)})})]})]})})]})}function Z({label:t,value:n}){return e(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[i(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:t}),i(`div`,{className:`text-lg font-semibold text-foreground`,children:n})]})}var yr={active:!1,pinned:!1,nodeId:null,reason:``};function br(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function xr(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??``}:yr,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:yr;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:yr,audio:o}}).toSorted(br)}function Sr(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function Cr(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:Sr(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:Sr(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:Sr(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function wr(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(br)}function Tr(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 Er(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??Y.t(`helpers.assignmentRows.cameraFallback`,{id:e})}function Dr(e,t,n){let r=[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])];return[{value:`auto`,label:Y.t(`helpers.assignmentRows.auto`)},...r.map(e=>({value:e,label:Y.t(`helpers.assignmentRows.pinTo`,{node:n(e)})}))]}function Or({roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o}){if(n.nodeId===null)return null;let s=n.nodeId,c=o===void 0?!1:n.active&&s===o;return i(Tt,{roleId:e,roleLabel:t,nodeName:r(s),colorId:nt(a,s),emphasized:c,pinned:n.pinned})}function kr({detection:t,decoder:n,audio:r,nameOf:a,colorByNodeId:o,emphasizeOnNodeId:s}){let c=(e,t,n)=>i(Or,{roleId:e,roleLabel:t,state:n,nameOf:a,colorByNodeId:o,emphasizeOnNodeId:s},e);return e(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[c(`detection`,`Detection`,t),c(`decode`,`Decode`,n),c(`audio`,`Audio`,r)]})}function Ar({snap:t}){let n=H(),{t:r}=X();if(t===void 0)return i(`div`,{className:`flex h-8 items-center text-[11px] text-foreground-subtle`,title:r(`assignments.assignmentStatusCell.noMetricsInTheLast`,`No metrics in the last 10 s — the camera has no session running`),children:r(`assignments.assignmentStatusCell.noLiveData`,`no live data`)});let{phase:a,actualFps:o,avgInferenceTimeMs:s,queueDepth:c,configuredFps:l,droppedFrames:u}=t.metrics,d=xn(a,n);return e(`div`,{className:`flex h-8 min-w-0 flex-col justify-center font-mono text-[10px] leading-tight tabular-nums`,children:[e(`span`,{className:`inline-flex min-w-0 items-center gap-1 ${d.textColor}`,children:[i(Yt,{phase:a,className:`h-2.5 w-2.5 shrink-0`}),i(`span`,{className:`truncate font-semibold uppercase tracking-wider`,children:d.label}),i(`span`,{className:`text-foreground`,children:o.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:r(`pipeline.assignmentStatusCell.configuredFps`,{fps:l.toFixed(0)})})]}),e(`span`,{className:`truncate text-foreground-subtle`,children:[i(`span`,{className:`text-foreground`,children:s.toFixed(0)}),` ms`,c>0&&e(`span`,{className:`ml-1 text-warning`,children:[`q`,c]}),i(`span`,{className:u>0?`ml-1 text-warning`:`ml-1`,children:r(`pipeline.assignmentStatusCell.drops`,{count:u})})]})]})}s();var jr=1e4,Mr=5e3;function Nr(e){let[t,n]=o(new Map);return Nt(`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)))}),a(()=>{if(t.size===0)return;let e=setInterval(()=>{n(e=>{let t=Date.now()-jr,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},Mr);return()=>clearInterval(e)},[t.size]),t}var Pr=3e5;function Fr({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:a}){let{t:o}=X();return i(I,{"aria-label":o(`assignments.placementControls.nodePin`,`Node pin`),title:o(`assignments.placementControls.autoLetsEachSessionPick`,`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:[...Dr(e,t,n)],onChange:e=>a(e.target.value)})}function Ir({deviceId:e,nodeId:t}){let{t:n}=X(),r=l(),{data:a}=Et({deviceId:e},{refetchOnMount:`always`}),{data:o}=qe({nodeId:t},{staleTime:Pr}),s=_n({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(a===void 0||o===void 0)return i(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:n(`assignments.placementControls.accelerator`,`accelerator: …`)});let c=o.devices??[],u=c.filter(e=>e.enabled),d=a?.deviceKey??`auto`,f=d!==`auto`&&!u.some(e=>e.key===d),p=c.find(e=>e.key===d),m=[{value:`auto`,label:n(`assignments.placementControls.anyAccelerator`,`Any accelerator`)},...f?[{value:d,label:n(`pipeline.placementControls.notEnabled`,{name:p?`${en(p)} (${d})`:d})}]:[],...u.map(e=>({value:e.key,label:`${en(e)} · ${e.format}`}))];return i(I,{"aria-label":n(`assignments.placementControls.inferenceDevicePin`,`Inference device pin`),title:n(`assignments.placementControls.pinDetectionToOneAccelerator`,`Pin detection to one accelerator of the node, or let each session pick.`),value:d,disabled:s.isPending,options:m,onChange:t=>s.mutate({deviceId:e,deviceKey:t.target.value})})}s();function Lr(e){let n=t(null);return e.nodeId!==null&&(n.current=e),n.current}function Rr({deviceId:t,state:n,...r}){let{t:a}=X(),o=Lr(n);return e(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[i(Fr,{state:n,...r}),o?.nodeId==null?i(I,{"aria-label":a(`assignments.clusterRowCells.inferenceDevicePinNoNode`,`Inference device pin (no node yet)`),title:a(`assignments.clusterRowCells.anAcceleratorIsPinnedOn`,`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:a(`assignments.clusterRowCells.anyAccelerator`,`Any accelerator`)}]}):i(Ir,{deviceId:t,nodeId:o.nodeId})]})}function zr({state:t,nameOf:n}){let{t:r}=X(),a=Lr(t);if(a?.nodeId==null)return i(`span`,{className:`text-[11px] text-foreground-subtle`,children:r(`assignments.clusterRowCells.noSessionYet`,`— no session yet`)});let o=t.active&&t.nodeId!==null,s=a.pinned?`pinned`:`auto · ${a.reason||`capacity`}`;return e(`div`,{"data-testid":`resolved-placement`,className:`flex w-40 min-w-0 flex-col leading-tight`,title:a.pinned?void 0:r(`assignments.clusterRowCells.anUnpinnedCameraIsPlaced`,`An unpinned camera is placed again at every session start, so this can change between sessions.`),children:[e(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[i(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${o?`bg-success`:`bg-foreground-subtle/40`}`}),i(`span`,{"data-testid":`resolved-placement-node`,className:`truncate font-medium ${o?`text-foreground`:`text-foreground-muted`}`,children:n(a.nodeId)})]}),i(`span`,{className:`truncate pl-3 text-[10px] ${a.pinned?`text-warning`:`text-foreground-subtle`}`,children:o?s:r(`assignments.clusterRowCells.idleLastSession`,`{{how}} · idle, last session`,{how:s})})]})}function Br({deviceId:t,deviceName:n}){let{t:r}=X(),[a,s]=o(!1);return e(d,{children:[i(bt,{icon:O,variant:`ghost`,size:`sm`,"aria-label":r(`assignments.clusterRowCells.streamBrokersOf`,`Stream brokers of {{deviceName}}`,{deviceName:n}),title:r(`assignments.clusterRowCells.streamBrokersClients`,`Stream brokers & clients`),onClick:()=>s(!0)}),i(wt,{open:a,onOpenChange:s,children:e(tt,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[i(at,{children:i(Ft,{children:r(`pipeline.clusterRowCells.brokersTitle`,{device:n})})}),i(At,{children:a&&i(Ot,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t,instanceId:`pipeline-row/${t}`,config:{variant:`compact`}})})]})})]})}function Vr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function Hr(e,t){return t.size===0?!0:t.has(e)}var Ur=[{value:`active`,get label(){return Y.t(`helpers.cameraActivity.active`)}},{value:`recently-active`,get label(){return Y.t(`helpers.cameraActivity.recentlyActive`)}},{value:`inactive`,get label(){return Y.t(`helpers.cameraActivity.inactive`)}}];s();var Wr=[`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 Kr(){let{t}=X(),r=l();Vt([`pipelineOrchestrator`,`getPipelineAssignments`],Wr),Vt([`pipelineOrchestrator`,`getAudioAssignments`],Wr),Vt([`pipelineOrchestrator`,`getCameraStatuses`],Wr);let{data:a}=Rt({isCamera:!0,projection:`slim`}),{data:s}=it(void 0),{data:c}=We(void 0),{data:u}=et({}),{data:d}=ut(void 0),{nodes:f}=K(),p=Nr(),m=n(()=>Tr(f),[f]),h=n(()=>jt(d),[d]),g=n(()=>f.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[f]),_=n(()=>Cr(xr((a??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),s??[],c??[]),u??[]),[a,s,c,u]),[v,y]=o(()=>new Set),b=n(()=>_.filter(e=>Hr(Vr({hasPipelineAssignment:e.pipeline.active,hasFreshMetrics:p.has(e.deviceId)}),v)),[_,p,v]),x=e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=()=>Gr(r),C=Qe({onSuccess:S}),w=on({onSuccess:S}),T=C.isPending||w.isPending,E=[{key:`camera`,header:t(`pipeline.cameraAssignmentsTable.camera`,`Camera`),width:`w-44`,sortValue:e=>e.deviceName,render:n=>e(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[i(On,{to:`/devices/${String(n.deviceId)}`,className:`min-w-0 truncate text-xs font-medium text-primary hover:underline`,title:n.deviceName,children:n.deviceName}),n.disabled&&i(q,{variant:`default`,children:t(`common.off`)})]})},{key:`placement`,header:t(`pipeline.cameraAssignmentsTable.placement`,`Placement`),width:`w-80`,notSortableReason:`A pair of controls — editing one would move the row under the cursor.`,render:e=>i(Rr,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:g,nameOf:m,pending:T,onChange:t=>t===`auto`?w.mutate({deviceId:e.deviceId}):C.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`roles`,header:t(`pipeline.cameraAssignmentsTable.rolesHere`,`Roles here`),notSortableReason:`A set of roles has no single order.`,render:e=>i(kr,{detection:e.detection,decoder:e.decoder,audio:e.audio,nameOf:m,colorByNodeId:h})},{key:`resolved`,header:t(`pipeline.cameraAssignmentsTable.runningOn`,`Running on`),width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:m(e.pipeline.nodeId),render:e=>i(zr,{state:e.pipeline,nameOf:m})},{key:`status`,header:t(`pipeline.cameraAssignmentsTable.status`,`Status`),width:`w-40`,sortValue:e=>p.get(e.deviceId)?.metrics.actualFps??null,render:e=>i(Ar,{snap:p.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>i(Br,{deviceId:e.deviceId,deviceName:e.deviceName})}],ee=a===void 0?`Loading cameras…`:_.length===0?`No cameras`:`No cameras match this activity filter.`;return e(`div`,{className:`flex flex-col gap-2`,children:[i(`nav`,{"aria-label":t(`pipeline.cameraAssignmentsTable.filterByCameraActivity`,`Filter by camera activity`),"data-testid":`assignments-activity-filter`,children:i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:Ur.map(e=>{let t=v.has(e.value);return i(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:F(ae,t?re:M),onClick:()=>x(e.value),children:e.label},e.value)})})}),i(wn,{columns:E,rows:b,rowKey:e=>e.deviceId,minWidthPx:920,maxBodyHeight:Ke,emptyMessage:ee})]})}s();function qr({nodeId:e}){let{t}=X(),r=l();Vt([`pipelineOrchestrator`,`getCameraStatuses`],Wr);let{data:a}=et({}),{data:o}=ut(void 0),{data:s}=Rt({isCamera:!0,projection:`slim`}),{nodes:c}=K(),u=Nr(),d=n(()=>Tr(c),[c]),f=n(()=>jt(o),[o]),p=n(()=>wr(e,a??[],Er((s??[]).map(e=>({id:e.id,name:e.name})))),[e,a,s]),m=c.filter(t=>t.isOnline&&t.id!==e),h=()=>Gr(r),g=Qe({onSuccess:h}),_=on({onSuccess:h}),v=St({onSuccess:h}),y=cn({onSuccess:h}),b=e=>[...e.detection.active?m.map(n=>({id:`detect-${n.id}`,label:t(`pipeline.nodeCameraAssignmentsTable.moveDetectionTo`,`Move detection to {{name}}`,{name:n.name}),onClick:()=>g.mutate({deviceId:e.deviceId,agentNodeId:n.id})})):[],...e.audio.active?m.map(n=>({id:`audio-${n.id}`,label:t(`pipeline.nodeCameraAssignmentsTable.moveAudioTo`,`Move audio to {{name}}`,{name:n.name}),onClick:()=>v.mutate({deviceId:e.deviceId,nodeId:n.id})})):[],{id:`unpin-detect`,label:t(`pipeline.nodeCameraAssignmentsTable.unpinDetection`,`Unpin detection`),hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>_.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:t(`pipeline.nodeCameraAssignmentsTable.unpinAudio`,`Unpin audio`),hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>y.mutate({deviceId:e.deviceId})}];return i(wn,{columns:[{key:`camera`,header:t(`pipeline.nodeCameraAssignmentsTable.camera`,`Camera`),width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(On,{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:t(`pipeline.nodeCameraAssignmentsTable.rolesHere`,`Roles here`),notSortableReason:`A set of roles has no single order.`,render:t=>i(kr,{detection:t.detection,decoder:t.decoder,audio:t.audio,nameOf:d,colorByNodeId:f,emphasizeOnNodeId:e})},{key:`status`,header:t(`pipeline.nodeCameraAssignmentsTable.status`,`Status`),width:`w-40`,sortValue:e=>u.get(e.deviceId)?.metrics.actualFps??null,render:e=>i(Ar,{snap:u.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>i(He,{items:b(e),title:t(`pipeline.nodeCameraAssignmentsTable.move`,`Move {{deviceName}}`,{deviceName:e.deviceName})})}],rows:p,rowKey:e=>e.deviceId,minWidthPx:560,maxBodyHeight:Ke,emptyMessage:a===void 0?t(`pipeline.nodeCameraAssignmentsTable.loadingCameras`,`Loading cameras…`):t(`pipeline.nodeCameraAssignmentsTable.noCameraRunsOnThis`,`No camera runs on this node right now`)})}function Jr({nodeId:t,refreshToken:n}){let{t:r}=X(),{nodes:a}=K(),o=a.find(e=>e.id===t)?.name??t;return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(vr,{refreshToken:n,nodeId:t}),e(`div`,{className:`space-y-2`,children:[e(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:r(`pipeline.nodeCamerasTab.camerasOn`,{node:o})}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:r(`pipeline.nodeCamerasTab.theRolesEachCameraRuns`,`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.`)})]}),i(qr,{nodeId:t})]})]})}s();function Yr(e,t){let n=Math.max(0,t-e),r=Math.floor(e/1e3),i=Math.floor(n/1e3);return Y.t(`pipeline.nodeEnginesTab.idleLeft`,{idle:r,left:i})}function Xr({nodeId:t,refreshToken:r}){let{t:a}=X(),o=l(),s=P(),c=Sn({onSettled:()=>{o.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:u}=xt({nodeId:t}),d=ot(`pipeline.engine-metrics-snapshot`,e=>e.nodeId===t)?.engines??u??null,f=d===null;Vt([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:p}=Qt({nodeId:t}),{values:m}=It(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,e=>e.nodeId===t),h=n(()=>m.filter(e=>e.metrics.phase===`active`).length,[m]),g=e=>{let n=p??[];if(n.length===0){c.mutate({nodeId:t,engine:e,force:!1});return}(async()=>{await s({title:a(`pipeline.nodeEnginesTab.killEngine`,`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:a(`pipeline.nodeEnginesTab.killEngine`,`Kill engine`),variant:`danger`})&&c.mutate({nodeId:t,engine:e,force:!0})})()};return e(`div`,{className:`space-y-6`,children:[e(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:a(`pipeline.nodeEnginesTab.inferenceEnginesOnThisNode`,`Inference engines on this node`)}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:a(`pipeline.nodeEnginesTab.summary`,{engines:(d??[]).length,cameras:(p??[]).length,active:h})})]}),i(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:e(`table`,{className:`w-full text-xs min-w-[640px]`,children:[i(`thead`,{className:`bg-surface`,children:e(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[i(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:a(`pipeline.nodeEnginesTab.kind`,`Kind`)}),i(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:a(`pipeline.nodeEnginesTab.runtimeBackendDevice`,`Runtime / Backend / Device`)}),i(`th`,{className:`text-left px-3 py-2`,children:a(`pipeline.nodeEnginesTab.models`,`Models`)}),i(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:a(`pipeline.nodeEnginesTab.poolPid`,`Pool PID`)}),i(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:a(`pipeline.nodeEnginesTab.autoKill`,`Auto-kill`)}),i(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:a(`pipeline.nodeEnginesTab.inUse`,`In use`)}),i(`th`,{className:`w-20`})]})}),e(`tbody`,{children:[f&&i(`tr`,{children:i(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:a(`common.loading`,`Loading…`)})}),!f&&(d??[]).map(t=>{let n=t.kind===`device-pool`;return e(`tr`,{className:`border-t border-border ${n?`bg-primary/[0.05]`:``}`,children:[i(`td`,{className:`px-3 py-2`,children:e(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[i(n?Le:z,{className:`h-3 w-3`}),a(n?`pipeline.nodeEnginesTab.pool`:`pipeline.nodeEnginesTab.runtime`)]})}),i(`td`,{className:`px-3 py-2`,children:e(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[i(ie,{className:`h-3 w-3`}),t.engine.runtime,`/`,t.engine.backend,t.engine.device?`/${t.engine.device}`:``,t.engine.format?` · ${t.engine.format}`:``]})}),i(`td`,{className:`px-3 py-2`,children:t.modelsLoaded.length===0?i(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):i(`div`,{className:`flex flex-wrap gap-1`,children:t.modelsLoaded.map(e=>i(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),i(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:t.poolPid??`—`}),i(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:t.idleMs!==null&&t.idleTtlMs!==null?i(`span`,{className:`text-foreground-subtle`,children:Yr(t.idleMs,t.idleTtlMs)}):i(`span`,{className:`text-foreground-subtle/50`,children:a(`common.never`)})}),i(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(p??[]).length}),i(`td`,{className:`px-3 py-2 text-right`,children:n?i(`span`,{className:`text-[11px] text-foreground-subtle`,children:a(`common.auto`)}):e(J,{variant:`ghost`,size:`sm`,disabled:c.isPending,onClick:()=>g(t.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[i(U,{className:`h-3.5 w-3.5`}),a(`pipeline.nodeEnginesTab.kill`,`Kill`)]})})]},t.engineKey)}),!f&&(d??[]).length===0&&i(`tr`,{children:i(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:a(`pipeline.nodeEnginesTab.noEnginesResidentTheFactory`,`No engines resident — the factory spins up on the first pipeline run.`)})})]})]})}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:i(En,{i18nKey:`pipeline.nodeEnginesTab.legend`,components:{strong:i(`strong`,{className:`text-foreground`})}})}),c.isError&&i(Ye,{message:a(`pipeline.nodeEnginesTab.killFailed`,{message:c.error instanceof Error?c.error.message:a(`common.unknownError`)})})]})}var Zr=`pipeline-runner`,Qr=200;function $r({nodeId:t}){let{t:n}=X();return e(`div`,{className:`flex flex-col gap-3`,children:[e(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:n(`pipeline.nodeLogsTab.runnerLogs`,`Runner logs`)}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:n(`pipeline.nodeLogsTab.description`,{node:t})})]}),i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(sn,{agentId:t,addonId:Zr,limit:Qr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1,showSourceSelect:!0})})]})}s();function ei({nodeId:t,title:r}){let a=H(),{t:o}=X(),{data:s}=Tn(),{data:c}=it(void 0),l=n(()=>{let e=new Map;for(let t of s??[])e.set(t.id,t.name);return e},[s]),u=n(()=>{if(!t)return null;let e=new Set;for(let n of c??[])n.agentNodeId===t&&e.add(n.deviceId);return e},[t,c]),d=Nr(t),f=n(()=>{let e=[];for(let t of d.values())u&&!u.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[d,u]);return f.length===0?e(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[r??o(`pipeline.cameraStatusStrip.cameras`,`Cameras`),`: no live snapshots yet`]}):e(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[e(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[i(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:r??o(`pipeline.cameraStatusStrip.cameras`,`Cameras`)}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:f.length})]}),i(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map(t=>{let n=l.get(t.deviceId)??`#${t.deviceId}`,r=xn(t.metrics.phase,a);return e(`div`,{title:o(`pipeline.cameraStatusStrip.fpsMsInferQ`,`{{name}} · {{label}} · {{value3}} fps · {{value4}}ms infer · q={{queueDepth}}`,{name:n,label:r.label,value3:t.metrics.actualFps.toFixed(1),value4:t.metrics.avgInferenceTimeMs.toFixed(0),queueDepth:t.metrics.queueDepth}),className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${r.badgeClass}`,children:[i(Yt,{phase:t.metrics.phase,className:`h-2.5 w-2.5`}),i(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:n}),i(`span`,{className:`font-mono tabular-nums`,children:t.metrics.actualFps.toFixed(1)}),i(`span`,{className:`opacity-60`,children:o(`common.fpsWord`)})]},t.deviceId)})})]})}function ti(e,t,n,r){let i=t===void 0?void 0:e.find(e=>e.key===t)?.steps?.[n]?.settings,a={...r?.[n],...i};return Object.keys(a).length>0?a:void 0}function ni(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 ri=`pipeline-analytics`,ii=`face-gallery`,ai=`pipeline-orchestrator`,oi=`pipeline-runner`,si=`audio-analyzer`,ci=`stream-broker`,li=`snapshot`,ui=`recorder`,di=`embedding-encoder`,fi=`recordingNodeId`;function pi(e){return[...we.filter(t=>t.stepId===e).map(e=>be(e.stepId)),...Se.filter(t=>t.stepId===e).map(e=>Te(e.stepId,e.key))]}var mi=`faces`,hi=`semantic-search`,gi=`load-balancer`,_i=`streaming`,vi=`recorder`,yi=`load`,bi=[{id:mi,get title(){return Y.t(`helpers.clusterSettingsSections.facesTitle`)},get hint(){return Y.t(`helpers.clusterSettingsSections.facesHint`)},panels:[{addonId:ai,fieldKeys:pi(`face-embedding`)},{addonId:ri,capability:ii},{addonId:ai,sectionIds:[ye]}]},{id:hi,get title(){return Y.t(`helpers.clusterSettingsSections.semanticTitle`)},get hint(){return Y.t(`helpers.clusterSettingsSections.semanticHint`)},panels:[{addonId:ai,fieldKeys:pi(`clip-embedding`)},{addonId:di,capability:`embedding-encoder`,fieldScope:`cluster`}]},{id:he,get title(){return Y.t(`helpers.clusterSettingsSections.cropTitle`)},get hint(){return Y.t(`helpers.clusterSettingsSections.cropHint`)},panels:[{addonId:ai,sectionIds:[he]}]},{id:xe,get title(){return Y.t(`helpers.clusterSettingsSections.nativeTitle`)},get hint(){return Y.t(`helpers.clusterSettingsSections.nativeHint`)},panels:[{addonId:ai,sectionIds:[xe]}]},{id:_i,get title(){return Y.t(`helpers.clusterSettingsSections.streamingTitle`)},get hint(){return Y.t(`helpers.clusterSettingsSections.streamingHint`)},panels:[{addonId:ci,capability:`stream-broker`,fieldScope:`cluster`},{addonId:li,capability:`snapshot`,fieldScope:`cluster`}]},{id:vi,get title(){return Y.t(`helpers.clusterSettingsSections.recorderTitle`)},get hint(){return Y.t(`helpers.clusterSettingsSections.recorderHint`)},panels:[{addonId:ui,capability:`recording`,fieldScope:`cluster`,omitFieldKeys:[fi]}]},{id:`runner-defaults`,get title(){return Y.t(`helpers.clusterSettingsSections.runnerTitle`)},get hint(){return Y.t(`helpers.clusterSettingsSections.runnerHint`)},panels:[{addonId:oi,fieldScope:`cluster`},{addonId:si,fieldScope:`cluster`}]},{id:gi,get title(){return Y.t(`helpers.clusterSettingsSections.loadTitle`)},get hint(){return Y.t(`helpers.clusterSettingsSections.loadHint`)},panels:[{addonId:ai,sectionIds:[yi]}]},{id:`failover`,get title(){return Y.t(`helpers.clusterSettingsSections.failoverTitle`)},get hint(){return Y.t(`helpers.clusterSettingsSections.failoverHint`)},panels:[{addonId:ai,sectionIds:[`failover`]}]}],xi={"cluster-step-models":mi};function Si(e){return e===`clip-embedding`?hi:mi}var Ci=`ctab`,wi=`section`;function Ti(e,t){let n=new URLSearchParams({view:`nodes`,node:ss,[Ci]:e});return t!==void 0&&n.set(wi,t),`/system/pipeline?${n.toString()}`}function Ei(e){return Ti(`settings`,Si(e))}function Di(){return Ti(`load-balancing`)}var Oi=`pipeline-orchestrator`;function ki(e){return we.find(t=>t.stepId===e)??null}function Ai({step:t,engineFormat:n,runnableModelIds:r}){let{t:a}=X(),{data:o}=ze({addonId:Oi,cap:Oi,scope:`cluster`}),s=De(o??null)[t.stepId]??t.defaultModelId,c=t.options.find(e=>e.id===s)?.label??s,l=r.length>0&&!r.includes(s);return e(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[e(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[i(`span`,{className:`font-medium text-foreground`,children:t.label}),i(`span`,{className:`font-mono text-foreground`,children:c}),i(`span`,{title:a(`pipeline.clusterStepModel.oneValueForTheWhole`,`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:a(`pipeline.clusterStepModel.clusterWide`)}),i(On,{to:Ei(t.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:a(`pipeline.clusterStepModel.changeInClusterSettings`,`Change in Cluster → Settings ›`)})]}),e(`p`,{className:W,children:[a(`pipeline.clusterStepModel.oneModelForEveryNode`,`One model for every node and camera:`),` `,a(`pipeline.clusterStepModel.indexNote`,{index:t.indexName})]}),l&&i(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:i(En,{i18nKey:`pipeline.clusterStepModel.noBuild`,values:{engine:n,model:s,index:t.indexName},components:{b:i(`b`,{})}})})]})}var ji=`pipeline-orchestrator`;function Mi({addonId:t,highlightLabel:n}){let{t:r}=X(),a=ge(t),{data:o}=ze({addonId:ji,cap:ji,scope:`cluster`});if(a.length===0)return null;let s=_e(o??null)[t]??{};return e(`section`,{className:`space-y-1.5 border-t border-border/60 pt-3`,"aria-label":r(`stepInspector.clusterOwnedSettings.clusterWideSettings`,`Cluster-wide settings`),children:[e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`h3`,{className:D,children:r(`stepInspector.clusterOwnedSettings.clusterWideSettings`,`Cluster-wide settings`)}),i(On,{to:Ei(t),className:`ml-auto text-[11px] text-primary hover:underline`,children:r(`stepInspector.clusterOwnedSettings.editInClusterSettings`,`Edit in Cluster → Settings ›`)})]}),a.map(t=>e(`div`,{className:`${p} rounded px-2 ${n===t.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[i(`span`,{className:R,children:t.label}),i(`span`,{className:y,children:i(`span`,{className:`font-mono text-xs text-foreground`,children:String(s[t.key]??t.default)})})]},t.key)),i(`p`,{className:W,children:r(`stepInspector.clusterOwnedSettings.oneValueForEveryNode`,`One value for every node and camera — this step writes into a shared index.`)})]})}function Ni({rows:t,hint:n}){let{t:r}=X();return e(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[i(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.map(t=>e(`li`,{className:`${T} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[i(`span`,{className:t.href===void 0?`min-w-0 flex-1 truncate text-foreground-muted`:`basis-full text-foreground-muted`,children:t.label}),i(`span`,{className:`font-mono text-foreground`,children:t.modelId??`—`}),i(`span`,{className:`text-[10px] text-foreground-subtle`,children:t.sourceLabel}),t.href!==void 0&&i(On,{to:t.href,className:`ml-auto text-[11px] text-primary hover:underline`,children:r(`stepInspector.effectiveModelSummary.changeOnAccelerator`)})]},t.id))}),i(`p`,{className:W,children:n??r(`stepInspector.effectiveModelSummary.toChangeAModelOpen`,`To change a model, open that accelerator's cell in the table.`)})]})}s();function Pi(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:en(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Fi({tree:a,searchRows:s,accelerators:c,cellState:l,stepBadge:u,disabledCount:d,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:y}){let{t:b}=X(),x=P(),C=mt(),{selection:w,open:T,close:ee}=Bn(n(()=>jn(a).map(e=>e.node.addonId),[a]),n(()=>c.map(e=>e.id),[c])),[D,O]=o(``),[k,A]=o(null),[j,te]=o(null),M=t(null),ne=t(null),N=t(null);Ue(N);let F=t(null),I=n(()=>Dt(s,D),[s,D]),L=n(()=>D.trim()===``?a:Un(a,new Set(I.map(e=>e.addonId))),[a,I,D]),R=e=>I.find(t=>t.addonId===e)?.matchedField??null,z=n(()=>c.map(Pi),[c]),B=e=>c.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),V=c.find(e=>e.id===w.acceleratorId)??null,H=w.stepId!==null,U=r(async e=>{if(m){if(!await x({title:b(`stepInspector.stepMatrixFrame.discardUnsavedChanges`,`Discard unsaved changes?`),message:b(`stepInspector.stepMatrixFrame.thisStepHasChangesThat`,`This step has changes that are not saved yet.`),confirmLabel:b(`stepInspector.stepMatrixFrame.discard`,`Discard`),variant:`danger`}))return;h()}e()},[x,m,h,b]),re=()=>{requestAnimationFrame(()=>F.current?.focus())},ie=(e,t,n=!1)=>{if(e===w.stepId&&(t?.id??null)===w.acceleratorId){n&&re();return}let r=()=>{A(R(e)),T({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&re()};e===w.stepId?r():U(r)},ae=()=>{let e=w.stepId;U(()=>{if(ee(),e!==null){let t=V===null?null:un({agentNodeId:V.nodeId,deviceKey:V.deviceKey});requestAnimationFrame(()=>M.current?.focusCell(e,t))}})},oe=e=>{if(e.key===`Enter`){let t=I[0];if(t===void 0)return;e.preventDefault(),ie(t.addonId,void 0,!0)}else e.key===`Escape`&&O(``)},se=C?i(kt,{onClick:ae}):i(bt,{icon:E,variant:`ghost`,size:`sm`,"aria-label":b(`common.close`,`Close`),onClick:ae});return e(`div`,{ref:ne,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),N.current?.focus()),e.key===`Escape`&&t&&H&&(e.preventDefault(),ae())},children:[e(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[i(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),i(bn,{ref:N,type:`search`,value:D,onChange:e=>O(e.target.value),onKeyDown:oe,placeholder:b(`stepInspector.stepMatrixFrame.filterStepsOrSettings`,`Filter steps or settings /`),"aria-label":b(`stepInspector.stepMatrixFrame.filterStepsOrSettings2`,`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`}),d>0&&e(`label`,{className:`inline-flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[i(S,{checked:f,onChange:e=>p(e.target.checked)}),b(`stepInspector.stepMatrixFrame.showDisabled`,{count:d})]}),_]}),w.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:b(`stepInspector.stepMatrixFrame.staleStep`,{id:w.staleStepId})}),L.length===0?i(`p`,{className:`${W} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:b(`stepInspector.stepMatrixFrame.noStepMatches`,{query:D})}):i(Zt,{ref:M,tree:L,agents:z,label:v,getCellState:(e,t)=>{let n=B(t);return n===void 0?{kind:`na`}:l(e,n)},onCellClick:(e,t,n)=>ie(e,B(t),n),onStepClick:(e,t)=>ie(e,void 0,t),...u===void 0?{}:{stepBadge:u},selectedCell:H&&w.stepId!==null&&V!==null?{addonId:w.stepId,agentNodeId:V.nodeId,deviceKey:V.deviceKey}:null,fallbackNodeId:j,onFallbackNodeChange:te,reserveRightPx:H&&!C?432:0}),i(ct,{open:H,anchor:ne,onClose:ae,label:b(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:w.stepId!==null&&y({stepId:w.stepId,accelerator:V,matchedField:k,closeButton:se,onEscape:ae,headingRef:e=>{F.current=e}})})]})}s();function Ii(e){a(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}s();function Li(e,t,n){return e.map(e=>{let r={...e.steps},i=r[t.stepId]??{},a=t.models[e.key],o=t.jumps[e.key],s=t.accelerator?.deviceKey===e.key?{...Object.fromEntries(Object.entries(i.settings??{}).filter(([e])=>!n(e))),...t.accelerator.settings}:i.settings,c=s!==void 0&&Object.keys(s).length>0?s:void 0,l=a===void 0?i.modelId:a??void 0,u=o===void 0?i.jumpDeviceKey:o||void 0,d={...l===void 0?{}:{modelId:l},...c===void 0?{}:{settings:c},...u===void 0?{}:{jumpDeviceKey:u}};return Object.keys(d).length>0?r[t.stepId]=d:delete r[t.stepId],{key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:r}})}function Ri(e,t){return t===void 0?0:[...new Set([...Object.keys(e),...Object.keys(t)])].filter(n=>!Ee(e[n],t[n])).length}function zi(e,t,n,r){if(t===null)return 0;let i=Object.entries(t.models).filter(([n,r])=>(r??void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.modelId).length,a=Object.entries(t.jumps).filter(([n,r])=>(r||void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.jumpDeviceKey).length,o=Ri(n,t.nodeSettings),s=t.accelerator===void 0?0:Ri(r(t.accelerator.deviceKey),t.accelerator.settings);return i+a+o+s}function Bi({nodeId:t,nodeName:r,toolbar:a}){let{t:s}=X(),c=l(),u=qe({nodeId:t},{refetchOnMount:`always`}),f=Wt({nodeId:t},{refetchOnMount:`always`}),p=nn({agentNodeId:t},{refetchOnMount:`always`}),m=p.data?.stepSettings,h=De(ze({addonId:`pipeline-orchestrator`,cap:`pipeline-orchestrator`,scope:`cluster`}).data??null),g=u.data?.devices??[],_=f.data??null,[v,y]=o(null),[b,x]=o(null),[S,C]=o(null),w=Be({onSuccess:()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),T=an({onSuccess:()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]})}}),[E,ee]=o(!1),O=n(()=>_?Ge(_):[],[_]),k=n(()=>jn(O),[O]),[A,j]=o(!1),te=n(()=>Wn(t,r,g,A),[t,r,g,A]),M=n(()=>Wn(t,r,g),[t,r,g]),ne=M.length>=2,N=(e,t)=>ti(g,t?.deviceKey,e,m)??{},P=e=>m?.[e]??{},F=(e,t)=>g.find(e=>e.key===t)?.steps?.[e]?.settings??{},L=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return M.find(e=>e.deviceKey===r);if(!zn(e,t))return M.filter(n=>n.id!==t.id&&zn(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},R=(e,t)=>{let n=Rn(_,e),r=ki(e),i=Nn(_,t),a=N(e,t),o=L(n,t);return Vn({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?Fn(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...Hn(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:h[e]??r.defaultModelId}:{},...o?{jumpTo:Ve(o.device)}:{}})},z=k.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Pn(Rn(_,e.addonId))}));if(u.isLoading||f.isLoading||p.isLoading)return i(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:s(`stepInspector.nodeStepInspector.loadingPipeline`,`Loading pipeline…`)});if(_===null)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:s(`stepInspector.nodeStepInspector.catalogUnavailable`,`Catalog unavailable.`)});let B=e(`span`,{className:W,children:[s(`stepInspector.nodeStepInspector.accelerators`,`Accelerators:`),` `,i(`span`,{className:`text-foreground`,children:M.length>0?M.map(e=>Ve(e.device)).join(` · `):s(`stepInspector.nodeStepInspector.noneEnabled`,`none enabled`)}),g.some(e=>!e.enabled)&&e(d,{children:[` `,s(`stepInspector.nodeStepInspector.off`,`— off:`),` `,g.filter(e=>!e.enabled).map(Ve).join(`, `)]}),` `,`·`,` `,i(On,{to:Di(),className:`text-primary hover:underline`,children:s(`stepInspector.nodeStepInspector.clusterLoadBalancing`,`Cluster → Load balancing ›`)})]});return i(Fi,{tree:O,searchRows:z,accelerators:te,cellState:R,disabledCount:g.filter(e=>!e.enabled).length,showDisabled:A,onShowDisabledChange:j,dirty:v!==null&&zi(g,v,P(v.stepId),e=>F(v.stepId,e))>0,onDiscard:()=>y(null),summary:B,...a===void 0?{}:{toolbar:a},label:s(`stepInspector.nodeStepInspector.detectionSteps`,`Detection steps`),renderDetail:({stepId:n,accelerator:a,matchedField:o,closeButton:c,onEscape:l,headingRef:u})=>{let f=Rn(_,n);if(f===null)return i(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:s(`stepInspector.nodeStepInspector.noStepSelected`,`No step selected.`)});let p=v?.stepId===n?v:null,m=a??M[0]??te[0],h=p?.nodeSettings??P(n),O=a===null?{}:p?.accelerator?.deviceKey===a.deviceKey?p.accelerator.settings:F(n,a.deviceKey),k={...h,...O},A=zi(g,p,P(n),e=>F(n,e)),j=e=>{C(null),y(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},R=ki(n),z=Cn(f),{nodeFields:B,acceleratorFields:V}=Gn(z),H=new Set(V.flatMap(e=>`key`in e?[e.key,`${e.key}ModelId`]:[])),U=m===void 0?void 0:Nn(_,m),re=e=>{let t=p?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},ie=m===void 0?void 0:Fn(f,m,{nodePin:re(m)}).modelId,ae=t=>{let r=re(t),o=Fn(f,t,{nodePin:r}),c=Nn(_,t),l=Hn(n,a?.id===t.id?k:N(n,t),c),u=p?.jumps[t.deviceKey],m=L(f,t,u),h=zn(f,t)?l&&c?i(Bt,{rootModel:c,stepModelId:o.modelId}):void 0:e(d,{children:[s(`stepInspector.nodeStepInspector.noBuild`,{format:t.device.format}),` `,m?s(`stepInspector.nodeStepInspector.itRunsOnInstead`,`It runs on {{shortLabel}} instead.`,{shortLabel:m.shortLabel}):s(`stepInspector.nodeStepInspector.itDoesNotRunHere`,`It does not run here.`)]}),g=ne?e(`label`,{className:`block space-y-1`,children:[i(`span`,{className:`text-[11px] font-medium text-foreground`,children:s(`stepInspector.nodeStepInspector.runOn`,`Run on`)}),i(I,{"aria-label":s(`stepInspector.nodeStepInspector.runOn`,`Run on`),value:u??t.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:s(`stepInspector.nodeStepInspector.autoThisAcceleratorOrThe`,`Auto (this accelerator, or the next one that can run it)`)},...M.filter(e=>e.id!==t.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:e=>j({jumps:{...p?.jumps,[t.deviceKey]:e.target.value}})}),i(`span`,{className:W,children:s(`stepInspector.nodeStepInspector.routesThisStepAndIts`,`Routes this step (and its child steps) to another accelerator of this node.`)})]}):void 0;return{label:t.label,format:t.device.format,modelId:o.modelId,source:o.source===`node`?`node`:`default`,sourceLabel:o.source===`node`?`node pin`:`hardware default`,models:Xe(f.models??[],t.device.format),defaultModelId:f.defaultModelIdByFormat?.[t.device.format]??f.defaultModelId,expanded:b===t.id,onToggle:()=>x(e=>e===t.id?null:t.id),onChangeModel:e=>j({models:{...p?.models,[t.deviceKey]:e}}),...r===void 0?{}:{onReset:()=>j({models:{...p?.models,[t.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...h===void 0?{}:{note:h},...g===void 0?{}:{extra:g},changed:p?.models[t.deviceKey]!==void 0||u!==void 0}},oe=async()=>{if(p!==null){ee(!0);try{(Object.keys(p.models).length>0||Object.keys(p.jumps).length>0||p.accelerator!==void 0)&&await w.mutateAsync({agentNodeId:t,inferenceDevices:ni(Li(g,p,e=>H.has(e)))}),p.nodeSettings!==void 0&&Ri(P(n),p.nodeSettings)>0&&await T.mutateAsync({agentNodeId:t,addonId:n,settings:Object.keys(p.nodeSettings).length>0?{...p.nodeSettings}:null}),y(null),C({kind:`saved`})}catch(e){C({kind:`error`,error:e instanceof Error?e.message:String(e)})}finally{ee(!1)}}};return i(Ct,{ref:u,title:a===null?`${f.name} · ${r}`:`${f.name} · ${a.label}`,subtitle:a===null?s(`stepInspector.nodeStepInspector.everyAcceleratorOf`,`{{slot}} · every accelerator of {{nodeName}}`,{slot:f.slot,nodeName:r}):s(`stepInspector.nodeStepInspector.baseForEveryCameraThat`,`{{slot}} · {{format}} · base for every camera that lands here`,{slot:f.slot,format:a.device.format}),leading:c,onEscape:l,saveBar:{dirtyCount:A,saving:E,status:S?.kind??null,...S?.error===void 0?{}:{error:S.error},onSave:()=>void oe(),onDiscard:()=>y(null)},children:e(`div`,{className:`space-y-3`,children:[e(`section`,{className:`space-y-2`,"aria-label":s(`stepInspector.nodeStepInspector.model`,`Model`),children:[i(`h3`,{className:D,children:s(`stepInspector.nodeStepInspector.model`,`Model`)}),R!==null&&m!==void 0?i(Ai,{step:R,engineFormat:m.device.format,runnableModelIds:Xe(f.models??[],m.device.format).map(e=>e.id)}):te.length===0?i(`p`,{className:W,children:i(En,{i18nKey:`stepInspector.nodeStepInspector.noAcceleratorEnabled`,components:{link:i(On,{to:Di(),className:`text-primary hover:underline`})}})}):a===null?i(Ni,{rows:te.map(e=>{let t=Fn(f,e,{nodePin:re(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):i(rt,{...ae(a)},a.id)]}),(z.length>0||U!==void 0)&&R===null&&e(`section`,{"aria-label":s(`stepInspector.nodeStepInspector.settings`,`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:s(`stepInspector.nodeStepInspector.nodeWideSettings`,{node:r})}),(B.length>0||U!==void 0)&&i(Vi,{addon:f,fields:B,settings:h,layerLabel:s(`stepInspector.nodeStepInspector.nodeLayer`,`Node`),modelId:vn(f,ie,k,U),root:U,highlight:o,onChange:e=>j({nodeSettings:e})}),V.length>0&&(a===null?i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`accelerator-settings-hint`,children:s(`stepInspector.nodeStepInspector.thresholdsPerAccelerator`,`Confidence thresholds belong to the model, so they are set per accelerator: open that accelerator's cell.`)}):e(`div`,{className:`space-y-1 border-t border-border/60 pt-2`,children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`accelerator-settings-scope`,children:s(`stepInspector.nodeStepInspector.acceleratorSettings`,{accelerator:a.label})}),i(Vi,{addon:f,fields:V,settings:O,layerLabel:s(`stepInspector.nodeStepInspector.acceleratorLayer`,`This accelerator`),modelId:vn(f,ie,k,U),root:void 0,highlight:o,onChange:e=>j({accelerator:{deviceKey:a.deviceKey,settings:e}})})]}))]}),i(Mi,{addonId:n,highlightLabel:o})]})})}})}function Vi({addon:e,fields:t,settings:n,layerLabel:r,modelId:a,root:o,highlight:s,onChange:c}){let l=t.find(e=>`label`in e&&e.label===s)?.key??null;return Ii(l===null?null:yn(l)),i(Ut,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:r},modelId:a,...o===void 0?{}:{rootModel:o},highlightKey:l,onChangeLayer:c})}s();function Hi({nodeId:t,refreshToken:n}){let{t:r}=X(),a=P(),[s,c]=o(null),{nodes:l}=K(),u=l.find(e=>e.id===t)?.name??t,f=Pt({onSuccess:e=>{c(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),p=async()=>{await a({title:r(`pipeline.nodePipelineTab.resetToHardwareAwareDefaults`,`Reset {{nodeName}} to hardware-aware defaults?`,{nodeName:u}),message:r(`pipeline.nodePipelineTab.thisClearsEveryPerDevice`,`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:r(`common.reset`,`Reset`),variant:`danger`})&&(c(null),f.mutate({agentNodeId:t}))};return e(`div`,{className:`space-y-2`,children:[i(ei,{nodeId:t}),i(Bi,{nodeId:t,nodeName:u,toolbar:e(d,{children:[s&&i(`span`,{className:`text-[11px] text-success`,children:s}),f.isError&&i(`span`,{className:`text-[11px] text-danger`,children:f.error instanceof Error?f.error.message:r(`pipeline.nodePipelineTab.resetFailed`,`Reset failed`)}),i(J,{variant:`outline`,size:`sm`,onClick:()=>{p()},disabled:f.isPending,title:r(`pipeline.nodePipelineTab.clearThisNodeSPer`,`Clear this node's per-device model defaults + per-camera overrides scoped to this node`),children:f.isPending?r(`pipeline.nodePipelineTab.resetting`,`Resetting…`):r(`pipeline.nodePipelineTab.resetToDefault`,`Reset to default`)})]})})]})}var Ui=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],Wi=`decoder-nodeav`,Gi=`ntab`,Ki={decoder:`engine`},qi={engine:`Engine & decoder`},Ji=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function Yi({nodeId:t,refreshToken:n}){let{t:r}=X(),[a,o]=Dn(),{nodes:s}=K(),c=s.find(e=>e.id===t)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??Wi,l=[...Ui,c],u=a.get(Gi),d={assignments:{id:`assignments`,label:r(`pipeline.nodeDetail.assignments`,`Assignments`),order:-10,content:i(Jr,{nodeId:t,refreshToken:n})},tree:{id:`tree`,label:r(`pipeline.nodeDetail.pipeline`,`Pipeline`),order:39,content:i(Hi,{nodeId:t,refreshToken:n})},engines:{id:`engines`,label:r(`pipeline.nodeDetail.warmInstances`,`Warm instances`),order:180,content:i(Xr,{nodeId:t,refreshToken:n})},logs:{id:`logs`,label:r(`pipeline.nodeDetail.logs`,`Logs`),order:300,content:i($r,{nodeId:t})}},f=_r.map(e=>d[e]);return e(`div`,{className:`flex flex-col h-full`,children:[i(gr,{nodeId:t,refreshToken:n}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:i(kn,{nodeId:t,addonIds:l,level:`global`,fieldScope:`perNode`,emptyMessage:Ji,tabAliases:Ki,tabLabelOverrides:qi,extraTabs:f,activeTab:u===null?null:Ki[u]??u,onActiveTabChange:e=>o(t=>{let n=new URLSearchParams(t);n.set(Gi,e);for(let e of Ln)n.delete(e);return n},{replace:!0})})})]})}function Xi(){let{t}=X();return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`min-w-0`,children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:t(`pipeline.clusterAssignmentsTab.cameraPlacement`,`Camera placement`)}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`pipeline.clusterAssignmentsTab.pinACameraToA`,`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.`)})]}),i(Kr,{})]})}function Zi(e){return`${Math.round(e*100)}%`}function Qi(e){return Y.t(`helpers.autoTuneViewModel.sessions`,{count:e})}var $i={"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`},ea={"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 ta(e){return e===null?`—`:$i[e]??e}function na(e){return e===null?`—`:ea[e]??e}function ra(e){switch(e.kind){case`capacity`:return Y.t(`helpers.autoTuneViewModel.capacity`,{sessions:Qi(e.sessions),min:e.minSessions});case`tie-faster`:return Y.t(`helpers.autoTuneViewModel.tieFaster`,{over:e.over,recall:Zi(e.recallDelta)});case`stepped-down`:return Y.t(`helpers.autoTuneViewModel.steppedDown`,{from:e.from,limitedBy:e.limitedBy,to:e.to});case`no-fit-lightest`:return Y.t(`helpers.autoTuneViewModel.noFitLightest`,{min:Qi(e.minSessions),sessions:Qi(e.sessions)});case`derived-latency`:return Y.t(`helpers.autoTuneViewModel.derivedLatency`,{modelId:e.modelId});case`cpu-device`:return Y.t(`helpers.autoTuneViewModel.cpuDevice`);case`device-disabled`:return Y.t(`helpers.autoTuneViewModel.deviceDisabled`);case`device-unavailable`:return Y.t(`helpers.autoTuneViewModel.deviceUnavailable`);case`node-offline`:return Y.t(`helpers.autoTuneViewModel.nodeOffline`);case`no-hardware-facts`:return Y.t(`helpers.autoTuneViewModel.noHardwareFacts`);case`no-measured-data`:return Y.t(`helpers.autoTuneViewModel.noMeasuredData`);case`no-family-build`:return Y.t(`helpers.autoTuneViewModel.noFamilyBuild`,{format:e.format});case`kept-custom-pin`:return Y.t(`helpers.autoTuneViewModel.keptCustomPin`,{modelId:e.modelId,deviceKey:e.deviceKey})}}function ia(e,t){switch(e.kind){case`custom-pin-kept`:return Y.t(`helpers.autoTuneViewModel.customPinNode`,{node:t(e.nodeId),modelId:e.modelId,deviceKey:e.deviceKey});case`custom-registry-unreadable`:return Y.t(`helpers.autoTuneViewModel.customRegistryUnreadable`,{error:e.error})}}function aa(e){return{modelChanges:e.nodeChanges.reduce((e,t)=>e+t.modelPins.length,0),thresholdClears:e.nodeChanges.reduce((e,t)=>e+t.thresholds.length,0)}}function oa(e){let t=aa(e);return t.modelChanges+t.thresholdClears===0}function sa(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 ca(e,t){return e?.kind===`node-benchmark`?Y.t(`helpers.autoTuneViewModel.latencyMeasured`,{date:new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}):e?.kind===`estimated`?Y.t(`helpers.autoTuneViewModel.latencyEstimated`,{hardware:na(e.estimatedFrom)}):Y.t(`helpers.autoTuneViewModel.latencyTable`)}s();var la=[.3,.4,.5];function ua(e){return la.some(t=>t===e)}var da=[1,2,3,4,6,8];function fa({plan:t,node:n,nodeName:r}){let{t:a}=X();return e(`section`,{className:b,"data-testid":`auto-tune-node-${n.nodeId}`,children:[e(`header`,{className:`${V} flex flex-wrap items-center gap-2`,children:[i(z,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),i(`h3`,{className:`${D} min-w-0 flex-1`,children:r(n.nodeId)}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[na(n.hardwareClass),n.cpuModel===null?``:` · ${n.cpuModel}`]}),n.skipped?i(q,{variant:`warning`,children:a(`pipeline.clusterAutoTuneTab.notChanged`,`Not changed`)}):n.acceleratorModelId!==null&&i(q,{variant:`info`,children:n.acceleratorModelId})]}),n.reasons.length>0&&i(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>i(`li`,{children:ra(e)},t))}),i(`div`,{className:`overflow-x-auto`,children:e(`table`,{className:`w-full text-xs`,children:[i(`thead`,{children:e(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[i(`th`,{className:`px-3 py-1.5 font-medium`,children:a(`pipeline.clusterAutoTuneTab.device`,`Device`)}),i(`th`,{className:`px-3 py-1.5 font-medium`,children:a(`pipeline.clusterAutoTuneTab.capacity`,`Capacity`)}),i(`th`,{className:`px-3 py-1.5 font-medium`,children:a(`pipeline.clusterAutoTuneTab.detector`,`Detector`)}),i(`th`,{className:`px-3 py-1.5 font-medium`,children:a(`pipeline.clusterAutoTuneTab.why`,`Why`)})]})}),i(`tbody`,{children:n.devices.map(r=>{let o=sa(t,n.nodeId,r.deviceKey);return e(`tr`,{className:`border-t border-border align-top`,children:[e(`td`,{className:`px-3 py-1.5`,children:[i(`div`,{className:`font-mono text-foreground`,children:r.deviceKey}),i(`div`,{className:`text-[11px] text-foreground-subtle`,children:ta(r.accelerator)})]}),e(`td`,{className:`px-3 py-1.5 text-foreground-muted`,children:[r.chosen===null?`—`:a(`pipeline.clusterAutoTuneTab.sessionsAtFps`,{count:r.chosen.capacitySessions,fps:t.cameraFps}),r.chosen!==null&&e(`div`,{className:`text-[11px] text-foreground-subtle`,children:[a(`pipeline.clusterAutoTuneTab.fpsKeptFree`,{fps:r.chosen.fps,percent:Math.round(t.headroom*100)}),i(`div`,{children:ca(r.chosen.source)})]})]}),i(`td`,{className:`px-3 py-1.5`,children:r.chosen===null?i(`span`,{className:`text-foreground-subtle`,children:a(`common.unchanged`)}):o!==null&&o.before!==o.after?e(`span`,{children:[i(`span`,{className:`text-foreground-subtle`,children:o.before??a(`common.defaultWord`)}),` → `,i(`span`,{className:`font-medium text-foreground`,children:o.after})]}):i(`span`,{className:`text-foreground`,children:r.chosen.modelId})}),i(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:r.reasons.map((e,t)=>i(`div`,{children:ra(e)},t))})]},r.deviceKey)})})]})})]})}function pa({plan:t,nodeName:n}){let{t:r}=X();return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:e(`div`,{children:[i(`div`,{className:D,children:r(`pipeline.clusterAutoTuneTab.nodeSettings`,`Node settings`)}),t.nodeChanges.length===0?i(`div`,{className:`text-foreground-subtle`,children:r(`pipeline.clusterAutoTuneTab.noChange`,`No change.`)}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:t.nodeChanges.flatMap(t=>[...t.modelPins.map(i=>e(`li`,{children:[e(`span`,{className:`font-mono`,children:[n(t.nodeId),` · `,t.deviceKey]}),` `,`— `,i.stepId,`: `,i.before??r(`pipeline.clusterAutoTuneTab.defaultModel`),` →`,` `,i.after??r(`pipeline.clusterAutoTuneTab.stepDefault`,`step default`)]},`${t.nodeId}/${t.deviceKey}/${i.stepId}/pin`)),...t.thresholds.map(i=>e(`li`,{children:[e(`span`,{className:`font-mono`,children:[n(t.nodeId),` · `,t.deviceKey]}),` `,`—`,` `,r(`pipeline.clusterAutoTuneTab.thresholdReset`,{step:i.stepId,keys:i.keys.join(`, `)})]},`${t.nodeId}/${t.deviceKey}/${i.stepId}/thr`))])})]})})}function ma({result:t}){let{t:n}=X();return t.kind===`refused`?i(`div`,{className:`text-xs text-warning`,children:n(`pipeline.clusterAutoTuneTab.anotherApplyIsAlreadyRunning`,`Another apply is already running.`)}):t.kind===`stale`?i(`div`,{className:`text-xs text-warning`,children:n(`pipeline.clusterAutoTuneTab.theConfigurationChangedSinceThe`,`The configuration changed since the plan was shown. Review the updated plan below and apply again.`)}):e(`ul`,{className:`text-xs`,"data-testid":`auto-tune-result`,children:[t.kind===`aborted`&&i(`li`,{className:`text-danger`,children:n(`pipeline.clusterAutoTuneTab.aModelCouldNotBe`,`A model could not be downloaded: nothing was changed.`)}),t.phases.map(t=>e(`li`,{className:t.ok?`text-foreground-muted`:`text-danger`,children:[t.ok?`✓`:`✗`,` `,t.phase,`: `,t.detail]},t.phase))]})}function ha(){let{t}=X(),r=l(),[a,s]=o(.4),[c,u]=o(2),[d,f]=o(!1),[p,m]=o(!1),[h,g]=o(null),{nodes:_}=K(),v=n(()=>Tr(_),[_]),y=pn({headroom:a,minSessionsPerDevice:c},{enabled:d,refetchOnWindowFocus:!1}),x=Je({onSuccess:e=>{g(e),m(!1),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.kind===`applied`&&y.refetch()}}),S=h?.kind===`stale`?h.plan:y.data,C=S===void 0?null:aa(S);return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[e(`section`,{className:b,children:[e(`header`,{className:`${V} flex flex-wrap items-center gap-2`,children:[i(oe,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),i(`h3`,{className:`${D} min-w-0 flex-1`,children:t(`pipeline.clusterAutoTuneTab.autoTune`,`Auto tune`)})]}),e(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[i(`p`,{children:t(`pipeline.clusterAutoTuneTab.picksForEveryAcceleratorThe`,`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 on the accelerators and clears their threshold overrides, so each model runs its own default thresholds. Cameras carry no model or threshold of their own. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`)}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(`label`,{className:`flex items-center gap-1.5`,children:[i(`span`,{className:`whitespace-nowrap`,children:t(`pipeline.clusterAutoTuneTab.keepFree`,`Keep free`)}),i(I,{"aria-label":t(`pipeline.clusterAutoTuneTab.shareOfEachAcceleratorKept`,`Share of each accelerator kept free`),value:String(a),options:la.map(e=>({value:String(e),label:t(`pipeline.clusterAutoTuneTab.ofEachAccelerator`,`{{value1}}% of each accelerator`,{value1:Math.round(e*100)})})),onChange:e=>{let t=Number(e.target.value);ua(t)&&s(t)}})]}),e(`label`,{className:`flex items-center gap-1.5`,children:[i(`span`,{className:`whitespace-nowrap`,children:t(`pipeline.clusterAutoTuneTab.atLeast`,`At least`)}),i(I,{"aria-label":t(`pipeline.clusterAutoTuneTab.minimumParallelSessionsPerDevice`,`Minimum parallel sessions per device`),value:String(c),options:da.map(e=>({value:String(e),label:t(`pipeline.clusterAutoTuneTab.camerasAtOnce`,{count:e})})),onChange:e=>{let t=Number(e.target.value);da.some(e=>e===t)&&u(t)}})]}),i(J,{size:`sm`,variant:`secondary`,onClick:()=>{g(null),f(!0),d&&y.refetch()},children:y.isFetching?t(`pipeline.clusterAutoTuneTab.computing`,`Computing…`):S===void 0?t(`pipeline.clusterAutoTuneTab.computePlan`,`Compute plan`):t(`pipeline.clusterAutoTuneTab.recompute`,`Recompute`)}),S!==void 0&&i(J,{size:`sm`,disabled:oa(S),onClick:()=>m(!0),children:t(`pipeline.clusterAutoTuneTab.apply`,`Apply…`)})]}),y.error!==null&&i(`div`,{className:`text-danger`,children:y.error.message}),h!==null&&i(ma,{result:h}),C!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:t(`pipeline.clusterAutoTuneTab.planSummary`,{modelChanges:C.modelChanges,thresholdClears:C.thresholdClears})})]})]}),S?.warnings.map((e,t)=>i(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:ia(e,v)},t)),S?.nodes.map(e=>i(fa,{plan:S,node:e,nodeName:v},e.nodeId)),S!==void 0&&i(wt,{open:p,onOpenChange:m,children:e(tt,{width:`lg`,scroll:`body`,children:[e(at,{children:[i(Ft,{children:t(`pipeline.clusterAutoTuneTab.applyAutoTune`,`Apply auto tune?`)}),i(lt,{children:t(`pipeline.clusterAutoTuneTab.theseAreAllTheChanges`,`These are all the changes. Every override listed is removed and cannot be restored.`)})]}),i(At,{children:i(pa,{plan:S,nodeName:v})}),e(dn,{children:[i(J,{variant:`ghost`,onClick:()=>m(!1),children:t(`common.cancel`,`Cancel`)}),i(J,{variant:`danger`,disabled:x.isPending,onClick:()=>x.mutate({planHash:S.planHash,headroom:a,minSessionsPerDevice:c}),children:x.isPending?t(`pipeline.clusterAutoTuneTab.applying`,`Applying…`):t(`common.apply`,`Apply`)})]})]})})]})}var ga={disabled:`pipeline.nodeLoadOverview.exclusion.disabled`,unavailable:`pipeline.nodeLoadOverview.exclusion.unavailable`,"cannot-host-camera-root":`pipeline.nodeLoadOverview.exclusion.cannotHostCameraRoot`,"accelerator-preferred":`pipeline.nodeLoadOverview.exclusion.acceleratorPreferred`};function _a(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function va(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function ya(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:en(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?_a(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 ba(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=ya(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),va(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?_a(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?_a(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}s();var xa=2e4,Sa=3e5;function Ca({stats:e,targetWeights:t,showAccelerators:r=!0}){let{t:a}=X(),{nodes:o}=K(),s=se().trpcClient,l=ht(void 0,{placeholderData:u,staleTime:xa,refetchInterval:xa,refetchOnWindowFocus:!0}),d=ut(void 0,{staleTime:Sa}),f=n(()=>o.map(e=>e.id),[o]),p=c({queries:f.map(e=>({queryKey:Re(Lt.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>s.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Sa,refetchOnWindowFocus:!1,placeholderData:u}))}),h=n(()=>{let e={};return f.forEach((t,n)=>{let r=p[n]?.data;r&&(e[t]=r.devices)}),e},[f,p.map(e=>e.dataUpdatedAt).join(`|`)]),g=n(()=>{let e=new Map;for(let t of d.data??[])e.set(t.nodeId,t.settings);return e},[d.data]),_=n(()=>o.map(e=>{let n=g.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:pr(n).pipeline,weight:t?.[e.id]??tr(n,`detectWeight`)??1,maxCameras:tr(n,`maxCameras`)}}),[o,g,t]),v=l.data??[],y=n(()=>ba({nodes:_,loads:v,devicesByNode:h}),[_,v,h]),b=y.reduce((e,t)=>e+(t.attachedCameras??0),0),x=y.reduce((e,t)=>e+(t.activeCameras??0),0),S=l.dataUpdatedAt>0?Date.now()-l.dataUpdatedAt:null,C=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return i(G,{headingId:`load-balancing-node-load`,title:a(`pipeline.nodeLoadOverview.nodeLoad`,`Node load`),icon:A,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:a(`pipeline.nodeLoadOverview.summaryLine`,{active:x,attached:b,reading:l.data===void 0?a(`pipeline.nodeLoadOverview.reading`,`reading…`):a(`pipeline.nodeLoadOverview.readingAge`,{age:S===null?`—`:`${Math.round(S/1e3)}s`})})}),children:i(`div`,{className:m,children:y.length===0?i(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:a(`pipeline.nodeLoadOverview.noClusterNodesReportedYet`,`No cluster nodes reported yet.`)}):i(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:y.map(e=>i(wa,{row:e,placed:C.get(e.nodeId),showAccelerators:r},e.nodeId))})})})}function wa({row:t,placed:n,showAccelerators:r}){let{t:a}=X(),o=t.attachedCameras===null?`—`:`${t.activeCameras??0} / ${t.attachedCameras}${t.maxCameras===null?``:` of ${t.maxCameras}`}`;return e(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[e(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[i(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${t.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),i(`span`,{className:`truncate text-xs font-medium text-foreground`,title:t.nodeId,children:t.name}),!t.detectEnabled&&i(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:a(`pipeline.nodeLoadOverview.noDetect`,`no detect`)}),!t.reported&&t.isOnline&&e(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:a(`pipeline.nodeLoadOverview.onlineButItDidNot`,`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`),children:[i(j,{className:`h-2.5 w-2.5`}),` `,a(`pipeline.nodeLoadOverview.noReading`)]}),!t.isOnline&&e(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[i(B,{className:`h-2.5 w-2.5`}),` `,a(`common.offline`)]})]}),e(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[i(Da,{label:a(`pipeline.nodeLoadOverview.runningAttached`,`Running / attached`),value:o,title:a(`pipeline.nodeLoadOverview.sessionsInInferenceNowCameras`,`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`)}),i(Da,{label:a(`pipeline.nodeLoadOverview.targetShare`,`Target share`),value:t.weightSharePct===null?`out of play`:`${t.weightSharePct}%`,title:a(`pipeline.nodeLoadOverview.theNodeShareAutomaticOr`,`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`)}),i(Da,{label:a(`pipeline.nodeLoadOverview.actualShare1H`,`Actual share (1 h)`),value:n?.observedShare===null||n===void 0?`—`:`${Math.round(n.observedShare*100)}%`,title:a(`pipeline.nodeLoadOverview.timeWeightedShareOfThe`,`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.`)}),i(Da,{label:a(`pipeline.nodeLoadOverview.peakYields`,`Peak · yields`),value:n===void 0?`—`:`${n.peakSessions} · ${n.yieldsAway}`,title:a(`pipeline.nodeLoadOverview.mostSessionsThisNodeRan`,`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.`)}),i(Da,{label:a(`pipeline.nodeLoadOverview.scoreQueue`,`Score · queue`),value:t.score===null?`—`:`${t.score} · ${t.queueDepthTotal??0}`,title:a(`pipeline.nodeLoadOverview.theCapacityScoreBalanceMinimises`,`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`)}),t.capacityPct!==null&&i(Da,{label:a(`pipeline.nodeLoadOverview.capFill`,`Cap fill`),value:`${t.capacityPct}%`,title:a(`pipeline.nodeLoadOverview.attachedMaxcameras`,`attached / maxCameras.`)}),t.avgInferenceTimeMs!==null&&i(Da,{label:a(`pipeline.nodeLoadOverview.avgInfer`,`Avg infer`),value:`${Math.round(t.avgInferenceTimeMs)} ms`,title:a(`pipeline.nodeLoadOverview.meanInferenceTimeAcrossThis`,`Mean inference time across this node's attached cameras.`)}),t.decodeHwaccel!==null&&i(Da,{label:a(`pipeline.nodeLoadOverview.decode`,`Decode`),value:t.decodeHwaccel,title:a(`pipeline.nodeLoadOverview.thisNodeSProbedDecode`,`This node's probed decode hwaccel.`)})]}),r&&i(Ta,{row:t})]})}function Ta({row:t}){let{t:n}=X();return t.devices.length===0?i(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:n(`pipeline.nodeLoadOverview.acceleratorsNotReadYet`,`Accelerators not read yet.`)}):e(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[e(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[i(ne,{className:`h-2.5 w-2.5`}),n(`pipeline.nodeLoadOverview.accelerators`,`Accelerators`),t.eligibleDeviceCount===0&&i(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:n(`pipeline.nodeLoadOverview.noDeviceIsACamera`,`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`),children:n(`pipeline.nodeLoadOverview.noneInPlayRunnerDefault`,`none in play · runner default pool`)})]}),i(`ul`,{className:`mt-1 space-y-0.5`,children:t.devices.map(e=>i(Ea,{device:e},e.key))})]})}function Ea({device:t}){let{t:n}=X(),r=t.exclusion;return e(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[i(z,{className:`h-2.5 w-2.5 shrink-0 ${r===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),i(`span`,{className:`shrink-0 font-medium ${r===null?`text-foreground`:`text-foreground-subtle`}`,title:`${t.key} · ${t.format}`,children:t.label}),r===null?e(d,{children:[i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:n(`pipeline.nodeLoadOverview.sharePct`,{pct:t.weightSharePct})}),e(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,title:t.sessions===null?n(`pipeline.nodeLoadOverview.notKnownTheNodeDid`,`Not known: the node did not report, or runs a session no device accounts for.`):void 0,children:[`· `,n(`common.sessionsCount`,{count:t.sessions??0}),t.maxSessions===null?``:`/${t.maxSessions}`]}),t.atCap&&i(`span`,{className:`shrink-0 text-amber-400`,title:n(`pipeline.nodeLoadOverview.atItsMaxsessionsCapThe`,`At its maxSessions cap — the balancer skips it until a session ends.`),children:n(`pipeline.nodeLoadOverview.atCap`,`· at cap`)})]}):i(`span`,{className:`truncate text-foreground-subtle/80`,title:n(ga[r]),children:n(`pipeline.nodeLoadOverview.excludedWith`,{reason:n(ga[r])})})]})}function Da({label:t,value:n,title:r}){return e(`div`,{className:`min-w-0`,title:r,children:[i(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:t}),i(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:n})]})}function Oa(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function ka(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 Aa(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function ja(e){return e.reason===`disabled`?Y.t(`helpers.loadBalancingViewModel.stalePinDisabled`,{deviceKey:e.deviceKey}):Y.t(`helpers.loadBalancingViewModel.stalePinMissing`,{deviceKey:e.deviceKey})}function Ma(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 Na(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(`, `),i=n.map(e=>t(e.nodeId)).join(`, `);return Y.t(`helpers.loadBalancingViewModel.shareNote`,{count:n.length,names:i,into:r})}var Pa=[{value:`hardware`,get label(){return Y.t(`helpers.loadBalancingViewModel.hardwareLabel`)},get hint(){return Y.t(`helpers.loadBalancingViewModel.hardwareHint`)}},{value:`benchmark`,get label(){return Y.t(`helpers.loadBalancingViewModel.benchmarkLabel`)},get hint(){return Y.t(`helpers.loadBalancingViewModel.benchmarkHint`)}},{value:`manual`,get label(){return Y.t(`helpers.loadBalancingViewModel.manualLabel`)},get hint(){return Y.t(`helpers.loadBalancingViewModel.manualHint`)}}];function Fa(e){return e===`no-benchmark-results`?Y.t(`helpers.loadBalancingViewModel.fallbackNone`):e===`partial-benchmark-results`?Y.t(`helpers.loadBalancingViewModel.fallbackPartial`):null}function Ia(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)}: ${Fa(e.capacityFallback)??``}`).join(` · `)}s();function La(e,t,n){return Math.min(Math.max(e,t),n)}function Ra(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 za(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:La(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 Ba(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 Va({nodes:t,pending:n,onCommitWeights:r,weightLabel:s=`Detection weight`,emptyHint:c,footnote:l,readOnly:u=!1}){let{t:p}=X(),[m,h]=o(()=>Ra(t)),[g,y]=o(new Set);a(()=>{h(Ra(t)),y(e=>new Set([...e].filter(e=>t.some(t=>t.id===e))))},[t.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let b=t.map(e=>e.id),x=e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=(e,t)=>{h(n=>za(n,e,t,g,b))},C=()=>{let e=Ba(m,b,g),n=t.filter(t=>(e[t.id]??0)!==t.weight).map(e=>e.id);if(n.length===0)return;let i=new Set([...n,...g]);r(t.filter(e=>i.has(e.id)).map(t=>({nodeId:t.id,weight:e[t.id]??0})))};if(t.length===0)return i(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:c??p(`placementBoard.weightSliderStack.noDetectEnabledNodesEnable`,`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`)});let w=t.length===1;return e(`div`,{className:`space-y-3`,children:[t.map(t=>{let r=m[t.id]??0,a=g.has(t.id);return e(`div`,{className:`flex items-center gap-3`,children:[i(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:t.name,children:t.name}),i(f,{"aria-label":p(`placementBoard.weightSliderStack.for`,`{{weightLabel}} for {{name}}`,{weightLabel:s,name:t.name}),min:0,max:100,step:1,value:Math.round(r),disabled:u||n||a||w,onChange:e=>S(t.id,Number(e.target.value)),onPointerUp:()=>C(),onKeyUp:()=>C(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),e(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(r),`%`]}),!u&&i(J,{variant:`unstyled`,type:`button`,onClick:()=>x(t.id),disabled:n||w,"aria-pressed":a,title:a?p(`placementBoard.weightSliderStack.unlockAllowRebalancing`,`Unlock — allow rebalancing`):p(`placementBoard.weightSliderStack.lockThisShareWhenOthers`,`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:i(a?_:v,{className:`h-3.5 w-3.5`})})]},t.id)}),i(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:l??i(d,{children:p(`placementBoard.weightSliderStack.draggingOneSliderSplitsThe`,`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 Ha(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}function Ua(e){if(e.presence===`absent`)return`absent`;if(e.presence===`unknown`)return`unknown`;switch(e.exclusion){case null:return`active`;case`disabled`:return`disabled`;case`unavailable`:return e.available?`backoff`:`unavailable`;case`cannot-host-camera-root`:return`root-incapable`;case`accelerator-preferred`:return`standby`}}function Wa(e,t,n){let r=new Map((t?.devices??[]).map(e=>[e.deviceKey,e])),i=new Map((n?.devices??[]).map(e=>[e.deviceKey,e.sessionsNow]));return e.map(e=>{let t=r.get(e.key),a=n===void 0?null:i.get(e.key)??0;return{device:e,state:Ua(e),share:t===void 0?null:{configuredPct:t.configuredPct,effectivePct:t.effectivePct},sessionsNow:a,atCap:a!==null&&e.maxSessions!==null&&a>=e.maxSessions}})}var Ga={active:`success`,disabled:`neutral`,absent:`danger`,unknown:`neutral`,unavailable:`warning`,backoff:`warning`,"root-incapable":`info`,standby:`neutral`};s();function Ka(e){let t=en(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:z,hue:`slate`}:r===`npu`?{label:t,Icon:ie,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:je,hue:`violet`}:n===`edgetpu`?{label:t,Icon:Fe,hue:`emerald`}:{label:t,Icon:z,hue:`slate`}}var qa={active:[`placementBoard.nodeInferenceDevices.state.active`,`in use`],disabled:[`placementBoard.nodeInferenceDevices.state.disabled`,`switched off`],absent:[`placementBoard.nodeInferenceDevices.state.absent`,`absent`],unknown:[`placementBoard.nodeInferenceDevices.state.unknown`,`unknown`],unavailable:[`placementBoard.nodeInferenceDevices.state.unavailable`,`unavailable`],backoff:[`placementBoard.nodeInferenceDevices.state.backoff`,`pool down`],"root-incapable":[`placementBoard.nodeInferenceDevices.state.rootIncapable`,`no root model`],standby:[`placementBoard.nodeInferenceDevices.state.standby`,`fallback`]},Ja={active:[`placementBoard.nodeInferenceDevices.stateHint.active`,`A camera-root candidate: placement may start sessions on it.`],disabled:[`placementBoard.nodeInferenceDevices.stateHint.disabled`,`Switched off: it takes no sessions.`],absent:[`placementBoard.nodeInferenceDevices.stateHint.absent`,`The node no longer reports this device (unplugged, or moved to another node). Its settings are kept; it is never used. Forget it to delete them.`],unknown:[`placementBoard.nodeInferenceDevices.stateHint.unknown`,`The node's probe did not answer, so whether the device is there is not known.`],unavailable:[`placementBoard.nodeInferenceDevices.stateHint.unavailable`,`On the node, but the probe reports it unusable.`],backoff:[`placementBoard.nodeInferenceDevices.stateHint.backoff`,`Reported by the node, but its inference pool is down or backing off.`],"root-incapable":[`placementBoard.nodeInferenceDevices.stateHint.rootIncapable`,`Its format cannot run the camera root detector; it serves enrichment steps only.`],standby:[`placementBoard.nodeInferenceDevices.stateHint.standby`,`The CPU fallback: it takes no sessions while an accelerator is serving this node.`]};function Ya({nodeId:t,nodeName:r,isOnline:s,suggestedMaxSessions:c,shareSource:u,sharesAutomatic:f,share:p,placed:m}){let{t:h}=X(),g=l(),{data:_,isLoading:v}=qe({nodeId:t},{refetchInterval:15e3}),y=()=>{g.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},b=Be({onSettled:y}),x=Ze({onSettled:y}),S=Lt.platformProbe.rescanAccelerators.useMutation({onSettled:y}),C=_?.devices??[],w=_?.reachable??s,[T,E]=o({});a(()=>{E(Object.fromEntries(C.map(e=>[e.key,Xa(e)])))},[C.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let ee=n(()=>C.filter(e=>(T[e.key]?.enabled??e.enabled)&&e.available).length,[C,T]),[D,O]=o(null),A=D??!0,j=e=>{let n=C.map(t=>{let n=e[t.key]??Xa(t);return{key:t.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});b.mutate({agentNodeId:t,inferenceDevices:ni(n)})},M=(e,t)=>{let n=T[e.key]??Xa(e),r={...T,[e.key]:{...n,...t}};E(r),j(r)},ne=n(()=>Wa(C,p,m),[C,p,m]),N=n(()=>C.filter(e=>(T[e.key]?.enabled??e.enabled)&&e.available),[C,T]),P=n(()=>N.map(e=>({id:e.key,name:Ka(e).label,weight:T[e.key]?.weight??e.weight})),[N,T]),F=e=>{let t={...T};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}E(t),j(t)},I=b.isPending||x.isPending,L=Za(h,f?u:`manual`),R=[{key:`device`,header:h(`placementBoard.nodeInferenceDevices.colDevice`,`Device`),nowrap:!1,sortValue:e=>Ka(e.device).label,render:e=>i($a,{row:e,steps:T[e.device.key]?.steps})},{key:`state`,header:h(`placementBoard.nodeInferenceDevices.colState`,`State`),sortValue:e=>e.state,render:e=>i(`span`,{title:h(Ja[e.state][0],Ja[e.state][1]),children:i(q,{variant:Ga[e.state],size:`sm`,children:h(qa[e.state][0],qa[e.state][1])})})},{key:`share`,header:h(`placementBoard.nodeInferenceDevices.colShare`,`Share`),align:`right`,sortValue:e=>e.share?.effectivePct??null,render:e=>i(eo,{row:e,sourceLabel:L})},{key:`sessions`,header:h(`placementBoard.nodeInferenceDevices.colSessions`,`Sessions`),align:`right`,sortValue:e=>e.sessionsNow,render:t=>e(`span`,{className:`tabular-nums text-xs text-foreground`,children:[t.sessionsNow??`—`,t.atCap&&i(q,{variant:`warning`,size:`sm`,className:`ml-1`,children:h(`placementBoard.nodeInferenceDevices.atCap`,`at cap`)})]})},{key:`cap`,header:h(`placementBoard.nodeInferenceDevices.colCap`,`Max sessions`),notSortableReason:h(`placementBoard.nodeInferenceDevices.capNotSortable`,`An editable field: sort by Sessions instead.`),render:t=>{let n=T[t.device.key]??Xa(t.device);if(!(n.enabled&&t.device.available))return i(`span`,{className:`text-xs text-foreground-subtle`,children:`—`});let r=Ka(t.device).label;return e(`div`,{className:`flex items-center justify-end gap-1`,children:[i(bn,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:e=>{let n=e.target.value.trim(),r=n===``?null:Number.parseInt(n,10);M(t.device,{maxSessions:r!==null&&r>0?r:null})},disabled:I,"aria-label":h(`placementBoard.nodeInferenceDevices.maxConcurrentSessionsFor`,`Max concurrent sessions for {{label}}`,{label:r}),className:`w-16 text-right`}),i(to,{suggested:c?.[t.device.key]??null,current:n.maxSessions,pending:I,onApply:e=>M(t.device,{maxSessions:e})})]})}},{key:`enabled`,header:h(`placementBoard.nodeInferenceDevices.colEnabled`,`Enabled`),align:`right`,notSortableReason:h(`placementBoard.nodeInferenceDevices.enabledNotSortable`,`A switch: sort by State instead.`),render:e=>{let n=Ka(e.device).label;if(e.state===`absent`)return i(tn,{label:h(`placementBoard.nodeInferenceDevices.forget`,`Forget`),icon:U,size:`sm`,triggerVariant:`ghost`,disabled:I,title:h(`placementBoard.nodeInferenceDevices.forgetTitle`,`Forget {{label}} on {{node}}?`,{label:n,node:r}),description:h(`placementBoard.nodeInferenceDevices.forgetDescription`,`Its stored settings (switch, weight, cap, step models) are deleted. If the device comes back it starts from the defaults.`),action:()=>x.mutateAsync({agentNodeId:t,deviceKey:e.device.key})});let a=T[e.device.key]??Xa(e.device);return i(ln,{checked:a.enabled&&e.device.available,onCheckedChange:()=>M(e.device,{enabled:!a.enabled}),disabled:!e.device.available||I,"aria-label":h(`placementBoard.nodeInferenceDevices.enable`,`Enable {{label}}`,{label:n})})}}],z=b.error??x.error??S.error;return e(`div`,{className:`rounded-lg border border-border bg-surface`,children:[e(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[e(J,{variant:`ghost`,size:`sm`,onClick:()=>O(!A),className:`min-w-0 flex-1 justify-start`,"aria-expanded":A,children:[i(te,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${A?`rotate-90`:``}`}),i(`span`,{className:`truncate text-sm font-medium text-foreground`,children:r}),i(`span`,{className:`ml-auto flex items-center gap-1 text-xs text-foreground-subtle`,children:w?e(d,{children:[i(Le,{className:`h-3.5 w-3.5`}),h(`pipeline.nodeInferenceDevices.accelerators`,{count:ee})]}):e(d,{children:[i(B,{className:`h-3.5 w-3.5`}),` `,h(`common.unreachable`)]})})]}),e(J,{variant:`ghost`,size:`sm`,onClick:()=>S.mutate({nodeId:t}),disabled:S.isPending||!w,title:h(`placementBoard.nodeInferenceDevices.rescanTitle`,`Probe this node for accelerators now (a Coral plugged in or pulled out). The node also re-probes every minute.`),children:[i(k,{className:`h-3.5 w-3.5 ${S.isPending?`animate-spin`:``}`}),h(`placementBoard.nodeInferenceDevices.rescan`,`Rescan`)]})]}),A&&e(`div`,{className:`space-y-3 border-t border-border p-3`,children:[w?v&&C.length===0?i(`p`,{className:`text-center text-xs text-foreground-subtle`,children:h(`placementBoard.nodeInferenceDevices.probingAccelerators`,`Probing accelerators…`)}):i(wn,{columns:R,rows:ne,rowKey:e=>e.device.key,minWidthPx:640,bordered:!1,emptyMessage:h(`placementBoard.nodeInferenceDevices.noInferenceDevicesReportedBy`,`No inference devices reported by this node's platform probe.`)}):i(no,{}),S.data!==void 0&&i(`p`,{className:`text-xs text-foreground-subtle`,children:Qa(h,S.data.appeared,S.data.disappeared)}),w&&!f&&N.length>=2&&e(`div`,{className:`space-y-3 rounded-lg border border-border p-3`,children:[e(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[i(Ne,{className:`h-3.5 w-3.5`}),h(`placementBoard.nodeInferenceDevices.acceleratorShare`,`Accelerator share`)]}),i(Va,{nodes:P,pending:I,onCommitWeights:F,weightLabel:`Accelerator share`,footnote:h(`placementBoard.nodeInferenceDevices.dragToShiftTheShare`,`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%.`)})]}),z!=null&&e(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-xs text-danger`,children:[h(`placementBoard.nodeInferenceDevices.failedToSaveInferenceDevices`,`Failed to save inference devices:`),` `,z.message]})]})]})}function Xa(e){return{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}}function Za(e,t){switch(t){case`benchmark`:return e(`placementBoard.nodeInferenceDevices.sourceBenchmark`,`benchmark`);case`hardware`:return e(`placementBoard.nodeInferenceDevices.sourceHardware`,`hardware`);case`manual`:return e(`placementBoard.nodeInferenceDevices.sourceManual`,`manual`);case void 0:return null}}function Qa(e,t,n){return t.length===0&&n.length===0?e(`placementBoard.nodeInferenceDevices.rescanNoChange`,`Rescanned: no change.`):e(`placementBoard.nodeInferenceDevices.rescanChanged`,`Rescanned: appeared {{appeared}} · disappeared {{disappeared}}`,{appeared:t.length>0?t.join(`, `):`—`,disappeared:n.length>0?n.join(`, `):`—`})}function $a({row:t,steps:n}){let r=Ka(t.device),a=Ha({defaultModelId:t.device.defaultModelId,steps:n??t.device.steps??{}});return e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[i(r.Icon,{className:`h-4 w-4 shrink-0 text-foreground-subtle`}),e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-1.5`,children:[i(`span`,{className:`text-sm font-medium text-foreground`,children:r.label}),i(q,{variant:`neutral`,size:`sm`,className:`font-mono`,children:t.device.format})]}),e(`div`,{className:`flex flex-wrap items-center gap-x-1.5 text-xs text-foreground-subtle`,children:[i(`span`,{className:`font-mono`,children:t.device.key}),a!==null&&e(d,{children:[i(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:i(En,{i18nKey:`pipeline.nodeInferenceDevices.rootModel`,values:{model:a},components:{mono:i(`span`,{className:`font-mono text-foreground-muted`})}})})]})]})]})]})}function eo({row:t,sourceLabel:n}){let{t:r}=X();if(t.share===null)return i(`span`,{className:`text-xs text-foreground-subtle`,children:`—`});let{configuredPct:a,effectivePct:o}=t.share,s=Math.round(a)!==Math.round(o);return e(`div`,{className:`text-right`,children:[e(`div`,{className:`tabular-nums text-sm text-foreground`,children:[Math.round(o),`%`]}),e(`div`,{className:`text-xs text-foreground-subtle`,children:[s?r(`placementBoard.nodeInferenceDevices.shareConfigured`,`set {{pct}}%`,{pct:Math.round(a)}):null,s&&n!==null?` · `:null,n]})]})}function to({suggested:e,current:t,pending:n,onApply:r}){let{t:a}=X();return e===null||e<1||e===t?null:i(J,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:a(`placementBoard.nodeInferenceDevices.advisoryCapFromTheMeasured`,`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`),children:a(`pipeline.nodeInferenceDevices.use`,{value:e})})}function no(){let{t}=X();return e(`div`,{className:`flex flex-col items-center gap-2 px-4 py-6 text-center`,children:[i(B,{className:`h-6 w-6 text-foreground-subtle`}),i(`p`,{className:`text-xs font-medium text-foreground`,children:t(`placementBoard.nodeInferenceDevices.nodeUnreachable`,`Node unreachable`)}),i(`p`,{className:`max-w-sm text-xs text-foreground-subtle`,children:t(`placementBoard.nodeInferenceDevices.thePlatformProbeCouldnT`,`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`)})]})}s();var ro=3600*1e3,io=2e4,ao=.4;function oo({refreshToken:t,onOpenAutoTune:r}){let{t:a}=X(),s=l(),{nodes:c}=K(),f=ut(void 0),p=Rt({isCamera:!0,projection:`slim`}),h=Mt({windowMs:ro},{refetchInterval:io,placeholderData:u}).data,g=yt(void 0,{refetchInterval:io,placeholderData:u}).data,_=()=>{Zn(s),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},v=Gt({onSuccess:_}),y=qt({onSuccess:()=>{_(),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),b=Jt({onSuccess:_}),x=st(),[S,C]=o(!1),w=g?.source,E=w===`benchmark`?`benchmark`:`hardware`,D=Xt({headroom:ao,source:E},{enabled:S,staleTime:1/0}),O=D.data,k=n(()=>{let e=new Map((f.data??[]).map(e=>[e.nodeId,e.settings]));return c.filter(t=>pr(e.get(t.id)).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:tr(n,`detectWeight`)??1,maxCameras:tr(n,`maxCameras`)}})},[c,f.data]),A=e=>c.find(t=>t.id===e)?.name??e,j=Er((p.data??[]).map(e=>({id:e.id,name:e.name}))),te=O?Aa(O):void 0,M=Ma(k,g),ne=w!==`manual`,N=g!==void 0&&g.source!==`manual`&&!g.autoPending,P=e=>g?.nodes.find(t=>t.nodeId===e),F=e=>h?.nodes.find(t=>t.nodeId===e),I=g?Na(g,A):null,L=g?Ia(g,A):null,R=Pa.find(e=>e.value===w)?.hint;return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(vr,{refreshToken:t}),i(Ca,{stats:h,showAccelerators:!1,...g!==void 0&&g.source!==`manual`&&!g.autoPending?{targetWeights:Object.fromEntries(g.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),i(G,{headingId:`load-balancing-node-shares`,title:a(`pipeline.clusterLoadBalancingTab.nodeShares`,`Node shares`),icon:Ne,actions:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(`div`,{role:`radiogroup`,"aria-label":a(`pipeline.clusterLoadBalancingTab.shareSource`,`Share source`),className:`flex items-center gap-1`,children:Pa.map(e=>i(J,{role:`radio`,"aria-checked":w===e.value,variant:w===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:y.isPending||g===void 0,onClick:()=>{w!==e.value&&y.mutate({source:e.value})},children:e.label},e.value))}),e(J,{variant:`outline`,size:`sm`,onClick:()=>{C(!0),S&&D.refetch()},disabled:D.isFetching,children:[i(ee,{className:`h-3.5 w-3.5`}),D.isFetching?a(`pipeline.clusterLoadBalancingTab.suggesting`,`Suggesting…`):E===`benchmark`?a(`pipeline.clusterLoadBalancingTab.suggestFromBenchmark`,`Suggest from benchmark`):a(`pipeline.clusterLoadBalancingTab.suggestFromHardware`,`Suggest from hardware`)]}),e(J,{variant:`ghost`,size:`sm`,onClick:r,children:[i(oe,{className:`h-3.5 w-3.5`}),a(`pipeline.clusterLoadBalancingTab.autoTune`,`Auto tune`)]}),e(J,{variant:`outline`,size:`sm`,onClick:()=>x.mutate(void 0),disabled:x.isPending,title:a(`pipeline.clusterLoadBalancingTab.moveStandingAlwaysOnCameras`,`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:[i(ie,{className:`h-3.5 w-3.5`}),x.isPending?a(`pipeline.clusterLoadBalancingTab.rebalancing`,`Rebalancing…`):a(`pipeline.clusterLoadBalancingTab.rebalance`,`Rebalance`)]})]}),children:e(`div`,{className:`${m} space-y-3`,children:[R!==void 0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:R}),h&&e(`p`,{className:`text-[10px] text-foreground-subtle`,children:[a(`pipeline.clusterLoadBalancingTab.policy`,`Policy:`),` `,i(q,{variant:h.policy===`share`?`info`:`default`,children:h.policy===`share`?a(`pipeline.clusterLoadBalancingTab.honourShares`,`honour shares`):`least-loaded`}),` `,` · ${a(`pipeline.clusterLoadBalancingTab.clusterPeak`,{count:h.clusterPeakSessions})}`,h.policy===`least-loaded`&&` · ${a(`pipeline.clusterLoadBalancingTab.leastLoadedNote`)}`]}),i(Va,{nodes:M.nodes,pending:v.isPending,readOnly:M.readOnly,onCommitWeights:e=>v.mutate(Oa(e)),weightLabel:`Node share`,...M.readOnly?{footnote:g?.autoPending?i(d,{children:a(`pipeline.clusterLoadBalancingTab.automaticSharesAreBeingComputed`,`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`)}):e(d,{children:[w===`benchmark`?a(`pipeline.clusterLoadBalancingTab.benchmarkEachNodeSShare`,`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`):a(`pipeline.clusterLoadBalancingTab.hardwareEachNodeSShare`,`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`),a(`pipeline.clusterLoadBalancingTab.recomputedWheneverANodeOr`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`),g?.computedAt!=null&&i(`span`,{className:`ml-1`,children:a(g.trigger===null?`pipeline.clusterLoadBalancingTab.lastAt`:`pipeline.clusterLoadBalancingTab.lastAtTrigger`,{time:new Date(g.computedAt).toLocaleTimeString(),trigger:g.trigger??``})}),`.`]})}:{}}),I!==null&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:I}),L!==null&&i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:L}),y.isError&&i(Ye,{message:a(`pipeline.clusterLoadBalancingTab.switchFailed`,{message:y.error instanceof Error?y.error.message:a(`common.unknownError`)})}),v.isError&&i(Ye,{message:a(`pipeline.clusterLoadBalancingTab.saveFailed`,{message:v.error instanceof Error?v.error.message:a(`common.unknownError`)})}),e(`details`,{className:`rounded-md border border-border`,children:[i(`summary`,{className:`${T} cursor-pointer text-xs text-foreground`,children:a(`pipeline.clusterLoadBalancingTab.maxConcurrentSessionsAdvanced`,`Max concurrent sessions (advanced)`)}),i(`ul`,{className:`divide-y divide-border border-t border-border`,children:k.map(t=>e(`li`,{className:`${T} flex items-center gap-2`,children:[i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:t.name}),i(bn,{type:`number`,min:1,placeholder:`∞`,defaultValue:t.maxCameras??``,"aria-label":a(`pipeline.clusterLoadBalancingTab.maxConcurrentSessionsFor`,`Max concurrent sessions for {{name}}`,{name:t.name}),className:`w-20 text-right`,disabled:b.isPending,onBlur:e=>{let n=e.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==t.maxCameras&&b.mutate({agentNodeId:t.id,maxCameras:i})}})]},t.id))}),i(`p`,{className:`${T} ${W} border-t border-border`,children:a(`pipeline.clusterLoadBalancingTab.aHardCapOnThe`,`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.`)})]})]})}),D.isError&&i(Ye,{message:a(`pipeline.clusterLoadBalancingTab.suggestionFailed`,{message:D.error instanceof Error?D.error.message:a(`common.unknownError`)})}),O&&i(so,{suggestion:O,nameOf:A,pending:v.isPending,...ne?{}:{onApply:()=>v.mutate(ka(O))}}),i(G,{headingId:`load-balancing-accelerators`,title:a(`pipeline.clusterLoadBalancingTab.accelerators`,`Accelerators`),icon:z,children:i(`div`,{className:`${m} space-y-2`,children:k.length===0?i(rn,{title:a(`pipeline.clusterLoadBalancingTab.noDetectCapableNodes`,`No detect-capable nodes`),description:a(`pipeline.clusterLoadBalancingTab.enableDetectionOnANode`,`Enable detection on a node in Roles & nodes to configure its accelerators.`)}):k.map(e=>i(Ya,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...te?.[e.id]===void 0?{}:{suggestedMaxSessions:te[e.id]},sharesAutomatic:N,...g===void 0?{}:{shareSource:g.source},...P(e.id)===void 0?{}:{share:P(e.id)},...F(e.id)===void 0?{}:{placed:F(e.id)}},e.id))})}),h!==void 0&&h.stalePins.length>0&&i(co,{stats:h,cameraName:j})]})}function so({suggestion:t,nameOf:n,pending:r,onApply:a}){let{t:o}=X();return e(G,{headingId:`load-balancing-suggestion`,title:t.source===`benchmark`?o(`pipeline.clusterLoadBalancingTab.suggestedFromBenchmark`,`Suggested from benchmark`):o(`pipeline.clusterLoadBalancingTab.suggestedFromHardware`,`Suggested from hardware`),icon:ee,...a===void 0?{}:{actions:i(J,{size:`sm`,onClick:a,disabled:r,children:o(`pipeline.clusterLoadBalancingTab.applySuggestedShares`,`Apply suggested shares`)})},children:[i(`ul`,{className:`divide-y divide-border`,children:t.nodes.map(t=>e(`li`,{className:`${T} space-y-0.5`,children:[e(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[i(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:n(t.nodeId)}),i(`span`,{className:`tabular-nums text-foreground`,children:t.share===null?o(`common.skipped`):`${t.share}%`})]}),e(`p`,{className:W,children:[Fa(t.capacityFallback)===null?``:`${Fa(t.capacityFallback)} · `,t.skippedReason===null?o(`pipeline.clusterLoadBalancingTab.parallelSessions`,`≈ {{capacitySessions}} parallel sessions · {{value2}}`,{capacitySessions:t.capacitySessions,value2:t.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}):o(`pipeline.clusterLoadBalancingTab.notPartOfTheSuggestion`,`not part of the suggestion — {{skippedReason}}`,{skippedReason:t.skippedReason})]})]},t.nodeId))}),e(`p`,{className:`${T} ${W} border-t border-border`,children:[o(`pipeline.clusterLoadBalancingTab.sharesIntro`,{fps:t.cameraFps,headroom:Math.round(t.headroom*100),basis:t.source===`benchmark`?o(`pipeline.clusterLoadBalancingTab.measuredByNodeBenchmarksOr`,`measured by node benchmarks, or from the hardware table where a node has no results`):o(`pipeline.clusterLoadBalancingTab.atTheModelsAutoTune`,`at the models Auto tune picks (at least {{minSessionsPerDevice}} per accelerator), from the measured speed of each node's hardware`,{minSessionsPerDevice:t.minSessionsPerDevice})}),` `,a===void 0?o(`pipeline.clusterLoadBalancingTab.automaticSharesAlreadyFollowThis`,`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`):o(`pipeline.clusterLoadBalancingTab.applyingWritesTheNodeAnd`,`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`)]})]})}function co({stats:t,cameraName:n}){let{t:r}=X(),a=l(),o=_n({onSuccess:()=>{a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return i(G,{headingId:`load-balancing-stale-pins`,title:r(`pipeline.clusterLoadBalancingTab.staleDevicePins`,`Stale device pins`),icon:Pe,children:i(`ul`,{className:`divide-y divide-border`,children:t.stalePins.map(t=>e(`li`,{className:`${T} flex items-center gap-2`,children:[e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs text-foreground`,title:n(t.deviceId),children:n(t.deviceId)}),i(`p`,{className:W,children:ja(t)})]}),i(J,{variant:`outline`,size:`sm`,disabled:o.isPending,onClick:()=>o.mutate({deviceId:t.deviceId,deviceKey:`auto`}),children:r(`pipeline.clusterLoadBalancingTab.clearPin`,`Clear pin`)})]},t.deviceId))})})}function lo({node:t,emphasis:n=!1}){let{t:r}=X(),a=t.isHub?C:z;return e(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[i(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${t.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),i(a,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),e(`div`,{className:`min-w-0`,children:[e(`div`,{className:`flex items-center gap-1.5 ${n?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[i(`span`,{className:`truncate`,children:t.name}),t.isHub&&i(q,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:r(`common.hubWord`)}),!t.isOnline&&i(q,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:r(`common.offline`)})]}),i(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:t.id})]})]})}function uo({nodes:e,actions:t}){let{t:n}=X();return i(wn,{columns:[{key:`node`,header:n(`placementBoard.nodeCapabilitiesTable.node`,`Node`),sortValue:e=>e.name,render:e=>i(lo,{node:e})},...ir.map(e=>({key:e.key,header:n(e.labelKey),align:`center`,notSortableReason:`A switch — sorting would move the row while it is being changed.`,render:r=>i(ln,{"aria-label":n(`placementBoard.nodeCapabilitiesTable.on`,`{{label}} on {{name}}`,{label:n(e.labelKey),name:r.name}),title:n(e.hintKey),checked:Xn(r.effective,e.key),disabled:t.capabilityPending,onCheckedChange:n=>t.onToggleCapability(r.id,e.key,n)})}))],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:n(`placementBoard.nodeCapabilitiesTable.noClusterNodesReportingYet`,`No cluster nodes reporting yet.`)})}function fo({roleValues:t,options:n,pending:r,onRoleChange:a}){let{t:o}=X(),s=n.map(e=>({value:e.id,label:e.id===`hub`?o(`placementBoard.roleControls.default`,`{{name}} (default)`,{name:e.name}):e.name}));return i(`ul`,{className:`divide-y divide-border`,children:sr.map(n=>e(`li`,{className:`${T} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[e(`div`,{className:`min-w-0 flex-1 basis-56`,children:[i(`div`,{className:`text-xs font-medium text-foreground`,children:lr(n)}),i(`p`,{className:W,children:cr(n)})]}),i(`div`,{className:`w-full sm:w-48`,children:i(I,{"aria-label":o(`placementBoard.roleControls.node`,`{{value1}} node`,{value1:lr(n)}),value:t[n],disabled:r,options:s,onChange:e=>a(n,e.target.value)})})]},n))})}s();function po(){let{t}=X(),r=l(),{nodes:a}=K(),o=ut(void 0),s=ze({addonId:$n,cap:Jn,scope:`cluster`}),c=ze({addonId:ar,cap:Yn,scope:`cluster`}),u=ze({addonId:or,cap:nr,scope:`cluster`}),d=()=>Zn(r),f=vt({onSuccess:d}),p=gn({onSuccess:d}),m=n(()=>{let e=new Map;for(let t of o.data??[])e.set(t.nodeId,t.settings);return e},[o.data]),h=n(()=>a.map(e=>{let t=m.get(e.id),n=pr(t);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[a,m]),g={ingestNode:Qn(s.data,`ingestNode`,`hub`),recordingNode:Qn(c.data,er,`hub`),audioNode:Qn(s.data,`audioNode`,`hub`),motionNode:Qn(s.data,`motionNode`,`hub`),postProcessingNode:Qn(u.data,rr,`hub`)},_=n(()=>{let e=a.filter(e=>e.isOnline).map(e=>e.id),t=e=>a.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,...sr.map(e=>g[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:t(e)}))},[a,g]),v=o.isLoading||s.isLoading||c.isLoading||u.isLoading,y=(e,t,n)=>{f.mutate({agentNodeId:e,[t]:n})},b=(e,t)=>{if(e===`recordingNode`){p.mutate({addonId:ar,cap:Yn,scope:`cluster`,patch:{[er]:t}});return}if(e===`postProcessingNode`){p.mutate({addonId:or,cap:nr,scope:`cluster`,patch:{[rr]:t}});return}p.mutate({addonId:$n,cap:Jn,scope:`cluster`,patch:{[e]:t}})},x={capabilityPending:f.isPending,onToggleCapability:y},S=v?i(ce,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":t(`pipeline.clusterRolesNodesTab.loading`,`Loading`)}):null;return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[e(G,{headingId:`roles-nodes-cluster-roles`,title:t(`pipeline.clusterRolesNodesTab.clusterRoles`,`Cluster roles`),icon:Me,actions:S,children:[i(`p`,{className:`${W} border-b border-border px-3 py-1.5 sm:px-4`,children:t(`pipeline.clusterRolesNodesTab.oneNodeHoldsEachRole`,`One node holds each role for every camera. Detection shares and caps are on Load balancing.`)}),i(fo,{roleValues:g,options:_,pending:p.isPending,onRoleChange:b})]}),i(G,{headingId:`roles-nodes-node-capabilities`,title:t(`pipeline.clusterRolesNodesTab.nodeCapabilities`,`Node capabilities`),icon:C,children:i(uo,{nodes:h,actions:x})})]})}s();var mo=2500,ho={faces:g,"semantic-search":oe,"detail-crop":Ie,"native-lease":Le,streaming:O,recorder:L,"runner-defaults":z,"load-balancer":Ne,failover:x},go=[`cluster`,yi];function _o(e){a(()=>{if(e===null)return;let t=xi[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`),mo),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function vo({section:t}){let{t:n}=X();return i(`div`,{"data-cluster-settings-card":t.id,className:`rounded-lg`,children:i(G,{headingId:`cluster-settings-${t.id}`,title:t.title,...ho[t.id]===void 0?{}:{icon:ho[t.id]},children:e(`div`,{className:`${m} space-y-3`,children:[i(`p`,{className:W,children:t.hint}),t.panels.map(e=>i(kn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:go.filter(t=>!(e.sectionIds??[]).includes(t)),emptyMessage:n(`pipeline.clusterSettingsTab.notAvailableTheAddonThat`,`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.omitFieldKeys===void 0?{}:{omitFieldKeys:e.omitFieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}:${(e.sectionIds??e.fieldKeys??[]).join(`,`)}`))]})})})}function yo({refreshToken:e}){let[t]=Dn();return _o(t.get(wi)),i(`div`,{className:`space-y-3 sm:space-y-4`,children:bi.map(e=>i(vo,{section:e},e.id))})}function bo(e){return e?.hex}function xo({hex:e}){return i(`span`,{className:`inline-block h-3 w-3 shrink-0 rounded-sm border border-border`,style:{backgroundColor:e}})}function So({id:t,label:n,swatch:r}){let a=bo(r);return a===void 0?null:e(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 text-xs`,"data-testid":`palette-entry-${t}`,children:[r?.form===`gradient`?i(`span`,{className:`flex h-4 overflow-hidden rounded-sm`,children:fe.map(e=>i(`span`,{className:`h-4 w-2`,style:{backgroundColor:a,opacity:e}},e))}):i(`span`,{className:`h-4 w-3 shrink-0 rounded-sm`,style:{backgroundColor:a}}),i(`span`,{children:n}),i(`span`,{className:`font-mono text-[11px] opacity-80`,children:a})]})}function Co({ground:t,group:n,swatches:r}){let{t:a}=X();return e(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[i(So,{id:n.id,label:n.label,swatch:r[n.id]}),n.children.length>0&&e(`details`,{"data-testid":`palette-subs-${t}-${n.id}`,children:[i(`summary`,{className:`cursor-pointer text-[11px] opacity-80`,children:a(`pipeline.palette.subclasses`,`Subclasses`)}),i(`div`,{className:`mt-1 flex flex-col gap-1 pl-4`,children:n.children.map(e=>i(So,{id:e.id,label:e.label,swatch:r[e.id]},e.id))})]})]})}function wo({swatches:t}){let{t:n}=X(),r=le(),a=[{id:`dark`,background:pe.dark,ink:pe.light},{id:`light`,background:pe.light,ink:pe.dark}];return e(`div`,{className:`flex flex-col gap-2`,"data-testid":`palette-preview`,children:[i(`div`,{className:`text-[11px] text-foreground-subtle`,children:n(`pipeline.palette.preview`,`Timeline marks`)}),a.map(e=>i(`div`,{className:`grid grid-cols-1 gap-x-4 gap-y-2 rounded-md border border-border p-2 sm:grid-cols-2`,"data-testid":`palette-ground-${e.id}`,style:{backgroundColor:e.background,color:e.ink},children:r.map(n=>i(Co,{ground:e.id,group:n,swatches:t},n.id))},e.id))]})}function To(e){for(let t of le()){if(t.id===e)return t.label;let n=t.children.find(t=>t.id===e);if(n!==void 0)return n.label}return e}s();function Eo(e){return/^#[0-9a-f]{6}$/.test(e)}function Do(e,t){let n={};for(let r of me){let i=t[r],a=e[r];i===void 0||a===void 0||i.hex!==a.hex&&(n[r]=i)}return n}function Oo({status:t,reason:r,source:a,presetId:s,customized:c,swatches:l,presets:u,saving:d,onApply:f}){let{t:p}=X(),[m,h]=o(c===!0),[g,_]=o(s??u[0]?.id??`camstack`),[v,y]=o(l??u[0]?.swatches??{}),b=u.find(e=>e.id===g)??u[0],x=n(()=>b===void 0?null:ue(v,b.fallbacks),[b,v]);if(t===`pending`)return i(`p`,{className:`text-xs text-foreground-subtle`,role:`status`,children:p(`pipeline.palette.pending`,`Reading the cluster palette…`)});let S=e=>{let t=u.find(t=>t.id===e);t!==void 0&&(h(!1),_(e),y(t.swatches),f({presetId:e}))},C=()=>{b!==void 0&&(h(!0),y(b.swatches))},w=(e,t)=>{if(typeof t!=`string`)return;let n=t.trim().toLowerCase();if(!Eo(n))return;let r=v[e],i=r?.form===`gradient`?{...r,hex:n}:{form:`solid`,hex:n};y({...v,[e]:i})};return e(`div`,{className:`flex flex-col gap-4`,children:[t===`unknown`&&i(`p`,{className:`text-xs text-warning`,role:`status`,"data-testid":`palette-unknown`,children:p(`pipeline.palette.unknown`,`The stored palette cannot be read ({{reason}}). Boxes use the bundled CamStack preset.`,{reason:r??``})}),t===`ready`&&a===`unconfigured`&&i(`p`,{className:`text-xs text-foreground-subtle`,children:p(`pipeline.palette.sourceUnconfigured`,`CamStack preset (cluster default)`)}),i(G,{headingId:`palette-presets`,title:p(`pipeline.palette.presets`,`Presets`),children:e(`div`,{className:`flex flex-wrap gap-2 p-3`,children:[u.map(t=>i(J,{type:`button`,size:`sm`,variant:!m&&t.id===g?`primary`:`outline`,onClick:()=>S(t.id),disabled:d,children:e(`span`,{className:`inline-flex items-center gap-1`,children:[[`person`,`vehicle`,`animal`].map(e=>{let n=bo(t.swatches[e]);return n===void 0?null:i(xo,{hex:n},e)}),t.name]})},t.id)),i(J,{type:`button`,size:`sm`,variant:m?`primary`:`outline`,onClick:C,disabled:d||b===void 0,children:p(`pipeline.palette.custom`,`Custom`)})]})}),i(wo,{swatches:v}),x!==null&&x.ok&&i(`p`,{className:`text-xs text-success`,"data-testid":`palette-verdict`,children:p(`pipeline.palette.valid`,`Every colour is distinct on both themes.`)}),x!==null&&!x.ok&&i(`p`,{className:`text-xs text-danger`,"data-testid":`palette-verdict`,children:p(`pipeline.palette.invalid`,`This palette is refused: {{reason}}`,{reason:de(x.violations)})}),m&&b!==void 0&&i(G,{headingId:`palette-custom`,title:p(`pipeline.palette.custom`,`Custom`),children:e(`div`,{className:`flex flex-col gap-2 p-3`,children:[me.map(e=>{let t=bo(v[e]);return t===void 0?null:i(pt,{field:{type:`color`,key:e,label:To(e)},values:{[e]:t},onChange:(t,n)=>w(e,n)},e)}),i(J,{type:`button`,size:`sm`,onClick:()=>{if(b===void 0||x===null||!x.ok)return;let e=Do(b.swatches,v);f(Object.keys(e).length>0?{presetId:b.id,overrides:e}:{presetId:b.id})},disabled:d||x===null||!x.ok,children:p(`pipeline.palette.save`,`Save custom palette`)})]})})]})}function ko(){let e=ft({}),t=gt({}),n=$e(),r=r=>{n.mutate(r,{onSuccess:()=>{e.refetch(),t.refetch()}})};if(e.isPending||t.isPending)return i(Oo,{status:`pending`,presets:[],onApply:r});if(e.isError||e.data===void 0)return i(Oo,{status:`unknown`,reason:e.isError?String(e.error):`no palette`,presets:t.data??[],saving:n.isPending,onApply:r});if(t.isError||t.data===void 0)return i(Oo,{status:`unknown`,reason:String(t.error),presets:[],saving:n.isPending,onApply:r});if(e.data.status===`unknown`)return i(Oo,{status:`unknown`,reason:e.data.reason,presets:t.data,saving:n.isPending,onApply:r});let a=e.data;return i(Oo,{status:`ready`,source:a.source,presetId:a.presetId,customized:a.customized,swatches:a.swatches,presets:t.data,saving:n.isPending,onApply:r},`${a.presetId}:${String(a.customized)}`)}var Ao=`pipeline-orchestrator`,jo=200;function Mo(){let{t}=X();return e(`div`,{className:`flex flex-col gap-3`,children:[e(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:t(`pipeline.clusterOrchestratorLogsTab.orchestratorLogs`,`Orchestrator logs`)}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`pipeline.clusterOrchestratorLogsTab.dispatchDecisionsBalancerMovesAnd`,`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.`)})]}),i(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:i(sn,{addonId:Ao,limit:jo,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1,showSourceSelect:!0})})]})}var No=[{id:`assignments`,labelKey:`pipeline.clusterDetail.tabAssignments`},{id:`load-balancing`,labelKey:`pipeline.clusterDetail.tabLoadBalancing`},{id:`auto-tune`,labelKey:`pipeline.clusterDetail.tabAutoTune`},{id:`roles-nodes`,labelKey:`pipeline.clusterDetail.tabRoles`},{id:`settings`,labelKey:`common.settings`},{id:`logs`,labelKey:`common.logs`},{id:`palette`,labelKey:`pipeline.clusterDetail.tabPalette`}];function Po(e){return No.some(t=>t.id===e)}function Fo({refreshToken:t}){let{t:n}=X(),[r,a]=Dn(),o=r.get(Ci),s=Po(o)?o:`assignments`,c=e=>{a(t=>{let n=new URLSearchParams(t);return n.set(Ci,e),n.delete(wi),n},{replace:!0})};return e(`div`,{className:`flex flex-col h-full`,children:[e(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[i(`h2`,{className:`text-base font-semibold text-foreground`,children:n(`pipeline.clusterDetail.clusterOrchestration`,`Cluster Orchestration`)}),i(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:n(`pipeline.clusterDetail.cameraAssignmentsLoadBalancingThe`,`Camera assignments, load balancing, the detector recommendation, cluster roles, settings and the display palette.`)})]}),i(Ht,{value:s,onValueChange:e=>{Po(e)&&c(e)},className:`px-4 sm:px-6`,children:i(mn,{className:`border-border`,children:No.map(e=>i(Kt,{value:e.id,className:`h-auto py-2 border-b-2`,children:n(e.labelKey)},e.id))})}),e(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[s===`assignments`&&i(Xi,{}),s===`load-balancing`&&i(oo,{refreshToken:t,onOpenAutoTune:()=>c(`auto-tune`)}),s===`auto-tune`&&i(ha,{}),s===`roles-nodes`&&i(po,{}),s===`settings`&&i(yo,{refreshToken:t}),s===`logs`&&i(Mo,{}),s===`palette`&&i(ko,{})]})]})}function Q({title:t,children:n}){return e(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[i(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:t}),i(`div`,{className:`flex flex-col gap-1 min-w-0`,children:n})]})}function $({label:t,children:n,overridden:r=!1}){return e(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[i(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:t,children:t}),i(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:n}),r&&i(Io,{})]})}function Io(){let{t:e}=X();return i(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:e(`cameras.cardPrimitives.deviceLevelOverrideActive`,`Device-level override active`),"aria-label":e(`cameras.cardPrimitives.deviceLevelOverrideActive`,`Device-level override active`),role:`img`})}var Lo={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 Ro({tone:e=`neutral`,children:t,title:n}){return i(`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 ${Lo[e]}`,children:t})}function zo({children:e}){return i(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Bo({icon:t,label:n,nodeId:r,pinned:a,reason:o,overridden:s}){let{t:c}=X();return e(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[i(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),i(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:n}),r===null?i(`span`,{className:`text-foreground-subtle italic`,children:c(`cameras.configBlocks.unassigned`)}):e(d,{children:[i(`span`,{className:`font-mono text-foreground truncate`,title:r,children:r}),a?e(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:c(`cameras.configBlocks.manuallyPinned`,`Manually pinned`),children:[i(N,{className:`h-2.5 w-2.5`}),` `,c(`cameras.configBlocks.manual`)]}):i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:c(`cameras.configBlocks.autoReason`,{reason:o!==void 0&&o.length>0?o:c(`cameras.configBlocks.capacity`)})}),s&&i(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:c(`cameras.configBlocks.persistedSettingsPinForThis`,`Persisted settings pin for this role`)})]})]})}function Vo({assignment:t,settings:n,onlineNodes:r,pinPending:a,onDetectionPinChange:o}){let{t:s}=X(),c=t.pinned.detection&&t.detectionNodeId!==null?t.detectionNodeId:`auto`,l=[...new Set([...t.detectionNodeId===null?[]:[t.detectionNodeId],...r.map(e=>e.id)])];return e(Q,{title:s(`cameras.configBlocks.whereItRuns`,`Where it runs`),children:[i(Bo,{icon:z,label:s(`cameras.configBlocks.detection`,`Detection`),nodeId:t.detectionNodeId,pinned:t.pinned.detection,reason:t.reasons.detection,overridden:n.overriddenKeys.has(`pipelineNodeId`)}),i(Bo,{icon:L,label:s(`cameras.configBlocks.decoder`,`Decoder`),nodeId:t.decoderNodeId,pinned:t.pinned.decoder,reason:t.reasons.decoder,overridden:n.overriddenKeys.has(`decoderNodeId`)}),i(Bo,{icon:h,label:s(`cameras.configBlocks.audio`,`Audio`),nodeId:t.audioNodeId,pinned:t.pinned.audio,reason:t.reasons.audio,overridden:n.overriddenKeys.has(`audioNodeId`)}),i(Bo,{icon:O,label:s(`cameras.configBlocks.source`,`Source`),nodeId:t.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),i(`div`,{className:`mt-1.5`,children:e(I,{value:c,disabled:a,"aria-label":s(`cameras.configBlocks.detectionPlacementPin`,`Detection placement pin`),onChange:e=>o(e.target.value),className:`w-full min-w-0`,children:[i(`option`,{value:`auto`,children:s(`cameras.configBlocks.autoLoadBalanced`,`Auto (load balanced)`)}),l.map(e=>i(`option`,{value:e,children:s(`cameras.configBlocks.pinDetection`,{node:r.find(t=>t.id===e)?.name??e})},e))]})})]})}function Ho(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Uo(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function Wo(e){return e===null?Y.t(`pipeline.configBlocks.fpsDefault`):e===0?Y.t(`pipeline.configBlocks.fpsNative`):`${e} fps`}function Go({streams:t,brokerProfiles:n,settings:r,motionEnabled:a,motionFpsLive:o,cameraSensors:s}){let{t:c}=X(),l=Uo(n,r.detectionStreamProfile),u=Uo(n,r.motionStreamProfile),f=r.motionSources.includes(`analyzer`);return e(Q,{title:c(`cameras.configBlocks.streamsMotion`,`Streams & motion`),children:[e($,{label:c(`cameras.configBlocks.detectStream`,`Detect stream`),overridden:r.overriddenKeys.has(`detectionStreamProfile`),children:[r.detectionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),i($,{label:c(`cameras.configBlocks.detectFps`,`Detect FPS`),overridden:r.overriddenKeys.has(`detectionFps`),children:Wo(r.detectionFps)}),e($,{label:c(`cameras.configBlocks.motionSrc`,`Motion src`),overridden:r.overriddenKeys.has(`motionSources`),children:[r.motionSources.length>0?r.motionSources.map(ve).join(` + `):c(`cameras.configBlocks.none`),a===!1&&` · ${c(`cameras.configBlocks.inactive`)}`]}),i($,{label:c(`cameras.configBlocks.cameraSensors`,`Camera sensors`),children:In(s)}),f&&e(d,{children:[e($,{label:c(`cameras.configBlocks.motionStream`,`Motion stream`),overridden:r.overriddenKeys.has(`motionStreamProfile`),children:[r.motionStreamProfile??`—`,u!==void 0&&` · ${u.width}×${u.height} ${u.codec}`]}),e($,{label:c(`cameras.configBlocks.motionFps`,`Motion FPS`),overridden:r.overriddenKeys.has(`motionFps`),children:[Wo(r.motionFps),o!==null&&` · ${c(`cameras.configBlocks.liveFps`,{fps:o.toFixed(1)})}`]})]}),i($,{label:c(`cameras.configBlocks.cooldown`,`Cooldown`),overridden:r.overriddenKeys.has(`motionCooldownMs`),children:r.motionCooldownMs===null?c(`cameras.configBlocks.defaultValue`):`${r.motionCooldownMs/1e3}s`}),i(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:t.length===0?i(zo,{children:c(`cameras.configBlocks.noStreamsRegistered`,`No streams registered`)}):t.map(t=>e(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:t.camStreamId,children:[i(`span`,{className:`text-foreground-muted`,children:t.kind}),` `,Ho(t)]},t.camStreamId))})]})}function Ko({steps:t,audioModelId:n,audioEnabled:r,audioMode:a}){let{t:o}=X();return e(Q,{title:o(`cameras.configBlocks.pipelineSteps`,`Pipeline steps`),children:[t===void 0?i(zo,{children:o(`cameras.configBlocks.resolving`,`Resolving…`)}):t.length===0?i(zo,{children:o(`cameras.configBlocks.noStepsConfigured`,`No steps configured`)}):i(`div`,{className:`flex flex-wrap gap-1`,children:t.map((t,n)=>i(Ro,{tone:t.enabled&&t.depth===0?`info`:`neutral`,title:t.modelId??t.addonId,children:e(`span`,{className:t.enabled?``:`line-through opacity-60`,children:[t.depth>0&&i(`span`,{className:`opacity-50`,children:`↳ `}),t.addonId,t.modelId!==null&&e(`span`,{className:`font-mono opacity-75`,children:[` · `,t.modelId]})]})},`${t.addonId}-${n}`))}),i(`div`,{className:`mt-1`,children:e($,{label:o(`cameras.configBlocks.audioClass`,`Audio class.`),children:[a??`—`,r!==null&&` · ${o(r?`cameras.configBlocks.running`:`cameras.configBlocks.off`)}`,n!==null&&` · ${n}`]})})]})}var qo={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Jo({detection:t,live:n,detectionMode:r,modeOverridden:a}){let o=H(),{t:s}=X();if(t===null)return e(Q,{title:s(`cameras.runtimeBlocks.detectionRuntime`,`Detection runtime`),children:[i($,{label:s(`cameras.runtimeBlocks.mode`,`Mode`),overridden:a,children:r??`—`}),i(zo,{children:s(`cameras.runtimeBlocks.detectionStageInactiveOrUnreachable`,`Detection stage inactive or unreachable`)})]});let c=n?.phase??t.phase,l=n?.actualFps??t.actualFps,u=n?.configuredFps??t.configuredFps,d=n?.avgInferenceTimeMs??t.avgInferenceMs,f=n?.queueDepth??t.queueDepth,p=xn(c,o),m=c===`active`&&l===0;return e(Q,{title:s(`cameras.runtimeBlocks.detectionRuntime`,`Detection runtime`),children:[e(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[e(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${p.badgeClass}`,children:[i(Yt,{phase:c,className:`h-2.5 w-2.5`}),p.label]}),n!==void 0&&i(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:s(`common.live`)})]}),i($,{label:s(`cameras.runtimeBlocks.mode`,`Mode`),overridden:a,children:r??`—`}),e($,{label:`FPS`,children:[i(`span`,{className:m?`text-danger font-semibold`:``,children:l.toFixed(1)}),i(`span`,{className:`ml-1 text-foreground-subtle`,children:s(`cameras.runtimeBlocks.configuredFps`,{fps:u.toFixed(0)})})]}),e($,{label:s(`cameras.runtimeBlocks.inference`,`Inference`),children:[d.toFixed(0),` ms`,f>0&&i(`span`,{className:`ml-1 text-warning`,children:s(`cameras.runtimeBlocks.queue`,{depth:f})}),n!==void 0&&n.droppedFrames>0&&i(`span`,{className:`ml-1 text-warning`,children:s(`cameras.runtimeBlocks.drops`,{count:n.droppedFrames})})]}),e($,{label:s(`cameras.runtimeBlocks.engine`,`Engine`),children:[t.engine.backend,` · `,t.engine.device]}),e($,{label:s(`cameras.runtimeBlocks.provisioning`,`Provisioning`),children:[i(Ro,{tone:qo[t.provisioning.state]??`neutral`,children:t.provisioning.state}),t.provisioning.error!==void 0&&e(`span`,{className:`text-danger text-[10px]`,children:[` `,t.provisioning.error]})]})]})}function Yo({broker:t}){let{t:n}=X();return t===null?i(Q,{title:n(`cameras.runtimeBlocks.streamBroker`,`Stream broker`),children:i(zo,{children:n(`cameras.runtimeBlocks.brokerStageInactiveOrUnreachable`,`Broker stage inactive or unreachable`)})}):e(Q,{title:n(`cameras.runtimeBlocks.streamBroker`,`Stream broker`),children:[t.profiles.length===0?i(zo,{children:n(`cameras.runtimeBlocks.noBrokerProfiles`,`No broker profiles`)}):i(`div`,{className:`flex flex-col gap-1`,children:t.profiles.map(t=>{let r=t.status===`streaming`,a=r&&t.inFps===0;return e(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[i(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${a?`bg-danger`:r?`bg-success animate-pulse`:`bg-border`}`,title:t.status}),i(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:t.profile,children:t.profile}),e(`span`,{className:`text-foreground-subtle truncate`,children:[t.width,`×`,t.height,` `,t.codec]}),i(`span`,{className:`ml-auto shrink-0 ${a?`text-danger`:`text-foreground`}`,children:n(`cameras.runtimeBlocks.fpsValue`,{value:t.inFps===null?`—`:t.inFps.toFixed(0)})}),e(`span`,{className:`text-foreground-subtle shrink-0`,title:n(`cameras.runtimeBlocks.subscribers`,`Subscribers`),children:[`×`,t.subscribers]})]},t.profile)})}),e(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[i(Ro,{tone:t.webrtcSessions>0?`info`:`neutral`,children:n(`cameras.runtimeBlocks.webrtc`,{count:t.webrtcSessions})}),i(Ro,{tone:t.rtspRestream?`success`:`neutral`,children:t.rtspRestream?n(`cameras.runtimeBlocks.restreamOn`):n(`cameras.runtimeBlocks.restreamOff`)})]})]})}function Xo({decoder:e}){let{t}=X();return e===null?i(Q,{title:t(`cameras.runtimeBlocks.decoder`,`Decoder`),children:i(zo,{children:t(`cameras.runtimeBlocks.decoderStageInactiveOrUnreachable`,`Decoder stage inactive or unreachable`)})}):i(Q,{title:t(`cameras.runtimeBlocks.decoder`,`Decoder`),children:i($,{label:t(`cameras.runtimeBlocks.node`,`Node`),children:e.nodeId})})}s();var Zo=`pipeline-orchestrator`,Qo={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},$o={healthy:`pipeline.cameraPipelineCard.healthHealthy`,idle:`pipeline.cameraPipelineCard.healthIdle`,error:`pipeline.cameraPipelineCard.healthError`};function es({problems:t}){return i(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:t.map(t=>e(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${t.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[i(j,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),i(`span`,{className:`min-w-0`,children:t.message})]},t.code))})}function ts({deviceId:t,name:r,online:a,status:o,live:s,onlineNodes:c}){let{t:u}=X(),d=l(),{data:f}=_t({addonId:Zo,deviceId:t,nodeId:`hub`},{staleTime:3e4}),{data:p}=zt({deviceId:t},{staleTime:3e4}),m=n(()=>Kn(f),[f]),h=n(()=>p===void 0?void 0:qn(p.steps),[p]),g=n(()=>o===void 0?[]:An(o),[o]),_=()=>{d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=Qe({onSuccess:_}),y=on({onSuccess:_}),b=e=>{e===`auto`?y.mutate({deviceId:t}):v.mutate({deviceId:t,agentNodeId:e})},x=o===void 0?`idle`:Mn(o),S=g.some(e=>e.severity===`error`),C=g.length>0,w=S?`border-danger/50`:C?`border-warning/40`:`border-border`;return e(`article`,{"aria-label":u(`cameras.cameraPipelineCard.pipelineStatus`,`{{name}} pipeline status`,{name:r}),className:`rounded-lg border ${w} bg-background overflow-hidden`,children:[e(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[i(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${S?`bg-danger`:Qo[x]}`,title:S?u(`common.error`,`Error`):u($o[x]),"aria-label":S?u(`common.error`,`Error`):u($o[x]),role:`img`}),i(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:r,children:r}),e(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,t]}),!a&&i(Ro,{tone:`danger`,children:u(`common.offline`)}),e(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[m.detectionMode!==null&&i(Ro,{tone:m.detectionMode===`disabled`?`warning`:m.detectionMode===`always-on`?`info`:`neutral`,title:u(`cameras.cameraPipelineCard.objectDetectionMode`,`Object detection mode`),children:m.detectionMode===`disabled`?u(`cameras.cameraPipelineCard.detectionOff`,`detection off`):m.detectionMode}),o?.recording!=null&&(o.recording.active?e(Ro,{tone:`danger`,title:u(`cameras.cameraPipelineCard.recording`,`Recording ({{mode}})`,{mode:o.recording.mode}),children:[i(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):o.recording.mode!==`off`&&i(Ro,{tone:`neutral`,title:u(`cameras.cameraPipelineCard.recordingMode`,`Recording mode`),children:u(`pipeline.cameraPipelineCard.recMode`,{mode:o.recording.mode})}))]})]}),g.length>0&&i(es,{problems:g}),o===void 0?i(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:u(`cameras.cameraPipelineCard.noPipelineStatusYetThe`,`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`)}):e(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[i(Vo,{assignment:o.assignment,settings:m,onlineNodes:c,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),i(Jo,{detection:o.detection,live:s,detectionMode:m.detectionMode,modeOverridden:m.overriddenKeys.has(`detectionMode`)}),i(Ko,{steps:h,audioModelId:p?.audio?.modelId??null,audioEnabled:o.audio?.enabled??p?.audio?.enabled??null,audioMode:m.audioMode}),i(Go,{streams:o.source.streams,brokerProfiles:o.broker?.profiles,settings:m,motionEnabled:o.motion?.enabled??null,motionFpsLive:o.motion?.fps??null,cameraSensors:o.cameraSensors}),i(Yo,{broker:o.broker}),i(Xo,{decoder:o.decoder})]})]})}s();var ns=5e3,rs=1e4,is=5e3;function as(e){let t=l(),{data:r,isLoading:i}=Tn(),{data:s,isLoading:c}=et({},{refetchInterval:ns}),{nodes:u}=K();a(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[d,f]=o(new Map);Nt(Ce.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&f(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),a(()=>{if(d.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-rs,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},is);return()=>clearInterval(e)},[d.size]);let p=n(()=>{let e=new Map;for(let t of s??[])e.set(t.deviceId,t);return e},[s]);return{rows:n(()=>(r??[]).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)),[r,p]),liveMetrics:d,onlineNodes:n(()=>(u??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[u]),isLoading:i||c}}s();function os({refreshToken:t}){let{t:r}=X(),{rows:a,liveMetrics:o,onlineNodes:s,isLoading:c}=as(t),l=n(()=>[...a.map(e=>{let t=e.status===void 0?[]:An(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),[a]),u=n(()=>{let e=0,t=0;for(let n of l)(n.errorCount>0||n.warningCount>0)&&(t+=1),(o.get(n.row.deviceId)?.phase??n.row.status?.detection?.phase)===`active`&&(e+=1);return{total:l.length,active:e,issues:t}},[l,o]);return c&&a.length===0?i(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:r(`cameras.camerasOverview.loadingCameraPipelines`,`Loading camera pipelines…`)}):a.length===0?i(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:r(`cameras.camerasOverview.noCamerasFound`,`No cameras found`)}):i(`div`,{className:`h-full overflow-y-auto`,children:e(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[e(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[i(`span`,{children:i(En,{i18nKey:`pipeline.camerasOverview.camerasTotal`,values:{count:u.total},components:{b:i(`span`,{className:`font-semibold text-foreground`})}})}),i(`span`,{children:i(En,{i18nKey:`pipeline.camerasOverview.activelyInferring`,values:{count:u.active},components:{b:i(`span`,{className:`font-semibold text-success`})}})}),e(`span`,{children:[i(`span`,{className:`font-semibold ${u.issues>0?`text-danger`:`text-foreground`}`,children:u.issues}),` `,r(`cameras.camerasOverview.withIssues`,`with issues`)]}),i(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:r(`cameras.camerasOverview.polledEvery5SDetection`,`polled every 5 s · detection metrics live at 1 Hz`)})]}),l.map(({row:e})=>i(ts,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:o.get(e.deviceId),onlineNodes:s},e.deviceId))]})})}s();var ss=`__cluster__`;function cs(e){return e===`cameras`?`cameras`:`nodes`}function ls({viewMode:t,onNodes:n,onCameras:r}){let{t:a}=X();return e(`div`,{className:`flex items-center gap-1 rounded-lg border border-border bg-surface p-0.5`,role:`tablist`,"aria-label":a(`pipeline.pipelineView`,`Pipeline view`),children:[i(`button`,{type:`button`,role:`tab`,"aria-selected":t===`nodes`,onClick:n,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,t===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:a(`pipeline.nodes`,`Nodes`)}),i(`button`,{type:`button`,role:`tab`,"aria-selected":t===`cameras`,onClick:r,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,t===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:a(`pipeline.cameras`,`Cameras`)})]})}function us(){let{t}=X(),[n,r]=Dn(),s=cs(n.get(`view`)),c=n.get(`node`)??`__cluster__`,[l,u]=o(0),[f,p]=o(!1);return a(()=>{s===`nodes`&&!n.get(`node`)&&r(e=>{let t=new URLSearchParams(e);return t.set(`view`,`nodes`),t.set(`node`,ss),t},{replace:!0})},[s,n,r]),e(hn,{icon:ke,title:t(`pipeline.pipeline`,`Pipeline`),subtitle:t(`pipeline.detectionPlacementLoadAndPer`,`Detection placement, load and per-camera runtime across the cluster.`),actions:e(J,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>u(e=>e+1),title:t(`common.refresh`,`Refresh`),children:[i(k,{className:`h-3.5 w-3.5`}),t(`common.refresh`,`Refresh`)]}),nav:i(ls,{viewMode:s,onNodes:()=>{r({view:`nodes`,node:c},{replace:!0})},onCameras:()=>{r({view:`cameras`},{replace:!0})}}),className:`flex h-full min-h-0 flex-col overflow-hidden`,children:[s===`nodes`&&e(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(e=>!e),"aria-expanded":f,className:`flex w-full shrink-0 justify-between border-b border-border md:hidden`,children:[i(`span`,{children:t(f?`pipeline.hideNodeList`:`pipeline.showNodeList`)}),i(Oe,{className:[`h-4 w-4 transition-transform`,f?`rotate-180`:``].join(` `)})]}),i(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden md:flex-row`,children:s===`nodes`?e(d,{children:[i(`aside`,{className:[f?`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:i(hr,{selectedNodeId:c,onSelect:e=>{r({view:`nodes`,node:e},{replace:!0}),p(!1)},refreshToken:l})}),i(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:c===`__cluster__`?i(Fo,{refreshToken:l}):i(Yi,{nodeId:c,refreshToken:l})})]}):i(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:i(os,{refreshToken:l})})})]})}export{us as PipelinePage};
@@ -1,2 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o as l,t as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{$i as d,In as f,Jn as p,Nr as m,Qa as h,Yn as g,Z as _,Zi as v,ar as y,ct as b,ft as x,va as S,wn as C,xr as w,yt as T,zr as E}from"./player-overlays-D546iNTv.js";import{Vc as D}from"./client-DQzHwaNb.js";import{n as O,t as ee}from"./ruler-Buxogset.js";import{r as te}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.js-8kv6pj9W.js";import{Aa as k,Af as ne,Ar as A,Br as re,Da as j,Df as ie,Dr as ae,Fp as oe,Ip as se,Ir as M,Kp as ce,Lr as le,Nf as ue,Or as de,Pp as fe,Rr as N,Tr as pe,Zp as P,hi as me,ia as he,ka as F,kn as ge,la as I,p as _e,pp as L,xp as R,zr as ve}from"./src-C9_yKHH3.js";import{t as ye}from"./i18n-HSlX-YO0.js";import{t as z}from"./useTranslation-BJr-n0es.js";import"./mount-CVOfqhXA.js";import{b as be,bi as xe,w as Se,wi as Ce,xi as we}from"./index-BN2PojUq.js";import{t as Te}from"./AdminSectionedPage-3F0XiS4h.js";import{t as B}from"./AdminPage-Dvziohv2.js";import{t as Ee}from"./BootstrapSettingsForm-D5_YCsD2.js";c();var V=`method`,H=8;function U(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function W(e){return Array.isArray(e)?e.filter(U):[]}function G(e,t){let n=e.$ref;if(typeof n!=`string`||!n.startsWith(`#/`))return e;let r=t;for(let e of n.slice(2).split(`/`))r=U(r)?r[e]:void 0;return U(r)?r:e}function K(e){let t=e.type;return typeof t==`string`?[t]:Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function q(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function J(e,t,n){let r=G(e,t);if(n>H)return null;if(`default`in r)return r.default;if(`const`in r)return r.const;let i=r.enum;if(Array.isArray(i)&&i.length>0)return i[0];let a=[...W(r.anyOf),...W(r.oneOf)];if(a.length>0){let e=a.find(e=>!K(G(e,t)).includes(`null`))??a[0];return e===void 0?null:J(e,t,n+1)}let o=W(r.allOf);if(o.length>0)return o.reduce((e,r)=>{let i=J(r,t,n+1);return U(e)&&U(i)?{...e,...i}:i},{});switch(K(r).find(e=>e!==`null`)){case`object`:return Y(r,t,n);case`array`:return[];case`string`:return``;case`number`:case`integer`:return typeof r.minimum==`number`?r.minimum:0;case`boolean`:return!1;default:return U(r.properties)?Y(r,t,n):null}}function Y(e,t,n){let r=U(e.properties)?e.properties:{},i={};for(let a of q(e)){let e=r[a];i[a]=U(e)?J(e,t,n+1):null}return i}function De(e){if(e!==null)return J(e,e,0)}function Oe(e){return e===null?`null`:Array.isArray(e)?`array`:typeof e==`number`?Number.isInteger(e)?`integer`:`number`:typeof e}function ke(e,t){let n=Oe(e);return n===t||t===`number`&&n===`integer`}function X(e,t){return e===``?String(t):`${e}.${t}`}function Z(e,t,n,r,i){let a=G(t,n);if(i>H*2)return[];let o=[...W(a.anyOf),...W(a.oneOf)];if(o.length>0&&!o.some(t=>Z(e,t,n,r,i+1).length===0))return[{path:r,code:`no-branch`,expected:`${o.length}`}];let s=[];for(let t of W(a.allOf))s.push(...Z(e,t,n,r,i+1));let c=K(a);if(c.length>0&&!c.some(t=>ke(e,t)))return[...s,{path:r,code:`type`,expected:c.join(` | `)}];`const`in a&&JSON.stringify(a.const)!==JSON.stringify(e)&&s.push({path:r,code:`const`,expected:JSON.stringify(a.const)});let l=a.enum;if(Array.isArray(l)){let t=l.map(e=>JSON.stringify(e));t.includes(JSON.stringify(e))||s.push({path:r,code:`enum`,expected:t.join(`, `)})}if(typeof e==`number`&&s.push(...Ae(e,a,r)),typeof e==`string`&&s.push(...je(e,a,r)),Array.isArray(e)&&U(a.items)){let t=a.items;e.forEach((e,a)=>s.push(...Z(e,t,n,X(r,a),i+1)))}return U(e)&&s.push(...Me(e,a,n,r,i)),s}function Ae(e,t,n){let r=[],i=t.minimum,a=t.maximum;return typeof i==`number`&&e<i&&r.push({path:n,code:`minimum`,expected:`${i}`}),typeof a==`number`&&e>a&&r.push({path:n,code:`maximum`,expected:`${a}`}),r}function je(e,t,n){let r=[],i=t.minLength,a=t.maxLength;return typeof i==`number`&&e.length<i&&r.push({path:n,code:`min-length`,expected:`${i}`}),typeof a==`number`&&e.length>a&&r.push({path:n,code:`max-length`,expected:`${a}`}),r}function Me(e,t,n,r,i){let a=[],o=U(t.properties)?t.properties:{};for(let n of q(t))n in e||a.push({path:X(r,n),code:`required`,expected:n});for(let[s,c]of Object.entries(e)){let e=o[s];U(e)?a.push(...Z(c,e,n,X(r,s),i+1)):t.additionalProperties===!1&&a.push({path:X(r,s),code:`unknown-field`,expected:s})}return a}function Ne(e,t){return t===null?[]:Z(e,t,t,``,0)}function Pe(e){if(e.trim()===``)return{ok:!0,value:void 0};try{return{ok:!0,value:JSON.parse(e)}}catch(e){return{ok:!1,message:e instanceof Error?e.message:String(e)}}}function Q(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function Fe(e){let t=`${e.hubBase}/trpc/${e.path}`,n=`-H "Authorization: Bearer $CAMSTACK_TOKEN"`,r=e.input===void 0?null:JSON.stringify({json:e.input});if(e.kind===`mutation`){let e=r??JSON.stringify({json:null});return[`curl -sS -X POST ${n} \\`,` -H 'Content-Type: application/json' \\`,` --data ${Q(e)} \\`,` ${Q(t)}`].join(`
2
- `)}return`curl -sS ${n} \\\n ${Q(`${t}${r===null?``:`?input=${encodeURIComponent(r)}`}`)}`}function $(e,t){let n=e[t];return typeof n==`string`?n:null}function Ie(e){let t=e instanceof Error?e.message:String(e),n=U(e)||e instanceof Error?Reflect.get(e,`data`):void 0;if(!U(n))return{message:t,code:null,httpStatus:null,path:null,capRouteReason:null};let r=n.httpStatus;return{message:t,code:$(n,`code`),httpStatus:typeof r==`number`?r:null,path:$(n,`path`),capRouteReason:$(n,`capRouteReason`)}}function Le(e){if(e===void 0)return`undefined`;try{return JSON.stringify(e,null,2)??String(e)}catch{return String(e)}}var Re={searchText:e=>[e.path,e.scope?.capName??``],facetGroups:[{id:`router`,value:e=>e.router},{id:`kind`,value:e=>e.kind},{id:`tier`,value:e=>e.tier},{id:`source`,value:e=>e.source}]},ze={query:`info`,mutation:`warning`,subscription:`neutral`},Be={public:`success`,protected:`neutral`,admin:`primary`};function Ve({kind:e}){let{t}=z();return i(F,{variant:ze[e],size:`sm`,children:t(`system.apiExplorer.kind.${e}`)})}function He({tier:e}){let{t}=z();return i(F,{variant:Be[e],style:`outline`,size:`sm`,children:t(`system.apiExplorer.tier.${e}`)})}function Ue({methods:t,selectedPath:n,onSelect:r}){let{t:a}=z(),o=pe(t,Re),s=e=>a(`system.apiExplorer.group.${e}`),c=e=>t=>e===`router`?t:a(`system.apiExplorer.${e}.${t}`),l=[{key:`path`,header:a(`system.apiExplorer.column.method`),sortValue:e=>e.path,render:t=>e(`span`,{className:`font-mono text-xs`,children:[e(`span`,{className:`text-foreground-muted`,children:[t.router,`.`]}),i(`span`,{className:`text-foreground`,children:t.method})]})},{key:`kind`,header:a(`system.apiExplorer.column.kind`),sortValue:e=>e.kind,render:e=>i(Ve,{kind:e.kind})},{key:`tier`,header:a(`system.apiExplorer.column.tier`),sortValue:e=>e.tier,render:e=>i(He,{tier:e.tier})},{key:`scope`,header:a(`system.apiExplorer.column.scope`),sortValue:e=>e.scope===null?null:`${e.scope.capName}:${e.scope.access}`,render:t=>t.scope===null?i(`span`,{className:`text-xs text-foreground-subtle`,children:a(`system.apiExplorer.coreRoute`)}):e(`span`,{className:`font-mono text-xs text-foreground-muted`,children:[t.scope.capName,` · `,t.scope.access]})}];return e(`div`,{className:`space-y-3`,children:[i(ae,{state:o.state,facets:o.facets,groups:o.groups.map(e=>({...e,label:s(e.id),facetLabel:c(e.id),...e.id===`router`?{display:`menu`}:{}})),labels:{searchPlaceholder:a(`system.apiExplorer.searchPlaceholder`),searchLabel:a(`system.apiExplorer.searchLabel`),facetsLabel:a(`system.apiExplorer.facetsLabel`),clearLabel:a(`system.apiExplorer.clearFilters`)},onSearch:o.setSearch,onToggleFacet:o.toggleFacet,onToggleGroupFacet:o.toggleGroupFacet,onClear:o.clear}),i(ve,{columns:l,rows:o.rows,rowKey:e=>e.path,onRowClick:e=>r(e.path),rowClassName:e=>e.path===n?`bg-primary/10`:void 0,minWidthPx:560,maxBodyHeight:re,defaultSort:{columnKey:`path`,dir:`asc`},emptyMessage:o.active?a(`system.apiExplorer.noMatch`):a(`system.apiExplorer.noMethods`)})]})}var We={yes:`success`,"per-device":`warning`,no:`danger`},Ge={yes:`system.apiExplorer.callableYes`,"per-device":`system.apiExplorer.callablePerDevice`,no:`system.apiExplorer.callableNo`};function Ke(e){let t=De(e);return t===void 0?``:JSON.stringify(t,null,2)}function qe({method:t}){let{t:r}=z(),s=b(),c=te(P.useUtils().client),l=P.apiCatalog.inputSchema.useQuery({path:t.path},{enabled:t.hasInput,staleTime:1/0}),u=l.data?.schema??null,[d,f]=o(``),[m,h]=o(null),[g,v]=o(!1);a(()=>{f(Ke(u))},[u]);let x=n(()=>Pe(d),[d]),C=x.ok?Ne(x.value,u):[],w=t.kind!==`subscription`&&t.callable!==`no`,T=w&&x.ok&&C.length===0&&!g,E=t.kind===`mutation`?`mutation`:`query`,D=Fe({hubBase:_(),path:t.path,kind:E,input:x.ok?x.value:void 0}),O=async()=>{if(!x.ok||t.kind===`mutation`&&!await s({title:r(`system.apiExplorer.confirmTitle`),message:r(`system.apiExplorer.confirmMessage`,{method:t.path}),confirmLabel:r(`system.apiExplorer.run`),variant:`danger`}))return;v(!0);let e=performance.now();try{h({kind:`ok`,value:E===`mutation`?await c.mutation(t.path,x.value):await c.query(t.path,x.value),ms:performance.now()-e})}catch(t){h({kind:`error`,error:Ie(t),ms:performance.now()-e})}finally{v(!1)}};return i(M,{headingId:`api-explorer-method`,title:r(`system.apiExplorer.column.method`),icon:S,actions:e(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[i(Ve,{kind:t.kind}),i(He,{tier:t.tier})]}),children:e(`div`,{className:`space-y-4 p-3 sm:p-4`,children:[i(`p`,{className:`break-all font-mono text-sm text-foreground`,children:t.path}),i(le,{items:[{key:r(`system.apiExplorer.column.scope`),value:t.scope===null?r(`system.apiExplorer.coreRouteLong`):r(`system.apiExplorer.scopeValue`,{cap:t.scope.capName,access:t.scope.access,capScope:t.scope.capScope})},{key:r(`system.apiExplorer.callable`),value:i(F,{variant:We[t.callable],size:`sm`,children:r(Ge[t.callable])})}]}),t.kind===`subscription`&&i(`p`,{className:`text-sm text-foreground-muted`,children:r(`system.apiExplorer.subscriptionNote`)}),t.hasInput&&i(Je,{loading:l.isPending,error:l.error?.message??l.data?.error??null,schema:u}),w&&e(`div`,{className:`space-y-2`,children:[i(`label`,{htmlFor:`api-explorer-input`,className:`text-xs font-medium text-foreground-muted`,children:r(`system.apiExplorer.input`)}),i(me,{id:`api-explorer-input`,value:d,onChange:e=>f(e.target.value),rows:t.hasInput?8:2,spellCheck:!1,placeholder:t.hasInput?void 0:r(`system.apiExplorer.noInput`),state:x.ok&&C.length===0?`default`:`error`,className:`font-mono text-xs`}),i(Ye,{parseError:x.ok?null:x.message,issues:C}),e(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e(L,{onClick:()=>void O(),disabled:!T,children:[i(y,{className:`h-3.5 w-3.5`}),r(g?`system.apiExplorer.running`:`system.apiExplorer.run`)]}),t.hasInput&&e(L,{variant:`ghost`,onClick:()=>f(Ke(u)),children:[i(p,{className:`h-3.5 w-3.5`}),r(`system.apiExplorer.resetInput`)]})]})]}),m!==null&&i(Xe,{outcome:m}),t.kind!==`subscription`&&e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[i(`span`,{className:`text-xs font-medium text-foreground-muted`,children:r(`system.apiExplorer.curl`)}),i(de,{value:D,label:r(`system.apiExplorer.copy`),srLabel:r(`system.apiExplorer.curl`)})]}),i(A,{maxHeight:200,children:D}),i(`p`,{className:`text-xs text-foreground-subtle`,children:r(`system.apiExplorer.curlHint`)})]})]})})}function Je({loading:t,error:n,schema:r}){let{t:a}=z();return e(`div`,{className:`space-y-2`,children:[i(`span`,{className:`text-xs font-medium text-foreground-muted`,children:a(`system.apiExplorer.inputSchema`)}),t?i(k,{className:`h-24 w-full`}):n===null?i(A,{maxHeight:240,children:Le(r)}):i(j,{variant:`warning`,message:a(`system.apiExplorer.schemaUnavailable`,{error:n})})]})}function Ye({parseError:t,issues:n}){let{t:r}=z();return t===null&&n.length===0?null:e(`ul`,{className:`space-y-0.5 text-xs text-danger`,role:`alert`,children:[t!==null&&i(`li`,{children:r(`system.apiExplorer.invalidJson`,{error:t})}),n.map(e=>i(`li`,{children:r(`system.apiExplorer.issue.${e.code}`,{path:e.path===``?r(`system.apiExplorer.rootPath`):e.path,expected:e.expected})},`${e.path}:${e.code}`))]})}function Xe({outcome:t}){let{t:n}=z(),r=n(`system.apiExplorer.duration`,{ms:Math.round(t.ms)});if(t.kind===`ok`)return e(`div`,{className:`space-y-2`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-xs font-medium text-foreground-muted`,children:n(`system.apiExplorer.result`)}),i(F,{variant:`success`,size:`sm`,children:r})]}),i(A,{maxHeight:400,children:Le(t.value)})]});let{error:a}=t,o=[{key:n(`system.apiExplorer.errorCode`),value:a.code},{key:n(`system.apiExplorer.errorStatus`),value:a.httpStatus},{key:n(`system.apiExplorer.errorPath`),value:a.path},{key:n(`system.apiExplorer.errorCapRoute`),value:a.capRouteReason}].flatMap(e=>e.value===null?[]:[{key:e.key,value:String(e.value)}]);return i(j,{title:`${n(`system.apiExplorer.callFailed`)} · ${r}`,message:e(`div`,{className:`space-y-2`,children:[i(`p`,{className:`break-words`,children:a.message}),o.length>0&&i(le,{items:o})]})})}c();function Ze(){let{t:n}=z(),[o,s]=Ce(),c=o.get(V),l=P.apiCatalog.list.useQuery(void 0,{staleTime:1/0}),u=t(null),d=l.data?.methods.find(e=>e.path===c)??null,f=r(e=>{s(t=>{let n=new URLSearchParams(t);return n.set(V,e),n},{replace:!0})},[s]),p=d?.path??null;return a(()=>{p!==null&&u.current?.scrollIntoView?.({block:`start`,behavior:`smooth`})},[p]),i(B,{embedded:!0,icon:S,title:n(`system.apiExplorer.title`),subtitle:n(`system.apiExplorer.subtitle`),children:l.isPending?i(k,{className:`h-64 w-full`}):l.error===null?e(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[i(M,{headingId:`api-explorer-methods`,title:n(`system.apiExplorer.methodsTitle`,{count:l.data.methods.length}),children:i(`div`,{className:`p-3 sm:p-4`,children:i(Ue,{methods:l.data.methods,selectedPath:c,onSelect:f})})}),i(`div`,{ref:u,className:`min-w-0 scroll-mt-4`,children:d===null?c===null?i(I,{icon:w,title:n(`system.apiExplorer.pickTitle`),description:n(`system.apiExplorer.pickDescription`)}):i(j,{variant:`warning`,message:n(`system.apiExplorer.unknownMethod`,{method:c})}):i(qe,{method:d},d.path)})]}):i(j,{title:n(`system.apiExplorer.couldNotLoad`),message:l.error.message,onRetry:()=>void l.refetch()})})}var Qe={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},$e={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function et({entry:t,actions:n}){let r=t.name.toLowerCase(),a=Qe[r]??`border-primary`,o=$e[r]??`bg-primary/5`,s=t.providers.find(e=>e.active),c=n?.pendingCapability===t.name;return e(`div`,{className:`rounded-lg border-t-2 border border-border ${a} ${o} p-3 space-y-2`,children:[e(`div`,{className:`flex items-center justify-between gap-2`,children:[e(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[t.name,c&&i(E,{className:`h-3 w-3 animate-spin text-primary`})]}),i(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${t.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:t.mode})]}),t.mode===`singleton`?i(tt,{entry:t,actions:n,activeProvider:s,isPending:c}):i(nt,{entry:t,actions:n,isPending:c})]})}function tt({entry:t,actions:n,activeProvider:r,isPending:a}){let{t:o}=z();if(!n)return i(`div`,{children:r?e(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[i(v,{className:`h-3 w-3 text-green-400 shrink-0`}),i(`span`,{className:`font-medium`,children:r.addonName}),i(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):i(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:o(`addons.capabilityMap.noActiveProvider`,`No active provider`)})});if(t.providers.length===0)return i(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:o(`addons.capabilityMap.noProviders`,`No providers`)});let s=`__inherit__`;return e(`div`,{className:`space-y-2`,children:[i(`div`,{className:`space-y-1`,children:t.providers.map(r=>{let o=r.active;return e(L,{variant:`unstyled`,type:`button`,disabled:a||o,onClick:()=>n.onSelectSingleton(t.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${o?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[i(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${o?`border-green-400 bg-green-400`:`border-border`}`}),i(`span`,{className:`font-medium truncate`,children:r.addonName}),o&&i(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),t.perNode&&t.perNode.length>0&&i(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:t.perNode.map(r=>{let c=r.hasOverride&&r.resolvedActive?r.resolvedActive:s,l=[{value:s,label:r.resolvedActive?o(`addons.capabilityMap.inheritGlobalWith`,{provider:r.resolvedActive}):o(`addons.capabilityMap.inheritGlobal`)},...r.providers.map(e=>({value:e,label:e}))],u=e=>{e===s?n.onClearNodeSingleton(t.name,r.nodeId):n.onSelectNodeSingleton(t.name,r.nodeId,e)},d=a;return e(`div`,{className:`space-y-0.5`,children:[e(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&i(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:o(`common.override`)})]}),l.map(t=>{let n=c===t.value;return e(L,{variant:`unstyled`,type:`button`,disabled:d||n,onClick:()=>u(t.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${n?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[i(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${n?`border-green-400 bg-green-400`:`border-border`}`}),i(`span`,{className:`font-medium truncate`,children:t.label}),n&&t.value!==s&&i(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},t.value)})]},r.nodeId)})})]})}function nt({entry:t,actions:n,isPending:r}){let{t:a}=z();if(t.providers.length===0)return i(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:a(`addons.capabilityMap.noProviders`,`No providers`)});if(!n)return i(`div`,{className:`space-y-1`,children:t.providers.map(t=>e(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[i(`span`,{className:`text-foreground-subtle`,children:t.addonName}),t.active&&i(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},t.addonId))});let o=t.providers.filter(e=>e.active).map(e=>e.addonId),s=(e,r)=>{let i=r?[...new Set([...o,e])]:o.filter(t=>t!==e);n.onToggleCollection(t.name,i)};return i(`div`,{className:`space-y-1`,children:t.providers.map(t=>e(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[e(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[i(h,{checked:t.active,disabled:r,onChange:e=>s(t.addonId,e.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),i(`span`,{className:`text-foreground truncate`,children:t.addonName})]}),t.active&&i(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},t.addonId))})}function rt({capabilities:e,actions:t}){let{t:n}=z();return e.length===0?i(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:n(`addons.capabilityMap.noCapabilitiesRegistered`,`No capabilities registered`)}):i(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>i(et,{entry:e,actions:t},e.name))})}c();var it=[`capabilities`,`listCapabilities`];function at(e){return e===`singleton`||e===`collection`}function ot(e){let t=e.indexOf(`@`);return t===-1?ye.t(`system.capabilities.providerHub`,{addonId:e}):`${e.slice(0,t)} (${e.slice(t+1)})`}function st(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:ot(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function ct(){let{t}=z(),r=T(),[a,c]=o(null),[l,f]=o(null),p=s({queryKey:it,queryFn:()=>r.trpcClient.capabilities.listCapabilities.query()}),m=n(()=>{let e=(p.data??[]).flatMap(e=>at(e.mode)?[st(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[p.data]),h=n(()=>m.filter(e=>e.mode===`singleton`),[m]),g=n(()=>m.filter(e=>e.mode===`collection`),[m]),_=u({mutationFn:e=>r.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId}),onMutate:e=>{c(e.capName),f(null)},onSuccess:async(e,n)=>{f({kind:`success`,message:t(`system.capabilities.isNowActive`,`{{capName}} → {{addonId}} is now active.`,{capName:n.capName,addonId:n.addonId})}),await p.refetch()},onError:(e,n)=>{f({kind:`error`,message:t(`system.capabilities.failedToSet`,{cap:n.capName,error:e instanceof Error?e.message:t(`common.unknownError`)})})},onSettled:()=>c(null)}),y=u({mutationFn:e=>r.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId,nodeId:e.nodeId}),onMutate:e=>{c(e.capName),f(null)},onSuccess:async(e,t)=>{f({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await p.refetch()},onError:(e,n)=>{f({kind:`error`,message:t(`system.capabilities.failedToSetOnNode`,{cap:n.capName,node:n.nodeId,error:e instanceof Error?e.message:t(`common.unknownError`)})})},onSettled:()=>c(null)}),b=u({mutationFn:e=>r.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:e.capName,nodeId:e.nodeId}),onMutate:e=>{c(e.capName),f(null)},onSuccess:async(e,n)=>{f({kind:`success`,message:t(`system.capabilities.nowInheritsTheGlobalDefault`,`{{capName}} @ {{nodeId}} now inherits the global default.`,{capName:n.capName,nodeId:n.nodeId})}),await p.refetch()},onError:(e,n)=>{f({kind:`error`,message:t(`system.capabilities.failedToClearOnNode`,{cap:n.capName,node:n.nodeId,error:e instanceof Error?e.message:t(`common.unknownError`)})})},onSettled:()=>c(null)}),x=u({mutationFn:e=>r.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:e.capName,enabledAddonIds:[...e.enabledAddonIds]}),onMutate:e=>{c(e.capName),f(null)},onSuccess:async(e,n)=>{f({kind:`success`,message:t(`system.capabilities.providerSEnabled`,`{{capName}}: {{length}} provider(s) enabled.`,{capName:n.capName,length:n.enabledAddonIds.length})}),await p.refetch()},onError:(e,n)=>{f({kind:`error`,message:t(`system.capabilities.failedToUpdate`,{cap:n.capName,error:e instanceof Error?e.message:t(`common.unknownError`)})})},onSettled:()=>c(null)}),S={onSelectSingleton:(e,t)=>_.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>y.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>b.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>x.mutate({capName:e,enabledAddonIds:t}),pendingCapability:a};return e(B,{embedded:!0,icon:C,title:t(`system.capabilities.capabilities`,`Capabilities`),subtitle:t(`system.capabilities.chooseWhichProviderIsActive`,`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`),children:[l&&e(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${l.kind===`success`?`border-success/30 bg-success/10 text-success`:`border-danger/40 bg-danger/10 text-danger`}`,children:[l.kind===`success`?i(v,{className:`h-3.5 w-3.5 shrink-0`}):i(d,{className:`h-3.5 w-3.5 shrink-0`}),i(`span`,{children:l.message})]}),p.isLoading&&i(`div`,{className:`flex items-center justify-center py-16`,children:i(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),p.isError&&!p.isLoading&&i(j,{title:t(`system.capabilities.failedToLoadCapabilities`,`Failed to load capabilities`),message:p.error instanceof Error?p.error.message:t(`system.capabilities.unknownError`,`Unknown error`),onRetry:()=>void p.refetch()}),!p.isLoading&&!p.isError&&m.length===0&&i(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:t(`system.capabilities.noCapabilitiesRegistered`,`No capabilities registered.`)}),!p.isLoading&&!p.isError&&m.length>0&&e(`div`,{className:`space-y-6`,children:[h.length>0&&e(`section`,{className:`space-y-2`,children:[i(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:t(`system.capabilities.singletonPickOneProvider`,`Singleton — pick one provider`)}),i(rt,{capabilities:h,actions:S})]}),g.length>0&&e(`section`,{className:`space-y-2`,children:[i(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:t(`system.capabilities.collectionEnableASet`,`Collection — enable a set`)}),i(rt,{capabilities:g,actions:S})]})]})]})}var lt={escape:`Esc`,enter:`Enter`};function ut(e,t){let n=se(e),r=lt[n.key]??n.key.toUpperCase();return t===`mac`?`${n.alt?`⌥`:``}${n.shift?`⇧`:``}${n.mod?`⌘`:``}${r}`:[...n.mod?[`Ctrl`]:[],...n.alt?[`Alt`]:[],...n.shift?[`Shift`]:[],r].join(`+`)}function dt(){let{t}=z(),n=fe(),r=oe();return i(M,{headingId:`settings-hotkeys`,title:t(`systemPage.settings.hotkeys.title`,`Keyboard shortcuts`),icon:O,testId:`settings-hotkeys`,children:e(`div`,{className:`space-y-2 p-3`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:t(`systemPage.settings.hotkeys.description`,`The shortcuts active on this page. They cannot be changed.`)}),n.length===0?i(I,{title:t(`systemPage.settings.hotkeys.empty`,`No shortcuts are active on this page.`)}):n.map(e=>i(N,{label:e.label??t(`systemPage.settings.hotkeys.unnamed`,`Shortcut`),children:i(`kbd`,{className:`rounded-md border border-border bg-surface px-1.5 py-0.5 font-mono text-xs text-foreground`,children:ut(e.combo,r)})},`${e.scope}|${e.combo}`))]})})}c();var ft=[[`system`]];function pt(e){return e.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}function mt(){let{t}=z(),n=l(),r=ne(),s=ue(),c=ie(),[u,d]=o(``),[f,p]=o(``),[h,_]=o(null),v=r.data?.location??null;a(()=>{d(v===null?``:pt(v.latitude)),p(v===null?``:pt(v.longitude))},[v]);let y=async()=>{await n.invalidateQueries({queryKey:ft})},b=async e=>{e.preventDefault();let t=Number(u),n=Number(f);if(u.trim()===``||f.trim()===``){_(`Enter both a latitude and a longitude, or press Clear.`);return}if(!Number.isFinite(t)||t<-90||t>90){_(`Latitude must be between -90 and 90 decimal degrees.`);return}if(!Number.isFinite(n)||n<-180||n>180){_(`Longitude must be between -180 and 180 decimal degrees.`);return}_(null),await s.mutateAsync({latitude:t,longitude:n}),await y()},x=async()=>{_(null),await s.mutateAsync(null),await y()},S=async()=>{_(null),await c.mutateAsync(),await y()},C=s.isPending||c.isPending||r.isLoading;return e(he,{className:`space-y-3`,children:[e(`div`,{className:`flex items-start justify-between gap-3`,children:[e(`div`,{className:`flex items-start gap-2`,children:[i(m,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),i(`div`,{children:i(`h3`,{className:`text-sm font-medium`,children:t(`settings.siteLocationCard.siteLocation`,`Site location`)})})]}),v===null?i(F,{variant:`warning`,children:t(`settings.siteLocationCard.notConfigured`,`Not configured`)}):i(F,{variant:v.source===`operator-set`?`success`:`info`,children:v.source===`operator-set`?t(`settings.siteLocationCard.setByYou`,`Set by you`):t(`settings.siteLocationCard.derivedFromIp`,`Derived from IP`)})]}),v?.label!==void 0&&v.label!==``?i(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings.siteLocationCard.detectedNear`,{place:v.label})}):null,v===null&&r.data?.derivationAttemptedAt!==null?e(`p`,{className:`text-xs text-warning`,children:[t(`settings.siteLocationCard.automaticDetectionFromThePublic`,`Automatic detection from the public IP did not succeed`),r.data?.derivationError!==null&&r.data?.derivationError!==void 0?`: ${r.data.derivationError}`:`.`,` `,t(`settings.siteLocationCard.itIsNotRetriedOn`,`It is not retried on its own — enter the coordinates, or press Detect.`)]}):null,e(`form`,{className:`flex flex-wrap items-end gap-3`,onSubmit:b,children:[e(`label`,{className:`flex flex-col gap-1 text-xs`,children:[i(`span`,{className:`text-muted-foreground`,children:t(`settings.siteLocationCard.latitude`,`Latitude`)}),i(R,{className:`w-40`,value:u,inputMode:`decimal`,placeholder:`40.851800`,onChange:e=>d(e.target.value),"aria-label":t(`settings.siteLocationCard.latitude`,`Latitude`)})]}),e(`label`,{className:`flex flex-col gap-1 text-xs`,children:[i(`span`,{className:`text-muted-foreground`,children:t(`settings.siteLocationCard.longitude`,`Longitude`)}),i(R,{className:`w-40`,value:f,inputMode:`decimal`,placeholder:`14.268100`,onChange:e=>p(e.target.value),"aria-label":t(`settings.siteLocationCard.longitude`,`Longitude`)})]}),i(L,{type:`submit`,disabled:C,children:t(`common.save`,`Save`)}),e(L,{type:`button`,variant:`ghost`,disabled:C,onClick:S,children:[i(g,{className:`h-3.5 w-3.5 mr-1`}),t(`settings.siteLocationCard.detectFromIp`,`Detect from IP`)]}),v===null?null:i(L,{type:`button`,variant:`ghost`,disabled:C,onClick:x,children:t(`settings.siteLocationCard.clear`,`Clear`)})]}),h===null?null:i(`p`,{className:`text-xs text-danger`,children:h}),i(`p`,{className:`text-xs text-muted-foreground`,children:t(`settings.siteLocationCard.wgs84DecimalDegreesDetectAsks`,`WGS84 decimal degrees. Detect asks a public geo-IP service once and will not overwrite a value you typed — clear it first.`)})]})}c();function ht(e){return D.some(t=>t===e)}function gt(e){return ge.some(t=>t===e)}function _t(){let{t}=z(),n=_e(),[r,a]=o(!1),[s,c]=o(null),l=e=>{a(!0),c(null),n.update(e).catch(e=>c(e instanceof Error?e.message:String(e))).finally(()=>a(!1))},u=n.status!==`ok`||!n.writable||r;return i(M,{headingId:`settings-units`,title:t(`systemPage.myAccess.units.title`,`Units`),icon:ee,testId:`settings-units`,children:e(`div`,{className:`space-y-2 p-3`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:t(`systemPage.myAccess.units.description`,`How readings are shown to you, on every device you sign in on. Stored values do not change.`)}),n.status===`error`&&i(j,{message:t(`systemPage.myAccess.units.loadError`,`Your unit preferences could not be read.`)}),n.status===`ok`&&!n.writable&&i(j,{message:t(`systemPage.myAccess.units.unreadable`,`The saved unit preferences are in a format this version cannot read, so they are left untouched.`)}),s!==null&&i(j,{message:s}),i(N,{label:t(`systemPage.myAccess.units.temperature`,`Temperature`),children:i(x,{"aria-label":t(`systemPage.myAccess.units.temperature`,`Temperature`),value:n.value.temperature,disabled:u,onChange:e=>{let t=e.target.value;gt(t)&&l({temperature:t})},options:[{value:`celsius`,label:t(`systemPage.myAccess.units.celsius`,`Celsius (°C)`)},{value:`fahrenheit`,label:t(`systemPage.myAccess.units.fahrenheit`,`Fahrenheit (°F)`)}]})}),i(N,{label:t(`systemPage.myAccess.units.system`,`Other measurements`),children:i(x,{"aria-label":t(`systemPage.myAccess.units.system`,`Other measurements`),value:n.value.system,disabled:u,onChange:e=>{let t=e.target.value;ht(t)&&l({system:t})},options:[{value:`metric`,label:t(`systemPage.myAccess.units.metric`,`Metric (km/h, hPa, mm)`)},{value:`imperial`,label:t(`systemPage.myAccess.units.imperial`,`Imperial (mph, inHg, in)`)}]})})]})})}function vt(){let{t}=z(),{nodes:n,isLoading:r}=ce(),a=n.find(e=>e.isHub&&e.isOnline);return e(B,{embedded:!0,children:[i(mt,{}),r?i(`div`,{className:`text-foreground-subtle text-sm py-12 text-center`,children:t(`admin.system.settings.loadingHubTopology`,`Loading hub topology…`)}):a?i(Ee,{emptyMessage:t(`admin.system.settings.bootstrapUnavailable`,`Not available — the addon that owns the server settings did not answer.`)}):e(`div`,{className:`flex flex-col items-center justify-center text-foreground-subtle text-sm gap-2 py-12`,children:[i(f,{className:`h-8 w-8 opacity-30`}),i(`p`,{children:t(`admin.system.settings.noOnlineHubNodeFound`,`No online hub node found.`)}),i(`p`,{className:`text-xs`,children:t(`admin.system.settings.settingsWillAppearOnceThe`,`Settings will appear once the hub is reachable.`)})]}),e(`section`,{"aria-labelledby":`settings-per-user`,className:`mt-3 sm:mt-4 space-y-3 sm:space-y-4`,children:[i(`h2`,{id:`settings-per-user`,className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:t(`systemPage.settings.perUser`,`Your settings`)}),i(_t,{}),i(dt,{})]})]})}function yt(){let{t:e}=z(),t=be(`/system/settings`,{t:e,isAdmin:!0})??{icon:f,title:e(`system.systemNav`,`System`)},{search:n,hash:r}=we();return new URLSearchParams(n).get(`tab`)===`secrets`?i(xe,{replace:!0,to:`${Se(n)}${r}`}):i(Te,{icon:t.icon,title:t.title,defaultSection:`settings`,sectionsLabel:`${t.title} sections`,sections:[{id:`settings`,label:e(`system.system.settings`,`Settings`),content:i(vt,{})},{id:`capabilities`,label:e(`system.system.capabilities`,`Capabilities`),content:i(ct,{})},{id:`api-explorer`,label:e(`system.system.apiExplorer`),content:i(Ze,{}),ownedParams:[`method`]}]})}export{yt as SystemPage};
@@ -1 +0,0 @@
1
- import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,i as l,o as u,q as d,x as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Bn as p,Ga as m,Qa as h,Ra as g,Ua as _,Va as v,ft as y,ir as b,qt as x,tn as S,yt as C}from"./player-overlays-D546iNTv.js";import{$o as w,An as T,Bs as E,Dr as D,Er as ee,Ga as te,Jr as O,Lr as ne,On as re,Pn as ie,Rr as ae,Ua as oe,Wa as k,Xs as A,hc as j,jn as se,kn as M,qr as N,zr as P}from"./client-DQzHwaNb.js";import{n as ce,t as F}from"./shapes-D4IRNSXI.js";import{t as le}from"./unlink-D3-IGpS8.js";import{$n as ue,Aa as I,Bn as de,Cp as fe,D as pe,Da as me,Ea as he,Fn as ge,Gd as _e,Gi as ve,Hn as ye,In as be,Ji as xe,Jn as Se,Kn as Ce,Kt as L,Ln as we,Np as Te,O as Ee,Oa as De,Pf as Oe,Qn as ke,Rf as Ae,Rn as je,Sp as R,T as Me,Ta as Ne,Ui as Pe,Un as Fe,Vn as Ie,Wi as Le,Wn as z,Xn as Re,Yi as ze,Yn as Be,Zn as Ve,Zs as He,ar as Ue,cr as We,di as Ge,er as Ke,fi as qe,ir as Je,k as Ye,la as Xe,li as Ze,lp as Qe,lr as $e,nr as B,ns as et,or as V,pp as H,q as tt,qi as nt,qn as rt,rr as it,rt as at,sr as ot,tr as st,ui as ct,ut as U,v as lt,xa as ut,xp as W,zn as dt}from"./src-C9_yKHH3.js";import{t as G}from"./useTranslation-BJr-n0es.js";import{a as ft,c as pt,d as mt,f as ht,i as gt,l as _t,n as vt,o as yt,r as bt,u as xt}from"./command-vocab-CeQ0ypHW.js";import{At as St,Ct,St as wt,kt as Tt,wt as Et,xt as Dt}from"./CompositionBlockEditor-BUQTd-UR.js";c();function K(e){return e.kind===`dynamic`}function Ot(e){return e.replace(/-([a-z0-9])/g,(e,t)=>t.toUpperCase())}function q(e,t){return t.from===`status`&&t.cap!==void 0?t.cap:e}function J(e){return e.from===`method`?e.method:`getStatus`}function Y(e,t){return typeof e==`object`&&e?Reflect.get(e,t):void 0}function kt(e){return typeof e==`string`||typeof e==`number`}function At(e,t){let n=t.from===`status`?Y(e,t.field):e;if(!Array.isArray(n))return[];let r=[];for(let e of n){if(t.where!==void 0&&Y(e,t.where.key)!==t.where.equals)continue;let n=t.valueKey===void 0?e:Y(e,t.valueKey);if(!kt(n))continue;let i=t.labelKey===void 0?n:Y(e,t.labelKey);r.push({value:n,label:kt(i)?String(i):String(n)})}return r}function jt(e,t){let n=t.from===`status`?Y(e,t.field):e;return Array.isArray(n)?{kind:`answered`,choiceCount:At(e,t).length}:{kind:`failed`}}var Mt=3e4;function Nt(e){return typeof e==`object`&&!!e&&typeof Reflect.get(e,`query`)==`function`}function Pt(e,t,n,r){return{queryKey:[`build`,`dynamic-offer`,t,n,r],staleTime:Mt,retry:!1,queryFn:async()=>{let i=typeof e==`object`&&e?Reflect.get(e,Ot(n)):void 0,a=typeof i==`object`&&i?Reflect.get(i,r):void 0;if(!Nt(a)||t===null)throw Error(`no readable ${n}.${r}`);return a.query({deviceId:t})}}}function X(e,t){return`${e}.${t}`}function Ft(e){let t=new Map;for(let n of e)for(let e of n.openArgs){if(!K(e.offer))continue;let r=q(n.cap,e.offer),i=J(e.offer),a=X(r,i);t.has(a)||t.set(a,{key:a,readCap:r,read:i,offer:e.offer})}return[...t.values()]}function It(e,t){let n=C(),r=Ft(t),i=l({queries:r.map(t=>({...Pt(n.trpcClient,e,t.readCap,t.read),enabled:e!==null&&e>0}))}),a=new Map;return r.forEach((e,t)=>{let n=i[t];n===void 0||n.isPending?a.set(e.key,{kind:`pending`}):n.isError?a.set(e.key,{kind:`failed`}):a.set(e.key,jt(n.data,e.offer))}),(e,t)=>a.get(X(q(e,t),J(t)))??{kind:`pending`}}function Lt(e){let t=new Map;for(let n of e){if(n.offeredWhen===null)continue;let e=`${X(n.cap,n.offeredWhen.method)}#${n.offeredWhen.field}`;t.has(e)||t.set(e,{key:e,cap:n.cap,gate:n.offeredWhen})}return[...t.values()]}function Rt(e,t){let n=C(),r=Lt(t),i=l({queries:r.map(t=>({...Pt(n.trpcClient,e,t.cap,t.gate.method),enabled:e!==null&&e>0}))}),a=new Map;return r.forEach((e,t)=>{let n=i[t];n===void 0||n.isPending?a.set(e.key,{kind:`pending`}):n.isError?a.set(e.key,{kind:`failed`}):a.set(e.key,re(n.data,e.gate))}),(e,t)=>a.get(`${X(e,t.method)}#${t.field}`)??{kind:`pending`}}function zt(e,t,n){let r=C(),i=n===null?``:J(n),a=n===null?t:q(t,n),o=s({...Pt(r.trpcClient,e,a,i),enabled:e!==null&&e>0&&n!==null});if(n===null||e===null)return{state:`unavailable`};if(o.isPending)return{state:`loading`};if(o.isError)return{state:`unavailable`};let c=At(o.data,n);return c.length===0?{state:`unavailable`}:{state:`ready`,choices:c}}var Bt=`deviceId`;function Vt(e){return M(e.caps,e.type)}function Ht(e){let[t,...n]=e;if(t===void 0)return[];let r=n.map(e=>new Set(e.map(e=>e.id)));return t.filter(e=>r.every(t=>t.has(e.id))&&(n.length===0||!Ut(e)))}function Ut(e){return e.openArgs.some(e=>e.offer.kind===`dynamic`)}function Wt(e){let t=new Map;for(let n of e)for(let e of Vt(n))t.has(e.id)||t.set(e.id,e);return[...t.values()]}function Gt(e,t){return e.filter(e=>T(e.caps,[t],`any`,e.type))}function Kt(e,t){return e.find(e=>e.id===t)??{id:t,caps:[]}}function qt(e,t,n){if(t===null)return[];if(t.kind===`devices`)return t.ids.length===0?[]:Ht(t.ids.map(t=>Vt(Kt(e,t))));if(t.kind===`var`&&t.name===`deviceId`)return Wt(e).filter(e=>!Ut(e));if(t.kind===`var`&&t.name===`item`){let t=n.roundDevices??[];return t.length===0?[]:Ht(t.map(t=>Vt(Kt(e,t))))}return[]}function Jt(e){let t=new Map;for(let n of e)t.set(n.cap,[...t.get(n.cap)??[],n]);return[...t.entries()].map(([e,t])=>({cap:e,actions:t}))}function Yt(e,t,n,r){let i=Xt(r.trim());return i===``?!0:[e.label[t],e.phrase[t],n,e.id].some(e=>Xt(e).includes(i))}function Xt(e){return e.normalize(`NFD`).replace(/\p{Diacritic}/gu,``).toLowerCase()}function Zt(e){return e?.kind===`devices`?e.ids:[]}function Qt(e,t,n,r){return n===null?null:qt(e,t,r).some(e=>e.id===n)?n:null}function $t(e,t,n){if(t?.kind!==`devices`)return t;let r=new Set(Gt(e,n).map(e=>e.id)),i=t.ids.filter(e=>r.has(e));return i.length===0?null:{kind:`devices`,ids:i}}function en(e){return e.toLowerCase().startsWith(`it`)?`it`:`en`}function tn(e,t){return e===`error`||t===`error`?`failed`:e===`pending`||t===`pending`?`pending`:`answered`}function nn(e){let t=He({projection:`slim`}),r=n(()=>{let n=t.status===`success`?Tt(t.data):[],r=new Set(e??[]);return n.filter(e=>!r.has(e.type))},[t.status,t.data,e]),i=St(r.map(e=>e.id)),a=n(()=>r.map(e=>({id:e.id,type:e.type,caps:i.data?.get(e.id)??[]})),[r,i.data]),o=r.length===0&&t.status===`success`?`success`:i.status;return{rows:r,fleet:a,listState:tn(t.status,o)}}function rn(e,t,n){return Jt(e).map(e=>({cap:e.cap,title:Et(e.cap,n),rows:e.actions.map(e=>({cap:e.cap,path:e.id,label:e.label[t],valueText:``}))}))}function an({target:t,allowTriggerDevice:n,round:r,onPick:a}){let{t:o}=G(),s=[...n?[{name:Bt,label:o(`customize.sourceSelector.action.triggerDevice`)}]:[],...r?[{name:w,label:o(`customize.sourceSelector.action.roundDevice`)}]:[]];return s.length===0?null:i(`ul`,{className:`flex flex-col gap-1`,"data-testid":`action-pseudo-targets`,children:s.map(n=>i(`li`,{children:e(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground`,children:[i(De,{name:`action-pseudo-target`,checked:t?.kind===`var`&&t.name===n.name,"data-testid":`action-target-var-${n.name}`,onChange:()=>a({kind:`var`,name:n.name})}),i(`span`,{children:n.label})]})},n.name))})}function on(e,t){if(e?.kind!==`devices`||e.ids.length<=1||t===void 0||!t.openArgs.some(e=>e.offer.kind===`dynamic`))return e;let n=e.ids[e.ids.length-1];return n===void 0?e:{kind:`devices`,ids:[n]}}function sn({value:t,onChange:r,allowTriggerDevice:a=!1,roundDevices:s,multiple:c=!0,excludeTypes:l,args:u,fillHeight:d=!1}){let{t:f,i18n:p}=G(),m=en(p.language),[h,g]=o(`by-device`),[_,v]=o(`devices`),[y,b]=o(``),{fleet:x,listState:S}=nn(l),C=Ne(`command-devices`),w=n(()=>s===void 0?{}:{roundDevices:s},[s]),T=n(()=>qt(x,t.target,w),[x,t.target,w]),E=t.target?.kind===`devices`&&t.target.ids.length===1?t.target.ids[0]??null:null,D=It(E,T),ee=Rt(E,T),te=E===null?T:se(T,D,ee),O=n(()=>Wt(x),[x]),ne=O.find(e=>e.id===t.actionId),re=e=>{let n=on(e,h===`by-action`?ne:void 0);r({target:n,actionId:h===`by-device`?Qt(x,n,t.actionId,w):t.actionId})},ie=e=>{r({target:h===`by-action`?$t(x,t.target,e):t.target,actionId:e})},ae=h===`by-action`&&t.actionId!==null?{actions:[t.actionId]}:void 0,oe=Zt(t.target).map(e=>({deviceId:e})),k=e(`div`,{className:d?`flex min-h-0 flex-1 flex-col gap-2`:`flex min-h-0 flex-col gap-2`,"data-testid":`action-device-column`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground-muted`,children:f(`customize.sourceSelector.action.devicesHeading`)}),i(an,{target:t.target,allowTriggerDevice:a&&(h===`by-device`||t.actionId!==null),round:s!==void 0,onPick:re}),h===`by-action`&&t.actionId===null?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:f(`customize.sourceSelector.action.pickActionFirst`)}):i(he,{requires:ae,excludeTypes:l,kind:`device`,multiple:c,picked:oe,onSelect:e=>{C.push(e.deviceId);let n=Zt(t.target),r=c?n.includes(e.deviceId)?n.filter(t=>t!==e.deviceId):[...n,e.deviceId]:n.length===1&&n[0]===e.deviceId?[]:[e.deviceId];re(r.length===0?null:{kind:`devices`,ids:r})},railFirst:!1,recentIds:C.ids,autoFocus:h===`by-device`,fill:d})]}),A=h===`by-device`?te:O,j=A.filter(e=>Yt(e,m,Et(e.cap,p.language),y)),M=e(`div`,{className:`flex min-h-0 flex-col gap-2`,"data-testid":`action-command-column`,children:[i(`h3`,{className:`text-[11px] font-medium text-foreground-muted`,children:f(`customize.sourceSelector.action.actionsHeading`)}),(h===`by-action`||A.length>=8)&&i(W,{type:`search`,value:y,"aria-label":f(`customize.sourceSelector.action.search`),placeholder:f(`customize.sourceSelector.action.search`),"data-testid":`action-search`,onChange:e=>b(e.target.value)}),h===`by-device`&&t.target===null?i(`p`,{className:`text-[11px] text-foreground-subtle`,children:f(`customize.sourceSelector.action.pickDeviceFirst`)}):S===`pending`?i(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:f(`customize.sourceSelector.action.loading`)}):j.length===0?i(`p`,{className:`text-[11px] text-foreground-subtle`,"data-testid":`action-none`,children:y.trim()===``?Zt(t.target).length>1?f(`customize.sourceSelector.action.noCommon`):f(`customize.sourceSelector.action.none`):f(`customize.sourceSelector.action.noMatch`,{query:y})}):i(Me,{name:`action-command`,groups:rn(j,m,p.language),value:t.actionId===null?null:{cap:A.find(e=>e.id===t.actionId)?.cap??``,path:t.actionId},rowTestId:e=>`action-row-${e.path}`,onPick:e=>ie(e.path)})]}),N=h===`by-device`?t.target!==null:t.actionId!==null,P=h===`by-device`?t.target?.kind===`devices`?t.target.ids.length:t.target===null?0:1:t.actionId===null?0:1;return e(`div`,{className:d?`flex min-h-0 flex-1 flex-col gap-3`:`flex flex-col gap-3`,children:[i(tt,{label:f(`customize.sourceSelector.action.mode`),value:h,options:[{value:`by-device`,label:f(`customize.sourceSelector.action.byDevice`)},{value:`by-action`,label:f(`customize.sourceSelector.action.byAction`)}],onChange:e=>{if(e===`by-device`){let e=Qt(x,t.target,t.actionId,w);e!==t.actionId&&r({target:t.target,actionId:e})}g(e),v(`devices`),b(``)}}),i(Dt,{step:_,devices:h===`by-device`?k:M,values:h===`by-device`?M:k,back:N?{label:f(`customize.sourceSelector.backToDevices`),ariaLabel:f(`customize.sourceSelector.backToDevices`)}:null,onBack:()=>v(wt()),done:{countLabel:f(`customize.sourceSelector.pickedCount`,{count:P}),label:f(`customize.sourceSelector.done`),disabled:!N},onDone:()=>{let e=Ct(P);e!==null&&v(e)},fillHeight:d}),u!=null&&t.actionId!==null&&t.target!==null&&i(`div`,{"data-testid":`action-args`,className:`flex max-h-[40%] shrink-0 flex-col gap-2 overflow-y-auto border-t border-border pt-3`,children:u})]})}c();function cn(e){return e===void 0||!Number.isFinite(e)?``:String(e)}function ln({value:e,onValue:t,onBrace:n,onBlur:r,...a}){let[s,c]=o(null);return i(W,{...a,inputMode:`decimal`,value:s??cn(e),onChange:e=>{let r=e.target.value;if(r.includes(`{`)){n?.();return}c(r);let i=r.trim()===``?NaN:Number(r);t(Number.isFinite(i)?i:null)},onBlur:e=>{c(null),r?.(e)}})}function Z({widthClass:e,...t}){return i(`span`,{className:`block max-w-full ${e}`,children:i(y,{...t})})}c();function un(e){return e.kind===`fixed`?String(e.value):``}function dn({arg:t,locale:n,variables:r,value:a,onChange:s,choices:c}){let{t:l}=G(),[u,d]=o(!1),f=t.label[n],p=vt(t,a),m=a.kind===`var`?i(Qe,{label:a.name,onRemove:()=>s(gt(t))}):i(fn,{arg:t,locale:n,value:a,onChange:s,onBrace:()=>d(!0),choices:c});return e(`span`,{className:`inline-flex flex-col gap-0.5 align-top`,"data-testid":`arg-${t.key}`,children:[e(`span`,{className:`inline-flex items-center gap-1`,children:[m,r.length>0&&e(Ze,{open:u,onOpenChange:d,children:[i(qe,{"aria-label":l(`flow.arg.useVariable`,`Use a variable for {{label}}`,{label:f}),className:`h-8 rounded-md border border-border bg-surface px-2 font-mono text-xs text-foreground hover:bg-surface-hover`,children:`{x}`}),i(ct,{children:r.map(e=>i(Ge,{onClick:()=>s({kind:`var`,name:e.name}),children:`${e.name} · ${e.hint}`},e.name))})]})]}),i(mn,{arg:t,value:a,issue:p})]})}function fn({arg:e,locale:t,value:n,onChange:r,onBrace:a,choices:o}){let{t:s}=G(),c=e.offer,l=e.label[t];if(K(c)&&o?.state===`ready`){let t=o.choices.some(e=>e.value===n.value);return i(Z,{widthClass:`w-48`,"aria-label":l,"data-testid":`dynamic-${e.key}`,value:String(n.value),onChange:e=>{let t=o.choices.find(t=>String(t.value)===e.target.value);t!==void 0&&r({kind:`fixed`,value:t.value})},options:[...t?[]:[{value:String(n.value),label:n.value===``?s(`flow.arg.choose`,`Choose…`):String(n.value)}],...o.choices.map(e=>({value:String(e.value),label:e.label}))]})}if(c.kind===`enum`)return i(Z,{widthClass:`w-40`,"aria-label":l,value:String(n.value),onChange:e=>{let t=c.values.find(t=>String(t.value)===e.target.value);t!==void 0&&r({kind:`fixed`,value:t.value})},options:c.values.map(e=>({value:String(e.value),label:e.label[t]}))});if(c.kind===`boolean`)return i(Z,{widthClass:`w-28`,"aria-label":l,value:n.value===!0?`yes`:`no`,onChange:e=>r({kind:`fixed`,value:e.target.value===`yes`}),options:[{value:`yes`,label:s(`common.yes`,`Yes`)},{value:`no`,label:s(`common.no`,`No`)}]});let u=_t(e);return u===void 0?c.kind===`number`?i(pn,{label:l,unit:c.unit,value:n,onChange:r,onBrace:a}):c.kind===`text`&&c.secret===!0?i(W,{"aria-label":l,type:`password`,className:`w-40`,value:un(n),onChange:e=>r({kind:`fixed`,value:e.target.value})}):i(lt,{label:l,className:`flex w-56 flex-col gap-1`,testId:`arg-text-${e.key}`,value:un(n),onChange:e=>r({kind:`fixed`,value:e})}):i(pe,{quantity:u.quantity,storedUnit:u.unit,value:typeof n.value==`number`?n.value:void 0,unit:n.unit,min:u.min,max:u.max,"aria-label":l,onBrace:a,onChange:e=>{let t=Ye(e,u.unit);r({kind:`fixed`,value:t.value,unit:t.unit})}})}function pn({label:t,unit:n,value:r,onChange:a,onBrace:o}){return e(f,{children:[i(ln,{"aria-label":t,className:`w-20`,value:typeof r.value==`number`?r.value:void 0,onValue:e=>a({kind:`fixed`,value:e??NaN}),onBrace:o}),n!==void 0&&i(`span`,{className:`text-sm text-foreground-muted`,children:n})]})}function mn({arg:e,value:t,issue:n}){let{t:r}=G(),a=e.offer;if(t.kind!==`fixed`||a.kind!==`number`||a.min===void 0&&a.max===void 0)return null;let o=_t(e),s=o===void 0?a.unit:t.unit??o.unit,c=o===void 0?{min:a.min,max:a.max}:Ee({min:a.min,max:a.max},o.unit,s??o.unit),l=s??``,u=e=>e===void 0||o===void 0?e:Number(e.toPrecision(4)),d={min:u(c.min),max:u(c.max)},f=d.min!==void 0&&d.max!==void 0?r(`flow.arg.range`,`{{min}} to {{max}} {{unit}}`,{min:d.min,max:d.max,unit:l}):d.min===void 0?r(`flow.arg.atMost`,`at most {{max}} {{unit}}`,{max:d.max,unit:l}):r(`flow.arg.atLeast`,`at least {{min}} {{unit}}`,{min:d.min,unit:l});return i(`span`,{className:`text-[11px] ${n===null?`text-foreground-subtle`:`text-danger`}`,role:n===null?void 0:`alert`,children:f.trim()})}var hn=[A.Container],gn=[A.Camera];function _n(e,t){let n=E(e);if(n!==void 0)return M([n.cap],t).find(t=>t.id===e)}function vn(e,t){return e.kind===`devices`?e.ids.map(t.deviceName).join(`, `):e.kind===`var`?e.name===`deviceId`?t.triggerDevice:e.name===`item`?t.roundDevice:`{${e.name}}`:t.someDevices}function yn(e,t,n){if(t.kind===`var`)return`{${t.name}}`;let r=e.offer;if(r.kind===`enum`){let e=r.values.find(e=>e.value===t.value);return e===void 0?String(t.value):e.label[n]}return String(t.value)}function bn(e,t,n,r){if(e.actionId===``)return null;let i=_n(e.actionId,r);if(i===void 0)return null;let a=pt([i],e),o=vn(e.target,n);return mt(i.phrase[t]).map(e=>{if(e.kind===`text`)return e.text;if(e.key===`device`)return o;let n=i.openArgs.find(t=>t.key===e.key),r=a?.values[e.key];return n===void 0||r===void 0?`{${e.key}}`:yn(n,r,t)}).join(``)}function xn({deviceId:e,cap:t,arg:n,...r}){return i(dn,{arg:n,choices:zt(e,t,K(n.offer)?n.offer:null),...r})}c();function Sn(e){let{t}=G();return{deviceName:t=>e.find(e=>e.id===t)?.name??`#${String(t)}`,triggerDevice:t(`flow.command.triggerDevice`),roundDevice:t(`automation.repeat.itemHint`,`the device of this round`),someDevices:t(`flow.command.domainDevices`)}}function Cn({step:t,devices:n,variables:r,roundDevices:a,singleTarget:s=!1,autoOpen:c=!0,onChange:l}){let{t:u,i18n:d}=G(),f=ht(d.language),p=Sn(n),[m,h]=o(c&&t.actionId===``);return e(`div`,{className:`flex flex-wrap items-center gap-2`,"data-testid":`command-step`,children:[i(`p`,{className:`min-w-0 flex-1 text-sm text-foreground`,"data-testid":`command-step-phrase`,children:bn(t,f,p,wn(t.target,n))??i(`span`,{className:`text-foreground-subtle`,children:u(`flow.command.pickCommand`)})}),i(H,{variant:`outline`,size:`sm`,"data-testid":`command-step-change`,onClick:()=>h(!0),children:t.actionId===``?u(`flow.command.choose`):u(`flow.command.change`)}),m&&i(En,{step:t,devices:n,variables:r,singleTarget:s,...a===void 0?{}:{roundDevices:a},onCancel:()=>h(!1),onConfirm:e=>{h(!1),l(e)}})]})}function wn(e,t){if(e?.kind!==`devices`)return;let n=e.ids[0];return t.find(e=>e.id===n)?.type}function Tn(e){return{target:e.target.kind===`devices`&&e.target.ids.length===0?null:e.target,actionId:e.actionId===``?null:e.actionId}}function En({step:t,devices:n,variables:r,roundDevices:a,singleTarget:s,onCancel:c,onConfirm:l}){let{t:u,i18n:d}=G(),p=ht(d.language),[m,h]=o(()=>Tn(t)),g=m.actionId===null?void 0:_n(m.actionId,wn(m.target,n)),[_,v]=o(()=>g===void 0?{}:pt([g],t)?.values??ft(g)),y=g===void 0?null:yt(g,_),b=m.target!==null&&g!==void 0&&y===null;return i(at,{open:!0,onClose:c,title:u(`flow.command.dialogTitle`),width:`xl`,fill:!0,testId:`command-picker-dialog`,footer:e(f,{children:[i(H,{variant:`ghost`,onClick:c,children:u(`common.cancel`,`Cancel`)}),i(H,{disabled:!b,"data-testid":`command-picker-confirm`,onClick:()=>{m.target===null||g===void 0||y!==null||l(bt(g,m.target,_))},children:u(`flow.command.use`)})]}),children:i(sn,{value:m,onChange:e=>{if(e.actionId!==m.actionId){let t=e.actionId===null?void 0:_n(e.actionId,wn(e.target,n));v(t===void 0?{}:ft(t))}h(e)},allowTriggerDevice:!s,multiple:!s,excludeTypes:hn,fillHeight:!0,...a===void 0?{}:{roundDevices:a},args:g!==void 0&&g.openArgs.length>0?i(Dn,{action:g,deviceId:m.target===null?null:xt({target:m.target}),values:_,locale:p,variables:r,onChange:v}):null})})}function Dn({action:t,deviceId:n,values:r,locale:a,variables:o,onChange:s}){return i(`div`,{className:`flex flex-wrap items-start gap-3`,"data-testid":`command-args`,children:t.openArgs.map(c=>{let l=r[c.key];if(l===void 0)return null;let u=e=>s({...r,[c.key]:e});return e(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground`,children:[c.label[a],n===null?i(dn,{arg:c,locale:a,variables:o,value:l,onChange:u}):i(xn,{deviceId:n,cap:t.cap,arg:c,locale:a,variables:o,value:l,onChange:u})]},c.key)})})}c();var On=6e4;function kn(){let e=He({projection:`slim`});return n(()=>{let t=new Map((e.data??[]).map(e=>[e.id,e.name]));return(e.data??[]).filter(e=>ie(String(e.type))).map(e=>({id:e.id,name:e.name,stableId:e.stableId,addonId:e.addonId,type:String(e.type),location:e.location??null,parentName:e.parentDeviceId===null?null:t.get(e.parentDeviceId)??null})).toSorted((e,t)=>e.name.localeCompare(t.name))},[e.data])}function An(e){let t=C();return s({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:On,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function jn(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Mn(){return et()}function Nn(e){let t=new Map;for(let n of e)for(let e of n)t.has(e.id)||t.set(e.id,e);let n=[...t.values()];return[...n.filter(e=>e.id.startsWith(`core:`)),...n.filter(e=>!e.id.startsWith(`core:`))]}function Pn(e,t){let n=e.nameI18n;return n===void 0?e.name:t.startsWith(`it`)?n.it:n.en}function Fn(e){let t=D({columns:e.size.cols,rows:e.size.rows,buttons:[]},e,{row:0,col:0});return t.ok?t.layout:null}function In(e,t,n,r){let i=t.trim().toLowerCase();return i===``?[...e]:e.filter(e=>Pn(e,n).toLowerCase().includes(i)||r(e.category).toLowerCase().includes(i))}function Ln(e,t){let n=ee(e,t);return n!==null&&n>1}function Rn(e,t,n={}){let r=n.fillWidth===!0?ee(e,t):null,i=r===null||r<2?{}:{scale:{cols:r}};if(n.at!==void 0)return D(e,t,n.at,i);let a=D(e,t,{row:0,col:0},i);if(a.ok||a.reason===`outside`||a.reason===`too-many`)return a;for(let n=0;n<e.rows;n+=1)for(let r=0;r<e.columns;r+=1){let a=D(e,t,{row:n,col:r},i);if(a.ok)return a}return a}c();function zn({open:t,grid:n,onOpenChange:r,onPick:a}){let{t:o,i18n:s}=G();return i(Pe,{open:t,onOpenChange:r,children:e(ve,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[i(xe,{children:i(ze,{children:o(`remote.palette.title`)})}),i(Le,{children:t&&i(Bn,{grid:n,language:s.language,onPick:a})})]})})}function Bn({grid:t,language:r,onPick:a}){let{t:s}=G(),c=_e({}),[l,u]=o(``),[d,f]=o(!1),[m,g]=o(null),_=e=>s(`remote.palette.category.${e}`,e),v=In(n(()=>Nn(c.data===void 0?[]:[c.data]),[c.data]),l,r,_),y=v.some(e=>Ln(t,e));return c.isError?i(me,{title:s(`remote.palette.errorTitle`),message:c.error.message,onRetry:()=>void c.refetch()}):c.data===void 0?e(`div`,{className:`grid gap-2 sm:grid-cols-2`,"data-testid":`palette-loading`,children:[i(I,{className:`h-24`}),i(I,{className:`h-24`}),i(I,{className:`h-24`}),i(I,{className:`h-24`})]}):e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[i(p,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),i(W,{value:l,className:`pl-8`,placeholder:s(`remote.palette.search`),"aria-label":s(`remote.palette.search`),onChange:e=>u(e.target.value),"data-testid":`palette-search`})]}),y&&e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-muted`,children:[i(h,{checked:d,onChange:e=>f(e.target.checked),"data-testid":`palette-fill-width`}),s(`remote.palette.fillWidth`)]}),m!==null&&i(`p`,{role:`status`,className:`text-xs text-success`,"data-testid":`palette-added`,children:s(`remote.palette.added`,{name:m})}),v.length===0?i(Xe,{icon:F,title:s(`remote.palette.emptyTitle`),description:s(`remote.palette.emptyDescription`)}):i(`ul`,{className:`grid gap-2 sm:grid-cols-2`,"data-testid":`palette-list`,children:v.map(e=>i(`li`,{children:i(Vn,{component:e,language:r,category:_(e.category),onPick:()=>{a(e,{fillWidth:d}),g(Pn(e,r))}})},e.id))})]})}function Vn({component:t,language:r,category:a,onPick:o}){let{t:s}=G(),c=n(()=>Fn(t),[t]),l=Pn(t,r);return e(`button`,{type:`button`,className:`flex h-full w-full items-center gap-3 rounded-lg border border-border bg-surface p-2 text-left hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary`,"data-testid":`palette-item-${t.id}`,onClick:o,children:[i(`span`,{className:`w-20 shrink-0`,children:c!==null&&i(ge,{grid:c,label:l,compact:!0})}),e(`span`,{className:`min-w-0`,children:[i(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:l}),e(`span`,{className:`block truncate text-xs text-foreground-muted`,children:[a,` ·`,` `,s(`remote.palette.size`,{cols:t.size.cols,rows:t.size.rows})]})]})]})}function Q(e,t){let n=t.kind===`group`?z(e,t.id):e.buttons.find(e=>e.id===t.id);return n===void 0?void 0:{row:n.row,col:n.col,rowSpan:n.rowSpan,colSpan:n.colSpan}}function Hn(e,t,n,r,i){if(e.width<=0||e.height<=0)return{row:0,col:0};let a=Math.floor((n-e.left)/e.width*t.columns),o=(r-e.top)/e.height;if(i===void 0||i.length!==t.rows||o<0)return{col:a,row:Math.floor(o*t.rows)};let s=i.reduce((e,t)=>e+t,0),c=0;for(let[e,t]of i.entries())if(c+=t/s,o<c)return{col:a,row:e};return{col:a,row:Math.max(t.rows,Math.floor(o*t.rows))}}function Un(e,t,n){return{row:n.row-(t.row-e.row),col:n.col-(t.col-e.col)}}function Wn(e,t,n){return t.kind===`group`?Ve(e,t.id,n.row,n.col):Re(e,t.id,n.row,n.col)}function Gn(e,t,n){let r=Q(e,t);if(r===void 0)return null;let i=Wn(e,t,n);return{rect:{...r,row:n.row,col:n.col},valid:i.status===`ok`,reason:i.status===`ok`?null:i.reason}}function Kn(e){switch(e){case`ArrowUp`:return{dRow:-1,dCol:0};case`ArrowDown`:return{dRow:1,dCol:0};case`ArrowLeft`:return{dRow:0,dCol:-1};case`ArrowRight`:return{dRow:0,dCol:1};default:return null}}function qn(e,t,n,r){let i=Q(e,t);return i===void 0?{status:`refused`,reason:`unknown-button`}:Wn(e,t,{row:i.row+n,col:i.col+r})}c();var Jn=4;function Yn(e,n,i){let[s,c]=o(null),l=t({grid:e,onDrop:i});l.current={grid:e,onDrop:i};let u=t(null),d=t(!1);return a(()=>()=>u.current?.(),[]),{drag:s,onItemPointerDown:r((e,t)=>{let r=n.current;if(r===null||t.button!==0)return;let i=r.getBoundingClientRect();if(Q(l.current.grid,e)===void 0)return;let a={item:e,startX:t.clientX,startY:t.clientY,grabbed:Hn(i,l.current.grid,t.clientX,t.clientY,st(l.current.grid)),active:!1,target:null},o=e=>{if(!a.active){if(Math.hypot(e.clientX-a.startX,e.clientY-a.startY)<Jn)return;a.active=!0}let t=l.current.grid,n=Hn(r.getBoundingClientRect(),t,e.clientX,e.clientY,st(t)),i=Q(t,a.item);i!==void 0&&(a.target=Un(i,a.grabbed,n),c({item:a.item,preview:Gn(t,a.item,a.target)}))},s=e=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,f),window.removeEventListener(`pointercancel`,p),window.removeEventListener(`keydown`,m),u.current=null,c(null),a.active&&(d.current=!0,window.setTimeout(()=>{d.current=!1},0),e&&a.target!==null&&l.current.onDrop(Wn(l.current.grid,a.item,a.target)))},f=()=>s(!0),p=()=>s(!1),m=e=>{e.key===`Escape`&&s(!1)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,f),window.addEventListener(`pointercancel`,p),window.addEventListener(`keydown`,m),u.current=()=>s(!1)},[n]),consumeDragClick:r(()=>{let e=d.current;return d.current=!1,e},[])}}c();var Xn=`__custom__`;function Zn({value:n,onChange:r}){let{t:a}=G(),[s,c]=o(null),[l,u]=o(null),[d,f]=o(!1),p=t(null),m=s?.kind===`button`?s.id:null,h=s?.kind===`group`?s.id:null,g=n.buttons.find(e=>e.id===m)??null,_=h===null?void 0:z(n,h),v=(e,t)=>{if(e.status===`ok`){u(null),r(e.grid),t?.(e.grid);return}u(a(`remote.layout.refusal.${e.reason}`))},y=Yn(n,p,e=>v(e));return e(`div`,{className:`grid gap-4 md:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]`,children:[e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`grid grid-cols-2 gap-2`,children:[i(U,{label:a(`remote.layout.columns`),children:i(L,{value:n.columns,onDelta:e=>v(Ke(n,n.columns+e,n.rows))})}),i(U,{label:a(`remote.layout.rows`),children:i(L,{value:n.rows,onDelta:e=>v(Ke(n,n.columns,n.rows+e))})})]}),i(ge,{grid:n,label:a(`remote.layout.previewLabel`),selectedId:m,selectedGroupId:h,onSelect:e=>{y.consumeDragClick()||c({kind:`button`,id:e})},onSelectGroup:e=>{y.consumeDragClick()||c({kind:`group`,id:e})},showEmptyCells:!0,gridRef:p,drag:y.drag,onItemPointerDown:y.onItemPointerDown,onItemKeyDown:(e,t)=>{let r=Kn(t.key);r!==null&&(t.preventDefault(),v(qn(n,e,r.dRow,r.dCol)))}}),i(`p`,{className:`text-xs text-foreground-subtle`,children:a(`remote.layout.dragHint`)}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(H,{variant:`outline`,size:`sm`,onClick:()=>f(!0),"data-testid":`remote-add-component`,children:[i(F,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`remote.layout.addComponent`)]}),e(H,{variant:`outline`,size:`sm`,onClick:()=>v(de(n,`ok`),e=>{let t=e.buttons.at(-1);c(t===void 0?null:{kind:`button`,id:t.id})}),"data-testid":`remote-add-button`,children:[i(b,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),a(`remote.layout.addButton`)]})]}),l!==null&&i(`p`,{role:`alert`,className:`text-xs text-warning`,"data-testid":`remote-layout-refusal`,children:l})]}),i(`div`,{className:`min-w-0`,children:g===null?_===void 0?i(`p`,{className:`text-xs text-foreground-subtle`,children:a(`remote.layout.selectHint`)}):i(er,{grid:n,groupId:_.id,apply:v,onGone:()=>c(null)}):i($n,{grid:n,buttonId:g.id,apply:v,onRemove:()=>{r(ke(n,g.id)),c(null),u(null)}})}),i(zn,{open:d,grid:n,onOpenChange:f,onPick:(e,t)=>{let i=Rn(n,e,t);if(!i.ok){u(a(`remote.layout.refusal.${i.reason}`));return}u(null),r(i.layout);let o=i.buttonIds[0];c(i.groupId===null?o===void 0?null:{kind:`button`,id:o}:{kind:`group`,id:i.groupId})}})]})}function Qn(e,t){return[...dt.flatMap(n=>rt(n).map(r=>({value:r,label:be(r,t),group:e(`remote.roleGroup.${n}`)}))),{value:Xn,label:e(`remote.layout.customRole`),group:e(`remote.roleGroup.custom`)}]}function $n({grid:t,buttonId:n,apply:r,onRemove:a}){let{t:s,i18n:c}=G(),l=t.buttons.find(e=>e.id===n),u=l===void 0?null:oe(l.role),[d,f]=o(null);if(l===void 0)return null;let p=Ce(l.role)||d!==null,b=d??u??``,x=te(b),C={trigger:s(`remote.layout.pickIcon`),panel:s(`remote.layout.iconPanel`),searchPlaceholder:s(`deviceDisplay.iconSearchPlaceholder`),clear:s(`remote.layout.noIcon`),noMatches:s(`deviceDisplay.iconNoMatches`)},w=e=>s(`deviceDisplay.iconCategory.${e}`,{defaultValue:j(e)});return e(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-3`,"data-testid":`remote-inspector`,children:[i(ut,{mode:`single`,singleDisplay:`field`,label:s(`remote.layout.role`),options:Qn((e,t)=>s(e,t??e),c.language),value:p?Xn:l.role,onChange:e=>{if(e===Xn){f(u??``);return}f(null),r(B(t,l.id,{role:e}))}}),p&&i(U,{label:s(`remote.layout.customKey`),...b!==``&&!x?{error:s(`remote.layout.customKeyInvalid`)}:{},children:i(W,{value:b,placeholder:`hdmi_1`,onChange:e=>{let n=e.target.value;f(n),te(n)&&r(B(t,l.id,{role:k(n)}))}})}),e(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)] items-end gap-2`,children:[i(U,{label:s(`remote.layout.icon`),children:i(fe,{value:l.icon??null,onPick:e=>r(B(t,l.id,{icon:e})),fallbackGlyph:F,categoryLabel:w,labels:C})}),i(U,{label:s(`remote.layout.label`),children:i(W,{value:l.label??``,maxLength:40,onChange:e=>r(B(t,l.id,{label:e.target.value}))})})]}),i(U,{label:s(`remote.layout.appIcon`),children:i(y,{value:$e(l.icon)?.key??``,options:[{value:``,label:s(`remote.layout.noApp`)},...ot.map(e=>({value:e.key,label:e.label}))],onChange:e=>{let n=e.target.value;n===``?$e(l.icon)!==void 0&&r(B(t,l.id,{icon:null})):r(B(t,l.id,{icon:We(n)}))},"data-testid":`remote-app-icon`})}),e(`div`,{className:`grid grid-cols-2 gap-3`,children:[i(U,{label:s(`remote.layout.shape`),children:i(y,{value:l.shape??``,options:[{value:``,label:s(`remote.layout.lookDefault`)},...N.map(e=>({value:e,label:s(`remote.layout.shapes.${e}`)}))],onChange:e=>{let n=N.find(t=>t===e.target.value);r(it(t,l.id,{shape:n??null}))},"data-testid":`remote-shape`})}),i(U,{label:s(`remote.layout.tone`),children:i(y,{value:l.tone??``,options:[{value:``,label:s(`remote.layout.lookDefault`)},...O.map(e=>({value:e,label:s(`remote.layout.tones.${e}`)}))],onChange:e=>{let n=O.find(t=>t===e.target.value);r(it(t,l.id,{tone:n??null}))},"data-testid":`remote-tone`})})]}),l.tone!==void 0&&[`red`,`green`,`yellow`,`blue`].includes(l.tone)&&e(`label`,{className:`flex items-center gap-2 text-xs text-foreground-muted`,children:[i(h,{checked:l.showLegend===!0,onChange:e=>r(it(t,l.id,{showLegend:e.target.checked})),"data-testid":`remote-show-legend`}),s(`remote.layout.showLegend`)]}),e(`div`,{className:`grid grid-cols-2 gap-3`,children:[i(U,{label:s(`remote.layout.move`),children:e(`div`,{className:`flex items-center gap-1`,children:[i(R,{icon:_,size:`sm`,variant:`secondary`,"aria-label":s(`remote.layout.moveLeft`),onClick:()=>r(V(t,l.id,0,-1))}),i(R,{icon:g,size:`sm`,variant:`secondary`,"aria-label":s(`remote.layout.moveUp`),onClick:()=>r(V(t,l.id,-1,0))}),i(R,{icon:m,size:`sm`,variant:`secondary`,"aria-label":s(`remote.layout.moveDown`),onClick:()=>r(V(t,l.id,1,0))}),i(R,{icon:v,size:`sm`,variant:`secondary`,"aria-label":s(`remote.layout.moveRight`),onClick:()=>r(V(t,l.id,0,1))})]})}),i(U,{label:s(`remote.layout.position`),children:i(`p`,{className:`text-xs text-foreground-muted`,"data-testid":`remote-position`,children:s(`remote.layout.positionValue`,{row:l.row+1,col:l.col+1})})}),i(U,{label:s(`remote.layout.height`),children:i(L,{value:l.rowSpan,onDelta:e=>r(ue(t,l.id,l.rowSpan+e,l.colSpan))})}),i(U,{label:s(`remote.layout.width`),children:i(L,{value:l.colSpan,onDelta:e=>r(ue(t,l.id,l.rowSpan,l.colSpan+e))})})]}),e(H,{variant:`danger`,size:`sm`,onClick:a,children:[i(S,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),s(`remote.layout.removeButton`)]})]})}function er({grid:t,groupId:n,apply:r,onGone:a}){let{t:o}=G(),s=z(t,n);if(s===void 0)return null;let c=Be(t,n).length;return e(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-3`,"data-testid":`remote-group-inspector`,children:[i(`p`,{className:`text-xs text-foreground-muted`,children:o(`remote.layout.groupSummary`,{frame:o(`remote.layout.frames.${s.frame}`,s.frame),count:c,row:s.row+1,col:s.col+1})}),i(U,{label:o(`remote.layout.groupTitle`),children:i(W,{value:s.title??``,maxLength:40,onChange:e=>r(Je(t,s.id,e.target.value)),"data-testid":`remote-group-title`})}),s.frame===`divider`&&e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(U,{label:o(`remote.layout.separatorSize`),children:i(y,{value:s.size??`compact`,options:[{value:`compact`,label:o(`remote.layout.separatorSizeCompact`)},{value:`normal`,label:o(`remote.layout.separatorSizeNormal`)}],onChange:e=>r(Ue(t,s.id,{size:e.target.value===`normal`?`normal`:`compact`})),"data-testid":`remote-separator-size`})}),e(`label`,{className:`flex items-center gap-2 self-end pb-2 text-xs text-foreground-muted`,children:[i(h,{checked:s.hideTitle===!0,onChange:e=>r(Ue(t,s.id,{hideTitle:e.target.checked})),"data-testid":`remote-separator-hide-title`}),o(`remote.layout.separatorHideLabel`)]})]}),e(`div`,{className:`flex flex-wrap gap-2`,children:[e(H,{variant:`outline`,size:`sm`,"data-testid":`remote-group-ungroup`,onClick:()=>{r(ye(t,s.id,!0)),a()},children:[i(le,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),o(`remote.layout.ungroup`)]}),e(H,{variant:`danger`,size:`sm`,"data-testid":`remote-group-delete`,onClick:()=>{r(ye(t,s.id,!1)),a()},children:[i(S,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),o(`remote.layout.deleteGroup`)]})]})]})}var tr={remote:{label:e=>e(`remote.templates.kind.remote`),emptyPayload:Fe,summary:(e,t)=>{let n=Se(e);return t(`remote.templates.layoutSummary`,{columns:n.columns,rows:n.rows,count:n.buttons.length})},renderEditor:(e,t)=>i(Zn,{value:Se(e),onChange:t}),isSavable:e=>Ie(Se(e))!==null,presets:e=>we.map(t=>({id:t.id,label:e(`remote.templates.preset.${t.id}`),payload:()=>je(t.id)}))},automation:{label:e=>e(`build.templates.kindAutomation`,`Automation`),emptyPayload:()=>({version:1,body:{when:{kind:`any`,children:[]},actions:[]},inputs:[],bindings:[]}),summary:(e,t)=>{let n=P.safeParse(e);return n.success?t(`build.templates.inputsSummary`,{count:n.data.inputs.length}):``},renderEditor:()=>null,isSavable:e=>P.safeParse(e).success,presets:()=>[]}};function $(e){return tr[e]}var nr=ne.filter(e=>e!==`automation`);function rr(e,t){let n=ae(e,t);return n.ok?n.payload:null}c();function ir(e={}){let t=u(),n=Oe(),r=Ae(),[i,a]=o(null);return{save:async i=>{a(null);try{let o=i.id===null?await n.mutateAsync({kind:i.kind,name:i.name,payload:i.payload,...ar(i)}):await r.mutateAsync({id:i.id,name:i.name,payload:i.payload,...ar(i)});return o.status===`refused`?(a(o.detail),!1):(await t.invalidateQueries({queryKey:[[`template`]]}),i.id===null&&e.onCreated?.(o.template.id),!0)}catch(e){return a(e instanceof Error?e.message:String(e)),!1}},saving:n.isPending||r.isPending,error:i,clearError:()=>a(null)}}function ar(e){return e.tags===void 0?{}:{tags:[...e.tags]}}function or(e){return{past:[],present:e,future:[]}}var sr=e=>e.past.length>0,cr=e=>e.future.length>0;function lr(e,t){switch(t.type){case`edit`:return Object.is(t.value,e.present)?e:{past:[...e.past,e.present].slice(-100),present:t.value,future:[]};case`undo`:{let t=e.past.at(-1);return t===void 0?e:{past:e.past.slice(0,-1),present:t,future:[e.present,...e.future]}}case`redo`:{let[t,...n]=e.future;return t===void 0?e:{past:[...e.past,e.present],present:t,future:n}}}}c();function ur(e,t){let[n,r]=o(e.name);a(()=>r(e.name),[e.name]);let[i,s]=d(lr,{kind:e.kind,presetId:``,payload:e.payload},or),{kind:c,presetId:l,payload:u}=i.present,f=e=>s({type:`edit`,value:{...i.present,payload:e}}),p=()=>s({type:`undo`}),m=()=>s({type:`redo`});Te(`mod+z`,p,{allowInInput:!1,label:`Undo`}),Te(`mod+shift+z`,m,{allowInInput:!1,label:`Redo`});let h=$(c),g=rr(c,u),_=n.trim()!==``&&g!==null&&h.isSavable(u)&&!t;return{name:n,setName:r,kind:c,presetId:l,payload:u,setPayload:f,undo:p,redo:m,canUndo:sr(i),canRedo:cr(i),canSave:_,dispatch:s,toDraft:()=>g===null?null:{id:e.id,kind:c,name:n.trim(),payload:g,...e.tags===void 0?{}:{tags:e.tags}}}}function dr({editor:t}){let{t:n}=G();return e(f,{children:[i(R,{icon:x,size:`sm`,variant:`ghost`,"aria-label":n(`remote.history.undo`),title:n(`remote.history.undo`),disabled:!t.canUndo,onClick:t.undo,"data-testid":`template-undo`}),i(R,{icon:ce,size:`sm`,variant:`ghost`,"aria-label":n(`remote.history.redo`),title:n(`remote.history.redo`),disabled:!t.canRedo,onClick:t.redo,"data-testid":`template-redo`})]})}function fr({editor:t,draftId:n,error:r}){let{t:a}=G(),{kind:o,presetId:s,payload:c,name:l,dispatch:u}=t,d=$(o),p=d.presets(a);return e(f,{children:[e(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[i(U,{label:a(`remote.templates.name`),children:i(W,{value:l,maxLength:120,onChange:e=>t.setName(e.target.value),"data-testid":`template-name`})}),n===null&&nr.length>1&&i(U,{label:a(`remote.templates.kind.label`),children:i(y,{value:o,options:nr.map(e=>({value:e,label:$(e).label(a)})),onChange:e=>{let t=nr.find(t=>t===e.target.value);t!==void 0&&u({type:`edit`,value:{kind:t,presetId:``,payload:$(t).emptyPayload()}})}})}),n===null&&p.length>0&&i(U,{label:a(`remote.templates.startFrom`),children:i(y,{value:s,options:[{value:``,label:a(`remote.templates.startBlank`)},...p.map(e=>({value:e.id,label:e.label}))],onChange:e=>{let n=p.find(t=>t.id===e.target.value);u({type:`edit`,value:{kind:o,presetId:n?.id??``,payload:n===void 0?d.emptyPayload():n.payload()}}),n!==void 0&&l.trim()===``&&t.setName(n.label)},"data-testid":`template-preset`})})]}),d.renderEditor(c,t.setPayload),r!==null&&i(`p`,{role:`alert`,className:`text-xs text-danger`,children:r})]})}function pr({draft:t,saving:n,error:r,onSave:a,onClose:o,back:s}){let{t:c}=G(),l=ur(t,n);return e(f,{children:[e(xe,{className:`flex-row items-center justify-between gap-2`,children:[e(`div`,{className:`flex min-w-0 items-center gap-2`,children:[s!==void 0&&e(H,{size:`sm`,variant:`ghost`,onClick:s.onBack,"data-testid":`template-back`,children:[i(_,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`span`,{className:`truncate`,children:s.label})]}),i(ze,{className:`truncate`,children:s===void 0?t.id===null?c(`remote.templates.newTitle`):c(`remote.templates.editTitle`):s.title})]}),i(`div`,{className:`flex shrink-0 items-center gap-1`,children:i(dr,{editor:l})})]}),i(Le,{className:`space-y-4`,children:i(fr,{editor:l,draftId:t.id,error:r})}),e(nt,{children:[i(H,{variant:`ghost`,onClick:o,children:c(`common.cancel`)}),i(H,{disabled:!l.canSave,onClick:()=>{let e=l.toDraft();e!==null&&a(e)},"data-testid":`template-save`,children:c(`common.save`)})]})]})}export{Wt as _,ir as a,jn as c,Dn as d,Cn as f,ln as g,Z as h,ur as i,kn as l,gn as m,fr as n,$ as o,hn as p,dr as r,Mn as s,pr as t,An as u,Ut as v,qt as y};