@camstack/addon-admin-ui 1.2.662 → 1.2.664

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 (92) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/assets/Addons-DbT3ta8z.js +5 -0
  3. package/dist/assets/{AdminPage-BTsUEgX1.js → AdminPage-DjU_tnVG.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-D662-gxB.js → AdminSectionedPage-C7aZLZRh.js} +1 -1
  5. package/dist/assets/AiProfiles-C-ql511o.js +3 -0
  6. package/dist/assets/{BootstrapSettingsForm-DB9tm-XM.js → BootstrapSettingsForm-bkltsyDh.js} +1 -1
  7. package/dist/assets/{Build-BrrMWCRs.js → Build-CyKLuVmF.js} +9 -9
  8. package/dist/assets/{Calendars-X5kuugfK.js → Calendars-CMSCqf10.js} +1 -1
  9. package/dist/assets/{CameraGrids-2YCn1hwy.js → CameraGrids-DN3Ls5A4.js} +1 -1
  10. package/dist/assets/{Cluster-BWUBYf2O.js → Cluster-D24Q3gsy.js} +1 -1
  11. package/dist/assets/{CompositionBlockEditor-IVaGWPoQ.js → CompositionBlockEditor-Cko2VX5-.js} +2 -2
  12. package/dist/assets/{CompositionEditorPage-CnDWWX--.js → CompositionEditorPage-Cq76qdLa.js} +1 -1
  13. package/dist/assets/Data-CI6UgZZY.js +2 -0
  14. package/dist/assets/{DeviceDetail-BEGQMf7d.js → DeviceDetail-D2CGNOL1.js} +2 -2
  15. package/dist/assets/{Devices-rx5eVBlk.js → Devices-BuYYfNPu.js} +1 -1
  16. package/dist/assets/{EmbedDevicePage-Df6vV2Fs.js → EmbedDevicePage-BQ1tRNUp.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-BWrh5XSf.js → EmbedPlayerPage-Csf7kYqH.js} +1 -1
  18. package/dist/assets/History-D9RNBn7H.js +1 -0
  19. package/dist/assets/Identity-Dum55imC.js +1 -0
  20. package/dist/assets/{InstancesTable-Cz2Nvv6V.js → InstancesTable-Bza_hcOv.js} +1 -1
  21. package/dist/assets/IntegrationDetail-DT-ZanyO.js +1 -0
  22. package/dist/assets/Integrations-BpkEEhcd.js +1 -0
  23. package/dist/assets/{Integrations-BwOWjFHm.js → Integrations-Y0x6acKZ.js} +2 -2
  24. package/dist/assets/{Library-ouqjvO91.js → Library-CqniXzi0.js} +1 -1
  25. package/dist/assets/Locations-BnLjl50_.js +3 -0
  26. package/dist/assets/{Logs-DhIxC1_t.js → Logs-D3qUktnv.js} +1 -1
  27. package/dist/assets/MyAccess-tguGEp30.js +2 -0
  28. package/dist/assets/{Network-C2DyBsm5.js → Network-C9GshUgl.js} +1 -1
  29. package/dist/assets/NodeAddonsSettingsPanel-YGDDqLon.js +2 -0
  30. package/dist/assets/{Notifications-DvmwEvAK.js → Notifications-CpQ7WD8S.js} +1 -1
  31. package/dist/assets/{Pipeline-DRXj7Gu_.js → Pipeline-sfp8tOti.js} +1 -1
  32. package/dist/assets/Recordings-zL4BQ-AD.js +1 -0
  33. package/dist/assets/SessionsList-B8py_Z_Y.js +2 -0
  34. package/dist/assets/{Showroom-ePgxQlHR.js → Showroom-Bq-MxPxP.js} +1 -1
  35. package/dist/assets/StorageLocationsTable-D1ZfEmZ0.js +1 -0
  36. package/dist/assets/{System-o0QFwzcf.js → System-C_sm8J4x.js} +1 -1
  37. package/dist/assets/{Terminal-VNG3sFJA.js → Terminal-DRqgGpAj.js} +3 -3
  38. package/dist/assets/{TrainingProviders-C3EJXLp7.js → TrainingProviders-BT4K0RVZ.js} +1 -1
  39. package/dist/assets/{Viewer-D_pGUq-Y.js → Viewer-CKME7kGT.js} +1 -1
  40. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CPteDxIA.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CANWs3BH.js} +1 -1
  41. package/dist/assets/{ai-page.helpers-CrXOsRH5.js → ai-page.helpers-F__brMbl.js} +1 -1
  42. package/dist/assets/{assignment-candidates-qVkiriMP.js → assignment-candidates-CJqDXIFp.js} +1 -1
  43. package/dist/assets/{authed-media-BXrXD050.js → authed-media-CjjuGXR2.js} +1 -1
  44. package/dist/assets/{board-model-lauwzeiV.js → board-model-DnTtSG-0.js} +1 -1
  45. package/dist/assets/device-detail-DHAwENUJ.js +1 -0
  46. package/dist/assets/{device-integration-icon-CLnHy0fo.js → device-integration-icon-DTlSLQS_.js} +1 -1
  47. package/dist/assets/device-picker-model-BFaT-X3C.js +1 -0
  48. package/dist/assets/{format-CIAv5hh2.js → format-DVsAf4qU.js} +1 -1
  49. package/dist/assets/{hostInit-DQkQDV8-.js → hostInit-DtJdIG7z.js} +1 -1
  50. package/dist/assets/i18n-CThuXMc5.js +1 -0
  51. package/dist/assets/index-Boq6U3AD.css +2 -0
  52. package/dist/assets/{index-Xpk4gTbv.js → index-DUv1kIQf.js} +3 -3
  53. package/dist/assets/{linked-devices-model-0tlf9-eZ.js → linked-devices-model-En6xpQk8.js} +1 -1
  54. package/dist/assets/{mf-entry-bootstrap-0-8ef88b9e.js → mf-entry-bootstrap-0-f1ce1aba.js} +2 -2
  55. package/dist/assets/mount-BFaT-X3C.js +1 -0
  56. package/dist/assets/{notification-rule-status-BVKLlf6x.js → notification-rule-status-_SY1WA7F.js} +1 -1
  57. package/dist/assets/remoteEntry-CN2LBUKI.js +1 -0
  58. package/dist/assets/src-CxMNFQ7c.js +272 -0
  59. package/dist/assets/{sso-popup-D3eOaBzJ.js → sso-popup-DyR-aOS2.js} +1 -1
  60. package/dist/assets/{step-inspector-model-eI0Wac5U.js → step-inspector-model-BAZSRIbI.js} +1 -1
  61. package/dist/assets/{use-scenes-feed-o6WPM551.js → use-scenes-feed-CdhtTGlS.js} +1 -1
  62. package/dist/assets/{use-stationary-objects-DniMKKDB.js → use-stationary-objects-Dkn3lZm7.js} +1 -1
  63. package/dist/assets/{useAdminDeviceRemoval-Bz31MUiO.js → useAdminDeviceRemoval-BKtAsw-I.js} +1 -1
  64. package/dist/assets/useEventInvalidation-BFaT-X3C.js +1 -0
  65. package/dist/assets/{useNodeUrlSelection-D2-CzRHy.js → useNodeUrlSelection-CH8FI53M.js} +1 -1
  66. package/dist/assets/useTemplateSave-B9ob9RKz.js +1 -0
  67. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-yMYUaEZc.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C33iQh-d.js} +2 -2
  68. package/dist/index.html +7 -7
  69. package/dist/server/addon.js +1 -1
  70. package/package.json +2 -2
  71. package/dist/assets/Addons-CjqcNK8h.js +0 -5
  72. package/dist/assets/AiProfiles-Cm2Q7JhZ.js +0 -3
  73. package/dist/assets/Data-n-6LtblT.js +0 -2
  74. package/dist/assets/History-D_aozO54.js +0 -1
  75. package/dist/assets/Identity-BmPRs4mg.js +0 -1
  76. package/dist/assets/IntegrationDetail-BSC9BD-J.js +0 -1
  77. package/dist/assets/Integrations-De2JyPXz.js +0 -1
  78. package/dist/assets/Locations-CUMzXXog.js +0 -3
  79. package/dist/assets/MyAccess-DqTYKZ2_.js +0 -2
  80. package/dist/assets/NodeAddonsSettingsPanel-DBYJefzi.js +0 -2
  81. package/dist/assets/Recordings-tBQ7GNq1.js +0 -1
  82. package/dist/assets/SessionsList-lLfA_jg3.js +0 -2
  83. package/dist/assets/StorageLocationsTable-DZjP3bRr.js +0 -1
  84. package/dist/assets/device-detail-BvB3nomd.js +0 -1
  85. package/dist/assets/device-picker-model-DRxal6IV.js +0 -1
  86. package/dist/assets/i18n-D9gvzMlq.js +0 -1
  87. package/dist/assets/index-C5CxkeN1.css +0 -2
  88. package/dist/assets/mount-DRxal6IV.js +0 -1
  89. package/dist/assets/remoteEntry-CCeILvpu.js +0 -1
  90. package/dist/assets/src-QaXiFLvn.js +0 -272
  91. package/dist/assets/useEventInvalidation-DRxal6IV.js +0 -1
  92. package/dist/assets/useTemplateSave-CoTTvn6r.js +0 -1
