@camstack/addon-admin-ui 1.2.88 → 1.2.89
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/{AddLocationWizard-BntkKU2V.js → AddLocationWizard-CYxP8ICv.js} +1 -1
- package/dist/assets/{AddonCollectionPage-DfZQjIPJ.js → AddonCollectionPage-Czx0Rf1Y.js} +1 -1
- package/dist/assets/{Addons-Cof7W-Ym.js → Addons-X9onTcjm.js} +1 -1
- package/dist/assets/{AdminTabs-FswV6m19.js → AdminTabs-BFe9RXxD.js} +1 -1
- package/dist/assets/{AiProfiles-Bol2xzPZ.js → AiProfiles-DS7dcd3T.js} +1 -1
- package/dist/assets/{BrokerForm-rlgpgB9M.js → BrokerForm-RC8ZQms1.js} +1 -1
- package/dist/assets/{Build--P11mU0s.js → Build-DYatQ35G.js} +1 -1
- package/dist/assets/{Capabilities-Di_wIznW.js → Capabilities-CdAjZZ5u.js} +1 -1
- package/dist/assets/{CapabilityBadges-BOwdQNDH.js → CapabilityBadges-mGyqruK0.js} +1 -1
- package/dist/assets/{Cluster-B58mM4Kr.js → Cluster-CIp91ynz.js} +1 -1
- package/dist/assets/{Data-uwnl2ZR0.js → Data-CmrUXYoi.js} +1 -1
- package/dist/assets/{DetectionIntelligence-wpF45dZl.js → DetectionIntelligence-D80ddmLz.js} +1 -1
- package/dist/assets/{DeviceAggregateSection-r5_ljoI1.js → DeviceAggregateSection-CmXH0Z_0.js} +1 -1
- package/dist/assets/{DeviceDetail-Bf3FJFNv.js → DeviceDetail-CY4j2jrm.js} +1 -1
- package/dist/assets/{Devices-D3k50BRl.js → Devices-C8E4qBqs.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-C2EWx5XY.js → EmbedPlayerPage-nLTLNYPt.js} +1 -1
- package/dist/assets/{Events-DuXVjBmB.js → Events-vfLnBqsv.js} +1 -1
- package/dist/assets/{FormBuilder-QY4tah4S.js → FormBuilder-CgXBJs1A.js} +1 -1
- package/dist/assets/{Identity-BV8WXb2H.js → Identity-C-6ig3ru.js} +1 -1
- package/dist/assets/{IntegrationDetail-ClwD7H7W.js → IntegrationDetail-CRrZPmmb.js} +1 -1
- package/dist/assets/{Integrations-BGbVMFT4.js → Integrations-CXvB3xLb.js} +1 -1
- package/dist/assets/{Integrations-Dy_WWWKK.js → Integrations-CnscVQeA.js} +1 -1
- package/dist/assets/{Logs-Dr2j0QZR.js → Logs-Ptalp9Ap.js} +1 -1
- package/dist/assets/{MotionZonesSettings-Ds8nYWoN.js → MotionZonesSettings-GG2onGsd.js} +1 -1
- package/dist/assets/{MyAccess-Bsf24wbg.js → MyAccess-C9X6mSCC.js} +1 -1
- package/dist/assets/{Network-D_OMCOsR.js → Network-DdfJzcEJ.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-B3-jgI6Y.js → NodeAddonsSettingsPanel-BYXH3-BP.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-vixWXUkV.js → NodeInferenceDevices-CJBU3t4h.js} +1 -1
- package/dist/assets/{Notifications-DbYpUqwt.js → Notifications-DVfJp0YC.js} +1 -1
- package/dist/assets/{Pipeline-m823fIKM.js → Pipeline-YNTCsnOx.js} +1 -1
- package/dist/assets/{Plates-BIkYeFJp.js → Plates-DzZx4BPp.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-C2nmPqsf.js → PrivacyMaskSettings-DlD5nHl0.js} +1 -1
- package/dist/assets/{ProviderIcon-yuhuUjyO.js → ProviderIcon-DaauzRy3.js} +1 -1
- package/dist/assets/{Recordings-ChPRJj_w.js → Recordings-i9RDqe2o.js} +1 -1
- package/dist/assets/{ScanNetworkModal-B6Dhtqhv.js → ScanNetworkModal-DwKJwpIs.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CpU_-6iK.js → SceneMonitorEditor-H2Z_9riR.js} +1 -1
- package/dist/assets/{Scenes-Bp-HU3HC.js → Scenes-DiJCcvjG.js} +1 -1
- package/dist/assets/{Settings-CxNCTStH.js → Settings-Clokst-N.js} +1 -1
- package/dist/assets/{Showroom-BfQj_ruk.js → Showroom-1ViARhyC.js} +1 -1
- package/dist/assets/{Terminal-COkGK9Eu.js → Terminal-mLwOsOgP.js} +5 -5
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CtfWG-B0.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BTd_JgZ5.js} +1 -1
- package/dist/assets/{bell-ring-BIkgL1EI.js → bell-ring-BPrVhIE4.js} +1 -1
- package/dist/assets/{boxes-EqdcdFpg.js → boxes-89UouT8T.js} +1 -1
- package/dist/assets/{build-cluster-graph-C0MeCzJZ.js → build-cluster-graph-Cbb1I-jq.js} +1 -1
- package/dist/assets/circle-check-big-D9ynSOrO.js +1 -0
- package/dist/assets/{circle-x-CBZPec7u.js → circle-x-Bsgek5uU.js} +1 -1
- package/dist/assets/clock-BvQlDL5a.js +1 -0
- package/dist/assets/{copy-BPgY4Eey.js → copy-BtDJ2xWI.js} +1 -1
- package/dist/assets/{debounced-invalidate-B1bc5kFD.js → debounced-invalidate-CfMppTLk.js} +1 -1
- package/dist/assets/{dist-DjbCvztb.js → dist-BJIJtrLw.js} +1 -1
- package/dist/assets/{dist-IEXliP3K.js → dist-BVCWYzWk.js} +3 -3
- package/dist/assets/{download-Dq2bfdRX.js → download-DrTCm0Zn.js} +1 -1
- package/dist/assets/{face-bbox-DUGyLE43.js → face-bbox-bnTYLJ2C.js} +1 -1
- package/dist/assets/{hard-drive-COdkuHqf.js → hard-drive-D6wUZdNf.js} +1 -1
- package/dist/assets/{hostInit-BSakAGif.js → hostInit-ZAX9mo8c.js} +1 -1
- package/dist/assets/{index-LPwis6Rq.js → index-D7fwM52p.js} +3 -3
- package/dist/assets/{key-round-CfAFZkMw.js → key-round-PssF2mH1.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-e9ffa7b9.js → mf-entry-bootstrap-0-12df8905.js} +2 -2
- package/dist/assets/{pencil-CfoKCBNv.js → pencil-DDE9Ut_f.js} +1 -1
- package/dist/assets/play-VJTjxs_g.js +1 -0
- package/dist/assets/{player-overlays-CBKaIBph.js → player-overlays-DsK1iDkv.js} +1 -1
- package/dist/assets/plus-CKJhtG9S.js +1 -0
- package/dist/assets/power-DIX0P9O_.js +1 -0
- package/dist/assets/{radio-BOUTlTbE.js → radio-Cgg_wmnh.js} +1 -1
- package/dist/assets/{refresh-cw-CllqntzE.js → refresh-cw-B06QF6BP.js} +1 -1
- package/dist/assets/remoteEntry-GRBshePF.js +1 -0
- package/dist/assets/rotate-ccw-CHuGPAms.js +1 -0
- package/dist/assets/rotate-cw-B7IVurj2.js +1 -0
- package/dist/assets/search-B9qXKjRG.js +1 -0
- package/dist/assets/{send-DcXtHjaz.js → send-CCB7-Bua.js} +1 -1
- package/dist/assets/{server-DbU7BgZv.js → server-qRR4BT4Q.js} +1 -1
- package/dist/assets/{shield-BojVNBVL.js → shield-Dhep2Fkd.js} +1 -1
- package/dist/assets/square-CfRn6ZFd.js +1 -0
- package/dist/assets/{square-check-big-Ch-X3CcM.js → square-check-big-CKJTPtsS.js} +1 -1
- package/dist/assets/src-DY4vbC0g.js +349 -0
- package/dist/assets/{src-BLHY9yig.js → src-DnZ6ZcH0.js} +3 -3
- package/dist/assets/{star-BotqSaGv.js → star-Cfry0hZj.js} +1 -1
- package/dist/assets/{undo-2-CXIWJrgH.js → undo-2-CP7k5Csp.js} +1 -1
- package/dist/assets/{upload-CafOTsXz.js → upload-DKCLx4MR.js} +1 -1
- package/dist/assets/{use-scenes-feed-DTuzztEP.js → use-scenes-feed-Cf4dSlYi.js} +1 -1
- package/dist/assets/useEventInvalidation-CINdEbPJ.js +1 -0
- package/dist/assets/{video-GQHe9bLG.js → video-LCt0QHTC.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-7s6IgvIP.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D-HrWJSs.js} +2 -2
- package/dist/assets/{wifi-MOwlhPpo.js → wifi-BHTVIRt4.js} +1 -1
- package/dist/assets/{zap-BiojyRpM.js → zap-BXQ1pVxK.js} +1 -1
- package/dist/index.html +5 -5
- package/dist/server/addon.js +17 -9
- package/package.json +1 -1
- package/dist/assets/circle-check-big-DGl1OsLR.js +0 -1
- package/dist/assets/clock-M4NiOyl_.js +0 -1
- package/dist/assets/play-CqrjGyv7.js +0 -1
- package/dist/assets/plus-DHRgxEWi.js +0 -1
- package/dist/assets/power-DGhEdOiQ.js +0 -1
- package/dist/assets/remoteEntry-BsYVmvk8.js +0 -1
- package/dist/assets/rotate-ccw-CdTrnBTI.js +0 -1
- package/dist/assets/rotate-cw-Dre2EA6E.js +0 -1
- package/dist/assets/search-Dx_k5G37.js +0 -1
- package/dist/assets/square-DynbJcCj.js +0 -1
- package/dist/assets/src-0pbBUmTo.js +0 -349
- package/dist/assets/useEventInvalidation-BDOhX3vo.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,T as i,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as p}from"./player-overlays-CBKaIBph.js";import{$ as m,$a as h,Aa as g,B as _,Ba as v,Bt as y,Da as b,Ea as x,Fa as S,Fs as C,Ga as w,Ht as T,Ia as E,Is as D,It as O,J as k,Ja as A,Jt as ee,Ka as j,La as M,Ls as N,Ma as P,Na as F,Oa as I,Pa as L,Ps as R,Qa as z,Ra as te,Rs as ne,Rt as re,Ua as B,Vt as ie,Xa as ae,Ya as oe,b as se,co as ce,d as le,do as ue,eo as de,gn as fe,h as pe,hn as me,i as he,ja as ge,ka as _e,ln as ve,lo as ye,no as be,po as xe,ro as Se,ta as V,to as Ce,u as we,uo as Te,vn as Ee,zt as De}from"./src-BLHY9yig.js";import{n as Oe}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{Lt as ke,Rt as Ae,bt as je,f as Me,h as Ne,p as Pe}from"./src-0pbBUmTo.js";import{a as Fe,d as Ie,i as Le,l as Re,n as H,o as ze,r as Be,t as Ve,u as He}from"./NodeInferenceDevices-vixWXUkV.js";import{t as Ue}from"./download-Dq2bfdRX.js";import{t as We}from"./hard-drive-COdkuHqf.js";import{n as Ge,t as Ke}from"./video-GQHe9bLG.js";import{t as qe}from"./pencil-CfoKCBNv.js";import{t as Je}from"./plus-DHRgxEWi.js";import{t as Ye}from"./radio-BOUTlTbE.js";import{t as Xe}from"./refresh-cw-CllqntzE.js";import{t as Ze}from"./search-Dx_k5G37.js";import{t as Qe}from"./server-DbU7BgZv.js";import{t as $e}from"./square-check-big-Ch-X3CcM.js";import{t as et}from"./square-DynbJcCj.js";import{t as tt}from"./zap-BiojyRpM.js";import{C as U,D as nt,E as rt,F as it,I as at,K as ot,N as W,O as st,P as ct,R as lt,X as ut,a as dt,i as ft,o as pt,s as mt,z as ht}from"./index-LPwis6Rq.js";import{t as gt}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-BDOhX3vo.js";import{r as _t,t as vt}from"./build-cluster-graph-C0MeCzJZ.js";import{n as yt}from"./format-size-CO9d3C3-.js";import{t as bt}from"./NodeAddonsSettingsPanel-B3-jgI6Y.js";var xt=ot(`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`}]]),St=ot(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),Ct=ot(`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`}]]);n();function wt(e){return e}function Tt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Et(e,t){return typeof e==`boolean`?e:wt(t)}function Dt(e,t){return{pipeline:Et(Tt(e,`detect`),t),audio:Et(Tt(e,`audio`),t),ingest:Et(Tt(e,`ingest`),t)}}function Ot(e,t,n){let r=e?.find(e=>e.nodeId===t);return Dt(r?.settings,n)}function kt({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:i}=V(void 0),{data:a}=w(void 0),{data:s}=A(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return r(`div`,{className:`flex flex-col h-full`,children:[r(`button`,{type:`button`,onClick:()=>t(ni),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[d(rt,{className:`h-4 w-4 flex-shrink-0`}),r(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let i=e===n.id,a=c.get(n.id)??0,l=n.isHub?Qe:W,u=Ot(s,n.id,n.isHub),f=n.isOnline?null:_(_t(n.lastSeen));return r(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),r(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[r(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),r(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&r(o,{children:[d(`span`,{children:`•`}),r(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(Ke,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&r(o,{children:[d(`span`,{children:`•`}),r(`span`,{className:`text-destructive`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),r(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(O,{variant:u.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),d(O,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),r(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[r(`span`,{children:[u,` online`]}),f>0&&r(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function At({nodeId:e,refreshToken:t}){let{data:n}=V(void 0),i=n?.find(t=>t.id===e),a=C(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?r(`div`,{className:`px-6 py-4 border-b border-border`,children:[r(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),i.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),r(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:i.cpuModel??`CPU`}),d(`span`,{children:`•`}),r(`span`,{children:[i.cpuCores,` cores`]}),d(`span`,{children:`•`}),r(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),a&&r(o,{children:[d(`span`,{children:`•`}),r(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),r(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),r(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&r(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:r(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function jt({refreshToken:e,nodeId:t}){let[n,i]=u(new Map),{nodes:o}=R();N(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&i(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=te(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[l,o]);if(t){let e=l.get(t);return r(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),r(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(G,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(G,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(G,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(G,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(G,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return r(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),r(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(G,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(G,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(G,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(G,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(G,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),r(`tbody`,{children:[m.map(([e,t])=>r(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function G({label:e,value:t}){return r(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}n();var Mt={active:!1,pinned:!1,nodeId:null,reason:``},Nt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],Pt=3e5,Ft={pipeline:W,decoder:st,audio:Ge},It={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function Lt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let s=c(),[l,p]=u(null),[m,h]=u(null),[g,_]=u(new Map);he([`pipelineOrchestrator`,`getPipelineAssignments`],Nt),he([`pipelineOrchestrator`,`getAudioAssignments`],Nt),he([`pipelineOrchestrator`,`getCameraStatuses`],Nt);let{data:y}=w(void 0),{data:b}=M(void 0),{data:x}=v({},{enabled:e===`agent`}),{nodes:S}=R(),{data:C}=Re();N(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&_(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),f(()=>{if(g.size===0)return;let e=setInterval(()=>{_(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)},[g.size]);let T=a(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),E=a(()=>{if(e===`agent`){let e=[];for(let n of x??[]){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:T.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:T.get(e)??`Device ${e}`,pipeline:Mt,decoder:Mt,audio:Mt};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 b??[]){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,b,x,T,e,t]),D=a(()=>(S??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[S]),O=()=>{s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},k=L({onSuccess:O}),A=Te({onSuccess:O}),j=F({onSuccess:O}),P=ye({onSuccess:O}),I=(e,t,n)=>{t===`pipeline`?k.mutate({deviceId:e,agentNodeId:n}):j.mutate({deviceId:e,nodeId:n}),p(null)},z=(e,t)=>{t===`pipeline`?A.mutate({deviceId:e}):P.mutate({deviceId:e}),p(null)};return d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[d(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&d(`th`,{className:`w-10`}),d(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?r(o,{children:[d(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),d(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):r(o,{children:[d(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),d(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),d(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),d(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),r(`tbody`,{children:[E.map(t=>{let a=g.get(t.deviceId),s=m===t.deviceId;return r(i.Fragment,{children:[r(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&d(`td`,{className:`px-2 py-2 align-middle`,children:d(`button`,{type:`button`,onClick:()=>h(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:d(s?lt:at,{className:`h-3.5 w-3.5`})})}),r(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[d(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),r(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?r(o,{children:[d(`td`,{className:`px-3 py-2 align-middle`,children:d(zt,{state:t.pipeline,onlineNodes:D,pending:k.isPending||A.isPending,onChange:e=>{e===`auto`?z(t.deviceId,`pipeline`):I(t.deviceId,`pipeline`,e)}})}),d(`td`,{className:`px-3 py-2 align-middle`,children:d(Vt,{state:t.pipeline,deviceId:t.deviceId})})]}):r(o,{children:[d(Ut,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:l?.deviceId===t.deviceId&&l.role===`pipeline`,onToggleMenu:()=>p(l?.deviceId===t.deviceId&&l.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>p(null),onMove:e=>I(t.deviceId,`pipeline`,e),onUnpin:()=>z(t.deviceId,`pipeline`)}),d(Ut,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:D,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),d(Ut,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:l?.deviceId===t.deviceId&&l.role===`audio`,onToggleMenu:()=>p(l?.deviceId===t.deviceId&&l.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>p(null),onMove:e=>I(t.deviceId,`audio`,e),onUnpin:()=>z(t.deviceId,`audio`)})]}),d(`td`,{className:`px-3 py-2 align-middle`,children:d(qt,{snap:a})})]}),s&&!n&&r(`tr`,{className:`bg-surface/50`,children:[d(`td`,{}),r(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&d(Rt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),d(ee,{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)}),E.length===0&&d(`tr`,{children:d(`td`,{colSpan:n?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 Rt({deviceId:e,nodeId:t}){let n=c(),{data:i}=B({nodeId:t}),{data:a}=j({deviceId:e}),o=ce({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),s=i?.devices??[],l=a?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l);return r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[d(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),r(`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:[d(`option`,{value:`auto`,children:`Auto (balanced)`}),u&&r(`option`,{value:l,children:[`Pin → `,l,` (not on this node)`]}),s.map(e=>r(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&d(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function zt({state:e,onlineNodes:t,pending:n,onChange:i}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return r(`select`,{value:a,disabled:n,"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:[d(`option`,{value:`auto`,children:`Auto`}),o.map(e=>r(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Bt(e){let n=t(null);return e.nodeId!==null&&(n.current=e),n.current}function Vt({state:e,deviceId:t}){let n=Bt(e),i=e.active&&e.nodeId!==null;if(n===null||n.nodeId===null)return d(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`— · no session yet`});let a=n.pinned?`pinned · manual`:`auto · ${n.reason||`capacity`}`;return r(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[d(`span`,{className:`font-mono text-[11px] truncate ${i?`text-foreground`:`text-foreground-subtle`}`,title:n.pinned?n.nodeId:`${n.nodeId} — an unpinned camera is re-elected per on-motion session, so this can change between sessions`,children:n.nodeId}),d(`span`,{className:`truncate ${n.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:a,children:a}),d(`span`,{className:`truncate text-[10px] ${i?`text-emerald-400`:`text-foreground-subtle/70`}`,children:i?`● running here`:`○ idle · last session here`}),d(Ht,{deviceId:t,nodeId:n.nodeId})]})}function Ht({deviceId:e,nodeId:t}){let n=c(),{data:i}=j({deviceId:e},{refetchOnMount:`always`}),{data:a}=B({nodeId:t},{staleTime:Pt}),o=ce({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return d(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let s=a.devices??[],l=s.filter(e=>e.enabled),u=i.deviceKey??`auto`,f=u!==`auto`&&!l.some(e=>e.key===u),p=s.find(e=>e.key===u);return r(`select`,{value:u,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:[d(`option`,{value:`auto`,children:`Auto (balanced)`}),f&&r(`option`,{value:u,children:[p?`${H(p).label} (${u})`:u,` (not enabled)`]}),l.map(e=>r(`option`,{value:e.key,children:[H(e).label,` · `,e.format]},e.key))]})}function Ut({role:e,state:t,mode:n,onlineNodes:i,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:l,onUnpin:u}){let f=Ft[e],p=i.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||n===`cluster`)&&(p.length>0||t.pinned);return r(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[d(n===`agent`?Wt:Gt,{state:t,Icon:f}),d(`div`,{className:`ml-auto shrink-0`,children:m&&d(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${It[e]} actions`,children:d(xt,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&d(Jt,{title:It[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:u,onClose:c})]})}function Wt({state:e,Icon:t}){return r(`div`,{className:`flex items-center gap-1.5`,children:[d(e.active?$e:et,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),d(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&d(Ct,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Gt({state:e,Icon:t}){return!e.active||!e.nodeId?r(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[d(t,{className:`h-3 w-3`}),d(`span`,{className:`text-[10px] italic`,children:`—`})]}):r(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),r(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[d(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),d(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?r(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[d(Ct,{className:`h-2.5 w-2.5`}),` manual`]}):r(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Kt=`min-h-[3.25rem]`;function qt({snap:e}){if(!e)return d(`div`,{className:`flex items-center ${Kt}`,children:d(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=m(t);return r(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Kt}`,children:[r(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[d(pe,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),r(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),r(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),r(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[d(`span`,{className:`text-foreground`,children:i.toFixed(0)}),d(`span`,{children:` ms`}),a>0&&r(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),r(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,d(`span`,{className:`text-foreground`,children:s})]})]})}function Jt({title:e,targets:n,pinned:i,onMove:a,onUnpin:o,onClose:s}){let c=t(null);return f(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),r(`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:[d(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),n.length>0&&d(`div`,{className:`py-1`,children:n.map(e=>r(`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&&r(`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 `,e.toLowerCase()]}),n.length===0&&!i&&d(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Yt({nodeId:e,refreshToken:t}){return r(`div`,{className:`space-y-6`,children:[d(jt,{refreshToken:t,nodeId:e}),r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),r(`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.`]})]}),d(Lt,{mode:`agent`,nodeId:e,compact:!0})]})}n();function Xt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Zt({nodeId:e,refreshToken:t}){let n=c(),i=ge({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=P({nodeId:e}),s=C(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,l=s===null;he([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:u}=xe({nodeId:e}),{values:f}=D(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),p=a(()=>f.filter(e=>e.metrics.phase===`active`).length,[f]),m=t=>{let n=u??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||i.mutate({nodeId:e,engine:t,force:n.length>0})};return r(`div`,{className:`space-y-6`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(s??[]).length,` engine(s) resident in RAM. `,(u??[]).length,` `,`camera(s) attached, `,p,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),r(`tbody`,{children:[l&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!l&&(s??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return r(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:r(`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`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[d(t?St:n?Ie:W,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:r(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(tt,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),d(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?d(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>d(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),d(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),d(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?d(`span`,{className:`text-foreground-subtle`,children:Xt(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(u??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:n?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):r(`button`,{type:`button`,disabled:i.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:[d(mt,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!l&&(s??[]).length===0&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),r(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),i.isError&&r(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,i.error instanceof Error?i.error.message:`unknown`]})]})}n();var Qt=new Set(je);function $t(e){return Qt.has(e)}function en(e,t,n){return`${e}/${t}/${n}`}function tn(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function nn(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function K(e){return e.format}function rn(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function an({addonId:e,model:t,format:n,isActive:i,progress:a,errorMsg:o,onDownload:s,onDelete:c}){let l=t.formats[n];return l?r(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[d(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${l.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),r(`div`,{className:`flex-1 min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),a&&a.progress>=0&&a.progress<100&&r(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[d(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:d(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${a.progress}%`}})}),r(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(a.progress),`%`]})]})]}),d(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:yt(l.sizeMB)}),o&&r(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:o,children:[d(it,{className:`h-3 w-3 shrink-0`}),o]}),l.downloaded?r(`button`,{onClick:c,disabled:i,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[i?d(U,{className:`h-3 w-3 animate-spin`}):d(mt,{className:`h-3 w-3`}),i?`Deleting...`:`Delete`]}):r(`button`,{onClick:s,disabled:i,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[i?d(U,{className:`h-3 w-3 animate-spin`}):d(Ue,{className:`h-3 w-3`}),i?`Downloading...`:`Download`]})]}):null}function on({engines:e,activeEngine:t,viewEngine:n,onSelect:i}){let[a,o]=u(!1);return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>o(!a),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[d(W,{className:`h-4 w-4 text-primary shrink-0`}),r(`div`,{className:`flex-1 min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-sm font-medium text-foreground`,children:tn(n)}),K(n)===K(t)&&d(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:nn(n)})]}),d(lt,{className:`h-4 w-4 text-foreground-subtle transition-transform ${a?`rotate-180`:``}`})]}),a&&d(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let a=K(e)===K(n),s=K(e)===K(t);return r(`button`,{type:`button`,onClick:()=>{i(e),o(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${a?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[d(W,{className:`h-4 w-4 shrink-0 ${a?`text-primary`:`text-foreground-subtle`}`}),r(`div`,{className:`flex-1`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-sm font-medium ${a?`text-primary`:`text-foreground`}`,children:tn(e)}),s&&d(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:nn(e)})]}),a&&d(ct,{className:`h-4 w-4 text-primary shrink-0`})]},K(e))})})]})}function sn({embedded:t=!1,nodeId:n}={}){let i=c(),a=n??`hub`,[s,l]=u(null),[f,p]=u(new Set),[m,h]=u(new Map),[_,v]=u(new Map),[y,S]=u(``),{data:C=[]}=I({nodeId:a}),w=C.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:E}=g({nodeId:a}),D=E,{data:O,isLoading:k}=_e({nodeId:a}),A=b(),ee=x();N(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,r=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||r===void 0||(h(e=>{let t=new Map(e);return r===100||r===-1?t.delete(n):t.set(n,{modelId:n,progress:r,totalMB:a}),t}),r===100&&i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let j=D??{runtime:`node`,backend:`cpu`,format:`onnx`},M=w.find(e=>e.format===s)??j,P=M.format,F=e=>e.formats[P]?.downloaded===!0,L=O?.slots??[],R=L.map(e=>({...e,addons:e.addons.map(e=>({...e,models:T(e.models,P)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),z=rn(R,P),te=e(async(e,t,n)=>{if(!$t(n))return;let r=en(e,t,n);p(e=>new Set([...e,r])),v(e=>{let t=new Map(e);return t.delete(r),t});try{await A.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){v(t=>new Map([...t,[r,e instanceof Error?e.message:`Download failed`]]))}finally{p(e=>{let t=new Set(e);return t.delete(r),t})}},[A,i,a]),ne=e(async(e,t,n)=>{if(!$t(n))return;let r=en(e,t,n);p(e=>new Set([...e,r])),v(e=>{let t=new Map(e);return t.delete(r),t});try{await ee.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){v(t=>new Map([...t,[r,e instanceof Error?e.message:`Delete failed`]]))}finally{p(e=>{let t=new Set(e);return t.delete(r),t})}},[ee,i,a]),re=e(e=>{l(e.format)},[]),B=y.trim()?R.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(y.toLowerCase())||t.id.toLowerCase().includes(y.toLowerCase())||e.name.toLowerCase().includes(y.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):R,ie=r(o,{children:[k&&d(`div`,{className:`flex items-center justify-center py-16`,children:d(U,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!k&&L.length===0&&r(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[d(We,{className:`h-8 w-8 mb-3 opacity-30`}),d(`span`,{className:`text-sm`,children:`No pipeline steps available`}),d(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!k&&L.length>0&&r(o,{children:[d(on,{engines:w,activeEngine:j,viewEngine:M,onSelect:re}),r(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[r(`span`,{children:[d(`span`,{className:`font-semibold text-foreground tabular-nums`,children:z.total}),d(`span`,{className:`ml-1`,children:`compatible models`})]}),d(`span`,{className:`text-border`,children:`|`}),r(`span`,{children:[d(`span`,{className:`font-semibold text-success tabular-nums`,children:z.downloaded}),d(`span`,{className:`ml-1`,children:`downloaded`})]}),d(`span`,{className:`text-border`,children:`|`}),r(`span`,{className:`tabular-nums`,children:[yt(z.downloadedSizeMB),d(`span`,{className:`ml-1`,children:`on disk`})]})]}),z.total>5&&r(`div`,{className:`relative`,children:[d(Ze,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:y,onChange:e=>S(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),B.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+T(t.models,P).filter(F).length,0);return r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[d(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),d(`div`,{className:`flex-1 h-px bg-border`}),r(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=en(e.id,t.id,P);return d(an,{addonId:e.id,model:t,format:P,isActive:f.has(n),progress:m.get(t.id),errorMsg:_.get(n),onDownload:()=>te(e.id,t.id,P),onDelete:()=>ne(e.id,t.id,P)},`${e.id}/${t.id}`)}))})]},e.id)}),B.length===0&&d(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:y.trim()?r(o,{children:[`No models matching “`,y,`”`]}):r(o,{children:[`No models available for `,tn(M),` format`]})})]})]});return t?d(`div`,{className:`space-y-4`,children:ie}):d(gt,{children:ie})}function cn({nodeId:e,refreshToken:t}){return d(sn,{embedded:!0,nodeId:e})}var ln=`pipeline-runner`,un=200;function dn({nodeId:e}){return r(`div`,{className:`flex flex-col gap-3`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(k,{agentId:e,addonId:ln,limit:un,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}n(),n();function fn({nodeId:e,title:t}){let{data:n}=Re(),{data:i}=w(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of i??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,i]),[c,l]=u(new Map);N(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||l(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),f(()=>{if(c.size===0)return;let e=setInterval(()=>{l(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=a(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return p.length===0?r(`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`]}):r(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[r(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:p.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=m(e.metrics.phase);return r(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[d(pe,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var pn=`pipeline-orchestrator`;function mn(e){return Me.find(t=>t.stepId===e)??null}function hn({title:e}){return d(`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 gn({step:e,engineFormat:t,runnableModelIds:n}){let i=c(),{data:a,isLoading:o}=fe({addonId:pn}),s=Ee({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),l=Ne(a??null)[e.stepId]??e.defaultModelId,u=n.length>0&&!n.includes(l);return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[r(`div`,{className:`flex items-center text-[11px] font-medium text-foreground`,children:[e.label,d(hn,{})]}),r(`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?d(U,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):d(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,disabled:s.isPending,onChange:t=>{t.target.value!==l&&s.mutate({addonId:pn,patch:{[Pe(e.stepId)]:t.target.value}})},children:e.options.map(t=>r(`option`,{value:t.id,children:[t.label,t.id===e.defaultModelId?` (default)`:``]},t.id))}),u&&r(`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 `,d(`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.`]}),d(`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.`})]})}n();function q(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 _n(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 vn({nodeId:e,refreshToken:t}){let n=c(),[i,s]=u(null),[l,f]=u(null),[p,m]=u(``),[h,g]=u(null),_=B({nodeId:e},{refetchOnMount:`always`}),v=_e({nodeId:e},{refetchOnMount:`always`}),b=Ne(fe({addonId:`pipeline-orchestrator`}).data??null),x=_.data?.devices??[],S=be({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),C=a(()=>v.data?we(v.data):[],[v.data]),w=a(()=>x.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:H(t).label})),[x,e]),E=e=>x.find(t=>t.key===e)??null,D=a(()=>x.filter(e=>e.enabled),[x]),O=D.length>=2,k=(e,t)=>ie(q(v.data??null,e)?.models??[],t?.format),A=e=>{let t=E(e);return t?H(t).label:e},ee=(e,t)=>D.filter(n=>n.key!==t&&k(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,j=e=>{let t=q(v.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},M=(e,t)=>{let n=q(v.data??null,e);if(n)return De(n,t)},N=(e,t)=>{let n=j(e),r=n.kind===`gate`?n.effectiveOn:!1,i=q(v.data??null,e),a=t.deviceKey===void 0?null:E(t.deviceKey),o=ie(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&D.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:ee(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:A(i)}}let c=mn(e);return c?{kind:`enabled`,modelId:b[e]??c.defaultModelId,clusterWide:!0}:{kind:`enabled`,modelId:(i?y({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&D.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:A(s.jumpDeviceKey)}:{}}},P=i&&v.data?q(v.data,i.addonId):null,F=i?E(i.deviceKey):null,I=F?.format??`coreml`,L=i?M(i.addonId,F):void 0,R=()=>{s(null),f(null),m(``)},z=(e,t)=>{if(t.deviceKey===void 0)return;let n=E(t.deviceKey)?.steps?.[e];s({addonId:e,deviceKey:t.deviceKey});let r=n?.settings??Fe(x.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??``)},te=()=>{if(!i)return;let t=_n(l),n=p!==``&&p!==i.deviceKey?p:void 0,r=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,a=x.map(e=>{let t={...e.steps};return e.key===i.deviceKey&&(r?t[i.addonId]=r:delete t[i.addonId]),{key:e.key,enabled:e.key===i.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}}),o=r?.settings!==void 0&&Object.keys(r.settings).length>0?ze(a,i.deviceKey,i.addonId):a;S.mutate({agentNodeId:e,inferenceDevices:Le(o)},{onSuccess:R})};if(_.isLoading||v.isLoading)return d(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(x.length===0)return d(`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(!v.data)return d(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ne=i!==null&&P!==null&&F!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`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`,` `,d(`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.`]}),d(`div`,{className:ne?`md:pr-[360px]`:``,children:C.length>0?d(se,{tree:C,agents:w,gateFor:j,getCellState:N,onCellClick:z,selectedCell:i?{addonId:i.addonId,agentNodeId:e,deviceKey:i.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:h,onFallbackNodeChange:g,hideGate:!0}):d(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),d(le,{open:ne,onClose:R,title:P?.name??``,subtitle:i&&F?`${e} · ${H(F).label} · ${F.format}`:``,footer:r(o,{children:[d(`div`,{className:`flex-1`}),d(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:R,children:`Cancel`}),d(`button`,{type:`button`,disabled:!i||!l||S.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:te,children:S.isPending?`Saving…`:`Save`})]}),children:P&&i&&mn(i.addonId)?d(gn,{step:mn(i.addonId),engineFormat:I,runnableModelIds:T(P.models??[],I).map(e=>e.id)}):P&&i&&l?r(`div`,{className:`space-y-3`,children:[O&&r(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[d(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),r(`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:[d(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),D.filter(e=>e.key!==i.deviceKey).map(e=>r(`option`,{value:e.key,children:[H(e).label,` · `,e.format]},e.key))]}),d(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),d(re,{mode:`agent`,addon:P,agentDefault:l,agentNodeId:e,engineFormat:I,effectiveModelId:L,onChangeAgentConfig:f})]}):d(`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.`})})]})}n();var yn=[`pipeline-orchestrator`],bn=[`decoder`],xn=!1;function Sn({nodeId:e,refreshToken:t}){let n=ve(),[i,a]=u(null),[o,s]=u(null),c=(V(void 0).data??[]).find(t=>t.id===e),l=c?.name??e,f=c?.isOnline??!1,p=z({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)`)}}),m=async()=>{await n({title:`Reset ${l} 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),p.mutate({agentNodeId:e}))};return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&d(`span`,{className:`text-emerald-400`,children:o}),p.isError&&d(`span`,{className:`text-red-400`,children:p.error instanceof Error?p.error.message:`Reset failed`}),d(`button`,{type:`button`,onClick:()=>{m()},disabled:p.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:p.isPending?`Resetting…`:`Reset to default`})]}),d(fn,{nodeId:e}),d(bt,{nodeId:e,addonIds:yn,level:`global`,sectionIds:bn}),xn,xn,r(`div`,{children:[d(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),d(Ve,{nodeId:e,nodeName:l,isOnline:f})]}),r(`div`,{children:[d(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),d(vn,{nodeId:e,refreshToken:t})]})]})}var Cn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],wn=`decoder-nodeav`;function Tn({nodeId:e,refreshToken:t}){let{data:n}=V(void 0),i=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??wn,a=[...Cn,i];return r(`div`,{className:`flex flex-col h-full`,children:[d(At,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:d(bt,{nodeId:e,addonIds:a,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:d(Yt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:d(Sn,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:d(Zt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:d(cn,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:d(dn,{nodeId:e})}]})})]})}function En(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 Dn={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 On(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function kn(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:En(e),format:e.format,sessions:i,queueDepth:r?.queueDepth??0,weight:a,weightSharePct:e.exclusion===null?On(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 An(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=kn(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?On(l,i.maxCameras):null,queueDepthTotal:a?.load.queueDepthTotal??null,avgInferenceTimeMs:a?.load.avgInferenceTimeMs??null,score:a?.score??null,weight:c,weightSharePct:s?On(c,n):null,cameraSharePct:l===null?null:On(l,r),decodeHwaccel:a?.decodeHwaccel??null,devices:o,eligibleDeviceCount:o.filter(e=>e.exclusion===null).length}})}var jn=`pipeline-orchestrator`,Mn=`recorder`,Nn=`recordingNodeId`,Pn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],Fn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function In(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function Ln(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Rn(e,t,n){let r=In(e,t);return typeof r==`string`&&r.length>0?r:n}function zn(e,t,n){let r=In(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function Bn(e,t){let n=Ln(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function Vn(e,t){let n=Ln(e,t);return typeof n==`string`&&n.length>0?n:null}function Hn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function Un(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`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function Wn(e,t){switch(t){case`detect`:return e.pipeline}}function Gn(e){return e instanceof Error?e.message:`Failed to save`}function Kn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}n();var qn=2e4,Jn=3e5;function Yn(){let{nodes:e}=R(),t=p().trpcClient,n=E(void 0,{placeholderData:l,staleTime:qn,refetchInterval:qn,refetchOnWindowFocus:!0}),i=A(void 0,{staleTime:Jn}),o=a(()=>e.map(e=>e.id),[e]),c=s({queries:o.map(e=>({queryKey:Oe(ne.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>t.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Jn,refetchOnWindowFocus:!1,placeholderData:l}))}),u=a(()=>{let e={};return o.forEach((t,n)=>{let r=c[n]?.data;r&&(e[t]=r.devices)}),e},[o,c.map(e=>e.dataUpdatedAt).join(`|`)]),f=a(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),m=a(()=>e.map(e=>{let t=f.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:Dt(t,e.isHub).pipeline,weight:Bn(t,`detectWeight`)??1,maxCameras:Bn(t,`maxCameras`)}}),[e,f]),h=n.data??[],g=a(()=>An({nodes:m,loads:h,devicesByNode:u}),[m,h,u]),_=g.reduce((e,t)=>e+(t.attachedCameras??0),0),v=g.reduce((e,t)=>e+(t.activeCameras??0),0),y=n.dataUpdatedAt>0?Date.now()-n.dataUpdatedAt:null;return r(`section`,{className:`rounded-md border border-border bg-surface px-3 py-2.5`,children:[r(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 mb-2`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Node load`}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[v,` running · `,_,` attached across `,g.length,` `,g.length===1?`node`:`nodes`]}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle/70 tabular-nums`,children:n.data===void 0?`reading…`:`reading ${y===null?`—`:`${Math.round(y/1e3)}s`} old · every ${qn/1e3}s`})]}),g.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:g.map(e=>d(Xn,{row:e},e.nodeId))})]})}function Xn({row:e}){let t=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return r(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[r(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&r(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[d(pt,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&r(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(dt,{className:`h-2.5 w-2.5`}),` offline`]})]}),r(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:t,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`detectWeight normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share`,value:e.cameraSharePct===null?`—`:`${e.cameraSharePct}%`,title:`Share of the cluster's attached cameras this node carries right now.`}),d(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(Zn,{row:e})]})}function Zn({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):r(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[r(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(nt,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(Qn,{device:e},e.key))})]})}function Qn({device:e}){let t=e.exclusion;return r(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(W,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?r(o,{children:[r(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),r(`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&&r(`span`,{className:`shrink-0 tabular-nums text-amber-400`,children:[`· q`,e.queueDepth]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):r(`span`,{className:`truncate text-foreground-subtle/80`,title:Dn[t],children:[`excluded — `,Dn[t]]})]})}function J({label:e,value:t,title:n}){return r(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function $n(){return r(`div`,{className:`space-y-6`,children:[d(fn,{title:`Cluster cameras`}),d(Yn,{}),r(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),d(`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.`})]}),d(Lt,{mode:`cluster`})]})}function er({capability:e,label:t,hint:n,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`,u=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,f=a?ht:He;return r(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${i}`,title:`${t} — ${n}`,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} ${u}`,children:[d(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),d(`span`,{children:t})]})}function tr({node:e,emphasis:t=!1}){let n=e.isHub?Qe:W;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(O,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(O,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}n();function nr({nodeId:e,value:t,detectedHosts:n,status:i,errorMessage:a,onCommit:o}){let[s,c]=u(t??``);f(()=>{c(t??``)},[t]);let l=n[0],p=l===void 0?`auto-detect`:`auto: ${l}`,m=i===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return r(`div`,{className:`flex items-center gap-1.5`,children:[d(`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`}),r(`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?d(U,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):d(ht,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&i===`success`&&d(ht,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&d(`span`,{title:a??`Failed to save reachable host`,children:d(it,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}function rr({label:e,children:t}){return r(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function ir({node:e,actions:t}){return r(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[d(tr,{node:e,emphasis:!0}),d(`div`,{className:`grid grid-cols-2 gap-2`,children:Fn.map(n=>d(er,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Wn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),d(`div`,{className:`space-y-3 border-t border-border pt-3`,children:d(rr,{label:`Reachable host`,children:d(nr,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function ar(){return r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function or({nodes:e,actions:t}){return d(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:r(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[d(`thead`,{children:r(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[d(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),Fn.map(e=>d(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),d(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),d(`tbody`,{children:e.map(e=>r(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[d(`td`,{className:`px-4 py-3 align-middle`,children:d(tr,{node:e})}),Fn.map(n=>d(`td`,{className:`px-3 py-3 text-center align-middle`,children:d(er,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Wn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),d(`td`,{className:`px-4 py-3 align-middle`,children:d(nr,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function sr({role:e,value:t,options:n,pending:i,onChange:a}){return r(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[d(`span`,{className:`text-xs font-semibold text-foreground`,children:Hn(e)}),d(`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:n.map(e=>d(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),d(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Un(e)})]})}function cr({roleValues:e,options:t,pending:n,lowFpsEnabled:i,fpsMinThreshold:a,onRoleChange:o,onLowFpsToggle:s}){return r(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[Pn.map(r=>d(sr,{role:r,value:e[r],options:t,pending:n,onChange:o},r)),r(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[d(`input`,{type:`checkbox`,checked:i,disabled:n,onChange:e=>s(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),r(`span`,{className:`flex flex-col gap-0.5`,children:[d(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),r(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,i?`${a} fps`:`disabled`]})]})]})]})}n();function lr(){let e=c(),{nodes:t}=R(),n=A(void 0),i=fe({addonId:jn}),s=fe({addonId:Mn}),l=()=>Kn(e),f=de({onSuccess:l}),p=Ce(),m=Se({onSuccess:l}),h=Ee({onSuccess:l}),[g,_]=u(!1),v=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),y=a(()=>t.map(e=>{let t=v.get(e.id),n=Dt(t,e.isHub),r=Bn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:Bn(t,`maxCameras`),reachableHost:Vn(t,`reachableHost`),detectedHosts:e.localIps}}),[t,v]),b=y.filter(e=>e.effective.pipeline),x={ingestNode:Rn(i.data,`ingestNode`,`hub`),recordingNode:Rn(s.data,Nn,`hub`),audioNode:Rn(i.data,`audioNode`,`hub`),motionNode:Rn(i.data,`motionNode`,`hub`)},S=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...Pn.map(e=>x[e]),...e])].filter(e=>e.length>0)},[t,x]),C=zn(i.data,`fpsMinThreshold`,0),w=C>0,T=n.isLoading||i.isLoading||s.isLoading,E=(e,t,n)=>{f.mutate({agentNodeId:e,[t]:n})},D=(e,t)=>{if(e===`recordingNode`){h.mutate({addonId:Mn,patch:{[Nn]:t}});return}h.mutate({addonId:jn,patch:{[e]:t}})},O=e=>{h.mutate({addonId:jn,patch:{fpsMinThreshold:e?Math.max(1,C):0}})},k=e=>m.variables?.agentNodeId===e?m.isPending?`pending`:m.isError?`error`:m.isSuccess?`success`:`idle`:`idle`,ee=e=>k(e)===`error`?Gn(m.error):null,j=async e=>{_(!0);try{for(let t of e)await p.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{_(!1),l()}},M={capabilityPending:f.isPending,onToggleCapability:E,onCommitReachableHost:(e,t)=>m.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:k,reachableHostErrorMessage:ee};return r(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[r(`header`,{className:`flex items-start justify-between gap-4`,children:[r(`div`,{className:`space-y-1`,children:[d(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),d(`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.`})]}),T&&d(U,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),r(`div`,{className:`space-y-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),d(cr,{roleValues:x,options:S,pending:h.isPending,lowFpsEnabled:w,fpsMinThreshold:C,onRoleChange:D,onLowFpsToggle:O})]}),r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),d(ar,{})]}),y.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):r(o,{children:[d(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:y.map(e=>d(ir,{node:e,actions:M},e.id))}),d(`div`,{className:`hidden @3xl/clustertab:block`,children:d(or,{nodes:y,actions:M})})]})]}),r(`div`,{className:`space-y-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),d(Be,{nodes:b,pending:g,onCommitWeights:e=>void j(e)})]}),r(`div`,{className:`space-y-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),b.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):d(`div`,{className:`space-y-2`,children:b.map(e=>d(Ve,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}n();var ur=!1;function dr({refreshToken:e}){let t=c(),{data:n}=V(void 0);a(()=>vt(n??[]),[n]);let i=ae({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return r(`div`,{className:`space-y-6`,children:[d(jt,{refreshToken:e}),d(lr,{}),ur,r(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[r(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),d(`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.`})]}),r(`button`,{type:`button`,onClick:()=>i.mutate(void 0),disabled:i.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:[d(tt,{className:`h-3.5 w-3.5`}),i.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var fr=[`pipeline-orchestrator`],pr=`pipeline-analytics`,mr=`face-gallery`;function hr({refreshToken:e}){return r(`div`,{className:`space-y-4 max-w-3xl`,children:[d(bt,{nodeId:`hub`,addonIds:fr,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer, failover, enrichment models, and the admission settings those models share. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`}),d(bt,{nodeId:`hub`,addonIds:[pr],level:`global`,capability:mr,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.`})]})}n();function gr({refreshToken:e}){let t=c(),{data:n,isLoading:i}=oe(),[a,s]=u(null),[l,f]=u(``),[p,m]=u(``),h=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},g=ue({onSuccess:()=>{s(null),h()}}),_=S({onSuccess:h}),v=e=>{s(e.id),f(e.name),m(e.description??``)},y=()=>{s(null),f(``),m(``)},b=()=>{if(!a)return;let e=p.trim();g.mutate({id:a,name:l.trim()||`Untitled`,...e?{description:e}:{}})};if(i)return d(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let x=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return d(`div`,{className:`space-y-6 max-w-4xl`,children:r(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),d(`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.`})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[x.length,` template`,x.length===1?``:`s`]})]}),x.length===0?r(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[d(Je,{className:`h-6 w-6 opacity-40`}),d(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):d(`ul`,{className:`divide-y divide-border`,children:x.map(e=>{let t=a===e.id;return d(`li`,{className:`px-4 py-3 text-xs`,children:r(`div`,{className:`flex items-start gap-3`,children:[d(`div`,{className:`flex-1 min-w-0`,children:t?r(`div`,{className:`space-y-2`,children:[d(`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:l,onChange:e=>f(e.target.value),placeholder:`Template name`,autoFocus:!0}),d(`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)`})]}):r(o,{children:[d(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&d(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,r(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),d(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?r(o,{children:[r(`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:[d(ht,{className:`h-3 w-3`}),`Save`]}),r(`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:[d(ft,{className:`h-3 w-3`}),`Cancel`]})]}):r(o,{children:[d(`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:d(qe,{className:`h-3 w-3`})}),d(`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:d(mt,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var _r=`pipeline-orchestrator`,vr=200;function yr(){return r(`div`,{className:`flex flex-col gap-3`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(k,{addonId:_r,limit:vr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}n();var br=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function xr({refreshToken:e}){let[t,n]=u(`assignments`);return r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:br.map(e=>d(`button`,{type:`button`,onClick:()=>n(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))}),r(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&d($n,{}),t===`balancer`&&d(dr,{refreshToken:e}),t===`settings`&&d(hr,{refreshToken:e}),t===`templates`&&d(gr,{refreshToken:e}),t===`logs`&&d(yr,{})]})]})}var Sr=`armed:`;function Cr(e){return e.assignment.reasons.detection?.startsWith(Sr)===!0}function wr(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Cr(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Tr(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&&!Cr(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 Er(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Dr(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Or(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function kr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Ar={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 jr(e){if(!Er(e)||!Array.isArray(e.sections))return Ar;let t=ke(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)kr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Dr(n(`detectionFps`)),motionSources:Or(n(`motionSources`)),motionFps:Dr(n(`motionFps`)),motionCooldownMs:Dr(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 Mr(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(...Mr(r.children,t+1));return n}function X({title:e,children:t}){return r(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return r(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(Nr,{})]})}function Nr(){return d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var Pr={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return d(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${Pr[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Fr({icon:e,label:t,nodeId:n,pinned:i,reason:a,overridden:s}){return r(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):r(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),i?r(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(Ct,{className:`h-2.5 w-2.5`}),` manual`]}):r(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function Ir({assignment:e,settings:t,onlineNodes:n,pinPending:i,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return r(X,{title:`Where it runs`,children:[d(Fr,{icon:W,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(Fr,{icon:st,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(Fr,{icon:Ge,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(Fr,{icon:Ye,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:r(`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:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>r(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function Lr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Rr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function zr(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function Br({streams:e,brokerProfiles:t,settings:n,motionEnabled:i,motionFpsLive:a}){let s=Rr(t,n.detectionStreamProfile),c=Rr(t,n.motionStreamProfile),l=n.motionSources.includes(`analyzer`);return r(X,{title:`Streams & motion`,children:[r(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,s!==void 0&&` · ${s.width}×${s.height} ${s.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:zr(n.detectionFps)}),r(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,i===!1&&` · inactive`]}),l&&r(o,{children:[r(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),r(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[zr(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>r(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,Lr(e)]},e.camStreamId))})]})}function Vr({steps:e,audioModelId:t,audioEnabled:n,audioMode:i}){return r(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:r(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&r(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:r(Z,{label:`Audio class.`,children:[i??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var Hr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Ur({detection:e,live:t,detectionMode:n,modeOverridden:i}){if(e===null)return r(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:i,children:n??`—`}),d($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=m(a),f=a===`active`&&o===0;return r(X,{title:`Detection runtime`,children:[r(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[r(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(pe,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:i,children:n??`—`}),r(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),r(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),r(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&r(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&r(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),r(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),r(Z,{label:`Provisioning`,children:[d(Q,{tone:Hr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&r(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function Wr({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):r(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return r(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),r(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),r(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),r(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),r(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[r(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),r(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function Gr({decoder:e,detectionActive:t}){if(e===null)return d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return r(X,{title:`Decoder`,children:[d(Z,{label:`Node`,children:e.nodeId}),d(Z,{label:`Sessions`,children:e.sessionCount}),r(Z,{label:`SHM frames`,children:[d(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),d(`span`,{className:`text-foreground-subtle`,children:` written`})]}),r(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&r(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),r(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&d(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}n();var Kr=`pipeline-orchestrator`,qr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Jr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Yr({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>r(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[d(pt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Xr({deviceId:e,name:t,online:n,status:i,live:o,onlineNodes:s}){let l=c(),{data:u}=me({addonId:Kr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=h({deviceId:e},{staleTime:3e4}),p=a(()=>jr(u),[u]),m=a(()=>f===void 0?void 0:Mr(f.steps),[f]),g=a(()=>i===void 0?[]:Tr(i),[i]),_=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=L({onSuccess:_}),y=Te({onSuccess:_}),b=t=>{t===`auto`?y.mutate({deviceId:e}):v.mutate({deviceId:e,agentNodeId:t})},x=i===void 0?`idle`:wr(i),S=g.some(e=>e.severity===`error`),C=g.length>0,w=S?`border-danger/50`:C?`border-warning/40`:`border-border`;return r(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${w} bg-background overflow-hidden`,children:[r(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${S?`bg-danger`:qr[x]}`,title:S?`Error`:Jr[x],"aria-label":S?`Error`:Jr[x],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),r(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),i?.recording!=null&&(i.recording.active?r(Q,{tone:`danger`,title:`Recording (${i.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):i.recording.mode!==`off`&&r(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,i.recording.mode]}))]})]}),g.length>0&&d(Yr,{problems:g}),i===void 0?d(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(Ir,{assignment:i.assignment,settings:p,onlineNodes:s,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),d(Ur,{detection:i.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(Vr,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:i.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(Br,{streams:i.source.streams,brokerProfiles:i.broker?.profiles,settings:p,motionEnabled:i.motion?.enabled??null,motionFpsLive:i.motion?.fps??null}),d(Wr,{broker:i.broker}),d(Gr,{decoder:i.decoder,detectionActive:i.detection?.phase===`active`})]})]})}n();var Zr=5e3,Qr=1e4,$r=5e3;function ei(e){let t=c(),{data:n,isLoading:r}=Re(),{data:i,isLoading:o}=v({},{refetchInterval:Zr}),{nodes:s}=R();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);N(Ae.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-Qr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},$r);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}n();function ti({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:i,isLoading:o}=ei(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:Tr(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:r(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[r(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[r(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),r(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),r(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(Xr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:i},e.deviceId))]})})}n();var ni=`__cluster__`;function ri(e){return e===`cameras`?`cameras`:`nodes`}function ii(){let[e,t]=ut(),n=ri(e.get(`view`)),i=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:ni},{replace:!0})},[n,e,t]),r(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[r(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[r(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[d(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:i},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),d(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),d(`div`,{className:`flex items-center gap-2`,children:r(`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:[d(Xe,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),n===`nodes`&&r(`button`,{type:`button`,onClick:()=>l(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:[r(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(lt,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?r(o,{children:[d(`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:d(kt,{selectedNodeId:i,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:i===`__cluster__`?d(xr,{refreshToken:a}):d(Tn,{nodeId:i,refreshToken:a})})]}):d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:d(ti,{refreshToken:a})})})]})}export{ii as PipelinePage};
|
|
1
|
+
import{I as e,K as t,Q as n,S as r,T as i,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as p}from"./player-overlays-DsK1iDkv.js";import{$ as m,$a as h,Aa as g,B as _,Ba as v,Bt as y,Da as b,Ea as x,Fa as S,Fs as C,Ga as w,Ht as T,Ia as E,Is as D,It as O,J as k,Ja as A,Jt as ee,Ka as j,La as M,Ls as N,Ma as P,Na as F,Oa as I,Pa as L,Ps as R,Qa as z,Ra as te,Rs as ne,Rt as re,Ua as B,Vt as ie,Xa as ae,Ya as oe,b as se,co as ce,d as le,do as ue,eo as de,gn as fe,h as pe,hn as me,i as he,ja as ge,ka as _e,ln as ve,lo as ye,no as be,po as xe,ro as Se,ta as V,to as Ce,u as we,uo as Te,vn as Ee,zt as De}from"./src-DnZ6ZcH0.js";import{n as Oe}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{Lt as ke,Rt as Ae,bt as je,f as Me,h as Ne,p as Pe}from"./src-DY4vbC0g.js";import{a as Fe,d as Ie,i as Le,l as Re,n as H,o as ze,r as Be,t as Ve,u as He}from"./NodeInferenceDevices-CJBU3t4h.js";import{t as Ue}from"./download-DrTCm0Zn.js";import{t as We}from"./hard-drive-D6wUZdNf.js";import{n as Ge,t as Ke}from"./video-LCt0QHTC.js";import{t as qe}from"./pencil-DDE9Ut_f.js";import{t as Je}from"./plus-CKJhtG9S.js";import{t as Ye}from"./radio-Cgg_wmnh.js";import{t as Xe}from"./refresh-cw-B06QF6BP.js";import{t as Ze}from"./search-B9qXKjRG.js";import{t as Qe}from"./server-qRR4BT4Q.js";import{t as $e}from"./square-check-big-CKJTPtsS.js";import{t as et}from"./square-CfRn6ZFd.js";import{t as tt}from"./zap-BXQ1pVxK.js";import{C as U,D as nt,E as rt,F as it,I as at,K as ot,N as W,O as st,P as ct,R as lt,X as ut,a as dt,i as ft,o as pt,s as mt,z as ht}from"./index-D7fwM52p.js";import{t as gt}from"./AdminPage-CCD07UMs.js";import"./useEventInvalidation-CINdEbPJ.js";import{r as _t,t as vt}from"./build-cluster-graph-Cbb1I-jq.js";import{n as yt}from"./format-size-CO9d3C3-.js";import{t as bt}from"./NodeAddonsSettingsPanel-BYXH3-BP.js";var xt=ot(`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`}]]),St=ot(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),Ct=ot(`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`}]]);n();function wt(e){return e}function Tt(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Et(e,t){return typeof e==`boolean`?e:wt(t)}function Dt(e,t){return{pipeline:Et(Tt(e,`detect`),t),audio:Et(Tt(e,`audio`),t),ingest:Et(Tt(e,`ingest`),t)}}function Ot(e,t,n){let r=e?.find(e=>e.nodeId===t);return Dt(r?.settings,n)}function kt({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:i}=V(void 0),{data:a}=w(void 0),{data:s}=A(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=i??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return r(`div`,{className:`flex flex-col h-full`,children:[r(`button`,{type:`button`,onClick:()=>t(ni),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[d(rt,{className:`h-4 w-4 flex-shrink-0`}),r(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let i=e===n.id,a=c.get(n.id)??0,l=n.isHub?Qe:W,u=Ot(s,n.id,n.isHub),f=n.isOnline?null:_(_t(n.lastSeen));return r(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),r(`div`,{className:`min-w-0 flex-1`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),r(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[r(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),r(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&r(o,{children:[d(`span`,{children:`•`}),r(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(Ke,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&r(o,{children:[d(`span`,{children:`•`}),r(`span`,{className:`text-destructive`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),r(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(O,{variant:u.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),d(O,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),r(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[r(`span`,{children:[u,` online`]}),f>0&&r(`span`,{className:`text-destructive`,children:[f,` offline`]})]})]})}function At({nodeId:e,refreshToken:t}){let{data:n}=V(void 0),i=n?.find(t=>t.id===e),a=C(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return i?r(`div`,{className:`px-6 py-4 border-b border-border`,children:[r(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:i.name}),i.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),i.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),r(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:i.cpuModel??`CPU`}),d(`span`,{children:`•`}),r(`span`,{children:[i.cpuCores,` cores`]}),d(`span`,{children:`•`}),r(`span`,{children:[Math.round(i.memoryMB/1024),` GB`]}),a&&r(o,{children:[d(`span`,{children:`•`}),r(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),r(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),r(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&r(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:r(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function jt({refreshToken:e,nodeId:t}){let[n,i]=u(new Map),{nodes:o}=R();N(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&i(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=te(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[l,o]);if(t){let e=l.get(t);return r(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),r(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(G,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(G,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(G,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(G,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(G,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return r(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),r(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(G,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(G,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(G,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(G,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(G,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),r(`tbody`,{children:[m.map(([e,t])=>r(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function G({label:e,value:t}){return r(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}n();var Mt={active:!1,pinned:!1,nodeId:null,reason:``},Nt=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],Pt=3e5,Ft={pipeline:W,decoder:st,audio:Ge},It={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function Lt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let s=c(),[l,p]=u(null),[m,h]=u(null),[g,_]=u(new Map);he([`pipelineOrchestrator`,`getPipelineAssignments`],Nt),he([`pipelineOrchestrator`,`getAudioAssignments`],Nt),he([`pipelineOrchestrator`,`getCameraStatuses`],Nt);let{data:y}=w(void 0),{data:b}=M(void 0),{data:x}=v({},{enabled:e===`agent`}),{nodes:S}=R(),{data:C}=Re();N(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&_(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),f(()=>{if(g.size===0)return;let e=setInterval(()=>{_(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)},[g.size]);let T=a(()=>{let e=new Map;for(let t of C??[])e.set(t.id,t.name);return e},[C]),E=a(()=>{if(e===`agent`){let e=[];for(let n of x??[]){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:T.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:T.get(e)??`Device ${e}`,pipeline:Mt,decoder:Mt,audio:Mt};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 b??[]){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,b,x,T,e,t]),D=a(()=>(S??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[S]),O=()=>{s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),s.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},k=L({onSuccess:O}),A=Te({onSuccess:O}),j=F({onSuccess:O}),P=ye({onSuccess:O}),I=(e,t,n)=>{t===`pipeline`?k.mutate({deviceId:e,agentNodeId:n}):j.mutate({deviceId:e,nodeId:n}),p(null)},z=(e,t)=>{t===`pipeline`?A.mutate({deviceId:e}):P.mutate({deviceId:e}),p(null)};return d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[d(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&d(`th`,{className:`w-10`}),d(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?r(o,{children:[d(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),d(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):r(o,{children:[d(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),d(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),d(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),d(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),r(`tbody`,{children:[E.map(t=>{let a=g.get(t.deviceId),s=m===t.deviceId;return r(i.Fragment,{children:[r(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&d(`td`,{className:`px-2 py-2 align-middle`,children:d(`button`,{type:`button`,onClick:()=>h(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:d(s?lt:at,{className:`h-3.5 w-3.5`})})}),r(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[d(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),r(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?r(o,{children:[d(`td`,{className:`px-3 py-2 align-middle`,children:d(zt,{state:t.pipeline,onlineNodes:D,pending:k.isPending||A.isPending,onChange:e=>{e===`auto`?z(t.deviceId,`pipeline`):I(t.deviceId,`pipeline`,e)}})}),d(`td`,{className:`px-3 py-2 align-middle`,children:d(Vt,{state:t.pipeline,deviceId:t.deviceId})})]}):r(o,{children:[d(Ut,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:l?.deviceId===t.deviceId&&l.role===`pipeline`,onToggleMenu:()=>p(l?.deviceId===t.deviceId&&l.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>p(null),onMove:e=>I(t.deviceId,`pipeline`,e),onUnpin:()=>z(t.deviceId,`pipeline`)}),d(Ut,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:D,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),d(Ut,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:l?.deviceId===t.deviceId&&l.role===`audio`,onToggleMenu:()=>p(l?.deviceId===t.deviceId&&l.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>p(null),onMove:e=>I(t.deviceId,`audio`,e),onUnpin:()=>z(t.deviceId,`audio`)})]}),d(`td`,{className:`px-3 py-2 align-middle`,children:d(qt,{snap:a})})]}),s&&!n&&r(`tr`,{className:`bg-surface/50`,children:[d(`td`,{}),r(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&d(Rt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),d(ee,{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)}),E.length===0&&d(`tr`,{children:d(`td`,{colSpan:n?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 Rt({deviceId:e,nodeId:t}){let n=c(),{data:i}=B({nodeId:t}),{data:a}=j({deviceId:e}),o=ce({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),s=i?.devices??[],l=a?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l);return r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[d(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),r(`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:[d(`option`,{value:`auto`,children:`Auto (balanced)`}),u&&r(`option`,{value:l,children:[`Pin → `,l,` (not on this node)`]}),s.map(e=>r(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&d(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function zt({state:e,onlineNodes:t,pending:n,onChange:i}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return r(`select`,{value:a,disabled:n,"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:[d(`option`,{value:`auto`,children:`Auto`}),o.map(e=>r(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Bt(e){let n=t(null);return e.nodeId!==null&&(n.current=e),n.current}function Vt({state:e,deviceId:t}){let n=Bt(e),i=e.active&&e.nodeId!==null;if(n===null||n.nodeId===null)return d(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`— · no session yet`});let a=n.pinned?`pinned · manual`:`auto · ${n.reason||`capacity`}`;return r(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[d(`span`,{className:`font-mono text-[11px] truncate ${i?`text-foreground`:`text-foreground-subtle`}`,title:n.pinned?n.nodeId:`${n.nodeId} — an unpinned camera is re-elected per on-motion session, so this can change between sessions`,children:n.nodeId}),d(`span`,{className:`truncate ${n.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:a,children:a}),d(`span`,{className:`truncate text-[10px] ${i?`text-emerald-400`:`text-foreground-subtle/70`}`,children:i?`● running here`:`○ idle · last session here`}),d(Ht,{deviceId:t,nodeId:n.nodeId})]})}function Ht({deviceId:e,nodeId:t}){let n=c(),{data:i}=j({deviceId:e},{refetchOnMount:`always`}),{data:a}=B({nodeId:t},{staleTime:Pt}),o=ce({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(i===void 0||a===void 0)return d(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let s=a.devices??[],l=s.filter(e=>e.enabled),u=i.deviceKey??`auto`,f=u!==`auto`&&!l.some(e=>e.key===u),p=s.find(e=>e.key===u);return r(`select`,{value:u,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:[d(`option`,{value:`auto`,children:`Auto (balanced)`}),f&&r(`option`,{value:u,children:[p?`${H(p).label} (${u})`:u,` (not enabled)`]}),l.map(e=>r(`option`,{value:e.key,children:[H(e).label,` · `,e.format]},e.key))]})}function Ut({role:e,state:t,mode:n,onlineNodes:i,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:l,onUnpin:u}){let f=Ft[e],p=i.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||n===`cluster`)&&(p.length>0||t.pinned);return r(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[d(n===`agent`?Wt:Gt,{state:t,Icon:f}),d(`div`,{className:`ml-auto shrink-0`,children:m&&d(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${It[e]} actions`,children:d(xt,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&d(Jt,{title:It[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:u,onClose:c})]})}function Wt({state:e,Icon:t}){return r(`div`,{className:`flex items-center gap-1.5`,children:[d(e.active?$e:et,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),d(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&d(Ct,{className:`h-2.5 w-2.5 text-amber-400`})]})}function Gt({state:e,Icon:t}){return!e.active||!e.nodeId?r(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[d(t,{className:`h-3 w-3`}),d(`span`,{className:`text-[10px] italic`,children:`—`})]}):r(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),r(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[d(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),d(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?r(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[d(Ct,{className:`h-2.5 w-2.5`}),` manual`]}):r(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Kt=`min-h-[3.25rem]`;function qt({snap:e}){if(!e)return d(`div`,{className:`flex items-center ${Kt}`,children:d(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:i,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=m(t);return r(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Kt}`,children:[r(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[d(pe,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),r(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),r(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),r(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[d(`span`,{className:`text-foreground`,children:i.toFixed(0)}),d(`span`,{children:` ms`}),a>0&&r(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),r(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,d(`span`,{className:`text-foreground`,children:s})]})]})}function Jt({title:e,targets:n,pinned:i,onMove:a,onUnpin:o,onClose:s}){let c=t(null);return f(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),r(`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:[d(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),n.length>0&&d(`div`,{className:`py-1`,children:n.map(e=>r(`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&&r(`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 `,e.toLowerCase()]}),n.length===0&&!i&&d(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Yt({nodeId:e,refreshToken:t}){return r(`div`,{className:`space-y-6`,children:[d(jt,{refreshToken:t,nodeId:e}),r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),r(`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.`]})]}),d(Lt,{mode:`agent`,nodeId:e,compact:!0})]})}n();function Xt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Zt({nodeId:e,refreshToken:t}){let n=c(),i=ge({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=P({nodeId:e}),s=C(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,l=s===null;he([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:u}=xe({nodeId:e}),{values:f}=D(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),p=a(()=>f.filter(e=>e.metrics.phase===`active`).length,[f]),m=t=>{let n=u??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||i.mutate({nodeId:e,engine:t,force:n.length>0})};return r(`div`,{className:`space-y-6`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(s??[]).length,` engine(s) resident in RAM. `,(u??[]).length,` `,`camera(s) attached, `,p,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:r(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:r(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),r(`tbody`,{children:[l&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!l&&(s??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return r(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:r(`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`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[d(t?St:n?Ie:W,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:r(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(tt,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),d(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?d(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>d(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),d(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),d(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?d(`span`,{className:`text-foreground-subtle`,children:Xt(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(u??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:n?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):r(`button`,{type:`button`,disabled:i.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:[d(mt,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!l&&(s??[]).length===0&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),r(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),i.isError&&r(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,i.error instanceof Error?i.error.message:`unknown`]})]})}n();var Qt=new Set(je);function $t(e){return Qt.has(e)}function en(e,t,n){return`${e}/${t}/${n}`}function tn(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function nn(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function K(e){return e.format}function rn(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function an({addonId:e,model:t,format:n,isActive:i,progress:a,errorMsg:o,onDownload:s,onDelete:c}){let l=t.formats[n];return l?r(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[d(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${l.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),r(`div`,{className:`flex-1 min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),a&&a.progress>=0&&a.progress<100&&r(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[d(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:d(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${a.progress}%`}})}),r(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(a.progress),`%`]})]})]}),d(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:yt(l.sizeMB)}),o&&r(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:o,children:[d(it,{className:`h-3 w-3 shrink-0`}),o]}),l.downloaded?r(`button`,{onClick:c,disabled:i,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[i?d(U,{className:`h-3 w-3 animate-spin`}):d(mt,{className:`h-3 w-3`}),i?`Deleting...`:`Delete`]}):r(`button`,{onClick:s,disabled:i,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[i?d(U,{className:`h-3 w-3 animate-spin`}):d(Ue,{className:`h-3 w-3`}),i?`Downloading...`:`Download`]})]}):null}function on({engines:e,activeEngine:t,viewEngine:n,onSelect:i}){let[a,o]=u(!1);return r(`div`,{className:`relative`,children:[r(`button`,{type:`button`,onClick:()=>o(!a),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[d(W,{className:`h-4 w-4 text-primary shrink-0`}),r(`div`,{className:`flex-1 min-w-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-sm font-medium text-foreground`,children:tn(n)}),K(n)===K(t)&&d(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:nn(n)})]}),d(lt,{className:`h-4 w-4 text-foreground-subtle transition-transform ${a?`rotate-180`:``}`})]}),a&&d(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let a=K(e)===K(n),s=K(e)===K(t);return r(`button`,{type:`button`,onClick:()=>{i(e),o(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${a?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[d(W,{className:`h-4 w-4 shrink-0 ${a?`text-primary`:`text-foreground-subtle`}`}),r(`div`,{className:`flex-1`,children:[r(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-sm font-medium ${a?`text-primary`:`text-foreground`}`,children:tn(e)}),s&&d(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:nn(e)})]}),a&&d(ct,{className:`h-4 w-4 text-primary shrink-0`})]},K(e))})})]})}function sn({embedded:t=!1,nodeId:n}={}){let i=c(),a=n??`hub`,[s,l]=u(null),[f,p]=u(new Set),[m,h]=u(new Map),[_,v]=u(new Map),[y,S]=u(``),{data:C=[]}=I({nodeId:a}),w=C.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:E}=g({nodeId:a}),D=E,{data:O,isLoading:k}=_e({nodeId:a}),A=b(),ee=x();N(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,r=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||r===void 0||(h(e=>{let t=new Map(e);return r===100||r===-1?t.delete(n):t.set(n,{modelId:n,progress:r,totalMB:a}),t}),r===100&&i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let j=D??{runtime:`node`,backend:`cpu`,format:`onnx`},M=w.find(e=>e.format===s)??j,P=M.format,F=e=>e.formats[P]?.downloaded===!0,L=O?.slots??[],R=L.map(e=>({...e,addons:e.addons.map(e=>({...e,models:T(e.models,P)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),z=rn(R,P),te=e(async(e,t,n)=>{if(!$t(n))return;let r=en(e,t,n);p(e=>new Set([...e,r])),v(e=>{let t=new Map(e);return t.delete(r),t});try{await A.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){v(t=>new Map([...t,[r,e instanceof Error?e.message:`Download failed`]]))}finally{p(e=>{let t=new Set(e);return t.delete(r),t})}},[A,i,a]),ne=e(async(e,t,n)=>{if(!$t(n))return;let r=en(e,t,n);p(e=>new Set([...e,r])),v(e=>{let t=new Map(e);return t.delete(r),t});try{await ee.mutateAsync({addonId:e,modelId:t,format:n,nodeId:a}),i.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){v(t=>new Map([...t,[r,e instanceof Error?e.message:`Delete failed`]]))}finally{p(e=>{let t=new Set(e);return t.delete(r),t})}},[ee,i,a]),re=e(e=>{l(e.format)},[]),B=y.trim()?R.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(y.toLowerCase())||t.id.toLowerCase().includes(y.toLowerCase())||e.name.toLowerCase().includes(y.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):R,ie=r(o,{children:[k&&d(`div`,{className:`flex items-center justify-center py-16`,children:d(U,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!k&&L.length===0&&r(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[d(We,{className:`h-8 w-8 mb-3 opacity-30`}),d(`span`,{className:`text-sm`,children:`No pipeline steps available`}),d(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!k&&L.length>0&&r(o,{children:[d(on,{engines:w,activeEngine:j,viewEngine:M,onSelect:re}),r(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[r(`span`,{children:[d(`span`,{className:`font-semibold text-foreground tabular-nums`,children:z.total}),d(`span`,{className:`ml-1`,children:`compatible models`})]}),d(`span`,{className:`text-border`,children:`|`}),r(`span`,{children:[d(`span`,{className:`font-semibold text-success tabular-nums`,children:z.downloaded}),d(`span`,{className:`ml-1`,children:`downloaded`})]}),d(`span`,{className:`text-border`,children:`|`}),r(`span`,{className:`tabular-nums`,children:[yt(z.downloadedSizeMB),d(`span`,{className:`ml-1`,children:`on disk`})]})]}),z.total>5&&r(`div`,{className:`relative`,children:[d(Ze,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),d(`input`,{type:`text`,value:y,onChange:e=>S(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),B.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+T(t.models,P).filter(F).length,0);return r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 mb-2`,children:[d(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),d(`div`,{className:`flex-1 h-px bg-border`}),r(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=en(e.id,t.id,P);return d(an,{addonId:e.id,model:t,format:P,isActive:f.has(n),progress:m.get(t.id),errorMsg:_.get(n),onDownload:()=>te(e.id,t.id,P),onDelete:()=>ne(e.id,t.id,P)},`${e.id}/${t.id}`)}))})]},e.id)}),B.length===0&&d(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:y.trim()?r(o,{children:[`No models matching “`,y,`”`]}):r(o,{children:[`No models available for `,tn(M),` format`]})})]})]});return t?d(`div`,{className:`space-y-4`,children:ie}):d(gt,{children:ie})}function cn({nodeId:e,refreshToken:t}){return d(sn,{embedded:!0,nodeId:e})}var ln=`pipeline-runner`,un=200;function dn({nodeId:e}){return r(`div`,{className:`flex flex-col gap-3`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),r(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(k,{agentId:e,addonId:ln,limit:un,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}n(),n();function fn({nodeId:e,title:t}){let{data:n}=Re(),{data:i}=w(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of i??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,i]),[c,l]=u(new Map);N(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||l(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),f(()=>{if(c.size===0)return;let e=setInterval(()=>{l(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=a(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return p.length===0?r(`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`]}):r(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[r(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:p.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=m(e.metrics.phase);return r(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[d(pe,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var pn=`pipeline-orchestrator`;function mn(e){return Me.find(t=>t.stepId===e)??null}function hn({title:e}){return d(`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 gn({step:e,engineFormat:t,runnableModelIds:n}){let i=c(),{data:a,isLoading:o}=fe({addonId:pn}),s=Ee({onSuccess:()=>{i.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),l=Ne(a??null)[e.stepId]??e.defaultModelId,u=n.length>0&&!n.includes(l);return r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[r(`div`,{className:`flex items-center text-[11px] font-medium text-foreground`,children:[e.label,d(hn,{})]}),r(`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?d(U,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):d(`select`,{className:`w-full rounded border border-border bg-surface px-2 py-1 text-xs`,value:l,disabled:s.isPending,onChange:t=>{t.target.value!==l&&s.mutate({addonId:pn,patch:{[Pe(e.stepId)]:t.target.value}})},children:e.options.map(t=>r(`option`,{value:t.id,children:[t.label,t.id===e.defaultModelId?` (default)`:``]},t.id))}),u&&r(`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 `,d(`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.`]}),d(`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.`})]})}n();function q(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 _n(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 vn({nodeId:e,refreshToken:t}){let n=c(),[i,s]=u(null),[l,f]=u(null),[p,m]=u(``),[h,g]=u(null),_=B({nodeId:e},{refetchOnMount:`always`}),v=_e({nodeId:e},{refetchOnMount:`always`}),b=Ne(fe({addonId:`pipeline-orchestrator`}).data??null),x=_.data?.devices??[],S=be({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),C=a(()=>v.data?we(v.data):[],[v.data]),w=a(()=>x.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:H(t).label})),[x,e]),E=e=>x.find(t=>t.key===e)??null,D=a(()=>x.filter(e=>e.enabled),[x]),O=D.length>=2,k=(e,t)=>ie(q(v.data??null,e)?.models??[],t?.format),A=e=>{let t=E(e);return t?H(t).label:e},ee=(e,t)=>D.filter(n=>n.key!==t&&k(e,n)).toSorted((e,t)=>e.key<t.key?-1:+(e.key>t.key))[0]??null,j=e=>{let t=q(v.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},M=(e,t)=>{let n=q(v.data??null,e);if(n)return De(n,t)},N=(e,t)=>{let n=j(e),r=n.kind===`gate`?n.effectiveOn:!1,i=q(v.data??null,e),a=t.deviceKey===void 0?null:E(t.deviceKey),o=ie(i?.models??[],a?.format),s=a?.steps?.[e];if(!o){if(!r)return{kind:`na`};let n=s?.jumpDeviceKey,i=n!==void 0&&D.some(e=>e.key===n)?n:t.deviceKey===void 0?void 0:ee(e,t.deviceKey)?.key;return i===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:A(i)}}let c=mn(e);return c?{kind:`enabled`,modelId:b[e]??c.defaultModelId,clusterWide:!0}:{kind:`enabled`,modelId:(i?y({catalog:i,device:a,base:s?.modelId}):void 0)??`Auto`,...s?.jumpDeviceKey!==void 0&&D.some(e=>e.key===s.jumpDeviceKey)?{jumpTo:A(s.jumpDeviceKey)}:{}}},P=i&&v.data?q(v.data,i.addonId):null,F=i?E(i.deviceKey):null,I=F?.format??`coreml`,L=i?M(i.addonId,F):void 0,R=()=>{s(null),f(null),m(``)},z=(e,t)=>{if(t.deviceKey===void 0)return;let n=E(t.deviceKey)?.steps?.[e];s({addonId:e,deviceKey:t.deviceKey});let r=n?.settings??Fe(x.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??``)},te=()=>{if(!i)return;let t=_n(l),n=p!==``&&p!==i.deviceKey?p:void 0,r=t||n!==void 0?{...t,...n===void 0?{}:{jumpDeviceKey:n}}:null,a=x.map(e=>{let t={...e.steps};return e.key===i.deviceKey&&(r?t[i.addonId]=r:delete t[i.addonId]),{key:e.key,enabled:e.key===i.deviceKey?!0:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:t}}),o=r?.settings!==void 0&&Object.keys(r.settings).length>0?ze(a,i.deviceKey,i.addonId):a;S.mutate({agentNodeId:e,inferenceDevices:Le(o)},{onSuccess:R})};if(_.isLoading||v.isLoading)return d(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(x.length===0)return d(`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(!v.data)return d(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let ne=i!==null&&P!==null&&F!==null;return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`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`,` `,d(`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.`]}),d(`div`,{className:ne?`md:pr-[360px]`:``,children:C.length>0?d(se,{tree:C,agents:w,gateFor:j,getCellState:N,onCellClick:z,selectedCell:i?{addonId:i.addonId,agentNodeId:e,deviceKey:i.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:h,onFallbackNodeChange:g,hideGate:!0}):d(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),d(le,{open:ne,onClose:R,title:P?.name??``,subtitle:i&&F?`${e} · ${H(F).label} · ${F.format}`:``,footer:r(o,{children:[d(`div`,{className:`flex-1`}),d(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:R,children:`Cancel`}),d(`button`,{type:`button`,disabled:!i||!l||S.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:te,children:S.isPending?`Saving…`:`Save`})]}),children:P&&i&&mn(i.addonId)?d(gn,{step:mn(i.addonId),engineFormat:I,runnableModelIds:T(P.models??[],I).map(e=>e.id)}):P&&i&&l?r(`div`,{className:`space-y-3`,children:[O&&r(`div`,{className:`rounded-md border border-border bg-muted/10 px-3 py-2 space-y-1`,children:[d(`label`,{className:`block text-[11px] font-medium text-foreground`,children:`Run on`}),r(`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:[d(`option`,{value:``,children:`Auto (this device, or auto-jump if unsupported)`}),D.filter(e=>e.key!==i.deviceKey).map(e=>r(`option`,{value:e.key,children:[H(e).label,` · `,e.format]},e.key))]}),d(`p`,{className:`text-[10px] leading-snug text-foreground-subtle`,children:`Route this step (and its child steps) to another accelerator on this node.`})]}),d(re,{mode:`agent`,addon:P,agentDefault:l,agentNodeId:e,engineFormat:I,effectiveModelId:L,onChangeAgentConfig:f})]}):d(`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.`})})]})}n();var yn=[`pipeline-orchestrator`],bn=[`decoder`],xn=!1;function Sn({nodeId:e,refreshToken:t}){let n=ve(),[i,a]=u(null),[o,s]=u(null),c=(V(void 0).data??[]).find(t=>t.id===e),l=c?.name??e,f=c?.isOnline??!1,p=z({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)`)}}),m=async()=>{await n({title:`Reset ${l} 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),p.mutate({agentNodeId:e}))};return r(`div`,{className:`relative h-full w-full space-y-3`,children:[r(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[o&&d(`span`,{className:`text-emerald-400`,children:o}),p.isError&&d(`span`,{className:`text-red-400`,children:p.error instanceof Error?p.error.message:`Reset failed`}),d(`button`,{type:`button`,onClick:()=>{m()},disabled:p.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:p.isPending?`Resetting…`:`Reset to default`})]}),d(fn,{nodeId:e}),d(bt,{nodeId:e,addonIds:yn,level:`global`,sectionIds:bn}),xn,xn,r(`div`,{children:[d(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),d(Ve,{nodeId:e,nodeName:l,isOnline:f})]}),r(`div`,{children:[d(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),d(vn,{nodeId:e,refreshToken:t})]})]})}var Cn=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],wn=`decoder-nodeav`;function Tn({nodeId:e,refreshToken:t}){let{data:n}=V(void 0),i=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??wn,a=[...Cn,i];return r(`div`,{className:`flex flex-col h-full`,children:[d(At,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:d(bt,{nodeId:e,addonIds:a,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:d(Yt,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:d(Sn,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:d(Zt,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:d(cn,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:d(dn,{nodeId:e})}]})})]})}function En(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 Dn={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 On(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function kn(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:En(e),format:e.format,sessions:i,queueDepth:r?.queueDepth??0,weight:a,weightSharePct:e.exclusion===null?On(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 An(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=kn(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?On(l,i.maxCameras):null,queueDepthTotal:a?.load.queueDepthTotal??null,avgInferenceTimeMs:a?.load.avgInferenceTimeMs??null,score:a?.score??null,weight:c,weightSharePct:s?On(c,n):null,cameraSharePct:l===null?null:On(l,r),decodeHwaccel:a?.decodeHwaccel??null,devices:o,eligibleDeviceCount:o.filter(e=>e.exclusion===null).length}})}var jn=`pipeline-orchestrator`,Mn=`recorder`,Nn=`recordingNodeId`,Pn=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],Fn=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function In(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function Ln(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Rn(e,t,n){let r=In(e,t);return typeof r==`string`&&r.length>0?r:n}function zn(e,t,n){let r=In(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function Bn(e,t){let n=Ln(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function Vn(e,t){let n=Ln(e,t);return typeof n==`string`&&n.length>0?n:null}function Hn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function Un(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`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function Wn(e,t){switch(t){case`detect`:return e.pipeline}}function Gn(e){return e instanceof Error?e.message:`Failed to save`}function Kn(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}n();var qn=2e4,Jn=3e5;function Yn(){let{nodes:e}=R(),t=p().trpcClient,n=E(void 0,{placeholderData:l,staleTime:qn,refetchInterval:qn,refetchOnWindowFocus:!0}),i=A(void 0,{staleTime:Jn}),o=a(()=>e.map(e=>e.id),[e]),c=s({queries:o.map(e=>({queryKey:Oe(ne.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>t.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Jn,refetchOnWindowFocus:!1,placeholderData:l}))}),u=a(()=>{let e={};return o.forEach((t,n)=>{let r=c[n]?.data;r&&(e[t]=r.devices)}),e},[o,c.map(e=>e.dataUpdatedAt).join(`|`)]),f=a(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),m=a(()=>e.map(e=>{let t=f.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:Dt(t,e.isHub).pipeline,weight:Bn(t,`detectWeight`)??1,maxCameras:Bn(t,`maxCameras`)}}),[e,f]),h=n.data??[],g=a(()=>An({nodes:m,loads:h,devicesByNode:u}),[m,h,u]),_=g.reduce((e,t)=>e+(t.attachedCameras??0),0),v=g.reduce((e,t)=>e+(t.activeCameras??0),0),y=n.dataUpdatedAt>0?Date.now()-n.dataUpdatedAt:null;return r(`section`,{className:`rounded-md border border-border bg-surface px-3 py-2.5`,children:[r(`div`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-1 mb-2`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Node load`}),r(`span`,{className:`text-[10px] text-foreground-subtle`,children:[v,` running · `,_,` attached across `,g.length,` `,g.length===1?`node`:`nodes`]}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle/70 tabular-nums`,children:n.data===void 0?`reading…`:`reading ${y===null?`—`:`${Math.round(y/1e3)}s`} old · every ${qn/1e3}s`})]}),g.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:g.map(e=>d(Xn,{row:e},e.nodeId))})]})}function Xn({row:e}){let t=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return r(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[r(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&r(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[d(pt,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&r(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(dt,{className:`h-2.5 w-2.5`}),` offline`]})]}),r(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:t,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`detectWeight normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share`,value:e.cameraSharePct===null?`—`:`${e.cameraSharePct}%`,title:`Share of the cluster's attached cameras this node carries right now.`}),d(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(Zn,{row:e})]})}function Zn({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):r(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[r(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(nt,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(Qn,{device:e},e.key))})]})}function Qn({device:e}){let t=e.exclusion;return r(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(W,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?r(o,{children:[r(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),r(`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&&r(`span`,{className:`shrink-0 tabular-nums text-amber-400`,children:[`· q`,e.queueDepth]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):r(`span`,{className:`truncate text-foreground-subtle/80`,title:Dn[t],children:[`excluded — `,Dn[t]]})]})}function J({label:e,value:t,title:n}){return r(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function $n(){return r(`div`,{className:`space-y-6`,children:[d(fn,{title:`Cluster cameras`}),d(Yn,{}),r(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),d(`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.`})]}),d(Lt,{mode:`cluster`})]})}function er({capability:e,label:t,hint:n,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`,u=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,f=a?ht:He;return r(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${i}`,title:`${t} — ${n}`,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} ${u}`,children:[d(f,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),d(`span`,{children:t})]})}function tr({node:e,emphasis:t=!1}){let n=e.isHub?Qe:W;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),r(`div`,{className:`min-w-0`,children:[r(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(O,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(O,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}n();function nr({nodeId:e,value:t,detectedHosts:n,status:i,errorMessage:a,onCommit:o}){let[s,c]=u(t??``);f(()=>{c(t??``)},[t]);let l=n[0],p=l===void 0?`auto-detect`:`auto: ${l}`,m=i===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return r(`div`,{className:`flex items-center gap-1.5`,children:[d(`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`}),r(`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?d(U,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):d(ht,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&i===`success`&&d(ht,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),i===`error`&&d(`span`,{title:a??`Failed to save reachable host`,children:d(it,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}function rr({label:e,children:t}){return r(`div`,{className:`flex items-center justify-between gap-3`,children:[d(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function ir({node:e,actions:t}){return r(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[d(tr,{node:e,emphasis:!0}),d(`div`,{className:`grid grid-cols-2 gap-2`,children:Fn.map(n=>d(er,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Wn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),d(`div`,{className:`space-y-3 border-t border-border pt-3`,children:d(rr,{label:`Reachable host`,children:d(nr,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function ar(){return r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),r(`span`,{className:`inline-flex items-center gap-1.5`,children:[d(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function or({nodes:e,actions:t}){return d(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:r(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[d(`thead`,{children:r(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[d(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),Fn.map(e=>d(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),d(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),d(`tbody`,{children:e.map(e=>r(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[d(`td`,{className:`px-4 py-3 align-middle`,children:d(tr,{node:e})}),Fn.map(n=>d(`td`,{className:`px-3 py-3 text-center align-middle`,children:d(er,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:Wn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),d(`td`,{className:`px-4 py-3 align-middle`,children:d(nr,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function sr({role:e,value:t,options:n,pending:i,onChange:a}){return r(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[d(`span`,{className:`text-xs font-semibold text-foreground`,children:Hn(e)}),d(`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:n.map(e=>d(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),d(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:Un(e)})]})}function cr({roleValues:e,options:t,pending:n,lowFpsEnabled:i,fpsMinThreshold:a,onRoleChange:o,onLowFpsToggle:s}){return r(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[Pn.map(r=>d(sr,{role:r,value:e[r],options:t,pending:n,onChange:o},r)),r(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[d(`input`,{type:`checkbox`,checked:i,disabled:n,onChange:e=>s(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),r(`span`,{className:`flex flex-col gap-0.5`,children:[d(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),r(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,i?`${a} fps`:`disabled`]})]})]})]})}n();function lr(){let e=c(),{nodes:t}=R(),n=A(void 0),i=fe({addonId:jn}),s=fe({addonId:Mn}),l=()=>Kn(e),f=de({onSuccess:l}),p=Ce(),m=Se({onSuccess:l}),h=Ee({onSuccess:l}),[g,_]=u(!1),v=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),y=a(()=>t.map(e=>{let t=v.get(e.id),n=Dt(t,e.isHub),r=Bn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:Bn(t,`maxCameras`),reachableHost:Vn(t,`reachableHost`),detectedHosts:e.localIps}}),[t,v]),b=y.filter(e=>e.effective.pipeline),x={ingestNode:Rn(i.data,`ingestNode`,`hub`),recordingNode:Rn(s.data,Nn,`hub`),audioNode:Rn(i.data,`audioNode`,`hub`),motionNode:Rn(i.data,`motionNode`,`hub`)},S=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...Pn.map(e=>x[e]),...e])].filter(e=>e.length>0)},[t,x]),C=zn(i.data,`fpsMinThreshold`,0),w=C>0,T=n.isLoading||i.isLoading||s.isLoading,E=(e,t,n)=>{f.mutate({agentNodeId:e,[t]:n})},D=(e,t)=>{if(e===`recordingNode`){h.mutate({addonId:Mn,patch:{[Nn]:t}});return}h.mutate({addonId:jn,patch:{[e]:t}})},O=e=>{h.mutate({addonId:jn,patch:{fpsMinThreshold:e?Math.max(1,C):0}})},k=e=>m.variables?.agentNodeId===e?m.isPending?`pending`:m.isError?`error`:m.isSuccess?`success`:`idle`:`idle`,ee=e=>k(e)===`error`?Gn(m.error):null,j=async e=>{_(!0);try{for(let t of e)await p.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{_(!1),l()}},M={capabilityPending:f.isPending,onToggleCapability:E,onCommitReachableHost:(e,t)=>m.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:k,reachableHostErrorMessage:ee};return r(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[r(`header`,{className:`flex items-start justify-between gap-4`,children:[r(`div`,{className:`space-y-1`,children:[d(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),d(`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.`})]}),T&&d(U,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),r(`div`,{className:`space-y-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),d(cr,{roleValues:x,options:S,pending:h.isPending,lowFpsEnabled:w,fpsMinThreshold:C,onRoleChange:D,onLowFpsToggle:O})]}),r(`div`,{className:`space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),d(ar,{})]}),y.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):r(o,{children:[d(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:y.map(e=>d(ir,{node:e,actions:M},e.id))}),d(`div`,{className:`hidden @3xl/clustertab:block`,children:d(or,{nodes:y,actions:M})})]})]}),r(`div`,{className:`space-y-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),d(Be,{nodes:b,pending:g,onCommitWeights:e=>void j(e)})]}),r(`div`,{className:`space-y-3`,children:[d(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),b.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):d(`div`,{className:`space-y-2`,children:b.map(e=>d(Ve,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}n();var ur=!1;function dr({refreshToken:e}){let t=c(),{data:n}=V(void 0);a(()=>vt(n??[]),[n]);let i=ae({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return r(`div`,{className:`space-y-6`,children:[d(jt,{refreshToken:e}),d(lr,{}),ur,r(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[r(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Rebalance`}),d(`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.`})]}),r(`button`,{type:`button`,onClick:()=>i.mutate(void 0),disabled:i.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:[d(tt,{className:`h-3.5 w-3.5`}),i.isPending?`Rebalancing…`:`Rebalance pipelines`]})]})]})}var fr=[`pipeline-orchestrator`],pr=`pipeline-analytics`,mr=`face-gallery`;function hr({refreshToken:e}){return r(`div`,{className:`space-y-4 max-w-3xl`,children:[d(bt,{nodeId:`hub`,addonIds:fr,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer, failover, enrichment models, and the admission settings those models share. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`}),d(bt,{nodeId:`hub`,addonIds:[pr],level:`global`,capability:mr,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.`})]})}n();function gr({refreshToken:e}){let t=c(),{data:n,isLoading:i}=oe(),[a,s]=u(null),[l,f]=u(``),[p,m]=u(``),h=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},g=ue({onSuccess:()=>{s(null),h()}}),_=S({onSuccess:h}),v=e=>{s(e.id),f(e.name),m(e.description??``)},y=()=>{s(null),f(``),m(``)},b=()=>{if(!a)return;let e=p.trim();g.mutate({id:a,name:l.trim()||`Untitled`,...e?{description:e}:{}})};if(i)return d(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let x=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return d(`div`,{className:`space-y-6 max-w-4xl`,children:r(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[r(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),d(`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.`})]}),r(`div`,{className:`text-[11px] text-foreground-subtle`,children:[x.length,` template`,x.length===1?``:`s`]})]}),x.length===0?r(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[d(Je,{className:`h-6 w-6 opacity-40`}),d(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):d(`ul`,{className:`divide-y divide-border`,children:x.map(e=>{let t=a===e.id;return d(`li`,{className:`px-4 py-3 text-xs`,children:r(`div`,{className:`flex items-start gap-3`,children:[d(`div`,{className:`flex-1 min-w-0`,children:t?r(`div`,{className:`space-y-2`,children:[d(`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:l,onChange:e=>f(e.target.value),placeholder:`Template name`,autoFocus:!0}),d(`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)`})]}):r(o,{children:[d(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&d(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),r(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,r(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),d(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?r(o,{children:[r(`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:[d(ht,{className:`h-3 w-3`}),`Save`]}),r(`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:[d(ft,{className:`h-3 w-3`}),`Cancel`]})]}):r(o,{children:[d(`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:d(qe,{className:`h-3 w-3`})}),d(`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:d(mt,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}var _r=`pipeline-orchestrator`,vr=200;function yr(){return r(`div`,{className:`flex flex-col gap-3`,children:[r(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(k,{addonId:_r,limit:vr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}n();var br=[{id:`assignments`,label:`Assignments`},{id:`balancer`,label:`Balancer`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function xr({refreshToken:e}){let[t,n]=u(`assignments`);return r(`div`,{className:`flex flex-col h-full`,children:[r(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Per-camera assignments, the load balancer (live load + inference-device weights), cluster-wide settings, and the pipeline template library.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:br.map(e=>d(`button`,{type:`button`,onClick:()=>n(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))}),r(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&d($n,{}),t===`balancer`&&d(dr,{refreshToken:e}),t===`settings`&&d(hr,{refreshToken:e}),t===`templates`&&d(gr,{refreshToken:e}),t===`logs`&&d(yr,{})]})]})}var Sr=`armed:`;function Cr(e){return e.assignment.reasons.detection?.startsWith(Sr)===!0}function wr(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Cr(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Tr(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&&!Cr(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 Er(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Dr(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Or(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function kr(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Ar={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 jr(e){if(!Er(e)||!Array.isArray(e.sections))return Ar;let t=ke(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)kr(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Dr(n(`detectionFps`)),motionSources:Or(n(`motionSources`)),motionFps:Dr(n(`motionFps`)),motionCooldownMs:Dr(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 Mr(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(...Mr(r.children,t+1));return n}function X({title:e,children:t}){return r(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return r(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(Nr,{})]})}function Nr(){return d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var Pr={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return d(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${Pr[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Fr({icon:e,label:t,nodeId:n,pinned:i,reason:a,overridden:s}){return r(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):r(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),i?r(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(Ct,{className:`h-2.5 w-2.5`}),` manual`]}):r(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function Ir({assignment:e,settings:t,onlineNodes:n,pinPending:i,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return r(X,{title:`Where it runs`,children:[d(Fr,{icon:W,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(Fr,{icon:st,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(Fr,{icon:Ge,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(Fr,{icon:Ye,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:r(`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:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>r(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function Lr(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function Rr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function zr(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function Br({streams:e,brokerProfiles:t,settings:n,motionEnabled:i,motionFpsLive:a}){let s=Rr(t,n.detectionStreamProfile),c=Rr(t,n.motionStreamProfile),l=n.motionSources.includes(`analyzer`);return r(X,{title:`Streams & motion`,children:[r(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,s!==void 0&&` · ${s.width}×${s.height} ${s.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:zr(n.detectionFps)}),r(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,i===!1&&` · inactive`]}),l&&r(o,{children:[r(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),r(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[zr(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>r(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,Lr(e)]},e.camStreamId))})]})}function Vr({steps:e,audioModelId:t,audioEnabled:n,audioMode:i}){return r(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:r(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&r(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:r(Z,{label:`Audio class.`,children:[i??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var Hr={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Ur({detection:e,live:t,detectionMode:n,modeOverridden:i}){if(e===null)return r(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:i,children:n??`—`}),d($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=m(a),f=a===`active`&&o===0;return r(X,{title:`Detection runtime`,children:[r(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[r(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(pe,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:i,children:n??`—`}),r(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),r(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),r(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&r(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&r(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),r(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),r(Z,{label:`Provisioning`,children:[d(Q,{tone:Hr[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&r(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function Wr({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):r(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return r(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),r(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),r(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),r(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),r(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[r(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),r(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function Gr({decoder:e,detectionActive:t}){if(e===null)return d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return r(X,{title:`Decoder`,children:[d(Z,{label:`Node`,children:e.nodeId}),d(Z,{label:`Sessions`,children:e.sessionCount}),r(Z,{label:`SHM frames`,children:[d(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),d(`span`,{className:`text-foreground-subtle`,children:` written`})]}),r(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&r(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),r(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&d(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}n();var Kr=`pipeline-orchestrator`,qr={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},Jr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Yr({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>r(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[d(pt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Xr({deviceId:e,name:t,online:n,status:i,live:o,onlineNodes:s}){let l=c(),{data:u}=me({addonId:Kr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=h({deviceId:e},{staleTime:3e4}),p=a(()=>jr(u),[u]),m=a(()=>f===void 0?void 0:Mr(f.steps),[f]),g=a(()=>i===void 0?[]:Tr(i),[i]),_=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},v=L({onSuccess:_}),y=Te({onSuccess:_}),b=t=>{t===`auto`?y.mutate({deviceId:e}):v.mutate({deviceId:e,agentNodeId:t})},x=i===void 0?`idle`:wr(i),S=g.some(e=>e.severity===`error`),C=g.length>0,w=S?`border-danger/50`:C?`border-warning/40`:`border-border`;return r(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${w} bg-background overflow-hidden`,children:[r(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${S?`bg-danger`:qr[x]}`,title:S?`Error`:Jr[x],"aria-label":S?`Error`:Jr[x],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),r(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),r(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),i?.recording!=null&&(i.recording.active?r(Q,{tone:`danger`,title:`Recording (${i.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):i.recording.mode!==`off`&&r(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,i.recording.mode]}))]})]}),g.length>0&&d(Yr,{problems:g}),i===void 0?d(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(Ir,{assignment:i.assignment,settings:p,onlineNodes:s,pinPending:v.isPending||y.isPending,onDetectionPinChange:b}),d(Ur,{detection:i.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(Vr,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:i.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(Br,{streams:i.source.streams,brokerProfiles:i.broker?.profiles,settings:p,motionEnabled:i.motion?.enabled??null,motionFpsLive:i.motion?.fps??null}),d(Wr,{broker:i.broker}),d(Gr,{decoder:i.decoder,detectionActive:i.detection?.phase===`active`})]})]})}n();var Zr=5e3,Qr=1e4,$r=5e3;function ei(e){let t=c(),{data:n,isLoading:r}=Re(),{data:i,isLoading:o}=v({},{refetchInterval:Zr}),{nodes:s}=R();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);N(Ae.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-Qr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},$r);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}n();function ti({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:i,isLoading:o}=ei(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:Tr(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:r(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[r(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[r(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),r(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),r(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(Xr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:i},e.deviceId))]})})}n();var ni=`__cluster__`;function ri(e){return e===`cameras`?`cameras`:`nodes`}function ii(){let[e,t]=ut(),n=ri(e.get(`view`)),i=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:ni},{replace:!0})},[n,e,t]),r(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[r(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[r(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[d(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:i},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),d(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),d(`div`,{className:`flex items-center gap-2`,children:r(`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:[d(Xe,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),n===`nodes`&&r(`button`,{type:`button`,onClick:()=>l(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:[r(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(lt,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?r(o,{children:[d(`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:d(kt,{selectedNodeId:i,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:i===`__cluster__`?d(xr,{refreshToken:a}):d(Tn,{nodeId:i,refreshToken:a})})]}):d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:d(ti,{refreshToken:a})})})]})}export{ii as PipelinePage};
|