@camstack/addon-admin-ui 1.2.180 → 1.2.182
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/{AddonCollectionPage-YWSS97Ay.js → AddonCollectionPage-ClRQxGHN.js} +1 -1
- package/dist/assets/{Addons-BZtKYLdQ.js → Addons-Bv7_AT7a.js} +1 -1
- package/dist/assets/{AdminTabs-CvzQqvQ2.js → AdminTabs-CFFk8Gq2.js} +1 -1
- package/dist/assets/{AiProfiles-DPIY6pXE.js → AiProfiles-BkVvZjBt.js} +1 -1
- package/dist/assets/{BrokerForm-CSWSM5E3.js → BrokerForm-CnbMKye3.js} +1 -1
- package/dist/assets/{Build-B5e3d9OE.js → Build-LHUANBaC.js} +4 -4
- package/dist/assets/{Capabilities-BhX7H7A3.js → Capabilities-CQyVFXwc.js} +1 -1
- package/dist/assets/{CapabilityBadges-C6J6DUiF.js → CapabilityBadges-BVl3DqAY.js} +1 -1
- package/dist/assets/{Cluster-D4vC3LDb.js → Cluster-BVyTdAw9.js} +1 -1
- package/dist/assets/{Data-AWkktSkO.js → Data-IQvWpvwm.js} +1 -1
- package/dist/assets/{DetectionIntelligence-BulJ1PR6.js → DetectionIntelligence-DYxoWljf.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-CxK7LKD7.js → DeviceAggregateSection-BkJvTv6R.js} +1 -1
- package/dist/assets/{DeviceDetail-CvD1gXWg.js → DeviceDetail-B4CDw_uE.js} +2 -2
- package/dist/assets/{Devices-BrnhG2yA.js → Devices-Da6lCmM1.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Bx_3MKA_.js → EmbedPlayerPage-BrlPmwQN.js} +1 -1
- package/dist/assets/Events-XqdJMMnc.js +1 -0
- package/dist/assets/{FormBuilder-CeJriJnB.js → FormBuilder-BHMEtnu5.js} +1 -1
- package/dist/assets/{Identity-CbcWeh3q.js → Identity-BML0YvY7.js} +1 -1
- package/dist/assets/{IntegrationDetail-BucwfXdG.js → IntegrationDetail-D98ibjds.js} +1 -1
- package/dist/assets/{Integrations-CMytenco.js → Integrations-CBGusDGc.js} +1 -1
- package/dist/assets/{Integrations-CRQESrDA.js → Integrations-jy5wlUOd.js} +1 -1
- package/dist/assets/{Locations-C8gFThSR.js → Locations-B5NgeJWC.js} +1 -1
- package/dist/assets/{Logs-CWjWt9q0.js → Logs-DCvmzvJM.js} +1 -1
- package/dist/assets/{MotionZonesSettings-D8VKOXWT.js → MotionZonesSettings-DqnH_Gs6.js} +1 -1
- package/dist/assets/{MyAccess-3MVtgu4Y.js → MyAccess-BDptJLtf.js} +1 -1
- package/dist/assets/{Network-CH_-1dg3.js → Network-CYtzk3zV.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-CAgPuUXP.js → NodeAddonsSettingsPanel-BGgUY4XE.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-DwKyjZtD.js → NodeInferenceDevices-D3A4x8bv.js} +1 -1
- package/dist/assets/Notifications-BEmMmODG.js +1 -0
- package/dist/assets/{Pipeline-uUq4eaJx.js → Pipeline-CG87k4Oa.js} +1 -1
- package/dist/assets/{Plates-Cvn0qzNl.js → Plates-BTLd8fUg.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DJOVa6ie.js → PrivacyMaskSettings-CbfH0ERf.js} +1 -1
- package/dist/assets/{ProviderIcon-BtV-sntq.js → ProviderIcon-O8r_QNGL.js} +1 -1
- package/dist/assets/{Recordings-Dm93cVox.js → Recordings-d0qBQcso.js} +1 -1
- package/dist/assets/{ScanNetworkModal-DERxYp4p.js → ScanNetworkModal-CtmBxzX9.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-Nj4V9mEW.js → SceneMonitorEditor-BT0zgTYN.js} +1 -1
- package/dist/assets/{Scenes-DrYeEAQr.js → Scenes-NHLxYc_S.js} +1 -1
- package/dist/assets/{Settings-D69aa5g2.js → Settings-CK6wx_0Y.js} +1 -1
- package/dist/assets/{Showroom-MQJ0VJvL.js → Showroom-BKUzFfAO.js} +1 -1
- package/dist/assets/{StorageLocationsPanel-DMMtPiIw.js → StorageLocationsPanel-69SpAdoc.js} +1 -1
- package/dist/assets/{Terminal-D2__NuTD.js → Terminal-CZexyI6Z.js} +1 -1
- package/dist/assets/{Viewer-D3jGCzRF.js → Viewer-APDxxm2p.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BAkTiR-X.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-VrbJl3Qd.js} +1 -1
- package/dist/assets/{authed-media-D1kJQtIT.js → authed-media-Cg9pZxod.js} +1 -1
- package/dist/assets/{bell-off-CMQECrEv.js → bell-off-DVh1wvB6.js} +1 -1
- package/dist/assets/{bell-ring-DeD2zNEz.js → bell-ring-C6dXgglD.js} +1 -1
- package/dist/assets/{boxes-BOblQ-ls.js → boxes-B2bGIv3Y.js} +1 -1
- package/dist/assets/circle-check-big-D7yIDwoW.js +1 -0
- package/dist/assets/circle-dot-C3ZiQ9_N.js +1 -0
- package/dist/assets/circle-slash-BLDy7CCl.js +1 -0
- package/dist/assets/{circle-x-C_rGRhdN.js → circle-x-DVtn0byc.js} +1 -1
- package/dist/assets/clock-Cps8N7BK.js +1 -0
- package/dist/assets/{copy-BZuCtI3O.js → copy-BCOqkIux.js} +1 -1
- package/dist/assets/{debounced-invalidate-BgiZ3c7w.js → debounced-invalidate-DbvO3iHu.js} +1 -1
- package/dist/assets/dist--2HmeXG6.js +349 -0
- package/dist/assets/{dist-Cjqh0Wan.js → dist-Cq7gfGRn.js} +1 -1
- package/dist/assets/{download-C6xLIiU_.js → download-Dt_BbY-T.js} +1 -1
- package/dist/assets/{face-bbox-X2c2pZhf.js → face-bbox-wpEQBKoF.js} +1 -1
- package/dist/assets/{flame-BhIbsH2x.js → flame-DB_pOs8X.js} +1 -1
- package/dist/assets/{format-size-k04xOT1z.js → format-size-BB-Sd9ut.js} +1 -1
- package/dist/assets/{hard-drive-rdkKraiy.js → hard-drive-BWmfHlkd.js} +1 -1
- package/dist/assets/{hostInit-I7x5oehb.js → hostInit-DoXLTGfC.js} +1 -1
- package/dist/assets/{index-C8HFXQxE.js → index-BCxSnXqL.js} +3 -3
- package/dist/assets/{key-round-COOgqcTh.js → key-round-BqkosmYw.js} +1 -1
- package/dist/assets/{layers-lue4_9YZ.js → layers-Lhlv5z1U.js} +1 -1
- package/dist/assets/{location-owned-usage-DVWSFdep.js → location-owned-usage-D1xSRh8g.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-79ff0e6c.js → mf-entry-bootstrap-0-f8898cd2.js} +2 -2
- package/dist/assets/{pencil-5Cn86bl9.js → pencil-M7v7qavP.js} +1 -1
- package/dist/assets/play-CpJXJ88m.js +1 -0
- package/dist/assets/{player-overlays-CoerrptV.js → player-overlays-DbFWkG_Z.js} +1 -1
- package/dist/assets/plus-Cpe6mmKM.js +1 -0
- package/dist/assets/power-uas7CntH.js +1 -0
- package/dist/assets/{radio-CU9ZnR4Z.js → radio-CV4hi-g1.js} +1 -1
- package/dist/assets/{refresh-cw-B-P_o53G.js → refresh-cw-Deiyupek.js} +1 -1
- package/dist/assets/remoteEntry-I8A6vOgw.js +1 -0
- package/dist/assets/rotate-ccw-BftMdgSU.js +1 -0
- package/dist/assets/rotate-cw-BObSYKb8.js +1 -0
- package/dist/assets/{send-XDAKixAc.js → send-Clr6PN4I.js} +1 -1
- package/dist/assets/{server-C427hfGt.js → server-BE9Zw1mn.js} +1 -1
- package/dist/assets/{shield-BWCmH1kT.js → shield-CZC9yz_v.js} +1 -1
- package/dist/assets/{shield-alert-DTXVS-Ta.js → shield-alert-Ca4rdJui.js} +1 -1
- package/dist/assets/square-DSQ5ASQ3.js +1 -0
- package/dist/assets/{square-check-big-BCxzVNZx.js → square-check-big-DMuUREuL.js} +1 -1
- package/dist/assets/src-CHoZc4cE.js +349 -0
- package/dist/assets/src-CTrNqyF8.js +67 -0
- package/dist/assets/{undo-2-B3te1nYu.js → undo-2-uDFd438J.js} +1 -1
- package/dist/assets/{use-scenes-feed-C4_7pwbO.js → use-scenes-feed-CWs5G4Fz.js} +1 -1
- package/dist/assets/useEventInvalidation-C9rmpIc-.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BYezMUac.js → useNodeUrlSelection-C-RIZqAN.js} +1 -1
- package/dist/assets/user-round-CIt8A80d.js +1 -0
- package/dist/assets/{video-B3YII17O.js → video-DiXIeNMQ.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BSnk8W8e.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-8goUeGfT.js} +2 -2
- package/dist/assets/{wifi-UK98YB3i.js → wifi-DvjdHQli.js} +1 -1
- package/dist/assets/{zap-Dzo7ItBz.js → zap-BoQkEUB5.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +219 -6
- package/package.json +1 -1
- package/dist/assets/Events-D7Mv3ryu.js +0 -1
- package/dist/assets/Notifications-C89fuBIK.js +0 -1
- package/dist/assets/circle-check-big-gFn2KRua.js +0 -1
- package/dist/assets/circle-dot-DkhFtw9d.js +0 -1
- package/dist/assets/circle-slash-Cxgp0h3p.js +0 -1
- package/dist/assets/clock-Cd5wZEYk.js +0 -1
- package/dist/assets/dist-BPfNrxiG.js +0 -349
- package/dist/assets/play-DfalhZZ_.js +0 -1
- package/dist/assets/plus-CcspwfVs.js +0 -1
- package/dist/assets/power-DyRoEcfz.js +0 -1
- package/dist/assets/remoteEntry-DeAlYwDc.js +0 -1
- package/dist/assets/rotate-ccw-DAf8VwGq.js +0 -1
- package/dist/assets/rotate-cw-C91Jaxpm.js +0 -1
- package/dist/assets/square-bC5Wc9VY.js +0 -1
- package/dist/assets/src-71h6VhtY.js +0 -349
- package/dist/assets/src-jkGuV7J0.js +0 -67
- package/dist/assets/useEventInvalidation-rcKOAt1n.js +0 -1
- package/dist/assets/user-round-DxDGNxWB.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{K as e,Q as t,S as n,T as r,W as i,b as a,i as o,o as s,p as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as f}from"./player-overlays-CoerrptV.js";import{$s as p,Ba as m,Bt as h,Ft as g,H as _,Ha as v,Ia as y,Ka as b,La as x,Lt as S,Qa as C,Qs as w,Ra as T,Rt as E,Sn as D,Ua as O,Va as k,Vt as A,Wa as j,Y as M,Ya as N,Za as P,_o as F,ao as I,b as L,bo as R,co as ee,d as te,ec as z,eo as B,go as ne,h as re,ho as ie,io as ae,lo as oe,nc as se,no as ce,oo as le,qt as ue,r as de,rc as fe,sn as pe,so as me,tc as he,to as ge,tt as _e,u as ve,uo as ye,vn as be,vo as xe,yn as Se,za as Ce,zt as we}from"./src-jkGuV7J0.js";import{n as Te}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{Gt as Ee,Kt as De,f as Oe,h as ke,p as Ae}from"./src-71h6VhtY.js";import{a as je,i as Me,l as Ne,n as V,o as Pe,r as Fe,t as Ie,u as Le}from"./NodeInferenceDevices-DwKyjZtD.js";import{t as Re}from"./flame-BhIbsH2x.js";import{t as ze}from"./layers-lue4_9YZ.js";import{n as Be,t as Ve}from"./video-B3YII17O.js";import{t as He}from"./pencil-5Cn86bl9.js";import{t as Ue}from"./plus-CcspwfVs.js";import{t as We}from"./radio-CU9ZnR4Z.js";import{t as Ge}from"./refresh-cw-B-P_o53G.js";import{t as Ke}from"./server-C427hfGt.js";import{t as qe}from"./square-check-big-BCxzVNZx.js";import{t as Je}from"./square-bC5Wc9VY.js";import{t as Ye}from"./zap-Dzo7ItBz.js";import{B as H,D as Xe,I as Ze,J as Qe,L as $e,O as et,P as U,Q as tt,a as nt,i as rt,k as it,o as at,r as ot,w as st,z as ct}from"./index-C8HFXQxE.js";import"./useEventInvalidation-rcKOAt1n.js";import{t as lt}from"./NodeAddonsSettingsPanel-CAgPuUXP.js";import{t as ut}from"./StorageLocationsPanel-DMMtPiIw.js";var dt=Qe(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ft=Qe(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);t();function pt(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 mt(e){return e}function ht(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function gt(e,t){return typeof e==`boolean`?e:mt(t)}function _t(e,t){return{pipeline:gt(ht(e,`detect`),t),audio:gt(ht(e,`audio`),t),ingest:gt(ht(e,`ingest`),t)}}function vt(e,t,n){let r=e?.find(e=>e.nodeId===t);return _t(r?.settings,n)}function yt({selectedNodeId:e,onSelect:t,refreshToken:r}){let{nodes:i}=p(),{data:o}=P(void 0),{data:s}=B(void 0),c=new Map;for(let e of o??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],d=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return n(`div`,{className:`flex flex-col h-full`,children:[n(`button`,{type:`button`,onClick:()=>t(Ur),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[u(Xe,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[u(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(r=>{let i=e===r.id,o=c.get(r.id)??0,l=r.isHub?Ke:U,d=vt(s,r.id,r.isHub),f=r.isOnline?null:_(pt(r.lastSeen));return n(`button`,{type:`button`,onClick:()=>t(r.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${r.isOnline?``:` opacity-60`}`,children:[u(l,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),n(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[n(`span`,{children:[r.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),o>0&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[u(Ve,{className:`h-2.5 w-2.5`}),o]})]}),!r.isOnline&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`text-destructive`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),n(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[u(g,{variant:d.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),u(g,{variant:d.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},r.id)})}),n(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[n(`span`,{children:[d,` online`]}),f>0&&n(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function bt({nodeId:e,refreshToken:t}){let{nodes:r}=p(),i=r?.find(t=>t.id===e),o=z(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?n(`div`,{className:`px-6 py-4 border-b border-border`,children:[n(`div`,{className:`flex items-center gap-2 mb-1`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),i.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[u(`span`,{children:i.cpuModel??`CPU`}),u(`span`,{children:`•`}),n(`span`,{children:[i.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),o&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{children:[o.attachedCameras,` cameras (`,o.activeCameras,` active)`]}),u(`span`,{children:`•`}),n(`span`,{children:[o.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),u(`span`,{children:`•`}),n(`span`,{children:[`queue `,o.queueDepthTotal]}),o.hardware.hasGpu&&n(a,{children:[u(`span`,{children:`•`}),u(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):u(`div`,{className:`px-6 py-4 border-b border-border`,children:n(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var xt=[`assignments`,`tree`,`engines`,`logs`];function St({refreshToken:e,nodeId:t}){let[r,a]=l(new Map),{nodes:o}=w();se(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&a(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=j(void 0),c=i(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),d=i(()=>{let e=new Map,t=Date.now()-3e4;for(let n of r.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[r]),f=i(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=i(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of d.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[d,o]);if(t){let e=d.get(t);return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[u(W,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),u(W,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),u(W,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),u(W,{label:`Queue`,value:e?String(e.queueDepth):`—`}),u(W,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...d.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[u(W,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),u(W,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),u(W,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),u(W,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),u(W,{label:`Queue depth`,value:String(p.queueDepth)})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[480px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),u(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),u(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),u(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),u(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),u(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),n(`tbody`,{children:[m.map(([e,t])=>n(`tr`,{className:`border-t border-border`,children:[u(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&u(`tr`,{children:u(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function W({label:e,value:t}){return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[u(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),u(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}t();var Ct={active:!1,pinned:!1,nodeId:null,reason:``},wt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],Tt=3e5,Et={pipeline:U,decoder:it,audio:Be},Dt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function Ot({mode:e,nodeId:t,compact:o=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let c=s(),[f,p]=l(null),[h,g]=l(null),[_,v]=l(new Map);de([`pipelineOrchestrator`,`getPipelineAssignments`],wt),de([`pipelineOrchestrator`,`getAudioAssignments`],wt),de([`pipelineOrchestrator`,`getCameraStatuses`],wt);let{data:y}=P(void 0),{data:x}=O(void 0),{data:S}=b({},{enabled:e===`agent`}),{nodes:C}=w(),{data:T}=Ne();se(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&v(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),d(()=>{if(_.size===0)return;let e=setInterval(()=>{v(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[_.size]);let E=i(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),D=i(()=>{if(e===`agent`){let e=[];for(let n of S??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:E.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:E.get(e)??`Device ${e}`,pipeline:Ct,decoder:Ct,audio:Ct};return n.set(e,r),r};for(let i of y??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of x??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[y,x,S,E,e,t]),k=i(()=>(C??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[C]),A=()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},j=m({onSuccess:A}),M=F({onSuccess:A}),N=Ce({onSuccess:A}),I=ne({onSuccess:A}),L=(e,t,n)=>{t===`pipeline`?j.mutate({deviceId:e,agentNodeId:n}):N.mutate({deviceId:e,nodeId:n}),p(null)},R=(e,t)=>{t===`pipeline`?M.mutate({deviceId:e}):I.mutate({deviceId:e}),p(null)};return u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!o&&u(`th`,{className:`w-10`}),u(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?n(a,{children:[u(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),u(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):n(a,{children:[u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),u(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),n(`tbody`,{children:[D.map(t=>{let i=_.get(t.deviceId),s=h===t.deviceId;return n(r.Fragment,{children:[n(`tr`,{className:`border-t border-border align-middle relative`,children:[!o&&u(`td`,{className:`px-2 py-2 align-middle`,children:u(`button`,{type:`button`,onClick:()=>g(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:u(s?ct:$e,{className:`h-3.5 w-3.5`})})}),n(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[u(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?n(a,{children:[u(`td`,{className:`px-3 py-2 align-middle`,children:u(At,{state:t.pipeline,onlineNodes:k,pending:j.isPending||M.isPending,onChange:e=>{e===`auto`?R(t.deviceId,`pipeline`):L(t.deviceId,`pipeline`,e)}})}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(Mt,{state:t.pipeline,deviceId:t.deviceId})})]}):n(a,{children:[u(Pt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:k,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`pipeline`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>p(null),onMove:e=>L(t.deviceId,`pipeline`,e),onUnpin:()=>R(t.deviceId,`pipeline`)}),u(Pt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:k,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),u(Pt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:k,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`audio`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>p(null),onMove:e=>L(t.deviceId,`audio`,e),onUnpin:()=>R(t.deviceId,`audio`)})]}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(Rt,{snap:i})})]}),s&&!o&&n(`tr`,{className:`bg-surface/50`,children:[u(`td`,{}),n(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&u(kt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),u(ue,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),D.length===0&&u(`tr`,{children:u(`td`,{colSpan:o?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function kt({deviceId:e,nodeId:t}){let r=s(),{data:i}=N({nodeId:t}),{data:a}=C({deviceId:e}),o=ie({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),c=i?.devices??[],l=a?.deviceKey??`auto`,d=l!==`auto`&&!c.some(e=>e.key===l);return n(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),n(`select`,{value:l,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),d&&n(`option`,{value:l,children:[`Pin → `,l,` (not on this node)`]}),c.map(e=>n(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&u(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function At({state:e,onlineNodes:t,pending:r,onChange:i}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return n(`select`,{value:a,disabled:r,"aria-label":`Pipeline placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[u(`option`,{value:`auto`,children:`Auto`}),o.map(e=>n(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function jt(t){let n=e(null);return t.nodeId!==null&&(n.current=t),n.current}function Mt({state:e,deviceId:t}){let r=jt(e),i=e.active&&e.nodeId!==null;if(r===null||r.nodeId===null)return u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`— · no session yet`});let a=r.pinned?`pinned · manual`:`auto · ${r.reason||`capacity`}`;return n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] truncate ${i?`text-foreground`:`text-foreground-subtle`}`,title:r.pinned?r.nodeId:`${r.nodeId} — an unpinned camera is re-elected per on-motion session, so this can change between sessions`,children:r.nodeId}),u(`span`,{className:`truncate ${r.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:a,children:a}),u(`span`,{className:`truncate text-[10px] ${i?`text-emerald-400`:`text-foreground-subtle/70`}`,children:i?`● running here`:`○ idle · last session here`}),u(Nt,{deviceId:t,nodeId:r.nodeId})]})}function Nt({deviceId:e,nodeId:t}){let r=s(),{data:i}=C({deviceId:e},{refetchOnMount:`always`}),{data:a}=N({nodeId:t},{staleTime:Tt}),o=ie({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return u(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let c=a.devices??[],l=c.filter(e=>e.enabled),d=i.deviceKey??`auto`,f=d!==`auto`&&!l.some(e=>e.key===d),p=c.find(e=>e.key===d);return n(`select`,{value:d,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),f&&n(`option`,{value:d,children:[p?`${V(p).label} (${d})`:d,` (not enabled)`]}),l.map(e=>n(`option`,{value:e.key,children:[V(e).label,` · `,e.format]},e.key))]})}function Pt({role:e,state:t,mode:r,onlineNodes:i,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:l,onUnpin:d}){let f=Et[e],p=i.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||r===`cluster`)&&(p.length>0||t.pinned);return n(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[u(r===`agent`?Ft:It,{state:t,Icon:f}),u(`div`,{className:`ml-auto shrink-0`,children:m&&u(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${Dt[e]} actions`,children:u(dt,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&u(zt,{title:Dt[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:d,onClose:c})]})}function Ft({state:e,Icon:t}){return n(`div`,{className:`flex items-center gap-1.5`,children:[u(e.active?qe:Je,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),u(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&u(ft,{className:`h-2.5 w-2.5 text-amber-400`})]})}function It({state:e,Icon:t}){return!e.active||!e.nodeId?n(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[u(t,{className:`h-3 w-3`}),u(`span`,{className:`text-[10px] italic`,children:`—`})]}):n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),u(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?n(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[u(ft,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Lt=`min-h-[3.25rem]`;function Rt({snap:e}){if(!e)return u(`div`,{className:`flex items-center ${Lt}`,children:u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:r,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=_e(t);return n(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Lt}`,children:[n(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[u(re,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:r.toFixed(1)}),n(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:i.toFixed(0)}),u(`span`,{children:` ms`}),a>0&&n(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),n(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,u(`span`,{className:`text-foreground`,children:s})]})]})}function zt({title:t,targets:r,pinned:i,onMove:a,onUnpin:o,onClose:s}){let c=e(null);return d(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),n(`div`,{ref:c,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[u(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:t}),r.length>0&&u(`div`,{className:`py-1`,children:r.map(e=>n(`button`,{type:`button`,onClick:()=>a(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),i&&n(`button`,{type:`button`,onClick:o,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,t.toLowerCase()]}),r.length===0&&!i&&u(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Bt({nodeId:e,refreshToken:t}){return n(`div`,{className:`space-y-6`,children:[u(St,{refreshToken:t,nodeId:e}),n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),u(Ot,{mode:`agent`,nodeId:e,compact:!0})]})}t();function Vt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Ht({nodeId:e,refreshToken:t}){let r=s(),a=x({onSettled:()=>{r.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=T({nodeId:e}),c=z(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,l=c===null;de([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:d}=R({nodeId:e}),{values:f}=he(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),p=i(()=>f.filter(e=>e.metrics.phase===`active`).length,[f]),m=t=>{let n=d??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||a.mutate({nodeId:e,engine:t,force:n.length>0})};return n(`div`,{className:`space-y-6`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(c??[]).length,` engine(s) resident in RAM. `,(d??[]).length,` `,`camera(s) attached, `,p,` actively dispatching frames. Refreshes every 5s.`]})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),u(`th`,{className:`text-left px-3 py-2`,children:`Models`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),u(`th`,{className:`w-20`})]})}),n(`tbody`,{children:[l&&u(`tr`,{children:u(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!l&&(c??[]).map(e=>{let t=e.kind===`warm-override`,r=e.kind===`device-pool`;return n(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:r?`bg-primary/[0.05]`:``}`,children:[u(`td`,{className:`px-3 py-2`,children:n(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:r?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[u(t?Re:r?ze:U,{className:`h-3 w-3`}),t?`warm`:r?`pool`:`runtime`]})}),u(`td`,{className:`px-3 py-2`,children:n(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[u(Ye,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),u(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?u(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>u(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),u(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),u(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?u(`span`,{className:`text-foreground-subtle`,children:Vt(e.idleMs,e.idleTtlMs)}):u(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(d??[]).length}),u(`td`,{className:`px-3 py-2 text-right`,children:r?u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):n(`button`,{type:`button`,disabled:a.isPending,onClick:()=>m(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[u(at,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!l&&(c??[]).length===0&&u(`tr`,{children:u(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[u(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,u(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,u(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),a.isError&&n(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,a.error instanceof Error?a.error.message:`unknown`]})]})}var Ut=`pipeline-runner`,Wt=200;function Gt({nodeId:e}){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(M,{agentId:e,addonId:Ut,limit:Wt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t(),t();function Kt({nodeId:e,title:t}){let{data:r}=Ne(),{data:a}=P(void 0),o=i(()=>{let e=new Map;for(let t of r??[])e.set(t.id,t.name);return e},[r]),s=i(()=>{if(!e)return null;let t=new Set;for(let n of a??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,a]),[c,f]=l(new Map);se(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||f(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),d(()=>{if(c.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let p=i(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return p.length===0?n(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):n(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[n(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:p.length})]}),u(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,r=_e(e.metrics.phase);return n(`div`,{title:`${t} · ${r.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${r.badgeClass}`,children:[u(re,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),u(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),u(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),u(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var qt=`pipeline-orchestrator`;function Jt(e){return Oe.find(t=>t.stepId===e)??null}function Yt({title:e}){return u(`span`,{title:e??`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`ml-1 rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`})}function Xt({step:e,engineFormat:t,runnableModelIds:r}){let i=s(),{data:a,isLoading:o}=Se({addonId:qt}),c=D({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),l=ke(a??null)[e.stepId]??e.defaultModelId,d=r.length>0&&!r.includes(l);return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[n(`div`,{className:`flex items-center text-[11px] font-medium text-foreground`,children:[e.label,u(Yt,{})]}),n(`p`,{className:`mt-1 text-[10px] leading-snug text-foreground-subtle`,children:[`Applies to every node. Changing it does not corrupt `,e.indexName,` — every vector carries the model that produced it and only matches its own — but it STRANDS it: the existing vectors stay readable and match nothing until a re-embed pass has run.`]})]}),o?u(st,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):u(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,disabled:c.isPending,onChange:t=>{t.target.value!==l&&c.mutate({addonId:qt,patch:{[Ae(e.stepId)]:t.target.value}})},children:e.options.map(t=>n(`option`,{value:t.id,children:[t.label,t.id===e.defaultModelId?` (default)`:``]},t.id))}),d&&n(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[10px] leading-snug text-amber-300`,children:[`This node's engine (`,t,`) ships no build of `,u(`b`,{children:l}),`. It will REFUSE this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`. Either pick a model with a `,t,` build, or accept that this node contributes nothing to that index.`]}),u(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Stored once, in Pipeline → Cluster → Settings → Enrichment models. This editor writes that same row — there is no per-node copy of this value. Step knobs for this encoder (minimum face size, …) live on that same settings page.`})]})}t();function G(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Zt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function Qt({nodeId:e,refreshToken:t}){let r=s(),[o,c]=l(null),[d,f]=l(null),[p,m]=l(``),[g,_]=l(null),v=N({nodeId:e},{refetchOnMount:`always`}),b=y({nodeId:e},{refetchOnMount:`always`}),x=ke(Se({addonId:`pipeline-orchestrator`}).data??null),C=v.data?.devices??[],w=oe({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),T=i(()=>b.data?ve(b.data):[],[b.data]),D=i(()=>C.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:V(t).label})),[C,e]),O=e=>C.find(t=>t.key===e)??null,k=i(()=>C.filter(e=>e.enabled),[C]),j=k.length>=2,M=(e,t)=>h(G(b.data??null,e)?.models??[],t?.format),P=e=>{let t=O(e);return t?V(t).label:e},F=(e,t)=>k.filter(n=>n.key!==t&&M(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,I=e=>{let t=G(b.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},R=(e,t)=>{let n=G(b.data??null,e);if(n)return E(n,t)},ee=(e,t)=>{let n=I(e),r=n.kind===`gate`?n.effectiveOn:!1,i=G(b.data??null,e),a=t.deviceKey===void 0?null:O(t.deviceKey),o=h(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&k.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:F(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:P(i)}}let c=Jt(e);return c?{kind:`enabled`,modelId:x[e]??c.defaultModelId,clusterWide:!0}:{kind:`enabled`,modelId:(i?we({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&k.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:P(s.jumpDeviceKey)}:{}}},z=o&&b.data?G(b.data,o.addonId):null,B=o?O(o.deviceKey):null,ne=B?.format??`coreml`,re=o?R(o.addonId,B):void 0,ie=()=>{c(null),f(null),m(``)},ae=(e,t)=>{if(t.deviceKey===void 0)return;let n=O(t.deviceKey)?.steps?.[e];c({addonId:e,deviceKey:t.deviceKey});let r=n?.settings??je(C.map(e=>({key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}})),t.deviceKey,e)??{};f({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:r}),m(n?.jumpDeviceKey??``)},se=()=>{if(!o)return;let t=Zt(d),n=p!==``&&p!==o.deviceKey?p:void 0,r=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,i=C.map(e=>{let t={...e.steps};return e.key===o.deviceKey&&(r?t[o.addonId]=r:delete t[o.addonId]),{key:e.key,enabled:e.key===o.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}}),a=r?.settings!==void 0&&Object.keys(r.settings).length>0?Pe(i,o.deviceKey,o.addonId):i;w.mutate({agentNodeId:e,inferenceDevices:Me(a)},{onSuccess:ie})};if(v.isLoading||b.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(C.length===0)return u(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!b.data)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ce=o!==null&&z!==null&&B!==null;return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,u(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),u(`div`,{className:ce?`md:pr-[360px]`:``,children:T.length>0?u(L,{tree:T,agents:D,gateFor:I,getCellState:ee,onCellClick:ae,selectedCell:o?{addonId:o.addonId,agentNodeId:e,deviceKey:o.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:g,onFallbackNodeChange:_,hideGate:!0}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(te,{open:ce,onClose:ie,title:z?.name??``,subtitle:o&&B?`${e} · ${V(B).label} · ${B.format}`:``,footer:n(a,{children:[u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:ie,children:`Cancel`}),u(`button`,{type:`button`,disabled:!o||!d||w.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:se,children:w.isPending?`Saving…`:`Save`})]}),children:z&&o&&Jt(o.addonId)?u(Xt,{step:Jt(o.addonId),engineFormat:ne,runnableModelIds:A(z.models??[],ne).map(e=>e.id)}):z&&o&&d?n(`div`,{className:`space-y-3`,children:[j&&n(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[u(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),n(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:p,onChange:e=>m(e.target.value),children:[u(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),k.filter(e=>e.key!==o.deviceKey).map(e=>n(`option`,{value:e.key,children:[V(e).label,` · `,e.format]},e.key))]}),u(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),u(S,{mode:`agent`,addon:z,agentDefault:d,agentNodeId:e,engineFormat:ne,effectiveModelId:re,onChangeAgentConfig:f})]}):u(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}t();var $t=!1;function en({nodeId:e,refreshToken:t}){let r=pe(),[i,a]=l(null),[o,s]=l(null),{nodes:c}=w(),d=c.find(t=>t.id===e),f=d?.name??e,p=d?.isOnline??!1,m=ae({onSuccess:e=>{s(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),h=async()=>{await r({title:`Reset ${f} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(s(null),m.mutate({agentNodeId:e}))};return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&u(`span`,{className:`text-emerald-400`,children:o}),m.isError&&u(`span`,{className:`text-red-400`,children:m.error instanceof Error?m.error.message:`Reset failed`}),u(`button`,{type:`button`,onClick:()=>{h()},disabled:m.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:m.isPending?`Resetting…`:`Reset to default`})]}),u(Kt,{nodeId:e}),$t,$t,n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),u(Ie,{nodeId:e,nodeName:f,isOnline:p})]}),n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),u(Qt,{nodeId:e,refreshToken:t})]})]})}var tn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],nn=`decoder-nodeav`;function rn({nodeId:e,refreshToken:t}){let{nodes:r}=w(),i=r.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??nn,a=[...tn,i],o={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:u(Bt,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:u(en,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:u(Ht,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:u(Gt,{nodeId:e})}},s=xt.map(e=>o[e]);return n(`div`,{className:`flex flex-col h-full`,children:[u(bt,{nodeId:e,refreshToken:t}),u(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:u(lt,{nodeId:e,addonIds:a,level:`global`,extraTabs:s})})]})}function an(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?`CPU`:t===`openvino`&&n===`npu`?`Intel NPU`:t===`openvino`&&(n===`gpu`||n===`igpu`)?`Intel iGPU`:t===`edgetpu`?`Coral Edge TPU`:t===`coreml`?`Apple ANE`:`${e.backend} ${e.device}`.trim()}var on={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 sn(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function cn(e,t){let n=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let r=t.get(e.key),i=r?.sessions??0,a=e.weight>0?e.weight:1;return{key:e.key,label:an(e),format:e.format,sessions:i,queueDepth:r?.queueDepth??0,weight:a,weightSharePct:e.exclusion===null?sn(a,n):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function ln(e){let t=new Map(e.loads.map(e=>[e.nodeId,e])),n=e.nodes.filter(e=>e.isOnline&&e.detectEnabled).reduce((e,t)=>e+(t.weight>0?t.weight:1),0),r=e.loads.reduce((e,t)=>e+t.load.attachedCameras,0);return e.nodes.map(i=>{let a=t.get(i.id),o=cn(e.devicesByNode[i.id]??[],new Map((a?.load.devices??[]).map(e=>[e.deviceKey,{sessions:e.attachedCameras,queueDepth:e.queueDepthTotal}]))),s=i.isOnline&&i.detectEnabled,c=i.weight>0?i.weight:1,l=a?.load.attachedCameras??null;return{nodeId:i.id,name:i.name,isOnline:i.isOnline,detectEnabled:i.detectEnabled,reported:a!==void 0,attachedCameras:l,activeCameras:a?.load.activeCameras??null,maxCameras:i.maxCameras,capacityPct:l!==null&&i.maxCameras!==null&&i.maxCameras>0?sn(l,i.maxCameras):null,queueDepthTotal:a?.load.queueDepthTotal??null,avgInferenceTimeMs:a?.load.avgInferenceTimeMs??null,score:a?.score??null,weight:c,weightSharePct:s?sn(c,n):null,cameraSharePct:l===null?null:sn(l,r),decodeHwaccel:a?.decodeHwaccel??null,devices:o,eligibleDeviceCount:o.filter(e=>e.exclusion===null).length}})}var un=`pipeline-orchestrator`,dn=`recorder`,fn=`recordingNodeId`,pn=`pipeline-analytics`,mn=`postProcessingNodeId`,hn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`,`postProcessingNode`],gn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function _n(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function vn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function K(e,t,n){let r=_n(e,t);return typeof r==`string`&&r.length>0?r:n}function yn(e,t,n){let r=_n(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function q(e,t){let n=vn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function bn(e,t){let n=vn(e,t);return typeof n==`string`&&n.length>0?n:null}function xn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:e===`postProcessingNode`?`Post-processing`:`Motion Node`}function Sn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:e===`postProcessingNode`?`Runs detection post-processing (events, media, audio & motion)`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function Cn(e,t){switch(t){case`detect`:return e.pipeline}}function wn(e){return e instanceof Error?e.message:`Failed to save`}function Tn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}t();var En=2e4,Dn=3e5;function On(){let{nodes:e}=w(),t=f().trpcClient,r=v(void 0,{placeholderData:c,staleTime:En,refetchInterval:En,refetchOnWindowFocus:!0}),a=B(void 0,{staleTime:Dn}),s=i(()=>e.map(e=>e.id),[e]),l=o({queries:s.map(e=>({queryKey:Te(fe.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>t.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Dn,refetchOnWindowFocus:!1,placeholderData:c}))}),d=i(()=>{let e={};return s.forEach((t,n)=>{let r=l[n]?.data;r&&(e[t]=r.devices)}),e},[s,l.map(e=>e.dataUpdatedAt).join(`|`)]),p=i(()=>{let e=new Map;for(let t of a.data??[])e.set(t.nodeId,t.settings);return e},[a.data]),m=i(()=>e.map(e=>{let t=p.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:_t(t,e.isHub).pipeline,weight:q(t,`detectWeight`)??1,maxCameras:q(t,`maxCameras`)}}),[e,p]),h=r.data??[],g=i(()=>ln({nodes:m,loads:h,devicesByNode:d}),[m,h,d]),_=g.reduce((e,t)=>e+(t.attachedCameras??0),0),y=g.reduce((e,t)=>e+(t.activeCameras??0),0),b=r.dataUpdatedAt>0?Date.now()-r.dataUpdatedAt:null;return n(`section`,{className:`rounded-md border border-border bg-surface px-3 py-2.5`,children:[n(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 mb-2`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Node load`}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[y,` running · `,_,` attached across `,g.length,` `,g.length===1?`node`:`nodes`]}),u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle/70 tabular-nums`,children:r.data===void 0?`reading…`:`reading ${b===null?`—`:`${Math.round(b/1e3)}s`} old · every ${En/1e3}s`})]}),g.length===0?u(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):u(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:g.map(e=>u(kn,{row:e},e.nodeId))})]})}function kn({row:e}){let t=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),u(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&u(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&n(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[u(nt,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&n(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[u(rt,{className:`h-2.5 w-2.5`}),` offline`]})]}),n(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[u(J,{label:`Running / attached`,value:t,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),u(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`detectWeight normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),u(J,{label:`Actual share`,value:e.cameraSharePct===null?`—`:`${e.cameraSharePct}%`,title:`Share of the cluster's attached cameras this node carries right now.`}),u(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&u(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&u(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&u(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),u(An,{row:e})]})}function An({row:e}){return e.devices.length===0?u(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):n(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[n(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[u(et,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&u(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),u(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>u(jn,{device:e},e.key))})]})}function jn({device:e}){let t=e.exclusion;return n(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[u(U,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),u(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?n(a,{children:[n(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),n(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[`· `,e.sessions,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.queueDepth>0&&n(`span`,{className:`shrink-0 tabular-nums text-amber-400`,children:[`· q`,e.queueDepth]}),e.atCap&&u(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):n(`span`,{className:`truncate text-foreground-subtle/80`,title:on[t],children:[`excluded — `,on[t]]})]})}function J({label:e,value:t,title:r}){return n(`div`,{className:`min-w-0`,title:r,children:[u(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Mn(){return n(`div`,{className:`space-y-6`,children:[u(Kt,{title:`Cluster cameras`}),u(On,{}),n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),u(Ot,{mode:`cluster`})]})}function Nn({capability:e,label:t,hint:r,nodeId:i,active:a,pending:o,layout:s,onToggle:c}){let l=a?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,d=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,f=a?H:Le;return n(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${i}`,title:`${t} — ${r}`,disabled:o,onClick:()=>c(e,!a),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${l} ${d}`,children:[u(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),u(`span`,{children:t})]})}function Pn({node:e,emphasis:t=!1}){let r=e.isHub?Ke:U;return n(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[u(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),u(r,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[u(`span`,{className:`truncate`,children:e.name}),e.isHub&&u(g,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&u(g,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),u(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}t();function Fn({nodeId:e,value:t,detectedHosts:r,status:i,errorMessage:a,onCommit:o}){let[s,c]=l(t??``);d(()=>{c(t??``)},[t]);let f=r[0],p=f===void 0?`auto-detect`:`auto: ${f}`,m=i===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return n(`div`,{className:`flex items-center gap-1.5`,children:[u(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:p,value:s,disabled:m,onChange:e=>c(e.target.value),onBlur:v,onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&c(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),n(`button`,{type:`button`,onClick:v,disabled:!_,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[m?u(st,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(H,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&i===`success`&&u(H,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&u(`span`,{title:a??`Failed to save reachable host`,children:u(Ze,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}t();var In=1024,Ln=65536;function Rn(e,t,n){let r=e.trim();if(r.length===0)return{value:null,error:null};let i=Number(r);return Number.isInteger(i)?i<t?{value:null,error:`at least ${t}`}:i>n?{value:null,error:`at most ${n}`}:{value:i,error:null}:{value:null,error:`whole number`}}function zn({nodeId:e,decodeBudgetMb:t,maxLiveDecodeWorkers:r,status:i,errorMessage:a,onCommit:o}){let[s,c]=l(t===null?``:String(t)),[f,p]=l(r===null?``:String(r));d(()=>{c(t===null?``:String(t))},[t]),d(()=>{p(r===null?``:String(r))},[r]);let m=Rn(s,In,Ln),h=Rn(f,1,32),g=i===`pending`,_=m.value!==t||h.value!==r,v=m.error!==null||h.error!==null,y=_&&!v&&!g,b=()=>{y&&o(e,{decodeBudgetMb:m.value,maxLiveDecodeWorkers:h.value})},x=`w-24 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`;return n(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`input`,{"aria-label":`Decode budget MB for ${e}`,type:`number`,inputMode:`numeric`,min:In,max:Ln,placeholder:`auto`,value:s,disabled:g,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:x}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`MB`}),u(`input`,{"aria-label":`Max decode workers for ${e}`,type:`number`,inputMode:`numeric`,min:1,max:32,placeholder:`auto`,value:f,disabled:g,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:x}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`workers`}),n(`button`,{type:`button`,onClick:b,disabled:!y,"aria-label":`Save decode limits for ${e}`,title:`Save decode limits`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[g?u(st,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(H,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),m.error===null?null:n(`span`,{className:`text-[11px] text-red-400`,children:[`budget: `,m.error]}),h.error===null?null:n(`span`,{className:`text-[11px] text-red-400`,children:[`workers: `,h.error]}),!_&&!g&&i===`success`&&u(H,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&u(`span`,{title:a??`Failed to save decode limits`,children:u(Ze,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":`Save failed`,role:`img`})})]})}function Bn({label:e,children:t}){return n(`div`,{className:`flex items-center justify-between gap-3`,children:[u(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Vn({node:e,actions:t}){return n(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[u(Pn,{node:e,emphasis:!0}),u(`div`,{className:`grid grid-cols-2 gap-2`,children:gn.map(n=>u(Nn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Cn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),n(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[u(Bn,{label:`Reachable host`,children:u(Fn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),u(Bn,{label:`Decode limits`,children:u(zn,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]})]})}function Hn(){return n(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Un({nodes:e,actions:t}){return u(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:n(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[u(`thead`,{children:n(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),gn.map(e=>u(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`}),u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Decode limits`})]})}),u(`tbody`,{children:e.map(e=>n(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[u(`td`,{className:`px-4 py-3 align-middle`,children:u(Pn,{node:e})}),gn.map(n=>u(`td`,{className:`px-3 py-3 text-center align-middle`,children:u(Nn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Cn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),u(`td`,{className:`px-4 py-3 align-middle`,children:u(Fn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),u(`td`,{className:`px-4 py-3 align-middle`,children:u(zn,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]},e.id))})]})})}function Wn({role:e,value:t,options:r,pending:i,onChange:a}){return n(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[u(`span`,{className:`text-xs font-semibold text-foreground`,children:xn(e)}),u(`select`,{value:t,disabled:i,onChange:t=>a(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:r.map(e=>u(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),u(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Sn(e)})]})}function Gn({roleValues:e,options:t,pending:r,lowFpsEnabled:i,fpsMinThreshold:a,onRoleChange:o,onLowFpsToggle:s}){return n(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-3`,children:[hn.map(n=>u(Wn,{role:n,value:e[n],options:t,pending:r,onChange:o},n)),n(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[u(`input`,{type:`checkbox`,checked:i,disabled:r,onChange:e=>s(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),n(`span`,{className:`flex flex-col gap-0.5`,children:[u(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),n(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,i?`${a} fps`:`disabled`]})]})]})]})}t();function Kn(){let e=s(),{nodes:t}=w(),r=B(void 0),o=Se({addonId:un}),c=Se({addonId:dn}),d=Se({addonId:pn}),f=()=>Tn(e),p=le({onSuccess:f}),m=ee(),h=ye({onSuccess:f}),g=me({onSuccess:f}),_=D({onSuccess:f}),[v,y]=l(!1),b=i(()=>{let e=new Map;for(let t of r.data??[])e.set(t.nodeId,t.settings);return e},[r.data]),x=i(()=>t.map(e=>{let t=b.get(e.id),n=_t(t,e.isHub),r=q(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:q(t,`maxCameras`),reachableHost:bn(t,`reachableHost`),detectedHosts:e.localIps,decodeBudgetMb:q(t,`decodeBudgetMb`),maxLiveDecodeWorkers:q(t,`maxLiveDecodeWorkers`)}}),[t,b]),S=x.filter(e=>e.effective.pipeline),C={ingestNode:K(o.data,`ingestNode`,`hub`),recordingNode:K(c.data,fn,`hub`),audioNode:K(o.data,`audioNode`,`hub`),motionNode:K(o.data,`motionNode`,`hub`),postProcessingNode:K(d.data,mn,`hub`)},T=i(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...hn.map(e=>C[e]),...e])].filter(e=>e.length>0)},[t,C]),E=yn(o.data,`fpsMinThreshold`,0),O=E>0,k=r.isLoading||o.isLoading||c.isLoading||d.isLoading,A=(e,t,n)=>{p.mutate({agentNodeId:e,[t]:n})},j=(e,t)=>{if(e===`recordingNode`){_.mutate({addonId:dn,patch:{[fn]:t}});return}if(e===`postProcessingNode`){_.mutate({addonId:pn,patch:{[mn]:t}});return}_.mutate({addonId:un,patch:{[e]:t}})},M=e=>{_.mutate({addonId:un,patch:{fpsMinThreshold:e?Math.max(1,E):0}})},N=e=>h.variables?.agentNodeId===e?h.isPending?`pending`:h.isError?`error`:h.isSuccess?`success`:`idle`:`idle`,P=e=>N(e)===`error`?wn(h.error):null,F=e=>g.variables?.agentNodeId===e?g.isPending?`pending`:g.isError?`error`:g.isSuccess?`success`:`idle`:`idle`,I=e=>F(e)===`error`?wn(g.error):null,L=async e=>{y(!0);try{for(let t of e)await m.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{y(!1),f()}},R={capabilityPending:p.isPending,onToggleCapability:A,onCommitReachableHost:(e,t)=>h.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:N,reachableHostErrorMessage:P,onCommitDecodeLimits:(e,t)=>g.mutate({agentNodeId:e,...t}),decodeLimitsStatus:F,decodeLimitsErrorMessage:I};return n(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[n(`header`,{className:`flex items-start justify-between gap-4`,children:[n(`div`,{className:`space-y-1`,children:[u(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),u(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),k&&u(st,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),u(Gn,{roleValues:C,options:T,pending:_.isPending,lowFpsEnabled:O,fpsMinThreshold:E,onRoleChange:j,onLowFpsToggle:M})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Events folder`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),u(ut,{types:[`eventMedia`]})]}),n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),u(Hn,{})]}),x.length===0?u(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):n(a,{children:[u(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:x.map(e=>u(Vn,{node:e,actions:R},e.id))}),u(`div`,{className:`hidden @3xl/clustertab:block`,children:u(Un,{nodes:x,actions:R})})]})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),u(Fe,{nodes:S,pending:v,onCommitWeights:e=>void L(e)})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),S.length===0?u(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):u(`div`,{className:`space-y-2`,children:S.map(e=>u(Ie,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}t(),t(),t(),t();function qn(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Jn(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:qn(t)}}function Yn(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,lastSeen:e.lastSeen,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Jn)}}function Xn(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Yn),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}t();var Zn=!1;function Qn({refreshToken:e}){let t=s(),{nodes:r}=p();i(()=>Xn(r??[]),[r]);let a=ce({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return n(`div`,{className:`space-y-6`,children:[u(St,{refreshToken:e}),u(Kn,{}),Zn,n(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),n(`button`,{type:`button`,onClick:()=>a.mutate(void 0),disabled:a.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[u(Ye,{className:`h-3.5 w-3.5`}),a.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var $n=[`pipeline-orchestrator`],er=`pipeline-analytics`,tr=`face-gallery`;function nr({refreshToken:e}){return n(`div`,{className:`space-y-4 max-w-3xl`,children:[u(lt,{nodeId:`hub`,addonIds:$n,level:`global`,omitSectionIds:[`cluster`],title:`Cluster settings`,description:`Cluster-wide orchestration knobs: load balancer, failover, enrichment models, and the admission settings those models share. Ingest / Audio / Motion / Recording / Post-processing node pickers live on the Balancer tab. Per-camera pipelines live in Device Overrides.`}),u(lt,{nodeId:`hub`,addonIds:[er],level:`global`,capability:tr,title:`Face recognition`,description:`Match threshold, ambiguity margin, and auto-assign floors. Same settings as System → Settings → pipeline-analytics — this page asks the face-gallery cap, it does not store a second copy.`})]})}t();function rr({refreshToken:e}){let t=s(),{data:r,isLoading:i}=ge(),[o,c]=l(null),[d,f]=l(``),[p,m]=l(``),h=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},g=xe({onSuccess:()=>{c(null),h()}}),_=k({onSuccess:h}),v=e=>{c(e.id),f(e.name),m(e.description??``)},y=()=>{c(null),f(``),m(``)},b=()=>{if(!o)return;let e=p.trim();g.mutate({id:o,name:d.trim()||`Untitled`,...e?{description:e}:{}})};if(i)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let x=[...r??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return u(`div`,{className:`space-y-6 max-w-4xl`,children:n(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),u(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[x.length,` template`,x.length===1?``:`s`]})]}),x.length===0?n(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[u(Ue,{className:`h-6 w-6 opacity-40`}),u(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):u(`ul`,{className:`divide-y divide-border`,children:x.map(e=>{let t=o===e.id;return u(`li`,{className:`px-4 py-3 text-xs`,children:n(`div`,{className:`flex items-start gap-3`,children:[u(`div`,{className:`flex-1 min-w-0`,children:t?n(`div`,{className:`space-y-2`,children:[u(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:d,onChange:e=>f(e.target.value),placeholder:`Template name`,autoFocus:!0}),u(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:p,onChange:e=>m(e.target.value),placeholder:`Description (optional)`})]}):n(a,{children:[u(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&u(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),n(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,n(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),u(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?n(a,{children:[n(`button`,{type:`button`,onClick:b,disabled:g.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[u(H,{className:`h-3 w-3`}),`Save`]}),n(`button`,{type:`button`,onClick:y,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[u(ot,{className:`h-3 w-3`}),`Cancel`]})]}):n(a,{children:[u(`button`,{type:`button`,onClick:()=>v(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:u(He,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&_.mutate({id:e.id})},disabled:_.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:u(at,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var ir=`pipeline-orchestrator`,ar=200;function or(){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(M,{addonId:ir,limit:ar,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t();var sr=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function cr({refreshToken:e}){let[t,r]=l(`assignments`);return n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),u(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),u(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:sr.map(e=>u(`button`,{type:`button`,onClick:()=>r(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),n(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&u(Mn,{}),t===`balancer`&&u(Qn,{refreshToken:e}),t===`settings`&&u(nr,{refreshToken:e}),t===`templates`&&u(rr,{refreshToken:e}),t===`logs`&&u(or,{})]})]})}var lr=`armed:`;function ur(e){return e.assignment.reasons.detection?.startsWith(lr)===!0}function dr(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!ur(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function fr(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&!ur(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let s=e.degraded??[];if(s.length>0){let e=[...new Set(s.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function pr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function mr(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function hr(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function gr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var _r={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 vr(e){if(!pr(e)||!Array.isArray(e.sections))return _r;let t=Ee(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)gr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:mr(n(`detectionFps`)),motionSources:hr(n(`motionSources`)),motionFps:mr(n(`motionFps`)),motionCooldownMs:mr(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 yr(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(...yr(r.children,t+1));return n}function X({title:e,children:t}){return n(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[u(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),u(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:r=!1}){return n(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[u(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),u(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),r&&u(br,{})]})}function br(){return u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var xr={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return u(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${xr[e]}`,children:t})}function $({children:e}){return u(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Sr({icon:e,label:t,nodeId:r,pinned:i,reason:o,overridden:s}){return n(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[u(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),u(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),r===null?u(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):n(a,{children:[u(`span`,{className:`font-mono text-foreground truncate`,title:r,children:r}),i?n(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[u(ft,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,o!==void 0&&o.length>0?o:`capacity`]}),s&&u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function Cr({assignment:e,settings:t,onlineNodes:r,pinPending:i,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...r.map(e=>e.id)])];return n(X,{title:`Where it runs`,children:[u(Sr,{icon:U,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),u(Sr,{icon:it,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),u(Sr,{icon:Be,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),u(Sr,{icon:We,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),u(`div`,{className:`mt-1.5`,children:n(`select`,{value:o,disabled:i,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[u(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>n(`option`,{value:e,children:[`Pin detection → `,r.find(t=>t.id===e)?.name??e]},e))]})})]})}function wr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Tr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function Er(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function Dr({streams:e,brokerProfiles:t,settings:r,motionEnabled:i,motionFpsLive:o}){let s=Tr(t,r.detectionStreamProfile),c=Tr(t,r.motionStreamProfile),l=r.motionSources.includes(`analyzer`);return n(X,{title:`Streams & motion`,children:[n(Z,{label:`Detect stream`,overridden:r.overriddenKeys.has(`detectionStreamProfile`),children:[r.detectionStreamProfile??`—`,s!==void 0&&` · ${s.width}×${s.height} ${s.codec}`]}),u(Z,{label:`Detect FPS`,overridden:r.overriddenKeys.has(`detectionFps`),children:Er(r.detectionFps)}),n(Z,{label:`Motion src`,overridden:r.overriddenKeys.has(`motionSources`),children:[r.motionSources.length>0?r.motionSources.join(` + `):`none`,i===!1&&` · inactive`]}),l&&n(a,{children:[n(Z,{label:`Motion stream`,overridden:r.overriddenKeys.has(`motionStreamProfile`),children:[r.motionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),n(Z,{label:`Motion FPS`,overridden:r.overriddenKeys.has(`motionFps`),children:[Er(r.motionFps),o!==null&&` · live ${o.toFixed(1)}`]})]}),u(Z,{label:`Cooldown`,overridden:r.overriddenKeys.has(`motionCooldownMs`),children:r.motionCooldownMs===null?`default`:`${r.motionCooldownMs/1e3}s`}),u(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?u($,{children:`No streams registered`}):e.map(e=>n(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[u(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,wr(e)]},e.camStreamId))})]})}function Or({steps:e,audioModelId:t,audioEnabled:r,audioMode:i}){return n(X,{title:`Pipeline steps`,children:[e===void 0?u($,{children:`Resolving…`}):e.length===0?u($,{children:`No steps configured`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>u(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:n(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&u(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&n(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),u(`div`,{className:`mt-1`,children:n(Z,{label:`Audio class.`,children:[i??`—`,r!==null&&(r?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var kr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Ar({detection:e,live:t,detectionMode:r,modeOverridden:i}){if(e===null)return n(X,{title:`Detection runtime`,children:[u(Z,{label:`Mode`,overridden:i,children:r??`—`}),u($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,d=_e(a),f=a===`active`&&o===0;return n(X,{title:`Detection runtime`,children:[n(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[n(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${d.badgeClass}`,children:[u(re,{phase:a,className:`h-2.5 w-2.5`}),d.label]}),t!==void 0&&u(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),u(Z,{label:`Mode`,overridden:i,children:r??`—`}),n(Z,{label:`FPS`,children:[u(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),n(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),n(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&n(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&n(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),n(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),n(Z,{label:`Provisioning`,children:[u(Q,{tone:kr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&n(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function jr({broker:e}){return e===null?u(X,{title:`Stream broker`,children:u($,{children:`Broker stage inactive or unreachable`})}):n(X,{title:`Stream broker`,children:[e.profiles.length===0?u($,{children:`No broker profiles`}):u(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,r=t&&e.inFps===0;return n(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${r?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),u(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),n(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),n(`span`,{className:`ml-auto shrink-0 ${r?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),n(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),n(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[n(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),n(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function Mr({decoder:e,detectionActive:t}){if(e===null)return u(X,{title:`Decoder`,children:u($,{children:`Decoder stage inactive or unreachable`})});let r=t&&e.shm.framesWritten===0;return n(X,{title:`Decoder`,children:[u(Z,{label:`Node`,children:e.nodeId}),u(Z,{label:`Sessions`,children:e.sessionCount}),n(Z,{label:`SHM frames`,children:[u(`span`,{className:r?`text-danger font-semibold`:``,children:e.shm.framesWritten}),u(`span`,{className:`text-foreground-subtle`,children:` written`})]}),n(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&n(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),n(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&u(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}t();var Nr=`pipeline-orchestrator`,Pr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Fr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Ir({problems:e}){return u(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>n(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[u(nt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),u(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Lr({deviceId:e,name:t,online:r,status:a,live:o,onlineNodes:c}){let l=s(),{data:d}=be({addonId:Nr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=I({deviceId:e},{staleTime:3e4}),p=i(()=>vr(d),[d]),h=i(()=>f===void 0?void 0:yr(f.steps),[f]),g=i(()=>a===void 0?[]:fr(a),[a]),_=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=m({onSuccess:_}),y=F({onSuccess:_}),b=t=>{t===`auto`?y.mutate({deviceId:e}):v.mutate({deviceId:e,agentNodeId:t})},x=a===void 0?`idle`:dr(a),S=g.some(e=>e.severity===`error`),C=g.length>0,w=S?`border-danger/50`:C?`border-warning/40`:`border-border`;return n(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${w} bg-background overflow-hidden`,children:[n(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[u(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${S?`bg-danger`:Pr[x]}`,title:S?`Error`:Fr[x],"aria-label":S?`Error`:Fr[x],role:`img`}),u(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!r&&u(Q,{tone:`danger`,children:`offline`}),n(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&u(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),a?.recording!=null&&(a.recording.active?n(Q,{tone:`danger`,title:`Recording (${a.recording.mode})`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):a.recording.mode!==`off`&&n(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,a.recording.mode]}))]})]}),g.length>0&&u(Ir,{problems:g}),a===void 0?u(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):n(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[u(Cr,{assignment:a.assignment,settings:p,onlineNodes:c,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),u(Ar,{detection:a.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),u(Or,{steps:h,audioModelId:f?.audio?.modelId??null,audioEnabled:a.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),u(Dr,{streams:a.source.streams,brokerProfiles:a.broker?.profiles,settings:p,motionEnabled:a.motion?.enabled??null,motionFpsLive:a.motion?.fps??null}),u(jr,{broker:a.broker}),u(Mr,{decoder:a.decoder,detectionActive:a.detection?.phase===`active`})]})]})}t();var Rr=5e3,zr=1e4,Br=5e3;function Vr(e){let t=s(),{data:n,isLoading:r}=Ne(),{data:a,isLoading:o}=b({},{refetchInterval:Rr}),{nodes:c}=w();d(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[u,f]=l(new Map);se(De.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&f(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),d(()=>{if(u.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-zr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Br);return()=>clearInterval(e)},[u.size]);let p=i(()=>{let e=new Map;for(let t of a??[])e.set(t.deviceId,t);return e},[a]);return{rows:i(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:u,onlineNodes:i(()=>(c??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[c]),isLoading:r||o}}t();function Hr({refreshToken:e}){let{rows:t,liveMetrics:r,onlineNodes:a,isLoading:o}=Vr(e),s=i(()=>[...t.map(e=>{let t=e.status===void 0?[]:fr(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=i(()=>{let e=0,t=0;for(let n of s)(n.errorCount>0||n.warningCount>0)&&(t+=1),(r.get(n.row.deviceId)?.phase??n.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,r]);return o&&t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):u(`div`,{className:`h-full overflow-y-auto`,children:n(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[n(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[n(`span`,{children:[u(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),n(`span`,{children:[u(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),n(`span`,{children:[u(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),u(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>u(Lr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:r.get(e.deviceId),onlineNodes:a},e.deviceId))]})})}t();var Ur=`__cluster__`;function Wr(e){return e===`cameras`?`cameras`:`nodes`}function Gr(){let[e,t]=tt(),r=Wr(e.get(`view`)),i=e.get(`node`)??`__cluster__`,[o,s]=l(0),[c,f]=l(!1);return d(()=>{r===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Ur},{replace:!0})},[r,e,t]),n(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[n(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[u(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:i},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),u(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),u(`div`,{className:`flex items-center gap-2`,children:n(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[u(Ge,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),r===`nodes`&&n(`button`,{type:`button`,onClick:()=>f(e=>!e),"aria-expanded":c,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[n(`span`,{children:[c?`Hide`:`Show`,` node list`]}),u(ct,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),u(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:r===`nodes`?n(a,{children:[u(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:u(yt,{selectedNodeId:i,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),f(!1)},refreshToken:o})}),u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:i===`__cluster__`?u(cr,{refreshToken:o}):u(rn,{nodeId:i,refreshToken:o})})]}):u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:u(Hr,{refreshToken:o})})})]})}export{Gr as PipelinePage};
|
|
1
|
+
import{K as e,Q as t,S as n,T as r,W as i,b as a,i as o,o as s,p as c,q as l,x as u,z as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as f}from"./player-overlays-DbFWkG_Z.js";import{$s as p,Ba as m,Bt as h,Ft as g,H as _,Ha as v,Ia as y,Ka as b,La as x,Lt as S,Qa as C,Qs as w,Ra as T,Rt as E,Sn as D,Ua as O,Va as k,Vt as A,Wa as j,Y as M,Ya as N,Za as P,_o as F,ao as I,b as L,bo as R,co as ee,d as te,ec as z,eo as B,go as ne,h as re,ho as ie,io as ae,lo as oe,nc as se,no as ce,oo as le,qt as ue,r as de,rc as fe,sn as pe,so as me,tc as he,to as ge,tt as _e,u as ve,uo as ye,vn as be,vo as xe,yn as Se,za as Ce,zt as we}from"./src-CTrNqyF8.js";import{n as Te}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{Kt as Ee,f as De,h as Oe,p as ke,qt as Ae}from"./src-CHoZc4cE.js";import{a as je,i as Me,l as Ne,n as V,o as Pe,r as Fe,t as Ie,u as Le}from"./NodeInferenceDevices-D3A4x8bv.js";import{t as Re}from"./flame-DB_pOs8X.js";import{t as ze}from"./layers-Lhlv5z1U.js";import{n as Be,t as Ve}from"./video-DiXIeNMQ.js";import{t as He}from"./pencil-M7v7qavP.js";import{t as Ue}from"./plus-Cpe6mmKM.js";import{t as We}from"./radio-CV4hi-g1.js";import{t as Ge}from"./refresh-cw-Deiyupek.js";import{t as Ke}from"./server-BE9Zw1mn.js";import{t as qe}from"./square-check-big-DMuUREuL.js";import{t as Je}from"./square-DSQ5ASQ3.js";import{t as Ye}from"./zap-BoQkEUB5.js";import{B as H,D as Xe,I as Ze,J as Qe,L as $e,O as et,P as U,Q as tt,a as nt,i as rt,k as it,o as at,r as ot,w as st,z as ct}from"./index-BCxSnXqL.js";import"./useEventInvalidation-C9rmpIc-.js";import{t as lt}from"./NodeAddonsSettingsPanel-BGgUY4XE.js";import{t as ut}from"./StorageLocationsPanel-69SpAdoc.js";var dt=Qe(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ft=Qe(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);t();function pt(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 mt(e){return e}function ht(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function gt(e,t){return typeof e==`boolean`?e:mt(t)}function _t(e,t){return{pipeline:gt(ht(e,`detect`),t),audio:gt(ht(e,`audio`),t),ingest:gt(ht(e,`ingest`),t)}}function vt(e,t,n){let r=e?.find(e=>e.nodeId===t);return _t(r?.settings,n)}function yt({selectedNodeId:e,onSelect:t,refreshToken:r}){let{nodes:i}=p(),{data:o}=P(void 0),{data:s}=B(void 0),c=new Map;for(let e of o??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],d=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return n(`div`,{className:`flex flex-col h-full`,children:[n(`button`,{type:`button`,onClick:()=>t(Ur),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[u(Xe,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[u(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),u(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),u(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(r=>{let i=e===r.id,o=c.get(r.id)??0,l=r.isHub?Ke:U,d=vt(s,r.id,r.isHub),f=r.isOnline?null:_(pt(r.lastSeen));return n(`button`,{type:`button`,onClick:()=>t(r.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${r.isOnline?``:` opacity-60`}`,children:[u(l,{className:`h-4 w-4 flex-shrink-0`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex items-center gap-2`,children:[u(`span`,{className:`text-xs font-semibold truncate`,children:r.name}),r.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),r.isOnline&&u(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),n(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[n(`span`,{children:[r.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),o>0&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[u(Ve,{className:`h-2.5 w-2.5`}),o]})]}),!r.isOnline&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{className:`text-destructive`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),n(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[u(g,{variant:d.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),u(g,{variant:d.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:d.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},r.id)})}),n(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[n(`span`,{children:[d,` online`]}),f>0&&n(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function bt({nodeId:e,refreshToken:t}){let{nodes:r}=p(),i=r?.find(t=>t.id===e),o=z(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?n(`div`,{className:`px-6 py-4 border-b border-border`,children:[n(`div`,{className:`flex items-center gap-2 mb-1`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):u(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),i.isHub&&u(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[u(`span`,{children:i.cpuModel??`CPU`}),u(`span`,{children:`•`}),n(`span`,{children:[i.cpuCores,` cores`]}),u(`span`,{children:`•`}),n(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),o&&n(a,{children:[u(`span`,{children:`•`}),n(`span`,{children:[o.attachedCameras,` cameras (`,o.activeCameras,` active)`]}),u(`span`,{children:`•`}),n(`span`,{children:[o.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),u(`span`,{children:`•`}),n(`span`,{children:[`queue `,o.queueDepthTotal]}),o.hardware.hasGpu&&n(a,{children:[u(`span`,{children:`•`}),u(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):u(`div`,{className:`px-6 py-4 border-b border-border`,children:n(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var xt=[`assignments`,`tree`,`engines`,`logs`];function St({refreshToken:e,nodeId:t}){let[r,a]=l(new Map),{nodes:o}=w();se(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&a(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=j(void 0),c=i(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),d=i(()=>{let e=new Map,t=Date.now()-3e4;for(let n of r.values()){if(n.timestamp<t)continue;let r=n.nodeId??`hub`,i=e.get(r)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,n.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=n.metrics.actualFps,i.totalInferenceWeighted+=n.metrics.avgInferenceTimeMs,i.queueDepth+=n.metrics.queueDepth,e.set(r,i)}return e},[r]),f=i(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=i(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of d.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[d,o]);if(t){let e=d.get(t);return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[u(W,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),u(W,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),u(W,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),u(W,{label:`Queue`,value:e?String(e.queueDepth):`—`}),u(W,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...d.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return n(`div`,{className:`@container/liveload`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),n(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[u(W,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),u(W,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),u(W,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),u(W,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),u(W,{label:`Queue depth`,value:String(p.queueDepth)})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[480px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),u(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),u(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),u(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),u(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),u(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),n(`tbody`,{children:[m.map(([e,t])=>n(`tr`,{className:`border-t border-border`,children:[u(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&u(`tr`,{children:u(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function W({label:e,value:t}){return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[u(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),u(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}t();var Ct={active:!1,pinned:!1,nodeId:null,reason:``},wt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],Tt=3e5,Et={pipeline:U,decoder:it,audio:Be},Dt={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function Ot({mode:e,nodeId:t,compact:o=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let c=s(),[f,p]=l(null),[h,g]=l(null),[_,v]=l(new Map);de([`pipelineOrchestrator`,`getPipelineAssignments`],wt),de([`pipelineOrchestrator`,`getAudioAssignments`],wt),de([`pipelineOrchestrator`,`getCameraStatuses`],wt);let{data:y}=P(void 0),{data:x}=O(void 0),{data:S}=b({},{enabled:e===`agent`}),{nodes:C}=w(),{data:T}=Ne();se(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&v(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),d(()=>{if(_.size===0)return;let e=setInterval(()=>{v(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[_.size]);let E=i(()=>{let e=new Map;for(let t of T??[])e.set(t.id,t.name);return e},[T]),D=i(()=>{if(e===`agent`){let e=[];for(let n of S??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:E.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:E.get(e)??`Device ${e}`,pipeline:Ct,decoder:Ct,audio:Ct};return n.set(e,r),r};for(let i of y??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of x??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[y,x,S,E,e,t]),k=i(()=>(C??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[C]),A=()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},j=m({onSuccess:A}),M=F({onSuccess:A}),N=Ce({onSuccess:A}),I=ne({onSuccess:A}),L=(e,t,n)=>{t===`pipeline`?j.mutate({deviceId:e,agentNodeId:n}):N.mutate({deviceId:e,nodeId:n}),p(null)},R=(e,t)=>{t===`pipeline`?M.mutate({deviceId:e}):I.mutate({deviceId:e}),p(null)};return u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!o&&u(`th`,{className:`w-10`}),u(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?n(a,{children:[u(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),u(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):n(a,{children:[u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),u(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),u(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),n(`tbody`,{children:[D.map(t=>{let i=_.get(t.deviceId),s=h===t.deviceId;return n(r.Fragment,{children:[n(`tr`,{className:`border-t border-border align-middle relative`,children:[!o&&u(`td`,{className:`px-2 py-2 align-middle`,children:u(`button`,{type:`button`,onClick:()=>g(s?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":s?`Collapse broker details`:`Expand broker details`,children:u(s?ct:$e,{className:`h-3.5 w-3.5`})})}),n(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[u(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?n(a,{children:[u(`td`,{className:`px-3 py-2 align-middle`,children:u(At,{state:t.pipeline,onlineNodes:k,pending:j.isPending||M.isPending,onChange:e=>{e===`auto`?R(t.deviceId,`pipeline`):L(t.deviceId,`pipeline`,e)}})}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(Mt,{state:t.pipeline,deviceId:t.deviceId})})]}):n(a,{children:[u(Pt,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:k,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`pipeline`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>p(null),onMove:e=>L(t.deviceId,`pipeline`,e),onUnpin:()=>R(t.deviceId,`pipeline`)}),u(Pt,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:k,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),u(Pt,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:k,isMenuOpen:f?.deviceId===t.deviceId&&f.role===`audio`,onToggleMenu:()=>p(f?.deviceId===t.deviceId&&f.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>p(null),onMove:e=>L(t.deviceId,`audio`,e),onUnpin:()=>R(t.deviceId,`audio`)})]}),u(`td`,{className:`px-3 py-2 align-middle`,children:u(Rt,{snap:i})})]}),s&&!o&&n(`tr`,{className:`bg-surface/50`,children:[u(`td`,{}),n(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&u(kt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),u(ue,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),D.length===0&&u(`tr`,{children:u(`td`,{colSpan:o?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function kt({deviceId:e,nodeId:t}){let r=s(),{data:i}=N({nodeId:t}),{data:a}=C({deviceId:e}),o=ie({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),c=i?.devices??[],l=a?.deviceKey??`auto`,d=l!==`auto`&&!c.some(e=>e.key===l);return n(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[u(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),n(`select`,{value:l,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),d&&n(`option`,{value:l,children:[`Pin → `,l,` (not on this node)`]}),c.map(e=>n(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&u(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function At({state:e,onlineNodes:t,pending:r,onChange:i}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return n(`select`,{value:a,disabled:r,"aria-label":`Pipeline placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[u(`option`,{value:`auto`,children:`Auto`}),o.map(e=>n(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function jt(t){let n=e(null);return t.nodeId!==null&&(n.current=t),n.current}function Mt({state:e,deviceId:t}){let r=jt(e),i=e.active&&e.nodeId!==null;if(r===null||r.nodeId===null)return u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`— · no session yet`});let a=r.pinned?`pinned · manual`:`auto · ${r.reason||`capacity`}`;return n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] truncate ${i?`text-foreground`:`text-foreground-subtle`}`,title:r.pinned?r.nodeId:`${r.nodeId} — an unpinned camera is re-elected per on-motion session, so this can change between sessions`,children:r.nodeId}),u(`span`,{className:`truncate ${r.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:a,children:a}),u(`span`,{className:`truncate text-[10px] ${i?`text-emerald-400`:`text-foreground-subtle/70`}`,children:i?`● running here`:`○ idle · last session here`}),u(Nt,{deviceId:t,nodeId:r.nodeId})]})}function Nt({deviceId:e,nodeId:t}){let r=s(),{data:i}=C({deviceId:e},{refetchOnMount:`always`}),{data:a}=N({nodeId:t},{staleTime:Tt}),o=ie({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return u(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let c=a.devices??[],l=c.filter(e=>e.enabled),d=i.deviceKey??`auto`,f=d!==`auto`&&!l.some(e=>e.key===d),p=c.find(e=>e.key===d);return n(`select`,{value:d,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[u(`option`,{value:`auto`,children:`Auto (balanced)`}),f&&n(`option`,{value:d,children:[p?`${V(p).label} (${d})`:d,` (not enabled)`]}),l.map(e=>n(`option`,{value:e.key,children:[V(e).label,` · `,e.format]},e.key))]})}function Pt({role:e,state:t,mode:r,onlineNodes:i,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:l,onUnpin:d}){let f=Et[e],p=i.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||r===`cluster`)&&(p.length>0||t.pinned);return n(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[u(r===`agent`?Ft:It,{state:t,Icon:f}),u(`div`,{className:`ml-auto shrink-0`,children:m&&u(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${Dt[e]} actions`,children:u(dt,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&u(zt,{title:Dt[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:d,onClose:c})]})}function Ft({state:e,Icon:t}){return n(`div`,{className:`flex items-center gap-1.5`,children:[u(e.active?qe:Je,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),u(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&u(ft,{className:`h-2.5 w-2.5 text-amber-400`})]})}function It({state:e,Icon:t}){return!e.active||!e.nodeId?n(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[u(t,{className:`h-3 w-3`}),u(`span`,{className:`text-[10px] italic`,children:`—`})]}):n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),n(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[u(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),u(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?n(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[u(ft,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Lt=`min-h-[3.25rem]`;function Rt({snap:e}){if(!e)return u(`div`,{className:`flex items-center ${Lt}`,children:u(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:r,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=_e(t);return n(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Lt}`,children:[n(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[u(re,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),u(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:r.toFixed(1)}),n(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),n(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[u(`span`,{className:`text-foreground`,children:i.toFixed(0)}),u(`span`,{children:` ms`}),a>0&&n(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),n(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,u(`span`,{className:`text-foreground`,children:s})]})]})}function zt({title:t,targets:r,pinned:i,onMove:a,onUnpin:o,onClose:s}){let c=e(null);return d(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),n(`div`,{ref:c,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[u(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:t}),r.length>0&&u(`div`,{className:`py-1`,children:r.map(e=>n(`button`,{type:`button`,onClick:()=>a(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),i&&n(`button`,{type:`button`,onClick:o,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,t.toLowerCase()]}),r.length===0&&!i&&u(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Bt({nodeId:e,refreshToken:t}){return n(`div`,{className:`space-y-6`,children:[u(St,{refreshToken:t,nodeId:e}),n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),u(Ot,{mode:`agent`,nodeId:e,compact:!0})]})}t();function Vt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Ht({nodeId:e,refreshToken:t}){let r=s(),a=x({onSettled:()=>{r.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=T({nodeId:e}),c=z(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,l=c===null;de([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:d}=R({nodeId:e}),{values:f}=he(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),p=i(()=>f.filter(e=>e.metrics.phase===`active`).length,[f]),m=t=>{let n=d??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||a.mutate({nodeId:e,engine:t,force:n.length>0})};return n(`div`,{className:`space-y-6`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(c??[]).length,` engine(s) resident in RAM. `,(d??[]).length,` `,`camera(s) attached, `,p,` actively dispatching frames. Refreshes every 5s.`]})]}),u(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[u(`thead`,{className:`bg-surface`,children:n(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),u(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),u(`th`,{className:`text-left px-3 py-2`,children:`Models`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),u(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),u(`th`,{className:`w-20`})]})}),n(`tbody`,{children:[l&&u(`tr`,{children:u(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!l&&(c??[]).map(e=>{let t=e.kind===`warm-override`,r=e.kind===`device-pool`;return n(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:r?`bg-primary/[0.05]`:``}`,children:[u(`td`,{className:`px-3 py-2`,children:n(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:r?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[u(t?Re:r?ze:U,{className:`h-3 w-3`}),t?`warm`:r?`pool`:`runtime`]})}),u(`td`,{className:`px-3 py-2`,children:n(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[u(Ye,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),u(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?u(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>u(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),u(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),u(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?u(`span`,{className:`text-foreground-subtle`,children:Vt(e.idleMs,e.idleTtlMs)}):u(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),u(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(d??[]).length}),u(`td`,{className:`px-3 py-2 text-right`,children:r?u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):n(`button`,{type:`button`,disabled:a.isPending,onClick:()=>m(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[u(at,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!l&&(c??[]).length===0&&u(`tr`,{children:u(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),n(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[u(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,u(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,u(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),a.isError&&n(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,a.error instanceof Error?a.error.message:`unknown`]})]})}var Ut=`pipeline-runner`,Wt=200;function Gt({nodeId:e}){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),n(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(M,{agentId:e,addonId:Ut,limit:Wt,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t(),t();function Kt({nodeId:e,title:t}){let{data:r}=Ne(),{data:a}=P(void 0),o=i(()=>{let e=new Map;for(let t of r??[])e.set(t.id,t.name);return e},[r]),s=i(()=>{if(!e)return null;let t=new Set;for(let n of a??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,a]),[c,f]=l(new Map);se(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||f(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),d(()=>{if(c.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let p=i(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return p.length===0?n(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):n(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[n(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:p.length})]}),u(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,r=_e(e.metrics.phase);return n(`div`,{title:`${t} · ${r.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${r.badgeClass}`,children:[u(re,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),u(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),u(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),u(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var qt=`pipeline-orchestrator`;function Jt(e){return De.find(t=>t.stepId===e)??null}function Yt({title:e}){return u(`span`,{title:e??`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`ml-1 rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`})}function Xt({step:e,engineFormat:t,runnableModelIds:r}){let i=s(),{data:a,isLoading:o}=Se({addonId:qt}),c=D({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),l=Oe(a??null)[e.stepId]??e.defaultModelId,d=r.length>0&&!r.includes(l);return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[n(`div`,{className:`flex items-center text-[11px] font-medium text-foreground`,children:[e.label,u(Yt,{})]}),n(`p`,{className:`mt-1 text-[10px] leading-snug text-foreground-subtle`,children:[`Applies to every node. Changing it does not corrupt `,e.indexName,` — every vector carries the model that produced it and only matches its own — but it STRANDS it: the existing vectors stay readable and match nothing until a re-embed pass has run.`]})]}),o?u(st,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):u(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,disabled:c.isPending,onChange:t=>{t.target.value!==l&&c.mutate({addonId:qt,patch:{[ke(e.stepId)]:t.target.value}})},children:e.options.map(t=>n(`option`,{value:t.id,children:[t.label,t.id===e.defaultModelId?` (default)`:``]},t.id))}),d&&n(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[10px] leading-snug text-amber-300`,children:[`This node's engine (`,t,`) ships no build of `,u(`b`,{children:l}),`. It will REFUSE this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`. Either pick a model with a `,t,` build, or accept that this node contributes nothing to that index.`]}),u(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Stored once, in Pipeline → Cluster → Settings → Enrichment models. This editor writes that same row — there is no per-node copy of this value. Step knobs for this encoder (minimum face size, …) live on that same settings page.`})]})}t();function G(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Zt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function Qt({nodeId:e,refreshToken:t}){let r=s(),[o,c]=l(null),[d,f]=l(null),[p,m]=l(``),[g,_]=l(null),v=N({nodeId:e},{refetchOnMount:`always`}),b=y({nodeId:e},{refetchOnMount:`always`}),x=Oe(Se({addonId:`pipeline-orchestrator`}).data??null),C=v.data?.devices??[],w=oe({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),T=i(()=>b.data?ve(b.data):[],[b.data]),D=i(()=>C.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:V(t).label})),[C,e]),O=e=>C.find(t=>t.key===e)??null,k=i(()=>C.filter(e=>e.enabled),[C]),j=k.length>=2,M=(e,t)=>h(G(b.data??null,e)?.models??[],t?.format),P=e=>{let t=O(e);return t?V(t).label:e},F=(e,t)=>k.filter(n=>n.key!==t&&M(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,I=e=>{let t=G(b.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},R=(e,t)=>{let n=G(b.data??null,e);if(n)return E(n,t)},ee=(e,t)=>{let n=I(e),r=n.kind===`gate`?n.effectiveOn:!1,i=G(b.data??null,e),a=t.deviceKey===void 0?null:O(t.deviceKey),o=h(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&k.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:F(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:P(i)}}let c=Jt(e);return c?{kind:`enabled`,modelId:x[e]??c.defaultModelId,clusterWide:!0}:{kind:`enabled`,modelId:(i?we({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&k.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:P(s.jumpDeviceKey)}:{}}},z=o&&b.data?G(b.data,o.addonId):null,B=o?O(o.deviceKey):null,ne=B?.format??`coreml`,re=o?R(o.addonId,B):void 0,ie=()=>{c(null),f(null),m(``)},ae=(e,t)=>{if(t.deviceKey===void 0)return;let n=O(t.deviceKey)?.steps?.[e];c({addonId:e,deviceKey:t.deviceKey});let r=n?.settings??je(C.map(e=>({key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}})),t.deviceKey,e)??{};f({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:r}),m(n?.jumpDeviceKey??``)},se=()=>{if(!o)return;let t=Zt(d),n=p!==``&&p!==o.deviceKey?p:void 0,r=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,i=C.map(e=>{let t={...e.steps};return e.key===o.deviceKey&&(r?t[o.addonId]=r:delete t[o.addonId]),{key:e.key,enabled:e.key===o.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}}),a=r?.settings!==void 0&&Object.keys(r.settings).length>0?Pe(i,o.deviceKey,o.addonId):i;w.mutate({agentNodeId:e,inferenceDevices:Me(a)},{onSuccess:ie})};if(v.isLoading||b.isLoading)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(C.length===0)return u(`div`,{className:`rounded-md border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`});if(!b.data)return u(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ce=o!==null&&z!==null&&B!==null;return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,u(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),u(`div`,{className:ce?`md:pr-[360px]`:``,children:T.length>0?u(L,{tree:T,agents:D,gateFor:I,getCellState:ee,onCellClick:ae,selectedCell:o?{addonId:o.addonId,agentNodeId:e,deviceKey:o.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:g,onFallbackNodeChange:_,hideGate:!0}):u(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),u(te,{open:ce,onClose:ie,title:z?.name??``,subtitle:o&&B?`${e} · ${V(B).label} · ${B.format}`:``,footer:n(a,{children:[u(`div`,{className:`flex-1`}),u(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:ie,children:`Cancel`}),u(`button`,{type:`button`,disabled:!o||!d||w.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:se,children:w.isPending?`Saving…`:`Save`})]}),children:z&&o&&Jt(o.addonId)?u(Xt,{step:Jt(o.addonId),engineFormat:ne,runnableModelIds:A(z.models??[],ne).map(e=>e.id)}):z&&o&&d?n(`div`,{className:`space-y-3`,children:[j&&n(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[u(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),n(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:p,onChange:e=>m(e.target.value),children:[u(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),k.filter(e=>e.key!==o.deviceKey).map(e=>n(`option`,{value:e.key,children:[V(e).label,` · `,e.format]},e.key))]}),u(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),u(S,{mode:`agent`,addon:z,agentDefault:d,agentNodeId:e,engineFormat:ne,effectiveModelId:re,onChangeAgentConfig:f})]}):u(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}t();var $t=!1;function en({nodeId:e,refreshToken:t}){let r=pe(),[i,a]=l(null),[o,s]=l(null),{nodes:c}=w(),d=c.find(t=>t.id===e),f=d?.name??e,p=d?.isOnline??!1,m=ae({onSuccess:e=>{s(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),h=async()=>{await r({title:`Reset ${f} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(s(null),m.mutate({agentNodeId:e}))};return n(`div`,{className:`relative h-full w-full space-y-3`,children:[n(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&u(`span`,{className:`text-emerald-400`,children:o}),m.isError&&u(`span`,{className:`text-red-400`,children:m.error instanceof Error?m.error.message:`Reset failed`}),u(`button`,{type:`button`,onClick:()=>{h()},disabled:m.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:m.isPending?`Resetting…`:`Reset to default`})]}),u(Kt,{nodeId:e}),$t,$t,n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),u(Ie,{nodeId:e,nodeName:f,isOnline:p})]}),n(`div`,{children:[u(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),u(Qt,{nodeId:e,refreshToken:t})]})]})}var tn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],nn=`decoder-nodeav`;function rn({nodeId:e,refreshToken:t}){let{nodes:r}=w(),i=r.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??nn,a=[...tn,i],o={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:u(Bt,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:u(en,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:u(Ht,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:u(Gt,{nodeId:e})}},s=xt.map(e=>o[e]);return n(`div`,{className:`flex flex-col h-full`,children:[u(bt,{nodeId:e,refreshToken:t}),u(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:u(lt,{nodeId:e,addonIds:a,level:`global`,extraTabs:s})})]})}function an(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?`CPU`:t===`openvino`&&n===`npu`?`Intel NPU`:t===`openvino`&&(n===`gpu`||n===`igpu`)?`Intel iGPU`:t===`edgetpu`?`Coral Edge TPU`:t===`coreml`?`Apple ANE`:`${e.backend} ${e.device}`.trim()}var on={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 sn(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function cn(e,t){let n=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let r=t.get(e.key),i=r?.sessions??0,a=e.weight>0?e.weight:1;return{key:e.key,label:an(e),format:e.format,sessions:i,queueDepth:r?.queueDepth??0,weight:a,weightSharePct:e.exclusion===null?sn(a,n):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function ln(e){let t=new Map(e.loads.map(e=>[e.nodeId,e])),n=e.nodes.filter(e=>e.isOnline&&e.detectEnabled).reduce((e,t)=>e+(t.weight>0?t.weight:1),0),r=e.loads.reduce((e,t)=>e+t.load.attachedCameras,0);return e.nodes.map(i=>{let a=t.get(i.id),o=cn(e.devicesByNode[i.id]??[],new Map((a?.load.devices??[]).map(e=>[e.deviceKey,{sessions:e.attachedCameras,queueDepth:e.queueDepthTotal}]))),s=i.isOnline&&i.detectEnabled,c=i.weight>0?i.weight:1,l=a?.load.attachedCameras??null;return{nodeId:i.id,name:i.name,isOnline:i.isOnline,detectEnabled:i.detectEnabled,reported:a!==void 0,attachedCameras:l,activeCameras:a?.load.activeCameras??null,maxCameras:i.maxCameras,capacityPct:l!==null&&i.maxCameras!==null&&i.maxCameras>0?sn(l,i.maxCameras):null,queueDepthTotal:a?.load.queueDepthTotal??null,avgInferenceTimeMs:a?.load.avgInferenceTimeMs??null,score:a?.score??null,weight:c,weightSharePct:s?sn(c,n):null,cameraSharePct:l===null?null:sn(l,r),decodeHwaccel:a?.decodeHwaccel??null,devices:o,eligibleDeviceCount:o.filter(e=>e.exclusion===null).length}})}var un=`pipeline-orchestrator`,dn=`recorder`,fn=`recordingNodeId`,pn=`pipeline-analytics`,mn=`postProcessingNodeId`,hn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`,`postProcessingNode`],gn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function _n(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function vn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function K(e,t,n){let r=_n(e,t);return typeof r==`string`&&r.length>0?r:n}function yn(e,t,n){let r=_n(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function q(e,t){let n=vn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function bn(e,t){let n=vn(e,t);return typeof n==`string`&&n.length>0?n:null}function xn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:e===`postProcessingNode`?`Post-processing`:`Motion Node`}function Sn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:e===`postProcessingNode`?`Runs detection post-processing (events, media, audio & motion)`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function Cn(e,t){switch(t){case`detect`:return e.pipeline}}function wn(e){return e instanceof Error?e.message:`Failed to save`}function Tn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}t();var En=2e4,Dn=3e5;function On(){let{nodes:e}=w(),t=f().trpcClient,r=v(void 0,{placeholderData:c,staleTime:En,refetchInterval:En,refetchOnWindowFocus:!0}),a=B(void 0,{staleTime:Dn}),s=i(()=>e.map(e=>e.id),[e]),l=o({queries:s.map(e=>({queryKey:Te(fe.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>t.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Dn,refetchOnWindowFocus:!1,placeholderData:c}))}),d=i(()=>{let e={};return s.forEach((t,n)=>{let r=l[n]?.data;r&&(e[t]=r.devices)}),e},[s,l.map(e=>e.dataUpdatedAt).join(`|`)]),p=i(()=>{let e=new Map;for(let t of a.data??[])e.set(t.nodeId,t.settings);return e},[a.data]),m=i(()=>e.map(e=>{let t=p.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:_t(t,e.isHub).pipeline,weight:q(t,`detectWeight`)??1,maxCameras:q(t,`maxCameras`)}}),[e,p]),h=r.data??[],g=i(()=>ln({nodes:m,loads:h,devicesByNode:d}),[m,h,d]),_=g.reduce((e,t)=>e+(t.attachedCameras??0),0),y=g.reduce((e,t)=>e+(t.activeCameras??0),0),b=r.dataUpdatedAt>0?Date.now()-r.dataUpdatedAt:null;return n(`section`,{className:`rounded-md border border-border bg-surface px-3 py-2.5`,children:[n(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 mb-2`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Node load`}),n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[y,` running · `,_,` attached across `,g.length,` `,g.length===1?`node`:`nodes`]}),u(`span`,{className:`ml-auto text-[10px] text-foreground-subtle/70 tabular-nums`,children:r.data===void 0?`reading…`:`reading ${b===null?`—`:`${Math.round(b/1e3)}s`} old · every ${En/1e3}s`})]}),g.length===0?u(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):u(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:g.map(e=>u(kn,{row:e},e.nodeId))})]})}function kn({row:e}){let t=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return n(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[u(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),u(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&u(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&n(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[u(nt,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&n(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[u(rt,{className:`h-2.5 w-2.5`}),` offline`]})]}),n(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[u(J,{label:`Running / attached`,value:t,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),u(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`detectWeight normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),u(J,{label:`Actual share`,value:e.cameraSharePct===null?`—`:`${e.cameraSharePct}%`,title:`Share of the cluster's attached cameras this node carries right now.`}),u(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&u(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&u(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&u(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),u(An,{row:e})]})}function An({row:e}){return e.devices.length===0?u(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):n(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[n(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[u(et,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&u(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),u(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>u(jn,{device:e},e.key))})]})}function jn({device:e}){let t=e.exclusion;return n(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[u(U,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),u(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?n(a,{children:[n(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),n(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[`· `,e.sessions,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.queueDepth>0&&n(`span`,{className:`shrink-0 tabular-nums text-amber-400`,children:[`· q`,e.queueDepth]}),e.atCap&&u(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):n(`span`,{className:`truncate text-foreground-subtle/80`,title:on[t],children:[`excluded — `,on[t]]})]})}function J({label:e,value:t,title:r}){return n(`div`,{className:`min-w-0`,title:r,children:[u(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),u(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Mn(){return n(`div`,{className:`space-y-6`,children:[u(Kt,{title:`Cluster cameras`}),u(On,{}),n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Cluster load, inference-device weights, and Rebalance live on the Balancer tab.`})]}),u(Ot,{mode:`cluster`})]})}function Nn({capability:e,label:t,hint:r,nodeId:i,active:a,pending:o,layout:s,onToggle:c}){let l=a?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,d=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,f=a?H:Le;return n(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${i}`,title:`${t} — ${r}`,disabled:o,onClick:()=>c(e,!a),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${l} ${d}`,children:[u(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),u(`span`,{children:t})]})}function Pn({node:e,emphasis:t=!1}){let r=e.isHub?Ke:U;return n(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[u(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),u(r,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[u(`span`,{className:`truncate`,children:e.name}),e.isHub&&u(g,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&u(g,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),u(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}t();function Fn({nodeId:e,value:t,detectedHosts:r,status:i,errorMessage:a,onCommit:o}){let[s,c]=l(t??``);d(()=>{c(t??``)},[t]);let f=r[0],p=f===void 0?`auto-detect`:`auto: ${f}`,m=i===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return n(`div`,{className:`flex items-center gap-1.5`,children:[u(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:p,value:s,disabled:m,onChange:e=>c(e.target.value),onBlur:v,onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&c(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),n(`button`,{type:`button`,onClick:v,disabled:!_,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[m?u(st,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(H,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&i===`success`&&u(H,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&u(`span`,{title:a??`Failed to save reachable host`,children:u(Ze,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}t();var In=1024,Ln=65536;function Rn(e,t,n){let r=e.trim();if(r.length===0)return{value:null,error:null};let i=Number(r);return Number.isInteger(i)?i<t?{value:null,error:`at least ${t}`}:i>n?{value:null,error:`at most ${n}`}:{value:i,error:null}:{value:null,error:`whole number`}}function zn({nodeId:e,decodeBudgetMb:t,maxLiveDecodeWorkers:r,status:i,errorMessage:a,onCommit:o}){let[s,c]=l(t===null?``:String(t)),[f,p]=l(r===null?``:String(r));d(()=>{c(t===null?``:String(t))},[t]),d(()=>{p(r===null?``:String(r))},[r]);let m=Rn(s,In,Ln),h=Rn(f,1,32),g=i===`pending`,_=m.value!==t||h.value!==r,v=m.error!==null||h.error!==null,y=_&&!v&&!g,b=()=>{y&&o(e,{decodeBudgetMb:m.value,maxLiveDecodeWorkers:h.value})},x=`w-24 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`;return n(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u(`input`,{"aria-label":`Decode budget MB for ${e}`,type:`number`,inputMode:`numeric`,min:In,max:Ln,placeholder:`auto`,value:s,disabled:g,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:x}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`MB`}),u(`input`,{"aria-label":`Max decode workers for ${e}`,type:`number`,inputMode:`numeric`,min:1,max:32,placeholder:`auto`,value:f,disabled:g,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:x}),u(`span`,{className:`text-[11px] text-foreground-subtle`,children:`workers`}),n(`button`,{type:`button`,onClick:b,disabled:!y,"aria-label":`Save decode limits for ${e}`,title:`Save decode limits`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[g?u(st,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(H,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),m.error===null?null:n(`span`,{className:`text-[11px] text-red-400`,children:[`budget: `,m.error]}),h.error===null?null:n(`span`,{className:`text-[11px] text-red-400`,children:[`workers: `,h.error]}),!_&&!g&&i===`success`&&u(H,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&u(`span`,{title:a??`Failed to save decode limits`,children:u(Ze,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":`Save failed`,role:`img`})})]})}function Bn({label:e,children:t}){return n(`div`,{className:`flex items-center justify-between gap-3`,children:[u(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Vn({node:e,actions:t}){return n(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[u(Pn,{node:e,emphasis:!0}),u(`div`,{className:`grid grid-cols-2 gap-2`,children:gn.map(n=>u(Nn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Cn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),n(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[u(Bn,{label:`Reachable host`,children:u(Fn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),u(Bn,{label:`Decode limits`,children:u(zn,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]})]})}function Hn(){return n(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),n(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Un({nodes:e,actions:t}){return u(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:n(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[u(`thead`,{children:n(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),gn.map(e=>u(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`}),u(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Decode limits`})]})}),u(`tbody`,{children:e.map(e=>n(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[u(`td`,{className:`px-4 py-3 align-middle`,children:u(Pn,{node:e})}),gn.map(n=>u(`td`,{className:`px-3 py-3 text-center align-middle`,children:u(Nn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Cn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),u(`td`,{className:`px-4 py-3 align-middle`,children:u(Fn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),u(`td`,{className:`px-4 py-3 align-middle`,children:u(zn,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]},e.id))})]})})}function Wn({role:e,value:t,options:r,pending:i,onChange:a}){return n(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[u(`span`,{className:`text-xs font-semibold text-foreground`,children:xn(e)}),u(`select`,{value:t,disabled:i,onChange:t=>a(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:r.map(e=>u(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),u(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Sn(e)})]})}function Gn({roleValues:e,options:t,pending:r,lowFpsEnabled:i,fpsMinThreshold:a,onRoleChange:o,onLowFpsToggle:s}){return n(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-3`,children:[hn.map(n=>u(Wn,{role:n,value:e[n],options:t,pending:r,onChange:o},n)),n(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[u(`input`,{type:`checkbox`,checked:i,disabled:r,onChange:e=>s(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),n(`span`,{className:`flex flex-col gap-0.5`,children:[u(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),n(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,i?`${a} fps`:`disabled`]})]})]})]})}t();function Kn(){let e=s(),{nodes:t}=w(),r=B(void 0),o=Se({addonId:un}),c=Se({addonId:dn}),d=Se({addonId:pn}),f=()=>Tn(e),p=le({onSuccess:f}),m=ee(),h=ye({onSuccess:f}),g=me({onSuccess:f}),_=D({onSuccess:f}),[v,y]=l(!1),b=i(()=>{let e=new Map;for(let t of r.data??[])e.set(t.nodeId,t.settings);return e},[r.data]),x=i(()=>t.map(e=>{let t=b.get(e.id),n=_t(t,e.isHub),r=q(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:q(t,`maxCameras`),reachableHost:bn(t,`reachableHost`),detectedHosts:e.localIps,decodeBudgetMb:q(t,`decodeBudgetMb`),maxLiveDecodeWorkers:q(t,`maxLiveDecodeWorkers`)}}),[t,b]),S=x.filter(e=>e.effective.pipeline),C={ingestNode:K(o.data,`ingestNode`,`hub`),recordingNode:K(c.data,fn,`hub`),audioNode:K(o.data,`audioNode`,`hub`),motionNode:K(o.data,`motionNode`,`hub`),postProcessingNode:K(d.data,mn,`hub`)},T=i(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...hn.map(e=>C[e]),...e])].filter(e=>e.length>0)},[t,C]),E=yn(o.data,`fpsMinThreshold`,0),O=E>0,k=r.isLoading||o.isLoading||c.isLoading||d.isLoading,A=(e,t,n)=>{p.mutate({agentNodeId:e,[t]:n})},j=(e,t)=>{if(e===`recordingNode`){_.mutate({addonId:dn,patch:{[fn]:t}});return}if(e===`postProcessingNode`){_.mutate({addonId:pn,patch:{[mn]:t}});return}_.mutate({addonId:un,patch:{[e]:t}})},M=e=>{_.mutate({addonId:un,patch:{fpsMinThreshold:e?Math.max(1,E):0}})},N=e=>h.variables?.agentNodeId===e?h.isPending?`pending`:h.isError?`error`:h.isSuccess?`success`:`idle`:`idle`,P=e=>N(e)===`error`?wn(h.error):null,F=e=>g.variables?.agentNodeId===e?g.isPending?`pending`:g.isError?`error`:g.isSuccess?`success`:`idle`:`idle`,I=e=>F(e)===`error`?wn(g.error):null,L=async e=>{y(!0);try{for(let t of e)await m.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{y(!1),f()}},R={capabilityPending:p.isPending,onToggleCapability:A,onCommitReachableHost:(e,t)=>h.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:N,reachableHostErrorMessage:P,onCommitDecodeLimits:(e,t)=>g.mutate({agentNodeId:e,...t}),decodeLimitsStatus:F,decodeLimitsErrorMessage:I};return n(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[n(`header`,{className:`flex items-start justify-between gap-4`,children:[n(`div`,{className:`space-y-1`,children:[u(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),u(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),k&&u(st,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),u(Gn,{roleValues:C,options:T,pending:_.isPending,lowFpsEnabled:O,fpsMinThreshold:E,onRoleChange:j,onLowFpsToggle:M})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Events folder`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),u(ut,{types:[`eventMedia`]})]}),n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),u(Hn,{})]}),x.length===0?u(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):n(a,{children:[u(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:x.map(e=>u(Vn,{node:e,actions:R},e.id))}),u(`div`,{className:`hidden @3xl/clustertab:block`,children:u(Un,{nodes:x,actions:R})})]})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),u(Fe,{nodes:S,pending:v,onCommitWeights:e=>void L(e)})]}),n(`div`,{className:`space-y-3`,children:[u(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),S.length===0?u(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):u(`div`,{className:`space-y-2`,children:S.map(e=>u(Ie,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}t(),t(),t(),t();function qn(e){if(e===void 0||e.length===0)return[];let t=new Set,n=[];for(let r of e)for(let e of r.capabilities){let i=`${e}\0${r.addonId}`;t.has(i)||(t.add(i),n.push({name:e,addonId:r.addonId}))}return n.toSorted((e,t)=>e.name.localeCompare(t.name))}function Jn(e){let t=e.services;return{pid:e.pid,name:e.name,addonId:t?.[0]?.addonId??``,cpu:e.cpuPercent,mem:e.memoryRss,state:e.state,caps:qn(t)}}function Yn(e){return{nodeId:e.id,isHub:e.isHub,isOnline:e.isOnline,lastSeen:e.lastSeen,identity:{name:e.name,ip:e.localIps?.[0]??``,cpu:e.cpuPercent,mem:e.memoryPercent,platform:e.platform,arch:e.arch},runners:e.processes.map(Jn)}}function Xn(e){let t=e.toSorted((e,t)=>{let n=+!!e.isHub;return+!!t.isHub-n}).map(Yn),n=t.find(e=>e.isHub);return n===void 0?{nodes:t,edges:[]}:{nodes:t,edges:t.filter(e=>!e.isHub).map(e=>({id:`hub:${n.nodeId}->${e.nodeId}`,source:n.nodeId,target:e.nodeId,online:e.isOnline&&n.isOnline}))}}t();var Zn=!1;function Qn({refreshToken:e}){let t=s(),{nodes:r}=p();i(()=>Xn(r??[]),[r]);let a=ce({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return n(`div`,{className:`space-y-6`,children:[u(St,{refreshToken:e}),u(Kn,{}),Zn,n(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[n(`div`,{className:`min-w-0`,children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Recompute the optimal node for every assigned camera from current load + hardware affinity, and migrate the ones no longer on their best node. Pinned cameras never move.`})]}),n(`button`,{type:`button`,onClick:()=>a.mutate(void 0),disabled:a.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[u(Ye,{className:`h-3.5 w-3.5`}),a.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var $n=[`pipeline-orchestrator`],er=`pipeline-analytics`,tr=`face-gallery`;function nr({refreshToken:e}){return n(`div`,{className:`space-y-4 max-w-3xl`,children:[u(lt,{nodeId:`hub`,addonIds:$n,level:`global`,omitSectionIds:[`cluster`],title:`Cluster settings`,description:`Cluster-wide orchestration knobs: load balancer, failover, enrichment models, and the admission settings those models share. Ingest / Audio / Motion / Recording / Post-processing node pickers live on the Balancer tab. Per-camera pipelines live in Device Overrides.`}),u(lt,{nodeId:`hub`,addonIds:[er],level:`global`,capability:tr,title:`Face recognition`,description:`Match threshold, ambiguity margin, and auto-assign floors. Same settings as System → Settings → pipeline-analytics — this page asks the face-gallery cap, it does not store a second copy.`})]})}t();function rr({refreshToken:e}){let t=s(),{data:r,isLoading:i}=ge(),[o,c]=l(null),[d,f]=l(``),[p,m]=l(``),h=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},g=xe({onSuccess:()=>{c(null),h()}}),_=k({onSuccess:h}),v=e=>{c(e.id),f(e.name),m(e.description??``)},y=()=>{c(null),f(``),m(``)},b=()=>{if(!o)return;let e=p.trim();g.mutate({id:o,name:d.trim()||`Untitled`,...e?{description:e}:{}})};if(i)return u(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let x=[...r??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return u(`div`,{className:`space-y-6 max-w-4xl`,children:n(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[n(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),u(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),n(`div`,{className:`text-[11px] text-foreground-subtle`,children:[x.length,` template`,x.length===1?``:`s`]})]}),x.length===0?n(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[u(Ue,{className:`h-6 w-6 opacity-40`}),u(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):u(`ul`,{className:`divide-y divide-border`,children:x.map(e=>{let t=o===e.id;return u(`li`,{className:`px-4 py-3 text-xs`,children:n(`div`,{className:`flex items-start gap-3`,children:[u(`div`,{className:`flex-1 min-w-0`,children:t?n(`div`,{className:`space-y-2`,children:[u(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:d,onChange:e=>f(e.target.value),placeholder:`Template name`,autoFocus:!0}),u(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:p,onChange:e=>m(e.target.value),placeholder:`Description (optional)`})]}):n(a,{children:[u(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&u(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),n(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,n(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),u(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?n(a,{children:[n(`button`,{type:`button`,onClick:b,disabled:g.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[u(H,{className:`h-3 w-3`}),`Save`]}),n(`button`,{type:`button`,onClick:y,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[u(ot,{className:`h-3 w-3`}),`Cancel`]})]}):n(a,{children:[u(`button`,{type:`button`,onClick:()=>v(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:u(He,{className:`h-3 w-3`})}),u(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&_.mutate({id:e.id})},disabled:_.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:u(at,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var ir=`pipeline-orchestrator`,ar=200;function or(){return n(`div`,{className:`flex flex-col gap-3`,children:[n(`div`,{children:[u(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),u(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),u(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:u(M,{addonId:ir,limit:ar,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}t();var sr=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function cr({refreshToken:e}){let[t,r]=l(`assignments`);return n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[u(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),u(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),u(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:sr.map(e=>u(`button`,{type:`button`,onClick:()=>r(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),n(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&u(Mn,{}),t===`balancer`&&u(Qn,{refreshToken:e}),t===`settings`&&u(nr,{refreshToken:e}),t===`templates`&&u(rr,{refreshToken:e}),t===`logs`&&u(or,{})]})]})}var lr=`armed:`;function ur(e){return e.assignment.reasons.detection?.startsWith(lr)===!0}function dr(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!ur(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function fr(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&!ur(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let s=e.degraded??[];if(s.length>0){let e=[...new Set(s.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function pr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function mr(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function hr(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function gr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var _r={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 vr(e){if(!pr(e)||!Array.isArray(e.sections))return _r;let t=Ee(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)gr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:mr(n(`detectionFps`)),motionSources:hr(n(`motionSources`)),motionFps:mr(n(`motionFps`)),motionCooldownMs:mr(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 yr(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(...yr(r.children,t+1));return n}function X({title:e,children:t}){return n(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[u(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),u(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:r=!1}){return n(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[u(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),u(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),r&&u(br,{})]})}function br(){return u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var xr={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return u(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${xr[e]}`,children:t})}function $({children:e}){return u(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Sr({icon:e,label:t,nodeId:r,pinned:i,reason:o,overridden:s}){return n(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[u(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),u(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),r===null?u(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):n(a,{children:[u(`span`,{className:`font-mono text-foreground truncate`,title:r,children:r}),i?n(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[u(ft,{className:`h-2.5 w-2.5`}),` manual`]}):n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,o!==void 0&&o.length>0?o:`capacity`]}),s&&u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function Cr({assignment:e,settings:t,onlineNodes:r,pinPending:i,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...r.map(e=>e.id)])];return n(X,{title:`Where it runs`,children:[u(Sr,{icon:U,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),u(Sr,{icon:it,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),u(Sr,{icon:Be,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),u(Sr,{icon:We,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),u(`div`,{className:`mt-1.5`,children:n(`select`,{value:o,disabled:i,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[u(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>n(`option`,{value:e,children:[`Pin detection → `,r.find(t=>t.id===e)?.name??e]},e))]})})]})}function wr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Tr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function Er(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function Dr({streams:e,brokerProfiles:t,settings:r,motionEnabled:i,motionFpsLive:o}){let s=Tr(t,r.detectionStreamProfile),c=Tr(t,r.motionStreamProfile),l=r.motionSources.includes(`analyzer`);return n(X,{title:`Streams & motion`,children:[n(Z,{label:`Detect stream`,overridden:r.overriddenKeys.has(`detectionStreamProfile`),children:[r.detectionStreamProfile??`—`,s!==void 0&&` · ${s.width}×${s.height} ${s.codec}`]}),u(Z,{label:`Detect FPS`,overridden:r.overriddenKeys.has(`detectionFps`),children:Er(r.detectionFps)}),n(Z,{label:`Motion src`,overridden:r.overriddenKeys.has(`motionSources`),children:[r.motionSources.length>0?r.motionSources.join(` + `):`none`,i===!1&&` · inactive`]}),l&&n(a,{children:[n(Z,{label:`Motion stream`,overridden:r.overriddenKeys.has(`motionStreamProfile`),children:[r.motionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),n(Z,{label:`Motion FPS`,overridden:r.overriddenKeys.has(`motionFps`),children:[Er(r.motionFps),o!==null&&` · live ${o.toFixed(1)}`]})]}),u(Z,{label:`Cooldown`,overridden:r.overriddenKeys.has(`motionCooldownMs`),children:r.motionCooldownMs===null?`default`:`${r.motionCooldownMs/1e3}s`}),u(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?u($,{children:`No streams registered`}):e.map(e=>n(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[u(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,wr(e)]},e.camStreamId))})]})}function Or({steps:e,audioModelId:t,audioEnabled:r,audioMode:i}){return n(X,{title:`Pipeline steps`,children:[e===void 0?u($,{children:`Resolving…`}):e.length===0?u($,{children:`No steps configured`}):u(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>u(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:n(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&u(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&n(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),u(`div`,{className:`mt-1`,children:n(Z,{label:`Audio class.`,children:[i??`—`,r!==null&&(r?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var kr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Ar({detection:e,live:t,detectionMode:r,modeOverridden:i}){if(e===null)return n(X,{title:`Detection runtime`,children:[u(Z,{label:`Mode`,overridden:i,children:r??`—`}),u($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,d=_e(a),f=a===`active`&&o===0;return n(X,{title:`Detection runtime`,children:[n(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[n(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${d.badgeClass}`,children:[u(re,{phase:a,className:`h-2.5 w-2.5`}),d.label]}),t!==void 0&&u(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),u(Z,{label:`Mode`,overridden:i,children:r??`—`}),n(Z,{label:`FPS`,children:[u(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),n(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),n(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&n(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&n(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),n(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),n(Z,{label:`Provisioning`,children:[u(Q,{tone:kr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&n(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function jr({broker:e}){return e===null?u(X,{title:`Stream broker`,children:u($,{children:`Broker stage inactive or unreachable`})}):n(X,{title:`Stream broker`,children:[e.profiles.length===0?u($,{children:`No broker profiles`}):u(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,r=t&&e.inFps===0;return n(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${r?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),u(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),n(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),n(`span`,{className:`ml-auto shrink-0 ${r?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),n(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),n(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[n(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),n(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function Mr({decoder:e,detectionActive:t}){if(e===null)return u(X,{title:`Decoder`,children:u($,{children:`Decoder stage inactive or unreachable`})});let r=t&&e.shm.framesWritten===0;return n(X,{title:`Decoder`,children:[u(Z,{label:`Node`,children:e.nodeId}),u(Z,{label:`Sessions`,children:e.sessionCount}),n(Z,{label:`SHM frames`,children:[u(`span`,{className:r?`text-danger font-semibold`:``,children:e.shm.framesWritten}),u(`span`,{className:`text-foreground-subtle`,children:` written`})]}),n(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&n(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),n(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&u(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}t();var Nr=`pipeline-orchestrator`,Pr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Fr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Ir({problems:e}){return u(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>n(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[u(nt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),u(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Lr({deviceId:e,name:t,online:r,status:a,live:o,onlineNodes:c}){let l=s(),{data:d}=be({addonId:Nr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=I({deviceId:e},{staleTime:3e4}),p=i(()=>vr(d),[d]),h=i(()=>f===void 0?void 0:yr(f.steps),[f]),g=i(()=>a===void 0?[]:fr(a),[a]),_=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=m({onSuccess:_}),y=F({onSuccess:_}),b=t=>{t===`auto`?y.mutate({deviceId:e}):v.mutate({deviceId:e,agentNodeId:t})},x=a===void 0?`idle`:dr(a),S=g.some(e=>e.severity===`error`),C=g.length>0,w=S?`border-danger/50`:C?`border-warning/40`:`border-border`;return n(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${w} bg-background overflow-hidden`,children:[n(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[u(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${S?`bg-danger`:Pr[x]}`,title:S?`Error`:Fr[x],"aria-label":S?`Error`:Fr[x],role:`img`}),u(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),n(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!r&&u(Q,{tone:`danger`,children:`offline`}),n(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&u(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),a?.recording!=null&&(a.recording.active?n(Q,{tone:`danger`,title:`Recording (${a.recording.mode})`,children:[u(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):a.recording.mode!==`off`&&n(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,a.recording.mode]}))]})]}),g.length>0&&u(Ir,{problems:g}),a===void 0?u(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):n(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[u(Cr,{assignment:a.assignment,settings:p,onlineNodes:c,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),u(Ar,{detection:a.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),u(Or,{steps:h,audioModelId:f?.audio?.modelId??null,audioEnabled:a.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),u(Dr,{streams:a.source.streams,brokerProfiles:a.broker?.profiles,settings:p,motionEnabled:a.motion?.enabled??null,motionFpsLive:a.motion?.fps??null}),u(jr,{broker:a.broker}),u(Mr,{decoder:a.decoder,detectionActive:a.detection?.phase===`active`})]})]})}t();var Rr=5e3,zr=1e4,Br=5e3;function Vr(e){let t=s(),{data:n,isLoading:r}=Ne(),{data:a,isLoading:o}=b({},{refetchInterval:Rr}),{nodes:c}=w();d(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[u,f]=l(new Map);se(Ae.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&f(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),d(()=>{if(u.size===0)return;let e=setInterval(()=>{f(e=>{let t=Date.now()-zr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Br);return()=>clearInterval(e)},[u.size]);let p=i(()=>{let e=new Map;for(let t of a??[])e.set(t.deviceId,t);return e},[a]);return{rows:i(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:u,onlineNodes:i(()=>(c??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[c]),isLoading:r||o}}t();function Hr({refreshToken:e}){let{rows:t,liveMetrics:r,onlineNodes:a,isLoading:o}=Vr(e),s=i(()=>[...t.map(e=>{let t=e.status===void 0?[]:fr(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=i(()=>{let e=0,t=0;for(let n of s)(n.errorCount>0||n.warningCount>0)&&(t+=1),(r.get(n.row.deviceId)?.phase??n.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,r]);return o&&t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?u(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):u(`div`,{className:`h-full overflow-y-auto`,children:n(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[n(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[n(`span`,{children:[u(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),n(`span`,{children:[u(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),n(`span`,{children:[u(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),u(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>u(Lr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:r.get(e.deviceId),onlineNodes:a},e.deviceId))]})})}t();var Ur=`__cluster__`;function Wr(e){return e===`cameras`?`cameras`:`nodes`}function Gr(){let[e,t]=tt(),r=Wr(e.get(`view`)),i=e.get(`node`)??`__cluster__`,[o,s]=l(0),[c,f]=l(!1);return d(()=>{r===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Ur},{replace:!0})},[r,e,t]),n(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[n(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[u(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:i},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),u(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,r===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),u(`div`,{className:`flex items-center gap-2`,children:n(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[u(Ge,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),r===`nodes`&&n(`button`,{type:`button`,onClick:()=>f(e=>!e),"aria-expanded":c,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[n(`span`,{children:[c?`Hide`:`Show`,` node list`]}),u(ct,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),u(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:r===`nodes`?n(a,{children:[u(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:u(yt,{selectedNodeId:i,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),f(!1)},refreshToken:o})}),u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:i===`__cluster__`?u(cr,{refreshToken:o}):u(rn,{nodeId:i,refreshToken:o})})]}):u(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:u(Hr,{refreshToken:o})})})]})}export{Gr as PipelinePage};
|