@@ -1 +1 @@
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{$t as f,A as p,Bn as m,Ct as h,D as g,Ha as _,In as v,It as y,Jn as b,Mn as x,Mr as S,N as C,O as w,Pr as T,Rr as E,Sr as D,St as O,T as k,Ti as A,Ua as j,V as M,Va as N,Wa as P,Xa as F,Yt as I,Zi as ee,_n as L,_t as R,b as z,ct as B,j as V,jr as te,k as H,kt as U,or as ne,qn as re,ri as ie,ui as ae,ut as W,v as oe,y as se,z as G}from"./player-overlays-D-xr6JNm.js";import{Ec as ce,Ii as le,Li as ue,Pi as de,Ri as fe,Rn as pe,ai as me,ci as he,f as ge,h as _e,ii as ve,li as ye,ni as be,oi as xe,p as Se,si as Ce,ui as we,zi as Te}from"./client-DbkHdobd.js";import{t as Ee}from"./chevron-down-CBb-F8DT.js";import{d as De,u as Oe}from"./terminal-DU-tvcEm.js";import{a as ke,i as Ae,n as je,r as Me,t as Ne}from"./usb-P4R9CjYI.js";import{t as Pe}from"./crop-B-t0rzRY.js";import{t as Fe}from"./layers-BH9u1mrE.js";import{n as Ie}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DzoL8nR8.js";import{$f as Le,$r as Re,$s as ze,Ar as Be,Au as Ve,Bl as He,Br as Ue,Ci as We,Da as Ge,Di as Ke,Du as qe,Ei as Je,Eu as Ye,F as Xe,Gl as Ze,Hl as Qe,Hr as $e,I as et,Jl as tt,Jr as nt,Kf as rt,Kl as it,L as at,Mu as ot,Of as K,Oi as st,Or as ct,Ou as lt,Pu as ut,Qr as dt,R as ft,Rf as q,Si as pt,Sp as mt,Sr as J,Ta as ht,Ti as gt,Tr as _t,Ur as vt,V as yt,Vl as bt,Wl as xt,Xl as St,Y as Ct,Yl as wt,_p as Y,_r as Tt,_u as Et,a as Dt,bp as Ot,bs as kt,ci as At,ct as jt,cu as Mt,da as Nt,di as Pt,du as Ft,ec as It,ei as Lt,eu as Rt,fu as zt,gu as Bt,hu as Vt,iu as Ht,ju as Ut,ki as Wt,kr as Gt,ku as Kt,mi as qt,mu as Jt,ni as Yt,nt as Xt,ou as Zt,qf as Qt,ql as $t,rr as en,ru as tn,st as nn,su as rn,tc as an,ti as on,tp as sn,ui as cn,ur as ln,uu as un,vp as dn,vu as fn,wa as pn,wi as mn,wr as hn,xn as gn,xp as _n,yn as vn,yp as yn,z as bn,zi as xn,zl as Sn}from"./src-QaXiFLvn.js";import{t as X}from"./i18n-D9gvzMlq.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{V as Cn,ci as wn,li as Tn,mi as En}from"./index-Xpk4gTbv.js";import"./useEventInvalidation-DRxal6IV.js";import{_ as Dn,a as On,b as kn,c as An,d as jn,f as Mn,g as Nn,h as Pn,i as Fn,l as In,m as Ln,n as Rn,p as zn,r as Bn,s as Vn,u as Hn,v as Un,y as Wn}from"./step-inspector-model-eI0Wac5U.js";import{t as Gn}from"./NodeAddonsSettingsPanel-DBYJefzi.js";import{a as Kn,c as qn,d as Jn,f as Yn,g as Xn,i as Zn,l as Qn,m as $n,n as er,o as tr,r as nr,s as rr,t as ir,u as ar,v as or,y as sr}from"./board-model-lauwzeiV.js";s();function cr(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 lr(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function ur(e){return e!==!1}function dr(e){return{pipeline:ur(lr(e,`detect`)),audio:ur(lr(e,`audio`)),ingest:ur(lr(e,`ingest`))}}function fr(e,t){let n=e?.find(e=>e.nodeId===t);return dr(n?.settings)}function pr({selectedNodeId:t,onSelect:n,refreshToken:r}){let a=F(),{t:o}=Z(),{nodes:s}=dn(),{data:c}=Zt(void 0),{data:l}=un(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(q,{variant:`unstyled`,type:`button`,onClick:()=>n($o),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(Oe,{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?v:A,p=fr(l,r.id),m=r.isOnline?null:gn(cr(r.lastSeen),a);return e(q,{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(y,{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(K,{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(K,{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 mr({nodeId:t,refreshToken:n}){let{t:r}=Z(),{nodes:a}=dn(),o=a?.find(e=>e.id===t),s=yn(`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 hr=[`assignments`,`tree`,`engines`,`logs`];function gr({refreshToken:t,nodeId:r}){let{t:a}=Z(),[s,c]=o(new Map),{nodes:l}=Y();_n(`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}=St(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(Q,{label:`FPS`,value:t?t.totalFps.toFixed(1):`—`}),i(Q,{label:a(`pipeline.liveLoadPanel.activeAttached`,`Active / Attached`),value:t?`${t.activeCameras}/${t.attachedCameras}`:`—`}),i(Q,{label:a(`pipeline.liveLoadPanel.avgInferMs`,`Avg infer ms`),value:t&&t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),i(Q,{label:a(`pipeline.liveLoadPanel.queue`,`Queue`),value:t?String(t.queueDepth):`—`}),i(Q,{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(Q,{label:a(`pipeline.liveLoadPanel.totalAgents`,`Total agents`),value:`${m.onlineAgents}/${m.totalAgents}`}),i(Q,{label:a(`pipeline.liveLoadPanel.activeAttached`,`Active / Attached`),value:`${m.activeCameras}/${m.attachedCameras}`}),i(Q,{label:a(`pipeline.liveLoadPanel.totalFps`,`Total FPS`),value:m.totalFps.toFixed(1)}),i(Q,{label:a(`pipeline.liveLoadPanel.avgInferenceMs`,`Avg inference ms`),value:m.avgInferenceTimeMs.toFixed(0)}),i(Q,{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 Q({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 _r={active:!1,pinned:!1,nodeId:null,reason:``};function vr(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function yr(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??``}:_r,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:_r;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:_r,audio:o}}).toSorted(vr)}function br(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function xr(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:br(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:br(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:br(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function Sr(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(vr)}function Cr(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 wr(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??X.t(`helpers.assignmentRows.cameraFallback`,{id:e})}function Tr(e,t,n){let r=[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])];return[{value:`auto`,label:X.t(`helpers.assignmentRows.auto`)},...r.map(e=>({value:e,label:X.t(`helpers.assignmentRows.pinTo`,{node:n(e)})}))]}function Er({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(ct,{roleId:e,roleLabel:t,nodeName:r(s),colorId:Be(a,s),emphasized:c,pinned:n.pinned})}function Dr({detection:t,decoder:n,audio:r,nameOf:a,colorByNodeId:o,emphasizeOnNodeId:s}){let c=(e,t,n)=>i(Er,{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 Or({snap:t}){let n=F(),{t:r}=Z();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=ln(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(Ct,{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 kr=1e4,Ar=5e3;function jr(e){let[t,n]=o(new Map);return _n(`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()-kr,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},Ar);return()=>clearInterval(e)},[t.size]),t}var Mr=3e5;function Nr({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:a}){let{t:o}=Z();return i(W,{"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:[...Tr(e,t,n)],onChange:e=>a(e.target.value)})}function Pr({deviceId:e,nodeId:t}){let{t:n}=Z(),r=l(),{data:a}=rn({deviceId:e},{refetchOnMount:`always`}),{data:o}=Ht({nodeId:t},{staleTime:Mr}),s=lt({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?`${cn(p)} (${d})`:d})}]:[],...u.map(e=>({value:e.key,label:`${cn(e)} · ${e.format}`}))];return i(W,{"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 Fr(e){let n=t(null);return e.nodeId!==null&&(n.current=e),n.current}function Ir({deviceId:t,state:n,...r}){let{t:a}=Z(),o=Fr(n);return e(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[i(Nr,{state:n,...r}),o?.nodeId==null?i(W,{"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(Pr,{deviceId:t,nodeId:o.nodeId})]})}function Lr({state:t,nameOf:n}){let{t:r}=Z(),a=Fr(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 Rr({deviceId:t,deviceName:n}){let{t:r}=Z(),[a,s]=o(!1);return e(d,{children:[i(Qt,{icon:b,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(We,{open:a,onOpenChange:s,children:e(gt,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[i(st,{children:i(Wt,{children:r(`pipeline.clusterRowCells.brokersTitle`,{device:n})})}),i(mn,{children:a&&i(pt,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t,instanceId:`pipeline-row/${t}`,config:{variant:`compact`}})})]})})]})}function zr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function Br(e,t){return t.size===0?!0:t.has(e)}var Vr=[{value:`active`,get label(){return X.t(`helpers.cameraActivity.active`)}},{value:`recently-active`,get label(){return X.t(`helpers.cameraActivity.recentlyActive`)}},{value:`inactive`,get label(){return X.t(`helpers.cameraActivity.inactive`)}}];s();var Hr=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function Ur(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function Wr(){let{t}=Z(),r=l();Dt([`pipelineOrchestrator`,`getPipelineAssignments`],Hr),Dt([`pipelineOrchestrator`,`getAudioAssignments`],Hr),Dt([`pipelineOrchestrator`,`getCameraStatuses`],Hr);let{data:a}=kt({isCamera:!0,projection:`slim`}),{data:s}=Zt(void 0),{data:c}=wt(void 0),{data:u}=Rt({}),{data:d}=un(void 0),{nodes:f}=Y(),p=jr(),m=n(()=>Cr(f),[f]),h=n(()=>Gt(d),[d]),g=n(()=>f.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[f]),_=n(()=>xr(yr((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=>Br(zr({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=()=>Ur(r),C=Ze({onSuccess:S}),w=ot({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(Tn,{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(K,{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(Ir,{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(Dr,{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(Lr,{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(Or,{snap:p.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>i(Rr,{deviceId:e.deviceId,deviceName:e.deviceName})}],D=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:Vr.map(e=>{let t=v.has(e.value);return i(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:P(se,t?oe:z),onClick:()=>x(e.value),children:e.label},e.value)})})}),i(hn,{columns:E,rows:b,rowKey:e=>e.deviceId,minWidthPx:920,maxBodyHeight:_t,emptyMessage:D})]})}s();function Gr({nodeId:e}){let{t}=Z(),r=l();Dt([`pipelineOrchestrator`,`getCameraStatuses`],Hr);let{data:a}=Rt({}),{data:o}=un(void 0),{data:s}=kt({isCamera:!0,projection:`slim`}),{nodes:c}=Y(),u=jr(),d=n(()=>Cr(c),[c]),f=n(()=>Gt(o),[o]),p=n(()=>Sr(e,a??[],wr((s??[]).map(e=>({id:e.id,name:e.name})))),[e,a,s]),m=c.filter(t=>t.isOnline&&t.id!==e),h=()=>Ur(r),g=Ze({onSuccess:h}),_=ot({onSuccess:h}),v=xt({onSuccess:h}),y=Ut({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(hn,{columns:[{key:`camera`,header:t(`pipeline.nodeCameraAssignmentsTable.camera`,`Camera`),width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(Tn,{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(Dr,{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(Or,{snap:u.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>i(vn,{items:b(e),title:t(`pipeline.nodeCameraAssignmentsTable.move`,`Move {{deviceName}}`,{deviceName:e.deviceName})})}],rows:p,rowKey:e=>e.deviceId,minWidthPx:560,maxBodyHeight:_t,emptyMessage:a===void 0?t(`pipeline.nodeCameraAssignmentsTable.loadingCameras`,`Loading cameras…`):t(`pipeline.nodeCameraAssignmentsTable.noCameraRunsOnThis`,`No camera runs on this node right now`)})}function Kr({nodeId:t,refreshToken:n}){let{t:r}=Z(),{nodes:a}=Y(),o=a.find(e=>e.id===t)?.name??t;return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(gr,{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(Gr,{nodeId:t})]})]})}s();function qr(e,t){let n=Math.max(0,t-e),r=Math.floor(e/1e3),i=Math.floor(n/1e3);return X.t(`pipeline.nodeEnginesTab.idleLeft`,{idle:r,left:i})}function Jr({nodeId:t,refreshToken:r}){let{t:a}=Z(),o=l(),s=B(),c=He({onSettled:()=>{o.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:u}=bt({nodeId:t}),d=yn(`pipeline.engine-metrics-snapshot`,e=>e.nodeId===t)?.engines??u??null,p=d===null;Dt([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:m}=ut({nodeId:t}),{values:h}=Ot(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,e=>e.nodeId===t),g=n(()=>h.filter(e=>e.metrics.phase===`active`).length,[h]),_=e=>{let n=m??[];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:(m??[]).length,active:g})})]}),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:[p&&i(`tr`,{children:i(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:a(`common.loading`,`Loading…`)})}),!p&&(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?Fe:A,{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(O,{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:qr(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:(m??[]).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(q,{variant:`ghost`,size:`sm`,disabled:c.isPending,onClick:()=>_(t.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[i(f,{className:`h-3.5 w-3.5`}),a(`pipeline.nodeEnginesTab.kill`,`Kill`)]})})]},t.engineKey)}),!p&&(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(wn,{i18nKey:`pipeline.nodeEnginesTab.legend`,components:{strong:i(`strong`,{className:`text-foreground`})}})}),c.isError&&i(Nt,{message:a(`pipeline.nodeEnginesTab.killFailed`,{message:c.error instanceof Error?c.error.message:a(`common.unknownError`)})})]})}var Yr=`pipeline-runner`,Xr=200;function Zr({nodeId:t}){let{t:n}=Z();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(en,{agentId:t,addonId:Yr,limit:Xr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1,showSourceSelect:!0})})]})}s();function Qr({nodeId:t,title:r}){let a=F(),{t:o}=Z(),{data:s}=Cn(),{data:c}=Zt(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=jr(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=ln(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(Ct,{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 $r(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 ei(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 ti=`pipeline-analytics`,ni=`face-gallery`,ri=`pipeline-orchestrator`,ii=`pipeline-runner`,ai=`audio-analyzer`;function oi(e){return[...ve.filter(t=>t.stepId===e).map(e=>xe(e.stepId)),...me.filter(t=>t.stepId===e).map(e=>he(e.stepId,e.key))]}var si=`faces`,ci=`semantic-search`,li=`load-balancer`,ui=`load`,di=[{id:si,get title(){return X.t(`helpers.clusterSettingsSections.facesTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.facesHint`)},panels:[{addonId:ri,fieldKeys:oi(`face-embedding`)},{addonId:ti,capability:ni}]},{id:ci,get title(){return X.t(`helpers.clusterSettingsSections.semanticTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.semanticHint`)},panels:[{addonId:ri,fieldKeys:oi(`clip-embedding`)}]},{id:Se,get title(){return X.t(`helpers.clusterSettingsSections.cropTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.cropHint`)},panels:[{addonId:ri,sectionIds:[Se]}]},{id:ge,get title(){return X.t(`helpers.clusterSettingsSections.nativeTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.nativeHint`)},panels:[{addonId:ri,sectionIds:[ge]}]},{id:`runner-defaults`,get title(){return X.t(`helpers.clusterSettingsSections.runnerTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.runnerHint`)},panels:[{addonId:ii,fieldScope:`cluster`},{addonId:ai,fieldScope:`cluster`}]},{id:li,get title(){return X.t(`helpers.clusterSettingsSections.loadTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.loadHint`)},panels:[{addonId:ri,sectionIds:[ui]}]},{id:`failover`,get title(){return X.t(`helpers.clusterSettingsSections.failoverTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.failoverHint`)},panels:[{addonId:ri,sectionIds:[`failover`]}]}],fi={"cluster-step-models":si};function pi(e){return e===`clip-embedding`?ci:si}var mi=`ctab`,hi=`section`;function gi(e,t){let n=new URLSearchParams({view:`nodes`,node:$o,[mi]:e});return t!==void 0&&n.set(hi,t),`/system/pipeline?${n.toString()}`}function _i(e){return gi(`settings`,pi(e))}function vi(){return gi(`load-balancing`)}var yi=`pipeline-orchestrator`;function bi(e){return ve.find(t=>t.stepId===e)??null}function xi({step:t,engineFormat:n,runnableModelIds:r}){let{t:a}=Z(),{data:o}=ht({addonId:yi,cap:yi,scope:`cluster`}),s=ye(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(Tn,{to:_i(t.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:a(`pipeline.clusterStepModel.changeInClusterSettings`,`Change in Cluster → Settings ›`)})]}),e(`p`,{className:G,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(wn,{i18nKey:`pipeline.clusterStepModel.noBuild`,values:{engine:n,model:s,index:t.indexName},components:{b:i(`b`,{})}})})]})}var Si=`pipeline-orchestrator`;function Ci({addonId:t,highlightLabel:n}){let{t:r}=Z(),a=Ce(t),{data:o}=ht({addonId:Si,cap:Si,scope:`cluster`});if(a.length===0)return null;let s=we(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:M,children:r(`stepInspector.clusterOwnedSettings.clusterWideSettings`,`Cluster-wide settings`)}),i(Tn,{to:_i(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:V,children:t.label}),i(`span`,{className:C,children:i(`span`,{className:`font-mono text-xs text-foreground`,children:String(s[t.key]??t.default)})})]},t.key)),i(`p`,{className:G,children:r(`stepInspector.clusterOwnedSettings.oneValueForEveryNode`,`One value for every node and camera — this step writes into a shared index.`)})]})}function wi({rows:t,hint:n}){let{t:r}=Z();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:`${k} 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(Tn,{to:t.href,className:`ml-auto text-[11px] text-primary hover:underline`,children:r(`stepInspector.effectiveModelSummary.changeOnAccelerator`)})]},t.id))}),i(`p`,{className:G,children:n??r(`stepInspector.effectiveModelSummary.toChangeAModelOpen`,`To change a model, open that accelerator's cell in the table.`)})]})}s();function Ti(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:cn(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Ei({tree:a,searchRows:s,accelerators:c,cellState:l,stepBadge:u,disabledCount:d,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:g,summary:v,toolbar:y,label:b,renderDetail:x}){let{t:S}=Z(),C=B(),w=Le(),{selection:T,open:E,close:D}=Ln(n(()=>On(a).map(e=>e.node.addonId),[a]),n(()=>c.map(e=>e.id),[c])),[O,k]=o(``),[A,j]=o(null),[M,N]=o(null),P=t(null),F=t(null),I=t(null);sn(I);let ee=t(null),L=n(()=>et(s,O),[s,O]),R=n(()=>O.trim()===``?a:Bn(a,new Set(L.map(e=>e.addonId))),[a,L,O]),z=e=>L.find(t=>t.addonId===e)?.matchedField??null,V=n(()=>c.map(Ti),[c]),te=e=>c.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),H=c.find(e=>e.id===T.acceleratorId)??null,U=T.stepId!==null,ne=r(async e=>{if(m){if(!await C({title:S(`stepInspector.stepMatrixFrame.discardUnsavedChanges`,`Discard unsaved changes?`),message:S(`stepInspector.stepMatrixFrame.thisStepHasChangesThat`,`This step has changes that are not saved yet.`),confirmLabel:S(`stepInspector.stepMatrixFrame.discard`,`Discard`),variant:`danger`}))return;g()}e()},[C,m,g,S]),re=()=>{requestAnimationFrame(()=>ee.current?.focus())},ie=(e,t,n=!1)=>{if(e===T.stepId&&(t?.id??null)===T.acceleratorId){n&&re();return}let r=()=>{j(z(e)),E({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&re()};e===T.stepId?r():ne(r)},ae=()=>{let e=T.stepId;ne(()=>{if(D(),e!==null){let t=H===null?null:jt({agentNodeId:H.nodeId,deviceKey:H.deviceKey});requestAnimationFrame(()=>P.current?.focusCell(e,t))}})},W=e=>{if(e.key===`Enter`){let t=L[0];if(t===void 0)return;e.preventDefault(),ie(t.addonId,void 0,!0)}else e.key===`Escape`&&k(``)},oe=w?i(bn,{onClick:ae}):i(Qt,{icon:h,variant:`ghost`,size:`sm`,"aria-label":S(`common.close`,`Close`),onClick:ae});return e(`div`,{ref:F,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),I.current?.focus()),e.key===`Escape`&&t&&U&&(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:v}),i(rt,{ref:I,type:`search`,value:O,onChange:e=>k(e.target.value),onKeyDown:W,placeholder:S(`stepInspector.stepMatrixFrame.filterStepsOrSettings`,`Filter steps or settings /`),"aria-label":S(`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(_,{checked:f,onChange:e=>p(e.target.checked)}),S(`stepInspector.stepMatrixFrame.showDisabled`,{count:d})]}),y]}),T.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:S(`stepInspector.stepMatrixFrame.staleStep`,{id:T.staleStepId})}),R.length===0?i(`p`,{className:`${G} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:S(`stepInspector.stepMatrixFrame.noStepMatches`,{query:O})}):i(nn,{ref:P,tree:R,agents:V,label:b,getCellState:(e,t)=>{let n=te(t);return n===void 0?{kind:`na`}:l(e,n)},onCellClick:(e,t,n)=>ie(e,te(t),n),onStepClick:(e,t)=>ie(e,void 0,t),...u===void 0?{}:{stepBadge:u},selectedCell:U&&T.stepId!==null&&H!==null?{addonId:T.stepId,agentNodeId:H.nodeId,deviceKey:H.deviceKey}:null,fallbackNodeId:M,onFallbackNodeChange:N,reserveRightPx:U&&!w?432:0}),i(yt,{open:U,anchor:F,onClose:ae,label:S(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:T.stepId!==null&&x({stepId:T.stepId,accelerator:H,matchedField:A,closeButton:oe,onEscape:ae,headingRef:e=>{ee.current=e}})})]})}s();function Di(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 Oi(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 ki(e,t){return t===void 0?0:[...new Set([...Object.keys(e),...Object.keys(t)])].filter(n=>!_e(e[n],t[n])).length}function Ai(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=ki(n,t.nodeSettings),s=t.accelerator===void 0?0:ki(r(t.accelerator.deviceKey),t.accelerator.settings);return i+a+o+s}function ji({nodeId:t,nodeName:r,toolbar:a}){let{t:s}=Z(),c=l(),u=Ht({nodeId:t},{refetchOnMount:`always`}),f=Sn({nodeId:t},{refetchOnMount:`always`}),p=tt({agentNodeId:t},{refetchOnMount:`always`}),m=p.data?.stepSettings,h=ye(ht({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=Et({onSuccess:()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),T=qe({onSuccess:()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]})}}),[E,D]=o(!1),O=n(()=>_?Xe(_):[],[_]),k=n(()=>On(O),[O]),[A,j]=o(!1),N=n(()=>Vn(t,r,g,A),[t,r,g,A]),P=n(()=>Vn(t,r,g),[t,r,g]),F=P.length>=2,I=(e,t)=>$r(g,t?.deviceKey,e,m)??{},ee=e=>m?.[e]??{},L=(e,t)=>g.find(e=>e.key===t)?.steps?.[e]?.settings??{},R=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return P.find(e=>e.deviceKey===r);if(!In(e,t))return P.filter(n=>n.id!==t.id&&In(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},z=(e,t)=>{let n=Fn(_,e),r=bi(e),i=An(_,t),a=I(e,t),o=R(n,t);return Rn({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?Mn(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...zn(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:h[e]??r.defaultModelId}:{},...o?{jumpTo:Pt(o.device)}:{}})},B=k.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:jn(Fn(_,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 V=e(`span`,{className:G,children:[s(`stepInspector.nodeStepInspector.accelerators`,`Accelerators:`),` `,i(`span`,{className:`text-foreground`,children:P.length>0?P.map(e=>Pt(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(Pt).join(`, `)]}),` `,`·`,` `,i(Tn,{to:vi(),className:`text-primary hover:underline`,children:s(`stepInspector.nodeStepInspector.clusterLoadBalancing`,`Cluster → Load balancing ›`)})]});return i(Ei,{tree:O,searchRows:B,accelerators:N,cellState:z,disabledCount:g.filter(e=>!e.enabled).length,showDisabled:A,onShowDisabledChange:j,dirty:v!==null&&Ai(g,v,ee(v.stepId),e=>L(v.stepId,e))>0,onDiscard:()=>y(null),summary:V,...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=Fn(_,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??P[0]??N[0],h=p?.nodeSettings??ee(n),O=a===null?{}:p?.accelerator?.deviceKey===a.deviceKey?p.accelerator.settings:L(n,a.deviceKey),k={...h,...O},A=Ai(g,p,ee(n),e=>L(n,e)),j=e=>{C(null),y(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},z=bi(n),B=Lt(f),{nodeFields:V,acceleratorFields:te}=Hn(B),H=new Set(te.flatMap(e=>`key`in e?[e.key,`${e.key}ModelId`]:[])),U=m===void 0?void 0:An(_,m),ne=e=>{let t=p?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},re=m===void 0?void 0:Mn(f,m,{nodePin:ne(m)}).modelId,ie=t=>{let r=ne(t),o=Mn(f,t,{nodePin:r}),c=An(_,t),l=zn(n,a?.id===t.id?k:I(n,t),c),u=p?.jumps[t.deviceKey],m=R(f,t,u),h=In(f,t)?l&&c?i(dt,{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=F?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(W,{"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)`)},...P.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:G,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:At(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}},ae=async()=>{if(p!==null){D(!0);try{(Object.keys(p.models).length>0||Object.keys(p.jumps).length>0||p.accelerator!==void 0)&&await w.mutateAsync({agentNodeId:t,inferenceDevices:ei(Oi(g,p,e=>H.has(e)))}),p.nodeSettings!==void 0&&ki(ee(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{D(!1)}}};return i(ft,{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 ae(),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:M,children:s(`stepInspector.nodeStepInspector.model`,`Model`)}),z!==null&&m!==void 0?i(xi,{step:z,engineFormat:m.device.format,runnableModelIds:At(f.models??[],m.device.format).map(e=>e.id)}):N.length===0?i(`p`,{className:G,children:i(wn,{i18nKey:`stepInspector.nodeStepInspector.noAcceleratorEnabled`,components:{link:i(Tn,{to:vi(),className:`text-primary hover:underline`})}})}):a===null?i(wi,{rows:N.map(e=>{let t=Mn(f,e,{nodePin:ne(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):i(at,{...ie(a)},a.id)]}),(B.length>0||U!==void 0)&&z===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})}),(V.length>0||U!==void 0)&&i(Mi,{addon:f,fields:V,settings:h,layerLabel:s(`stepInspector.nodeStepInspector.nodeLayer`,`Node`),modelId:Re(f,re,k,U),root:U,highlight:o,onChange:e=>j({nodeSettings:e})}),te.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(Mi,{addon:f,fields:te,settings:O,layerLabel:s(`stepInspector.nodeStepInspector.acceleratorLayer`,`This accelerator`),modelId:Re(f,re,k,U),root:void 0,highlight:o,onChange:e=>j({accelerator:{deviceKey:a.deviceKey,settings:e}})})]}))]}),i(Ci,{addonId:n,highlightLabel:o})]})})}})}function Mi({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 Di(l===null?null:Yt(l)),i(on,{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 Ni({nodeId:t,refreshToken:n}){let{t:r}=Z(),a=B(),[s,c]=o(null),{nodes:l}=Y(),u=l.find(e=>e.id===t)?.name??t,f=Jt({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(Qr,{nodeId:t}),i(ji,{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(q,{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 Pi=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],Fi=`decoder-nodeav`,Ii=`ntab`,Li={decoder:`engine`},Ri={engine:`Engine & decoder`},zi=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function Bi({nodeId:t,refreshToken:n}){let{t:r}=Z(),[a,o]=En(),{nodes:s}=Y(),c=s.find(e=>e.id===t)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??Fi,l=[...Pi,c],u=a.get(Ii),d={assignments:{id:`assignments`,label:r(`pipeline.nodeDetail.assignments`,`Assignments`),order:-10,content:i(Kr,{nodeId:t,refreshToken:n})},tree:{id:`tree`,label:r(`pipeline.nodeDetail.pipeline`,`Pipeline`),order:39,content:i(Ni,{nodeId:t,refreshToken:n})},engines:{id:`engines`,label:r(`pipeline.nodeDetail.warmInstances`,`Warm instances`),order:180,content:i(Jr,{nodeId:t,refreshToken:n})},logs:{id:`logs`,label:r(`pipeline.nodeDetail.logs`,`Logs`),order:300,content:i(Zr,{nodeId:t})}},f=hr.map(e=>d[e]);return e(`div`,{className:`flex flex-col h-full`,children:[i(mr,{nodeId:t,refreshToken:n}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:i(Gn,{nodeId:t,addonIds:l,level:`global`,fieldScope:`perNode`,emptyMessage:zi,tabAliases:Li,tabLabelOverrides:Ri,extraTabs:f,activeTab:u===null?null:Li[u]??u,onActiveTabChange:e=>o(t=>{let n=new URLSearchParams(t);n.set(Ii,e);for(let e of Pn)n.delete(e);return n},{replace:!0})})})]})}function Vi(){let{t}=Z();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(Wr,{})]})}function Hi(e){return`${Math.round(e*100)}%`}function Ui(e){return X.t(`helpers.autoTuneViewModel.sessions`,{count:e})}var Wi={"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`},Gi={"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 Ki(e){return e===null?`—`:Wi[e]??e}function qi(e){return e===null?`—`:Gi[e]??e}function Ji(e){switch(e.kind){case`capacity`:return X.t(`helpers.autoTuneViewModel.capacity`,{sessions:Ui(e.sessions),min:e.minSessions});case`tie-faster`:return X.t(`helpers.autoTuneViewModel.tieFaster`,{over:e.over,recall:Hi(e.recallDelta)});case`stepped-down`:return X.t(`helpers.autoTuneViewModel.steppedDown`,{from:e.from,limitedBy:e.limitedBy,to:e.to});case`no-fit-lightest`:return X.t(`helpers.autoTuneViewModel.noFitLightest`,{min:Ui(e.minSessions),sessions:Ui(e.sessions)});case`derived-latency`:return X.t(`helpers.autoTuneViewModel.derivedLatency`,{modelId:e.modelId});case`cpu-device`:return X.t(`helpers.autoTuneViewModel.cpuDevice`);case`device-disabled`:return X.t(`helpers.autoTuneViewModel.deviceDisabled`);case`device-unavailable`:return X.t(`helpers.autoTuneViewModel.deviceUnavailable`);case`node-offline`:return X.t(`helpers.autoTuneViewModel.nodeOffline`);case`no-hardware-facts`:return X.t(`helpers.autoTuneViewModel.noHardwareFacts`);case`no-measured-data`:return X.t(`helpers.autoTuneViewModel.noMeasuredData`);case`no-family-build`:return X.t(`helpers.autoTuneViewModel.noFamilyBuild`,{format:e.format});case`kept-custom-pin`:return X.t(`helpers.autoTuneViewModel.keptCustomPin`,{modelId:e.modelId,deviceKey:e.deviceKey})}}function Yi(e,t){switch(e.kind){case`custom-pin-kept`:return X.t(`helpers.autoTuneViewModel.customPinNode`,{node:t(e.nodeId),modelId:e.modelId,deviceKey:e.deviceKey});case`custom-registry-unreadable`:return X.t(`helpers.autoTuneViewModel.customRegistryUnreadable`,{error:e.error})}}function Xi(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 Zi(e){let t=Xi(e);return t.modelChanges+t.thresholdClears===0}function Qi(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 $i(e,t){return e?.kind===`node-benchmark`?X.t(`helpers.autoTuneViewModel.latencyMeasured`,{date:new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}):e?.kind===`estimated`?X.t(`helpers.autoTuneViewModel.latencyEstimated`,{hardware:qi(e.estimatedFrom)}):X.t(`helpers.autoTuneViewModel.latencyTable`)}s();var ea=[.3,.4,.5];function ta(e){return ea.some(t=>t===e)}var na=[1,2,3,4,6,8];function ra({plan:t,node:n,nodeName:r}){let{t:a}=Z();return e(`section`,{className:w,"data-testid":`auto-tune-node-${n.nodeId}`,children:[e(`header`,{className:`${H} flex flex-wrap items-center gap-2`,children:[i(A,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),i(`h3`,{className:`${M} min-w-0 flex-1`,children:r(n.nodeId)}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[qi(n.hardwareClass),n.cpuModel===null?``:` · ${n.cpuModel}`]}),n.skipped?i(K,{variant:`warning`,children:a(`pipeline.clusterAutoTuneTab.notChanged`,`Not changed`)}):n.acceleratorModelId!==null&&i(K,{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:Ji(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=Qi(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:Ki(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:$i(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:Ji(e)},t))})]},r.deviceKey)})})]})})]})}function ia({plan:t,nodeName:n}){let{t:r}=Z();return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:e(`div`,{children:[i(`div`,{className:M,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 aa({result:t}){let{t:n}=Z();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 oa(){let{t}=Z(),r=l(),[a,s]=o(.4),[c,u]=o(2),[d,f]=o(!1),[p,m]=o(!1),[h,g]=o(null),{nodes:_}=Y(),v=n(()=>Cr(_),[_]),y=Ft({headroom:a,minSessionsPerDevice:c},{enabled:d,refetchOnWindowFocus:!1}),b=Qe({onSuccess:e=>{g(e),m(!1),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.kind===`applied`&&y.refetch()}}),x=h?.kind===`stale`?h.plan:y.data,S=x===void 0?null:Xi(x);return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[e(`section`,{className:w,children:[e(`header`,{className:`${H} flex flex-wrap items-center gap-2`,children:[i(L,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),i(`h3`,{className:`${M} 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(W,{"aria-label":t(`pipeline.clusterAutoTuneTab.shareOfEachAcceleratorKept`,`Share of each accelerator kept free`),value:String(a),options:ea.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);ta(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(W,{"aria-label":t(`pipeline.clusterAutoTuneTab.minimumParallelSessionsPerDevice`,`Minimum parallel sessions per device`),value:String(c),options:na.map(e=>({value:String(e),label:t(`pipeline.clusterAutoTuneTab.camerasAtOnce`,{count:e})})),onChange:e=>{let t=Number(e.target.value);na.some(e=>e===t)&&u(t)}})]}),i(q,{size:`sm`,variant:`secondary`,onClick:()=>{g(null),f(!0),d&&y.refetch()},children:y.isFetching?t(`pipeline.clusterAutoTuneTab.computing`,`Computing…`):x===void 0?t(`pipeline.clusterAutoTuneTab.computePlan`,`Compute plan`):t(`pipeline.clusterAutoTuneTab.recompute`,`Recompute`)}),x!==void 0&&i(q,{size:`sm`,disabled:Zi(x),onClick:()=>m(!0),children:t(`pipeline.clusterAutoTuneTab.apply`,`Apply…`)})]}),y.error!==null&&i(`div`,{className:`text-danger`,children:y.error.message}),h!==null&&i(aa,{result:h}),S!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:t(`pipeline.clusterAutoTuneTab.planSummary`,{modelChanges:S.modelChanges,thresholdClears:S.thresholdClears})})]})]}),x?.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:Yi(e,v)},t)),x?.nodes.map(e=>i(ra,{plan:x,node:e,nodeName:v},e.nodeId)),x!==void 0&&i(We,{open:p,onOpenChange:m,children:e(gt,{width:`lg`,scroll:`body`,children:[e(st,{children:[i(Wt,{children:t(`pipeline.clusterAutoTuneTab.applyAutoTune`,`Apply auto tune?`)}),i(Je,{children:t(`pipeline.clusterAutoTuneTab.theseAreAllTheChanges`,`These are all the changes. Every override listed is removed and cannot be restored.`)})]}),i(mn,{children:i(ia,{plan:x,nodeName:v})}),e(Ke,{children:[i(q,{variant:`ghost`,onClick:()=>m(!1),children:t(`common.cancel`,`Cancel`)}),i(q,{variant:`danger`,disabled:b.isPending,onClick:()=>b.mutate({planHash:x.planHash,headroom:a,minSessionsPerDevice:c}),children:b.isPending?t(`pipeline.clusterAutoTuneTab.applying`,`Applying…`):t(`common.apply`,`Apply`)})]})]})})]})}var sa={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 ca(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function la(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function ua(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:cn(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?ca(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 da(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=ua(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),la(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?ca(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?ca(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}s();var fa=2e4,pa=3e5;function ma({stats:e,targetWeights:t,showAccelerators:r=!0}){let{t:a}=Z(),{nodes:o}=Y(),s=R().trpcClient,l=$t(void 0,{placeholderData:u,staleTime:fa,refetchInterval:fa,refetchOnWindowFocus:!0}),d=un(void 0,{staleTime:pa}),f=n(()=>o.map(e=>e.id),[o]),p=c({queries:f.map(e=>({queryKey:Ie(mt.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>s.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:pa,refetchOnWindowFocus:!1,placeholderData:u}))}),m=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(`|`)]),h=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=h.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:dr(n).pipeline,weight:t?.[e.id]??$n(n,`detectWeight`)??1,maxCameras:$n(n,`maxCameras`)}}),[o,h,t]),v=l.data??[],y=n(()=>da({nodes:_,loads:v,devicesByNode:m}),[_,v,m]),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(J,{headingId:`load-balancing-node-load`,title:a(`pipeline.nodeLoadOverview.nodeLoad`,`Node load`),icon:N,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:g,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(ha,{row:e,placed:C.get(e.nodeId),showAccelerators:r},e.nodeId))})})})}function ha({row:t,placed:n,showAccelerators:r}){let{t:a}=Z(),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(I,{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(U,{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(va,{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(va,{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(va,{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(va,{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(va,{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(va,{label:a(`pipeline.nodeLoadOverview.capFill`,`Cap fill`),value:`${t.capacityPct}%`,title:a(`pipeline.nodeLoadOverview.attachedMaxcameras`,`attached / maxCameras.`)}),t.avgInferenceTimeMs!==null&&i(va,{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(va,{label:a(`pipeline.nodeLoadOverview.decode`,`Decode`),value:t.decodeHwaccel,title:a(`pipeline.nodeLoadOverview.thisNodeSProbedDecode`,`This node's probed decode hwaccel.`)})]}),r&&i(ga,{row:t})]})}function ga({row:t}){let{t:n}=Z();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(ie,{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(_a,{device:e},e.key))})]})}function _a({device:t}){let{t:n}=Z(),r=t.exclusion;return e(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[i(A,{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(sa[r]),children:n(`pipeline.nodeLoadOverview.excludedWith`,{reason:n(sa[r])})})]})}function va({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 ya(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function ba(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 xa(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Sa(e){return e.reason===`disabled`?X.t(`helpers.loadBalancingViewModel.stalePinDisabled`,{deviceKey:e.deviceKey}):X.t(`helpers.loadBalancingViewModel.stalePinMissing`,{deviceKey:e.deviceKey})}function Ca(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 wa(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 X.t(`helpers.loadBalancingViewModel.shareNote`,{count:n.length,names:i,into:r})}var Ta=[{value:`hardware`,get label(){return X.t(`helpers.loadBalancingViewModel.hardwareLabel`)},get hint(){return X.t(`helpers.loadBalancingViewModel.hardwareHint`)}},{value:`benchmark`,get label(){return X.t(`helpers.loadBalancingViewModel.benchmarkLabel`)},get hint(){return X.t(`helpers.loadBalancingViewModel.benchmarkHint`)}},{value:`manual`,get label(){return X.t(`helpers.loadBalancingViewModel.manualLabel`)},get hint(){return X.t(`helpers.loadBalancingViewModel.manualHint`)}}];function Ea(e){return e===`no-benchmark-results`?X.t(`helpers.loadBalancingViewModel.fallbackNone`):e===`partial-benchmark-results`?X.t(`helpers.loadBalancingViewModel.fallbackPartial`):null}function Da(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)}: ${Ea(e.capacityFallback)??``}`).join(` · `)}s();function Oa(e,t,n){return Math.min(Math.max(e,t),n)}function ka(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 Aa(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:Oa(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 ja(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 Ma({nodes:t,pending:n,onCommitWeights:r,weightLabel:s=`Detection weight`,emptyHint:c,footnote:l,readOnly:u=!1}){let{t:f}=Z(),[p,m]=o(()=>ka(t)),[h,g]=o(new Set);a(()=>{m(ka(t)),g(e=>new Set([...e].filter(e=>t.some(t=>t.id===e))))},[t.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let _=t.map(e=>e.id),v=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},y=(e,t)=>{m(n=>Aa(n,e,t,h,_))},b=()=>{let e=ja(p,_,h),n=t.filter(t=>(e[t.id]??0)!==t.weight).map(e=>e.id);if(n.length===0)return;let i=new Set([...n,...h]);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??f(`placementBoard.weightSliderStack.noDetectEnabledNodesEnable`,`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`)});let x=t.length===1;return e(`div`,{className:`space-y-3`,children:[t.map(t=>{let r=p[t.id]??0,a=h.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(j,{"aria-label":f(`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||x,onChange:e=>y(t.id,Number(e.target.value)),onPointerUp:()=>b(),onKeyUp:()=>b(),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(q,{variant:`unstyled`,type:`button`,onClick:()=>v(t.id),disabled:n||x,"aria-pressed":a,title:a?f(`placementBoard.weightSliderStack.unlockAllowRebalancing`,`Unlock — allow rebalancing`):f(`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?te:S,{className:`h-3.5 w-3.5`})})]},t.id)}),i(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:l??i(d,{children:f(`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 Na(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 Pa(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 Fa(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:Pa(e),share:t===void 0?null:{configuredPct:t.configuredPct,effectivePct:t.effectivePct},sessionsNow:a,atCap:a!==null&&e.maxSessions!==null&&a>=e.maxSessions}})}var Ia={active:`success`,disabled:`neutral`,absent:`danger`,unknown:`neutral`,unavailable:`warning`,backoff:`warning`,"root-incapable":`info`,standby:`neutral`};s();function La(e){let t=cn(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:A,hue:`slate`}:r===`npu`?{label:t,Icon:O,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:ke,hue:`violet`}:n===`edgetpu`?{label:t,Icon:Ne,hue:`emerald`}:{label:t,Icon:A,hue:`slate`}}var Ra={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`]},za={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 Ba({nodeId:t,nodeName:r,isOnline:s,suggestedMaxSessions:c,shareSource:u,sharesAutomatic:p,share:m,placed:h}){let{t:g}=Z(),_=l(),{data:v,isLoading:y}=Ht({nodeId:t},{refetchInterval:15e3}),b=()=>{_.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},x=Et({onSettled:b}),S=it({onSettled:b}),C=mt.platformProbe.rescanAccelerators.useMutation({onSettled:b}),w=v?.devices??[],T=v?.reachable??s,[E,D]=o({});a(()=>{D(Object.fromEntries(w.map(e=>[e.key,Va(e)])))},[w.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let O=n(()=>w.filter(e=>(E[e.key]?.enabled??e.enabled)&&e.available).length,[w,E]),[k,A]=o(null),j=k??!0,M=e=>{let n=w.map(t=>{let n=e[t.key]??Va(t);return{key:t.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});x.mutate({agentNodeId:t,inferenceDevices:ei(n)})},N=(e,t)=>{let n=E[e.key]??Va(e),r={...E,[e.key]:{...n,...t}};D(r),M(r)},P=n(()=>Fa(w,m,h),[w,m,h]),F=n(()=>w.filter(e=>(E[e.key]?.enabled??e.enabled)&&e.available),[w,E]),I=n(()=>F.map(e=>({id:e.key,name:La(e).label,weight:E[e.key]?.weight??e.weight})),[F,E]),L=e=>{let t={...E};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}D(t),M(t)},R=x.isPending||S.isPending,z=Ha(g,p?u:`manual`),B=[{key:`device`,header:g(`placementBoard.nodeInferenceDevices.colDevice`,`Device`),nowrap:!1,sortValue:e=>La(e.device).label,render:e=>i(Wa,{row:e,steps:E[e.device.key]?.steps})},{key:`state`,header:g(`placementBoard.nodeInferenceDevices.colState`,`State`),sortValue:e=>e.state,render:e=>i(`span`,{title:g(za[e.state][0],za[e.state][1]),children:i(K,{variant:Ia[e.state],size:`sm`,children:g(Ra[e.state][0],Ra[e.state][1])})})},{key:`share`,header:g(`placementBoard.nodeInferenceDevices.colShare`,`Share`),align:`right`,sortValue:e=>e.share?.effectivePct??null,render:e=>i(Ga,{row:e,sourceLabel:z})},{key:`sessions`,header:g(`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(K,{variant:`warning`,size:`sm`,className:`ml-1`,children:g(`placementBoard.nodeInferenceDevices.atCap`,`at cap`)})]})},{key:`cap`,header:g(`placementBoard.nodeInferenceDevices.colCap`,`Max sessions`),notSortableReason:g(`placementBoard.nodeInferenceDevices.capNotSortable`,`An editable field: sort by Sessions instead.`),render:t=>{let n=E[t.device.key]??Va(t.device);if(!(n.enabled&&t.device.available))return i(`span`,{className:`text-xs text-foreground-subtle`,children:`—`});let r=La(t.device).label;return e(`div`,{className:`flex items-center justify-end gap-1`,children:[i(rt,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:e=>{let n=e.target.value.trim(),r=n===``?null:Number.parseInt(n,10);N(t.device,{maxSessions:r!==null&&r>0?r:null})},disabled:R,"aria-label":g(`placementBoard.nodeInferenceDevices.maxConcurrentSessionsFor`,`Max concurrent sessions for {{label}}`,{label:r}),className:`w-16 text-right`}),i(Ka,{suggested:c?.[t.device.key]??null,current:n.maxSessions,pending:R,onApply:e=>N(t.device,{maxSessions:e})})]})}},{key:`enabled`,header:g(`placementBoard.nodeInferenceDevices.colEnabled`,`Enabled`),align:`right`,notSortableReason:g(`placementBoard.nodeInferenceDevices.enabledNotSortable`,`A switch: sort by State instead.`),render:e=>{let n=La(e.device).label;if(e.state===`absent`)return i(Tt,{label:g(`placementBoard.nodeInferenceDevices.forget`,`Forget`),icon:f,size:`sm`,triggerVariant:`ghost`,disabled:R,title:g(`placementBoard.nodeInferenceDevices.forgetTitle`,`Forget {{label}} on {{node}}?`,{label:n,node:r}),description:g(`placementBoard.nodeInferenceDevices.forgetDescription`,`Its stored settings (switch, weight, cap, step models) are deleted. If the device comes back it starts from the defaults.`),action:()=>S.mutateAsync({agentNodeId:t,deviceKey:e.device.key})});let a=E[e.device.key]??Va(e.device);return i(nt,{checked:a.enabled&&e.device.available,onCheckedChange:()=>N(e.device,{enabled:!a.enabled}),disabled:!e.device.available||R,"aria-label":g(`placementBoard.nodeInferenceDevices.enable`,`Enable {{label}}`,{label:n})})}}],V=x.error??S.error??C.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(q,{variant:`ghost`,size:`sm`,onClick:()=>A(!j),className:`min-w-0 flex-1 justify-start`,"aria-expanded":j,children:[i(ee,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${j?`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:T?e(d,{children:[i(Fe,{className:`h-3.5 w-3.5`}),g(`pipeline.nodeInferenceDevices.accelerators`,{count:O})]}):e(d,{children:[i(U,{className:`h-3.5 w-3.5`}),` `,g(`common.unreachable`)]})})]}),e(q,{variant:`ghost`,size:`sm`,onClick:()=>C.mutate({nodeId:t}),disabled:C.isPending||!T,title:g(`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(re,{className:`h-3.5 w-3.5 ${C.isPending?`animate-spin`:``}`}),g(`placementBoard.nodeInferenceDevices.rescan`,`Rescan`)]})]}),j&&e(`div`,{className:`space-y-3 border-t border-border p-3`,children:[T?y&&w.length===0?i(`p`,{className:`text-center text-xs text-foreground-subtle`,children:g(`placementBoard.nodeInferenceDevices.probingAccelerators`,`Probing accelerators…`)}):i(hn,{columns:B,rows:P,rowKey:e=>e.device.key,minWidthPx:640,bordered:!1,emptyMessage:g(`placementBoard.nodeInferenceDevices.noInferenceDevicesReportedBy`,`No inference devices reported by this node's platform probe.`)}):i(qa,{}),C.data!==void 0&&i(`p`,{className:`text-xs text-foreground-subtle`,children:Ua(g,C.data.appeared,C.data.disappeared)}),T&&!p&&F.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(je,{className:`h-3.5 w-3.5`}),g(`placementBoard.nodeInferenceDevices.acceleratorShare`,`Accelerator share`)]}),i(Ma,{nodes:I,pending:R,onCommitWeights:L,weightLabel:`Accelerator share`,footnote:g(`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%.`)})]}),V!=null&&e(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-xs text-danger`,children:[g(`placementBoard.nodeInferenceDevices.failedToSaveInferenceDevices`,`Failed to save inference devices:`),` `,V.message]})]})]})}function Va(e){return{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}}function Ha(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 Ua(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 Wa({row:t,steps:n}){let r=La(t.device),a=Na({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(K,{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(wn,{i18nKey:`pipeline.nodeInferenceDevices.rootModel`,values:{model:a},components:{mono:i(`span`,{className:`font-mono text-foreground-muted`})}})})]})]})]})]})}function Ga({row:t,sourceLabel:n}){let{t:r}=Z();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 Ka({suggested:e,current:t,pending:n,onApply:r}){let{t:a}=Z();return e===null||e<1||e===t?null:i(q,{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 qa(){let{t}=Z();return e(`div`,{className:`flex flex-col items-center gap-2 px-4 py-6 text-center`,children:[i(U,{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 Ja=3600*1e3,Ya=2e4,Xa=.4;function Za({refreshToken:t,onOpenAutoTune:r}){let{t:a}=Z(),s=l(),{nodes:c}=Y(),f=un(void 0),p=kt({isCamera:!0,projection:`slim`}),m=Mt({windowMs:Ja},{refetchInterval:Ya,placeholderData:u}).data,h=tn(void 0,{refetchInterval:Ya,placeholderData:u}).data,_=()=>{Yn(s),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},v=Ye({onSuccess:_}),y=Kt({onSuccess:()=>{_(),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),b=fn({onSuccess:_}),x=zt(),[S,C]=o(!1),w=h?.source,T=w===`benchmark`?`benchmark`:`hardware`,D=Ve({headroom:Xa,source:T},{enabled:S,staleTime:1/0}),j=D.data,M=n(()=>{let e=new Map((f.data??[]).map(e=>[e.nodeId,e.settings]));return c.filter(t=>dr(e.get(t.id)).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:$n(n,`detectWeight`)??1,maxCameras:$n(n,`maxCameras`)}})},[c,f.data]),N=e=>c.find(t=>t.id===e)?.name??e,P=wr((p.data??[]).map(e=>({id:e.id,name:e.name}))),F=j?xa(j):void 0,I=Ca(M,h),ee=w!==`manual`,R=h!==void 0&&h.source!==`manual`&&!h.autoPending,z=e=>h?.nodes.find(t=>t.nodeId===e),B=e=>m?.nodes.find(t=>t.nodeId===e),V=h?wa(h,N):null,te=h?Da(h,N):null,H=Ta.find(e=>e.value===w)?.hint;return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(gr,{refreshToken:t}),i(ma,{stats:m,showAccelerators:!1,...h!==void 0&&h.source!==`manual`&&!h.autoPending?{targetWeights:Object.fromEntries(h.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),i(J,{headingId:`load-balancing-node-shares`,title:a(`pipeline.clusterLoadBalancingTab.nodeShares`,`Node shares`),icon:je,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:Ta.map(e=>i(q,{role:`radio`,"aria-checked":w===e.value,variant:w===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:y.isPending||h===void 0,onClick:()=>{w!==e.value&&y.mutate({source:e.value})},children:e.label},e.value))}),e(q,{variant:`outline`,size:`sm`,onClick:()=>{C(!0),S&&D.refetch()},disabled:D.isFetching,children:[i(E,{className:`h-3.5 w-3.5`}),D.isFetching?a(`pipeline.clusterLoadBalancingTab.suggesting`,`Suggesting…`):T===`benchmark`?a(`pipeline.clusterLoadBalancingTab.suggestFromBenchmark`,`Suggest from benchmark`):a(`pipeline.clusterLoadBalancingTab.suggestFromHardware`,`Suggest from hardware`)]}),e(q,{variant:`ghost`,size:`sm`,onClick:r,children:[i(L,{className:`h-3.5 w-3.5`}),a(`pipeline.clusterLoadBalancingTab.autoTune`,`Auto tune`)]}),e(q,{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(O,{className:`h-3.5 w-3.5`}),x.isPending?a(`pipeline.clusterLoadBalancingTab.rebalancing`,`Rebalancing…`):a(`pipeline.clusterLoadBalancingTab.rebalance`,`Rebalance`)]})]}),children:e(`div`,{className:`${g} space-y-3`,children:[H!==void 0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:H}),m&&e(`p`,{className:`text-[10px] text-foreground-subtle`,children:[a(`pipeline.clusterLoadBalancingTab.policy`,`Policy:`),` `,i(K,{variant:m.policy===`share`?`info`:`default`,children:m.policy===`share`?a(`pipeline.clusterLoadBalancingTab.honourShares`,`honour shares`):`least-loaded`}),` `,` · ${a(`pipeline.clusterLoadBalancingTab.clusterPeak`,{count:m.clusterPeakSessions})}`,m.policy===`least-loaded`&&` · ${a(`pipeline.clusterLoadBalancingTab.leastLoadedNote`)}`]}),i(Ma,{nodes:I.nodes,pending:v.isPending,readOnly:I.readOnly,onCommitWeights:e=>v.mutate(ya(e)),weightLabel:`Node share`,...I.readOnly?{footnote:h?.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`),h?.computedAt!=null&&i(`span`,{className:`ml-1`,children:a(h.trigger===null?`pipeline.clusterLoadBalancingTab.lastAt`:`pipeline.clusterLoadBalancingTab.lastAtTrigger`,{time:new Date(h.computedAt).toLocaleTimeString(),trigger:h.trigger??``})}),`.`]})}:{}}),V!==null&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:V}),te!==null&&i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:te}),y.isError&&i(Nt,{message:a(`pipeline.clusterLoadBalancingTab.switchFailed`,{message:y.error instanceof Error?y.error.message:a(`common.unknownError`)})}),v.isError&&i(Nt,{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:`${k} 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:M.map(t=>e(`li`,{className:`${k} flex items-center gap-2`,children:[i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:t.name}),i(rt,{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:`${k} ${G} 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(Nt,{message:a(`pipeline.clusterLoadBalancingTab.suggestionFailed`,{message:D.error instanceof Error?D.error.message:a(`common.unknownError`)})}),j&&i(Qa,{suggestion:j,nameOf:N,pending:v.isPending,...ee?{}:{onApply:()=>v.mutate(ba(j))}}),i(J,{headingId:`load-balancing-accelerators`,title:a(`pipeline.clusterLoadBalancingTab.accelerators`,`Accelerators`),icon:A,children:i(`div`,{className:`${g} space-y-2`,children:M.length===0?i(xn,{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.`)}):M.map(e=>i(Ba,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...F?.[e.id]===void 0?{}:{suggestedMaxSessions:F[e.id]},sharesAutomatic:R,...h===void 0?{}:{shareSource:h.source},...z(e.id)===void 0?{}:{share:z(e.id)},...B(e.id)===void 0?{}:{placed:B(e.id)}},e.id))})}),m!==void 0&&m.stalePins.length>0&&i($a,{stats:m,cameraName:P})]})}function Qa({suggestion:t,nameOf:n,pending:r,onApply:a}){let{t:o}=Z();return e(J,{headingId:`load-balancing-suggestion`,title:t.source===`benchmark`?o(`pipeline.clusterLoadBalancingTab.suggestedFromBenchmark`,`Suggested from benchmark`):o(`pipeline.clusterLoadBalancingTab.suggestedFromHardware`,`Suggested from hardware`),icon:E,...a===void 0?{}:{actions:i(q,{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:`${k} 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:G,children:[Ea(t.capacityFallback)===null?``:`${Ea(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:`${k} ${G} 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 $a({stats:t,cameraName:n}){let{t:r}=Z(),a=l(),o=lt({onSuccess:()=>{a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return i(J,{headingId:`load-balancing-stale-pins`,title:r(`pipeline.clusterLoadBalancingTab.staleDevicePins`,`Stale device pins`),icon:Me,children:i(`ul`,{className:`divide-y divide-border`,children:t.stalePins.map(t=>e(`li`,{className:`${k} 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:G,children:Sa(t)})]}),i(q,{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 eo({node:t,emphasis:n=!1}){let{t:r}=Z(),a=t.isHub?v:A;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(K,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:r(`common.hubWord`)}),!t.isOnline&&i(K,{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 to({nodes:e,actions:t}){let{t:n}=Z();return i(hn,{columns:[{key:`node`,header:n(`placementBoard.nodeCapabilitiesTable.node`,`Node`),sortValue:e=>e.name,render:e=>i(eo,{node:e})},...nr.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(nt,{"aria-label":n(`placementBoard.nodeCapabilitiesTable.on`,`{{label}} on {{name}}`,{label:n(e.labelKey),name:r.name}),title:n(e.hintKey),checked:Jn(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 no({roleValues:t,options:n,pending:r,onRoleChange:a}){let{t:o}=Z(),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:ar.map(n=>e(`li`,{className:`${k} 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:sr(n)}),i(`p`,{className:G,children:or(n)})]}),i(`div`,{className:`w-full sm:w-48`,children:i(W,{"aria-label":o(`placementBoard.roleControls.node`,`{{value1}} node`,{value1:sr(n)}),value:t[n],disabled:r,options:s,onChange:e=>a(n,e.target.value)})})]},n))})}s();function ro(){let{t}=Z(),r=l(),{nodes:a}=Y(),o=un(void 0),s=ht({addonId:Zn,cap:Kn,scope:`cluster`}),c=ht({addonId:rr,cap:qn,scope:`cluster`}),u=ht({addonId:ir,cap:er,scope:`cluster`}),d=()=>Yn(r),f=Bt({onSuccess:d}),p=Ge({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=dr(t);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[a,m]),g={ingestNode:Xn(s.data,`ingestNode`,`hub`),recordingNode:Xn(c.data,Qn,`hub`),audioNode:Xn(s.data,`audioNode`,`hub`),motionNode:Xn(s.data,`motionNode`,`hub`),postProcessingNode:Xn(u.data,tr,`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`,...ar.map(e=>g[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:t(e)}))},[a,g]),y=o.isLoading||s.isLoading||c.isLoading||u.isLoading,b=(e,t,n)=>{f.mutate({agentNodeId:e,[t]:n})},x=(e,t)=>{if(e===`recordingNode`){p.mutate({addonId:rr,cap:qn,scope:`cluster`,patch:{[Qn]:t}});return}if(e===`postProcessingNode`){p.mutate({addonId:ir,cap:er,scope:`cluster`,patch:{[tr]:t}});return}p.mutate({addonId:Zn,cap:Kn,scope:`cluster`,patch:{[e]:t}})},S={capabilityPending:f.isPending,onToggleCapability:b},C=y?i(T,{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(J,{headingId:`roles-nodes-cluster-roles`,title:t(`pipeline.clusterRolesNodesTab.clusterRoles`,`Cluster roles`),icon:Ae,actions:C,children:[i(`p`,{className:`${G} 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(no,{roleValues:g,options:_,pending:p.isPending,onRoleChange:x})]}),i(J,{headingId:`roles-nodes-node-capabilities`,title:t(`pipeline.clusterRolesNodesTab.nodeCapabilities`,`Node capabilities`),icon:v,children:i(to,{nodes:h,actions:S})})]})}s();var io=2500,ao={faces:m,"semantic-search":L,"detail-crop":Pe,"native-lease":Fe,"runner-defaults":A,"load-balancer":je,failover:x},oo=[`cluster`,ui];function so(e){a(()=>{if(e===null)return;let t=fi[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`),io),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function co({section:t}){let{t:n}=Z();return i(`div`,{"data-cluster-settings-card":t.id,className:`rounded-lg`,children:i(J,{headingId:`cluster-settings-${t.id}`,title:t.title,...ao[t.id]===void 0?{}:{icon:ao[t.id]},children:e(`div`,{className:`${g} space-y-3`,children:[i(`p`,{className:G,children:t.hint}),t.panels.map(e=>i(Gn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:oo.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.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function lo({refreshToken:e}){let[t]=En();return so(t.get(hi)),i(`div`,{className:`space-y-3 sm:space-y-4`,children:di.map(e=>i(co,{section:e},e.id))})}function uo(e){return e?.hex}function fo({hex:e}){return i(`span`,{className:`inline-block h-3 w-3 shrink-0 rounded-sm border border-border`,style:{backgroundColor:e}})}function po({id:t,label:n,swatch:r}){let a=uo(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 mo({ground:t,group:n,swatches:r}){let{t:a}=Z();return e(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[i(po,{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(po,{id:e.id,label:e.label,swatch:r[e.id]},e.id))})]})]})}function ho({swatches:t}){let{t:n}=Z(),r=pe(),a=[{id:`dark`,background:ue.dark,ink:ue.light},{id:`light`,background:ue.light,ink:ue.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(mo,{ground:e.id,group:n,swatches:t},n.id))},e.id))]})}function go(e){for(let t of pe()){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 _o(e){return/^#[0-9a-f]{6}$/.test(e)}function vo(e,t){let n={};for(let r of Te){let i=t[r],a=e[r];i===void 0||a===void 0||i.hex!==a.hex&&(n[r]=i)}return n}function yo({status:t,reason:r,source:a,presetId:s,customized:c,swatches:l,presets:u,saving:d,onApply:f}){let{t:p}=Z(),[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:le(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(!_o(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(J,{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(q,{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=uo(t.swatches[e]);return n===void 0?null:i(fo,{hex:n},e)}),t.name]})},t.id)),i(q,{type:`button`,size:`sm`,variant:m?`primary`:`outline`,onClick:C,disabled:d||b===void 0,children:p(`pipeline.palette.custom`,`Custom`)})]})}),i(ho,{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(J,{headingId:`palette-custom`,title:p(`pipeline.palette.custom`,`Custom`),children:e(`div`,{className:`flex flex-col gap-2 p-3`,children:[Te.map(e=>{let t=uo(v[e]);return t===void 0?null:i(qt,{field:{type:`color`,key:e,label:go(e)},values:{[e]:t},onChange:(t,n)=>w(e,n)},e)}),i(q,{type:`button`,size:`sm`,onClick:()=>{if(b===void 0||x===null||!x.ok)return;let e=vo(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 bo(){let e=ze({}),t=It({}),n=an(),r=r=>{n.mutate(r,{onSuccess:()=>{e.refetch(),t.refetch()}})};if(e.isPending||t.isPending)return i(yo,{status:`pending`,presets:[],onApply:r});if(e.isError||e.data===void 0)return i(yo,{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(yo,{status:`unknown`,reason:String(t.error),presets:[],saving:n.isPending,onApply:r});if(e.data.status===`unknown`)return i(yo,{status:`unknown`,reason:e.data.reason,presets:t.data,saving:n.isPending,onApply:r});let a=e.data;return i(yo,{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 xo=`pipeline-orchestrator`,So=200;function Co(){let{t}=Z();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(en,{addonId:xo,limit:So,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1,showSourceSelect:!0})})]})}var wo=[{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 To(e){return wo.some(t=>t.id===e)}function Eo({refreshToken:t}){let{t:n}=Z(),[r,a]=En(),o=r.get(mi),s=To(o)?o:`assignments`,c=e=>{a(t=>{let n=new URLSearchParams(t);return n.set(mi,e),n.delete(hi),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(Ue,{value:s,onValueChange:e=>{To(e)&&c(e)},className:`px-4 sm:px-6`,children:i($e,{className:`border-border`,children:wo.map(e=>i(vt,{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(Vi,{}),s===`load-balancing`&&i(Za,{refreshToken:t,onOpenAutoTune:()=>c(`auto-tune`)}),s===`auto-tune`&&i(oa,{}),s===`roles-nodes`&&i(ro,{}),s===`settings`&&i(lo,{refreshToken:t}),s===`logs`&&i(Co,{}),s===`palette`&&i(bo,{})]})]})}function Do({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(Oo,{})]})}function Oo(){let{t:e}=Z();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 ko={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 Ao({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 ${ko[e]}`,children:t})}function jo({children:e}){return i(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Mo({icon:t,label:n,nodeId:r,pinned:a,reason:o,overridden:s}){let{t:c}=Z();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(ne,{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 No({assignment:t,settings:n,onlineNodes:r,pinPending:a,onDetectionPinChange:o}){let{t:s}=Z(),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(Do,{title:s(`cameras.configBlocks.whereItRuns`,`Where it runs`),children:[i(Mo,{icon:A,label:s(`cameras.configBlocks.detection`,`Detection`),nodeId:t.detectionNodeId,pinned:t.pinned.detection,reason:t.reasons.detection,overridden:n.overriddenKeys.has(`pipelineNodeId`)}),i(Mo,{icon:ae,label:s(`cameras.configBlocks.decoder`,`Decoder`),nodeId:t.decoderNodeId,pinned:t.pinned.decoder,reason:t.reasons.decoder,overridden:n.overriddenKeys.has(`decoderNodeId`)}),i(Mo,{icon:D,label:s(`cameras.configBlocks.audio`,`Audio`),nodeId:t.audioNodeId,pinned:t.pinned.audio,reason:t.reasons.audio,overridden:n.overriddenKeys.has(`audioNodeId`)}),i(Mo,{icon:b,label:s(`cameras.configBlocks.source`,`Source`),nodeId:t.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),i(`div`,{className:`mt-1.5`,children:e(W,{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 Po(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Fo(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function Io(e){return e===null?X.t(`pipeline.configBlocks.fpsDefault`):e===0?X.t(`pipeline.configBlocks.fpsNative`):`${e} fps`}function Lo({streams:t,brokerProfiles:n,settings:r,motionEnabled:a,motionFpsLive:o,cameraSensors:s}){let{t:c}=Z(),l=Fo(n,r.detectionStreamProfile),u=Fo(n,r.motionStreamProfile),f=r.motionSources.includes(`analyzer`);return e(Do,{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:Io(r.detectionFps)}),e($,{label:c(`cameras.configBlocks.motionSrc`,`Motion src`),overridden:r.overriddenKeys.has(`motionSources`),children:[r.motionSources.length>0?r.motionSources.map(be).join(` + `):c(`cameras.configBlocks.none`),a===!1&&` · ${c(`cameras.configBlocks.inactive`)}`]}),i($,{label:c(`cameras.configBlocks.cameraSensors`,`Camera sensors`),children:Nn(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:[Io(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(jo,{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}),` `,Po(t)]},t.camStreamId))})]})}function Ro({steps:t,audioModelId:n,audioEnabled:r,audioMode:a}){let{t:o}=Z();return e(Do,{title:o(`cameras.configBlocks.pipelineSteps`,`Pipeline steps`),children:[t===void 0?i(jo,{children:o(`cameras.configBlocks.resolving`,`Resolving…`)}):t.length===0?i(jo,{children:o(`cameras.configBlocks.noStepsConfigured`,`No steps configured`)}):i(`div`,{className:`flex flex-wrap gap-1`,children:t.map((t,n)=>i(Ao,{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 zo={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Bo({detection:t,live:n,detectionMode:r,modeOverridden:a}){let o=F(),{t:s}=Z();if(t===null)return e(Do,{title:s(`cameras.runtimeBlocks.detectionRuntime`,`Detection runtime`),children:[i($,{label:s(`cameras.runtimeBlocks.mode`,`Mode`),overridden:a,children:r??`—`}),i(jo,{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=ln(c,o),m=c===`active`&&l===0;return e(Do,{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(Ct,{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(Ao,{tone:zo[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 Vo({broker:t}){let{t:n}=Z();return t===null?i(Do,{title:n(`cameras.runtimeBlocks.streamBroker`,`Stream broker`),children:i(jo,{children:n(`cameras.runtimeBlocks.brokerStageInactiveOrUnreachable`,`Broker stage inactive or unreachable`)})}):e(Do,{title:n(`cameras.runtimeBlocks.streamBroker`,`Stream broker`),children:[t.profiles.length===0?i(jo,{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(Ao,{tone:t.webrtcSessions>0?`info`:`neutral`,children:n(`cameras.runtimeBlocks.webrtc`,{count:t.webrtcSessions})}),i(Ao,{tone:t.rtspRestream?`success`:`neutral`,children:t.rtspRestream?n(`cameras.runtimeBlocks.restreamOn`):n(`cameras.runtimeBlocks.restreamOff`)})]})]})}function Ho({decoder:e}){let{t}=Z();return e===null?i(Do,{title:t(`cameras.runtimeBlocks.decoder`,`Decoder`),children:i(jo,{children:t(`cameras.runtimeBlocks.decoderStageInactiveOrUnreachable`,`Decoder stage inactive or unreachable`)})}):i(Do,{title:t(`cameras.runtimeBlocks.decoder`,`Decoder`),children:i($,{label:t(`cameras.runtimeBlocks.node`,`Node`),children:e.nodeId})})}s();var Uo=`pipeline-orchestrator`,Wo={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Go={healthy:`pipeline.cameraPipelineCard.healthHealthy`,idle:`pipeline.cameraPipelineCard.healthIdle`,error:`pipeline.cameraPipelineCard.healthError`};function Ko({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(I,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),i(`span`,{className:`min-w-0`,children:t.message})]},t.code))})}function qo({deviceId:t,name:r,online:a,status:o,live:s,onlineNodes:c}){let{t:u}=Z(),d=l(),{data:f}=pn({addonId:Uo,deviceId:t,nodeId:`hub`},{staleTime:3e4}),{data:p}=Vt({deviceId:t},{staleTime:3e4}),m=n(()=>Un(f),[f]),h=n(()=>p===void 0?void 0:Wn(p.steps),[p]),g=n(()=>o===void 0?[]:Dn(o),[o]),_=()=>{d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=Ze({onSuccess:_}),y=ot({onSuccess:_}),b=e=>{e===`auto`?y.mutate({deviceId:t}):v.mutate({deviceId:t,agentNodeId:e})},x=o===void 0?`idle`:kn(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`:Wo[x]}`,title:S?u(`common.error`,`Error`):u(Go[x]),"aria-label":S?u(`common.error`,`Error`):u(Go[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(Ao,{tone:`danger`,children:u(`common.offline`)}),e(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[m.detectionMode!==null&&i(Ao,{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(Ao,{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(Ao,{tone:`neutral`,title:u(`cameras.cameraPipelineCard.recordingMode`,`Recording mode`),children:u(`pipeline.cameraPipelineCard.recMode`,{mode:o.recording.mode})}))]})]}),g.length>0&&i(Ko,{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(No,{assignment:o.assignment,settings:m,onlineNodes:c,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),i(Bo,{detection:o.detection,live:s,detectionMode:m.detectionMode,modeOverridden:m.overriddenKeys.has(`detectionMode`)}),i(Ro,{steps:h,audioModelId:p?.audio?.modelId??null,audioEnabled:o.audio?.enabled??p?.audio?.enabled??null,audioMode:m.audioMode}),i(Lo,{streams:o.source.streams,brokerProfiles:o.broker?.profiles,settings:m,motionEnabled:o.motion?.enabled??null,motionFpsLive:o.motion?.fps??null,cameraSensors:o.cameraSensors}),i(Vo,{broker:o.broker}),i(Ho,{decoder:o.decoder})]})]})}s();var Jo=5e3,Yo=1e4,Xo=5e3;function Zo(e){let t=l(),{data:r,isLoading:i}=Cn(),{data:s,isLoading:c}=Rt({},{refetchInterval:Jo}),{nodes:u}=Y();a(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[d,f]=o(new Map);_n(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()-Yo,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Xo);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 Qo({refreshToken:t}){let{t:r}=Z(),{rows:a,liveMetrics:o,onlineNodes:s,isLoading:c}=Zo(t),l=n(()=>[...a.map(e=>{let t=e.status===void 0?[]:Dn(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(wn,{i18nKey:`pipeline.camerasOverview.camerasTotal`,values:{count:u.total},components:{b:i(`span`,{className:`font-semibold text-foreground`})}})}),i(`span`,{children:i(wn,{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(qo,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:o.get(e.deviceId),onlineNodes:s},e.deviceId))]})})}s();var $o=`__cluster__`;function es(e){return e===`cameras`?`cameras`:`nodes`}function ts({viewMode:t,onNodes:n,onCameras:r}){let{t:a}=Z();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 ns(){let{t}=Z(),[n,r]=En(),s=es(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`,$o),t},{replace:!0})},[s,n,r]),e(Xt,{icon:De,title:t(`pipeline.pipeline`,`Pipeline`),subtitle:t(`pipeline.detectionPlacementLoadAndPer`,`Detection placement, load and per-camera runtime across the cluster.`),actions:e(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>u(e=>e+1),title:t(`common.refresh`,`Refresh`),children:[i(re,{className:`h-3.5 w-3.5`}),t(`common.refresh`,`Refresh`)]}),nav:i(ts,{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(q,{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(Ee,{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(pr,{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(Eo,{refreshToken:l}):i(Bi,{nodeId:c,refreshToken:l})})]}):i(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:i(Qo,{refreshToken:l})})})]})}export{ns as PipelinePage};
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{$t as f,A as p,Bn as m,Ct as h,D as g,Ha as _,In as v,It as y,Jn as b,Mn as x,Mr as S,N as C,O as w,Pr as T,Rr as E,Sr as D,St as O,T as k,Ti as A,Ua as j,V as M,Va as N,Wa as P,Xa as F,Yt as I,Zi as ee,_n as L,_t as R,b as z,ct as B,j as V,jr as te,k as H,kt as U,or as ne,qn as re,ri as ie,ui as ae,ut as W,v as oe,y as se,z as G}from"./player-overlays-D-xr6JNm.js";import{Ec as ce,Ii as le,Li as ue,Pi as de,Ri as fe,Rn as pe,ai as me,ci as he,f as ge,h as _e,ii as ve,li as ye,ni as be,oi as xe,p as Se,si as Ce,ui as we,zi as Te}from"./client-DbkHdobd.js";import{t as Ee}from"./chevron-down-CBb-F8DT.js";import{d as De,u as Oe}from"./terminal-DU-tvcEm.js";import{a as ke,i as Ae,n as je,r as Me,t as Ne}from"./usb-P4R9CjYI.js";import{t as Pe}from"./crop-B-t0rzRY.js";import{t as Fe}from"./layers-BH9u1mrE.js";import{n as Ie}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DzoL8nR8.js";import{$r as Le,Ai as Re,Ar as ze,Au as Be,Bi as Ve,Bl as He,Ci as Ue,Cp as We,Cr as K,Di as Ge,Du as Ke,Ea as qe,Ei as Je,Er as Ye,F as Xe,Fu as Ze,Gl as Qe,Hl as $e,I as et,Jf as tt,Jl as nt,Kl as rt,L as it,Mu as at,Nu as ot,Oa as st,Oi as ct,Ou as lt,R as ut,Sn as dt,Sp as ft,Ta as pt,Ti as mt,Tr as ht,Ul as gt,Ur as _t,V as vt,Vl as yt,Vr as bt,Wr as xt,Xl as St,Y as Ct,Yl as wt,Yr as Tt,Zl as Et,_u as Dt,a as Ot,au as kt,bn as At,bp as jt,ct as Mt,cu as Nt,di as Pt,dr as Ft,du as It,ec as Lt,ei as Rt,ep as zt,fa as Bt,fi as Vt,fu as Ht,gu as Ut,hi as Wt,hu as Gt,ir as Kt,iu as qt,jr as Jt,ju as Yt,kf as q,ki as Xt,kr as Zt,ku as Qt,li as $t,lu as en,nc as tn,ni as nn,np as rn,nt as an,pu as on,qf as sn,ql as cn,ri as ln,st as un,su as dn,tc as fn,ti as pn,tu as mn,vp as J,vr as hn,vu as gn,wi as _n,xp as vn,xs as yn,yp as bn,yu as xn,z as Sn,zf as Y}from"./src-CxMNFQ7c.js";import{t as X}from"./i18n-CThuXMc5.js";import{t as Z}from"./useTranslation-BJr-n0es.js";import{V as Cn,ci as wn,li as Tn,mi as En}from"./index-DUv1kIQf.js";import"./useEventInvalidation-BFaT-X3C.js";import{_ as Dn,a as On,b as kn,c as An,d as jn,f as Mn,g as Nn,h as Pn,i as Fn,l as In,m as Ln,n as Rn,p as zn,r as Bn,s as Vn,u as Hn,v as Un,y as Wn}from"./step-inspector-model-BAZSRIbI.js";import{t as Gn}from"./NodeAddonsSettingsPanel-YGDDqLon.js";import{a as Kn,c as qn,d as Jn,f as Yn,g as Xn,i as Zn,l as Qn,m as $n,n as er,o as tr,r as nr,s as rr,t as ir,u as ar,v as or,y as sr}from"./board-model-DnTtSG-0.js";s();function cr(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 lr(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function ur(e){return e!==!1}function dr(e){return{pipeline:ur(lr(e,`detect`)),audio:ur(lr(e,`audio`)),ingest:ur(lr(e,`ingest`))}}function fr(e,t){let n=e?.find(e=>e.nodeId===t);return dr(n?.settings)}function pr({selectedNodeId:t,onSelect:n,refreshToken:r}){let a=F(),{t:o}=Z(),{nodes:s}=bn(),{data:c}=dn(void 0),{data:l}=It(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(Y,{variant:`unstyled`,type:`button`,onClick:()=>n($o),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(Oe,{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?v:A,p=fr(l,r.id),m=r.isOnline?null:dt(cr(r.lastSeen),a);return e(Y,{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(y,{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 mr({nodeId:t,refreshToken:n}){let{t:r}=Z(),{nodes:a}=bn(),o=a?.find(e=>e.id===t),s=jt(`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 hr=[`assignments`,`tree`,`engines`,`logs`];function gr({refreshToken:t,nodeId:r}){let{t:a}=Z(),[s,c]=o(new Map),{nodes:l}=J();ft(`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}=Et(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(Q,{label:`FPS`,value:t?t.totalFps.toFixed(1):`—`}),i(Q,{label:a(`pipeline.liveLoadPanel.activeAttached`,`Active / Attached`),value:t?`${t.activeCameras}/${t.attachedCameras}`:`—`}),i(Q,{label:a(`pipeline.liveLoadPanel.avgInferMs`,`Avg infer ms`),value:t&&t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),i(Q,{label:a(`pipeline.liveLoadPanel.queue`,`Queue`),value:t?String(t.queueDepth):`—`}),i(Q,{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(Q,{label:a(`pipeline.liveLoadPanel.totalAgents`,`Total agents`),value:`${m.onlineAgents}/${m.totalAgents}`}),i(Q,{label:a(`pipeline.liveLoadPanel.activeAttached`,`Active / Attached`),value:`${m.activeCameras}/${m.attachedCameras}`}),i(Q,{label:a(`pipeline.liveLoadPanel.totalFps`,`Total FPS`),value:m.totalFps.toFixed(1)}),i(Q,{label:a(`pipeline.liveLoadPanel.avgInferenceMs`,`Avg inference ms`),value:m.avgInferenceTimeMs.toFixed(0)}),i(Q,{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 Q({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 _r={active:!1,pinned:!1,nodeId:null,reason:``};function vr(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function yr(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??``}:_r,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:_r;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:_r,audio:o}}).toSorted(vr)}function br(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function xr(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:br(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:br(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:br(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function Sr(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(vr)}function Cr(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 wr(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??X.t(`helpers.assignmentRows.cameraFallback`,{id:e})}function Tr(e,t,n){let r=[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])];return[{value:`auto`,label:X.t(`helpers.assignmentRows.auto`)},...r.map(e=>({value:e,label:X.t(`helpers.assignmentRows.pinTo`,{node:n(e)})}))]}function Er({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(Zt,{roleId:e,roleLabel:t,nodeName:r(s),colorId:Jt(a,s),emphasized:c,pinned:n.pinned})}function Dr({detection:t,decoder:n,audio:r,nameOf:a,colorByNodeId:o,emphasizeOnNodeId:s}){let c=(e,t,n)=>i(Er,{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 Or({snap:t}){let n=F(),{t:r}=Z();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=Ft(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(Ct,{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 kr=1e4,Ar=5e3;function jr(e){let[t,n]=o(new Map);return ft(`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()-kr,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},Ar);return()=>clearInterval(e)},[t.size]),t}var Mr=3e5;function Nr({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:a}){let{t:o}=Z();return i(W,{"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:[...Tr(e,t,n)],onChange:e=>a(e.target.value)})}function Pr({deviceId:e,nodeId:t}){let{t:n}=Z(),r=l(),{data:a}=Nt({deviceId:e},{refetchOnMount:`always`}),{data:o}=kt({nodeId:t},{staleTime:Mr}),s=Qt({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?`${Pt(p)} (${d})`:d})}]:[],...u.map(e=>({value:e.key,label:`${Pt(e)} · ${e.format}`}))];return i(W,{"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 Fr(e){let n=t(null);return e.nodeId!==null&&(n.current=e),n.current}function Ir({deviceId:t,state:n,...r}){let{t:a}=Z(),o=Fr(n);return e(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[i(Nr,{state:n,...r}),o?.nodeId==null?i(W,{"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(Pr,{deviceId:t,nodeId:o.nodeId})]})}function Lr({state:t,nameOf:n}){let{t:r}=Z(),a=Fr(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 Rr({deviceId:t,deviceName:n}){let{t:r}=Z(),[a,s]=o(!1);return e(d,{children:[i(tt,{icon:b,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(_n,{open:a,onOpenChange:s,children:e(Je,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[i(Xt,{children:i(Re,{children:r(`pipeline.clusterRowCells.brokersTitle`,{device:n})})}),i(mt,{children:a&&i(Ue,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t,instanceId:`pipeline-row/${t}`,config:{variant:`compact`}})})]})})]})}function zr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function Br(e,t){return t.size===0?!0:t.has(e)}var Vr=[{value:`active`,get label(){return X.t(`helpers.cameraActivity.active`)}},{value:`recently-active`,get label(){return X.t(`helpers.cameraActivity.recentlyActive`)}},{value:`inactive`,get label(){return X.t(`helpers.cameraActivity.inactive`)}}];s();var Hr=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function Ur(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function Wr(){let{t}=Z(),r=l();Ot([`pipelineOrchestrator`,`getPipelineAssignments`],Hr),Ot([`pipelineOrchestrator`,`getAudioAssignments`],Hr),Ot([`pipelineOrchestrator`,`getCameraStatuses`],Hr);let{data:a}=yn({isCamera:!0,projection:`slim`}),{data:s}=dn(void 0),{data:c}=St(void 0),{data:u}=mn({}),{data:d}=It(void 0),{nodes:f}=J(),p=jr(),m=n(()=>Cr(f),[f]),h=n(()=>ze(d),[d]),g=n(()=>f.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[f]),_=n(()=>xr(yr((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=>Br(zr({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=()=>Ur(r),C=rt({onSuccess:S}),w=ot({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(Tn,{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(Ir,{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(Dr,{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(Lr,{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(Or,{snap:p.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>i(Rr,{deviceId:e.deviceId,deviceName:e.deviceName})}],D=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:Vr.map(e=>{let t=v.has(e.value);return i(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:P(se,t?oe:z),onClick:()=>x(e.value),children:e.label},e.value)})})}),i(ht,{columns:E,rows:b,rowKey:e=>e.deviceId,minWidthPx:920,maxBodyHeight:Ye,emptyMessage:D})]})}s();function Gr({nodeId:e}){let{t}=Z(),r=l();Ot([`pipelineOrchestrator`,`getCameraStatuses`],Hr);let{data:a}=mn({}),{data:o}=It(void 0),{data:s}=yn({isCamera:!0,projection:`slim`}),{nodes:c}=J(),u=jr(),d=n(()=>Cr(c),[c]),f=n(()=>ze(o),[o]),p=n(()=>Sr(e,a??[],wr((s??[]).map(e=>({id:e.id,name:e.name})))),[e,a,s]),m=c.filter(t=>t.isOnline&&t.id!==e),h=()=>Ur(r),g=rt({onSuccess:h}),_=ot({onSuccess:h}),v=Qe({onSuccess:h}),y=at({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(ht,{columns:[{key:`camera`,header:t(`pipeline.nodeCameraAssignmentsTable.camera`,`Camera`),width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(Tn,{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(Dr,{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(Or,{snap:u.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>i(At,{items:b(e),title:t(`pipeline.nodeCameraAssignmentsTable.move`,`Move {{deviceName}}`,{deviceName:e.deviceName})})}],rows:p,rowKey:e=>e.deviceId,minWidthPx:560,maxBodyHeight:Ye,emptyMessage:a===void 0?t(`pipeline.nodeCameraAssignmentsTable.loadingCameras`,`Loading cameras…`):t(`pipeline.nodeCameraAssignmentsTable.noCameraRunsOnThis`,`No camera runs on this node right now`)})}function Kr({nodeId:t,refreshToken:n}){let{t:r}=Z(),{nodes:a}=J(),o=a.find(e=>e.id===t)?.name??t;return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(gr,{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(Gr,{nodeId:t})]})]})}s();function qr(e,t){let n=Math.max(0,t-e),r=Math.floor(e/1e3),i=Math.floor(n/1e3);return X.t(`pipeline.nodeEnginesTab.idleLeft`,{idle:r,left:i})}function Jr({nodeId:t,refreshToken:r}){let{t:a}=Z(),o=l(),s=B(),c=yt({onSettled:()=>{o.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:u}=$e({nodeId:t}),d=jt(`pipeline.engine-metrics-snapshot`,e=>e.nodeId===t)?.engines??u??null,p=d===null;Ot([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:m}=Ze({nodeId:t}),{values:h}=vn(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,e=>e.nodeId===t),g=n(()=>h.filter(e=>e.metrics.phase===`active`).length,[h]),_=e=>{let n=m??[];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:(m??[]).length,active:g})})]}),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:[p&&i(`tr`,{children:i(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:a(`common.loading`,`Loading…`)})}),!p&&(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?Fe:A,{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(O,{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:qr(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:(m??[]).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(Y,{variant:`ghost`,size:`sm`,disabled:c.isPending,onClick:()=>_(t.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[i(f,{className:`h-3.5 w-3.5`}),a(`pipeline.nodeEnginesTab.kill`,`Kill`)]})})]},t.engineKey)}),!p&&(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(wn,{i18nKey:`pipeline.nodeEnginesTab.legend`,components:{strong:i(`strong`,{className:`text-foreground`})}})}),c.isError&&i(Bt,{message:a(`pipeline.nodeEnginesTab.killFailed`,{message:c.error instanceof Error?c.error.message:a(`common.unknownError`)})})]})}var Yr=`pipeline-runner`,Xr=200;function Zr({nodeId:t}){let{t:n}=Z();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(Kt,{agentId:t,addonId:Yr,limit:Xr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1,showSourceSelect:!0})})]})}s();function Qr({nodeId:t,title:r}){let a=F(),{t:o}=Z(),{data:s}=Cn(),{data:c}=dn(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=jr(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=Ft(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(Ct,{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 $r(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 ei(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 ti=`pipeline-analytics`,ni=`face-gallery`,ri=`pipeline-orchestrator`,ii=`pipeline-runner`,ai=`audio-analyzer`;function oi(e){return[...ve.filter(t=>t.stepId===e).map(e=>xe(e.stepId)),...me.filter(t=>t.stepId===e).map(e=>he(e.stepId,e.key))]}var si=`faces`,ci=`semantic-search`,li=`load-balancer`,ui=`load`,di=[{id:si,get title(){return X.t(`helpers.clusterSettingsSections.facesTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.facesHint`)},panels:[{addonId:ri,fieldKeys:oi(`face-embedding`)},{addonId:ti,capability:ni}]},{id:ci,get title(){return X.t(`helpers.clusterSettingsSections.semanticTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.semanticHint`)},panels:[{addonId:ri,fieldKeys:oi(`clip-embedding`)}]},{id:Se,get title(){return X.t(`helpers.clusterSettingsSections.cropTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.cropHint`)},panels:[{addonId:ri,sectionIds:[Se]}]},{id:ge,get title(){return X.t(`helpers.clusterSettingsSections.nativeTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.nativeHint`)},panels:[{addonId:ri,sectionIds:[ge]}]},{id:`runner-defaults`,get title(){return X.t(`helpers.clusterSettingsSections.runnerTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.runnerHint`)},panels:[{addonId:ii,fieldScope:`cluster`},{addonId:ai,fieldScope:`cluster`}]},{id:li,get title(){return X.t(`helpers.clusterSettingsSections.loadTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.loadHint`)},panels:[{addonId:ri,sectionIds:[ui]}]},{id:`failover`,get title(){return X.t(`helpers.clusterSettingsSections.failoverTitle`)},get hint(){return X.t(`helpers.clusterSettingsSections.failoverHint`)},panels:[{addonId:ri,sectionIds:[`failover`]}]}],fi={"cluster-step-models":si};function pi(e){return e===`clip-embedding`?ci:si}var mi=`ctab`,hi=`section`;function gi(e,t){let n=new URLSearchParams({view:`nodes`,node:$o,[mi]:e});return t!==void 0&&n.set(hi,t),`/system/pipeline?${n.toString()}`}function _i(e){return gi(`settings`,pi(e))}function vi(){return gi(`load-balancing`)}var yi=`pipeline-orchestrator`;function bi(e){return ve.find(t=>t.stepId===e)??null}function xi({step:t,engineFormat:n,runnableModelIds:r}){let{t:a}=Z(),{data:o}=qe({addonId:yi,cap:yi,scope:`cluster`}),s=ye(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(Tn,{to:_i(t.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:a(`pipeline.clusterStepModel.changeInClusterSettings`,`Change in Cluster → Settings ›`)})]}),e(`p`,{className:G,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(wn,{i18nKey:`pipeline.clusterStepModel.noBuild`,values:{engine:n,model:s,index:t.indexName},components:{b:i(`b`,{})}})})]})}var Si=`pipeline-orchestrator`;function Ci({addonId:t,highlightLabel:n}){let{t:r}=Z(),a=Ce(t),{data:o}=qe({addonId:Si,cap:Si,scope:`cluster`});if(a.length===0)return null;let s=we(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:M,children:r(`stepInspector.clusterOwnedSettings.clusterWideSettings`,`Cluster-wide settings`)}),i(Tn,{to:_i(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:V,children:t.label}),i(`span`,{className:C,children:i(`span`,{className:`font-mono text-xs text-foreground`,children:String(s[t.key]??t.default)})})]},t.key)),i(`p`,{className:G,children:r(`stepInspector.clusterOwnedSettings.oneValueForEveryNode`,`One value for every node and camera — this step writes into a shared index.`)})]})}function wi({rows:t,hint:n}){let{t:r}=Z();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:`${k} 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(Tn,{to:t.href,className:`ml-auto text-[11px] text-primary hover:underline`,children:r(`stepInspector.effectiveModelSummary.changeOnAccelerator`)})]},t.id))}),i(`p`,{className:G,children:n??r(`stepInspector.effectiveModelSummary.toChangeAModelOpen`,`To change a model, open that accelerator's cell in the table.`)})]})}s();function Ti(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:Pt(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Ei({tree:a,searchRows:s,accelerators:c,cellState:l,stepBadge:u,disabledCount:d,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:g,summary:v,toolbar:y,label:b,renderDetail:x}){let{t:S}=Z(),C=B(),w=zt(),{selection:T,open:E,close:D}=Ln(n(()=>On(a).map(e=>e.node.addonId),[a]),n(()=>c.map(e=>e.id),[c])),[O,k]=o(``),[A,j]=o(null),[M,N]=o(null),P=t(null),F=t(null),I=t(null);rn(I);let ee=t(null),L=n(()=>et(s,O),[s,O]),R=n(()=>O.trim()===``?a:Bn(a,new Set(L.map(e=>e.addonId))),[a,L,O]),z=e=>L.find(t=>t.addonId===e)?.matchedField??null,V=n(()=>c.map(Ti),[c]),te=e=>c.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),H=c.find(e=>e.id===T.acceleratorId)??null,U=T.stepId!==null,ne=r(async e=>{if(m){if(!await C({title:S(`stepInspector.stepMatrixFrame.discardUnsavedChanges`,`Discard unsaved changes?`),message:S(`stepInspector.stepMatrixFrame.thisStepHasChangesThat`,`This step has changes that are not saved yet.`),confirmLabel:S(`stepInspector.stepMatrixFrame.discard`,`Discard`),variant:`danger`}))return;g()}e()},[C,m,g,S]),re=()=>{requestAnimationFrame(()=>ee.current?.focus())},ie=(e,t,n=!1)=>{if(e===T.stepId&&(t?.id??null)===T.acceleratorId){n&&re();return}let r=()=>{j(z(e)),E({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&re()};e===T.stepId?r():ne(r)},ae=()=>{let e=T.stepId;ne(()=>{if(D(),e!==null){let t=H===null?null:Mt({agentNodeId:H.nodeId,deviceKey:H.deviceKey});requestAnimationFrame(()=>P.current?.focusCell(e,t))}})},W=e=>{if(e.key===`Enter`){let t=L[0];if(t===void 0)return;e.preventDefault(),ie(t.addonId,void 0,!0)}else e.key===`Escape`&&k(``)},oe=w?i(Sn,{onClick:ae}):i(tt,{icon:h,variant:`ghost`,size:`sm`,"aria-label":S(`common.close`,`Close`),onClick:ae});return e(`div`,{ref:F,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),I.current?.focus()),e.key===`Escape`&&t&&U&&(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:v}),i(sn,{ref:I,type:`search`,value:O,onChange:e=>k(e.target.value),onKeyDown:W,placeholder:S(`stepInspector.stepMatrixFrame.filterStepsOrSettings`,`Filter steps or settings /`),"aria-label":S(`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(_,{checked:f,onChange:e=>p(e.target.checked)}),S(`stepInspector.stepMatrixFrame.showDisabled`,{count:d})]}),y]}),T.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:S(`stepInspector.stepMatrixFrame.staleStep`,{id:T.staleStepId})}),R.length===0?i(`p`,{className:`${G} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:S(`stepInspector.stepMatrixFrame.noStepMatches`,{query:O})}):i(un,{ref:P,tree:R,agents:V,label:b,getCellState:(e,t)=>{let n=te(t);return n===void 0?{kind:`na`}:l(e,n)},onCellClick:(e,t,n)=>ie(e,te(t),n),onStepClick:(e,t)=>ie(e,void 0,t),...u===void 0?{}:{stepBadge:u},selectedCell:U&&T.stepId!==null&&H!==null?{addonId:T.stepId,agentNodeId:H.nodeId,deviceKey:H.deviceKey}:null,fallbackNodeId:M,onFallbackNodeChange:N,reserveRightPx:U&&!w?432:0}),i(vt,{open:U,anchor:F,onClose:ae,label:S(`stepInspector.stepMatrixFrame.stepSettings`,`Step settings`),children:T.stepId!==null&&x({stepId:T.stepId,accelerator:H,matchedField:A,closeButton:oe,onEscape:ae,headingRef:e=>{ee.current=e}})})]})}s();function Di(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 Oi(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 ki(e,t){return t===void 0?0:[...new Set([...Object.keys(e),...Object.keys(t)])].filter(n=>!_e(e[n],t[n])).length}function Ai(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=ki(n,t.nodeSettings),s=t.accelerator===void 0?0:ki(r(t.accelerator.deviceKey),t.accelerator.settings);return i+a+o+s}function ji({nodeId:t,nodeName:r,toolbar:a}){let{t:s}=Z(),c=l(),u=kt({nodeId:t},{refetchOnMount:`always`}),f=He({nodeId:t},{refetchOnMount:`always`}),p=wt({agentNodeId:t},{refetchOnMount:`always`}),m=p.data?.stepSettings,h=ye(qe({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=gn({onSuccess:()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),T=lt({onSuccess:()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]})}}),[E,D]=o(!1),O=n(()=>_?Xe(_):[],[_]),k=n(()=>On(O),[O]),[A,j]=o(!1),N=n(()=>Vn(t,r,g,A),[t,r,g,A]),P=n(()=>Vn(t,r,g),[t,r,g]),F=P.length>=2,I=(e,t)=>$r(g,t?.deviceKey,e,m)??{},ee=e=>m?.[e]??{},L=(e,t)=>g.find(e=>e.key===t)?.steps?.[e]?.settings??{},R=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return P.find(e=>e.deviceKey===r);if(!In(e,t))return P.filter(n=>n.id!==t.id&&In(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},z=(e,t)=>{let n=Fn(_,e),r=bi(e),i=An(_,t),a=I(e,t),o=R(n,t);return Rn({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?Mn(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...zn(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:h[e]??r.defaultModelId}:{},...o?{jumpTo:Vt(o.device)}:{}})},B=k.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:jn(Fn(_,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 V=e(`span`,{className:G,children:[s(`stepInspector.nodeStepInspector.accelerators`,`Accelerators:`),` `,i(`span`,{className:`text-foreground`,children:P.length>0?P.map(e=>Vt(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(Vt).join(`, `)]}),` `,`·`,` `,i(Tn,{to:vi(),className:`text-primary hover:underline`,children:s(`stepInspector.nodeStepInspector.clusterLoadBalancing`,`Cluster → Load balancing ›`)})]});return i(Ei,{tree:O,searchRows:B,accelerators:N,cellState:z,disabledCount:g.filter(e=>!e.enabled).length,showDisabled:A,onShowDisabledChange:j,dirty:v!==null&&Ai(g,v,ee(v.stepId),e=>L(v.stepId,e))>0,onDiscard:()=>y(null),summary:V,...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=Fn(_,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??P[0]??N[0],h=p?.nodeSettings??ee(n),O=a===null?{}:p?.accelerator?.deviceKey===a.deviceKey?p.accelerator.settings:L(n,a.deviceKey),k={...h,...O},A=Ai(g,p,ee(n),e=>L(n,e)),j=e=>{C(null),y(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},z=bi(n),B=pn(f),{nodeFields:V,acceleratorFields:te}=Hn(B),H=new Set(te.flatMap(e=>`key`in e?[e.key,`${e.key}ModelId`]:[])),U=m===void 0?void 0:An(_,m),ne=e=>{let t=p?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},re=m===void 0?void 0:Mn(f,m,{nodePin:ne(m)}).modelId,ie=t=>{let r=ne(t),o=Mn(f,t,{nodePin:r}),c=An(_,t),l=zn(n,a?.id===t.id?k:I(n,t),c),u=p?.jumps[t.deviceKey],m=R(f,t,u),h=In(f,t)?l&&c?i(Le,{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=F?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(W,{"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)`)},...P.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:G,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:$t(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}},ae=async()=>{if(p!==null){D(!0);try{(Object.keys(p.models).length>0||Object.keys(p.jumps).length>0||p.accelerator!==void 0)&&await w.mutateAsync({agentNodeId:t,inferenceDevices:ei(Oi(g,p,e=>H.has(e)))}),p.nodeSettings!==void 0&&ki(ee(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{D(!1)}}};return i(ut,{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 ae(),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:M,children:s(`stepInspector.nodeStepInspector.model`,`Model`)}),z!==null&&m!==void 0?i(xi,{step:z,engineFormat:m.device.format,runnableModelIds:$t(f.models??[],m.device.format).map(e=>e.id)}):N.length===0?i(`p`,{className:G,children:i(wn,{i18nKey:`stepInspector.nodeStepInspector.noAcceleratorEnabled`,components:{link:i(Tn,{to:vi(),className:`text-primary hover:underline`})}})}):a===null?i(wi,{rows:N.map(e=>{let t=Mn(f,e,{nodePin:ne(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):i(it,{...ie(a)},a.id)]}),(B.length>0||U!==void 0)&&z===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})}),(V.length>0||U!==void 0)&&i(Mi,{addon:f,fields:V,settings:h,layerLabel:s(`stepInspector.nodeStepInspector.nodeLayer`,`Node`),modelId:Rt(f,re,k,U),root:U,highlight:o,onChange:e=>j({nodeSettings:e})}),te.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(Mi,{addon:f,fields:te,settings:O,layerLabel:s(`stepInspector.nodeStepInspector.acceleratorLayer`,`This accelerator`),modelId:Rt(f,re,k,U),root:void 0,highlight:o,onChange:e=>j({accelerator:{deviceKey:a.deviceKey,settings:e}})})]}))]}),i(Ci,{addonId:n,highlightLabel:o})]})})}})}function Mi({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 Di(l===null?null:ln(l)),i(nn,{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 Ni({nodeId:t,refreshToken:n}){let{t:r}=Z(),a=B(),[s,c]=o(null),{nodes:l}=J(),u=l.find(e=>e.id===t)?.name??t,f=Gt({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(Qr,{nodeId:t}),i(ji,{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(Y,{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 Pi=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],Fi=`decoder-nodeav`,Ii=`ntab`,Li={decoder:`engine`},Ri={engine:`Engine & decoder`},zi=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function Bi({nodeId:t,refreshToken:n}){let{t:r}=Z(),[a,o]=En(),{nodes:s}=J(),c=s.find(e=>e.id===t)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??Fi,l=[...Pi,c],u=a.get(Ii),d={assignments:{id:`assignments`,label:r(`pipeline.nodeDetail.assignments`,`Assignments`),order:-10,content:i(Kr,{nodeId:t,refreshToken:n})},tree:{id:`tree`,label:r(`pipeline.nodeDetail.pipeline`,`Pipeline`),order:39,content:i(Ni,{nodeId:t,refreshToken:n})},engines:{id:`engines`,label:r(`pipeline.nodeDetail.warmInstances`,`Warm instances`),order:180,content:i(Jr,{nodeId:t,refreshToken:n})},logs:{id:`logs`,label:r(`pipeline.nodeDetail.logs`,`Logs`),order:300,content:i(Zr,{nodeId:t})}},f=hr.map(e=>d[e]);return e(`div`,{className:`flex flex-col h-full`,children:[i(mr,{nodeId:t,refreshToken:n}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:i(Gn,{nodeId:t,addonIds:l,level:`global`,fieldScope:`perNode`,emptyMessage:zi,tabAliases:Li,tabLabelOverrides:Ri,extraTabs:f,activeTab:u===null?null:Li[u]??u,onActiveTabChange:e=>o(t=>{let n=new URLSearchParams(t);n.set(Ii,e);for(let e of Pn)n.delete(e);return n},{replace:!0})})})]})}function Vi(){let{t}=Z();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(Wr,{})]})}function Hi(e){return`${Math.round(e*100)}%`}function Ui(e){return X.t(`helpers.autoTuneViewModel.sessions`,{count:e})}var Wi={"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`},Gi={"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 Ki(e){return e===null?`—`:Wi[e]??e}function qi(e){return e===null?`—`:Gi[e]??e}function Ji(e){switch(e.kind){case`capacity`:return X.t(`helpers.autoTuneViewModel.capacity`,{sessions:Ui(e.sessions),min:e.minSessions});case`tie-faster`:return X.t(`helpers.autoTuneViewModel.tieFaster`,{over:e.over,recall:Hi(e.recallDelta)});case`stepped-down`:return X.t(`helpers.autoTuneViewModel.steppedDown`,{from:e.from,limitedBy:e.limitedBy,to:e.to});case`no-fit-lightest`:return X.t(`helpers.autoTuneViewModel.noFitLightest`,{min:Ui(e.minSessions),sessions:Ui(e.sessions)});case`derived-latency`:return X.t(`helpers.autoTuneViewModel.derivedLatency`,{modelId:e.modelId});case`cpu-device`:return X.t(`helpers.autoTuneViewModel.cpuDevice`);case`device-disabled`:return X.t(`helpers.autoTuneViewModel.deviceDisabled`);case`device-unavailable`:return X.t(`helpers.autoTuneViewModel.deviceUnavailable`);case`node-offline`:return X.t(`helpers.autoTuneViewModel.nodeOffline`);case`no-hardware-facts`:return X.t(`helpers.autoTuneViewModel.noHardwareFacts`);case`no-measured-data`:return X.t(`helpers.autoTuneViewModel.noMeasuredData`);case`no-family-build`:return X.t(`helpers.autoTuneViewModel.noFamilyBuild`,{format:e.format});case`kept-custom-pin`:return X.t(`helpers.autoTuneViewModel.keptCustomPin`,{modelId:e.modelId,deviceKey:e.deviceKey})}}function Yi(e,t){switch(e.kind){case`custom-pin-kept`:return X.t(`helpers.autoTuneViewModel.customPinNode`,{node:t(e.nodeId),modelId:e.modelId,deviceKey:e.deviceKey});case`custom-registry-unreadable`:return X.t(`helpers.autoTuneViewModel.customRegistryUnreadable`,{error:e.error})}}function Xi(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 Zi(e){let t=Xi(e);return t.modelChanges+t.thresholdClears===0}function Qi(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 $i(e,t){return e?.kind===`node-benchmark`?X.t(`helpers.autoTuneViewModel.latencyMeasured`,{date:new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}):e?.kind===`estimated`?X.t(`helpers.autoTuneViewModel.latencyEstimated`,{hardware:qi(e.estimatedFrom)}):X.t(`helpers.autoTuneViewModel.latencyTable`)}s();var ea=[.3,.4,.5];function ta(e){return ea.some(t=>t===e)}var na=[1,2,3,4,6,8];function ra({plan:t,node:n,nodeName:r}){let{t:a}=Z();return e(`section`,{className:w,"data-testid":`auto-tune-node-${n.nodeId}`,children:[e(`header`,{className:`${H} flex flex-wrap items-center gap-2`,children:[i(A,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),i(`h3`,{className:`${M} min-w-0 flex-1`,children:r(n.nodeId)}),e(`span`,{className:`text-[11px] text-foreground-subtle`,children:[qi(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:Ji(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=Qi(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:Ki(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:$i(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:Ji(e)},t))})]},r.deviceKey)})})]})})]})}function ia({plan:t,nodeName:n}){let{t:r}=Z();return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:e(`div`,{children:[i(`div`,{className:M,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 aa({result:t}){let{t:n}=Z();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 oa(){let{t}=Z(),r=l(),[a,s]=o(.4),[c,u]=o(2),[d,f]=o(!1),[p,m]=o(!1),[h,g]=o(null),{nodes:_}=J(),v=n(()=>Cr(_),[_]),y=Ht({headroom:a,minSessionsPerDevice:c},{enabled:d,refetchOnWindowFocus:!1}),b=gt({onSuccess:e=>{g(e),m(!1),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.kind===`applied`&&y.refetch()}}),x=h?.kind===`stale`?h.plan:y.data,S=x===void 0?null:Xi(x);return e(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[e(`section`,{className:w,children:[e(`header`,{className:`${H} flex flex-wrap items-center gap-2`,children:[i(L,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),i(`h3`,{className:`${M} 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(W,{"aria-label":t(`pipeline.clusterAutoTuneTab.shareOfEachAcceleratorKept`,`Share of each accelerator kept free`),value:String(a),options:ea.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);ta(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(W,{"aria-label":t(`pipeline.clusterAutoTuneTab.minimumParallelSessionsPerDevice`,`Minimum parallel sessions per device`),value:String(c),options:na.map(e=>({value:String(e),label:t(`pipeline.clusterAutoTuneTab.camerasAtOnce`,{count:e})})),onChange:e=>{let t=Number(e.target.value);na.some(e=>e===t)&&u(t)}})]}),i(Y,{size:`sm`,variant:`secondary`,onClick:()=>{g(null),f(!0),d&&y.refetch()},children:y.isFetching?t(`pipeline.clusterAutoTuneTab.computing`,`Computing…`):x===void 0?t(`pipeline.clusterAutoTuneTab.computePlan`,`Compute plan`):t(`pipeline.clusterAutoTuneTab.recompute`,`Recompute`)}),x!==void 0&&i(Y,{size:`sm`,disabled:Zi(x),onClick:()=>m(!0),children:t(`pipeline.clusterAutoTuneTab.apply`,`Apply…`)})]}),y.error!==null&&i(`div`,{className:`text-danger`,children:y.error.message}),h!==null&&i(aa,{result:h}),S!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:t(`pipeline.clusterAutoTuneTab.planSummary`,{modelChanges:S.modelChanges,thresholdClears:S.thresholdClears})})]})]}),x?.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:Yi(e,v)},t)),x?.nodes.map(e=>i(ra,{plan:x,node:e,nodeName:v},e.nodeId)),x!==void 0&&i(_n,{open:p,onOpenChange:m,children:e(Je,{width:`lg`,scroll:`body`,children:[e(Xt,{children:[i(Re,{children:t(`pipeline.clusterAutoTuneTab.applyAutoTune`,`Apply auto tune?`)}),i(Ge,{children:t(`pipeline.clusterAutoTuneTab.theseAreAllTheChanges`,`These are all the changes. Every override listed is removed and cannot be restored.`)})]}),i(mt,{children:i(ia,{plan:x,nodeName:v})}),e(ct,{children:[i(Y,{variant:`ghost`,onClick:()=>m(!1),children:t(`common.cancel`,`Cancel`)}),i(Y,{variant:`danger`,disabled:b.isPending,onClick:()=>b.mutate({planHash:x.planHash,headroom:a,minSessionsPerDevice:c}),children:b.isPending?t(`pipeline.clusterAutoTuneTab.applying`,`Applying…`):t(`common.apply`,`Apply`)})]})]})})]})}var sa={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 ca(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function la(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function ua(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:Pt(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?ca(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 da(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=ua(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),la(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?ca(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?ca(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}s();var fa=2e4,pa=3e5;function ma({stats:e,targetWeights:t,showAccelerators:r=!0}){let{t:a}=Z(),{nodes:o}=J(),s=R().trpcClient,l=nt(void 0,{placeholderData:u,staleTime:fa,refetchInterval:fa,refetchOnWindowFocus:!0}),d=It(void 0,{staleTime:pa}),f=n(()=>o.map(e=>e.id),[o]),p=c({queries:f.map(e=>({queryKey:Ie(We.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>s.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:pa,refetchOnWindowFocus:!1,placeholderData:u}))}),m=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(`|`)]),h=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=h.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:dr(n).pipeline,weight:t?.[e.id]??$n(n,`detectWeight`)??1,maxCameras:$n(n,`maxCameras`)}}),[o,h,t]),v=l.data??[],y=n(()=>da({nodes:_,loads:v,devicesByNode:m}),[_,v,m]),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(K,{headingId:`load-balancing-node-load`,title:a(`pipeline.nodeLoadOverview.nodeLoad`,`Node load`),icon:N,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:g,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(ha,{row:e,placed:C.get(e.nodeId),showAccelerators:r},e.nodeId))})})})}function ha({row:t,placed:n,showAccelerators:r}){let{t:a}=Z(),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(I,{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(U,{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(va,{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(va,{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(va,{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(va,{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(va,{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(va,{label:a(`pipeline.nodeLoadOverview.capFill`,`Cap fill`),value:`${t.capacityPct}%`,title:a(`pipeline.nodeLoadOverview.attachedMaxcameras`,`attached / maxCameras.`)}),t.avgInferenceTimeMs!==null&&i(va,{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(va,{label:a(`pipeline.nodeLoadOverview.decode`,`Decode`),value:t.decodeHwaccel,title:a(`pipeline.nodeLoadOverview.thisNodeSProbedDecode`,`This node's probed decode hwaccel.`)})]}),r&&i(ga,{row:t})]})}function ga({row:t}){let{t:n}=Z();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(ie,{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(_a,{device:e},e.key))})]})}function _a({device:t}){let{t:n}=Z(),r=t.exclusion;return e(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[i(A,{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(sa[r]),children:n(`pipeline.nodeLoadOverview.excludedWith`,{reason:n(sa[r])})})]})}function va({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 ya(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function ba(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 xa(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Sa(e){return e.reason===`disabled`?X.t(`helpers.loadBalancingViewModel.stalePinDisabled`,{deviceKey:e.deviceKey}):X.t(`helpers.loadBalancingViewModel.stalePinMissing`,{deviceKey:e.deviceKey})}function Ca(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 wa(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 X.t(`helpers.loadBalancingViewModel.shareNote`,{count:n.length,names:i,into:r})}var Ta=[{value:`hardware`,get label(){return X.t(`helpers.loadBalancingViewModel.hardwareLabel`)},get hint(){return X.t(`helpers.loadBalancingViewModel.hardwareHint`)}},{value:`benchmark`,get label(){return X.t(`helpers.loadBalancingViewModel.benchmarkLabel`)},get hint(){return X.t(`helpers.loadBalancingViewModel.benchmarkHint`)}},{value:`manual`,get label(){return X.t(`helpers.loadBalancingViewModel.manualLabel`)},get hint(){return X.t(`helpers.loadBalancingViewModel.manualHint`)}}];function Ea(e){return e===`no-benchmark-results`?X.t(`helpers.loadBalancingViewModel.fallbackNone`):e===`partial-benchmark-results`?X.t(`helpers.loadBalancingViewModel.fallbackPartial`):null}function Da(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)}: ${Ea(e.capacityFallback)??``}`).join(` · `)}s();function Oa(e,t,n){return Math.min(Math.max(e,t),n)}function ka(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 Aa(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:Oa(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 ja(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 Ma({nodes:t,pending:n,onCommitWeights:r,weightLabel:s=`Detection weight`,emptyHint:c,footnote:l,readOnly:u=!1}){let{t:f}=Z(),[p,m]=o(()=>ka(t)),[h,g]=o(new Set);a(()=>{m(ka(t)),g(e=>new Set([...e].filter(e=>t.some(t=>t.id===e))))},[t.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let _=t.map(e=>e.id),v=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},y=(e,t)=>{m(n=>Aa(n,e,t,h,_))},b=()=>{let e=ja(p,_,h),n=t.filter(t=>(e[t.id]??0)!==t.weight).map(e=>e.id);if(n.length===0)return;let i=new Set([...n,...h]);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??f(`placementBoard.weightSliderStack.noDetectEnabledNodesEnable`,`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`)});let x=t.length===1;return e(`div`,{className:`space-y-3`,children:[t.map(t=>{let r=p[t.id]??0,a=h.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(j,{"aria-label":f(`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||x,onChange:e=>y(t.id,Number(e.target.value)),onPointerUp:()=>b(),onKeyUp:()=>b(),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(Y,{variant:`unstyled`,type:`button`,onClick:()=>v(t.id),disabled:n||x,"aria-pressed":a,title:a?f(`placementBoard.weightSliderStack.unlockAllowRebalancing`,`Unlock — allow rebalancing`):f(`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?te:S,{className:`h-3.5 w-3.5`})})]},t.id)}),i(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:l??i(d,{children:f(`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 Na(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 Pa(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 Fa(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:Pa(e),share:t===void 0?null:{configuredPct:t.configuredPct,effectivePct:t.effectivePct},sessionsNow:a,atCap:a!==null&&e.maxSessions!==null&&a>=e.maxSessions}})}var Ia={active:`success`,disabled:`neutral`,absent:`danger`,unknown:`neutral`,unavailable:`warning`,backoff:`warning`,"root-incapable":`info`,standby:`neutral`};s();function La(e){let t=Pt(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:A,hue:`slate`}:r===`npu`?{label:t,Icon:O,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:ke,hue:`violet`}:n===`edgetpu`?{label:t,Icon:Ne,hue:`emerald`}:{label:t,Icon:A,hue:`slate`}}var Ra={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`]},za={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 Ba({nodeId:t,nodeName:r,isOnline:s,suggestedMaxSessions:c,shareSource:u,sharesAutomatic:p,share:m,placed:h}){let{t:g}=Z(),_=l(),{data:v,isLoading:y}=kt({nodeId:t},{refetchInterval:15e3}),b=()=>{_.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},x=gn({onSettled:b}),S=cn({onSettled:b}),C=We.platformProbe.rescanAccelerators.useMutation({onSettled:b}),w=v?.devices??[],T=v?.reachable??s,[E,D]=o({});a(()=>{D(Object.fromEntries(w.map(e=>[e.key,Va(e)])))},[w.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let O=n(()=>w.filter(e=>(E[e.key]?.enabled??e.enabled)&&e.available).length,[w,E]),[k,A]=o(null),j=k??!0,M=e=>{let n=w.map(t=>{let n=e[t.key]??Va(t);return{key:t.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});x.mutate({agentNodeId:t,inferenceDevices:ei(n)})},N=(e,t)=>{let n=E[e.key]??Va(e),r={...E,[e.key]:{...n,...t}};D(r),M(r)},P=n(()=>Fa(w,m,h),[w,m,h]),F=n(()=>w.filter(e=>(E[e.key]?.enabled??e.enabled)&&e.available),[w,E]),I=n(()=>F.map(e=>({id:e.key,name:La(e).label,weight:E[e.key]?.weight??e.weight})),[F,E]),L=e=>{let t={...E};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}D(t),M(t)},R=x.isPending||S.isPending,z=Ha(g,p?u:`manual`),B=[{key:`device`,header:g(`placementBoard.nodeInferenceDevices.colDevice`,`Device`),nowrap:!1,sortValue:e=>La(e.device).label,render:e=>i(Wa,{row:e,steps:E[e.device.key]?.steps})},{key:`state`,header:g(`placementBoard.nodeInferenceDevices.colState`,`State`),sortValue:e=>e.state,render:e=>i(`span`,{title:g(za[e.state][0],za[e.state][1]),children:i(q,{variant:Ia[e.state],size:`sm`,children:g(Ra[e.state][0],Ra[e.state][1])})})},{key:`share`,header:g(`placementBoard.nodeInferenceDevices.colShare`,`Share`),align:`right`,sortValue:e=>e.share?.effectivePct??null,render:e=>i(Ga,{row:e,sourceLabel:z})},{key:`sessions`,header:g(`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:g(`placementBoard.nodeInferenceDevices.atCap`,`at cap`)})]})},{key:`cap`,header:g(`placementBoard.nodeInferenceDevices.colCap`,`Max sessions`),notSortableReason:g(`placementBoard.nodeInferenceDevices.capNotSortable`,`An editable field: sort by Sessions instead.`),render:t=>{let n=E[t.device.key]??Va(t.device);if(!(n.enabled&&t.device.available))return i(`span`,{className:`text-xs text-foreground-subtle`,children:`—`});let r=La(t.device).label;return e(`div`,{className:`flex items-center justify-end gap-1`,children:[i(sn,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:e=>{let n=e.target.value.trim(),r=n===``?null:Number.parseInt(n,10);N(t.device,{maxSessions:r!==null&&r>0?r:null})},disabled:R,"aria-label":g(`placementBoard.nodeInferenceDevices.maxConcurrentSessionsFor`,`Max concurrent sessions for {{label}}`,{label:r}),className:`w-16 text-right`}),i(Ka,{suggested:c?.[t.device.key]??null,current:n.maxSessions,pending:R,onApply:e=>N(t.device,{maxSessions:e})})]})}},{key:`enabled`,header:g(`placementBoard.nodeInferenceDevices.colEnabled`,`Enabled`),align:`right`,notSortableReason:g(`placementBoard.nodeInferenceDevices.enabledNotSortable`,`A switch: sort by State instead.`),render:e=>{let n=La(e.device).label;if(e.state===`absent`)return i(hn,{label:g(`placementBoard.nodeInferenceDevices.forget`,`Forget`),icon:f,size:`sm`,triggerVariant:`ghost`,disabled:R,title:g(`placementBoard.nodeInferenceDevices.forgetTitle`,`Forget {{label}} on {{node}}?`,{label:n,node:r}),description:g(`placementBoard.nodeInferenceDevices.forgetDescription`,`Its stored settings (switch, weight, cap, step models) are deleted. If the device comes back it starts from the defaults.`),action:()=>S.mutateAsync({agentNodeId:t,deviceKey:e.device.key})});let a=E[e.device.key]??Va(e.device);return i(Tt,{checked:a.enabled&&e.device.available,onCheckedChange:()=>N(e.device,{enabled:!a.enabled}),disabled:!e.device.available||R,"aria-label":g(`placementBoard.nodeInferenceDevices.enable`,`Enable {{label}}`,{label:n})})}}],V=x.error??S.error??C.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(Y,{variant:`ghost`,size:`sm`,onClick:()=>A(!j),className:`min-w-0 flex-1 justify-start`,"aria-expanded":j,children:[i(ee,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${j?`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:T?e(d,{children:[i(Fe,{className:`h-3.5 w-3.5`}),g(`pipeline.nodeInferenceDevices.accelerators`,{count:O})]}):e(d,{children:[i(U,{className:`h-3.5 w-3.5`}),` `,g(`common.unreachable`)]})})]}),e(Y,{variant:`ghost`,size:`sm`,onClick:()=>C.mutate({nodeId:t}),disabled:C.isPending||!T,title:g(`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(re,{className:`h-3.5 w-3.5 ${C.isPending?`animate-spin`:``}`}),g(`placementBoard.nodeInferenceDevices.rescan`,`Rescan`)]})]}),j&&e(`div`,{className:`space-y-3 border-t border-border p-3`,children:[T?y&&w.length===0?i(`p`,{className:`text-center text-xs text-foreground-subtle`,children:g(`placementBoard.nodeInferenceDevices.probingAccelerators`,`Probing accelerators…`)}):i(ht,{columns:B,rows:P,rowKey:e=>e.device.key,minWidthPx:640,bordered:!1,emptyMessage:g(`placementBoard.nodeInferenceDevices.noInferenceDevicesReportedBy`,`No inference devices reported by this node's platform probe.`)}):i(qa,{}),C.data!==void 0&&i(`p`,{className:`text-xs text-foreground-subtle`,children:Ua(g,C.data.appeared,C.data.disappeared)}),T&&!p&&F.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(je,{className:`h-3.5 w-3.5`}),g(`placementBoard.nodeInferenceDevices.acceleratorShare`,`Accelerator share`)]}),i(Ma,{nodes:I,pending:R,onCommitWeights:L,weightLabel:`Accelerator share`,footnote:g(`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%.`)})]}),V!=null&&e(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-xs text-danger`,children:[g(`placementBoard.nodeInferenceDevices.failedToSaveInferenceDevices`,`Failed to save inference devices:`),` `,V.message]})]})]})}function Va(e){return{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}}function Ha(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 Ua(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 Wa({row:t,steps:n}){let r=La(t.device),a=Na({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(wn,{i18nKey:`pipeline.nodeInferenceDevices.rootModel`,values:{model:a},components:{mono:i(`span`,{className:`font-mono text-foreground-muted`})}})})]})]})]})]})}function Ga({row:t,sourceLabel:n}){let{t:r}=Z();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 Ka({suggested:e,current:t,pending:n,onApply:r}){let{t:a}=Z();return e===null||e<1||e===t?null:i(Y,{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 qa(){let{t}=Z();return e(`div`,{className:`flex flex-col items-center gap-2 px-4 py-6 text-center`,children:[i(U,{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 Ja=3600*1e3,Ya=2e4,Xa=.4;function Za({refreshToken:t,onOpenAutoTune:r}){let{t:a}=Z(),s=l(),{nodes:c}=J(),f=It(void 0),p=yn({isCamera:!0,projection:`slim`}),m=en({windowMs:Ja},{refetchInterval:Ya,placeholderData:u}).data,h=qt(void 0,{refetchInterval:Ya,placeholderData:u}).data,_=()=>{Yn(s),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},v=Ke({onSuccess:_}),y=Be({onSuccess:()=>{_(),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),b=xn({onSuccess:_}),x=on(),[S,C]=o(!1),w=h?.source,T=w===`benchmark`?`benchmark`:`hardware`,D=Yt({headroom:Xa,source:T},{enabled:S,staleTime:1/0}),j=D.data,M=n(()=>{let e=new Map((f.data??[]).map(e=>[e.nodeId,e.settings]));return c.filter(t=>dr(e.get(t.id)).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:$n(n,`detectWeight`)??1,maxCameras:$n(n,`maxCameras`)}})},[c,f.data]),N=e=>c.find(t=>t.id===e)?.name??e,P=wr((p.data??[]).map(e=>({id:e.id,name:e.name}))),F=j?xa(j):void 0,I=Ca(M,h),ee=w!==`manual`,R=h!==void 0&&h.source!==`manual`&&!h.autoPending,z=e=>h?.nodes.find(t=>t.nodeId===e),B=e=>m?.nodes.find(t=>t.nodeId===e),V=h?wa(h,N):null,te=h?Da(h,N):null,H=Ta.find(e=>e.value===w)?.hint;return e(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(gr,{refreshToken:t}),i(ma,{stats:m,showAccelerators:!1,...h!==void 0&&h.source!==`manual`&&!h.autoPending?{targetWeights:Object.fromEntries(h.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),i(K,{headingId:`load-balancing-node-shares`,title:a(`pipeline.clusterLoadBalancingTab.nodeShares`,`Node shares`),icon:je,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:Ta.map(e=>i(Y,{role:`radio`,"aria-checked":w===e.value,variant:w===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:y.isPending||h===void 0,onClick:()=>{w!==e.value&&y.mutate({source:e.value})},children:e.label},e.value))}),e(Y,{variant:`outline`,size:`sm`,onClick:()=>{C(!0),S&&D.refetch()},disabled:D.isFetching,children:[i(E,{className:`h-3.5 w-3.5`}),D.isFetching?a(`pipeline.clusterLoadBalancingTab.suggesting`,`Suggesting…`):T===`benchmark`?a(`pipeline.clusterLoadBalancingTab.suggestFromBenchmark`,`Suggest from benchmark`):a(`pipeline.clusterLoadBalancingTab.suggestFromHardware`,`Suggest from hardware`)]}),e(Y,{variant:`ghost`,size:`sm`,onClick:r,children:[i(L,{className:`h-3.5 w-3.5`}),a(`pipeline.clusterLoadBalancingTab.autoTune`,`Auto tune`)]}),e(Y,{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(O,{className:`h-3.5 w-3.5`}),x.isPending?a(`pipeline.clusterLoadBalancingTab.rebalancing`,`Rebalancing…`):a(`pipeline.clusterLoadBalancingTab.rebalance`,`Rebalance`)]})]}),children:e(`div`,{className:`${g} space-y-3`,children:[H!==void 0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:H}),m&&e(`p`,{className:`text-[10px] text-foreground-subtle`,children:[a(`pipeline.clusterLoadBalancingTab.policy`,`Policy:`),` `,i(q,{variant:m.policy===`share`?`info`:`default`,children:m.policy===`share`?a(`pipeline.clusterLoadBalancingTab.honourShares`,`honour shares`):`least-loaded`}),` `,` · ${a(`pipeline.clusterLoadBalancingTab.clusterPeak`,{count:m.clusterPeakSessions})}`,m.policy===`least-loaded`&&` · ${a(`pipeline.clusterLoadBalancingTab.leastLoadedNote`)}`]}),i(Ma,{nodes:I.nodes,pending:v.isPending,readOnly:I.readOnly,onCommitWeights:e=>v.mutate(ya(e)),weightLabel:`Node share`,...I.readOnly?{footnote:h?.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`),h?.computedAt!=null&&i(`span`,{className:`ml-1`,children:a(h.trigger===null?`pipeline.clusterLoadBalancingTab.lastAt`:`pipeline.clusterLoadBalancingTab.lastAtTrigger`,{time:new Date(h.computedAt).toLocaleTimeString(),trigger:h.trigger??``})}),`.`]})}:{}}),V!==null&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:V}),te!==null&&i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:te}),y.isError&&i(Bt,{message:a(`pipeline.clusterLoadBalancingTab.switchFailed`,{message:y.error instanceof Error?y.error.message:a(`common.unknownError`)})}),v.isError&&i(Bt,{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:`${k} 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:M.map(t=>e(`li`,{className:`${k} flex items-center gap-2`,children:[i(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:t.name}),i(sn,{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:`${k} ${G} 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(Bt,{message:a(`pipeline.clusterLoadBalancingTab.suggestionFailed`,{message:D.error instanceof Error?D.error.message:a(`common.unknownError`)})}),j&&i(Qa,{suggestion:j,nameOf:N,pending:v.isPending,...ee?{}:{onApply:()=>v.mutate(ba(j))}}),i(K,{headingId:`load-balancing-accelerators`,title:a(`pipeline.clusterLoadBalancingTab.accelerators`,`Accelerators`),icon:A,children:i(`div`,{className:`${g} space-y-2`,children:M.length===0?i(Ve,{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.`)}):M.map(e=>i(Ba,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...F?.[e.id]===void 0?{}:{suggestedMaxSessions:F[e.id]},sharesAutomatic:R,...h===void 0?{}:{shareSource:h.source},...z(e.id)===void 0?{}:{share:z(e.id)},...B(e.id)===void 0?{}:{placed:B(e.id)}},e.id))})}),m!==void 0&&m.stalePins.length>0&&i($a,{stats:m,cameraName:P})]})}function Qa({suggestion:t,nameOf:n,pending:r,onApply:a}){let{t:o}=Z();return e(K,{headingId:`load-balancing-suggestion`,title:t.source===`benchmark`?o(`pipeline.clusterLoadBalancingTab.suggestedFromBenchmark`,`Suggested from benchmark`):o(`pipeline.clusterLoadBalancingTab.suggestedFromHardware`,`Suggested from hardware`),icon:E,...a===void 0?{}:{actions:i(Y,{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:`${k} 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:G,children:[Ea(t.capacityFallback)===null?``:`${Ea(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:`${k} ${G} 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 $a({stats:t,cameraName:n}){let{t:r}=Z(),a=l(),o=Qt({onSuccess:()=>{a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),a.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return i(K,{headingId:`load-balancing-stale-pins`,title:r(`pipeline.clusterLoadBalancingTab.staleDevicePins`,`Stale device pins`),icon:Me,children:i(`ul`,{className:`divide-y divide-border`,children:t.stalePins.map(t=>e(`li`,{className:`${k} 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:G,children:Sa(t)})]}),i(Y,{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 eo({node:t,emphasis:n=!1}){let{t:r}=Z(),a=t.isHub?v:A;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 to({nodes:e,actions:t}){let{t:n}=Z();return i(ht,{columns:[{key:`node`,header:n(`placementBoard.nodeCapabilitiesTable.node`,`Node`),sortValue:e=>e.name,render:e=>i(eo,{node:e})},...nr.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(Tt,{"aria-label":n(`placementBoard.nodeCapabilitiesTable.on`,`{{label}} on {{name}}`,{label:n(e.labelKey),name:r.name}),title:n(e.hintKey),checked:Jn(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 no({roleValues:t,options:n,pending:r,onRoleChange:a}){let{t:o}=Z(),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:ar.map(n=>e(`li`,{className:`${k} 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:sr(n)}),i(`p`,{className:G,children:or(n)})]}),i(`div`,{className:`w-full sm:w-48`,children:i(W,{"aria-label":o(`placementBoard.roleControls.node`,`{{value1}} node`,{value1:sr(n)}),value:t[n],disabled:r,options:s,onChange:e=>a(n,e.target.value)})})]},n))})}s();function ro(){let{t}=Z(),r=l(),{nodes:a}=J(),o=It(void 0),s=qe({addonId:Zn,cap:Kn,scope:`cluster`}),c=qe({addonId:rr,cap:qn,scope:`cluster`}),u=qe({addonId:ir,cap:er,scope:`cluster`}),d=()=>Yn(r),f=Dt({onSuccess:d}),p=st({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=dr(t);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[a,m]),g={ingestNode:Xn(s.data,`ingestNode`,`hub`),recordingNode:Xn(c.data,Qn,`hub`),audioNode:Xn(s.data,`audioNode`,`hub`),motionNode:Xn(s.data,`motionNode`,`hub`),postProcessingNode:Xn(u.data,tr,`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`,...ar.map(e=>g[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:t(e)}))},[a,g]),y=o.isLoading||s.isLoading||c.isLoading||u.isLoading,b=(e,t,n)=>{f.mutate({agentNodeId:e,[t]:n})},x=(e,t)=>{if(e===`recordingNode`){p.mutate({addonId:rr,cap:qn,scope:`cluster`,patch:{[Qn]:t}});return}if(e===`postProcessingNode`){p.mutate({addonId:ir,cap:er,scope:`cluster`,patch:{[tr]:t}});return}p.mutate({addonId:Zn,cap:Kn,scope:`cluster`,patch:{[e]:t}})},S={capabilityPending:f.isPending,onToggleCapability:b},C=y?i(T,{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(K,{headingId:`roles-nodes-cluster-roles`,title:t(`pipeline.clusterRolesNodesTab.clusterRoles`,`Cluster roles`),icon:Ae,actions:C,children:[i(`p`,{className:`${G} 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(no,{roleValues:g,options:_,pending:p.isPending,onRoleChange:x})]}),i(K,{headingId:`roles-nodes-node-capabilities`,title:t(`pipeline.clusterRolesNodesTab.nodeCapabilities`,`Node capabilities`),icon:v,children:i(to,{nodes:h,actions:S})})]})}s();var io=2500,ao={faces:m,"semantic-search":L,"detail-crop":Pe,"native-lease":Fe,"runner-defaults":A,"load-balancer":je,failover:x},oo=[`cluster`,ui];function so(e){a(()=>{if(e===null)return;let t=fi[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`),io),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function co({section:t}){let{t:n}=Z();return i(`div`,{"data-cluster-settings-card":t.id,className:`rounded-lg`,children:i(K,{headingId:`cluster-settings-${t.id}`,title:t.title,...ao[t.id]===void 0?{}:{icon:ao[t.id]},children:e(`div`,{className:`${g} space-y-3`,children:[i(`p`,{className:G,children:t.hint}),t.panels.map(e=>i(Gn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:oo.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.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function lo({refreshToken:e}){let[t]=En();return so(t.get(hi)),i(`div`,{className:`space-y-3 sm:space-y-4`,children:di.map(e=>i(co,{section:e},e.id))})}function uo(e){return e?.hex}function fo({hex:e}){return i(`span`,{className:`inline-block h-3 w-3 shrink-0 rounded-sm border border-border`,style:{backgroundColor:e}})}function po({id:t,label:n,swatch:r}){let a=uo(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 mo({ground:t,group:n,swatches:r}){let{t:a}=Z();return e(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[i(po,{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(po,{id:e.id,label:e.label,swatch:r[e.id]},e.id))})]})]})}function ho({swatches:t}){let{t:n}=Z(),r=pe(),a=[{id:`dark`,background:ue.dark,ink:ue.light},{id:`light`,background:ue.light,ink:ue.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(mo,{ground:e.id,group:n,swatches:t},n.id))},e.id))]})}function go(e){for(let t of pe()){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 _o(e){return/^#[0-9a-f]{6}$/.test(e)}function vo(e,t){let n={};for(let r of Te){let i=t[r],a=e[r];i===void 0||a===void 0||i.hex!==a.hex&&(n[r]=i)}return n}function yo({status:t,reason:r,source:a,presetId:s,customized:c,swatches:l,presets:u,saving:d,onApply:f}){let{t:p}=Z(),[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:le(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(!_o(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(K,{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(Y,{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=uo(t.swatches[e]);return n===void 0?null:i(fo,{hex:n},e)}),t.name]})},t.id)),i(Y,{type:`button`,size:`sm`,variant:m?`primary`:`outline`,onClick:C,disabled:d||b===void 0,children:p(`pipeline.palette.custom`,`Custom`)})]})}),i(ho,{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(K,{headingId:`palette-custom`,title:p(`pipeline.palette.custom`,`Custom`),children:e(`div`,{className:`flex flex-col gap-2 p-3`,children:[Te.map(e=>{let t=uo(v[e]);return t===void 0?null:i(Wt,{field:{type:`color`,key:e,label:go(e)},values:{[e]:t},onChange:(t,n)=>w(e,n)},e)}),i(Y,{type:`button`,size:`sm`,onClick:()=>{if(b===void 0||x===null||!x.ok)return;let e=vo(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 bo(){let e=Lt({}),t=fn({}),n=tn(),r=r=>{n.mutate(r,{onSuccess:()=>{e.refetch(),t.refetch()}})};if(e.isPending||t.isPending)return i(yo,{status:`pending`,presets:[],onApply:r});if(e.isError||e.data===void 0)return i(yo,{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(yo,{status:`unknown`,reason:String(t.error),presets:[],saving:n.isPending,onApply:r});if(e.data.status===`unknown`)return i(yo,{status:`unknown`,reason:e.data.reason,presets:t.data,saving:n.isPending,onApply:r});let a=e.data;return i(yo,{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 xo=`pipeline-orchestrator`,So=200;function Co(){let{t}=Z();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(Kt,{addonId:xo,limit:So,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1,showSourceSelect:!0})})]})}var wo=[{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 To(e){return wo.some(t=>t.id===e)}function Eo({refreshToken:t}){let{t:n}=Z(),[r,a]=En(),o=r.get(mi),s=To(o)?o:`assignments`,c=e=>{a(t=>{let n=new URLSearchParams(t);return n.set(mi,e),n.delete(hi),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(bt,{value:s,onValueChange:e=>{To(e)&&c(e)},className:`px-4 sm:px-6`,children:i(_t,{className:`border-border`,children:wo.map(e=>i(xt,{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(Vi,{}),s===`load-balancing`&&i(Za,{refreshToken:t,onOpenAutoTune:()=>c(`auto-tune`)}),s===`auto-tune`&&i(oa,{}),s===`roles-nodes`&&i(ro,{}),s===`settings`&&i(lo,{refreshToken:t}),s===`logs`&&i(Co,{}),s===`palette`&&i(bo,{})]})]})}function Do({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(Oo,{})]})}function Oo(){let{t:e}=Z();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 ko={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 Ao({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 ${ko[e]}`,children:t})}function jo({children:e}){return i(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Mo({icon:t,label:n,nodeId:r,pinned:a,reason:o,overridden:s}){let{t:c}=Z();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(ne,{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 No({assignment:t,settings:n,onlineNodes:r,pinPending:a,onDetectionPinChange:o}){let{t:s}=Z(),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(Do,{title:s(`cameras.configBlocks.whereItRuns`,`Where it runs`),children:[i(Mo,{icon:A,label:s(`cameras.configBlocks.detection`,`Detection`),nodeId:t.detectionNodeId,pinned:t.pinned.detection,reason:t.reasons.detection,overridden:n.overriddenKeys.has(`pipelineNodeId`)}),i(Mo,{icon:ae,label:s(`cameras.configBlocks.decoder`,`Decoder`),nodeId:t.decoderNodeId,pinned:t.pinned.decoder,reason:t.reasons.decoder,overridden:n.overriddenKeys.has(`decoderNodeId`)}),i(Mo,{icon:D,label:s(`cameras.configBlocks.audio`,`Audio`),nodeId:t.audioNodeId,pinned:t.pinned.audio,reason:t.reasons.audio,overridden:n.overriddenKeys.has(`audioNodeId`)}),i(Mo,{icon:b,label:s(`cameras.configBlocks.source`,`Source`),nodeId:t.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),i(`div`,{className:`mt-1.5`,children:e(W,{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 Po(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Fo(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function Io(e){return e===null?X.t(`pipeline.configBlocks.fpsDefault`):e===0?X.t(`pipeline.configBlocks.fpsNative`):`${e} fps`}function Lo({streams:t,brokerProfiles:n,settings:r,motionEnabled:a,motionFpsLive:o,cameraSensors:s}){let{t:c}=Z(),l=Fo(n,r.detectionStreamProfile),u=Fo(n,r.motionStreamProfile),f=r.motionSources.includes(`analyzer`);return e(Do,{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:Io(r.detectionFps)}),e($,{label:c(`cameras.configBlocks.motionSrc`,`Motion src`),overridden:r.overriddenKeys.has(`motionSources`),children:[r.motionSources.length>0?r.motionSources.map(be).join(` + `):c(`cameras.configBlocks.none`),a===!1&&` · ${c(`cameras.configBlocks.inactive`)}`]}),i($,{label:c(`cameras.configBlocks.cameraSensors`,`Camera sensors`),children:Nn(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:[Io(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(jo,{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}),` `,Po(t)]},t.camStreamId))})]})}function Ro({steps:t,audioModelId:n,audioEnabled:r,audioMode:a}){let{t:o}=Z();return e(Do,{title:o(`cameras.configBlocks.pipelineSteps`,`Pipeline steps`),children:[t===void 0?i(jo,{children:o(`cameras.configBlocks.resolving`,`Resolving…`)}):t.length===0?i(jo,{children:o(`cameras.configBlocks.noStepsConfigured`,`No steps configured`)}):i(`div`,{className:`flex flex-wrap gap-1`,children:t.map((t,n)=>i(Ao,{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 zo={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Bo({detection:t,live:n,detectionMode:r,modeOverridden:a}){let o=F(),{t:s}=Z();if(t===null)return e(Do,{title:s(`cameras.runtimeBlocks.detectionRuntime`,`Detection runtime`),children:[i($,{label:s(`cameras.runtimeBlocks.mode`,`Mode`),overridden:a,children:r??`—`}),i(jo,{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=Ft(c,o),m=c===`active`&&l===0;return e(Do,{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(Ct,{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(Ao,{tone:zo[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 Vo({broker:t}){let{t:n}=Z();return t===null?i(Do,{title:n(`cameras.runtimeBlocks.streamBroker`,`Stream broker`),children:i(jo,{children:n(`cameras.runtimeBlocks.brokerStageInactiveOrUnreachable`,`Broker stage inactive or unreachable`)})}):e(Do,{title:n(`cameras.runtimeBlocks.streamBroker`,`Stream broker`),children:[t.profiles.length===0?i(jo,{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(Ao,{tone:t.webrtcSessions>0?`info`:`neutral`,children:n(`cameras.runtimeBlocks.webrtc`,{count:t.webrtcSessions})}),i(Ao,{tone:t.rtspRestream?`success`:`neutral`,children:t.rtspRestream?n(`cameras.runtimeBlocks.restreamOn`):n(`cameras.runtimeBlocks.restreamOff`)})]})]})}function Ho({decoder:e}){let{t}=Z();return e===null?i(Do,{title:t(`cameras.runtimeBlocks.decoder`,`Decoder`),children:i(jo,{children:t(`cameras.runtimeBlocks.decoderStageInactiveOrUnreachable`,`Decoder stage inactive or unreachable`)})}):i(Do,{title:t(`cameras.runtimeBlocks.decoder`,`Decoder`),children:i($,{label:t(`cameras.runtimeBlocks.node`,`Node`),children:e.nodeId})})}s();var Uo=`pipeline-orchestrator`,Wo={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Go={healthy:`pipeline.cameraPipelineCard.healthHealthy`,idle:`pipeline.cameraPipelineCard.healthIdle`,error:`pipeline.cameraPipelineCard.healthError`};function Ko({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(I,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),i(`span`,{className:`min-w-0`,children:t.message})]},t.code))})}function qo({deviceId:t,name:r,online:a,status:o,live:s,onlineNodes:c}){let{t:u}=Z(),d=l(),{data:f}=pt({addonId:Uo,deviceId:t,nodeId:`hub`},{staleTime:3e4}),{data:p}=Ut({deviceId:t},{staleTime:3e4}),m=n(()=>Un(f),[f]),h=n(()=>p===void 0?void 0:Wn(p.steps),[p]),g=n(()=>o===void 0?[]:Dn(o),[o]),_=()=>{d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),d.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=rt({onSuccess:_}),y=ot({onSuccess:_}),b=e=>{e===`auto`?y.mutate({deviceId:t}):v.mutate({deviceId:t,agentNodeId:e})},x=o===void 0?`idle`:kn(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`:Wo[x]}`,title:S?u(`common.error`,`Error`):u(Go[x]),"aria-label":S?u(`common.error`,`Error`):u(Go[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(Ao,{tone:`danger`,children:u(`common.offline`)}),e(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[m.detectionMode!==null&&i(Ao,{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(Ao,{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(Ao,{tone:`neutral`,title:u(`cameras.cameraPipelineCard.recordingMode`,`Recording mode`),children:u(`pipeline.cameraPipelineCard.recMode`,{mode:o.recording.mode})}))]})]}),g.length>0&&i(Ko,{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(No,{assignment:o.assignment,settings:m,onlineNodes:c,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),i(Bo,{detection:o.detection,live:s,detectionMode:m.detectionMode,modeOverridden:m.overriddenKeys.has(`detectionMode`)}),i(Ro,{steps:h,audioModelId:p?.audio?.modelId??null,audioEnabled:o.audio?.enabled??p?.audio?.enabled??null,audioMode:m.audioMode}),i(Lo,{streams:o.source.streams,brokerProfiles:o.broker?.profiles,settings:m,motionEnabled:o.motion?.enabled??null,motionFpsLive:o.motion?.fps??null,cameraSensors:o.cameraSensors}),i(Vo,{broker:o.broker}),i(Ho,{decoder:o.decoder})]})]})}s();var Jo=5e3,Yo=1e4,Xo=5e3;function Zo(e){let t=l(),{data:r,isLoading:i}=Cn(),{data:s,isLoading:c}=mn({},{refetchInterval:Jo}),{nodes:u}=J();a(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[d,f]=o(new Map);ft(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()-Yo,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Xo);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 Qo({refreshToken:t}){let{t:r}=Z(),{rows:a,liveMetrics:o,onlineNodes:s,isLoading:c}=Zo(t),l=n(()=>[...a.map(e=>{let t=e.status===void 0?[]:Dn(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(wn,{i18nKey:`pipeline.camerasOverview.camerasTotal`,values:{count:u.total},components:{b:i(`span`,{className:`font-semibold text-foreground`})}})}),i(`span`,{children:i(wn,{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(qo,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:o.get(e.deviceId),onlineNodes:s},e.deviceId))]})})}s();var $o=`__cluster__`;function es(e){return e===`cameras`?`cameras`:`nodes`}function ts({viewMode:t,onNodes:n,onCameras:r}){let{t:a}=Z();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 ns(){let{t}=Z(),[n,r]=En(),s=es(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`,$o),t},{replace:!0})},[s,n,r]),e(an,{icon:De,title:t(`pipeline.pipeline`,`Pipeline`),subtitle:t(`pipeline.detectionPlacementLoadAndPer`,`Detection placement, load and per-camera runtime across the cluster.`),actions:e(Y,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>u(e=>e+1),title:t(`common.refresh`,`Refresh`),children:[i(re,{className:`h-3.5 w-3.5`}),t(`common.refresh`,`Refresh`)]}),nav:i(ts,{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(Y,{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(Ee,{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(pr,{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(Eo,{refreshToken:l}):i(Bi,{nodeId:c,refreshToken:l})})]}):i(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:i(Qo,{refreshToken:l})})})]})}export{ns as PipelinePage};