@camstack/addon-admin-ui 1.2.400 → 1.2.401
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.
- package/dist/assets/{AddonAssetIcon-B8b_Ij3Q.js → AddonAssetIcon-CH44KPZz.js} +1 -1
- package/dist/assets/{Addons-Csw_pkUq.js → Addons-C78_DbR5.js} +1 -1
- package/dist/assets/{AdminSectionedPage-Dr8lqQvA.js → AdminSectionedPage-Cas7tPQF.js} +1 -1
- package/dist/assets/{AiProfiles-BUQCPfG2.js → AiProfiles-we-NM0x0.js} +1 -1
- package/dist/assets/{BrokerForm-CDY_h_x_.js → BrokerForm-Fue5yeWf.js} +1 -1
- package/dist/assets/{Build-DowgaoRs.js → Build-BMtzkZtb.js} +1 -1
- package/dist/assets/{Calendars-CjwnNTaU.js → Calendars-UUTinvNV.js} +1 -1
- package/dist/assets/{Cluster-B1dInAlz.js → Cluster-D4hEzfzb.js} +1 -1
- package/dist/assets/{ClusterStepModel-DvaE2Fpn.js → ClusterStepModel-CTANOakE.js} +1 -1
- package/dist/assets/{CompositionEditorPage-ILN_BH-0.js → CompositionEditorPage-CQw2AAoL.js} +1 -1
- package/dist/assets/{Data-hUPfS0O6.js → Data-Cv2ExaVb.js} +1 -1
- package/dist/assets/{DeviceDetail-ClcUBiDj.js → DeviceDetail-NIgDA3W2.js} +1 -1
- package/dist/assets/{Devices-CbF91f1O.js → Devices-C2mwY5Vm.js} +1 -1
- package/dist/assets/Identity-980vxd1i.js +1 -0
- package/dist/assets/{IntegrationDetail-CuUjr1ni.js → IntegrationDetail-CGyn--Ob.js} +1 -1
- package/dist/assets/{IntegrationHub-4oemdKQs.js → IntegrationHub-CWeAGP4K.js} +1 -1
- package/dist/assets/{Integrations-DPziOQvV.js → Integrations-BS1pA9wk.js} +1 -1
- package/dist/assets/{Integrations-CsXxPeGb.js → Integrations-CieAt3fz.js} +1 -1
- package/dist/assets/{Library-OaGdN5V3.js → Library-DbuK82vl.js} +1 -1
- package/dist/assets/{Locations-CPEee4O7.js → Locations-Br2MtIPm.js} +1 -1
- package/dist/assets/{Logs-BertXlLF.js → Logs-IXWqMTfX.js} +1 -1
- package/dist/assets/{MyAccess-HQF6tebp.js → MyAccess-6P61_7Zd.js} +1 -1
- package/dist/assets/{Network-CK42t6W_.js → Network-C90WVpEH.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-DRU_bmGt.js → NodeAddonsSettingsPanel-CTCzvYQd.js} +1 -1
- package/dist/assets/{Notifications-D5aHMhvU.js → Notifications-Uf92LH6m.js} +1 -1
- package/dist/assets/{Recordings-dPu5GCbo.js → Recordings-CGkCQLpU.js} +1 -1
- package/dist/assets/{ScanNetworkModal-XJW0dYom.js → ScanNetworkModal-CAD9TpeT.js} +1 -1
- package/dist/assets/{SessionsList-ZafI0kEX.js → SessionsList-BP3FF4d7.js} +1 -1
- package/dist/assets/{Showroom-CMomGEBv.js → Showroom-DoBL1cOM.js} +1 -1
- package/dist/assets/{System-SugJLaIm.js → System-lwL-J3ap.js} +1 -1
- package/dist/assets/{Terminal-CMZkgAtq.js → Terminal-BprsVHgI.js} +1 -1
- package/dist/assets/{device-integration-icon-DoswOpEp.js → device-integration-icon-AZ69SQUk.js} +1 -1
- package/dist/assets/{index-B-BE8EYQ.js → index-CFJxM0gv.js} +2 -2
- package/dist/assets/{location-owned-usage-DxjPP5ha.js → location-owned-usage-D9fKCiv6.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-50b2491c.js → mf-entry-bootstrap-0-3760bdf2.js} +1 -1
- package/dist/assets/{useNodeUrlSelection-yjHHXKaf.js → useNodeUrlSelection-BtLkr-A7.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Identity-Xw1YjqEJ.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Cyuzqnbw.js";import{I as t,K as n,Q as r,S as i,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{A as p,D as m,N as h,O as g,T as _,V as v,_t as y,b,ct as x,dt as S,gt as C,j as w,k as T,ot as E,v as D,y as O,yt as k,z as A}from"./player-overlays-9CMoB0XN.js";import{$l as j,An as M,As as N,Bs as P,C as ee,Cn as F,Cs as I,Ds as L,E as te,Ed as ne,Es as re,F as ie,Ff as ae,Fn as R,Gn as z,Gs as oe,H as se,Hd as ce,Hn as B,Hs as le,Ht as ue,In as de,J as fe,Js as pe,Jt as me,Ju as he,Ks as ge,Ls as _e,Mn as ve,Mt as ye,Nn as be,Ns as xe,O as Se,Os as Ce,Pn as we,Qd as V,Ql as Te,Qs as Ee,Rs as De,Ru as Oe,S as ke,Sn as H,Sr as Ae,Ss as je,Su as Me,T as Ne,Td as Pe,Ts as Fe,Tt as Ie,Un as Le,Ut as Re,Vs as ze,Vt as U,W as Be,Ws as Ve,Xs as He,Y as Ue,Ys as We,Yt as Ge,Zs as Ke,Zu as qe,ad as Je,bn as Ye,cc as Xe,cn as Ze,cu as Qe,dc as $e,du as et,ed as tt,eu as nt,fn as rt,fu as it,gn as at,hn as ot,jn as st,kd as ct,kn as lt,ks as ut,ku as dt,lc as ft,ln as pt,lu as mt,mn as ht,mu as gt,nr as _t,oc as vt,od as yt,pc as bt,pd as xt,pn as St,pu as Ct,ql as W,qt as wt,r as Tt,sc as Et,su as G,uc as Dt,un as Ot,ur as K,uu as kt,va as At,vn as jt,vr as Mt,vt as Nt,vu as Pt,w as Ft,wd as It,ws as Lt,yn as Rt,yr as zt,zd as Bt}from"./src-Ca4gNAmP.js";import{t as Vt}from"./crop-ChT009Qt.js";import{t as Ht}from"./layers-Bg1NrUAX.js";import{An as Ut,Br as Wt,Dn as Gt,En as Kt,Mn as qt,On as Jt,Tn as Yt,c as Xt,fi as Zt,jn as Qt,kn as $t,l as en,m as tn,wn as nn,yi as rn,zr as an}from"./client-1JBRoe76.js";import{n as on}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{$ as sn,H as cn,Y as ln,it as un,rt as dn}from"./index-B-BE8EYQ.js";import"./useEventInvalidation-DD88fyzH.js";import{t as fn}from"./NodeAddonsSettingsPanel-DRU_bmGt.js";import{a as pn,c as mn,d as hn,g as gn,h as _n,i as vn,l as yn,n as bn,o as xn,p as Sn,r as Cn,s as wn,t as Tn}from"./board-model-Bmts6hrg.js";var En=k(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),Dn=k(`crown`,[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]),On=k(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),kn=k(`scale`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`m19 8 3 8a5 5 0 0 1-6 0zV7`,key:`zcdpyk`}],[`path`,{d:`M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1`,key:`1yorad`}],[`path`,{d:`m5 8 3 8a5 5 0 0 1-6 0zV7`,key:`eua70x`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}]]),An=k(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]),jn=`step`,Mn=[jn,`acc`];function Nn(e,t){return`${e}/${t}`}function Pn(e,t,n){let r=n.step!==null&&e.includes(n.step),i=n.acc!==null&&t.includes(n.acc);return{stepId:r?n.step:null,acceleratorId:i?n.acc:null,staleStepId:n.step!==null&&n.step!==``&&!r&&e.length>0?n.step:null}}function Fn(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 In(e){return e}function Ln(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Rn(e,t){return typeof e==`boolean`?e:In(t)}function zn(e,t){return{pipeline:Rn(Ln(e,`detect`),t),audio:Rn(Ln(e,`audio`),t),ingest:Rn(Ln(e,`ingest`),t)}}function Bn(e,t,n){let r=e?.find(e=>e.nodeId===t);return zn(r?.settings,n)}function Vn({selectedNodeId:e,onSelect:t,refreshToken:n}){let{nodes:r}=Qe(),{data:a}=P(void 0),{data:s}=Ve(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=r??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return i(`div`,{className:`flex flex-col h-full`,children:[i(`button`,{type:`button`,onClick:()=>t(ko),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[d(dn,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Assignments, load balancing, roles`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let r=e===n.id,a=c.get(n.id)??0,l=n.isHub?qe:V,u=Bn(s,n.id,n.isHub),f=n.isOnline?null:Nt(Fn(n.lastSeen));return i(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-danger flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),i(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[i(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(Me,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`text-danger`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(K,{variant:u.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),d(K,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),i(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[i(`span`,{children:[u,` online`]}),f>0&&i(`span`,{className:`text-danger`,children:[f,` offline`]})]})]})}function Hn({nodeId:e,refreshToken:t}){let{nodes:n}=Qe(),r=n?.find(t=>t.id===e),a=mt(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?i(`div`,{className:`px-6 py-4 border-b border-border`,children:[i(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-danger/10 text-danger`,children:`offline`}),r.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:r.cpuModel??`CPU`}),d(`span`,{children:`•`}),i(`span`,{children:[r.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),i(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),i(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&i(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:i(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var Un=[`assignments`,`tree`,`engines`,`logs`];r();function Wn({refreshToken:e,nodeId:t}){let[n,r]=u(new Map),{nodes:o}=G();et(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=N(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[l,o]);if(t){let e=l.get(t);return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(q,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(q,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(q,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(q,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(q,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(q,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),i(`tbody`,{children:[m.map(([e,t])=>i(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}var Gn={active:!1,pinned:!1,nodeId:null,reason:``};function Kn(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function qn(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??``}:Gn,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:Gn;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:Gn,audio:o}}).toSorted(Kn)}function Jn(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function Yn(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:Jn(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:Jn(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:Jn(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function Xn(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(Kn)}function Zn(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 Qn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??`Camera ${e}`}function $n(e,t,n){return[{value:`auto`,label:`Auto`},...[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])].map(e=>({value:e,label:`Pin → ${n(e)}`}))]}function er({roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:i,emphasizeOnNodeId:a}){if(n.nodeId===null)return null;let o=n.nodeId,s=a===void 0?!1:n.active&&o===a;return d(wt,{roleId:e,roleLabel:t,nodeName:r(o),colorId:Ge(i,o),emphasized:s,pinned:n.pinned})}function tr({detection:e,decoder:t,audio:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o}){let s=(e,t,n)=>d(er,{roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o},e);return i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[s(`detection`,`Detection`,e),s(`decode`,`Decode`,t),s(`audio`,`Audio`,n)]})}function nr({snap:e}){if(e===void 0)return d(`div`,{className:`flex h-8 items-center text-[11px] text-foreground-subtle`,title:`No metrics in the last 10 s — the camera has no session running`,children:`no live data`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=ye(t);return i(`div`,{className:`flex h-8 min-w-0 flex-col justify-center font-mono text-[10px] leading-tight tabular-nums`,children:[i(`span`,{className:`inline-flex min-w-0 items-center gap-1 ${c.textColor}`,children:[d(ie,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate font-semibold uppercase tracking-wider`,children:c.label}),d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[`/`,o.toFixed(0),` fps`]})]}),i(`span`,{className:`truncate text-foreground-subtle`,children:[d(`span`,{className:`text-foreground`,children:r.toFixed(0)}),` ms`,a>0&&i(`span`,{className:`ml-1 text-warning`,children:[`q`,a]}),i(`span`,{className:s>0?`ml-1 text-warning`:`ml-1`,children:[`drops `,s]})]})]})}r();var rr=1e4,ir=5e3;function ar(e){let[t,n]=u(new Map);return et(`pipeline.camera-metrics-snapshot`,t=>{let r=t.data;typeof r.deviceId==`number`&&(e!==void 0&&r.nodeId!==e||n(e=>new Map(e).set(r.deviceId,r)))}),f(()=>{if(t.size===0)return;let e=setInterval(()=>{n(e=>{let t=Date.now()-rr,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},ir);return()=>clearInterval(e)},[t.size]),t}var or=3e5;function sr({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:i}){return d(W,{"aria-label":`Node pin`,title:`Auto lets each session pick its node; a pin keeps the camera on one node.`,value:e.pinned&&e.nodeId!==null?e.nodeId:`auto`,disabled:r,options:[...$n(e,t,n)],onChange:e=>i(e.target.value)})}function cr({deviceId:e,nodeId:t}){let n=c(),{data:r}=ze({deviceId:e},{refetchOnMount:`always`}),{data:i}=De({nodeId:t},{staleTime:or}),a=Et({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`accelerator: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),l=r?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l),f=o.find(e=>e.key===l),p=[{value:`auto`,label:`Any accelerator`},...u?[{value:l,label:`${f?`${H(f)} (${l})`:l} (not enabled)`}]:[],...s.map(e=>({value:e.key,label:`${H(e)} · ${e.format}`}))];return d(W,{"aria-label":`Inference device pin`,title:`Pin detection to one accelerator of the node, or let each session pick.`,value:l,disabled:a.isPending,options:p,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value})})}r();function lr(e){let t=n(null);return e.nodeId!==null&&(t.current=e),t.current}function ur({deviceId:e,state:t,...n}){let r=lr(t);return i(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[d(sr,{state:t,...n}),r?.nodeId==null?d(W,{"aria-label":`Inference device pin (no node yet)`,title:`An accelerator is pinned on the camera's node; this camera has not run on one yet.`,disabled:!0,defaultValue:`auto`,options:[{value:`auto`,label:`Any accelerator`}]}):d(cr,{deviceId:e,nodeId:r.nodeId})]})}function dr({state:e,nameOf:t}){let n=lr(e);if(n?.nodeId==null)return d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`— no session yet`});let r=e.active&&e.nodeId!==null,a=n.pinned?`pinned`:`auto · ${n.reason||`capacity`}`;return i(`div`,{"data-testid":`resolved-placement`,className:`flex w-40 min-w-0 flex-col leading-tight`,title:n.pinned?void 0:`An unpinned camera is placed again at every session start, so this can change between sessions.`,children:[i(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[d(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${r?`bg-success`:`bg-foreground-subtle/40`}`}),d(`span`,{"data-testid":`resolved-placement-node`,className:`truncate font-medium ${r?`text-foreground`:`text-foreground-muted`}`,children:t(n.nodeId)})]}),d(`span`,{className:`truncate pl-3 text-[10px] ${n.pinned?`text-warning`:`text-foreground-subtle`}`,children:r?a:`${a} · idle, last session`})]})}function fr({deviceId:e,deviceName:t}){let[n,r]=u(!1);return i(o,{children:[d(j,{icon:yt,variant:`ghost`,size:`sm`,"aria-label":`Stream brokers of ${t}`,title:`Stream brokers & clients`,onClick:()=>r(!0)}),d(M,{open:n,onOpenChange:r,children:i(ve,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[d(R,{children:i(de,{children:[t,` — stream brokers & clients`]})}),d(st,{children:n&&d(lt,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e,instanceId:`pipeline-row/${e}`,config:{variant:`compact`}})})]})})]})}function pr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function mr(e,t){return t.size===0?!0:t.has(e)}var hr=[{value:`active`,label:`Active`},{value:`recently-active`,label:`Recently active`},{value:`inactive`,label:`Inactive`}];r();var gr=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function _r(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function vr(){let e=c();Tt([`pipelineOrchestrator`,`getPipelineAssignments`],gr),Tt([`pipelineOrchestrator`,`getAudioAssignments`],gr),Tt([`pipelineOrchestrator`,`getCameraStatuses`],gr);let{data:t}=At({isCamera:!0,projection:`slim`}),{data:n}=P(void 0),{data:r}=ut(void 0),{data:o}=xe({}),{data:s}=Ve(void 0),{nodes:l}=G(),f=ar(),p=a(()=>Zn(l),[l]),m=a(()=>me(s),[s]),h=a(()=>l.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[l]),g=a(()=>Yn(qn((t??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),n??[],r??[]),o??[]),[t,n,r,o]),[_,v]=u(()=>new Set),y=a(()=>g.filter(e=>mr(pr({hasPipelineAssignment:e.pipeline.active,hasFreshMetrics:f.has(e.deviceId)}),_)),[g,f,_]),x=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=()=>_r(e),C=L({onSuccess:S}),w=$e({onSuccess:S}),T=C.isPending||w.isPending,E=[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[d(ln,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName}),e.disabled&&d(K,{variant:`default`,children:`off`})]})},{key:`placement`,header:`Placement`,width:`w-80`,notSortableReason:`A pair of controls — editing one would move the row under the cursor.`,render:e=>d(ur,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:h,nameOf:p,pending:T,onChange:t=>t===`auto`?w.mutate({deviceId:e.deviceId}):C.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:e=>d(tr,{detection:e.detection,decoder:e.decoder,audio:e.audio,nameOf:p,colorByNodeId:m})},{key:`resolved`,header:`Running on`,width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:p(e.pipeline.nodeId),render:e=>d(dr,{state:e.pipeline,nameOf:p})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>f.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(nr,{snap:f.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>d(fr,{deviceId:e.deviceId,deviceName:e.deviceName})}],k=t===void 0?`Loading cameras…`:g.length===0?`No cameras`:`No cameras match this activity filter.`;return i(`div`,{className:`flex flex-col gap-2`,children:[d(`nav`,{"aria-label":`Filter by camera activity`,"data-testid":`assignments-activity-filter`,children:d(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:hr.map(e=>{let t=_.has(e.value);return d(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:nt(O,t?D:b),onClick:()=>x(e.value),children:e.label},e.value)})})}),d(ue,{columns:E,rows:y,rowKey:e=>e.deviceId,minWidthPx:920,mobileMode:`scroll`,maxBodyHeight:Re,emptyMessage:k})]})}r();function yr({nodeId:e}){let t=c();Tt([`pipelineOrchestrator`,`getCameraStatuses`],gr);let{data:n}=xe({}),{data:r}=Ve(void 0),{data:i}=At({isCamera:!0,projection:`slim`}),{nodes:o}=G(),s=ar(),l=a(()=>Zn(o),[o]),u=a(()=>me(r),[r]),f=a(()=>Xn(e,n??[],Qn((i??[]).map(e=>({id:e.id,name:e.name})))),[e,n,i]),p=o.filter(t=>t.isOnline&&t.id!==e),m=()=>_r(t),h=L({onSuccess:m}),g=$e({onSuccess:m}),_=re({onSuccess:m}),v=Dt({onSuccess:m}),y=e=>[...e.detection.active?p.map(t=>({id:`detect-${t.id}`,label:`Move detection to ${t.name}`,onClick:()=>h.mutate({deviceId:e.deviceId,agentNodeId:t.id})})):[],...e.audio.active?p.map(t=>({id:`audio-${t.id}`,label:`Move audio to ${t.name}`,onClick:()=>_.mutate({deviceId:e.deviceId,nodeId:t.id})})):[],{id:`unpin-detect`,label:`Unpin detection`,hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>g.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:`Unpin audio`,hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>v.mutate({deviceId:e.deviceId})}];return d(ue,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>d(ln,{to:`/devices/${String(e.deviceId)}`,className:`block w-44 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:t=>d(tr,{detection:t.detection,decoder:t.decoder,audio:t.audio,nameOf:l,colorByNodeId:u,emphasizeOnNodeId:e})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(nr,{snap:s.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>d(Be,{items:y(e),title:`Move ${e.deviceName}`})}],rows:f,rowKey:e=>e.deviceId,minWidthPx:560,mobileMode:`scroll`,maxBodyHeight:Re,emptyMessage:n===void 0?`Loading cameras…`:`No camera runs on this node right now`})}function br({nodeId:e,refreshToken:t}){let{nodes:n}=G(),r=n.find(t=>t.id===e)?.name??e;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(Wn,{refreshToken:t,nodeId:e}),i(`div`,{className:`space-y-2`,children:[i(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:[`Cameras on `,r]}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The roles each camera runs here right now. Move a role or unpin it from the row menu; pins for every camera are on Cluster → Assignments.`})]}),d(yr,{nodeId:e})]})]})}r();function xr(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Sr({nodeId:e,refreshToken:t}){let n=c(),r=_t(),o=I({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:s}=Lt({nodeId:e}),l=mt(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??s??null,u=l===null;Tt([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=bt({nodeId:e}),{values:p}=kt(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=a(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),h=t=>{let n=f??[];if(n.length===0){o.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await r({title:`Kill engine`,message:`${String(n.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:`Kill engine`,variant:`danger`})&&o.mutate({nodeId:e,engine:t,force:!0})})()};return i(`div`,{className:`space-y-6`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(l??[]).length,` engine(s) resident in RAM. `,(f??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),i(`tbody`,{children:[u&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!u&&(l??[]).map(e=>{let t=e.kind===`device-pool`;return i(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[d(t?Ht:V,{className:`h-3 w-3`}),t?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(Ct,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),d(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?d(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>d(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),d(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),d(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?d(`span`,{className:`text-foreground-subtle`,children:xr(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(f??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:t?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):i(z,{variant:`ghost`,size:`sm`,disabled:o.isPending,onClick:()=>h(e.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[d(x,{className:`h-3.5 w-3.5`}),`Kill`]})})]},e.engineKey)}),!u&&(l??[]).length===0&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),o.isError&&d(B,{message:`Kill failed: ${o.error instanceof Error?o.error.message:`unknown error`}`})]})}var Cr=`pipeline-runner`,wr=200;function Tr({nodeId:e}){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(Ie,{agentId:e,addonId:Cr,limit:wr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}r();function Er({nodeId:e,title:t}){let{data:n}=cn(),{data:r}=P(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),c=ar(e),l=a(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return l.length===0?i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[i(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=ye(e.metrics.phase);return i(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[d(ie,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}function Dr(e,t,n){return e.map(e=>{if(e.key===t)return e;let r=e.steps[n];if(!r||r.settings===void 0)return e;let{settings:i,...a}=r,o={...e.steps};return Object.keys(a).length>0?o[n]=a:delete o[n],{...e,steps:o}})}function Or(e,t,n){let r=e.filter(e=>e.key!==t).toSorted((e,t)=>e.key.localeCompare(t.key)),i=[...r.filter(e=>!e.enabled),...r.filter(e=>e.enabled),...e.filter(e=>e.key===t)],a;for(let e of i){let t=e.steps?.[n]?.settings;!t||Object.keys(t).length===0||(a={...a,...t})}return a}function kr(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 Ar=`pipeline-orchestrator`;function jr({addonId:e,highlightLabel:t}){let n=Jt(e),{data:r}=zt({addonId:Ar});if(n.length===0)return null;let a=Qt(r??null)[e]??{};return i(`section`,{className:`space-y-1.5 border-t border-border/60 pt-3`,"aria-label":`Cluster-wide settings`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:v,children:`Cluster-wide settings`}),d(ln,{to:Io(e),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Edit in Cluster → Settings ›`})]}),n.map(e=>i(`div`,{className:`${p} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[d(`span`,{className:w,children:e.label}),d(`span`,{className:h,children:d(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),d(`p`,{className:A,children:`One value for every node and camera — this step writes into a shared index.`})]})}function Mr({rows:e}){return i(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>i(`li`,{className:`${_} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-foreground-muted`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:e.modelId??`—`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.sourceLabel})]},e.id))}),d(`p`,{className:A,children:`To change a model, open that accelerator's cell in the table.`})]})}r();function Nr(e,n){let[r,i]=sn(),o=r.get(jn),s=r.get(`acc`),c=a(()=>Pn(e,n,{step:o,acc:s}),[e,n,o,s]),l=t(e=>{i(t=>{let n=new URLSearchParams(t);return e(n),n},{replace:!0})},[i]);return{selection:c,open:t(e=>l(t=>{t.set(jn,e.stepId),e.acceleratorId===void 0?t.delete(`acc`):t.set(`acc`,e.acceleratorId)}),[l]),close:t(()=>l(e=>{e.delete(jn),e.delete(`acc`)}),[l])}}function Pr(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function Fr(e){return e.split(`.`)[0]??e}function Ir(e,t,n){return{id:Nn(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${Fr(t)} · ${H(n)}`,shortLabel:`${Fr(t)} · ${F(n)}`,nodeLabel:Fr(t),disabled:!n.enabled}}function Lr(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>Ir(e,t,n))}function Rr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>Ir(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>Ir(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[Ir(e.id,e.name,a)]})}function zr(e,t,n){return{modelId:jt({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function Br(e,t,n){let r=Pr(e,`object-detection`);if(r===null)return;let i=jt({catalog:r,device:t.device,base:t.device.steps?.[`object-detection`]?.modelId,override:n});if(i===void 0)return;let a=r.models.find(e=>e.id===i);return{modelId:i,name:a?.name??i,supplies:a?.suppliesSteps??[]}}function Vr(e,t,n){return!an(e)||n===void 0?!1:Wt(e,t,n.supplies).effective}function Hr(e,t){return e!==null&&Rt(e.models,t.device.format)}function Ur(e){return Hr(e.addon,e.acc)?e.clusterModelId===void 0?{kind:`enabled`,modelId:e.model.modelId??`Auto`,overridden:e.model.source===`camera`,...e.rootName===void 0?{}:{suppliedByRoot:e.rootName},...e.jumpTo===void 0?{}:{jumpTo:e.jumpTo}}:{kind:`enabled`,modelId:e.clusterModelId,clusterWide:!0}:e.gatedOn?e.jumpTo===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:e.jumpTo}:{kind:`na`}}function Wr(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function Gr(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=Jt(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function Kr(e){return e.flatMap(e=>[{node:e,depth:0},...Kr(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function qr(e,t){return e.flatMap(e=>{let n=qr(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}r();function Jr(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:H(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Yr({tree:e,searchRows:r,accelerators:o,cellState:s,stepBadge:c,disabledCount:l,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:y}){let b=_t(),x=Ze(),{selection:S,open:C,close:w}=Nr(a(()=>Kr(e).map(e=>e.node.addonId),[e]),a(()=>o.map(e=>e.id),[o])),[T,E]=u(``),[D,O]=u(null),[k,M]=u(null),N=n(null),P=n(null),F=n(null),I=n(null),L=a(()=>ee(r,T),[r,T]),ne=a(()=>T.trim()===``?e:qr(e,new Set(L.map(e=>e.addonId))),[e,L,T]),re=e=>L.find(t=>t.addonId===e)?.matchedField??null,ie=a(()=>o.map(Jr),[o]),ae=e=>o.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),R=o.find(e=>e.id===S.acceleratorId)??null,z=S.stepId!==null,oe=t(async e=>{if(m){if(!await b({title:`Discard unsaved changes?`,message:`This step has changes that are not saved yet.`,confirmLabel:`Discard`,variant:`danger`}))return;h()}e()},[b,m,h]),se=()=>{requestAnimationFrame(()=>I.current?.focus())},ce=(e,t,n=!1)=>{if(e===S.stepId&&(t?.id??null)===S.acceleratorId){n&&se();return}let r=()=>{O(re(e)),C({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&se()};e===S.stepId?r():oe(r)},B=()=>{let e=S.stepId;oe(()=>{if(w(),e!==null){let t=R===null?null:Ue({agentNodeId:R.nodeId,deviceKey:R.deviceKey});requestAnimationFrame(()=>N.current?.focusCell(e,t))}})},le=e=>{if(e.key===`Enter`){let t=L[0];if(t===void 0)return;e.preventDefault(),ce(t.addonId,void 0,!0)}else e.key===`Escape`&&E(``)},ue=x?d(te,{onClick:B}):d(j,{icon:gt,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:B});return i(`div`,{ref:P,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),F.current?.focus()),e.key===`Escape`&&t&&z&&(e.preventDefault(),B())},children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),d(`input`,{ref:F,type:`search`,value:T,onChange:e=>E(e.target.value),onKeyDown:le,placeholder:`Filter steps or settings /`,"aria-label":`Filter steps or settings`,className:`h-9 w-56 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30 md:h-7`}),l>0&&i(`label`,{className:`inline-flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(Ot,{checked:f,onChange:e=>p(e.target.checked)}),`Show disabled accelerators (`,l,`)`]}),_]}),S.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:[`The link names a step this pipeline does not have (`,S.staleStepId,`).`]}),ne.length===0?i(`p`,{className:`${A} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:[`No step matches “`,T,`”.`]}):d(fe,{ref:N,tree:ne,agents:ie,label:v,getCellState:(e,t)=>{let n=ae(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>ce(e,ae(t),n),onStepClick:(e,t)=>ce(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:z&&S.stepId!==null&&R!==null?{addonId:S.stepId,agentNodeId:R.nodeId,deviceKey:R.deviceKey}:null,fallbackNodeId:k,onFallbackNodeChange:M,reserveRightPx:z&&!x?432:0}),d(Se,{open:z,anchor:P,onClose:B,label:`Step settings`,children:S.stepId!==null&&y({stepId:S.stepId,accelerator:R,matchedField:D,closeButton:ue,onEscape:B,headingRef:e=>{I.current=e}})})]})}r();function Xr(e){f(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}r();function Zr(e,t){let n=e.filter(e=>e.steps?.[t]?.settings!==void 0),r=e=>e.toSorted((e,t)=>e.key.localeCompare(t.key));return r(n.filter(e=>e.enabled))[0]?.key??r(n)[0]?.key??r(e.filter(e=>e.enabled))[0]?.key??e[0]?.key}function Qr(e,t){let n=t.settings===void 0?void 0:Zr(e,t.stepId),r=e.map(e=>{let r={...e.steps},i=r[t.stepId]??{},a=t.models[e.key],o=t.jumps[e.key],s=e.key===n&&t.settings!==void 0?Object.keys(t.settings).length>0?t.settings:void 0:i.settings,c=a===void 0?i.modelId:a??void 0,l=o===void 0?i.jumpDeviceKey:o||void 0,u={...c===void 0?{}:{modelId:c},...s===void 0?{}:{settings:s},...l===void 0?{}:{jumpDeviceKey:l}};return Object.keys(u).length>0?r[t.stepId]=u:delete r[t.stepId],{key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:r}});return n===void 0?r:Dr(r,n,t.stepId)}function $r(e,t,n){if(t===null)return 0;let r=Object.entries(t.models).filter(([n,r])=>(r??void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.modelId).length,i=Object.entries(t.jumps).filter(([n,r])=>(r||void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.jumpDeviceKey).length,a=new Set([...Object.keys(n),...Object.keys(t.settings??{})]),o=t.settings===void 0?0:[...a].filter(e=>!tn(n[e],t.settings?.[e])).length;return r+i+o}function ei({nodeId:e,nodeName:t,toolbar:n}){let r=c(),s=De({nodeId:e},{refetchOnMount:`always`}),l=je({nodeId:e},{refetchOnMount:`always`}),f=Ut(zt({addonId:`pipeline-orchestrator`}).data??null),p=s.data?.devices??[],m=l.data??null,[h,g]=u(null),[_,y]=u(null),[b,x]=u(null),S=Ke({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),C=a(()=>m?ke(m):[],[m]),w=a(()=>Kr(C),[C]),[T,E]=u(!1),D=a(()=>Lr(e,t,p,T),[e,t,p,T]),O=a(()=>Lr(e,t,p),[e,t,p]),k=O.length>=2,j=(e,t)=>(t===void 0?void 0:Or(p,t.deviceKey,e))??{},M=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return O.find(e=>e.deviceKey===r);if(!Hr(e,t))return O.filter(n=>n.id!==t.id&&Hr(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},N=(e,t)=>{let n=Pr(m,e),r=zo(e),i=Br(m,t),a=j(e,t),o=M(n,t);return Ur({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?zr(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...Vr(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:f[e]??r.defaultModelId}:{},...o?{jumpTo:F(o.device)}:{}})},P=w.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Gr(Pr(m,e.addonId))}));if(s.isLoading||l.isLoading)return d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`});if(m===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`});let ee=i(`span`,{className:A,children:[`Accelerators:`,` `,d(`span`,{className:`text-foreground`,children:O.length>0?O.map(e=>F(e.device)).join(` · `):`none enabled`}),p.some(e=>!e.enabled)&&i(o,{children:[` `,`— off:`,` `,p.filter(e=>!e.enabled).map(F).join(`, `)]}),` `,`·`,` `,d(ln,{to:Lo(),className:`text-primary hover:underline`,children:`Cluster → Load balancing ›`})]});return d(Yr,{tree:C,searchRows:P,accelerators:D,cellState:N,disabledCount:p.filter(e=>!e.enabled).length,showDisabled:T,onShowDisabledChange:E,dirty:h!==null&&$r(p,h,j(h.stepId,D[0]))>0,onDiscard:()=>g(null),summary:ee,...n===void 0?{}:{toolbar:n},label:`Detection steps`,renderDetail:({stepId:n,accelerator:r,matchedField:a,closeButton:s,onEscape:c,headingRef:l})=>{let u=Pr(m,n);if(u===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let f=h?.stepId===n?h:null,C=r??O[0]??D[0],w=j(n,C),T=f?.settings??w,E=$r(p,f,w),N=e=>{x(null),g(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},P=zo(n),ee=ht(u),F=C===void 0?void 0:Br(m,C),I=e=>{let t=f?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},L=C===void 0?void 0:zr(u,C,{nodePin:I(C)}).modelId,te=D.length>1&&D.some(e=>!tn(j(n,e),w)),ne=e=>{let t=I(e),r=zr(u,e,{nodePin:t}),a=Br(m,e),s=Vr(n,f?.settings??j(n,e),a),c=f?.jumps[e.deviceKey],l=M(u,e,c),p=Hr(u,e)?s&&a?d(rt,{rootModel:a,stepModelId:r.modelId}):void 0:i(o,{children:[`No `,e.device.format,` build of this step.`,` `,l?`It runs on ${l.shortLabel} instead.`:`It does not run here.`]}),h=k?i(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Run on`}),d(W,{"aria-label":`Run on`,value:c??e.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:`Auto (this accelerator, or the next one that can run it)`},...O.filter(t=>t.id!==e.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:t=>N({jumps:{...f?.jumps,[e.deviceKey]:t.target.value}})}),d(`span`,{className:A,children:`Routes this step (and its child steps) to another accelerator of this node.`})]}):void 0;return{label:e.label,format:e.device.format,modelId:r.modelId,source:r.source===`node`?`node`:`default`,sourceLabel:r.source===`node`?`node pin`:`hardware default`,models:Ye(u.models??[],e.device.format),defaultModelId:u.defaultModelIdByFormat?.[e.device.format]??u.defaultModelId,expanded:_===e.id,onToggle:()=>y(t=>t===e.id?null:e.id),onChangeModel:t=>N({models:{...f?.models,[e.deviceKey]:t}}),...t===void 0?{}:{onReset:()=>N({models:{...f?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...p===void 0?{}:{note:p},...h===void 0?{}:{extra:h},changed:f?.models[e.deviceKey]!==void 0||c!==void 0}},re=()=>{f!==null&&S.mutate({agentNodeId:e,inferenceDevices:kr(Qr(p,f))},{onSuccess:()=>{g(null),x({kind:`saved`})},onError:e=>x({kind:`error`,error:e.message})})};return d(Ne,{ref:l,title:r===null?`${u.name} · ${t}`:`${u.name} · ${r.label}`,subtitle:r===null?`${u.slot} · every accelerator of ${t}`:`${u.slot} · ${r.device.format} · base for every camera that lands here`,leading:s,onEscape:c,saveBar:{dirtyCount:E,saving:S.isPending,status:b?.kind??null,...b?.error===void 0?{}:{error:b.error},onSave:re,onDiscard:()=>g(null)},children:i(`div`,{className:`space-y-3`,children:[i(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[d(`h3`,{className:v,children:`Model`}),P!==null&&C!==void 0?d(Bo,{step:P,engineFormat:C.device.format,runnableModelIds:Ye(u.models??[],C.device.format).map(e=>e.id)}):D.length===0?i(`p`,{className:A,children:[`No accelerator is enabled on this node —`,` `,d(ln,{to:Lo(),className:`text-primary hover:underline`,children:`enable one in Cluster → Load balancing`}),`.`]}):r===null?d(Mr,{rows:D.map(e=>{let t=zr(u,e,{nodePin:I(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):d(Ft,{...ne(r)},r.id)]}),(ee.length>0||F!==void 0)&&P===null&&i(`section`,{"aria-label":`Settings`,className:`space-y-2 border-t border-border/60 pt-2`,children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`settings-scope`,children:[`Node-wide: these settings apply on every accelerator of `,t,`.`]}),te&&d(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2 py-1 text-[11px] text-warning`,children:`This step's settings differ between this node's accelerators. Saving makes the values shown here node-wide.`}),d(ti,{addon:u,fields:ee,settings:T,modelId:St(u,L,T,F),root:F,highlight:a,onChange:e=>N({settings:e})})]}),d(jr,{addonId:n,highlightLabel:a})]})})}})}function ti({addon:e,fields:t,settings:n,modelId:r,root:i,highlight:a,onChange:o}){let s=t.find(e=>`label`in e&&e.label===a)?.key??null;return Xr(s===null?null:at(s)),d(ot,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:`Node`},modelId:r,...i===void 0?{}:{rootModel:i},highlightKey:s,onChangeLayer:o})}r();function ni({nodeId:e,refreshToken:t}){let n=_t(),[r,a]=u(null),{nodes:s}=G(),c=s.find(t=>t.id===e)?.name??e,l=pe({onSuccess:e=>{a(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${c} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(a(null),l.mutate({agentNodeId:e}))};return i(`div`,{className:`space-y-2`,children:[d(Er,{nodeId:e}),d(ei,{nodeId:e,nodeName:c,toolbar:i(o,{children:[r&&d(`span`,{className:`text-[11px] text-success`,children:r}),l.isError&&d(`span`,{className:`text-[11px] text-danger`,children:l.error instanceof Error?l.error.message:`Reset failed`}),d(z,{variant:`outline`,size:`sm`,onClick:()=>{f()},disabled:l.isPending,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:l.isPending?`Resetting…`:`Reset to default`})]})})]})}var ri=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],ii=`decoder-nodeav`,ai=`ntab`,oi={decoder:`engine`},si={engine:`Engine & decoder`},ci=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function li({nodeId:e,refreshToken:t}){let[n,r]=sn(),{nodes:a}=G(),o=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??ii,s=[...ri,o],c=n.get(ai),l={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:d(br,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:d(ni,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:d(Sr,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:d(Tr,{nodeId:e})}},u=Un.map(e=>l[e]);return i(`div`,{className:`flex flex-col h-full`,children:[d(Hn,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:d(fn,{nodeId:e,addonIds:s,level:`global`,fieldScope:`perNode`,emptyMessage:ci,tabAliases:oi,tabLabelOverrides:si,extraTabs:u,activeTab:c===null?null:oi[c]??c,onActiveTabChange:e=>r(t=>{let n=new URLSearchParams(t);n.set(ai,e);for(let e of Mn)n.delete(e);return n},{replace:!0})})})]})}function ui(){return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Camera placement`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pin a camera to a node, or to one accelerator of its node; Auto lets each session pick. Decode always runs with detection. Load, shares and caps are on Load balancing.`})]}),d(vr,{})]})}function di(e){return`${Math.round(e*100)}%`}function fi(e){return`${e} session${e===1?``:`s`}`}var pi={"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`},mi={"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 hi(e){return e===null?`—`:pi[e]??e}function gi(e){return e===null?`—`:mi[e]??e}function _i(e){switch(e.kind){case`capacity`:return`Capacity ${fi(e.sessions)} ≥ min ${e.minSessions}.`;case`tie-faster`:return`As accurate as ${e.over} (within ${di(e.recallDelta)} recall) and faster.`;case`stepped-down`:return`${e.from} would not fit the load on ${e.limitedBy}; ${e.to} is the most accurate that does.`;case`no-fit-lightest`:return`No model reaches ${fi(e.minSessions)} per device; the one with the most capacity (${fi(e.sessions)}) is used.`;case`derived-latency`:return`${e.modelId}: latency estimated from a similar chip, not measured on this one.`;case`cpu-device`:return`CPU fallback device: picked on its own.`;case`coral-untouched`:return`Coral: left as is (no YOLOv9 build exists for it).`;case`device-disabled`:return`Disabled: not changed.`;case`device-unavailable`:return`Not available on the node right now: not changed.`;case`node-offline`:return`Node offline: nothing on it will change.`;case`no-hardware-facts`:return`Hardware could not be read: nothing on this node will change.`;case`no-measured-data`:return`This hardware has no measured data: nothing on this node will change.`;case`no-family-build`:return`No YOLOv9 build for the ${e.format} format: not changed.`;case`kept-custom-pin`:return`Custom model ${e.modelId} is pinned on ${e.deviceKey}: Auto tune skips this device.`}}function vi(e,t){switch(e.kind){case`detector-store-cluster-wide`:return`Per-camera detector thresholds are not tied to a node, so they are cleared for every camera — including cameras that run on skipped nodes (${e.skippedNodes.map(t).join(`, `)}).`;case`detector-store-unreadable`:return`Per-camera detector thresholds could not be read (${e.error}); those will not be cleared.`;case`coral-enabled`:return`${t(e.nodeId)}: the Coral (${e.deviceKey}) is enabled and keeps running its SSD model, which finds far fewer people than YOLOv9. Consider disabling it.`;case`custom-pin-kept`:return e.deviceId===null?`${t(e.nodeId)}: custom model ${e.modelId} pinned on ${e.deviceKey??`—`} — Auto tune skips this node device.`:`Camera ${e.deviceId} pins custom model ${e.modelId} on ${t(e.nodeId)} — Auto tune keeps that override and its thresholds.`;case`custom-registry-unreadable`:return`The custom-model registry could not be read (${e.error}): every pin to a model outside the measured catalog is kept.`}}function yi(e){let t=e.nodeChanges.reduce((e,t)=>e+t.modelPins.length,0),n=e.nodeChanges.reduce((e,t)=>e+t.thresholds.length,0),r=new Set([...e.cameraClears.map(e=>e.deviceId),...e.detectorStoreClears.map(e=>e.deviceId)]);return{modelChanges:t,thresholdClears:n,cameraOverrideClears:e.cameraClears.length,detectorStoreClears:e.detectorStoreClears.length,camerasTouched:r.size}}function bi(e){let t=yi(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function xi(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 Si(e,t){return e?.kind===`node-benchmark`?`measured on this node, ${new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}`:`from the latency table — benchmark this node to measure it`}r();var Ci=[.3,.4,.5];function wi(e){return Ci.some(t=>t===e)}var Ti=[1,2,3,4,6,8];function Ei({plan:e,node:t,nodeName:n}){return i(`section`,{className:g,"data-testid":`auto-tune-node-${t.nodeId}`,children:[i(`header`,{className:`${T} flex flex-wrap items-center gap-2`,children:[d(V,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${v} min-w-0 flex-1`,children:n(t.nodeId)}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[gi(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?d(K,{variant:`warning`,children:`Not changed`}):t.acceleratorModelId!==null&&d(K,{variant:`info`,children:t.acceleratorModelId})]}),t.reasons.length>0&&d(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:t.reasons.map((e,t)=>d(`li`,{children:_i(e)},t))}),d(`div`,{className:`overflow-x-auto`,children:i(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:i(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Device`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Capacity`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Detector`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Why`})]})}),d(`tbody`,{children:t.devices.map(n=>{let r=xi(e,t.nodeId,n.deviceKey);return i(`tr`,{className:`border-t border-border align-top`,children:[i(`td`,{className:`px-3 py-1.5`,children:[d(`div`,{className:`font-mono text-foreground`,children:n.deviceKey}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:hi(n.accelerator)})]}),i(`td`,{className:`px-3 py-1.5 text-foreground-muted`,children:[n.chosen===null?`—`:`${n.chosen.capacitySessions} session${n.chosen.capacitySessions===1?``:`s`} at ${e.cameraFps} fps`,n.chosen!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n.chosen.fps,` fps, `,Math.round(e.headroom*100),`% kept free`,d(`div`,{children:Si(n.chosen.source)})]})]}),d(`td`,{className:`px-3 py-1.5`,children:n.chosen===null?d(`span`,{className:`text-foreground-subtle`,children:`unchanged`}):r!==null&&r.before!==r.after?i(`span`,{children:[d(`span`,{className:`text-foreground-subtle`,children:r.before??`default`}),` → `,d(`span`,{className:`font-medium text-foreground`,children:r.after})]}):d(`span`,{className:`text-foreground`,children:n.chosen.modelId})}),d(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>d(`div`,{children:_i(e)},t))})]},n.deviceKey)})})]})})]})}function Di({plan:e,nameOf:t,nodeName:n}){return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[i(`div`,{children:[d(`div`,{className:v,children:`Node settings`}),e.nodeChanges.length===0?d(`div`,{className:`text-foreground-subtle`,children:`No change.`}):d(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.nodeChanges.flatMap(e=>[...e.modelPins.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: `,t.before??`default`,` → `,t.after??`step default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/pin`)),...e.thresholds.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: reset `,t.keys.join(`, `),` to the model default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),i(`div`,{children:[d(`div`,{className:v,children:`Camera overrides cleared`}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?d(`div`,{className:`text-foreground-subtle`,children:`None.`}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,r)=>i(`li`,{children:[t(e.deviceId),` — `,n(e.nodeId),e.deviceKey===null?` (whole pipeline)`:` · ${e.deviceKey}`,` — `,e.stepId,e.modelIdBefore===null?``:`: model ${e.modelIdBefore} removed`,e.keys.length>0?`; ${e.keys.join(`, `)} reset`:``]},`c${r}`)),e.detectorStoreClears.map(e=>i(`li`,{children:[t(e.deviceId),` — detector thresholds: `,e.keys.join(`, `),` reset`]},`d${e.deviceId}`))]})]})]})}function Oi({result:e}){return e.kind===`refused`?d(`div`,{className:`text-xs text-warning`,children:`Another apply is already running.`}):e.kind===`stale`?d(`div`,{className:`text-xs text-warning`,children:`The configuration changed since the plan was shown. Review the updated plan below and apply again.`}):i(`ul`,{className:`text-xs`,"data-testid":`auto-tune-result`,children:[e.kind===`aborted`&&d(`li`,{className:`text-danger`,children:`A model could not be downloaded: nothing was changed.`}),e.phases.map(e=>i(`li`,{className:e.ok?`text-foreground-muted`:`text-danger`,children:[e.ok?`✓`:`✗`,` `,e.phase,`: `,e.detail]},e.phase))]})}function ki(){let e=c(),[t,n]=u(.4),[r,o]=u(2),[s,l]=u(!1),[f,p]=u(!1),[m,h]=u(null),{data:_}=cn(),y=a(()=>new Map((_??[]).map(e=>[e.id,e.name])),[_]),b=e=>y.get(e)??`Camera ${e}`,{nodes:x}=G(),S=a(()=>Zn(x),[x]),C=oe({headroom:t,minSessionsPerDevice:r},{enabled:s,refetchOnWindowFocus:!1}),w=Fe({onSuccess:t=>{h(t),p(!1),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.kind===`applied`&&C.refetch()}}),E=m?.kind===`stale`?m.plan:C.data,D=E===void 0?null:yi(E);return i(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[i(`section`,{className:g,children:[i(`header`,{className:`${T} flex flex-wrap items-center gap-2`,children:[d(Oe,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${v} min-w-0 flex-1`,children:`Auto tune`})]}),i(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[d(`p`,{children:`Picks, for every accelerator, the most accurate YOLOv9 detector that still carries at least the chosen number of cameras at once, from the node's hardware and measured speeds. Nothing is measured or estimated about your cameras' activity. Applying it sets those models and clears every model and threshold override — node level and per camera — so each model runs its own default thresholds. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`Keep free`}),d(W,{"aria-label":`Share of each accelerator kept free`,value:String(t),options:Ci.map(e=>({value:String(e),label:`${Math.round(e*100)}% of each accelerator`})),onChange:e=>{let t=Number(e.target.value);wi(t)&&n(t)}})]}),i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`At least`}),d(W,{"aria-label":`Minimum parallel sessions per device`,value:String(r),options:Ti.map(e=>({value:String(e),label:`${e} camera${e===1?``:`s`} at once per accelerator`})),onChange:e=>{let t=Number(e.target.value);Ti.some(e=>e===t)&&o(t)}})]}),d(z,{size:`sm`,variant:`secondary`,onClick:()=>{h(null),l(!0),s&&C.refetch()},children:C.isFetching?`Computing…`:E===void 0?`Compute plan`:`Recompute`}),E!==void 0&&d(z,{size:`sm`,disabled:bi(E),onClick:()=>p(!0),children:`Apply…`})]}),C.error!==null&&d(`div`,{className:`text-danger`,children:C.error.message}),m!==null&&d(Oi,{result:m}),D!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[D.modelChanges,` model change(s), `,D.thresholdClears,` node threshold reset(s), `,D.cameraOverrideClears+D.detectorStoreClears,` camera override(s) on `,D.camerasTouched,` camera(s).`]})]})]}),E?.warnings.map((e,t)=>d(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:vi(e,S)},t)),E?.nodes.map(e=>d(Ei,{plan:E,node:e,nodeName:S},e.nodeId)),E!==void 0&&d(M,{open:f,onOpenChange:p,children:i(ve,{width:`lg`,scroll:`body`,children:[i(R,{children:[d(de,{children:`Apply auto tune?`}),d(be,{children:`These are all the changes. Every override listed is removed and cannot be restored.`})]}),d(st,{children:d(Di,{plan:E,nameOf:b,nodeName:S})}),i(we,{children:[d(z,{variant:`ghost`,onClick:()=>p(!1),children:`Cancel`}),d(z,{variant:`danger`,disabled:w.isPending,onClick:()=>w.mutate({planHash:E.planHash,headroom:t,minSessionsPerDevice:r}),children:w.isPending?`Applying…`:`Apply`})]})]})})]})}var Ai={disabled:`switched off — not a dispatch target`,unavailable:`the node probe does not see it (unplugged or still provisioning)`,"cannot-host-camera-root":`its engine format has no object-detection root model`,"accelerator-preferred":`CPU fallback — it never competes while an accelerator is serving`};function ji(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function Mi(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function Ni(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:H(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?ji(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 Pi(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=Ni(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),Mi(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?ji(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?ji(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}r();var Fi=2e4,Ii=3e5;function Li({stats:e,targetWeights:t}){let{nodes:n}=G(),r=E().trpcClient,o=Ce(void 0,{placeholderData:l,staleTime:Fi,refetchInterval:Fi,refetchOnWindowFocus:!0}),c=Ve(void 0,{staleTime:Ii}),u=a(()=>n.map(e=>e.id),[n]),f=s({queries:u.map(e=>({queryKey:on(it.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Ii,refetchOnWindowFocus:!1,placeholderData:l}))}),p=a(()=>{let e={};return u.forEach((t,n)=>{let r=f[n]?.data;r&&(e[t]=r.devices)}),e},[u,f.map(e=>e.dataUpdatedAt).join(`|`)]),h=a(()=>{let e=new Map;for(let t of c.data??[])e.set(t.nodeId,t.settings);return e},[c.data]),g=a(()=>n.map(e=>{let n=h.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:zn(n,e.isHub).pipeline,weight:t?.[e.id]??hn(n,`detectWeight`)??1,maxCameras:hn(n,`maxCameras`)}}),[n,h,t]),_=o.data??[],v=a(()=>Pi({nodes:g,loads:_,devicesByNode:p}),[g,_,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),x=o.dataUpdatedAt>0?Date.now()-o.dataUpdatedAt:null,S=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return d(U,{headingId:`load-balancing-node-load`,title:`Node load`,icon:ae,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[b,` running · `,y,` attached ·`,` `,o.data===void 0?`reading…`:`${x===null?`—`:`${Math.round(x/1e3)}s`} old`]}),children:d(`div`,{className:m,children:v.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>d(Ri,{row:e,placed:S.get(e.nodeId)},e.nodeId))})})})}function Ri({row:e,placed:t}){let n=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[d(dt,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(Pt,{className:`h-2.5 w-2.5`}),` offline`]})]}),i(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:n,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share (1 h)`,value:t?.observedShare===null||t===void 0?`—`:`${Math.round(t.observedShare*100)}%`,title:`Time-weighted share of the cluster's PARALLEL detection sessions this node carried over the last hour — the quantity a share holds. '—' = no session ran here in the window.`}),d(J,{label:`Peak · yields`,value:t===void 0?`—`:`${t.peakSessions} · ${t.yieldsAway}`,title:`Most sessions this node ran at once in the last hour, and how many share turns it handed to another node because it was full or drowning.`}),d(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(zi,{row:e})]})}function zi({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):i(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[i(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(Bt,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(Bi,{device:e},e.key))})]})}function Bi({device:e}){let t=e.exclusion;return i(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(V,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?i(o,{children:[i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,title:e.sessions===null?`Not known: the node did not report, or runs a session no device accounts for.`:void 0,children:[`· `,e.sessions??`—`,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):i(`span`,{className:`truncate text-foreground-subtle/80`,title:Ai[t],children:[`excluded — `,Ai[t]]})]})}function J({label:e,value:t,title:n}){return i(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Vi(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Hi(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 Ui(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Wi(e){return e.reason===`disabled`?`${e.deviceKey} is not enabled on any node — sessions ignore this pin`:`no node offers ${e.deviceKey} — sessions ignore this pin`}function Gi(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 Ki(e,t){let n=e.nodes.filter(e=>!e.eligible);if(n.length===0)return null;let r=e.nodes.filter(e=>e.eligible).map(e=>`${t(e.nodeId)} ${Math.round(e.effectivePct)}%`).join(`, `);return`${n.map(e=>t(e.nodeId)).join(`, `)} cannot take sessions — ${n.length===1?`its share goes`:`their shares go`} to the others: ${r}`}var qi=[{value:`hardware`,label:`Hardware`,hint:`Each node’s share follows what its accelerators can carry at their Auto tune models, from the measured speed of its hardware. No load is measured or estimated.`},{value:`benchmark`,label:`Benchmark`,hint:`Each node’s share follows its own node-benchmark results. A node without results uses its hardware capacity instead, and says so.`},{value:`manual`,label:`Manual`,hint:`The sliders below, as you set them.`}];function Ji(e){return e===`no-benchmark-results`?`no benchmark results yet — sized from hardware`:e===`partial-benchmark-results`?`benchmark results miss some of its accelerators — sized from hardware`:null}function Yi(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)}: ${Ji(e.capacityFallback)??``}`).join(` · `)}r();function Xi(e,t,n){return Math.min(Math.max(e,t),n)}function Zi(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 Qi(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:Xi(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 $i(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 ea({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:a,footnote:s,readOnly:c=!1}){let[l,p]=u(()=>Zi(e)),[m,h]=u(new Set);f(()=>{p(Zi(e)),h(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let g=e.map(e=>e.id),_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=(e,t)=>{p(n=>Qi(n,e,t,m,g))},y=()=>{let t=$i(l,g,m),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...m]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:a??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let b=e.length===1;return i(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=l[e.id]??0,a=m.has(e.id);return i(`div`,{className:`flex items-center gap-3`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),d(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:c||t||a||b,onChange:t=>v(e.id,Number(t.target.value)),onPointerUp:()=>y(),onKeyUp:()=>y(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),i(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),!c&&d(`button`,{type:`button`,onClick:()=>_(e.id),disabled:t||b,"aria-pressed":a,title:a?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${a?`text-amber-400`:`text-foreground-subtle`}`,children:d(a?It:Pe,{className:`h-3.5 w-3.5`})})]},e.id)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:s??d(o,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}function ta(e){let t=e.steps?.[`object-detection`]?.modelId;return typeof t==`string`&&t.length>0?t:typeof e.defaultModelId==`string`&&e.defaultModelId.length>0?e.defaultModelId:null}r();function na(e){let t=H(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:V,hue:`slate`}:r===`npu`?{label:t,Icon:Ct,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:En,hue:`violet`}:n===`edgetpu`?{label:t,Icon:An,hue:`emerald`}:{label:t,Icon:V,hue:`slate`}}var ra={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function ia({nodeId:e,nodeName:t,isOnline:n,suggestedMaxSessions:r,autoDeviceShares:s}){let l=c(),{data:p,isLoading:m}=De({nodeId:e},{refetchInterval:15e3}),h=Ke({onSettled:()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),g=p?.devices??[],_=p?.reachable??n,[v,y]=u({});f(()=>{y(Object.fromEntries(g.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[g.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let b=a(()=>g.filter(e=>v[e.key]?.enabled??e.enabled).length,[g,v]),[x,S]=u(null),w=x??b>0,T=t=>{let n=g.map(e=>{let n=t[e.key]??E(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});h.mutate({agentNodeId:e,inferenceDevices:kr(n)})},E=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),D=e=>{if(!e.available)return;let t=v[e.key]??E(e),n={...v,[e.key]:{...t,enabled:!t.enabled}};y(n),T(n)},O=(e,t)=>{let n=v[e.key]??E(e),r={...v,[e.key]:{...n,maxSessions:t}};y(r),T(r)},k=a(()=>g.filter(e=>(v[e.key]?.enabled??e.enabled)&&e.available),[g,v]),A=a(()=>k.map(e=>({id:e.key,name:na(e).label,weight:s===void 0?v[e.key]?.weight??e.weight:Math.round(s[e.key]??0)})),[k,v,s]);return i(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[i(`button`,{type:`button`,onClick:()=>S(!w),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":w,children:[d(C,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${w?`rotate-90`:``}`}),d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),d(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:_?b>=2?i(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[d(Ht,{className:`h-3.5 w-3.5`}),b,` accelerators`]}):b===1?d(`span`,{className:`text-foreground-subtle`,children:`single default`}):d(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):i(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[d(Pt,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),w&&i(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[_?m&&g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):d(`ul`,{className:`space-y-2`,children:g.map(e=>{let t=na(e),n=v[e.key]??E(e),a=n.enabled&&e.available,s=ta({defaultModelId:e.defaultModelId,steps:n.steps});return i(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[d(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${ra[t.hue]}`,children:d(t.Icon,{className:`h-4.5 w-4.5`})}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),d(K,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&d(K,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`font-mono`,children:e.key}),s!==null&&i(o,{children:[d(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:[`root model`,` `,d(`span`,{className:`font-mono text-foreground/80`,children:s})]})]})]})]}),a&&i(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),d(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);O(e,r!=null&&r>0?r:null)},disabled:h.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),a&&d(aa,{suggested:r?.[e.key]??null,current:n.maxSessions,pending:h.isPending,onApply:t=>O(e,t)}),d(pt,{checked:a,onCheckedChange:()=>D(e),disabled:!e.available||h.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):d(oa,{}),_&&k.length>=2&&i(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[i(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[d(kn,{className:`h-3.5 w-3.5`}),`Accelerator share`]}),d(ea,{nodes:A,pending:h.isPending,onCommitWeights:e=>{let t={...v};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}y(t),T(t)},weightLabel:`Accelerator share`,readOnly:s!==void 0,footnote:s===void 0?d(o,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`}):d(o,{children:`Automatic: each accelerator's share follows its measured throughput at its model. Switch the node shares to manual to set them yourself.`})})]}),h.isError&&i(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,h.error instanceof Error?h.error.message:`unknown error`]})]})]})}function aa({suggested:e,current:t,pending:n,onApply:r}){return e===null||e<1||e===t?null:i(z,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`,children:[`use `,e]})}function oa(){return i(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[d(Pt,{className:`h-6 w-6 text-foreground-subtle/60`}),d(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),d(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}r();var sa=3600*1e3,ca=2e4,la=.4;function ua({refreshToken:e,onOpenAutoTune:t}){let n=c(),{nodes:r}=G(),s=Ve(void 0),f=At({isCamera:!0,projection:`slim`}),p=le({windowMs:sa},{refetchInterval:ca,placeholderData:l}).data,h=_e(void 0,{refetchInterval:ca,placeholderData:l}).data,g=()=>{yn(n),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},v=vt({onSuccess:g}),y=Xe({onSuccess:()=>{g(),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),b=Ee({onSuccess:g}),x=ge(),[S,C]=u(!1),w=h?.source,T=w===`benchmark`?`benchmark`:`hardware`,E=ft({headroom:la,source:T},{enabled:S,staleTime:1/0}),D=E.data,O=a(()=>{let e=new Map((s.data??[]).map(e=>[e.nodeId,e.settings]));return r.filter(t=>zn(e.get(t.id),t.isHub).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:hn(n,`detectWeight`)??1,maxCameras:hn(n,`maxCameras`)}})},[r,s.data]),k=e=>r.find(t=>t.id===e)?.name??e,j=Qn((f.data??[]).map(e=>({id:e.id,name:e.name}))),M=D?Ui(D):void 0,N=Gi(O,h),P=w!==`manual`,ee=e=>{if(h===void 0||h.source===`manual`||h.autoPending)return;let t=h.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},F=h?Ki(h,k):null,I=h?Yi(h,k):null,L=qi.find(e=>e.value===w)?.hint;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(fn,{nodeId:`hub`,addonIds:[Cn],level:`global`,sectionIds:[`load`],title:`Placement policy`,description:`How a new detection session picks its node and device, and what happens when a node falls behind. 'Honour shares' (default) holds the shares below for PARALLEL sessions.`}),d(Wn,{refreshToken:e}),d(Li,{stats:p,...h!==void 0&&h.source!==`manual`&&!h.autoPending?{targetWeights:Object.fromEntries(h.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),d(U,{headingId:`load-balancing-node-shares`,title:`Node shares`,icon:kn,actions:i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{role:`radiogroup`,"aria-label":`Share source`,className:`flex items-center gap-1`,children:qi.map(e=>d(z,{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))}),i(z,{variant:`outline`,size:`sm`,onClick:()=>{C(!0),S&&E.refetch()},disabled:E.isFetching,children:[d(ct,{className:`h-3.5 w-3.5`}),E.isFetching?`Suggesting…`:T===`benchmark`?`Suggest from benchmark`:`Suggest from hardware`]}),i(z,{variant:`ghost`,size:`sm`,onClick:t,children:[d(Oe,{className:`h-3.5 w-3.5`}),`Auto tune`]}),i(z,{variant:`outline`,size:`sm`,onClick:()=>x.mutate(void 0),disabled:x.isPending,title:`Move standing (always-on) cameras that are no longer on their best node. Pinned cameras never move; on-motion sessions are placed per session anyway.`,children:[d(Ct,{className:`h-3.5 w-3.5`}),x.isPending?`Rebalancing…`:`Rebalance`]})]}),children:i(`div`,{className:`${m} space-y-3`,children:[L!==void 0&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:L}),p&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Policy:`,` `,d(K,{variant:p.policy===`share`?`info`:`default`,children:p.policy===`share`?`honour shares`:`least-loaded`}),` `,`· cluster peak `,p.clusterPeakSessions,` parallel sessions in the last hour`,p.policy===`least-loaded`&&` · under least-loaded an idle node always wins, so shares only bite once nodes are busy`]}),d(ea,{nodes:N.nodes,pending:v.isPending,readOnly:N.readOnly,onCommitWeights:e=>v.mutate(Vi(e)),weightLabel:`Node share`,...N.readOnly?{footnote:h?.autoPending?d(o,{children:`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`}):i(o,{children:[w===`benchmark`?`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`:`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`,h?.computedAt==null?``:` — last at ${new Date(h.computedAt).toLocaleTimeString()}${h.trigger===null?``:` (${h.trigger})`}`,`.`]})}:{}}),F!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:F}),I!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:I}),y.isError&&d(B,{message:`Failed to switch shares: ${y.error instanceof Error?y.error.message:`unknown error`}`}),v.isError&&d(B,{message:`Failed to save shares: ${v.error instanceof Error?v.error.message:`unknown error`}`}),i(`details`,{className:`rounded-md border border-border`,children:[d(`summary`,{className:`${_} cursor-pointer text-xs text-foreground`,children:`Max concurrent sessions (advanced)`}),d(`ul`,{className:`divide-y divide-border border-t border-border`,children:O.map(e=>i(`li`,{className:`${_} flex items-center gap-2`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),d(Te,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":`Max concurrent sessions for ${e.name}`,className:`w-20 text-right`,disabled:b.isPending,onBlur:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==e.maxCameras&&b.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),d(`p`,{className:`${_} ${A} border-t border-border`,children:`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`})]})]})}),E.isError&&d(B,{message:`Suggestion failed: ${E.error instanceof Error?E.error.message:`unknown error`}`}),D&&d(da,{suggestion:D,nameOf:k,pending:v.isPending,...P?{}:{onApply:()=>v.mutate(Hi(D))}}),d(U,{headingId:`load-balancing-accelerators`,title:`Accelerators`,icon:V,children:d(`div`,{className:`${m} space-y-2`,children:O.length===0?d(Le,{title:`No detect-capable nodes`,description:`Enable detection on a node in Roles & nodes to configure its accelerators.`}):O.map(e=>d(ia,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...M?.[e.id]===void 0?{}:{suggestedMaxSessions:M[e.id]},...ee(e.id)===void 0?{}:{autoDeviceShares:ee(e.id)}},e.id))})}),p!==void 0&&p.stalePins.length>0&&d(fa,{stats:p,cameraName:j})]})}function da({suggestion:e,nameOf:t,pending:n,onApply:r}){return i(U,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?`Suggested from benchmark`:`Suggested from hardware`,icon:ct,...r===void 0?{}:{actions:d(z,{size:`sm`,onClick:r,disabled:n,children:`Apply suggested shares`})},children:[d(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>i(`li`,{className:`${_} space-y-0.5`,children:[i(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),d(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?`skipped`:`${e.share}%`})]}),i(`p`,{className:A,children:[Ji(e.capacityFallback)===null?``:`${Ji(e.capacityFallback)} · `,e.skippedReason===null?`≈ ${e.capacitySessions} parallel sessions · ${e.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}`:`not part of the suggestion — ${e.skippedReason}`]})]},e.nodeId))}),i(`p`,{className:`${_} ${A} border-t border-border`,children:[`Shares in proportion to each node's capacity in parallel sessions —`,` `,e.source===`benchmark`?`measured by node benchmarks, or from the hardware table where a node has no results`:`at the models Auto tune picks (at least ${e.minSessionsPerDevice} per accelerator), from the measured speed of each node's hardware`,`, counted in `,e.cameraFps,` fps sessions with`,` `,Math.round(e.headroom*100),`% kept free. No load is measured or estimated.`,r===void 0?`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`:`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`]})]})}function fa({stats:e,cameraName:t}){let n=c(),r=Et({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return d(U,{headingId:`load-balancing-stale-pins`,title:`Stale device pins`,icon:On,children:d(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>i(`li`,{className:`${_} flex items-center gap-2`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[d(`p`,{className:`truncate text-xs text-foreground`,title:t(e.deviceId),children:t(e.deviceId)}),d(`p`,{className:A,children:Wi(e)})]}),d(z,{variant:`outline`,size:`sm`,disabled:r.isPending,onClick:()=>r.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:`Clear pin`})]},e.deviceId))})})}function pa({node:e,emphasis:t=!1}){let n=e.isHub?qe:V;return i(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),i(`div`,{className:`min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(K,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(K,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}function ma({nodes:e,actions:t}){return d(ue,{columns:[{key:`node`,header:`Node`,sortValue:e=>e.name,render:e=>d(pa,{node:e})},...bn.map(e=>({key:e.key,header:e.label,align:`center`,notSortableReason:`A switch — sorting would move the row while it is being changed.`,render:n=>d(pt,{"aria-label":`${e.label} on ${n.name}`,title:e.hint,checked:mn(n.effective,e.key),disabled:t.capabilityPending,onCheckedChange:r=>t.onToggleCapability(n.id,e.key,r)})}))],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,mobileMode:`scroll`,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:`No cluster nodes reporting yet.`})}function ha({roleValues:e,options:t,pending:n,onRoleChange:r}){let a=t.map(e=>({value:e.id,label:e.id===`hub`?`${e.name} (default)`:e.name}));return d(`ul`,{className:`divide-y divide-border`,children:wn.map(t=>i(`li`,{className:`${_} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[i(`div`,{className:`min-w-0 flex-1 basis-56`,children:[d(`div`,{className:`text-xs font-medium text-foreground`,children:gn(t)}),d(`p`,{className:A,children:_n(t)})]}),d(`div`,{className:`w-full sm:w-48`,children:d(W,{"aria-label":`${gn(t)} node`,value:e[t],disabled:n,options:a,onChange:e=>r(t,e.target.value)})})]},t))})}r();function ga(){let e=c(),{nodes:t}=G(),n=Ve(void 0),r=zt({addonId:Cn}),o=zt({addonId:pn}),s=zt({addonId:Tn}),l=()=>yn(e),u=He({onSuccess:l}),f=Ae({onSuccess:l}),p=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),m=a(()=>t.map(e=>{let t=p.get(e.id),n=zn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[t,p]),h={ingestNode:Sn(r.data,`ingestNode`,`hub`),recordingNode:Sn(o.data,xn,`hub`),audioNode:Sn(r.data,`audioNode`,`hub`),motionNode:Sn(r.data,`motionNode`,`hub`),postProcessingNode:Sn(s.data,vn,`hub`)},g=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id),n=e=>t.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,...wn.map(e=>h[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:n(e)}))},[t,h]),_=n.isLoading||r.isLoading||o.isLoading||s.isLoading,v=(e,t,n)=>{u.mutate({agentNodeId:e,[t]:n})},y=(e,t)=>{if(e===`recordingNode`){f.mutate({addonId:pn,patch:{[xn]:t}});return}if(e===`postProcessingNode`){f.mutate({addonId:Tn,patch:{[vn]:t}});return}f.mutate({addonId:Cn,patch:{[e]:t}})},b={capabilityPending:u.isPending,onToggleCapability:v};return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(U,{headingId:`roles-nodes-cluster-roles`,title:`Cluster roles`,icon:Dn,actions:_?d(ne,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":`Loading`}):null,children:[d(`p`,{className:`${A} border-b border-border px-3 py-1.5 sm:px-4`,children:`One node holds each role for every camera. Detection shares and caps are on Load balancing.`}),d(ha,{roleValues:h,options:g,pending:f.isPending,onRoleChange:y})]}),d(U,{headingId:`roles-nodes-node-capabilities`,title:`Node capabilities`,icon:qe,children:d(ma,{nodes:m,actions:b})})]})}var _a=`pipeline-analytics`,va=`face-gallery`,ya=`pipeline-orchestrator`,ba=`pipeline-runner`,xa=`audio-analyzer`;function Sa(e){return[...Yt.filter(t=>t.stepId===e).map(e=>Gt(e.stepId)),...Kt.filter(t=>t.stepId===e).map(e=>$t(e.stepId,e.key))]}var Ca=`faces`,wa=`semantic-search`,Ta=[{id:Ca,title:`Faces & recognition`,hint:`The face encoder for every node, the smallest faces worth embedding, keeping and auto-assigning, and how a face is matched to a person.`,panels:[{addonId:ya,fieldKeys:Sa(`face-embedding`)},{addonId:_a,capability:va}]},{id:wa,title:`Semantic search`,hint:`The image encoder behind "search by description". One for the whole cluster: changing it hides existing results until the index is rebuilt.`,panels:[{addonId:ya,fieldKeys:Sa(`clip-embedding`)}]},{id:en,title:`Enrichment crop`,hint:`How the crop handed to face, plate and search models is cut from the frame.`,panels:[{addonId:ya,sectionIds:[en]}]},{id:Xt,title:`Full-resolution crops`,hint:`How long each camera keeps full-resolution pixels so a late crop (snapshot, face, plate) is sharp instead of cut from the small detection frame.`,panels:[{addonId:ya,sectionIds:[Xt]}]},{id:`runner-defaults`,title:`Runner defaults`,hint:`Values every node's detection runner and audio analyzer use. A node's own decode limits (Engine & decoder) take precedence.`,panels:[{addonId:ba,fieldScope:`cluster`},{addonId:xa,fieldScope:`cluster`}]},{id:`failover`,title:`Failover`,hint:`What happens to cameras when a node disconnects and comes back.`,panels:[{addonId:ya,sectionIds:[`failover`]}]}],Ea={"cluster-step-models":Ca};function Da(e){return e===`clip-embedding`?wa:Ca}r();var Oa=2500,ka={faces:tt,"semantic-search":Oe,"detail-crop":Vt,"native-lease":Ht,"runner-defaults":V,failover:he};function Aa(e){f(()=>{if(e===null)return;let t=Ea[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`),Oa),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function ja({section:e}){return d(`div`,{"data-cluster-settings-card":e.id,className:`rounded-lg`,children:d(U,{headingId:`cluster-settings-${e.id}`,title:e.title,...ka[e.id]===void 0?{}:{icon:ka[e.id]},children:i(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:A,children:e.hint}),e.panels.map(e=>d(fn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:[`cluster`,`load`],emptyMessage:`Not available — the addon that owns these settings did not answer.`,...e.capability===void 0?{}:{capability:e.capability},...e.sectionIds===void 0?{}:{sectionIds:e.sectionIds},...e.fieldKeys===void 0?{}:{fieldKeys:e.fieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function Ma({refreshToken:e}){let[t]=sn();return Aa(t.get(Po)),d(`div`,{className:`space-y-3 sm:space-y-4`,children:Ta.map(e=>d(ja,{section:e},e.id))})}var Na=`pipeline-orchestrator`,Pa=200;function Fa(){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(Ie,{addonId:Na,limit:Pa,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}var Ia=[{id:`assignments`,label:`Assignments`},{id:`load-balancing`,label:`Load balancing`},{id:`auto-tune`,label:`Auto tune`},{id:`roles-nodes`,label:`Roles`},{id:`settings`,label:`Settings`},{id:`logs`,label:`Logs`}];function La(e){return Ia.some(t=>t.id===e)}function Ra({refreshToken:e}){let[t,n]=sn(),r=t.get(No),a=La(r)?r:`assignments`,o=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(No,e),n.delete(Po),n},{replace:!0})};return i(`div`,{className:`flex flex-col h-full`,children:[i(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Ia.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[a===`assignments`&&d(ui,{}),a===`load-balancing`&&d(ua,{refreshToken:e,onOpenAutoTune:()=>o(`auto-tune`)}),a===`auto-tune`&&d(ki,{}),a===`roles-nodes`&&d(ga,{}),a===`settings`&&d(Ma,{refreshToken:e}),a===`logs`&&d(Fa,{})]})]})}var za=`armed:`;function Ba(e){return e.assignment.reasons.detection?.startsWith(za)===!0}function Va(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Ba(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Ha(e){let t=[],n=[],{assignment:r,detection:i,broker:a}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),r.detectionNodeId===null&&i===null&&!Ba(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let o=e.degraded??[];if(o.length>0){let e=[...new Set(o.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}n.push(...Ga(e.cameraSensors));for(let e of a?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Ua(e){return e.state===`unreadable`&&qt.state===`unreadable`&&e.reason===qt.reason}function Wa(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is missing`};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) is ${e.reason}`};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) cannot drive motion: ${e.reason}`};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is unreadable: ${e.reason}`}}}function Ga(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return Ua(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:`Camera sensors unreadable: ${e.reason}`}];let t=e.sensors.flatMap(e=>{let t=Wa(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[Ka(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:`Confirm / Replace cannot suppress this camera's own motion until its provider is updated`},...n]}function Ka(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?`Camera sensors are attached but never fire: add "Camera sensors" (onboard) to this camera's motion sources`:`Camera sensors are attached but never fire: this camera has no active detection`}}function qa(e){return e===void 0?`status unavailable from this node`:e.state===`not-configured`?`none attached`:e.state===`unreadable`?`unknown — ${e.reason}`:e.sensors.map(Ya).join(`, `)}function Ja(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function Ya(e){return`${Xa(e)}${Ja(e)}`}function Xa(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return`${e.name} (#${e.deviceId}) — unsupported`;case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function Za(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Qa(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function $a(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function eo(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var to={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function no(e){if(!Za(e)||!Array.isArray(e.sections))return to;let t=Zt(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)eo(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Qa(n(`detectionFps`)),motionSources:$a(n(`motionSources`)),motionFps:Qa(n(`motionFps`)),motionCooldownMs:Qa(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function ro(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...ro(r.children,t+1));return n}function X({title:e,children:t}){return i(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return i(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(io,{})]})}function io(){return d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var ao={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return d(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${ao[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function oo({icon:e,label:t,nodeId:n,pinned:r,reason:a,overridden:s}){return i(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):i(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?i(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(xt,{className:`h-2.5 w-2.5`}),` manual`]}):i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function so({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return i(X,{title:`Where it runs`,children:[d(oo,{icon:V,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(oo,{icon:ce,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(oo,{icon:S,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(oo,{icon:yt,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:i(`select`,{value:o,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>i(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function co(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function lo(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function uo(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function fo({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:a,cameraSensors:s}){let c=lo(t,n.detectionStreamProfile),l=lo(t,n.motionStreamProfile),u=n.motionSources.includes(`analyzer`);return i(X,{title:`Streams & motion`,children:[i(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:uo(n.detectionFps)}),i(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map(nn).join(` + `):`none`,r===!1&&` · inactive`]}),d(Z,{label:`Camera sensors`,children:qa(s)}),u&&i(o,{children:[i(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),i(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[uo(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>i(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,co(e)]},e.camStreamId))})]})}function po({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return i(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:i(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&i(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:i(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var mo={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function ho({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return i(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:r,children:n??`—`}),d($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=ye(a),f=a===`active`&&o===0;return i(X,{title:`Detection runtime`,children:[i(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[i(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(ie,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:r,children:n??`—`}),i(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),i(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&i(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&i(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),i(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),i(Z,{label:`Provisioning`,children:[d(Q,{tone:mo[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&i(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function go({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):i(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return i(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),i(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),i(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps===null?`—`:e.inFps.toFixed(0),`fps`]}),i(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),i(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[i(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),i(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function _o({decoder:e}){return e===null?d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})}):d(X,{title:`Decoder`,children:d(Z,{label:`Node`,children:e.nodeId})})}r();var vo=`pipeline-orchestrator`,yo={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},bo={healthy:`Healthy`,idle:`Idle`,error:`Error`};function xo({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>i(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[d(dt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function So({deviceId:e,name:t,online:n,status:r,live:o,onlineNodes:s}){let l=c(),{data:u}=Mt({addonId:vo,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=We({deviceId:e},{staleTime:3e4}),p=a(()=>no(u),[u]),m=a(()=>f===void 0?void 0:ro(f.steps),[f]),h=a(()=>r===void 0?[]:Ha(r),[r]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=L({onSuccess:g}),v=$e({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=r===void 0?`idle`:Va(r),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return i(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[i(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:yo[b]}`,title:x?`Error`:bo[b],"aria-label":x?`Error`:bo[b],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),i(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),r?.recording!=null&&(r.recording.active?i(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&i(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),h.length>0&&d(xo,{problems:h}),r===void 0?d(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):i(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(so,{assignment:r.assignment,settings:p,onlineNodes:s,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),d(ho,{detection:r.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(po,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:r.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(fo,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:p,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null,cameraSensors:r.cameraSensors}),d(go,{broker:r.broker}),d(_o,{decoder:r.decoder})]})]})}r();var Co=5e3,wo=1e4,To=5e3;function Eo(e){let t=c(),{data:n,isLoading:r}=cn(),{data:i,isLoading:o}=xe({},{refetchInterval:Co}),{nodes:s}=G();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);et(rn.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-wo,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},To);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}r();function Do({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:o}=Eo(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:Ha(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:i(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[i(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[i(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),i(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),i(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(So,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}var Oo=e({CLUSTER_NODE_ID:()=>ko,PipelinePage:()=>Mo});r();var ko=`__cluster__`;function Ao(e){return e===`cameras`?`cameras`:`nodes`}function jo({viewMode:e,onNodes:t,onCameras:n}){return i(`div`,{className:`flex items-center gap-1 rounded-lg border border-border bg-surface p-0.5`,role:`tablist`,"aria-label":`Pipeline view`,children:[d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`nodes`,onClick:t,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`cameras`,onClick:n,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]})}function Mo(){let[e,t]=sn(),n=Ao(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:ko},{replace:!0})},[n,e,t]),i(se,{icon:un,title:`Pipeline`,subtitle:`Detection placement, load and per-camera runtime across the cluster.`,actions:i(z,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s(e=>e+1),title:`Refresh`,children:[d(Je,{className:`h-3.5 w-3.5`}),`Refresh`]}),nav:d(jo,{viewMode:n,onNodes:()=>{t({view:`nodes`,node:r},{replace:!0})},onCameras:()=>{t({view:`cameras`},{replace:!0})}}),className:`flex h-full min-h-0 flex-col overflow-hidden`,children:[n===`nodes`&&i(z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>l(e=>!e),"aria-expanded":c,className:`flex w-full shrink-0 justify-between border-b border-border md:hidden`,children:[i(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(y,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden md:flex-row`,children:n===`nodes`?i(o,{children:[d(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b border-border md:border-b-0 md:border-r`,`max-h-[60vh] overflow-y-auto md:max-h-none`].join(` `),children:d(Vn,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:r===`__cluster__`?d(Ra,{refreshToken:a}):d(li,{nodeId:r,refreshToken:a})})]}):d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:d(Do,{refreshToken:a})})})]})}var No=`ctab`,Po=`section`;function Fo(e,t){let n=new URLSearchParams({view:`nodes`,node:ko,[No]:e});return t!==void 0&&n.set(Po,t),`/system/pipeline?${n.toString()}`}function Io(e){return Fo(`settings`,Da(e))}function Lo(){return Fo(`load-balancing`)}var Ro=`pipeline-orchestrator`;function zo(e){return Yt.find(t=>t.stepId===e)??null}function Bo({step:e,engineFormat:t,runnableModelIds:n}){let{data:r}=zt({addonId:Ro}),a=Ut(r??null)[e.stepId]??e.defaultModelId,o=e.options.find(e=>e.id===a)?.label??a,s=n.length>0&&!n.includes(a);return i(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:o}),d(`span`,{title:`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`}),d(ln,{to:Io(e.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Change in Cluster → Settings ›`})]}),i(`p`,{className:A,children:[`One model for every node and camera: `,e.indexName,` only matches vectors from the model that made them.`]}),s&&i(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:[`This accelerator's engine (`,t,`) ships no build of `,d(`b`,{children:a}),`. It refuses this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`.`]})]})}export{jr as _,Yr as a,Pr as c,Br as d,Hr as f,Mr as g,Vr as h,Xr as i,Kr as l,zr as m,zo as n,Rr as o,Gr as p,Oo as r,Ur as s,Bo as t,Wr as u,Or as v,Mn as y};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-Cyuzqnbw.js";import{I as t,K as n,Q as r,S as i,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{A as p,D as m,N as h,O as g,T as _,V as v,_t as y,b,ct as x,dt as S,gt as C,j as w,k as T,ot as E,v as D,y as O,yt as k,z as A}from"./player-overlays-9CMoB0XN.js";import{$l as j,An as M,As as N,Bs as P,C as ee,Cn as F,Cs as I,Ds as L,E as te,Ed as ne,Es as re,F as ie,Ff as ae,Fn as R,Gn as z,Gs as oe,H as se,Hd as ce,Hn as B,Hs as le,Ht as ue,In as de,J as fe,Js as pe,Jt as me,Ju as he,Ks as ge,Ls as _e,Mn as ve,Mt as ye,Nn as be,Ns as xe,O as Se,Os as Ce,Pn as we,Qd as V,Ql as Te,Qs as Ee,Rs as De,Ru as Oe,S as ke,Sn as H,Sr as Ae,Ss as je,Su as Me,T as Ne,Td as Pe,Ts as Fe,Tt as Ie,Un as Le,Ut as Re,Vs as ze,Vt as U,W as Be,Ws as Ve,Xs as He,Y as Ue,Ys as We,Yt as Ge,Zs as Ke,Zu as qe,ad as Je,bn as Ye,cc as Xe,cn as Ze,cu as Qe,dc as $e,du as et,ed as tt,eu as nt,fn as rt,fu as it,gn as at,hn as ot,jn as st,kd as ct,kn as lt,ks as ut,ku as dt,lc as ft,ln as pt,lu as mt,mn as ht,mu as gt,nr as _t,oc as vt,od as yt,pc as bt,pd as xt,pn as St,pu as Ct,ql as W,qt as wt,r as Tt,sc as Et,su as G,uc as Dt,un as Ot,ur as K,uu as kt,va as At,vn as jt,vr as Mt,vt as Nt,vu as Pt,w as Ft,wd as It,ws as Lt,yn as Rt,yr as zt,zd as Bt}from"./src-Ca4gNAmP.js";import{t as Vt}from"./crop-ChT009Qt.js";import{t as Ht}from"./layers-Bg1NrUAX.js";import{An as Ut,Br as Wt,Dn as Gt,En as Kt,Mn as qt,On as Jt,Tn as Yt,c as Xt,fi as Zt,jn as Qt,kn as $t,l as en,m as tn,wn as nn,yi as rn,zr as an}from"./client-1JBRoe76.js";import{n as on}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{$ as sn,H as cn,Y as ln,it as un,rt as dn}from"./index-CFJxM0gv.js";import"./useEventInvalidation-DD88fyzH.js";import{t as fn}from"./NodeAddonsSettingsPanel-CTCzvYQd.js";import{a as pn,c as mn,d as hn,g as gn,h as _n,i as vn,l as yn,n as bn,o as xn,p as Sn,r as Cn,s as wn,t as Tn}from"./board-model-Bmts6hrg.js";var En=k(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),Dn=k(`crown`,[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]),On=k(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),kn=k(`scale`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`m19 8 3 8a5 5 0 0 1-6 0zV7`,key:`zcdpyk`}],[`path`,{d:`M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1`,key:`1yorad`}],[`path`,{d:`m5 8 3 8a5 5 0 0 1-6 0zV7`,key:`eua70x`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}]]),An=k(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]),jn=`step`,Mn=[jn,`acc`];function Nn(e,t){return`${e}/${t}`}function Pn(e,t,n){let r=n.step!==null&&e.includes(n.step),i=n.acc!==null&&t.includes(n.acc);return{stepId:r?n.step:null,acceleratorId:i?n.acc:null,staleStepId:n.step!==null&&n.step!==``&&!r&&e.length>0?n.step:null}}function Fn(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 In(e){return e}function Ln(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Rn(e,t){return typeof e==`boolean`?e:In(t)}function zn(e,t){return{pipeline:Rn(Ln(e,`detect`),t),audio:Rn(Ln(e,`audio`),t),ingest:Rn(Ln(e,`ingest`),t)}}function Bn(e,t,n){let r=e?.find(e=>e.nodeId===t);return zn(r?.settings,n)}function Vn({selectedNodeId:e,onSelect:t,refreshToken:n}){let{nodes:r}=Qe(),{data:a}=P(void 0),{data:s}=Ve(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=r??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return i(`div`,{className:`flex flex-col h-full`,children:[i(`button`,{type:`button`,onClick:()=>t(ko),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[d(dn,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Assignments, load balancing, roles`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let r=e===n.id,a=c.get(n.id)??0,l=n.isHub?qe:V,u=Bn(s,n.id,n.isHub),f=n.isOnline?null:Nt(Fn(n.lastSeen));return i(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-danger flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),i(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[i(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(Me,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`text-danger`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(K,{variant:u.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),d(K,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),i(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[i(`span`,{children:[u,` online`]}),f>0&&i(`span`,{className:`text-danger`,children:[f,` offline`]})]})]})}function Hn({nodeId:e,refreshToken:t}){let{nodes:n}=Qe(),r=n?.find(t=>t.id===e),a=mt(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?i(`div`,{className:`px-6 py-4 border-b border-border`,children:[i(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-danger/10 text-danger`,children:`offline`}),r.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:r.cpuModel??`CPU`}),d(`span`,{children:`•`}),i(`span`,{children:[r.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),i(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),i(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&i(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:i(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var Un=[`assignments`,`tree`,`engines`,`logs`];r();function Wn({refreshToken:e,nodeId:t}){let[n,r]=u(new Map),{nodes:o}=G();et(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=N(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[l,o]);if(t){let e=l.get(t);return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(q,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(q,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(q,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(q,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(q,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(q,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),i(`tbody`,{children:[m.map(([e,t])=>i(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}var Gn={active:!1,pinned:!1,nodeId:null,reason:``};function Kn(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function qn(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??``}:Gn,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:Gn;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:Gn,audio:o}}).toSorted(Kn)}function Jn(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function Yn(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:Jn(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:Jn(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:Jn(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function Xn(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(Kn)}function Zn(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 Qn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??`Camera ${e}`}function $n(e,t,n){return[{value:`auto`,label:`Auto`},...[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])].map(e=>({value:e,label:`Pin → ${n(e)}`}))]}function er({roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:i,emphasizeOnNodeId:a}){if(n.nodeId===null)return null;let o=n.nodeId,s=a===void 0?!1:n.active&&o===a;return d(wt,{roleId:e,roleLabel:t,nodeName:r(o),colorId:Ge(i,o),emphasized:s,pinned:n.pinned})}function tr({detection:e,decoder:t,audio:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o}){let s=(e,t,n)=>d(er,{roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o},e);return i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[s(`detection`,`Detection`,e),s(`decode`,`Decode`,t),s(`audio`,`Audio`,n)]})}function nr({snap:e}){if(e===void 0)return d(`div`,{className:`flex h-8 items-center text-[11px] text-foreground-subtle`,title:`No metrics in the last 10 s — the camera has no session running`,children:`no live data`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=ye(t);return i(`div`,{className:`flex h-8 min-w-0 flex-col justify-center font-mono text-[10px] leading-tight tabular-nums`,children:[i(`span`,{className:`inline-flex min-w-0 items-center gap-1 ${c.textColor}`,children:[d(ie,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate font-semibold uppercase tracking-wider`,children:c.label}),d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[`/`,o.toFixed(0),` fps`]})]}),i(`span`,{className:`truncate text-foreground-subtle`,children:[d(`span`,{className:`text-foreground`,children:r.toFixed(0)}),` ms`,a>0&&i(`span`,{className:`ml-1 text-warning`,children:[`q`,a]}),i(`span`,{className:s>0?`ml-1 text-warning`:`ml-1`,children:[`drops `,s]})]})]})}r();var rr=1e4,ir=5e3;function ar(e){let[t,n]=u(new Map);return et(`pipeline.camera-metrics-snapshot`,t=>{let r=t.data;typeof r.deviceId==`number`&&(e!==void 0&&r.nodeId!==e||n(e=>new Map(e).set(r.deviceId,r)))}),f(()=>{if(t.size===0)return;let e=setInterval(()=>{n(e=>{let t=Date.now()-rr,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},ir);return()=>clearInterval(e)},[t.size]),t}var or=3e5;function sr({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:i}){return d(W,{"aria-label":`Node pin`,title:`Auto lets each session pick its node; a pin keeps the camera on one node.`,value:e.pinned&&e.nodeId!==null?e.nodeId:`auto`,disabled:r,options:[...$n(e,t,n)],onChange:e=>i(e.target.value)})}function cr({deviceId:e,nodeId:t}){let n=c(),{data:r}=ze({deviceId:e},{refetchOnMount:`always`}),{data:i}=De({nodeId:t},{staleTime:or}),a=Et({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`accelerator: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),l=r?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l),f=o.find(e=>e.key===l),p=[{value:`auto`,label:`Any accelerator`},...u?[{value:l,label:`${f?`${H(f)} (${l})`:l} (not enabled)`}]:[],...s.map(e=>({value:e.key,label:`${H(e)} · ${e.format}`}))];return d(W,{"aria-label":`Inference device pin`,title:`Pin detection to one accelerator of the node, or let each session pick.`,value:l,disabled:a.isPending,options:p,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value})})}r();function lr(e){let t=n(null);return e.nodeId!==null&&(t.current=e),t.current}function ur({deviceId:e,state:t,...n}){let r=lr(t);return i(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[d(sr,{state:t,...n}),r?.nodeId==null?d(W,{"aria-label":`Inference device pin (no node yet)`,title:`An accelerator is pinned on the camera's node; this camera has not run on one yet.`,disabled:!0,defaultValue:`auto`,options:[{value:`auto`,label:`Any accelerator`}]}):d(cr,{deviceId:e,nodeId:r.nodeId})]})}function dr({state:e,nameOf:t}){let n=lr(e);if(n?.nodeId==null)return d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`— no session yet`});let r=e.active&&e.nodeId!==null,a=n.pinned?`pinned`:`auto · ${n.reason||`capacity`}`;return i(`div`,{"data-testid":`resolved-placement`,className:`flex w-40 min-w-0 flex-col leading-tight`,title:n.pinned?void 0:`An unpinned camera is placed again at every session start, so this can change between sessions.`,children:[i(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[d(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${r?`bg-success`:`bg-foreground-subtle/40`}`}),d(`span`,{"data-testid":`resolved-placement-node`,className:`truncate font-medium ${r?`text-foreground`:`text-foreground-muted`}`,children:t(n.nodeId)})]}),d(`span`,{className:`truncate pl-3 text-[10px] ${n.pinned?`text-warning`:`text-foreground-subtle`}`,children:r?a:`${a} · idle, last session`})]})}function fr({deviceId:e,deviceName:t}){let[n,r]=u(!1);return i(o,{children:[d(j,{icon:yt,variant:`ghost`,size:`sm`,"aria-label":`Stream brokers of ${t}`,title:`Stream brokers & clients`,onClick:()=>r(!0)}),d(M,{open:n,onOpenChange:r,children:i(ve,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[d(R,{children:i(de,{children:[t,` — stream brokers & clients`]})}),d(st,{children:n&&d(lt,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e,instanceId:`pipeline-row/${e}`,config:{variant:`compact`}})})]})})]})}function pr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function mr(e,t){return t.size===0?!0:t.has(e)}var hr=[{value:`active`,label:`Active`},{value:`recently-active`,label:`Recently active`},{value:`inactive`,label:`Inactive`}];r();var gr=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function _r(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function vr(){let e=c();Tt([`pipelineOrchestrator`,`getPipelineAssignments`],gr),Tt([`pipelineOrchestrator`,`getAudioAssignments`],gr),Tt([`pipelineOrchestrator`,`getCameraStatuses`],gr);let{data:t}=At({isCamera:!0,projection:`slim`}),{data:n}=P(void 0),{data:r}=ut(void 0),{data:o}=xe({}),{data:s}=Ve(void 0),{nodes:l}=G(),f=ar(),p=a(()=>Zn(l),[l]),m=a(()=>me(s),[s]),h=a(()=>l.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[l]),g=a(()=>Yn(qn((t??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),n??[],r??[]),o??[]),[t,n,r,o]),[_,v]=u(()=>new Set),y=a(()=>g.filter(e=>mr(pr({hasPipelineAssignment:e.pipeline.active,hasFreshMetrics:f.has(e.deviceId)}),_)),[g,f,_]),x=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=()=>_r(e),C=L({onSuccess:S}),w=$e({onSuccess:S}),T=C.isPending||w.isPending,E=[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[d(ln,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName}),e.disabled&&d(K,{variant:`default`,children:`off`})]})},{key:`placement`,header:`Placement`,width:`w-80`,notSortableReason:`A pair of controls — editing one would move the row under the cursor.`,render:e=>d(ur,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:h,nameOf:p,pending:T,onChange:t=>t===`auto`?w.mutate({deviceId:e.deviceId}):C.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:e=>d(tr,{detection:e.detection,decoder:e.decoder,audio:e.audio,nameOf:p,colorByNodeId:m})},{key:`resolved`,header:`Running on`,width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:p(e.pipeline.nodeId),render:e=>d(dr,{state:e.pipeline,nameOf:p})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>f.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(nr,{snap:f.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>d(fr,{deviceId:e.deviceId,deviceName:e.deviceName})}],k=t===void 0?`Loading cameras…`:g.length===0?`No cameras`:`No cameras match this activity filter.`;return i(`div`,{className:`flex flex-col gap-2`,children:[d(`nav`,{"aria-label":`Filter by camera activity`,"data-testid":`assignments-activity-filter`,children:d(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:hr.map(e=>{let t=_.has(e.value);return d(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:nt(O,t?D:b),onClick:()=>x(e.value),children:e.label},e.value)})})}),d(ue,{columns:E,rows:y,rowKey:e=>e.deviceId,minWidthPx:920,mobileMode:`scroll`,maxBodyHeight:Re,emptyMessage:k})]})}r();function yr({nodeId:e}){let t=c();Tt([`pipelineOrchestrator`,`getCameraStatuses`],gr);let{data:n}=xe({}),{data:r}=Ve(void 0),{data:i}=At({isCamera:!0,projection:`slim`}),{nodes:o}=G(),s=ar(),l=a(()=>Zn(o),[o]),u=a(()=>me(r),[r]),f=a(()=>Xn(e,n??[],Qn((i??[]).map(e=>({id:e.id,name:e.name})))),[e,n,i]),p=o.filter(t=>t.isOnline&&t.id!==e),m=()=>_r(t),h=L({onSuccess:m}),g=$e({onSuccess:m}),_=re({onSuccess:m}),v=Dt({onSuccess:m}),y=e=>[...e.detection.active?p.map(t=>({id:`detect-${t.id}`,label:`Move detection to ${t.name}`,onClick:()=>h.mutate({deviceId:e.deviceId,agentNodeId:t.id})})):[],...e.audio.active?p.map(t=>({id:`audio-${t.id}`,label:`Move audio to ${t.name}`,onClick:()=>_.mutate({deviceId:e.deviceId,nodeId:t.id})})):[],{id:`unpin-detect`,label:`Unpin detection`,hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>g.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:`Unpin audio`,hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>v.mutate({deviceId:e.deviceId})}];return d(ue,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>d(ln,{to:`/devices/${String(e.deviceId)}`,className:`block w-44 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:t=>d(tr,{detection:t.detection,decoder:t.decoder,audio:t.audio,nameOf:l,colorByNodeId:u,emphasizeOnNodeId:e})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(nr,{snap:s.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>d(Be,{items:y(e),title:`Move ${e.deviceName}`})}],rows:f,rowKey:e=>e.deviceId,minWidthPx:560,mobileMode:`scroll`,maxBodyHeight:Re,emptyMessage:n===void 0?`Loading cameras…`:`No camera runs on this node right now`})}function br({nodeId:e,refreshToken:t}){let{nodes:n}=G(),r=n.find(t=>t.id===e)?.name??e;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(Wn,{refreshToken:t,nodeId:e}),i(`div`,{className:`space-y-2`,children:[i(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:[`Cameras on `,r]}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The roles each camera runs here right now. Move a role or unpin it from the row menu; pins for every camera are on Cluster → Assignments.`})]}),d(yr,{nodeId:e})]})]})}r();function xr(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Sr({nodeId:e,refreshToken:t}){let n=c(),r=_t(),o=I({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:s}=Lt({nodeId:e}),l=mt(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??s??null,u=l===null;Tt([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=bt({nodeId:e}),{values:p}=kt(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=a(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),h=t=>{let n=f??[];if(n.length===0){o.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await r({title:`Kill engine`,message:`${String(n.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:`Kill engine`,variant:`danger`})&&o.mutate({nodeId:e,engine:t,force:!0})})()};return i(`div`,{className:`space-y-6`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(l??[]).length,` engine(s) resident in RAM. `,(f??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),i(`tbody`,{children:[u&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!u&&(l??[]).map(e=>{let t=e.kind===`device-pool`;return i(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[d(t?Ht:V,{className:`h-3 w-3`}),t?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(Ct,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),d(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?d(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>d(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),d(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),d(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?d(`span`,{className:`text-foreground-subtle`,children:xr(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(f??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:t?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):i(z,{variant:`ghost`,size:`sm`,disabled:o.isPending,onClick:()=>h(e.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[d(x,{className:`h-3.5 w-3.5`}),`Kill`]})})]},e.engineKey)}),!u&&(l??[]).length===0&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),o.isError&&d(B,{message:`Kill failed: ${o.error instanceof Error?o.error.message:`unknown error`}`})]})}var Cr=`pipeline-runner`,wr=200;function Tr({nodeId:e}){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(Ie,{agentId:e,addonId:Cr,limit:wr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}r();function Er({nodeId:e,title:t}){let{data:n}=cn(),{data:r}=P(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),c=ar(e),l=a(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return l.length===0?i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[i(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=ye(e.metrics.phase);return i(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[d(ie,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}function Dr(e,t,n){return e.map(e=>{if(e.key===t)return e;let r=e.steps[n];if(!r||r.settings===void 0)return e;let{settings:i,...a}=r,o={...e.steps};return Object.keys(a).length>0?o[n]=a:delete o[n],{...e,steps:o}})}function Or(e,t,n){let r=e.filter(e=>e.key!==t).toSorted((e,t)=>e.key.localeCompare(t.key)),i=[...r.filter(e=>!e.enabled),...r.filter(e=>e.enabled),...e.filter(e=>e.key===t)],a;for(let e of i){let t=e.steps?.[n]?.settings;!t||Object.keys(t).length===0||(a={...a,...t})}return a}function kr(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 Ar=`pipeline-orchestrator`;function jr({addonId:e,highlightLabel:t}){let n=Jt(e),{data:r}=zt({addonId:Ar});if(n.length===0)return null;let a=Qt(r??null)[e]??{};return i(`section`,{className:`space-y-1.5 border-t border-border/60 pt-3`,"aria-label":`Cluster-wide settings`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:v,children:`Cluster-wide settings`}),d(ln,{to:Io(e),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Edit in Cluster → Settings ›`})]}),n.map(e=>i(`div`,{className:`${p} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[d(`span`,{className:w,children:e.label}),d(`span`,{className:h,children:d(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),d(`p`,{className:A,children:`One value for every node and camera — this step writes into a shared index.`})]})}function Mr({rows:e}){return i(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>i(`li`,{className:`${_} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-foreground-muted`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:e.modelId??`—`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.sourceLabel})]},e.id))}),d(`p`,{className:A,children:`To change a model, open that accelerator's cell in the table.`})]})}r();function Nr(e,n){let[r,i]=sn(),o=r.get(jn),s=r.get(`acc`),c=a(()=>Pn(e,n,{step:o,acc:s}),[e,n,o,s]),l=t(e=>{i(t=>{let n=new URLSearchParams(t);return e(n),n},{replace:!0})},[i]);return{selection:c,open:t(e=>l(t=>{t.set(jn,e.stepId),e.acceleratorId===void 0?t.delete(`acc`):t.set(`acc`,e.acceleratorId)}),[l]),close:t(()=>l(e=>{e.delete(jn),e.delete(`acc`)}),[l])}}function Pr(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function Fr(e){return e.split(`.`)[0]??e}function Ir(e,t,n){return{id:Nn(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${Fr(t)} · ${H(n)}`,shortLabel:`${Fr(t)} · ${F(n)}`,nodeLabel:Fr(t),disabled:!n.enabled}}function Lr(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>Ir(e,t,n))}function Rr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>Ir(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>Ir(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[Ir(e.id,e.name,a)]})}function zr(e,t,n){return{modelId:jt({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function Br(e,t,n){let r=Pr(e,`object-detection`);if(r===null)return;let i=jt({catalog:r,device:t.device,base:t.device.steps?.[`object-detection`]?.modelId,override:n});if(i===void 0)return;let a=r.models.find(e=>e.id===i);return{modelId:i,name:a?.name??i,supplies:a?.suppliesSteps??[]}}function Vr(e,t,n){return!an(e)||n===void 0?!1:Wt(e,t,n.supplies).effective}function Hr(e,t){return e!==null&&Rt(e.models,t.device.format)}function Ur(e){return Hr(e.addon,e.acc)?e.clusterModelId===void 0?{kind:`enabled`,modelId:e.model.modelId??`Auto`,overridden:e.model.source===`camera`,...e.rootName===void 0?{}:{suppliedByRoot:e.rootName},...e.jumpTo===void 0?{}:{jumpTo:e.jumpTo}}:{kind:`enabled`,modelId:e.clusterModelId,clusterWide:!0}:e.gatedOn?e.jumpTo===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:e.jumpTo}:{kind:`na`}}function Wr(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function Gr(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=Jt(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function Kr(e){return e.flatMap(e=>[{node:e,depth:0},...Kr(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function qr(e,t){return e.flatMap(e=>{let n=qr(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}r();function Jr(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:H(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Yr({tree:e,searchRows:r,accelerators:o,cellState:s,stepBadge:c,disabledCount:l,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:y}){let b=_t(),x=Ze(),{selection:S,open:C,close:w}=Nr(a(()=>Kr(e).map(e=>e.node.addonId),[e]),a(()=>o.map(e=>e.id),[o])),[T,E]=u(``),[D,O]=u(null),[k,M]=u(null),N=n(null),P=n(null),F=n(null),I=n(null),L=a(()=>ee(r,T),[r,T]),ne=a(()=>T.trim()===``?e:qr(e,new Set(L.map(e=>e.addonId))),[e,L,T]),re=e=>L.find(t=>t.addonId===e)?.matchedField??null,ie=a(()=>o.map(Jr),[o]),ae=e=>o.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),R=o.find(e=>e.id===S.acceleratorId)??null,z=S.stepId!==null,oe=t(async e=>{if(m){if(!await b({title:`Discard unsaved changes?`,message:`This step has changes that are not saved yet.`,confirmLabel:`Discard`,variant:`danger`}))return;h()}e()},[b,m,h]),se=()=>{requestAnimationFrame(()=>I.current?.focus())},ce=(e,t,n=!1)=>{if(e===S.stepId&&(t?.id??null)===S.acceleratorId){n&&se();return}let r=()=>{O(re(e)),C({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&se()};e===S.stepId?r():oe(r)},B=()=>{let e=S.stepId;oe(()=>{if(w(),e!==null){let t=R===null?null:Ue({agentNodeId:R.nodeId,deviceKey:R.deviceKey});requestAnimationFrame(()=>N.current?.focusCell(e,t))}})},le=e=>{if(e.key===`Enter`){let t=L[0];if(t===void 0)return;e.preventDefault(),ce(t.addonId,void 0,!0)}else e.key===`Escape`&&E(``)},ue=x?d(te,{onClick:B}):d(j,{icon:gt,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:B});return i(`div`,{ref:P,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),F.current?.focus()),e.key===`Escape`&&t&&z&&(e.preventDefault(),B())},children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),d(`input`,{ref:F,type:`search`,value:T,onChange:e=>E(e.target.value),onKeyDown:le,placeholder:`Filter steps or settings /`,"aria-label":`Filter steps or settings`,className:`h-9 w-56 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30 md:h-7`}),l>0&&i(`label`,{className:`inline-flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(Ot,{checked:f,onChange:e=>p(e.target.checked)}),`Show disabled accelerators (`,l,`)`]}),_]}),S.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:[`The link names a step this pipeline does not have (`,S.staleStepId,`).`]}),ne.length===0?i(`p`,{className:`${A} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:[`No step matches “`,T,`”.`]}):d(fe,{ref:N,tree:ne,agents:ie,label:v,getCellState:(e,t)=>{let n=ae(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>ce(e,ae(t),n),onStepClick:(e,t)=>ce(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:z&&S.stepId!==null&&R!==null?{addonId:S.stepId,agentNodeId:R.nodeId,deviceKey:R.deviceKey}:null,fallbackNodeId:k,onFallbackNodeChange:M,reserveRightPx:z&&!x?432:0}),d(Se,{open:z,anchor:P,onClose:B,label:`Step settings`,children:S.stepId!==null&&y({stepId:S.stepId,accelerator:R,matchedField:D,closeButton:ue,onEscape:B,headingRef:e=>{I.current=e}})})]})}r();function Xr(e){f(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}r();function Zr(e,t){let n=e.filter(e=>e.steps?.[t]?.settings!==void 0),r=e=>e.toSorted((e,t)=>e.key.localeCompare(t.key));return r(n.filter(e=>e.enabled))[0]?.key??r(n)[0]?.key??r(e.filter(e=>e.enabled))[0]?.key??e[0]?.key}function Qr(e,t){let n=t.settings===void 0?void 0:Zr(e,t.stepId),r=e.map(e=>{let r={...e.steps},i=r[t.stepId]??{},a=t.models[e.key],o=t.jumps[e.key],s=e.key===n&&t.settings!==void 0?Object.keys(t.settings).length>0?t.settings:void 0:i.settings,c=a===void 0?i.modelId:a??void 0,l=o===void 0?i.jumpDeviceKey:o||void 0,u={...c===void 0?{}:{modelId:c},...s===void 0?{}:{settings:s},...l===void 0?{}:{jumpDeviceKey:l}};return Object.keys(u).length>0?r[t.stepId]=u:delete r[t.stepId],{key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:r}});return n===void 0?r:Dr(r,n,t.stepId)}function $r(e,t,n){if(t===null)return 0;let r=Object.entries(t.models).filter(([n,r])=>(r??void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.modelId).length,i=Object.entries(t.jumps).filter(([n,r])=>(r||void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.jumpDeviceKey).length,a=new Set([...Object.keys(n),...Object.keys(t.settings??{})]),o=t.settings===void 0?0:[...a].filter(e=>!tn(n[e],t.settings?.[e])).length;return r+i+o}function ei({nodeId:e,nodeName:t,toolbar:n}){let r=c(),s=De({nodeId:e},{refetchOnMount:`always`}),l=je({nodeId:e},{refetchOnMount:`always`}),f=Ut(zt({addonId:`pipeline-orchestrator`}).data??null),p=s.data?.devices??[],m=l.data??null,[h,g]=u(null),[_,y]=u(null),[b,x]=u(null),S=Ke({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),C=a(()=>m?ke(m):[],[m]),w=a(()=>Kr(C),[C]),[T,E]=u(!1),D=a(()=>Lr(e,t,p,T),[e,t,p,T]),O=a(()=>Lr(e,t,p),[e,t,p]),k=O.length>=2,j=(e,t)=>(t===void 0?void 0:Or(p,t.deviceKey,e))??{},M=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return O.find(e=>e.deviceKey===r);if(!Hr(e,t))return O.filter(n=>n.id!==t.id&&Hr(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},N=(e,t)=>{let n=Pr(m,e),r=zo(e),i=Br(m,t),a=j(e,t),o=M(n,t);return Ur({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?zr(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...Vr(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:f[e]??r.defaultModelId}:{},...o?{jumpTo:F(o.device)}:{}})},P=w.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Gr(Pr(m,e.addonId))}));if(s.isLoading||l.isLoading)return d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`});if(m===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`});let ee=i(`span`,{className:A,children:[`Accelerators:`,` `,d(`span`,{className:`text-foreground`,children:O.length>0?O.map(e=>F(e.device)).join(` · `):`none enabled`}),p.some(e=>!e.enabled)&&i(o,{children:[` `,`— off:`,` `,p.filter(e=>!e.enabled).map(F).join(`, `)]}),` `,`·`,` `,d(ln,{to:Lo(),className:`text-primary hover:underline`,children:`Cluster → Load balancing ›`})]});return d(Yr,{tree:C,searchRows:P,accelerators:D,cellState:N,disabledCount:p.filter(e=>!e.enabled).length,showDisabled:T,onShowDisabledChange:E,dirty:h!==null&&$r(p,h,j(h.stepId,D[0]))>0,onDiscard:()=>g(null),summary:ee,...n===void 0?{}:{toolbar:n},label:`Detection steps`,renderDetail:({stepId:n,accelerator:r,matchedField:a,closeButton:s,onEscape:c,headingRef:l})=>{let u=Pr(m,n);if(u===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let f=h?.stepId===n?h:null,C=r??O[0]??D[0],w=j(n,C),T=f?.settings??w,E=$r(p,f,w),N=e=>{x(null),g(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},P=zo(n),ee=ht(u),F=C===void 0?void 0:Br(m,C),I=e=>{let t=f?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},L=C===void 0?void 0:zr(u,C,{nodePin:I(C)}).modelId,te=D.length>1&&D.some(e=>!tn(j(n,e),w)),ne=e=>{let t=I(e),r=zr(u,e,{nodePin:t}),a=Br(m,e),s=Vr(n,f?.settings??j(n,e),a),c=f?.jumps[e.deviceKey],l=M(u,e,c),p=Hr(u,e)?s&&a?d(rt,{rootModel:a,stepModelId:r.modelId}):void 0:i(o,{children:[`No `,e.device.format,` build of this step.`,` `,l?`It runs on ${l.shortLabel} instead.`:`It does not run here.`]}),h=k?i(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Run on`}),d(W,{"aria-label":`Run on`,value:c??e.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:`Auto (this accelerator, or the next one that can run it)`},...O.filter(t=>t.id!==e.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:t=>N({jumps:{...f?.jumps,[e.deviceKey]:t.target.value}})}),d(`span`,{className:A,children:`Routes this step (and its child steps) to another accelerator of this node.`})]}):void 0;return{label:e.label,format:e.device.format,modelId:r.modelId,source:r.source===`node`?`node`:`default`,sourceLabel:r.source===`node`?`node pin`:`hardware default`,models:Ye(u.models??[],e.device.format),defaultModelId:u.defaultModelIdByFormat?.[e.device.format]??u.defaultModelId,expanded:_===e.id,onToggle:()=>y(t=>t===e.id?null:e.id),onChangeModel:t=>N({models:{...f?.models,[e.deviceKey]:t}}),...t===void 0?{}:{onReset:()=>N({models:{...f?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...p===void 0?{}:{note:p},...h===void 0?{}:{extra:h},changed:f?.models[e.deviceKey]!==void 0||c!==void 0}},re=()=>{f!==null&&S.mutate({agentNodeId:e,inferenceDevices:kr(Qr(p,f))},{onSuccess:()=>{g(null),x({kind:`saved`})},onError:e=>x({kind:`error`,error:e.message})})};return d(Ne,{ref:l,title:r===null?`${u.name} · ${t}`:`${u.name} · ${r.label}`,subtitle:r===null?`${u.slot} · every accelerator of ${t}`:`${u.slot} · ${r.device.format} · base for every camera that lands here`,leading:s,onEscape:c,saveBar:{dirtyCount:E,saving:S.isPending,status:b?.kind??null,...b?.error===void 0?{}:{error:b.error},onSave:re,onDiscard:()=>g(null)},children:i(`div`,{className:`space-y-3`,children:[i(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[d(`h3`,{className:v,children:`Model`}),P!==null&&C!==void 0?d(Bo,{step:P,engineFormat:C.device.format,runnableModelIds:Ye(u.models??[],C.device.format).map(e=>e.id)}):D.length===0?i(`p`,{className:A,children:[`No accelerator is enabled on this node —`,` `,d(ln,{to:Lo(),className:`text-primary hover:underline`,children:`enable one in Cluster → Load balancing`}),`.`]}):r===null?d(Mr,{rows:D.map(e=>{let t=zr(u,e,{nodePin:I(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):d(Ft,{...ne(r)},r.id)]}),(ee.length>0||F!==void 0)&&P===null&&i(`section`,{"aria-label":`Settings`,className:`space-y-2 border-t border-border/60 pt-2`,children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`settings-scope`,children:[`Node-wide: these settings apply on every accelerator of `,t,`.`]}),te&&d(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2 py-1 text-[11px] text-warning`,children:`This step's settings differ between this node's accelerators. Saving makes the values shown here node-wide.`}),d(ti,{addon:u,fields:ee,settings:T,modelId:St(u,L,T,F),root:F,highlight:a,onChange:e=>N({settings:e})})]}),d(jr,{addonId:n,highlightLabel:a})]})})}})}function ti({addon:e,fields:t,settings:n,modelId:r,root:i,highlight:a,onChange:o}){let s=t.find(e=>`label`in e&&e.label===a)?.key??null;return Xr(s===null?null:at(s)),d(ot,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:`Node`},modelId:r,...i===void 0?{}:{rootModel:i},highlightKey:s,onChangeLayer:o})}r();function ni({nodeId:e,refreshToken:t}){let n=_t(),[r,a]=u(null),{nodes:s}=G(),c=s.find(t=>t.id===e)?.name??e,l=pe({onSuccess:e=>{a(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${c} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(a(null),l.mutate({agentNodeId:e}))};return i(`div`,{className:`space-y-2`,children:[d(Er,{nodeId:e}),d(ei,{nodeId:e,nodeName:c,toolbar:i(o,{children:[r&&d(`span`,{className:`text-[11px] text-success`,children:r}),l.isError&&d(`span`,{className:`text-[11px] text-danger`,children:l.error instanceof Error?l.error.message:`Reset failed`}),d(z,{variant:`outline`,size:`sm`,onClick:()=>{f()},disabled:l.isPending,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:l.isPending?`Resetting…`:`Reset to default`})]})})]})}var ri=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],ii=`decoder-nodeav`,ai=`ntab`,oi={decoder:`engine`},si={engine:`Engine & decoder`},ci=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function li({nodeId:e,refreshToken:t}){let[n,r]=sn(),{nodes:a}=G(),o=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??ii,s=[...ri,o],c=n.get(ai),l={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:d(br,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:d(ni,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:d(Sr,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:d(Tr,{nodeId:e})}},u=Un.map(e=>l[e]);return i(`div`,{className:`flex flex-col h-full`,children:[d(Hn,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:d(fn,{nodeId:e,addonIds:s,level:`global`,fieldScope:`perNode`,emptyMessage:ci,tabAliases:oi,tabLabelOverrides:si,extraTabs:u,activeTab:c===null?null:oi[c]??c,onActiveTabChange:e=>r(t=>{let n=new URLSearchParams(t);n.set(ai,e);for(let e of Mn)n.delete(e);return n},{replace:!0})})})]})}function ui(){return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Camera placement`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pin a camera to a node, or to one accelerator of its node; Auto lets each session pick. Decode always runs with detection. Load, shares and caps are on Load balancing.`})]}),d(vr,{})]})}function di(e){return`${Math.round(e*100)}%`}function fi(e){return`${e} session${e===1?``:`s`}`}var pi={"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`},mi={"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 hi(e){return e===null?`—`:pi[e]??e}function gi(e){return e===null?`—`:mi[e]??e}function _i(e){switch(e.kind){case`capacity`:return`Capacity ${fi(e.sessions)} ≥ min ${e.minSessions}.`;case`tie-faster`:return`As accurate as ${e.over} (within ${di(e.recallDelta)} recall) and faster.`;case`stepped-down`:return`${e.from} would not fit the load on ${e.limitedBy}; ${e.to} is the most accurate that does.`;case`no-fit-lightest`:return`No model reaches ${fi(e.minSessions)} per device; the one with the most capacity (${fi(e.sessions)}) is used.`;case`derived-latency`:return`${e.modelId}: latency estimated from a similar chip, not measured on this one.`;case`cpu-device`:return`CPU fallback device: picked on its own.`;case`coral-untouched`:return`Coral: left as is (no YOLOv9 build exists for it).`;case`device-disabled`:return`Disabled: not changed.`;case`device-unavailable`:return`Not available on the node right now: not changed.`;case`node-offline`:return`Node offline: nothing on it will change.`;case`no-hardware-facts`:return`Hardware could not be read: nothing on this node will change.`;case`no-measured-data`:return`This hardware has no measured data: nothing on this node will change.`;case`no-family-build`:return`No YOLOv9 build for the ${e.format} format: not changed.`;case`kept-custom-pin`:return`Custom model ${e.modelId} is pinned on ${e.deviceKey}: Auto tune skips this device.`}}function vi(e,t){switch(e.kind){case`detector-store-cluster-wide`:return`Per-camera detector thresholds are not tied to a node, so they are cleared for every camera — including cameras that run on skipped nodes (${e.skippedNodes.map(t).join(`, `)}).`;case`detector-store-unreadable`:return`Per-camera detector thresholds could not be read (${e.error}); those will not be cleared.`;case`coral-enabled`:return`${t(e.nodeId)}: the Coral (${e.deviceKey}) is enabled and keeps running its SSD model, which finds far fewer people than YOLOv9. Consider disabling it.`;case`custom-pin-kept`:return e.deviceId===null?`${t(e.nodeId)}: custom model ${e.modelId} pinned on ${e.deviceKey??`—`} — Auto tune skips this node device.`:`Camera ${e.deviceId} pins custom model ${e.modelId} on ${t(e.nodeId)} — Auto tune keeps that override and its thresholds.`;case`custom-registry-unreadable`:return`The custom-model registry could not be read (${e.error}): every pin to a model outside the measured catalog is kept.`}}function yi(e){let t=e.nodeChanges.reduce((e,t)=>e+t.modelPins.length,0),n=e.nodeChanges.reduce((e,t)=>e+t.thresholds.length,0),r=new Set([...e.cameraClears.map(e=>e.deviceId),...e.detectorStoreClears.map(e=>e.deviceId)]);return{modelChanges:t,thresholdClears:n,cameraOverrideClears:e.cameraClears.length,detectorStoreClears:e.detectorStoreClears.length,camerasTouched:r.size}}function bi(e){let t=yi(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function xi(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 Si(e,t){return e?.kind===`node-benchmark`?`measured on this node, ${new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}`:`from the latency table — benchmark this node to measure it`}r();var Ci=[.3,.4,.5];function wi(e){return Ci.some(t=>t===e)}var Ti=[1,2,3,4,6,8];function Ei({plan:e,node:t,nodeName:n}){return i(`section`,{className:g,"data-testid":`auto-tune-node-${t.nodeId}`,children:[i(`header`,{className:`${T} flex flex-wrap items-center gap-2`,children:[d(V,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${v} min-w-0 flex-1`,children:n(t.nodeId)}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[gi(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?d(K,{variant:`warning`,children:`Not changed`}):t.acceleratorModelId!==null&&d(K,{variant:`info`,children:t.acceleratorModelId})]}),t.reasons.length>0&&d(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:t.reasons.map((e,t)=>d(`li`,{children:_i(e)},t))}),d(`div`,{className:`overflow-x-auto`,children:i(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:i(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Device`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Capacity`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Detector`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Why`})]})}),d(`tbody`,{children:t.devices.map(n=>{let r=xi(e,t.nodeId,n.deviceKey);return i(`tr`,{className:`border-t border-border align-top`,children:[i(`td`,{className:`px-3 py-1.5`,children:[d(`div`,{className:`font-mono text-foreground`,children:n.deviceKey}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:hi(n.accelerator)})]}),i(`td`,{className:`px-3 py-1.5 text-foreground-muted`,children:[n.chosen===null?`—`:`${n.chosen.capacitySessions} session${n.chosen.capacitySessions===1?``:`s`} at ${e.cameraFps} fps`,n.chosen!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n.chosen.fps,` fps, `,Math.round(e.headroom*100),`% kept free`,d(`div`,{children:Si(n.chosen.source)})]})]}),d(`td`,{className:`px-3 py-1.5`,children:n.chosen===null?d(`span`,{className:`text-foreground-subtle`,children:`unchanged`}):r!==null&&r.before!==r.after?i(`span`,{children:[d(`span`,{className:`text-foreground-subtle`,children:r.before??`default`}),` → `,d(`span`,{className:`font-medium text-foreground`,children:r.after})]}):d(`span`,{className:`text-foreground`,children:n.chosen.modelId})}),d(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>d(`div`,{children:_i(e)},t))})]},n.deviceKey)})})]})})]})}function Di({plan:e,nameOf:t,nodeName:n}){return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[i(`div`,{children:[d(`div`,{className:v,children:`Node settings`}),e.nodeChanges.length===0?d(`div`,{className:`text-foreground-subtle`,children:`No change.`}):d(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.nodeChanges.flatMap(e=>[...e.modelPins.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: `,t.before??`default`,` → `,t.after??`step default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/pin`)),...e.thresholds.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: reset `,t.keys.join(`, `),` to the model default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),i(`div`,{children:[d(`div`,{className:v,children:`Camera overrides cleared`}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?d(`div`,{className:`text-foreground-subtle`,children:`None.`}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,r)=>i(`li`,{children:[t(e.deviceId),` — `,n(e.nodeId),e.deviceKey===null?` (whole pipeline)`:` · ${e.deviceKey}`,` — `,e.stepId,e.modelIdBefore===null?``:`: model ${e.modelIdBefore} removed`,e.keys.length>0?`; ${e.keys.join(`, `)} reset`:``]},`c${r}`)),e.detectorStoreClears.map(e=>i(`li`,{children:[t(e.deviceId),` — detector thresholds: `,e.keys.join(`, `),` reset`]},`d${e.deviceId}`))]})]})]})}function Oi({result:e}){return e.kind===`refused`?d(`div`,{className:`text-xs text-warning`,children:`Another apply is already running.`}):e.kind===`stale`?d(`div`,{className:`text-xs text-warning`,children:`The configuration changed since the plan was shown. Review the updated plan below and apply again.`}):i(`ul`,{className:`text-xs`,"data-testid":`auto-tune-result`,children:[e.kind===`aborted`&&d(`li`,{className:`text-danger`,children:`A model could not be downloaded: nothing was changed.`}),e.phases.map(e=>i(`li`,{className:e.ok?`text-foreground-muted`:`text-danger`,children:[e.ok?`✓`:`✗`,` `,e.phase,`: `,e.detail]},e.phase))]})}function ki(){let e=c(),[t,n]=u(.4),[r,o]=u(2),[s,l]=u(!1),[f,p]=u(!1),[m,h]=u(null),{data:_}=cn(),y=a(()=>new Map((_??[]).map(e=>[e.id,e.name])),[_]),b=e=>y.get(e)??`Camera ${e}`,{nodes:x}=G(),S=a(()=>Zn(x),[x]),C=oe({headroom:t,minSessionsPerDevice:r},{enabled:s,refetchOnWindowFocus:!1}),w=Fe({onSuccess:t=>{h(t),p(!1),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.kind===`applied`&&C.refetch()}}),E=m?.kind===`stale`?m.plan:C.data,D=E===void 0?null:yi(E);return i(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[i(`section`,{className:g,children:[i(`header`,{className:`${T} flex flex-wrap items-center gap-2`,children:[d(Oe,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${v} min-w-0 flex-1`,children:`Auto tune`})]}),i(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[d(`p`,{children:`Picks, for every accelerator, the most accurate YOLOv9 detector that still carries at least the chosen number of cameras at once, from the node's hardware and measured speeds. Nothing is measured or estimated about your cameras' activity. Applying it sets those models and clears every model and threshold override — node level and per camera — so each model runs its own default thresholds. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`Keep free`}),d(W,{"aria-label":`Share of each accelerator kept free`,value:String(t),options:Ci.map(e=>({value:String(e),label:`${Math.round(e*100)}% of each accelerator`})),onChange:e=>{let t=Number(e.target.value);wi(t)&&n(t)}})]}),i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`At least`}),d(W,{"aria-label":`Minimum parallel sessions per device`,value:String(r),options:Ti.map(e=>({value:String(e),label:`${e} camera${e===1?``:`s`} at once per accelerator`})),onChange:e=>{let t=Number(e.target.value);Ti.some(e=>e===t)&&o(t)}})]}),d(z,{size:`sm`,variant:`secondary`,onClick:()=>{h(null),l(!0),s&&C.refetch()},children:C.isFetching?`Computing…`:E===void 0?`Compute plan`:`Recompute`}),E!==void 0&&d(z,{size:`sm`,disabled:bi(E),onClick:()=>p(!0),children:`Apply…`})]}),C.error!==null&&d(`div`,{className:`text-danger`,children:C.error.message}),m!==null&&d(Oi,{result:m}),D!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[D.modelChanges,` model change(s), `,D.thresholdClears,` node threshold reset(s), `,D.cameraOverrideClears+D.detectorStoreClears,` camera override(s) on `,D.camerasTouched,` camera(s).`]})]})]}),E?.warnings.map((e,t)=>d(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:vi(e,S)},t)),E?.nodes.map(e=>d(Ei,{plan:E,node:e,nodeName:S},e.nodeId)),E!==void 0&&d(M,{open:f,onOpenChange:p,children:i(ve,{width:`lg`,scroll:`body`,children:[i(R,{children:[d(de,{children:`Apply auto tune?`}),d(be,{children:`These are all the changes. Every override listed is removed and cannot be restored.`})]}),d(st,{children:d(Di,{plan:E,nameOf:b,nodeName:S})}),i(we,{children:[d(z,{variant:`ghost`,onClick:()=>p(!1),children:`Cancel`}),d(z,{variant:`danger`,disabled:w.isPending,onClick:()=>w.mutate({planHash:E.planHash,headroom:t,minSessionsPerDevice:r}),children:w.isPending?`Applying…`:`Apply`})]})]})})]})}var Ai={disabled:`switched off — not a dispatch target`,unavailable:`the node probe does not see it (unplugged or still provisioning)`,"cannot-host-camera-root":`its engine format has no object-detection root model`,"accelerator-preferred":`CPU fallback — it never competes while an accelerator is serving`};function ji(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function Mi(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function Ni(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:H(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?ji(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 Pi(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=Ni(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),Mi(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?ji(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?ji(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}r();var Fi=2e4,Ii=3e5;function Li({stats:e,targetWeights:t}){let{nodes:n}=G(),r=E().trpcClient,o=Ce(void 0,{placeholderData:l,staleTime:Fi,refetchInterval:Fi,refetchOnWindowFocus:!0}),c=Ve(void 0,{staleTime:Ii}),u=a(()=>n.map(e=>e.id),[n]),f=s({queries:u.map(e=>({queryKey:on(it.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Ii,refetchOnWindowFocus:!1,placeholderData:l}))}),p=a(()=>{let e={};return u.forEach((t,n)=>{let r=f[n]?.data;r&&(e[t]=r.devices)}),e},[u,f.map(e=>e.dataUpdatedAt).join(`|`)]),h=a(()=>{let e=new Map;for(let t of c.data??[])e.set(t.nodeId,t.settings);return e},[c.data]),g=a(()=>n.map(e=>{let n=h.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:zn(n,e.isHub).pipeline,weight:t?.[e.id]??hn(n,`detectWeight`)??1,maxCameras:hn(n,`maxCameras`)}}),[n,h,t]),_=o.data??[],v=a(()=>Pi({nodes:g,loads:_,devicesByNode:p}),[g,_,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),x=o.dataUpdatedAt>0?Date.now()-o.dataUpdatedAt:null,S=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return d(U,{headingId:`load-balancing-node-load`,title:`Node load`,icon:ae,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[b,` running · `,y,` attached ·`,` `,o.data===void 0?`reading…`:`${x===null?`—`:`${Math.round(x/1e3)}s`} old`]}),children:d(`div`,{className:m,children:v.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>d(Ri,{row:e,placed:S.get(e.nodeId)},e.nodeId))})})})}function Ri({row:e,placed:t}){let n=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[d(dt,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(Pt,{className:`h-2.5 w-2.5`}),` offline`]})]}),i(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:n,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share (1 h)`,value:t?.observedShare===null||t===void 0?`—`:`${Math.round(t.observedShare*100)}%`,title:`Time-weighted share of the cluster's PARALLEL detection sessions this node carried over the last hour — the quantity a share holds. '—' = no session ran here in the window.`}),d(J,{label:`Peak · yields`,value:t===void 0?`—`:`${t.peakSessions} · ${t.yieldsAway}`,title:`Most sessions this node ran at once in the last hour, and how many share turns it handed to another node because it was full or drowning.`}),d(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(zi,{row:e})]})}function zi({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):i(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[i(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(Bt,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(Bi,{device:e},e.key))})]})}function Bi({device:e}){let t=e.exclusion;return i(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(V,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?i(o,{children:[i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,title:e.sessions===null?`Not known: the node did not report, or runs a session no device accounts for.`:void 0,children:[`· `,e.sessions??`—`,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):i(`span`,{className:`truncate text-foreground-subtle/80`,title:Ai[t],children:[`excluded — `,Ai[t]]})]})}function J({label:e,value:t,title:n}){return i(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Vi(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Hi(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 Ui(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Wi(e){return e.reason===`disabled`?`${e.deviceKey} is not enabled on any node — sessions ignore this pin`:`no node offers ${e.deviceKey} — sessions ignore this pin`}function Gi(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 Ki(e,t){let n=e.nodes.filter(e=>!e.eligible);if(n.length===0)return null;let r=e.nodes.filter(e=>e.eligible).map(e=>`${t(e.nodeId)} ${Math.round(e.effectivePct)}%`).join(`, `);return`${n.map(e=>t(e.nodeId)).join(`, `)} cannot take sessions — ${n.length===1?`its share goes`:`their shares go`} to the others: ${r}`}var qi=[{value:`hardware`,label:`Hardware`,hint:`Each node’s share follows what its accelerators can carry at their Auto tune models, from the measured speed of its hardware. No load is measured or estimated.`},{value:`benchmark`,label:`Benchmark`,hint:`Each node’s share follows its own node-benchmark results. A node without results uses its hardware capacity instead, and says so.`},{value:`manual`,label:`Manual`,hint:`The sliders below, as you set them.`}];function Ji(e){return e===`no-benchmark-results`?`no benchmark results yet — sized from hardware`:e===`partial-benchmark-results`?`benchmark results miss some of its accelerators — sized from hardware`:null}function Yi(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)}: ${Ji(e.capacityFallback)??``}`).join(` · `)}r();function Xi(e,t,n){return Math.min(Math.max(e,t),n)}function Zi(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 Qi(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:Xi(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 $i(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 ea({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:a,footnote:s,readOnly:c=!1}){let[l,p]=u(()=>Zi(e)),[m,h]=u(new Set);f(()=>{p(Zi(e)),h(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let g=e.map(e=>e.id),_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=(e,t)=>{p(n=>Qi(n,e,t,m,g))},y=()=>{let t=$i(l,g,m),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...m]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:a??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let b=e.length===1;return i(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=l[e.id]??0,a=m.has(e.id);return i(`div`,{className:`flex items-center gap-3`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),d(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:c||t||a||b,onChange:t=>v(e.id,Number(t.target.value)),onPointerUp:()=>y(),onKeyUp:()=>y(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),i(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),!c&&d(`button`,{type:`button`,onClick:()=>_(e.id),disabled:t||b,"aria-pressed":a,title:a?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${a?`text-amber-400`:`text-foreground-subtle`}`,children:d(a?It:Pe,{className:`h-3.5 w-3.5`})})]},e.id)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:s??d(o,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}function ta(e){let t=e.steps?.[`object-detection`]?.modelId;return typeof t==`string`&&t.length>0?t:typeof e.defaultModelId==`string`&&e.defaultModelId.length>0?e.defaultModelId:null}r();function na(e){let t=H(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:V,hue:`slate`}:r===`npu`?{label:t,Icon:Ct,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:En,hue:`violet`}:n===`edgetpu`?{label:t,Icon:An,hue:`emerald`}:{label:t,Icon:V,hue:`slate`}}var ra={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function ia({nodeId:e,nodeName:t,isOnline:n,suggestedMaxSessions:r,autoDeviceShares:s}){let l=c(),{data:p,isLoading:m}=De({nodeId:e},{refetchInterval:15e3}),h=Ke({onSettled:()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),g=p?.devices??[],_=p?.reachable??n,[v,y]=u({});f(()=>{y(Object.fromEntries(g.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[g.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let b=a(()=>g.filter(e=>v[e.key]?.enabled??e.enabled).length,[g,v]),[x,S]=u(null),w=x??b>0,T=t=>{let n=g.map(e=>{let n=t[e.key]??E(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});h.mutate({agentNodeId:e,inferenceDevices:kr(n)})},E=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),D=e=>{if(!e.available)return;let t=v[e.key]??E(e),n={...v,[e.key]:{...t,enabled:!t.enabled}};y(n),T(n)},O=(e,t)=>{let n=v[e.key]??E(e),r={...v,[e.key]:{...n,maxSessions:t}};y(r),T(r)},k=a(()=>g.filter(e=>(v[e.key]?.enabled??e.enabled)&&e.available),[g,v]),A=a(()=>k.map(e=>({id:e.key,name:na(e).label,weight:s===void 0?v[e.key]?.weight??e.weight:Math.round(s[e.key]??0)})),[k,v,s]);return i(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[i(`button`,{type:`button`,onClick:()=>S(!w),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":w,children:[d(C,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${w?`rotate-90`:``}`}),d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),d(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:_?b>=2?i(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[d(Ht,{className:`h-3.5 w-3.5`}),b,` accelerators`]}):b===1?d(`span`,{className:`text-foreground-subtle`,children:`single default`}):d(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):i(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[d(Pt,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),w&&i(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[_?m&&g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):d(`ul`,{className:`space-y-2`,children:g.map(e=>{let t=na(e),n=v[e.key]??E(e),a=n.enabled&&e.available,s=ta({defaultModelId:e.defaultModelId,steps:n.steps});return i(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[d(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${ra[t.hue]}`,children:d(t.Icon,{className:`h-4.5 w-4.5`})}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),d(K,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&d(K,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`font-mono`,children:e.key}),s!==null&&i(o,{children:[d(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:[`root model`,` `,d(`span`,{className:`font-mono text-foreground/80`,children:s})]})]})]})]}),a&&i(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),d(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);O(e,r!=null&&r>0?r:null)},disabled:h.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),a&&d(aa,{suggested:r?.[e.key]??null,current:n.maxSessions,pending:h.isPending,onApply:t=>O(e,t)}),d(pt,{checked:a,onCheckedChange:()=>D(e),disabled:!e.available||h.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):d(oa,{}),_&&k.length>=2&&i(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[i(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[d(kn,{className:`h-3.5 w-3.5`}),`Accelerator share`]}),d(ea,{nodes:A,pending:h.isPending,onCommitWeights:e=>{let t={...v};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}y(t),T(t)},weightLabel:`Accelerator share`,readOnly:s!==void 0,footnote:s===void 0?d(o,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`}):d(o,{children:`Automatic: each accelerator's share follows its measured throughput at its model. Switch the node shares to manual to set them yourself.`})})]}),h.isError&&i(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,h.error instanceof Error?h.error.message:`unknown error`]})]})]})}function aa({suggested:e,current:t,pending:n,onApply:r}){return e===null||e<1||e===t?null:i(z,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`,children:[`use `,e]})}function oa(){return i(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[d(Pt,{className:`h-6 w-6 text-foreground-subtle/60`}),d(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),d(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}r();var sa=3600*1e3,ca=2e4,la=.4;function ua({refreshToken:e,onOpenAutoTune:t}){let n=c(),{nodes:r}=G(),s=Ve(void 0),f=At({isCamera:!0,projection:`slim`}),p=le({windowMs:sa},{refetchInterval:ca,placeholderData:l}).data,h=_e(void 0,{refetchInterval:ca,placeholderData:l}).data,g=()=>{yn(n),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},v=vt({onSuccess:g}),y=Xe({onSuccess:()=>{g(),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),b=Ee({onSuccess:g}),x=ge(),[S,C]=u(!1),w=h?.source,T=w===`benchmark`?`benchmark`:`hardware`,E=ft({headroom:la,source:T},{enabled:S,staleTime:1/0}),D=E.data,O=a(()=>{let e=new Map((s.data??[]).map(e=>[e.nodeId,e.settings]));return r.filter(t=>zn(e.get(t.id),t.isHub).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:hn(n,`detectWeight`)??1,maxCameras:hn(n,`maxCameras`)}})},[r,s.data]),k=e=>r.find(t=>t.id===e)?.name??e,j=Qn((f.data??[]).map(e=>({id:e.id,name:e.name}))),M=D?Ui(D):void 0,N=Gi(O,h),P=w!==`manual`,ee=e=>{if(h===void 0||h.source===`manual`||h.autoPending)return;let t=h.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},F=h?Ki(h,k):null,I=h?Yi(h,k):null,L=qi.find(e=>e.value===w)?.hint;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(fn,{nodeId:`hub`,addonIds:[Cn],level:`global`,sectionIds:[`load`],title:`Placement policy`,description:`How a new detection session picks its node and device, and what happens when a node falls behind. 'Honour shares' (default) holds the shares below for PARALLEL sessions.`}),d(Wn,{refreshToken:e}),d(Li,{stats:p,...h!==void 0&&h.source!==`manual`&&!h.autoPending?{targetWeights:Object.fromEntries(h.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),d(U,{headingId:`load-balancing-node-shares`,title:`Node shares`,icon:kn,actions:i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{role:`radiogroup`,"aria-label":`Share source`,className:`flex items-center gap-1`,children:qi.map(e=>d(z,{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))}),i(z,{variant:`outline`,size:`sm`,onClick:()=>{C(!0),S&&E.refetch()},disabled:E.isFetching,children:[d(ct,{className:`h-3.5 w-3.5`}),E.isFetching?`Suggesting…`:T===`benchmark`?`Suggest from benchmark`:`Suggest from hardware`]}),i(z,{variant:`ghost`,size:`sm`,onClick:t,children:[d(Oe,{className:`h-3.5 w-3.5`}),`Auto tune`]}),i(z,{variant:`outline`,size:`sm`,onClick:()=>x.mutate(void 0),disabled:x.isPending,title:`Move standing (always-on) cameras that are no longer on their best node. Pinned cameras never move; on-motion sessions are placed per session anyway.`,children:[d(Ct,{className:`h-3.5 w-3.5`}),x.isPending?`Rebalancing…`:`Rebalance`]})]}),children:i(`div`,{className:`${m} space-y-3`,children:[L!==void 0&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:L}),p&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Policy:`,` `,d(K,{variant:p.policy===`share`?`info`:`default`,children:p.policy===`share`?`honour shares`:`least-loaded`}),` `,`· cluster peak `,p.clusterPeakSessions,` parallel sessions in the last hour`,p.policy===`least-loaded`&&` · under least-loaded an idle node always wins, so shares only bite once nodes are busy`]}),d(ea,{nodes:N.nodes,pending:v.isPending,readOnly:N.readOnly,onCommitWeights:e=>v.mutate(Vi(e)),weightLabel:`Node share`,...N.readOnly?{footnote:h?.autoPending?d(o,{children:`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`}):i(o,{children:[w===`benchmark`?`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`:`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`,h?.computedAt==null?``:` — last at ${new Date(h.computedAt).toLocaleTimeString()}${h.trigger===null?``:` (${h.trigger})`}`,`.`]})}:{}}),F!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:F}),I!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:I}),y.isError&&d(B,{message:`Failed to switch shares: ${y.error instanceof Error?y.error.message:`unknown error`}`}),v.isError&&d(B,{message:`Failed to save shares: ${v.error instanceof Error?v.error.message:`unknown error`}`}),i(`details`,{className:`rounded-md border border-border`,children:[d(`summary`,{className:`${_} cursor-pointer text-xs text-foreground`,children:`Max concurrent sessions (advanced)`}),d(`ul`,{className:`divide-y divide-border border-t border-border`,children:O.map(e=>i(`li`,{className:`${_} flex items-center gap-2`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),d(Te,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":`Max concurrent sessions for ${e.name}`,className:`w-20 text-right`,disabled:b.isPending,onBlur:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==e.maxCameras&&b.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),d(`p`,{className:`${_} ${A} border-t border-border`,children:`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`})]})]})}),E.isError&&d(B,{message:`Suggestion failed: ${E.error instanceof Error?E.error.message:`unknown error`}`}),D&&d(da,{suggestion:D,nameOf:k,pending:v.isPending,...P?{}:{onApply:()=>v.mutate(Hi(D))}}),d(U,{headingId:`load-balancing-accelerators`,title:`Accelerators`,icon:V,children:d(`div`,{className:`${m} space-y-2`,children:O.length===0?d(Le,{title:`No detect-capable nodes`,description:`Enable detection on a node in Roles & nodes to configure its accelerators.`}):O.map(e=>d(ia,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...M?.[e.id]===void 0?{}:{suggestedMaxSessions:M[e.id]},...ee(e.id)===void 0?{}:{autoDeviceShares:ee(e.id)}},e.id))})}),p!==void 0&&p.stalePins.length>0&&d(fa,{stats:p,cameraName:j})]})}function da({suggestion:e,nameOf:t,pending:n,onApply:r}){return i(U,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?`Suggested from benchmark`:`Suggested from hardware`,icon:ct,...r===void 0?{}:{actions:d(z,{size:`sm`,onClick:r,disabled:n,children:`Apply suggested shares`})},children:[d(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>i(`li`,{className:`${_} space-y-0.5`,children:[i(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),d(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?`skipped`:`${e.share}%`})]}),i(`p`,{className:A,children:[Ji(e.capacityFallback)===null?``:`${Ji(e.capacityFallback)} · `,e.skippedReason===null?`≈ ${e.capacitySessions} parallel sessions · ${e.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}`:`not part of the suggestion — ${e.skippedReason}`]})]},e.nodeId))}),i(`p`,{className:`${_} ${A} border-t border-border`,children:[`Shares in proportion to each node's capacity in parallel sessions —`,` `,e.source===`benchmark`?`measured by node benchmarks, or from the hardware table where a node has no results`:`at the models Auto tune picks (at least ${e.minSessionsPerDevice} per accelerator), from the measured speed of each node's hardware`,`, counted in `,e.cameraFps,` fps sessions with`,` `,Math.round(e.headroom*100),`% kept free. No load is measured or estimated.`,r===void 0?`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`:`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`]})]})}function fa({stats:e,cameraName:t}){let n=c(),r=Et({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return d(U,{headingId:`load-balancing-stale-pins`,title:`Stale device pins`,icon:On,children:d(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>i(`li`,{className:`${_} flex items-center gap-2`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[d(`p`,{className:`truncate text-xs text-foreground`,title:t(e.deviceId),children:t(e.deviceId)}),d(`p`,{className:A,children:Wi(e)})]}),d(z,{variant:`outline`,size:`sm`,disabled:r.isPending,onClick:()=>r.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:`Clear pin`})]},e.deviceId))})})}function pa({node:e,emphasis:t=!1}){let n=e.isHub?qe:V;return i(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),i(`div`,{className:`min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(K,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(K,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}function ma({nodes:e,actions:t}){return d(ue,{columns:[{key:`node`,header:`Node`,sortValue:e=>e.name,render:e=>d(pa,{node:e})},...bn.map(e=>({key:e.key,header:e.label,align:`center`,notSortableReason:`A switch — sorting would move the row while it is being changed.`,render:n=>d(pt,{"aria-label":`${e.label} on ${n.name}`,title:e.hint,checked:mn(n.effective,e.key),disabled:t.capabilityPending,onCheckedChange:r=>t.onToggleCapability(n.id,e.key,r)})}))],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,mobileMode:`scroll`,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:`No cluster nodes reporting yet.`})}function ha({roleValues:e,options:t,pending:n,onRoleChange:r}){let a=t.map(e=>({value:e.id,label:e.id===`hub`?`${e.name} (default)`:e.name}));return d(`ul`,{className:`divide-y divide-border`,children:wn.map(t=>i(`li`,{className:`${_} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[i(`div`,{className:`min-w-0 flex-1 basis-56`,children:[d(`div`,{className:`text-xs font-medium text-foreground`,children:gn(t)}),d(`p`,{className:A,children:_n(t)})]}),d(`div`,{className:`w-full sm:w-48`,children:d(W,{"aria-label":`${gn(t)} node`,value:e[t],disabled:n,options:a,onChange:e=>r(t,e.target.value)})})]},t))})}r();function ga(){let e=c(),{nodes:t}=G(),n=Ve(void 0),r=zt({addonId:Cn}),o=zt({addonId:pn}),s=zt({addonId:Tn}),l=()=>yn(e),u=He({onSuccess:l}),f=Ae({onSuccess:l}),p=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),m=a(()=>t.map(e=>{let t=p.get(e.id),n=zn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[t,p]),h={ingestNode:Sn(r.data,`ingestNode`,`hub`),recordingNode:Sn(o.data,xn,`hub`),audioNode:Sn(r.data,`audioNode`,`hub`),motionNode:Sn(r.data,`motionNode`,`hub`),postProcessingNode:Sn(s.data,vn,`hub`)},g=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id),n=e=>t.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,...wn.map(e=>h[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:n(e)}))},[t,h]),_=n.isLoading||r.isLoading||o.isLoading||s.isLoading,v=(e,t,n)=>{u.mutate({agentNodeId:e,[t]:n})},y=(e,t)=>{if(e===`recordingNode`){f.mutate({addonId:pn,patch:{[xn]:t}});return}if(e===`postProcessingNode`){f.mutate({addonId:Tn,patch:{[vn]:t}});return}f.mutate({addonId:Cn,patch:{[e]:t}})},b={capabilityPending:u.isPending,onToggleCapability:v};return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(U,{headingId:`roles-nodes-cluster-roles`,title:`Cluster roles`,icon:Dn,actions:_?d(ne,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":`Loading`}):null,children:[d(`p`,{className:`${A} border-b border-border px-3 py-1.5 sm:px-4`,children:`One node holds each role for every camera. Detection shares and caps are on Load balancing.`}),d(ha,{roleValues:h,options:g,pending:f.isPending,onRoleChange:y})]}),d(U,{headingId:`roles-nodes-node-capabilities`,title:`Node capabilities`,icon:qe,children:d(ma,{nodes:m,actions:b})})]})}var _a=`pipeline-analytics`,va=`face-gallery`,ya=`pipeline-orchestrator`,ba=`pipeline-runner`,xa=`audio-analyzer`;function Sa(e){return[...Yt.filter(t=>t.stepId===e).map(e=>Gt(e.stepId)),...Kt.filter(t=>t.stepId===e).map(e=>$t(e.stepId,e.key))]}var Ca=`faces`,wa=`semantic-search`,Ta=[{id:Ca,title:`Faces & recognition`,hint:`The face encoder for every node, the smallest faces worth embedding, keeping and auto-assigning, and how a face is matched to a person.`,panels:[{addonId:ya,fieldKeys:Sa(`face-embedding`)},{addonId:_a,capability:va}]},{id:wa,title:`Semantic search`,hint:`The image encoder behind "search by description". One for the whole cluster: changing it hides existing results until the index is rebuilt.`,panels:[{addonId:ya,fieldKeys:Sa(`clip-embedding`)}]},{id:en,title:`Enrichment crop`,hint:`How the crop handed to face, plate and search models is cut from the frame.`,panels:[{addonId:ya,sectionIds:[en]}]},{id:Xt,title:`Full-resolution crops`,hint:`How long each camera keeps full-resolution pixels so a late crop (snapshot, face, plate) is sharp instead of cut from the small detection frame.`,panels:[{addonId:ya,sectionIds:[Xt]}]},{id:`runner-defaults`,title:`Runner defaults`,hint:`Values every node's detection runner and audio analyzer use. A node's own decode limits (Engine & decoder) take precedence.`,panels:[{addonId:ba,fieldScope:`cluster`},{addonId:xa,fieldScope:`cluster`}]},{id:`failover`,title:`Failover`,hint:`What happens to cameras when a node disconnects and comes back.`,panels:[{addonId:ya,sectionIds:[`failover`]}]}],Ea={"cluster-step-models":Ca};function Da(e){return e===`clip-embedding`?wa:Ca}r();var Oa=2500,ka={faces:tt,"semantic-search":Oe,"detail-crop":Vt,"native-lease":Ht,"runner-defaults":V,failover:he};function Aa(e){f(()=>{if(e===null)return;let t=Ea[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`),Oa),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function ja({section:e}){return d(`div`,{"data-cluster-settings-card":e.id,className:`rounded-lg`,children:d(U,{headingId:`cluster-settings-${e.id}`,title:e.title,...ka[e.id]===void 0?{}:{icon:ka[e.id]},children:i(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:A,children:e.hint}),e.panels.map(e=>d(fn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:[`cluster`,`load`],emptyMessage:`Not available — the addon that owns these settings did not answer.`,...e.capability===void 0?{}:{capability:e.capability},...e.sectionIds===void 0?{}:{sectionIds:e.sectionIds},...e.fieldKeys===void 0?{}:{fieldKeys:e.fieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function Ma({refreshToken:e}){let[t]=sn();return Aa(t.get(Po)),d(`div`,{className:`space-y-3 sm:space-y-4`,children:Ta.map(e=>d(ja,{section:e},e.id))})}var Na=`pipeline-orchestrator`,Pa=200;function Fa(){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(Ie,{addonId:Na,limit:Pa,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}var Ia=[{id:`assignments`,label:`Assignments`},{id:`load-balancing`,label:`Load balancing`},{id:`auto-tune`,label:`Auto tune`},{id:`roles-nodes`,label:`Roles`},{id:`settings`,label:`Settings`},{id:`logs`,label:`Logs`}];function La(e){return Ia.some(t=>t.id===e)}function Ra({refreshToken:e}){let[t,n]=sn(),r=t.get(No),a=La(r)?r:`assignments`,o=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(No,e),n.delete(Po),n},{replace:!0})};return i(`div`,{className:`flex flex-col h-full`,children:[i(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Ia.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[a===`assignments`&&d(ui,{}),a===`load-balancing`&&d(ua,{refreshToken:e,onOpenAutoTune:()=>o(`auto-tune`)}),a===`auto-tune`&&d(ki,{}),a===`roles-nodes`&&d(ga,{}),a===`settings`&&d(Ma,{refreshToken:e}),a===`logs`&&d(Fa,{})]})]})}var za=`armed:`;function Ba(e){return e.assignment.reasons.detection?.startsWith(za)===!0}function Va(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Ba(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Ha(e){let t=[],n=[],{assignment:r,detection:i,broker:a}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),r.detectionNodeId===null&&i===null&&!Ba(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let o=e.degraded??[];if(o.length>0){let e=[...new Set(o.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}n.push(...Ga(e.cameraSensors));for(let e of a?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Ua(e){return e.state===`unreadable`&&qt.state===`unreadable`&&e.reason===qt.reason}function Wa(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is missing`};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) is ${e.reason}`};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) cannot drive motion: ${e.reason}`};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is unreadable: ${e.reason}`}}}function Ga(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return Ua(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:`Camera sensors unreadable: ${e.reason}`}];let t=e.sensors.flatMap(e=>{let t=Wa(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[Ka(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:`Confirm / Replace cannot suppress this camera's own motion until its provider is updated`},...n]}function Ka(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?`Camera sensors are attached but never fire: add "Camera sensors" (onboard) to this camera's motion sources`:`Camera sensors are attached but never fire: this camera has no active detection`}}function qa(e){return e===void 0?`status unavailable from this node`:e.state===`not-configured`?`none attached`:e.state===`unreadable`?`unknown — ${e.reason}`:e.sensors.map(Ya).join(`, `)}function Ja(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function Ya(e){return`${Xa(e)}${Ja(e)}`}function Xa(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return`${e.name} (#${e.deviceId}) — unsupported`;case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function Za(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Qa(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function $a(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function eo(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var to={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function no(e){if(!Za(e)||!Array.isArray(e.sections))return to;let t=Zt(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)eo(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Qa(n(`detectionFps`)),motionSources:$a(n(`motionSources`)),motionFps:Qa(n(`motionFps`)),motionCooldownMs:Qa(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function ro(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...ro(r.children,t+1));return n}function X({title:e,children:t}){return i(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return i(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(io,{})]})}function io(){return d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var ao={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return d(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${ao[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function oo({icon:e,label:t,nodeId:n,pinned:r,reason:a,overridden:s}){return i(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):i(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?i(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(xt,{className:`h-2.5 w-2.5`}),` manual`]}):i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function so({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return i(X,{title:`Where it runs`,children:[d(oo,{icon:V,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(oo,{icon:ce,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(oo,{icon:S,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(oo,{icon:yt,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:i(`select`,{value:o,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>i(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function co(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function lo(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function uo(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function fo({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:a,cameraSensors:s}){let c=lo(t,n.detectionStreamProfile),l=lo(t,n.motionStreamProfile),u=n.motionSources.includes(`analyzer`);return i(X,{title:`Streams & motion`,children:[i(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:uo(n.detectionFps)}),i(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map(nn).join(` + `):`none`,r===!1&&` · inactive`]}),d(Z,{label:`Camera sensors`,children:qa(s)}),u&&i(o,{children:[i(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),i(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[uo(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>i(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,co(e)]},e.camStreamId))})]})}function po({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return i(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:i(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&i(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:i(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var mo={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function ho({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return i(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:r,children:n??`—`}),d($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=ye(a),f=a===`active`&&o===0;return i(X,{title:`Detection runtime`,children:[i(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[i(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(ie,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:r,children:n??`—`}),i(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),i(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&i(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&i(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),i(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),i(Z,{label:`Provisioning`,children:[d(Q,{tone:mo[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&i(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function go({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):i(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return i(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),i(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),i(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps===null?`—`:e.inFps.toFixed(0),`fps`]}),i(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),i(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[i(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),i(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function _o({decoder:e}){return e===null?d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})}):d(X,{title:`Decoder`,children:d(Z,{label:`Node`,children:e.nodeId})})}r();var vo=`pipeline-orchestrator`,yo={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},bo={healthy:`Healthy`,idle:`Idle`,error:`Error`};function xo({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>i(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[d(dt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function So({deviceId:e,name:t,online:n,status:r,live:o,onlineNodes:s}){let l=c(),{data:u}=Mt({addonId:vo,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=We({deviceId:e},{staleTime:3e4}),p=a(()=>no(u),[u]),m=a(()=>f===void 0?void 0:ro(f.steps),[f]),h=a(()=>r===void 0?[]:Ha(r),[r]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=L({onSuccess:g}),v=$e({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=r===void 0?`idle`:Va(r),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return i(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[i(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:yo[b]}`,title:x?`Error`:bo[b],"aria-label":x?`Error`:bo[b],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),i(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),r?.recording!=null&&(r.recording.active?i(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&i(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),h.length>0&&d(xo,{problems:h}),r===void 0?d(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):i(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(so,{assignment:r.assignment,settings:p,onlineNodes:s,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),d(ho,{detection:r.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(po,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:r.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(fo,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:p,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null,cameraSensors:r.cameraSensors}),d(go,{broker:r.broker}),d(_o,{decoder:r.decoder})]})]})}r();var Co=5e3,wo=1e4,To=5e3;function Eo(e){let t=c(),{data:n,isLoading:r}=cn(),{data:i,isLoading:o}=xe({},{refetchInterval:Co}),{nodes:s}=G();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);et(rn.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-wo,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},To);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}r();function Do({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:o}=Eo(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:Ha(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:i(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[i(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[i(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),i(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),i(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(So,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}var Oo=e({CLUSTER_NODE_ID:()=>ko,PipelinePage:()=>Mo});r();var ko=`__cluster__`;function Ao(e){return e===`cameras`?`cameras`:`nodes`}function jo({viewMode:e,onNodes:t,onCameras:n}){return i(`div`,{className:`flex items-center gap-1 rounded-lg border border-border bg-surface p-0.5`,role:`tablist`,"aria-label":`Pipeline view`,children:[d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`nodes`,onClick:t,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`cameras`,onClick:n,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]})}function Mo(){let[e,t]=sn(),n=Ao(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:ko},{replace:!0})},[n,e,t]),i(se,{icon:un,title:`Pipeline`,subtitle:`Detection placement, load and per-camera runtime across the cluster.`,actions:i(z,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s(e=>e+1),title:`Refresh`,children:[d(Je,{className:`h-3.5 w-3.5`}),`Refresh`]}),nav:d(jo,{viewMode:n,onNodes:()=>{t({view:`nodes`,node:r},{replace:!0})},onCameras:()=>{t({view:`cameras`},{replace:!0})}}),className:`flex h-full min-h-0 flex-col overflow-hidden`,children:[n===`nodes`&&i(z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>l(e=>!e),"aria-expanded":c,className:`flex w-full shrink-0 justify-between border-b border-border md:hidden`,children:[i(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(y,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden md:flex-row`,children:n===`nodes`?i(o,{children:[d(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b border-border md:border-b-0 md:border-r`,`max-h-[60vh] overflow-y-auto md:max-h-none`].join(` `),children:d(Vn,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:r===`__cluster__`?d(Ra,{refreshToken:a}):d(li,{nodeId:r,refreshToken:a})})]}):d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:d(Do,{refreshToken:a})})})]})}var No=`ctab`,Po=`section`;function Fo(e,t){let n=new URLSearchParams({view:`nodes`,node:ko,[No]:e});return t!==void 0&&n.set(Po,t),`/system/pipeline?${n.toString()}`}function Io(e){return Fo(`settings`,Da(e))}function Lo(){return Fo(`load-balancing`)}var Ro=`pipeline-orchestrator`;function zo(e){return Yt.find(t=>t.stepId===e)??null}function Bo({step:e,engineFormat:t,runnableModelIds:n}){let{data:r}=zt({addonId:Ro}),a=Ut(r??null)[e.stepId]??e.defaultModelId,o=e.options.find(e=>e.id===a)?.label??a,s=n.length>0&&!n.includes(a);return i(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:o}),d(`span`,{title:`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`}),d(ln,{to:Io(e.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Change in Cluster → Settings ›`})]}),i(`p`,{className:A,children:[`One model for every node and camera: `,e.indexName,` only matches vectors from the model that made them.`]}),s&&i(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:[`This accelerator's engine (`,t,`) ships no build of `,d(`b`,{children:a}),`. It refuses this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`.`]})]})}export{jr as _,Yr as a,Pr as c,Br as d,Hr as f,Mr as g,Vr as h,Xr as i,Kr as l,zr as m,zo as n,Rr as o,Gr as p,Oo as r,Ur as s,Bo as t,Wr as u,Or as v,Mn as y};
|