@camstack/addon-admin-ui 1.2.355 → 1.2.356
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/Addons-vaVt3N8c.js +4 -0
- package/dist/assets/{AdminTabs-jmzYA4Gj.js → AdminTabs-BOhyA0v_.js} +1 -1
- package/dist/assets/AiProfiles-gc9Na6rv.js +3 -0
- package/dist/assets/{BrokerForm-Cv_WPhvt.js → BrokerForm-Bxjn8Xkb.js} +1 -1
- package/dist/assets/Build-DNhwnx2k.js +40 -0
- package/dist/assets/{Calendars-MFMnXqjT.js → Calendars-9eEuusHn.js} +1 -1
- package/dist/assets/{Capabilities-BzcFdoxe.js → Capabilities-BuQgXiX1.js} +1 -1
- package/dist/assets/Cluster-BGpeqgpD.js +11 -0
- package/dist/assets/ClusterStepModel-Cg0YqJM-.js +1 -0
- package/dist/assets/{CompositionEditor-C9f51ycE.js → CompositionEditor-DsZomdtR.js} +1 -1
- package/dist/assets/{CompositionEditorPage-GhqEH8fu.js → CompositionEditorPage-CEYhfRyr.js} +1 -1
- package/dist/assets/{Data-DW-C0JmT.js → Data-CxzcaPPX.js} +1 -1
- package/dist/assets/DetectionIntelligence-esy4sm8-.js +1 -0
- package/dist/assets/DeviceDetail-BUFpgkeN.js +2 -0
- package/dist/assets/{DeviceDoActionFields-DTRBrGeQ.js → DeviceDoActionFields-C_OPAByq.js} +1 -1
- package/dist/assets/{Devices-urEV4IEL.js → Devices-D5wKCK9_.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-RP6PYmQ3.js → EmbedPlayerPage-xTUcKS8t.js} +1 -1
- package/dist/assets/Events-BD2v1o2Z.js +1 -0
- package/dist/assets/Identity-hydVfEcG.js +1 -0
- package/dist/assets/IntegrationDetail-IjNeTPn2.js +1 -0
- package/dist/assets/{IntegrationHub-3NtGsJ8f.js → IntegrationHub-Czg3bSVM.js} +1 -1
- package/dist/assets/Integrations-ErVYCOG1.js +1 -0
- package/dist/assets/{Integrations-EkMwKxz0.js → Integrations-xrJzBxAs.js} +1 -1
- package/dist/assets/Locations-BBu_JUg1.js +3 -0
- package/dist/assets/{Logs-BwMwasxy.js → Logs-hVhOlpsU.js} +1 -1
- package/dist/assets/{MotionZonesSettings--ZP6wq8p.js → MotionZonesSettings-B8426WyB.js} +1 -1
- package/dist/assets/MyAccess-D0PqfqUg.js +2 -0
- package/dist/assets/Network-1FUHkoPH.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-BbRT6OqB.js → NodeAddonsSettingsPanel-Bin020YC.js} +1 -1
- package/dist/assets/Notifications-DBedpZv-.js +1 -0
- package/dist/assets/{Plates-D82UR8AW.js → Plates-D1_YX1bj.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-UJpZQuWF.js → PrivacyMaskSettings-C-lyYBaQ.js} +1 -1
- package/dist/assets/Recordings-9M71-km4.js +1 -0
- package/dist/assets/{ScanNetworkModal-Dq6vPLgX.js → ScanNetworkModal-DjrnLqkB.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CwTxeG1H.js → SceneMonitorEditor-CnTzBKHk.js} +1 -1
- package/dist/assets/{Scenes-BxWxF9RG.js → Scenes-9o38vvfG.js} +1 -1
- package/dist/assets/{Secrets-B1Py-XlE.js → Secrets-Di_XuHEM.js} +1 -1
- package/dist/assets/{Settings-D3l2szna.js → Settings-CdsQXImT.js} +1 -1
- package/dist/assets/{Showroom-DCK8-7b8.js → Showroom-CueI9Hof.js} +1 -1
- package/dist/assets/{Terminal-C2SFvaOH.js → Terminal-CgkhEdVL.js} +3 -3
- package/dist/assets/{Viewer-qJaACnXs.js → Viewer-CXSln4qp.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-4FAaqbgl.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D23uSeCV.js} +1 -1
- package/dist/assets/{archive-C9jrGy5Q.js → archive-HjFKqcYJ.js} +1 -1
- package/dist/assets/{authed-media-DQAkskU5.js → authed-media-DTi-1YAt.js} +1 -1
- package/dist/assets/{boxes-BNIPhLCT.js → boxes-Bhz-2O4q.js} +1 -1
- package/dist/assets/circle-slash-RDy1aZkR.js +1 -0
- package/dist/assets/client-DuQQ55XQ.js +357 -0
- package/dist/assets/crop-BWtvQsYY.js +1 -0
- package/dist/assets/{debounced-invalidate-COhAlfWE.js → debounced-invalidate-BmvWt3Mf.js} +1 -1
- package/dist/assets/{device-integration-icon-KaXkp2LK.js → device-integration-icon-vpQeGGPt.js} +1 -1
- package/dist/assets/device-picker-model-C1VaG3XC.js +1 -0
- package/dist/assets/dist-B46vwY9Q.js +357 -0
- package/dist/assets/{dist-YROsaxnC.js → dist-BVQ0qNkk.js} +1 -1
- package/dist/assets/{face-bbox-CFdWEIAo.js → face-bbox-DIMw9bdN.js} +1 -1
- package/dist/assets/{hard-drive-download-D11tb7sM.js → hard-drive-download-DGUpD-NK.js} +1 -1
- package/dist/assets/{hostInit-C1Zchdpp.js → hostInit-jbr3yepU.js} +1 -1
- package/dist/assets/{index-d2QAhmc-.js → index-I9Gc2ACc.js} +3 -3
- package/dist/assets/{layers-DYdFVal1.js → layers-TAdyTRRS.js} +1 -1
- package/dist/assets/{location-owned-usage-DJjVpEH8.js → location-owned-usage-D5P9h6fD.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-164529ae.js → mf-entry-bootstrap-0-c002b961.js} +2 -2
- package/dist/assets/mount-C1VaG3XC.js +1 -0
- package/dist/assets/notification-schedule-field-DdO5UXE-.js +1 -0
- package/dist/assets/{player-overlays-tKtUzh3g.js → player-overlays-PPtffSZH.js} +1 -1
- package/dist/assets/remoteEntry-CdbrIBDO.js +1 -0
- package/dist/assets/{send-C3mZ85mq.js → send-qYTKAtys.js} +1 -1
- package/dist/assets/{settings-2-CCI879zJ.js → settings-2-BfvfZMIZ.js} +1 -1
- package/dist/assets/{src-Y4G_LfLc.js → src-EnVigh-D.js} +17 -17
- package/dist/assets/{unlink-m4c0iz87.js → unlink-CvsfIFka.js} +1 -1
- package/dist/assets/{use-scenes-feed-DyIyOk7m.js → use-scenes-feed-DupdXK3r.js} +1 -1
- package/dist/assets/{use-stationary-objects-DqQJT1ff.js → use-stationary-objects-Blrh3fb3.js} +1 -1
- package/dist/assets/useEventInvalidation-C1VaG3XC.js +1 -0
- package/dist/assets/{useNodeUrlSelection-CEK0v_3k.js → useNodeUrlSelection-DemYJ0D7.js} +1 -1
- package/dist/assets/user-round-BCwcukON.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B0TfzpP_.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CFcHLszk.js} +2 -2
- package/dist/index.html +7 -7
- package/dist/server/addon.js +126 -2
- package/package.json +1 -1
- package/dist/assets/Addons-Bzf-UqEw.js +0 -4
- package/dist/assets/AiProfiles-DDUitYj8.js +0 -3
- package/dist/assets/Build-3A9gyeeL.js +0 -40
- package/dist/assets/Cluster-B8MOp6Pr.js +0 -11
- package/dist/assets/ClusterStepModel-DCIodYpM.js +0 -1
- package/dist/assets/DetectionIntelligence-CrH_kLX1.js +0 -1
- package/dist/assets/DeviceDetail-CDOw1qyD.js +0 -2
- package/dist/assets/Events-zS0-6Rd3.js +0 -1
- package/dist/assets/Identity-Dqul-DNR.js +0 -1
- package/dist/assets/IntegrationDetail-wBX3nT_i.js +0 -1
- package/dist/assets/Integrations-BAPCCTL_.js +0 -1
- package/dist/assets/Locations-CLBXHuE9.js +0 -3
- package/dist/assets/MyAccess-DRVHIYEW.js +0 -2
- package/dist/assets/Network-vx7gg32u.js +0 -1
- package/dist/assets/Notifications-DlINBoX1.js +0 -1
- package/dist/assets/Recordings-C9JJ_i3X.js +0 -1
- package/dist/assets/circle-slash-BYpk_wjd.js +0 -1
- package/dist/assets/client-HDm3z1QL.js +0 -357
- package/dist/assets/crop-9g1Z5sFT.js +0 -1
- package/dist/assets/device-picker-model-D_5ynS9o.js +0 -1
- package/dist/assets/dist-DPdG1Rf2.js +0 -357
- package/dist/assets/mount-D_5ynS9o.js +0 -1
- package/dist/assets/notification-schedule-field-C3V8Yo1S.js +0 -1
- package/dist/assets/remoteEntry-8SJYH9n-.js +0 -1
- package/dist/assets/useEventInvalidation-D_5ynS9o.js +0 -1
- package/dist/assets/user-round-BGmDt-wq.js +0 -1
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,V as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as d,gt as f,ht as p,st as m,vt as h}from"./player-overlays-tKtUzh3g.js";import{Ad as g,Fo as _,Go as v,Gs as y,Ho as b,If as x,Io as S,Jc as C,Kc as w,Nt as T,Pt as E,Pu as D,Uo as O,Wo as ee,Yc as te,_t as ne,ar as k,dd as re,du as ie,fu as A,gf as ae,gl as oe,gt as se,hc as ce,id as le,ir as ue,ld as j,nd as de,nf as fe,or as pe,qc as me,qn as he,rd as ge,sa as _e,sr as ve,ud as ye,vd as be,xf as xe,yu as Se}from"./src-Y4G_LfLc.js";import{t as Ce}from"./hard-drive-download-D11tb7sM.js";import{Kr as we}from"./client-HDm3z1QL.js";import{t as M}from"./useTranslation-Bc5yH9V9.js";import{t as Te}from"./NodeAddonsSettingsPanel-BbRT6OqB.js";import{t as N}from"./format-size-DIxKXxtj.js";import{n as Ee,r as De,t as Oe}from"./useNodeUrlSelection-CEK0v_3k.js";var P=h(`memory-stick`,[[`path`,{d:`M12 12v-2`,key:`fwoke6`}],[`path`,{d:`M12 18v-2`,key:`qj6yno`}],[`path`,{d:`M16 12v-2`,key:`heuere`}],[`path`,{d:`M16 18v-2`,key:`s1ct0w`}],[`path`,{d:`M2 11h1.5`,key:`15p63e`}],[`path`,{d:`M20 18v-2`,key:`12ehxp`}],[`path`,{d:`M20.5 11H22`,key:`khsy7a`}],[`path`,{d:`M4 18v-2`,key:`1c3oqr`}],[`path`,{d:`M8 12v-2`,key:`1mwtfd`}],[`path`,{d:`M8 18v-2`,key:`qcmpov`}],[`rect`,{x:`2`,y:`6`,width:`20`,height:`10`,rx:`2`,key:`1qcswk`}]]);n();function ke(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function Ae({state:e}){return l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var je=[`trace`,`debug`,`info`,`warn`,`error`];function Me({proc:e,nodeId:t,defaultExpanded:n,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[u,d]=c(s||n),[m,h]=c(null),[g,_]=c(`info`),y=e.name.includes(`(core)`),b=O(),x=ee(),S=v(),C=async e=>{h(e);try{await b.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},w=async()=>{h(e.name);try{await x.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},T=async n=>{let r=`${t}/${e.name}`;try{await S.mutateAsync({nodeId:r,level:n}),_(n)}catch(e){console.error(`Failed to set log level:`,e)}};return r(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[r(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>d(!u),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&d(!u)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?l(`span`,{className:`h-3 w-3 shrink-0`}):l(u?f:p,{className:`h-3 w-3 text-muted-foreground shrink-0`}),y?l(de,{className:`h-3.5 w-3.5 text-primary shrink-0`}):l(xe,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),l(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),l(Ae,{state:e.state}),r(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:N(e.memoryRss)}),l(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:ke(e.uptimeSeconds)}),!y&&r(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[r(ue,{children:[l(ve,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:g}),l(k,{align:`end`,className:`min-w-[70px] py-0.5`,children:je.map(e=>l(pe,{onClick:()=>T(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),l(`button`,{onClick:w,disabled:m===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:l(j,{className:`h-3 w-3 ${m===e.name?`animate-spin`:``}`})})]})]}),u&&o.length>0&&l(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>r(`div`,{children:[r(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[l(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),l(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&r(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>l(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&r(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),r(`div`,{className:`flex items-center gap-1 shrink-0`,children:[l(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:l(le,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:l(re,{className:`h-3 w-3`})}),l(`button`,{onClick:()=>C(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:l(j,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(ne,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&l(`div`,{className:`border-t border-border/40 bg-muted/5`,children:l(se,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),u&&o.length===0&&l(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function Ne({nodeId:e,processes:t}){let[n,r]=c(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):l(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>l(Me,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}var Pe={system:0,managed:1,root:2};n();function Fe(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function Ie(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Le({nodeId:e}){let t=s(),n=A(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:i}=S({nodeId:e}),o=n?.processes??i,c=a(()=>o?[...o]:[],[o]),u=a(()=>[{key:`classification`,header:`Class`,sortValue:e=>Pe[e.classification],render:e=>l(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>l(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>l(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:`Addon`,sortValue:e=>e.addonId,render:e=>l(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:`Command`,nowrap:!1,render:e=>l(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Ie(e.command)})},{key:`cpuPercent`,header:`CPU%`,align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>N(e.memoryRssBytes)},{key:`uptimeSec`,header:`Uptime`,align:`right`,sortValue:e=>e.uptimeSec,render:e=>l(`span`,{className:`text-foreground-subtle`,children:Fe(e.uptimeSec)})}],[]);return r(`div`,{className:`space-y-4`,children:[l(`div`,{className:`flex items-start justify-end gap-4`,children:r(`button`,{type:`button`,onClick:()=>t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[l(ye,{className:`h-3 w-3`}),` Refresh`]})}),l(T,{columns:u,rows:c,rowKey:e=>e.pid,minWidthPx:880,mobileMode:`scroll`,maxBodyHeight:E,emptyMessage:`Scanning…`})]})}var F={width:320,height:64},Re=.8,I=Math.ceil(8*Re-3)+1,L=F.width+34,R=F.height+I+1+11,ze=I+F.height+1+3+Math.ceil(8*Re),Be=[1,2,5,10],Ve=[1,2,4,8,16,32,64,128,256,512,1024],He=[1,1.5,2,2.5,3,4,5],z=[4,3,5,2],Ue=1e-9;function We(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return He.some(e=>Math.abs(t-e)<Ue)}let n=e/10**Math.floor(Math.log10(e));return He.some(e=>Math.abs(n-e)<Ue)}function Ge(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of Ve){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of Be){let t=e*i;if(t>=r)return t}return 10*i}function B(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=z.find(n=>We(e/n,t))??z[z.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var Ke=2.5;function V(e){return e*Ke}function H(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function U(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function W(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function G(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function qe(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function Je(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function Ye(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}n();var K={main:`var(--load-series-main)`,gc:`var(--load-series-gc)`},Xe=`
|
|
2
|
-
.load-chart-scope { --load-series-main: #2a78d6; --load-series-gc: #e87ba4; }
|
|
3
|
-
@media (prefers-color-scheme: dark) {
|
|
4
|
-
:root:not([data-theme="light"]) .load-chart-scope {
|
|
5
|
-
--load-series-main: #3987e5; --load-series-gc: #d55181;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
:root[data-theme="dark"] .load-chart-scope {
|
|
9
|
-
--load-series-main: #3987e5; --load-series-gc: #d55181;
|
|
10
|
-
}
|
|
11
|
-
`,q=F,Ze={height:R};function Qe({title:e,points:n,mainLabel:s,gcLabel:u,formatValue:d,emptyMessage:f,gapMs:p}){let m=i(),h=t(null),[g,_]=c(null),v=a(()=>{let e=n.map(e=>({atMs:e.atMs,value:e.main===null||e.gc===null?null:e.main+e.gc})),t=n.map(e=>({atMs:e.atMs,value:e.main})),r=Ge(e.map(e=>e.value),25,`linear`),i=H(e,q,r,p),a=H(t,q,r,p),o=a.map(e=>({x:e.x,y:e.y===null?null:q.height,gapBefore:e.gapBefore}));return{max:r,ticks:B(r,`linear`),upper:i,middle:a,base:o,gaps:Je(i),times:G(e,q),spanMs:qe(e)}},[n,p]),y=n.at(-1),b=g===null?void 0:n[g.index],x=b??y;return n.length===0||v.upper.every(e=>e.y===null)?l(Y,{title:e,children:l(ct,{message:f})}):l(Y,{title:e,legend:r(o,{children:[l(st,{color:K.main,label:s}),l(st,{color:K.gc,label:u})]}),readout:x&&x.main!==null&&x.gc!==null?r(o,{children:[b!==void 0&&l(ot,{atMs:b.atMs,spanMs:v.spanMs}),l(X,{color:K.main,text:d(x.main)}),l(X,{color:K.gc,text:d(x.gc)})]}):null,children:r(`svg`,{ref:h,viewBox:`0 0 ${L} ${R}`,preserveAspectRatio:`none`,className:`w-full`,style:Ze,role:`img`,"aria-label":`${e}: ${s} and ${u} over time`,onMouseLeave:()=>_(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*L-34,r=Ye(v.upper,n);r!==null&&_({index:r,xPx:v.upper[r].x})},children:[l($e,{ticks:v.ticks,max:v.max,formatValue:d}),l(at,{ticks:v.times,spanMs:v.spanMs}),r(`g`,{transform:`translate(34,${I})`,clipPath:`url(#${m})`,children:[l(`clipPath`,{id:m,children:l(`rect`,{x:0,y:0,width:q.width,height:q.height})}),l(et,{spans:v.gaps}),l(`path`,{d:W(v.middle,v.base),fill:K.main,fillOpacity:.85}),l(`path`,{d:W(v.upper,v.middle),fill:K.gc,fillOpacity:.85,stroke:`var(--color-surface, transparent)`,strokeWidth:2}),l(`path`,{d:U(v.upper),fill:`none`,stroke:K.gc,strokeWidth:2}),g!==null&&l(`line`,{x1:g.xPx,x2:g.xPx,y1:0,y2:q.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function J({title:e,points:n,formatValue:i,emptyMessage:s,axisFloor:u,axisScale:d=`linear`,gapMs:f}){let p=t(null),[m,h]=c(null),g=a(()=>{let e=Ge(n.map(e=>e.value),u,d),t=H(n,q,e,f);return{max:e,ticks:B(e,d),projected:t,gaps:Je(t),times:G(n,q),spanMs:qe(n)}},[n,u,d,f]),_=m===null?void 0:n[m.index],v=_??n.at(-1)??void 0;return n.length===0||g.projected.every(e=>e.y===null)?l(Y,{title:e,children:l(ct,{message:s})}):l(Y,{title:e,readout:v&&v.value!==null?r(o,{children:[_!==void 0&&l(ot,{atMs:_.atMs,spanMs:g.spanMs}),l(X,{color:K.main,text:i(v.value)})]}):null,children:r(`svg`,{ref:p,viewBox:`0 0 ${L} ${R}`,preserveAspectRatio:`none`,className:`w-full`,style:Ze,role:`img`,"aria-label":e,onMouseLeave:()=>h(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*L-34,r=Ye(g.projected,n);r!==null&&h({index:r,xPx:g.projected[r].x})},children:[l($e,{ticks:g.ticks,max:g.max,formatValue:i}),l(at,{ticks:g.times,spanMs:g.spanMs}),r(`g`,{transform:`translate(34,${I})`,children:[l(et,{spans:g.gaps}),l(`path`,{d:U(g.projected),fill:`none`,stroke:K.main,strokeWidth:2}),m!==null&&l(`line`,{x1:m.xPx,x2:m.xPx,y1:0,y2:q.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function $e({ticks:e,max:t,formatValue:n}){let i=t<=0?1:t;return l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>{let t=I+q.height-e/i*q.height;return r(`g`,{children:[l(`line`,{x1:34,x2:34+q.width,y1:t,y2:t,stroke:`currentColor`,strokeWidth:.5,strokeOpacity:.3}),l(`text`,{x:0,y:t+3,fontSize:8,fill:`currentColor`,children:n(e)})]},e)})})}function et({spans:e}){return e.length===0?null:l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>l(`rect`,{x:e.fromX,y:0,width:Math.max(1,e.toX-e.fromX),height:q.height,fill:`currentColor`,fillOpacity:.12,children:l(`title`,{children:`No samples in this interval — nothing was measured, nothing is drawn.`})},`${e.fromX}-${e.toX}`))})}var tt=10*6e4,nt={hour:`2-digit`,minute:`2-digit`},rt={hour:`2-digit`,minute:`2-digit`,second:`2-digit`};function it(e,t){return new Date(e).toLocaleTimeString(void 0,t<tt?rt:nt)}function at({ticks:e,spanMs:t}){return e.length===0?null:l(`g`,{className:`text-foreground-subtle`,children:e.map(e=>l(`text`,{x:34+e.x,y:ze,fontSize:8,textAnchor:e.anchor,fill:`currentColor`,children:it(e.atMs,t)},e.atMs))})}function ot({atMs:e,spanMs:t}){return l(`span`,{className:`text-[10px] tabular-nums text-foreground-subtle`,children:it(e,t)})}function Y({title:e,legend:t,readout:n,children:i}){return r(`div`,{className:`load-chart-scope min-w-0`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-1`,children:[l(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:e}),l(`div`,{className:`flex items-center gap-2`,children:n})]}),i,t&&l(`div`,{className:`flex items-center gap-3 mt-1`,children:t})]})}function st({color:e,label:t}){return r(`span`,{className:`inline-flex items-center gap-1 text-[9px] text-foreground-subtle`,children:[l(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function X({color:e,text:t}){return r(`span`,{className:`inline-flex items-center gap-1 text-[11px] tabular-nums text-foreground`,children:[l(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function ct({message:e}){return l(`div`,{className:`h-16 flex items-center justify-center rounded border border-dashed border-border text-[10px] text-foreground-subtle text-center px-2`,children:e})}function lt(e,t){let n=e.at(-1);return n===void 0?[t]:t.atMs>n.atMs?[...e,t]:e.some(e=>e.atMs===t.atMs)?e:[...e,t].toSorted((e,t)=>e.atMs-t.atMs)}function ut(e,t,n,r){let i=e.get(t),a=lt(i?.points??[],r);if(i!==void 0&&a===i.points)return e;let o=new Map(e);return o.set(t,{key:t,kind:n,points:a.slice(Math.max(0,a.length-720))}),o}function dt(e,t,n){let r=e;for(let e of we(t,n))r=ut(r,e.key,e.kind,e.point);return r}function ft(e,t){let n=e;for(let e of t)for(let t of e.points)n=ut(n,e.key,e.kind,t);return n}function pt(e){let t=null;for(let n of e.values()){let e=n.points.at(-1);e!==void 0&&(t===null||e.atMs>t)&&(t=e.atMs)}return t}var mt=12e4;function ht(e,t){return e===null?!1:t-e>mt}function gt(e){let t=e=>{let t=e.points.at(-1);return t===void 0?-1:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.key.localeCompare(n.key):r})}function _t(e){for(let t of e.values()){let e=t.points.at(-1);if(e&&e.cpuMainPercent!==null)return!0}return!1}var vt={key:`cpu`,dir:`desc`};function yt(e){let t=e.points.at(-1);return t===void 0?null:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent}function bt(e){return e.points.at(-1)?.memoryRssBytes??null}function xt(e,t,n){let r=n.trim().toLowerCase();return r===``?!0:e.toLowerCase().includes(r)||t.toLowerCase().includes(r)}function St(e,t){return t===`memory`?bt(e):yt(e)}function Ct(e,t,n){let r=e.filter(e=>t.selectedKeys.size>0&&!t.selectedKeys.has(e.key)?!1:xt(n(e),e.key,t.search)),i=(e,t)=>e.key.localeCompare(t.key);return[...r].toSorted((e,r)=>{if(t.sort.key===`name`){let a=n(e).localeCompare(n(r)),o=t.sort.dir===`asc`?a:-a;return o===0?i(e,r):o}let a=St(e,t.sort.key),o=St(r,t.sort.key);if(a===null&&o===null)return i(e,r);if(a===null)return 1;if(o===null)return-1;let s=t.sort.dir===`desc`?o-a:a-o;return s===0?i(e,r):s})}n();function wt(e,n=720){let r=A(`metrics.node-processes-snapshot`,t=>t.nodeId===e),[i,a]=c(new Map),[o,s]=c(void 0),l=t(null),{data:d,isPending:f}=_({forNodeId:e,sinceMs:o,maxPoints:n});u(()=>{d!==void 0&&a(e=>{let t=ft(e,d.series);return l.current=pt(t),t})},[d]);let p=r?.timestamp;u(()=>{r==null||p===void 0||(ht(l.current,p)&&s(l.current??0),a(e=>{let t=dt(e,r.processes,p);return l.current=pt(t),t}))},[p]),u(()=>{a(new Map),s(void 0),l.current=null},[e]);let m=0;for(let e of i.values())m=Math.max(m,e.points.length);return{series:gt(i),sampleCount:m,threadSplitAvailable:_t(i),loadingRetained:f,durable:d?.durable??null,bucketMs:d?.bucketMs??null,cadenceMs:d?.cadenceMs??null,retainedSamples:d?.retainedSamples??null}}var Tt=`__unclaimed__`;function Et(e,t){return{kind:e,deviceId:t,cpu:0,cpuKnown:!0,rss:0,rssKnown:!0,count:0,roles:new Set}}function Dt(e,t){return{key:e,kind:t.kind,deviceId:t.deviceId,cpuSeconds:t.cpuKnown?Math.round(t.cpu*100)/100:null,rssBytes:t.rssKnown?t.rss:null,unitCount:t.count,roles:[...t.roles].sort()}}function Ot(e,t){let n=new Map,r=new Set;for(let t of e){t.pid!==void 0&&r.add(t.pid);let e=t.deviceId!==null&&t.attribution!==`unattributable`,i=e?`device:${t.deviceId}`:`shared:${t.role}`,a=n.get(i)??Et(e?`camera`:`shared`,e?t.deviceId:null);a.count+=1,a.roles.add(t.role),t.cpuSeconds===void 0?a.cpuKnown=!1:a.cpu+=t.cpuSeconds,t.rssBytes===void 0?a.rssKnown=!1:a.rss+=t.rssBytes,n.set(i,a)}let i=[...n.entries()].map(([e,t])=>Dt(e,t));if(t===void 0)return i;let a=t.filter(e=>!r.has(e.pid));if(a.length===0)return i;let o=Et(`unclaimed`,null);for(let e of a)o.count+=1,o.rss+=e.memoryRssBytes;return o.cpuKnown=!1,[...i,Dt(Tt,o)]}var kt=[{family:`decode`,attribution:`measured`,unit:`one forked decode-worker child per decode SESSION`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:118`,`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:131`,`packages/addon-pipeline/src/pipeline-runner/index.ts:2765`,`packages/types/src/process/child-cost-registry.ts:188`]},{family:`transcode`,attribution:`measured`,unit:`one ffmpeg child per (camera, encode plan)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/egress-transcode-manager.ts:960`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:282`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:324`,`packages/types/src/ffmpeg/sharing-key.ts:139`]},{family:`recording`,attribution:`measured`,unit:`one passthrough ffmpeg per (camera, profile)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:33`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:217`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:279`,`packages/addon-pipeline/src/recorder/addon/recording-controller.ts:1710`]},{family:`detection`,attribution:`accounted`,unit:`a SHARED inference pool per (node, runtime, device) — no per-camera process`,perCamera:!1,wiredToday:!0,missingLink:"Nothing is missing for COUNTING — per-camera inference milliseconds, processed/shed frames and bytes-to-pool are already accumulated. What is missing is any basis for CPU seconds: `deviceId` reaches the pool as a diagnostic label and selects nothing, so cost can only ever be apportioned, never measured. Since 2026-08-27 the pool DECLARES this itself, contributing `deviceId: null` + `attribution: unattributable` rather than leaving an observer to infer it — the renunciation is data, and it is still refused by the chart gate.",evidence:[`packages/addon-pipeline/src/detection-pipeline/provider.ts:540`,`packages/addon-pipeline/src/detection-pipeline/engine/shared-inference-pool.ts:413`,`packages/types/src/interfaces/inference-engine.ts:24`,`packages/addon-pipeline/src/pipeline-runner/timing-sampler.ts:63`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:353`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:849`,`packages/addon-pipeline/src/pipeline-runner/frame-lazy-metrics.ts:100`]},{family:`streaming`,attribution:`measured`,unit:"one StreamBroker per `${deviceId}/${camStreamId}`, with an exact RTP ring byte counter",perCamera:!0,wiredToday:!1,missingLink:"The ffmpeg-backed ingest is now reported per camera, but that is the minority path. `rtpRingBytes` — the exact figure for the in-process case — is maintained on every push and drop and is still private and absent from `getStats()`. The three `EncodedRingBuffer`s track packets and duration and have no byte accumulator at all; the only byte figure they offer is `preRollBudgetBytes`, which is a BUDGET, not an occupancy.",evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2895`,`packages/addon-pipeline/src/stream-broker/rtsp/ffmpeg-push-reader.ts:189`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:494`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:498`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2505`,`packages/addon-pipeline/src/stream-broker/stream-broker/pre-roll.ts:269`]}];function At(e){return e.attribution===`measured`&&e.wiredToday}function jt(){let e=new Set;for(let t of kt)At(t)&&e.add(t.family);return e}var Mt=jt();function Nt(e){return!Mt.has(e.role)||e.deviceId===null?!1:e.attribution===`measured`}function Z(e){return`${e.addonId}${e.role}${e.unit}${e.pid??`-`}`}function Pt(){return{cpuSeconds:0,cpuKnown:!0,rssBytes:0,rssKnown:!0,unitCount:0,roles:new Set}}function Ft(e,t,n){if(t.cpuSeconds===void 0)return null;if(e===void 0)return t.startedAtMs===void 0||t.startedAtMs<n?null:t.cpuSeconds;if(e.cpuSeconds===void 0||e.startedAtMs===void 0||t.startedAtMs===void 0||e.startedAtMs!==t.startedAtMs)return null;let r=t.cpuSeconds-e.cpuSeconds;return r<0?null:r}function It(e){return Math.round(e*10)/10}function Lt(e,t){let n=t.atMs-e.atMs;if(n<=0)return[];let r=n/1e3,i=new Map;for(let t of e.entries)Nt(t)&&i.set(Z(t),t);let a=new Map,o=new Set;for(let n of t.entries){if(!Nt(n)||n.deviceId===null)continue;let t=Z(n);o.add(t);let r=a.get(n.deviceId)??Pt();r.unitCount+=1,r.roles.add(n.role);let s=Ft(i.get(t),n,e.atMs);s===null?r.cpuKnown=!1:r.cpuSeconds+=s,n.rssBytes===void 0?r.rssKnown=!1:r.rssBytes+=n.rssBytes,a.set(n.deviceId,r)}for(let[e,t]of i){if(o.has(e)||t.deviceId===null)continue;let n=a.get(t.deviceId);n!==void 0&&(n.cpuKnown=!1)}return[...a.entries()].map(([e,n])=>({deviceId:e,point:{atMs:t.atMs,cpuPercent:n.cpuKnown?It(n.cpuSeconds/r*100):null,rssBytes:n.rssKnown?n.rssBytes:null,unitCount:n.unitCount,roles:[...n.roles].toSorted()}}))}function Rt(e,t){if(t.length===0)return e;let n=new Map(e);for(let e of t){let t=n.get(e.deviceId),r=t?.points.at(-1);if(r!==void 0&&e.point.atMs<=r.atMs)continue;let i=[...t?.points??[],e.point];n.set(e.deviceId,{deviceId:e.deviceId,points:i.slice(Math.max(0,i.length-720))})}return n}function zt(e){let t=e=>{for(let t=e.points.length-1;t>=0;t--){let n=e.points[t]?.cpuPercent;if(n!=null)return n}return-1};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.deviceId-n.deviceId:r})}function Bt(e){let t=e.indexOf(`@`);return t===-1?{addonId:e,nodeId:null}:{addonId:e.slice(0,t),nodeId:e.slice(t+1)}}function Vt(e,t){let n=Bt(e);return n.nodeId===null?t.isHub:n.nodeId===t.nodeId}function Ht(e,t){return e.filter(e=>Vt(e.addonId,t))}n();function Ut(e){let n=A(`metrics.node-processes-snapshot`,t=>t.nodeId===e.nodeId),r=oe(void 0,{staleTime:1/0,refetchOnWindowFocus:!1}),[i,a]=c(new Map),o=t(null),s=t(r.refetch);s.current=r.refetch;let l=n?.timestamp;u(()=>{l!==void 0&&s.current()},[l]),u(()=>{a(new Map),o.current=null},[e.nodeId,e.isHub]);let d=r.data,f=r.dataUpdatedAt;u(()=>{if(d===void 0||f===0)return;let t={atMs:f,entries:Ht(d,e)},n=o.current;if(o.current=t,n===null)return;let r=Lt(n,t);r.length!==0&&a(e=>Rt(e,r))},[d,f,e.nodeId,e.isHub]);let p=d===void 0?[]:Ht(d,e),m=n?.processes,h=Ot(p,m);return{series:zt(i),unclaimed:h.find(e=>e.kind===`unclaimed`)??null,loading:r.isPending,error:r.error===null?null:r.error.message}}function Wt(e){let t=new Map;for(let n of e){let e=n.name?.trim();e===void 0||e===``||t.set(n.id,e)}return t}var Gt=25,Kt=64*1024*1024,qt=1e4;function Jt({scope:e,cadenceMs:t}){let{t:n}=M(),i=Ut(e),{data:a=[]}=_e({isCamera:!0,projection:`slim`}),o=Wt(a),s=V(t??qt);return r(`section`,{className:`space-y-3`,children:[i.error!==null&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[l(D,{className:`h-3 w-3 mt-0.5 shrink-0`}),l(`span`,{children:n(`cameraLoad.readFailed`,`Could not read the load contributions: {{error}}. This is a failed read, NOT an idle cluster.`,{error:i.error})})]}),l(Xt,{unclaimed:i.unclaimed}),i.series.length===0&&i.error===null&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:i.loading?n(`cameraLoad.loading`,`Reading what the addons report…`):n(`cameraLoad.waitingWindow`,`No per-camera window yet.`)}),l(`div`,{className:`space-y-3`,children:i.series.map(e=>r(`div`,{className:`rounded-lg border border-border p-3`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[l(Yt,{deviceId:e.deviceId,name:o.get(e.deviceId)}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`cameraLoad.unitCount`,`{{count}} unit(s): {{roles}}`,{count:e.points.at(-1)?.unitCount??0,roles:(e.points.at(-1)?.roles??[]).join(`, `)})})]}),r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(J,{title:n(`cameraLoad.cpuTitle`,`CPU % of one core (delta)`),points:e.points.map(e=>({atMs:e.atMs,value:e.cpuPercent})),formatValue:e=>`${e.toFixed(1)}%`,axisFloor:Gt,gapMs:s,emptyMessage:n(`cameraLoad.cpuUnavailable`,`No measurable window yet.`)}),l(J,{title:n(`cameraLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.rssBytes})),formatValue:N,axisFloor:Kt,axisScale:`bytes`,gapMs:s,emptyMessage:n(`cameraLoad.memoryUnavailable`,`No memory reported.`)})]})]},e.deviceId))})]})}function Yt({deviceId:e,name:t}){let{t:n}=M();return t===void 0?l(`span`,{className:`text-xs font-medium text-foreground`,children:n(`cameraLoad.deviceLabel`,`Camera {{deviceId}}`,{deviceId:e})}):r(`span`,{className:`flex items-baseline gap-1.5 min-w-0`,children:[l(`span`,{className:`text-xs font-medium text-foreground truncate`,children:t}),r(`span`,{className:`shrink-0 text-[10px] font-mono text-foreground-subtle`,children:[`#`,e]})]})}function Xt({unclaimed:e}){let{t}=M();return e===null||e.unitCount===0?null:l(`div`,{className:`flex items-center gap-2`,children:l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-amber-500/10 text-amber-400 font-medium tabular-nums`,children:t(`cameraLoad.unclaimedBadge`,`{{count}} unclaimed · {{rss}}`,{count:e.unitCount,rss:e.rssBytes===null?`—`:N(e.rssBytes)})})})}n();var Zt=256*1024*1024,Qt=1e4;function $t({nodeId:e,isHub:t}){let{t:n}=M(),{series:i,sampleCount:o,threadSplitAvailable:s,loadingRetained:u,bucketMs:d,cadenceMs:f}=wt(e),[p,m]=c(``),[h,g]=c(new Set),[_,v]=c(vt),y=e=>e.key===`__root__`?n(`clusterLoad.bucketRoot`,`Node supervisor`):e.key===`__unattributed__`?n(`clusterLoad.bucketUnattributed`,`Unattributed processes`):e.key,b=V(d??f??Qt),x=a(()=>Ct(i,{search:p,selectedKeys:h,sort:_},y),[i,p,h,_]),S=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return r(`div`,{className:`space-y-4`,children:[l(`style`,{children:Xe}),l(en,{bucketMs:d,cadenceMs:f}),!s&&o>0&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-amber-500/40 bg-amber-500/5 px-3 py-2 text-[11px] text-amber-400`,children:[l(D,{className:`h-3 w-3 mt-0.5 shrink-0`}),l(`span`,{children:n(`clusterLoad.noThreadSplit`,`No thread-level CPU split on this node — /proc/<pid>/task is Linux-only, and the first sample after a restart has no window to measure. CPU below falls back to the ps lifetime AVERAGE, which is not a rate.`)})]}),o===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:u?n(`clusterLoad.loadingRetained`,`Reading the retained series from this node…`):n(`clusterLoad.waitingFirstSample`,`No retained samples for this node — waiting for the next snapshot (up to 20s). The chart needs two to draw a rate.`)}),i.length>0&&r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r(`label`,{className:`relative flex-1 min-w-[160px]`,children:[l(ge,{className:`pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-foreground-subtle`}),l(`input`,{type:`search`,value:p,onChange:e=>m(e.target.value),placeholder:n(`clusterLoad.searchPlaceholder`,`Find a runner…`),"aria-label":n(`clusterLoad.searchLabel`,`Find a runner`),className:`w-full rounded border border-border bg-background py-1 pl-7 pr-2 text-[11px] text-foreground placeholder:text-foreground-subtle`})]}),l(tn,{sort:_,onChange:v})]}),r(`div`,{className:`flex flex-wrap items-center gap-1`,children:[i.map(e=>{let t=h.has(e.key);return l(`button`,{type:`button`,"aria-pressed":t,onClick:()=>S(e.key),className:`rounded-full border px-2 py-0.5 text-[10px] transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:y(e)},e.key)}),h.size>0&&r(`button`,{type:`button`,onClick:()=>g(new Set),className:`inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground`,children:[l(Se,{className:`h-2.5 w-2.5`}),n(`clusterLoad.clearFilter`,`All runners`)]})]})]}),i.length>0&&x.length===0&&l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:n(`clusterLoad.noMatches`,`No runner matches this search on {{count}} present. The node is reporting — the filter is hiding them.`,{count:i.length})}),l(`div`,{className:`space-y-3`,children:x.map(e=>r(`div`,{className:`rounded-lg border border-border p-3`,children:[r(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[l(`span`,{className:`text-xs font-medium text-foreground`,children:y(e)}),l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.processCount`,`{{count}} process(es)`,{count:e.points.at(-1)?.processCount??0})})]}),r(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[l(Qe,{title:s?n(`clusterLoad.cpuTitle`,`CPU % of one core`):n(`clusterLoad.cpuTitleLifetime`,`CPU % (ps lifetime average)`),mainLabel:n(`clusterLoad.seriesMain`,`Main threads`),gcLabel:n(`clusterLoad.seriesGc`,`GC / V8 helpers`),points:e.points.map(e=>({atMs:e.atMs,main:e.cpuMainPercent,gc:e.cpuGcPercent})),formatValue:e=>`${e.toFixed(0)}%`,gapMs:b,emptyMessage:n(`clusterLoad.cpuUnavailable`,`No thread split on this node. Lifetime average: {{avg}}%`,{avg:(e.points.at(-1)?.cpuLifetimePercent??0).toFixed(1)})}),l(J,{title:n(`clusterLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.memoryRssBytes})),formatValue:N,axisFloor:Zt,axisScale:`bytes`,gapMs:b,emptyMessage:n(`clusterLoad.memoryUnavailable`,`No memory samples yet.`)})]})]},e.key))}),l(Jt,{scope:{nodeId:e,isHub:t},cadenceMs:f})]})}function en({bucketMs:e,cadenceMs:t}){let{t:n}=M();return e===null?null:l(`p`,{className:`text-[10px] text-foreground-subtle`,children:t!==null&&e>t?n(`clusterLoad.captionBucket`,`1 point = {{bucket}}s (bucket MAXIMUM, not a mean)`,{bucket:Math.round(e/1e3)}):n(`clusterLoad.captionRaw`,`1 point = 1 snapshot`)})}function tn({sort:e,onChange:t}){let{t:n}=M(),i=[{key:`cpu`,label:n(`clusterLoad.sortCpu`,`CPU`)},{key:`memory`,label:n(`clusterLoad.sortMemory`,`Memory`)},{key:`name`,label:n(`clusterLoad.sortName`,`Name`)}];return r(`div`,{className:`flex items-center gap-1`,children:[l(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.sortBy`,`Sort by`)}),i.map(n=>{let i=e.key===n.key;return r(`button`,{type:`button`,"aria-pressed":i,onClick:()=>t(i?{key:n.key,dir:e.dir===`desc`?`asc`:`desc`}:{key:n.key,dir:n.key===`name`?`asc`:`desc`}),className:`rounded border px-1.5 py-0.5 text-[10px] transition-colors ${i?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:[n.label,i&&(e.dir===`desc`?` ↓`:` ↑`)]},n.key)})]})}var nn=`No per-node settings on this node. Every other setting these addons expose is one value for the whole cluster — edit those in System → Settings, not here.`;function rn({nodeId:e,addonIds:t}){return t.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):l(`div`,{className:`w-full py-2`,children:l(Te,{nodeId:e,addonIds:t,level:`global`,fieldScope:`perNode`,emptyMessage:nn,selfTabbed:!0})})}n();function an({nodeId:e,addons:t}){let n=s(),{data:r,isLoading:i}=y({nodeId:e}),o=a(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),c=ce({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return o.length===0?l(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):l(T,{columns:[{key:`capName`,header:`Capability`,width:`w-1/2`,sortValue:e=>e.capName,render:e=>l(`span`,{className:`font-medium`,children:e.capName})},{key:`provider`,header:`Bound provider`,render:t=>{let n=r?.[t.capName]??t.providers[0]??``,a=t.providers.length===1;return l(`select`,{value:n,onChange:n=>c.mutate({nodeId:e,capName:t.capName,addonId:n.target.value}),disabled:a||c.isPending||i,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:a?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:t.providers.map(e=>l(`option`,{value:e,children:e},e))})}}],rows:o,rowKey:e=>e.capName,minWidthPx:520,mobileMode:`scroll`,maxBodyHeight:E})}n();function on(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function sn(e){let[t,n]=c(!1),[i,a]=c(e.name),o=s(),u=b({onSuccess:()=>{o.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),d=(e.localIps??[]).filter(e=>!e.includes(`:`)),f=(e.localIps??[]).filter(e=>e.includes(`:`)),p=async()=>{if(!i.trim()||i===e.name){n(!1);return}try{await u.mutateAsync({nodeId:e.nodeId,name:i.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},m=[[`Node ID`,l(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?r(`div`,{className:`flex items-center gap-1.5`,children:[l(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p(),e.key===`Escape`&&n(!1)},disabled:u.isPending,autoFocus:!0}),l(`button`,{onClick:()=>void p(),disabled:u.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:l(ae,{className:`h-3.5 w-3.5`})}),l(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:l(Se,{className:`h-3.5 w-3.5`})})]}):r(`div`,{className:`flex items-center gap-1.5`,children:[l(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&l(`button`,{onClick:()=>{a(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:l(be,{className:`h-3 w-3`})})]})],[`Hostname`,l(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):l(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?r(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):l(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,r(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,r(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,l(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,l(`span`,{className:`text-xs`,children:on(e.uptime)})],[`Engines`,e.engines.length>0?l(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):l(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return d.length>0&&m.push([`IPv4`,l(`div`,{className:`flex flex-wrap gap-1.5`,children:d.map((e,t)=>l(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),f.length>0&&m.push([`IPv6`,l(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>l(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),l(`div`,{className:`py-2`,children:l(`table`,{className:`w-full text-sm`,children:l(`tbody`,{children:m.map(([e,t],n)=>r(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[l(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),l(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}n();var cn=[[`serverManagement`,`getServerPackageStatus`]];function ln({label:e,tone:t}){return l(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function Q({label:e,value:t}){return r(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[l(`span`,{className:`text-foreground-subtle`,children:e}),l(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}var un={ok:`border-emerald-500/40 bg-emerald-500/10 text-emerald-500`,warn:`border-amber-500/40 bg-amber-500/10 text-amber-500`,error:`border-red-500/40 bg-red-500/10 text-red-500`};function dn(e){return e.outcome===`failed`?`error`:(e.outcome,e.accepted?`ok`:`warn`)}function fn(e,t){let n=t instanceof Error?t.message:String(t);return`${e(`serverManagement.outcomeDropped`,`The connection dropped and the result could not be confirmed. The node may be restarting — re-check the version above.`)} — ${n}`}function pn({node:t}){let{t:n}=M(),i=s(),a=he(),[o,u]=c(!1),[d,f]=c(null),p=t.isHub?void 0:{nodeId:t.id},m=C(p,{refetchInterval:1e4,enabled:t.isOnline,retry:1}),h=m.data??null,_=e(()=>{i.invalidateQueries({queryKey:cn})},[i]),v=me({onSettled:_}),y=w({onSettled:_}),b=te({onSettled:_}),S=e(async()=>{if(h?.latestVersion==null){f({tone:`warn`,text:n(`serverManagement.outcomeNoTarget`,`No target version is known for this node — run "Check for update" first.`)});return}if(await a({title:n(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:n(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:h.packageName,version:h.latestVersion,node:t.name}),confirmLabel:n(`serverManagement.confirmUpdateAction`,`Update & restart`)})){f(null);try{let e=await y.mutateAsync({version:h.latestVersion,...p});f({tone:dn(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:fn(n,e)})}}},[y,a,t.name,p,h,n]),T=e(async()=>{if(await a({title:n(`serverManagement.confirmRestartTitle`,`Restart node`),message:n(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:t.name}),confirmLabel:n(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})){f(null);try{let e=await b.mutateAsync(p);f({tone:dn(e),text:e.message}),e.restarting&&u(!0)}catch(e){f({tone:`warn`,text:fn(n,e)})}}},[a,t.name,b,p,n]),E=()=>{switch(h?.bootMode){case`data-root`:return{label:n(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:n(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:n(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},D=()=>{if(h==null)return null;switch(h.updateState){case`checking`:return{label:n(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:n(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:n(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return h.restartRequired===!0?{label:n(`serverManagement.stateRestartRequired`,`restart required`),tone:`warn`}:h.updateAvailable?{label:n(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:n(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},O=h?.bootMode===`workspace`,ee=t.isOnline&&h!=null&&!O&&h.updateAvailable&&h.updateState===`idle`&&!y.isPending,ne=t.isOnline&&h!=null&&h.updateState===`idle`&&!b.isPending,k=t.isOnline?D():null;return r(`div`,{className:`space-y-4 py-2`,children:[r(`div`,{className:`flex items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[l(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:h?.packageName??t.rootPackage?.name??`@camstack/server`}),t.isOnline&&h!=null&&l(ln,{...E()})]}),k!=null&&l(ln,{...k})]}),!t.isOnline&&l(Q,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage?.version??null}),t.isOnline&&m.isLoading&&r(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[l(g,{className:`h-4 w-4 animate-spin`}),n(`common.loading`,`Loading…`)]}),t.isOnline&&m.isError&&r(`div`,{className:`space-y-1.5`,children:[l(`p`,{className:`text-sm text-red-500`,children:n(`serverManagement.loadError`,`Could not load the node root-package status.`)}),t.rootPackage!=null&&l(Q,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage.version})]}),t.isOnline&&h!=null&&r(`div`,{className:`space-y-1.5`,children:[l(Q,{label:n(`serverManagement.runningVersion`,`Running version`),value:h.runningVersion}),l(Q,{label:n(`serverManagement.latestVersion`,`Latest on registry`),value:h.latestVersion}),l(Q,{label:n(`serverManagement.imageSeedVersion`,`Image seed (baked)`),value:h.seedVersion}),l(Q,{label:n(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:h.nodeRuntimeVersion}),h.pendingVersion!=null&&l(Q,{label:n(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:h.pendingVersion}),h.installedVersion!=null&&h.installedVersion!==h.runningVersion&&l(Q,{label:n(`serverManagement.installedVersion`,`Installed on disk (runs after restart)`),value:h.installedVersion})]}),t.isOnline&&h?.imageContract?.state===`behind-series`&&r(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-xs leading-relaxed text-red-500`,children:[l(`p`,{className:`mb-0.5 font-semibold`,children:n(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),l(`p`,{children:h.imageContract.message})]}),t.isOnline&&O&&l(`p`,{className:`text-xs text-foreground-subtle`,children:n(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),d!=null&&l(`p`,{role:`status`,className:`rounded border px-2 py-1.5 text-xs leading-relaxed ${un[d.tone]}`,children:d.text}),o&&r(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[l(g,{className:`h-4 w-4 animate-spin`}),n(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),t.isOnline&&r(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:v.isPending||h?.updateState===`staging`,onClick:()=>v.mutate(p),children:[v.isPending?l(g,{className:`h-3.5 w-3.5 animate-spin`}):l(ye,{className:`h-3.5 w-3.5`}),n(`serverManagement.checkForUpdate`,`Check for update`)]}),ee&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void S(),children:[y.isPending?l(g,{className:`h-3.5 w-3.5 animate-spin`}):l(x,{className:`h-3.5 w-3.5`}),n(`serverManagement.updateTo`,`Update to {{version}}`,{version:h?.latestVersion??``})]}),r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!ne,onClick:()=>void T(),children:[b.isPending?l(g,{className:`h-3.5 w-3.5 animate-spin`}):l(j,{className:`h-3.5 w-3.5`}),n(`serverManagement.restart`,`Restart`)]})]}),t.isOnline&&h?.lastCheckedAtMs!=null&&r(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[l(Ce,{className:`h-3 w-3`}),n(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(h.lastCheckedAtMs).toLocaleString()})]})]})}n();function mn({node:e}){let t=d(),[n,i]=c(`info`),[a,o]=c(!1),[s,u]=c(null),f=e.processes??[],p=e.addons.map(e=>e.id),h=async()=>{if(!a){o(!0),u(null);try{await t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}).catch(()=>void 0);let n=await t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id});u({tone:n.stillListed?`warn`:`ok`,text:n.message})}catch(e){u({tone:`warn`,text:`Forget failed: ${e instanceof Error?e.message:String(e)}`})}finally{o(!1)}}};return e.isOnline?r(`div`,{className:`border border-border rounded-xl`,children:[r(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[l(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),l(`span`,{className:`text-sm font-semibold`,children:e.name}),r(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),r(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[r(`span`,{className:`flex items-center gap-1`,children:[l(fe,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),r(`span`,{className:`flex items-center gap-1`,children:[l(P,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),l(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`forks`,`processes`,`load`,`settings`,`capabilities`].map(e=>l(`button`,{onClick:()=>i(e),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===e?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e===`info`?`General`:e===`forks`?`Forks (${f.length})`:e===`processes`?`Processes`:e===`load`?`Load`:e===`settings`?`Settings`:`Capabilities`},e))}),r(`div`,{className:`px-4 py-2`,children:[n===`info`&&r(`div`,{className:`space-y-3`,children:[l(sn,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps,rootPackage:e.rootPackage}),l(`div`,{className:`border-t border-border pt-1`,children:l(pn,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`forks`&&l(Ne,{nodeId:e.id,processes:f}),n===`processes`&&l(Le,{nodeId:e.id}),n===`load`&&l($t,{nodeId:e.id,isHub:e.isHub}),n===`settings`&&l(rn,{nodeId:e.id,addonIds:p}),n===`capabilities`&&l(an,{nodeId:e.id,addons:e.addons})]})]}):r(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[r(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[l(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),l(`span`,{className:`text-sm font-semibold`,children:e.name}),r(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>l(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),e.rootPackage&&r(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),l(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),r(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[r(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),r(`button`,{type:`button`,onClick:()=>void h(),disabled:a,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[l(m,{className:`h-3 w-3`}),a?`Forgetting…`:`Forget node`]})]}),s!=null&&l(`p`,{role:`status`,className:`px-4 pb-3 text-xs leading-relaxed ${s.tone===`ok`?`text-emerald-500`:`text-amber-500`}`,children:s.text})]})}function hn({nodes:e,selected:t,onSelect:n}){let{t:i}=M(),a=Ee(e);return t===null?l(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-xs text-foreground-subtle`,children:i(`cluster.noNodes`,`No nodes in this cluster yet.`)}):r(`div`,{className:`flex flex-col gap-3`,children:[a.length>1&&l(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`tablist`,"aria-label":i(`cluster.nodeSelectorLabel`,`Nodes`),children:a.map(e=>l(gn,{node:e,active:e.id===t.id,onSelect:()=>n(e.id)},e.id))}),l(mn,{node:t})]})}function gn({node:e,active:t,onSelect:n}){let{t:i}=M();return r(`button`,{type:`button`,role:`tab`,"aria-selected":t,onClick:n,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground`}`,children:[l(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-destructive`}`}),l(`span`,{className:`font-medium`,children:e.name}),e.isOnline?r(`span`,{className:`inline-flex items-center gap-1 text-[10px] tabular-nums text-muted-foreground`,children:[l(fe,{className:`h-3 w-3`}),e.cpuPercent,`%`,l(P,{className:`h-3 w-3`}),e.memoryPercent,`%`]}):l(`span`,{className:`text-[10px] text-destructive`,children:i(`cluster.offline`,`offline`)})]})}var $=3,_n=7e3;function vn(e){return[...e].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1)}function yn(e){return e.isHub?{}:{nodeId:e.id}}function bn(e){return e.updateState===`staging`||e.updateState===`pending-restart`||e.pendingVersion!==null?!0:!e.updateAvailable}async function xn(e,t){let n=yn(e),r=`no answer`;for(let i=1;i<=$;i+=1)try{let r=await t.readStatus(n);return bn(r)?{nodeId:e.id,nodeName:e.name,outcome:`applied`,detail:`Connection dropped, and the node confirms the update landed (state ${r.updateState}, running ${r.runningVersion??`unknown`}).`}:{nodeId:e.id,nodeName:e.name,outcome:`failed`,detail:`Connection dropped and the node came back unchanged (still ${r.runningVersion??`unknown`}, update still available). Nothing was staged.`}}catch(e){r=e instanceof Error?e.message:String(e),i<$&&await t.wait(_n)}return{nodeId:e.id,nodeName:e.name,outcome:`unconfirmed`,detail:`Connection dropped and the node could not be confirmed after ${$} attempts (${r}). It may be restarting — re-check this node.`}}function Sn(e){return e.accepted?`applied`:e.outcome===`failed`?`failed`:`refused`}async function Cn(e,t){let n=[];for(let r of vn(e))try{let e=await t.apply(yn(r));n.push({nodeId:r.id,nodeName:r.name,outcome:Sn(e),detail:e.message})}catch{n.push(await xn(r,t))}return n}n();function wn(){let{nodes:e,isLoading:t}=ie(),n=a(()=>e??[],[e]);return{nodes:n,isLoading:t&&n.length===0}}var Tn={applied:`border-emerald-500/40 bg-emerald-500/10 text-emerald-500`,refused:`border-amber-500/40 bg-amber-500/10 text-amber-500`,failed:`border-red-500/40 bg-red-500/10 text-red-500`,unconfirmed:`border-amber-500/40 bg-amber-500/10 text-amber-500`};function En(){let{t}=M(),n=he(),{nodes:i,isLoading:o}=wn(),{selection:s,selectNode:u}=Oe(i),f=s.node,p=a(()=>i.filter(e=>e.isOnline),[i]),m=p.length,h=i.filter(e=>!e.isOnline).length,_=w(),v=d(),[y,b]=c(!1),[S,C]=c([]),T=e(async()=>{let e=p.map(e=>({id:e.id,name:e.name,isHub:e.isHub}));if(await n({title:t(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:t(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:t(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){b(!0),C([]);try{C(await Cn(e,{apply:e=>_.mutateAsync(e),readStatus:e=>v.trpcClient.serverManagement.getServerPackageStatus.query(e),wait:e=>new Promise(t=>setTimeout(t,e))}))}finally{b(!1)}}},[_,n,p,v,t]);return r(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[r(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[r(`div`,{className:`flex items-center gap-2`,children:[m>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[m,` online`]}),h>0&&r(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[h,` offline`]})]}),l(`div`,{className:`flex items-center gap-2`,children:m>1&&r(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:y,title:t(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void T(),children:[y?l(g,{className:`h-3.5 w-3.5 animate-spin`}):l(x,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateAll`,`Update all nodes`)]})})]}),S.length>0&&l(`ul`,{"aria-label":`update-all-report`,className:`flex flex-col gap-1 text-xs`,children:S.map(e=>r(`li`,{"data-outcome":e.outcome,className:`rounded border px-2 py-1 ${Tn[e.outcome]}`,children:[l(`span`,{className:`font-medium`,children:e.nodeName}),l(`span`,{className:`mx-1 uppercase tracking-wide`,children:e.outcome}),l(`span`,{className:`opacity-80`,children:e.detail})]},e.nodeId))}),o?l(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):r(`div`,{className:`flex-1 overflow-auto flex flex-col gap-3`,children:[l(De,{staleNodeId:s.staleNodeId,shownNodeName:f?.name??``}),l(hn,{nodes:i,selected:f,onSelect:u})]})]})}export{En as ClusterPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-Cyuzqnbw.js";import{I as t,K as n,Q as r,S as i,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{A as p,B as m,D as h,E as g,M as _,O as v,R as y,T as b,at as x,gt as S,ht as C,k as w,st as T,ut as E,vt as D}from"./player-overlays-tKtUzh3g.js";import{$s as O,$t as k,$u as A,Ad as j,B as ee,C as M,Cc as N,Cn as P,Ct as F,Cu as I,Dn as L,Du as R,E as te,En as ne,Fn as z,Fs as re,Hs as ie,I as B,In as V,Is as ae,Jt as oe,Kd as se,Ks as ce,Ls as le,Ms as ue,Mt as H,Nd as de,Nn as fe,Ns as pe,Nt as me,O as he,Od as ge,P as _e,Pn as ve,Ps as ye,Pt as be,Pu as xe,Qt as Se,Rs as Ce,S as we,Sn as Te,T as Ee,Tn as De,Ud as Oe,Uu as ke,V as Ae,Xs as je,Ys as Me,Zs as Ne,_c as Pe,_t as Fe,ac as Ie,ad as Le,an as Re,bc as ze,bn as Be,cc as Ve,cn as He,dd as Ue,dn as We,dr as Ge,du as Ke,ec as qe,en as Je,fn as Ye,fu as Xe,gc as Ze,gf as Qe,hu as $e,ic as et,in as tt,js as nt,kd as rt,lc as it,ln as at,mr as ot,mu as st,nd as ct,nf as U,nn as lt,oc as ut,pf as dt,pu as ft,qn as pt,qs as mt,r as ht,rc as gt,rn as _t,sa as vt,sc as yt,sn as bt,tc as xt,tn as St,tr as W,ud as Ct,ur as wt,ut as Tt,uu as G,vc as Et,vn as Dt,vu as Ot,w as kt,wn as At,xc as jt,xn as Mt,yc as Nt,yu as Pt,zf as Ft,zs as It}from"./src-Y4G_LfLc.js";import{t as Lt}from"./crop-9g1Z5sFT.js";import{t as Rt}from"./layers-DYdFVal1.js";import{An as zt,Dn as Bt,En as Vt,Lr as Ht,Mn as Ut,On as Wt,Rr as Gt,Tn as Kt,c as qt,jn as Jt,kn as Yt,l as Xt,m as Zt,pi as Qt,si as $t,wn as en}from"./client-HDm3z1QL.js";import{n as tn}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{$ as nn,G as rn,J as an,z as on}from"./index-d2QAhmc-.js";import"./useEventInvalidation-D_5ynS9o.js";import{t as sn}from"./NodeAddonsSettingsPanel-BbRT6OqB.js";var cn=D(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),ln=D(`crown`,[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]),un=D(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),dn=D(`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`}]]),fn=D(`scale`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`m19 8 3 8a5 5 0 0 1-6 0zV7`,key:`zcdpyk`}],[`path`,{d:`M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1`,key:`1yorad`}],[`path`,{d:`m5 8 3 8a5 5 0 0 1-6 0zV7`,key:`eua70x`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}]]),pn=D(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]),mn=`step`,hn=[mn,`acc`];function gn(e,t){return`${e}/${t}`}function _n(e,t,n){let r=n.step!==null&&e.includes(n.step),i=n.acc!==null&&t.includes(n.acc);return{stepId:r?n.step:null,acceleratorId:i?n.acc:null,staleStepId:n.step!==null&&n.step!==``&&!r&&e.length>0?n.step:null}}function vn(e){if(e==null)return null;if(typeof e==`number`)return e>0?e:null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function yn(e){return e}function bn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function xn(e,t){return typeof e==`boolean`?e:yn(t)}function Sn(e,t){return{pipeline:xn(bn(e,`detect`),t),audio:xn(bn(e,`audio`),t),ingest:xn(bn(e,`ingest`),t)}}function Cn(e,t,n){let r=e?.find(e=>e.nodeId===t);return Sn(r?.settings,n)}function wn({selectedNodeId:e,onSelect:t,refreshToken:n}){let{nodes:r}=Ke(),{data:a}=Me(void 0),{data:s}=O(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=r??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return i(`div`,{className:`flex flex-col h-full`,children:[i(`button`,{type:`button`,onClick:()=>t(Eo),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(nn,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Assignments, load balancing, roles`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let r=e===n.id,a=c.get(n.id)??0,l=n.isHub?ct:U,u=Cn(s,n.id,n.isHub),f=n.isOnline?null:Tt(vn(n.lastSeen));return i(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-danger flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),i(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[i(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(R,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`text-danger`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(W,{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(W,{variant:u.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:u.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),i(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[i(`span`,{children:[u,` online`]}),f>0&&i(`span`,{className:`text-danger`,children:[f,` offline`]})]})]})}function Tn({nodeId:e,refreshToken:t}){let{nodes:n}=Ke(),r=n?.find(t=>t.id===e),a=Xe(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?i(`div`,{className:`px-6 py-4 border-b border-border`,children:[i(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-danger/10 text-danger`,children:`offline`}),r.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:r.cpuModel??`CPU`}),d(`span`,{children:`•`}),i(`span`,{children:[r.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),i(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),i(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&i(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:i(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var En=[`assignments`,`tree`,`engines`,`logs`];r();function Dn({refreshToken:e,nodeId:t}){let[n,r]=u(new Map),{nodes:o}=G();st(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:s}=It(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[l,o]);if(t){let e=l.get(t);return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(K,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(K,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(K,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(K,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(K,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(K,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(K,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(K,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(K,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(K,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),i(`tbody`,{children:[m.map(([e,t])=>i(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function K({label:e,value:t}){return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}var On={active:!1,pinned:!1,nodeId:null,reason:``};function kn(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function An(e,t,n){let r=new Map(t.map(e=>[e.deviceId,e])),i=new Map(n.map(e=>[e.deviceId,e]));return e.map(e=>{let t=r.get(e.id),n=i.get(e.id);return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:t?{active:!0,pinned:t.pinned,nodeId:t.agentNodeId,reason:t.reason??``}:On,audio:n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:On}}).toSorted(kn)}function jn(e,t,n){let r=(t,n,r)=>({active:t!==null&&t===e,pinned:n,nodeId:t,reason:r??``});return t.map(({deviceId:e,assignment:t})=>({deviceId:e,deviceName:n(e),detection:r(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:r(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:r(t.audioNodeId,t.pinned.audio,t.reasons.audio)})).filter(e=>e.detection.active||e.decoder.active||e.audio.active).toSorted(kn)}function Mn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>{let n=t.get(e);return n!==void 0&&n!==``?n:e}}function Nn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??`Camera ${e}`}function Pn(e,t,n){return[{value:`auto`,label:`Auto`},...[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])].map(e=>({value:e,label:`Pin → ${n(e)}`}))]}function Fn({snap:e}){if(e===void 0)return d(`div`,{className:`flex h-8 items-center text-[11px] text-foreground-subtle`,title:`No metrics in the last 10 s — the camera has no session running`,children:`no live data`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=F(t);return i(`div`,{className:`flex h-8 min-w-0 flex-col justify-center font-mono text-[10px] leading-tight tabular-nums`,children:[i(`span`,{className:`inline-flex min-w-0 items-center gap-1 ${c.textColor}`,children:[d(_e,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate font-semibold uppercase tracking-wider`,children:c.label}),d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[`/`,o.toFixed(0),` fps`]})]}),i(`span`,{className:`truncate text-foreground-subtle`,children:[d(`span`,{className:`text-foreground`,children:r.toFixed(0)}),` ms`,a>0&&i(`span`,{className:`ml-1 text-warning`,children:[`q`,a]}),i(`span`,{className:s>0?`ml-1 text-warning`:`ml-1`,children:[`drops `,s]})]})]})}r();var In=1e4,Ln=5e3;function Rn(e){let[t,n]=u(new Map);return st(`pipeline.camera-metrics-snapshot`,t=>{let r=t.data;typeof r.deviceId==`number`&&(e!==void 0&&r.nodeId!==e||n(e=>new Map(e).set(r.deviceId,r)))}),f(()=>{if(t.size===0)return;let e=setInterval(()=>{n(e=>{let t=Date.now()-In,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},Ln);return()=>clearInterval(e)},[t.size]),t}var zn=3e5;function Bn({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:i}){return d(z,{"aria-label":`Node pin`,title:`Auto lets each session pick its node; a pin keeps the camera on one node.`,value:e.pinned&&e.nodeId!==null?e.nodeId:`auto`,disabled:r,options:[...Pn(e,t,n)],onChange:e=>i(e.target.value)})}function Vn({deviceId:e,nodeId:t}){let n=c(),{data:r}=je({deviceId:e},{refetchOnMount:`always`}),{data:i}=mt({nodeId:t},{staleTime:zn}),a=Pe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`accelerator: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),l=r?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l),f=o.find(e=>e.key===l),p=[{value:`auto`,label:`Any accelerator`},...u?[{value:l,label:`${f?`${We(f)} (${l})`:l} (not enabled)`}]:[],...s.map(e=>({value:e.key,label:`${We(e)} · ${e.format}`}))];return d(z,{"aria-label":`Inference device pin`,title:`Pin detection to one accelerator of the node, or let each session pick.`,value:l,disabled:a.isPending,options:p,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value})})}r();function Hn(e){let t=n(null);return e.nodeId!==null&&(t.current=e),t.current}function Un({deviceId:e,state:t,...n}){let r=Hn(t);return i(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[d(Bn,{state:t,...n}),r?.nodeId==null?d(z,{"aria-label":`Inference device pin (no node yet)`,title:`An accelerator is pinned on the camera's node; this camera has not run on one yet.`,disabled:!0,defaultValue:`auto`,options:[{value:`auto`,label:`Any accelerator`}]}):d(Vn,{deviceId:e,nodeId:r.nodeId})]})}function Wn({state:e,nameOf:t}){let n=Hn(e);if(n?.nodeId==null)return d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`— no session yet`});let r=e.active&&e.nodeId!==null,a=n.pinned?`pinned`:`auto · ${n.reason||`capacity`}`;return i(`div`,{className:`flex w-40 min-w-0 flex-col leading-tight`,title:n.pinned?void 0:`An unpinned camera is placed again at every session start, so this can change between sessions.`,children:[i(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[d(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${r?`bg-success`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate font-medium ${r?`text-foreground`:`text-foreground-muted`}`,children:t(n.nodeId)})]}),d(`span`,{className:`truncate pl-3 text-[10px] ${n.pinned?`text-warning`:`text-foreground-subtle`}`,children:r?a:`${a} · idle, last session`})]})}function Gn({deviceId:e,deviceName:t}){let[n,r]=u(!1);return i(o,{children:[d(Je,{icon:Ue,variant:`ghost`,size:`sm`,"aria-label":`Stream brokers of ${t}`,title:`Stream brokers & clients`,onClick:()=>r(!0)}),d(Mt,{open:n,onOpenChange:r,children:i(P,{width:`lg`,scroll:`body`,children:[d(ne,{children:i(L,{children:[t,` — stream brokers & clients`]})}),d(Te,{children:n&&d(Dt,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e,instanceId:`pipeline-row/${e}`,config:{variant:`compact`,title:`Stream brokers & clients`}})})]})})]})}r();var Kn=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function qn(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function Jn(){let e=c();ht([`pipelineOrchestrator`,`getPipelineAssignments`],Kn),ht([`pipelineOrchestrator`,`getAudioAssignments`],Kn);let{data:t}=vt({isCamera:!0,projection:`slim`}),{data:n}=Me(void 0),{data:r}=Ce(void 0),{nodes:o}=G(),s=Rn(),l=a(()=>Mn(o),[o]),u=a(()=>o.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),f=a(()=>An((t??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),n??[],r??[]),[t,n,r]),p=()=>qn(e),m=ae({onSuccess:p}),h=jt({onSuccess:p}),g=m.isPending||h.isPending;return d(me,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[d(`span`,{className:`min-w-0 truncate text-xs font-medium text-foreground`,title:e.deviceName,children:e.deviceName}),e.disabled&&d(W,{variant:`default`,children:`off`})]})},{key:`placement`,header:`Placement`,width:`w-80`,notSortableReason:`A pair of controls — editing one would move the row under the cursor.`,render:e=>d(Un,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:u,nameOf:l,pending:g,onChange:t=>t===`auto`?h.mutate({deviceId:e.deviceId}):m.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`resolved`,header:`Running on`,width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:l(e.pipeline.nodeId),render:e=>d(Wn,{state:e.pipeline,nameOf:l})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(Fn,{snap:s.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>d(Gn,{deviceId:e.deviceId,deviceName:e.deviceName})}],rows:f,rowKey:e=>e.deviceId,minWidthPx:760,mobileMode:`scroll`,maxBodyHeight:be,emptyMessage:t===void 0?`Loading cameras…`:`No cameras`})}r();function Yn({label:e,state:t,nameOf:n}){return t.active?i(W,{variant:`info`,className:`gap-1`,title:t.pinned?`Pinned here`:void 0,children:[t.pinned&&d(dn,{className:`h-2.5 w-2.5`,"aria-label":`pinned`}),e]}):t.nodeId===null?null:i(`span`,{className:`text-[10px] text-foreground-subtle`,children:[e,` on `,n(t.nodeId)]})}function Xn({nodeId:e}){let t=c();ht([`pipelineOrchestrator`,`getCameraStatuses`],Kn);let{data:n}=ie({}),{data:r}=vt({isCamera:!0,projection:`slim`}),{nodes:o}=G(),s=Rn(),l=a(()=>Mn(o),[o]),u=a(()=>jn(e,n??[],Nn((r??[]).map(e=>({id:e.id,name:e.name})))),[e,n,r]),f=o.filter(t=>t.isOnline&&t.id!==e),p=()=>qn(t),m=ae({onSuccess:p}),h=jt({onSuccess:p}),g=re({onSuccess:p}),_=ze({onSuccess:p}),v=e=>[...e.detection.active?f.map(t=>({id:`detect-${t.id}`,label:`Move detection to ${t.name}`,onClick:()=>m.mutate({deviceId:e.deviceId,agentNodeId:t.id})})):[],...e.audio.active?f.map(t=>({id:`audio-${t.id}`,label:`Move audio to ${t.name}`,onClick:()=>g.mutate({deviceId:e.deviceId,nodeId:t.id})})):[],{id:`unpin-detect`,label:`Unpin detection`,hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>h.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:`Unpin audio`,hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>_.mutate({deviceId:e.deviceId})}];return d(me,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>d(`span`,{className:`block w-44 truncate text-xs font-medium text-foreground`,title:e.deviceName,children:e.deviceName})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:e=>i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(Yn,{label:`Detection`,state:e.detection,nameOf:l}),d(Yn,{label:`Decode`,state:e.decoder,nameOf:l}),d(Yn,{label:`Audio`,state:e.audio,nameOf:l})]})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(Fn,{snap:s.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>d(B,{items:v(e),title:`Move ${e.deviceName}`})}],rows:u,rowKey:e=>e.deviceId,minWidthPx:560,mobileMode:`scroll`,maxBodyHeight:be,emptyMessage:n===void 0?`Loading cameras…`:`No camera runs on this node right now`})}function Zn({nodeId:e,refreshToken:t}){let{nodes:n}=G(),r=n.find(t=>t.id===e)?.name??e;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(Dn,{refreshToken:t,nodeId:e}),i(`div`,{className:`space-y-2`,children:[i(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:[`Cameras on `,r]}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The roles each camera runs here right now. Move a role or unpin it from the row menu; pins for every camera are on Cluster → Assignments.`})]}),d(Xn,{nodeId:e})]})]})}r();function Qn(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function $n({nodeId:e,refreshToken:t}){let n=c(),r=pt(),o=ue({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:s}=pe({nodeId:e}),l=Xe(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??s??null,u=l===null;ht([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=N({nodeId:e}),{values:p}=ft(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=a(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),h=t=>{let n=f??[];if(n.length===0){o.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await r({title:`Kill engine`,message:`${String(n.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:`Kill engine`,variant:`danger`})&&o.mutate({nodeId:e,engine:t,force:!0})})()};return i(`div`,{className:`space-y-6`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(l??[]).length,` engine(s) resident in RAM. `,(f??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),i(`tbody`,{children:[u&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!u&&(l??[]).map(e=>{let t=e.kind===`device-pool`;return i(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[d(t?Rt:U,{className:`h-3 w-3`}),t?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(Ot,{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:Qn(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(f??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:t?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):i(V,{variant:`ghost`,size:`sm`,disabled:o.isPending,onClick:()=>h(e.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[d(T,{className:`h-3.5 w-3.5`}),`Kill`]})})]},e.engineKey)}),!u&&(l??[]).length===0&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),o.isError&&d(fe,{message:`Kill failed: ${o.error instanceof Error?o.error.message:`unknown error`}`})]})}var er=`pipeline-runner`,tr=200;function nr({nodeId:e}){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(Fe,{agentId:e,addonId:er,limit:tr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}r();function rr({nodeId:e,title:t}){let{data:n}=on(),{data:r}=Me(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),c=Rn(e),l=a(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return l.length===0?i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[i(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=F(e.metrics.phase);return i(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[d(_e,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}function ir(e,t,n){return e.map(e=>{if(e.key===t)return e;let r=e.steps[n];if(!r||r.settings===void 0)return e;let{settings:i,...a}=r,o={...e.steps};return Object.keys(a).length>0?o[n]=a:delete o[n],{...e,steps:o}})}function ar(e,t,n){let r=e.filter(e=>e.key!==t).toSorted((e,t)=>e.key.localeCompare(t.key)),i=[...r.filter(e=>!e.enabled),...r.filter(e=>e.enabled),...e.filter(e=>e.key===t)],a;for(let e of i){let t=e.steps?.[n]?.settings;!t||Object.keys(t).length===0||(a={...a,...t})}return a}function or(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}var sr=`pipeline-orchestrator`;function cr({addonId:e,highlightLabel:t}){let n=Wt(e),{data:r}=Ge({addonId:sr});if(n.length===0)return null;let a=Jt(r??null)[e]??{};return i(`section`,{className:`space-y-1.5 border-t border-border/60 pt-3`,"aria-label":`Cluster-wide settings`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:m,children:`Cluster-wide settings`}),d(rn,{to:Mo(e),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Edit in Cluster → Settings ›`})]}),n.map(e=>i(`div`,{className:`${w} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[d(`span`,{className:p,children:e.label}),d(`span`,{className:_,children:d(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),d(`p`,{className:y,children:`One value for every node and camera — this step writes into a shared index.`})]})}function lr({rows:e}){return i(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>i(`li`,{className:`${b} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-foreground-muted`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:e.modelId??`—`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.sourceLabel})]},e.id))}),d(`p`,{className:y,children:`To change a model, open that accelerator's cell in the table.`})]})}r();function ur(e,n){let[r,i]=an(),o=r.get(mn),s=r.get(`acc`),c=a(()=>_n(e,n,{step:o,acc:s}),[e,n,o,s]),l=t(e=>{i(t=>{let n=new URLSearchParams(t);return e(n),n},{replace:!0})},[i]);return{selection:c,open:t(e=>l(t=>{t.set(mn,e.stepId),e.acceleratorId===void 0?t.delete(`acc`):t.set(`acc`,e.acceleratorId)}),[l]),close:t(()=>l(e=>{e.delete(mn),e.delete(`acc`)}),[l])}}function dr(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function fr(e){return e.split(`.`)[0]??e}function pr(e,t,n){return{id:gn(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${fr(t)} · ${We(n)}`,shortLabel:`${fr(t)} · ${Ye(n)}`,nodeLabel:fr(t),disabled:!n.enabled}}function mr(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>pr(e,t,n))}function hr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>pr(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>pr(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[pr(e.id,e.name,a)]})}function gr(e,t,n){return{modelId:bt({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function _r(e,t,n){let r=dr(e,`object-detection`);if(r===null)return;let i=bt({catalog:r,device:t.device,base:t.device.steps?.[`object-detection`]?.modelId,override:n});if(i===void 0)return;let a=r.models.find(e=>e.id===i);return{modelId:i,name:a?.name??i,supplies:a?.suppliesSteps??[]}}function vr(e,t,n){return!Ht(e)||n===void 0?!1:Gt(e,t,n.supplies).effective}function yr(e,t){return e!==null&&He(e.models,t.device.format)}function br(e){return yr(e.addon,e.acc)?e.clusterModelId===void 0?{kind:`enabled`,modelId:e.model.modelId??`Auto`,overridden:e.model.source===`camera`,...e.rootName===void 0?{}:{suppliedByRoot:e.rootName},...e.jumpTo===void 0?{}:{jumpTo:e.jumpTo}}:{kind:`enabled`,modelId:e.clusterModelId,clusterWide:!0}:e.gatedOn?e.jumpTo===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:e.jumpTo}:{kind:`na`}}function xr(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function Sr(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=Wt(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function Cr(e){return e.flatMap(e=>[{node:e,depth:0},...Cr(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function wr(e,t){return e.flatMap(e=>{let n=wr(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}r();function Tr(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:We(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Er({tree:e,searchRows:r,accelerators:o,cellState:s,stepBadge:c,disabledCount:l,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:b}){let x=pt(),S=oe(),{selection:C,open:w,close:T}=ur(a(()=>Cr(e).map(e=>e.node.addonId),[e]),a(()=>o.map(e=>e.id),[o])),[E,D]=u(``),[O,A]=u(null),[j,N]=u(null),P=n(null),F=n(null),I=n(null),L=n(null),R=a(()=>M(r,E),[r,E]),ne=a(()=>E.trim()===``?e:wr(e,new Set(R.map(e=>e.addonId))),[e,R,E]),z=e=>R.find(t=>t.addonId===e)?.matchedField??null,re=a(()=>o.map(Tr),[o]),ie=e=>o.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),B=o.find(e=>e.id===C.acceleratorId)??null,V=C.stepId!==null,ae=t(async e=>{if(m){if(!await x({title:`Discard unsaved changes?`,message:`This step has changes that are not saved yet.`,confirmLabel:`Discard`,variant:`danger`}))return;h()}e()},[x,m,h]),se=()=>{requestAnimationFrame(()=>L.current?.focus())},ce=(e,t,n=!1)=>{if(e===C.stepId&&(t?.id??null)===C.acceleratorId){n&&se();return}let r=()=>{A(z(e)),w({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&se()};e===C.stepId?r():ae(r)},le=()=>{let e=C.stepId;ae(()=>{if(T(),e!==null){let t=B===null?null:Ae({agentNodeId:B.nodeId,deviceKey:B.deviceKey});requestAnimationFrame(()=>P.current?.focusCell(e,t))}})},ue=e=>{if(e.key===`Enter`){let t=R[0];if(t===void 0)return;e.preventDefault(),ce(t.addonId,void 0,!0)}else e.key===`Escape`&&D(``)},H=S?d(te,{onClick:le}):d(Je,{icon:Pt,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:le});return i(`div`,{ref:F,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),I.current?.focus()),e.key===`Escape`&&t&&V&&(e.preventDefault(),le())},children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),d(`input`,{ref:I,type:`search`,value:E,onChange:e=>D(e.target.value),onKeyDown:ue,placeholder:`Filter steps or settings /`,"aria-label":`Filter steps or settings`,className:`h-9 w-56 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30 md:h-7`}),l>0&&i(`label`,{className:`inline-flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(k,{checked:f,onChange:e=>p(e.target.checked)}),`Show disabled accelerators (`,l,`)`]}),_]}),C.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:[`The link names a step this pipeline does not have (`,C.staleStepId,`).`]}),ne.length===0?i(`p`,{className:`${y} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:[`No step matches “`,E,`”.`]}):d(ee,{ref:P,tree:ne,agents:re,label:v,getCellState:(e,t)=>{let n=ie(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>ce(e,ie(t),n),onStepClick:(e,t)=>ce(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:V&&C.stepId!==null&&B!==null?{addonId:C.stepId,agentNodeId:B.nodeId,deviceKey:B.deviceKey}:null,fallbackNodeId:j,onFallbackNodeChange:N,reserveRightPx:V&&!S?432:0}),d(he,{open:V,anchor:F,onClose:le,label:`Step settings`,children:C.stepId!==null&&b({stepId:C.stepId,accelerator:B,matchedField:O,closeButton:H,onEscape:le,headingRef:e=>{L.current=e}})})]})}r();function Dr(e){f(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}r();function Or(e,t){let n=e.filter(e=>e.steps?.[t]?.settings!==void 0),r=e=>e.toSorted((e,t)=>e.key.localeCompare(t.key));return r(n.filter(e=>e.enabled))[0]?.key??r(n)[0]?.key??r(e.filter(e=>e.enabled))[0]?.key??e[0]?.key}function kr(e,t){let n=t.settings===void 0?void 0:Or(e,t.stepId),r=e.map(e=>{let r={...e.steps},i=r[t.stepId]??{},a=t.models[e.key],o=t.jumps[e.key],s=e.key===n&&t.settings!==void 0?Object.keys(t.settings).length>0?t.settings:void 0:i.settings,c=a===void 0?i.modelId:a??void 0,l=o===void 0?i.jumpDeviceKey:o||void 0,u={...c===void 0?{}:{modelId:c},...s===void 0?{}:{settings:s},...l===void 0?{}:{jumpDeviceKey:l}};return Object.keys(u).length>0?r[t.stepId]=u:delete r[t.stepId],{key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:r}});return n===void 0?r:ir(r,n,t.stepId)}function Ar(e,t,n){if(t===null)return 0;let r=Object.entries(t.models).filter(([n,r])=>(r??void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.modelId).length,i=Object.entries(t.jumps).filter(([n,r])=>(r||void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.jumpDeviceKey).length,a=new Set([...Object.keys(n),...Object.keys(t.settings??{})]),o=t.settings===void 0?0:[...a].filter(e=>!Zt(n[e],t.settings?.[e])).length;return r+i+o}function jr({nodeId:e,nodeName:t,toolbar:n}){let r=c(),s=mt({nodeId:e},{refetchOnMount:`always`}),l=nt({nodeId:e},{refetchOnMount:`always`}),f=zt(Ge({addonId:`pipeline-orchestrator`}).data??null),p=s.data?.devices??[],h=l.data??null,[g,_]=u(null),[v,b]=u(null),[x,S]=u(null),C=yt({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),w=a(()=>h?we(h):[],[h]),T=a(()=>Cr(w),[w]),[E,D]=u(!1),O=a(()=>mr(e,t,p,E),[e,t,p,E]),k=a(()=>mr(e,t,p),[e,t,p]),A=k.length>=2,j=(e,t)=>(t===void 0?void 0:ar(p,t.deviceKey,e))??{},ee=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return k.find(e=>e.deviceKey===r);if(!yr(e,t))return k.filter(n=>n.id!==t.id&&yr(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},M=(e,t)=>{let n=dr(h,e),r=Fo(e),i=_r(h,t),a=j(e,t),o=ee(n,t);return br({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?gr(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...vr(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:f[e]??r.defaultModelId}:{},...o?{jumpTo:Ye(o.device)}:{}})},N=T.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Sr(dr(h,e.addonId))}));if(s.isLoading||l.isLoading)return d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`});if(h===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`});let P=i(`span`,{className:y,children:[`Accelerators:`,` `,d(`span`,{className:`text-foreground`,children:k.length>0?k.map(e=>Ye(e.device)).join(` · `):`none enabled`}),p.some(e=>!e.enabled)&&i(o,{children:[` `,`— off:`,` `,p.filter(e=>!e.enabled).map(Ye).join(`, `)]}),` `,`·`,` `,d(rn,{to:No(),className:`text-primary hover:underline`,children:`Cluster → Load balancing ›`})]});return d(Er,{tree:w,searchRows:N,accelerators:O,cellState:M,disabledCount:p.filter(e=>!e.enabled).length,showDisabled:E,onShowDisabledChange:D,dirty:g!==null&&Ar(p,g,j(g.stepId,O[0]))>0,onDiscard:()=>_(null),summary:P,...n===void 0?{}:{toolbar:n},label:`Detection steps`,renderDetail:({stepId:n,accelerator:r,matchedField:a,closeButton:s,onEscape:c,headingRef:l})=>{let u=dr(h,n);if(u===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let f=g?.stepId===n?g:null,w=r??k[0]??O[0],T=j(n,w),E=f?.settings??T,D=Ar(p,f,T),M=e=>{S(null),_(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},N=Fo(n),P=_t(u),F=w===void 0?void 0:_r(h,w),I=e=>{let t=f?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},L=w===void 0?void 0:gr(u,w,{nodePin:I(w)}).modelId,R=O.length>1&&O.some(e=>!Zt(j(n,e),T)),te=e=>{let t=I(e),r=gr(u,e,{nodePin:t}),a=_r(h,e),s=vr(n,f?.settings??j(n,e),a),c=f?.jumps[e.deviceKey],l=ee(u,e,c),p=yr(u,e)?s&&a?d(St,{rootModel:a,stepModelId:r.modelId}):void 0:i(o,{children:[`No `,e.device.format,` build of this step.`,` `,l?`It runs on ${l.shortLabel} instead.`:`It does not run here.`]}),m=A?i(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Run on`}),d(z,{"aria-label":`Run on`,value:c??e.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:`Auto (this accelerator, or the next one that can run it)`},...k.filter(t=>t.id!==e.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:t=>M({jumps:{...f?.jumps,[e.deviceKey]:t.target.value}})}),d(`span`,{className:y,children:`Routes this step (and its child steps) to another accelerator of this node.`})]}):void 0;return{label:e.label,format:e.device.format,modelId:r.modelId,source:r.source===`node`?`node`:`default`,sourceLabel:r.source===`node`?`node pin`:`hardware default`,models:at(u.models??[],e.device.format),defaultModelId:u.defaultModelIdByFormat?.[e.device.format]??u.defaultModelId,expanded:v===e.id,onToggle:()=>b(t=>t===e.id?null:e.id),onChangeModel:t=>M({models:{...f?.models,[e.deviceKey]:t}}),...t===void 0?{}:{onReset:()=>M({models:{...f?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...p===void 0?{}:{note:p},...m===void 0?{}:{extra:m},changed:f?.models[e.deviceKey]!==void 0||c!==void 0}},ne=()=>{f!==null&&C.mutate({agentNodeId:e,inferenceDevices:or(kr(p,f))},{onSuccess:()=>{_(null),S({kind:`saved`})},onError:e=>S({kind:`error`,error:e.message})})};return d(Ee,{ref:l,title:r===null?`${u.name} · ${t}`:`${u.name} · ${r.label}`,subtitle:r===null?`${u.slot} · every accelerator of ${t}`:`${u.slot} · ${r.device.format} · base for every camera that lands here`,leading:s,onEscape:c,saveBar:{dirtyCount:D,saving:C.isPending,status:x?.kind??null,...x?.error===void 0?{}:{error:x.error},onSave:ne,onDiscard:()=>_(null)},children:i(`div`,{className:`space-y-3`,children:[i(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[d(`h3`,{className:m,children:`Model`}),N!==null&&w!==void 0?d(Io,{step:N,engineFormat:w.device.format,runnableModelIds:at(u.models??[],w.device.format).map(e=>e.id)}):O.length===0?i(`p`,{className:y,children:[`No accelerator is enabled on this node —`,` `,d(rn,{to:No(),className:`text-primary hover:underline`,children:`enable one in Cluster → Load balancing`}),`.`]}):r===null?d(lr,{rows:O.map(e=>{let t=gr(u,e,{nodePin:I(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):d(kt,{...te(r)},r.id)]}),(P.length>0||F!==void 0)&&N===null&&i(`section`,{"aria-label":`Settings`,className:`space-y-2 border-t border-border/60 pt-2`,children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`settings-scope`,children:[`Node-wide: these settings apply on every accelerator of `,t,`.`]}),R&&d(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2 py-1 text-[11px] text-warning`,children:`This step's settings differ between this node's accelerators. Saving makes the values shown here node-wide.`}),d(Mr,{addon:u,fields:P,settings:E,modelId:lt(u,L,E,F),root:F,highlight:a,onChange:e=>M({settings:e})})]}),d(cr,{addonId:n,highlightLabel:a})]})})}})}function Mr({addon:e,fields:t,settings:n,modelId:r,root:i,highlight:a,onChange:o}){let s=t.find(e=>`label`in e&&e.label===a)?.key??null;return Dr(s===null?null:Re(s)),d(tt,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:`Node`},modelId:r,...i===void 0?{}:{rootModel:i},highlightKey:s,onChangeLayer:o})}r();function Nr({nodeId:e,refreshToken:t}){let n=pt(),[r,a]=u(null),{nodes:s}=G(),c=s.find(t=>t.id===e)?.name??e,l=gt({onSuccess:e=>{a(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${c} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(a(null),l.mutate({agentNodeId:e}))};return i(`div`,{className:`space-y-2`,children:[d(rr,{nodeId:e}),d(jr,{nodeId:e,nodeName:c,toolbar:i(o,{children:[r&&d(`span`,{className:`text-[11px] text-success`,children:r}),l.isError&&d(`span`,{className:`text-[11px] text-danger`,children:l.error instanceof Error?l.error.message:`Reset failed`}),d(V,{variant:`outline`,size:`sm`,onClick:()=>{f()},disabled:l.isPending,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:l.isPending?`Resetting…`:`Reset to default`})]})})]})}var Pr=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],Fr=`decoder-nodeav`,Ir=`ntab`,Lr={decoder:`engine`},Rr={engine:`Engine & decoder`},zr=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function Br({nodeId:e,refreshToken:t}){let[n,r]=an(),{nodes:a}=G(),o=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??Fr,s=[...Pr,o],c=n.get(Ir),l={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:d(Zn,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:d(Nr,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:d($n,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:d(nr,{nodeId:e})}},u=En.map(e=>l[e]);return i(`div`,{className:`flex flex-col h-full`,children:[d(Tn,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:d(sn,{nodeId:e,addonIds:s,level:`global`,fieldScope:`perNode`,emptyMessage:zr,tabAliases:Lr,tabLabelOverrides:Rr,extraTabs:u,activeTab:c===null?null:Lr[c]??c,onActiveTabChange:e=>r(t=>{let n=new URLSearchParams(t);n.set(Ir,e);for(let e of hn)n.delete(e);return n},{replace:!0})})})]})}function Vr(){return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Camera placement`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pin a camera to a node, or to one accelerator of its node; Auto lets each session pick. Decode always runs with detection. Load, shares and caps are on Load balancing.`})]}),d(Jn,{})]})}function Hr(e){return`${Math.round(e*100)}%`}function Ur(e){return`${e} session${e===1?``:`s`}`}var Wr={"intel-npu":`Intel NPU`,"intel-igpu":`Intel iGPU`,"x86-cpu":`CPU`,"arm-cpu":`CPU`,"apple-ane":`Apple Neural Engine`,coral:`Coral Edge TPU`},Gr={"intel-core-ultra":`Intel Core Ultra`,"intel-n-series":`Intel N-series`,"apple-m-base":`Apple M (base)`,"apple-m-pro":`Apple M Pro / Max / Ultra`,unknown:`Not measured`};function Kr(e){return e===null?`—`:Wr[e]??e}function qr(e){return e===null?`—`:Gr[e]??e}function Jr(e){switch(e.kind){case`capacity`:return`Capacity ${Ur(e.sessions)} ≥ min ${e.minSessions}.`;case`tie-faster`:return`As accurate as ${e.over} (within ${Hr(e.recallDelta)} recall) and faster.`;case`stepped-down`:return`${e.from} would not fit the load on ${e.limitedBy}; ${e.to} is the most accurate that does.`;case`no-fit-lightest`:return`No model reaches ${Ur(e.minSessions)} per device; the one with the most capacity (${Ur(e.sessions)}) is used.`;case`derived-latency`:return`${e.modelId}: latency estimated from a similar chip, not measured on this one.`;case`cpu-device`:return`CPU fallback device: picked on its own.`;case`coral-untouched`:return`Coral: left as is (no YOLOv9 build exists for it).`;case`device-disabled`:return`Disabled: not changed.`;case`device-unavailable`:return`Not available on the node right now: not changed.`;case`node-offline`:return`Node offline: nothing on it will change.`;case`no-hardware-facts`:return`Hardware could not be read: nothing on this node will change.`;case`no-measured-data`:return`This hardware has no measured data: nothing on this node will change.`;case`no-family-build`:return`No YOLOv9 build for the ${e.format} format: not changed.`;case`kept-custom-pin`:return`Custom model ${e.modelId} is pinned on ${e.deviceKey}: Auto tune skips this device.`}}function Yr(e,t){switch(e.kind){case`detector-store-cluster-wide`:return`Per-camera detector thresholds are not tied to a node, so they are cleared for every camera — including cameras that run on skipped nodes (${e.skippedNodes.map(t).join(`, `)}).`;case`detector-store-unreadable`:return`Per-camera detector thresholds could not be read (${e.error}); those will not be cleared.`;case`coral-enabled`:return`${t(e.nodeId)}: the Coral (${e.deviceKey}) is enabled and keeps running its SSD model, which finds far fewer people than YOLOv9. Consider disabling it.`;case`custom-pin-kept`:return e.deviceId===null?`${t(e.nodeId)}: custom model ${e.modelId} pinned on ${e.deviceKey??`—`} — Auto tune skips this node device.`:`Camera ${e.deviceId} pins custom model ${e.modelId} on ${t(e.nodeId)} — Auto tune keeps that override and its thresholds.`;case`custom-registry-unreadable`:return`The custom-model registry could not be read (${e.error}): every pin to a model outside the measured catalog is kept.`}}function Xr(e){let t=e.nodeChanges.reduce((e,t)=>e+t.modelPins.length,0),n=e.nodeChanges.reduce((e,t)=>e+t.thresholds.length,0),r=new Set([...e.cameraClears.map(e=>e.deviceId),...e.detectorStoreClears.map(e=>e.deviceId)]);return{modelChanges:t,thresholdClears:n,cameraOverrideClears:e.cameraClears.length,detectorStoreClears:e.detectorStoreClears.length,camerasTouched:r.size}}function Zr(e){let t=Xr(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function Qr(e,t,n){let r=e.nodeChanges.find(e=>e.nodeId===t&&e.deviceKey===n)?.modelPins.find(e=>e.stepId===`object-detection`);return r===void 0?null:{before:r.before,after:r.after}}function $r(e,t){return e?.kind===`node-benchmark`?`measured on this node, ${new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}`:`from the latency table — benchmark this node to measure it`}r();var ei=[.3,.4,.5];function ti(e){return ei.some(t=>t===e)}var ni=[1,2,3,4,6,8];function ri({plan:e,node:t,nodeName:n}){return i(`section`,{className:h,"data-testid":`auto-tune-node-${t.nodeId}`,children:[i(`header`,{className:`${v} flex flex-wrap items-center gap-2`,children:[d(U,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${m} min-w-0 flex-1`,children:n(t.nodeId)}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[qr(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?d(W,{variant:`warning`,children:`Not changed`}):t.acceleratorModelId!==null&&d(W,{variant:`info`,children:t.acceleratorModelId})]}),t.reasons.length>0&&d(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:t.reasons.map((e,t)=>d(`li`,{children:Jr(e)},t))}),d(`div`,{className:`overflow-x-auto`,children:i(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:i(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Device`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Capacity`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Detector`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Why`})]})}),d(`tbody`,{children:t.devices.map(n=>{let r=Qr(e,t.nodeId,n.deviceKey);return i(`tr`,{className:`border-t border-border align-top`,children:[i(`td`,{className:`px-3 py-1.5`,children:[d(`div`,{className:`font-mono text-foreground`,children:n.deviceKey}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:Kr(n.accelerator)})]}),i(`td`,{className:`px-3 py-1.5 text-foreground-muted`,children:[n.chosen===null?`—`:`${n.chosen.capacitySessions} session${n.chosen.capacitySessions===1?``:`s`} at ${e.cameraFps} fps`,n.chosen!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n.chosen.fps,` fps, `,Math.round(e.headroom*100),`% kept free`,d(`div`,{children:$r(n.chosen.source)})]})]}),d(`td`,{className:`px-3 py-1.5`,children:n.chosen===null?d(`span`,{className:`text-foreground-subtle`,children:`unchanged`}):r!==null&&r.before!==r.after?i(`span`,{children:[d(`span`,{className:`text-foreground-subtle`,children:r.before??`default`}),` → `,d(`span`,{className:`font-medium text-foreground`,children:r.after})]}):d(`span`,{className:`text-foreground`,children:n.chosen.modelId})}),d(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>d(`div`,{children:Jr(e)},t))})]},n.deviceKey)})})]})})]})}function ii({plan:e,nameOf:t,nodeName:n}){return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[i(`div`,{children:[d(`div`,{className:m,children:`Node settings`}),e.nodeChanges.length===0?d(`div`,{className:`text-foreground-subtle`,children:`No change.`}):d(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.nodeChanges.flatMap(e=>[...e.modelPins.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: `,t.before??`default`,` → `,t.after??`step default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/pin`)),...e.thresholds.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: reset `,t.keys.join(`, `),` to the model default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),i(`div`,{children:[d(`div`,{className:m,children:`Camera overrides cleared`}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?d(`div`,{className:`text-foreground-subtle`,children:`None.`}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,r)=>i(`li`,{children:[t(e.deviceId),` — `,n(e.nodeId),e.deviceKey===null?` (whole pipeline)`:` · ${e.deviceKey}`,` — `,e.stepId,e.modelIdBefore===null?``:`: model ${e.modelIdBefore} removed`,e.keys.length>0?`; ${e.keys.join(`, `)} reset`:``]},`c${r}`)),e.detectorStoreClears.map(e=>i(`li`,{children:[t(e.deviceId),` — detector thresholds: `,e.keys.join(`, `),` reset`]},`d${e.deviceId}`))]})]})]})}function ai({result:e}){return e.kind===`refused`?d(`div`,{className:`text-xs text-warning`,children:`Another apply is already running.`}):e.kind===`stale`?d(`div`,{className:`text-xs text-warning`,children:`The configuration changed since the plan was shown. Review the updated plan below and apply again.`}):i(`ul`,{className:`text-xs`,"data-testid":`auto-tune-result`,children:[e.kind===`aborted`&&d(`li`,{className:`text-danger`,children:`A model could not be downloaded: nothing was changed.`}),e.phases.map(e=>i(`li`,{className:e.ok?`text-foreground-muted`:`text-danger`,children:[e.ok?`✓`:`✗`,` `,e.phase,`: `,e.detail]},e.phase))]})}function oi(){let e=c(),[t,n]=u(.4),[r,o]=u(2),[s,l]=u(!1),[f,p]=u(!1),[g,_]=u(null),{data:y}=on(),b=a(()=>new Map((y??[]).map(e=>[e.id,e.name])),[y]),x=e=>b.get(e)??`Camera ${e}`,{nodes:S}=G(),C=a(()=>Mn(S),[S]),w=qe({headroom:t,minSessionsPerDevice:r},{enabled:s,refetchOnWindowFocus:!1}),T=ye({onSuccess:t=>{_(t),p(!1),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.kind===`applied`&&w.refetch()}}),E=g?.kind===`stale`?g.plan:w.data,D=E===void 0?null:Xr(E);return i(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[i(`section`,{className:h,children:[i(`header`,{className:`${v} flex flex-wrap items-center gap-2`,children:[d(ke,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${m} min-w-0 flex-1`,children:`Auto tune`})]}),i(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[d(`p`,{children:`Picks, for every accelerator, the most accurate YOLOv9 detector that still carries at least the chosen number of cameras at once, from the node's hardware and measured speeds. Nothing is measured or estimated about your cameras' activity. Applying it sets those models and clears every model and threshold override — node level and per camera — so each model runs its own default thresholds. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`Keep free`}),d(z,{"aria-label":`Share of each accelerator kept free`,value:String(t),options:ei.map(e=>({value:String(e),label:`${Math.round(e*100)}% of each accelerator`})),onChange:e=>{let t=Number(e.target.value);ti(t)&&n(t)}})]}),i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`At least`}),d(z,{"aria-label":`Minimum parallel sessions per device`,value:String(r),options:ni.map(e=>({value:String(e),label:`${e} camera${e===1?``:`s`} at once per accelerator`})),onChange:e=>{let t=Number(e.target.value);ni.some(e=>e===t)&&o(t)}})]}),d(V,{size:`sm`,variant:`secondary`,onClick:()=>{_(null),l(!0),s&&w.refetch()},children:w.isFetching?`Computing…`:E===void 0?`Compute plan`:`Recompute`}),E!==void 0&&d(V,{size:`sm`,disabled:Zr(E),onClick:()=>p(!0),children:`Apply…`})]}),w.error!==null&&d(`div`,{className:`text-danger`,children:w.error.message}),g!==null&&d(ai,{result:g}),D!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[D.modelChanges,` model change(s), `,D.thresholdClears,` node threshold reset(s), `,D.cameraOverrideClears+D.detectorStoreClears,` camera override(s) on `,D.camerasTouched,` camera(s).`]})]})]}),E?.warnings.map((e,t)=>d(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:Yr(e,C)},t)),E?.nodes.map(e=>d(ri,{plan:E,node:e,nodeName:C},e.nodeId)),E!==void 0&&d(Mt,{open:f,onOpenChange:p,children:i(P,{width:`lg`,scroll:`body`,children:[i(ne,{children:[d(L,{children:`Apply auto tune?`}),d(At,{children:`These are all the changes. Every override listed is removed and cannot be restored.`})]}),d(Te,{children:d(ii,{plan:E,nameOf:x,nodeName:C})}),i(De,{children:[d(V,{variant:`ghost`,onClick:()=>p(!1),children:`Cancel`}),d(V,{variant:`danger`,disabled:T.isPending,onClick:()=>T.mutate({planHash:E.planHash,headroom:t,minSessionsPerDevice:r}),children:T.isPending?`Applying…`:`Apply`})]})]})})]})}var si={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 ci(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function li(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function ui(e,t,n){let r=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let i=t.get(e.key)??(n?0:null),a=e.weight>0?e.weight:1;return{key:e.key,label:We(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?ci(a,r):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function di(e){let t=new Map(e.loads.map(e=>[e.nodeId,e])),n=e.nodes.filter(e=>e.isOnline&&e.detectEnabled).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.nodes.map(r=>{let i=t.get(r.id),a=ui(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),li(i)),o=r.isOnline&&r.detectEnabled,s=r.weight>0?r.weight:1,c=i?.load.attachedCameras??null;return{nodeId:r.id,name:r.name,isOnline:r.isOnline,detectEnabled:r.detectEnabled,reported:i!==void 0,attachedCameras:c,activeCameras:i?.load.activeCameras??null,maxCameras:r.maxCameras,capacityPct:c!==null&&r.maxCameras!==null&&r.maxCameras>0?ci(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?ci(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}var fi=`pipeline-orchestrator`,pi=`recorder`,mi=`recordingNodeId`,hi=`pipeline-analytics`,gi=`postProcessingNodeId`,_i=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`,`postProcessingNode`],vi=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function yi(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function bi(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function xi(e,t,n){let r=yi(e,t);return typeof r==`string`&&r.length>0?r:n}function q(e,t){let n=bi(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function Si(e,t){let n=bi(e,t);return typeof n==`string`&&n.length>0?n:null}function Ci(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:e===`postProcessingNode`?`Post-processing`:`Motion`}function wi(e){return e===`ingestNode`?`Connects to every camera and serves its stream to the others`:e===`recordingNode`?`Writes the recordings`:e===`audioNode`?`Runs audio analysis for every camera`:e===`postProcessingNode`?`Builds events and their media from detections, audio and motion`:`Runs software motion detection; cameras with onboard motion are unaffected`}function Ti(e,t){switch(t){case`detect`:return e.pipeline}}function Ei(e){return e instanceof Error?e.message:`Failed to save`}function Di(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}r();var Oi=2e4,ki=3e5;function Ai({stats:e,targetWeights:t}){let{nodes:n}=G(),r=x().trpcClient,o=le(void 0,{placeholderData:l,staleTime:Oi,refetchInterval:Oi,refetchOnWindowFocus:!0}),c=O(void 0,{staleTime:ki}),u=a(()=>n.map(e=>e.id),[n]),f=s({queries:u.map(e=>({queryKey:tn($e.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:ki,refetchOnWindowFocus:!1,placeholderData:l}))}),p=a(()=>{let e={};return u.forEach((t,n)=>{let r=f[n]?.data;r&&(e[t]=r.devices)}),e},[u,f.map(e=>e.dataUpdatedAt).join(`|`)]),m=a(()=>{let e=new Map;for(let t of c.data??[])e.set(t.nodeId,t.settings);return e},[c.data]),h=a(()=>n.map(e=>{let n=m.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:Sn(n,e.isHub).pipeline,weight:t?.[e.id]??q(n,`detectWeight`)??1,maxCameras:q(n,`maxCameras`)}}),[n,m,t]),_=o.data??[],v=a(()=>di({nodes:h,loads:_,devicesByNode:p}),[h,_,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),S=o.dataUpdatedAt>0?Date.now()-o.dataUpdatedAt:null,C=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return d(H,{headingId:`load-balancing-node-load`,title:`Node load`,icon:Ft,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[b,` running · `,y,` attached ·`,` `,o.data===void 0?`reading…`:`${S===null?`—`:`${Math.round(S/1e3)}s`} old`]}),children:d(`div`,{className:g,children:v.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>d(ji,{row:e,placed:C.get(e.nodeId)},e.nodeId))})})})}function ji({row:e,placed:t}){let n=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[d(xe,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(I,{className:`h-2.5 w-2.5`}),` offline`]})]}),i(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:n,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share (1 h)`,value:t?.observedShare===null||t===void 0?`—`:`${Math.round(t.observedShare*100)}%`,title:`Time-weighted share of the cluster's PARALLEL detection sessions this node carried over the last hour — the quantity a share holds. '—' = no session ran here in the window.`}),d(J,{label:`Peak · yields`,value:t===void 0?`—`:`${t.peakSessions} · ${t.yieldsAway}`,title:`Most sessions this node ran at once in the last hour, and how many share turns it handed to another node because it was full or drowning.`}),d(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(Mi,{row:e})]})}function Mi({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):i(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[i(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(Oe,{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(Ni,{device:e},e.key))})]})}function Ni({device:e}){let t=e.exclusion;return i(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(U,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?i(o,{children:[i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,title:e.sessions===null?`Not known: the node did not report, or runs a session no device accounts for.`:void 0,children:[`· `,e.sessions??`—`,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):i(`span`,{className:`truncate text-foreground-subtle/80`,title:si[t],children:[`excluded — `,si[t]]})]})}function J({label:e,value:t,title:n}){return i(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Pi(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Fi(e){let t={},n={};for(let r of e.nodes){if(r.share===null||r.share<=0)continue;t[r.nodeId]=r.share;let e=Object.fromEntries(r.devices.filter(e=>e.share>0).map(e=>[e.deviceKey,e.share]));Object.keys(e).length>0&&(n[r.nodeId]=e)}return{nodes:t,devices:n}}function Ii(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Li(e){return e.reason===`disabled`?`${e.deviceKey} is not enabled on any node — sessions ignore this pin`:`no node offers ${e.deviceKey} — sessions ignore this pin`}function Ri(e,t){if(t===void 0||t.source===`manual`||t.autoPending)return{nodes:e,readOnly:t!==void 0&&t.source!==`manual`};let n=new Map(t.nodes.map(e=>[e.nodeId,e.configuredPct]));return{nodes:e.map(e=>({...e,weight:Math.round(n.get(e.id)??e.weight)})),readOnly:!0}}function zi(e,t){let n=e.nodes.filter(e=>!e.eligible);if(n.length===0)return null;let r=e.nodes.filter(e=>e.eligible).map(e=>`${t(e.nodeId)} ${Math.round(e.effectivePct)}%`).join(`, `);return`${n.map(e=>t(e.nodeId)).join(`, `)} cannot take sessions — ${n.length===1?`its share goes`:`their shares go`} to the others: ${r}`}var Bi=[{value:`hardware`,label:`Hardware`,hint:`Each node’s share follows what its accelerators can carry at their Auto tune models, from the measured speed of its hardware. No load is measured or estimated.`},{value:`benchmark`,label:`Benchmark`,hint:`Each node’s share follows its own node-benchmark results. A node without results uses its hardware capacity instead, and says so.`},{value:`manual`,label:`Manual`,hint:`The sliders below, as you set them.`}];function Vi(e){return e===`no-benchmark-results`?`no benchmark results yet — sized from hardware`:e===`partial-benchmark-results`?`benchmark results miss some of its accelerators — sized from hardware`:null}function Hi(e,t){if(e.source!==`benchmark`)return null;let n=e.nodes.filter(e=>e.capacityFallback!==null);return n.length===0?null:n.map(e=>`${t(e.nodeId)}: ${Vi(e.capacityFallback)??``}`).join(` · `)}r();function Ui(e,t,n){return Math.min(Math.max(e,t),n)}function Wi(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function Gi(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:Ui(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function Ki(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function qi({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:a,footnote:s,readOnly:c=!1}){let[l,p]=u(()=>Wi(e)),[m,h]=u(new Set);f(()=>{p(Wi(e)),h(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let g=e.map(e=>e.id),_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=(e,t)=>{p(n=>Gi(n,e,t,m,g))},y=()=>{let t=Ki(l,g,m),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...m]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:a??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let b=e.length===1;return i(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=l[e.id]??0,a=m.has(e.id);return i(`div`,{className:`flex items-center gap-3`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),d(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:c||t||a||b,onChange:t=>v(e.id,Number(t.target.value)),onPointerUp:()=>y(),onKeyUp:()=>y(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),i(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),!c&&d(`button`,{type:`button`,onClick:()=>_(e.id),disabled:t||b,"aria-pressed":a,title:a?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${a?`text-amber-400`:`text-foreground-subtle`}`,children:d(a?ge:rt,{className:`h-3.5 w-3.5`})})]},e.id)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:s??d(o,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}r();function Ji(e){let t=We(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:U,hue:`slate`}:r===`npu`?{label:t,Icon:Ot,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:cn,hue:`violet`}:n===`edgetpu`?{label:t,Icon:pn,hue:`emerald`}:{label:t,Icon:U,hue:`slate`}}var Yi={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function Xi({nodeId:e,nodeName:t,isOnline:n,suggestedMaxSessions:r,autoDeviceShares:s}){let l=c(),{data:p,isLoading:m}=mt({nodeId:e},{refetchInterval:15e3}),h=yt({onSettled:()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),g=p?.devices??[],_=p?.reachable??n,[v,y]=u({});f(()=>{y(Object.fromEntries(g.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[g.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let b=a(()=>g.filter(e=>v[e.key]?.enabled??e.enabled).length,[g,v]),[x,S]=u(null),w=x??b>0,T=t=>{let n=g.map(e=>{let n=t[e.key]??E(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});h.mutate({agentNodeId:e,inferenceDevices:or(n)})},E=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),D=e=>{if(!e.available)return;let t=v[e.key]??E(e),n={...v,[e.key]:{...t,enabled:!t.enabled}};y(n),T(n)},O=(e,t)=>{let n=v[e.key]??E(e),r={...v,[e.key]:{...n,maxSessions:t}};y(r),T(r)},k=a(()=>g.filter(e=>(v[e.key]?.enabled??e.enabled)&&e.available),[g,v]),A=a(()=>k.map(e=>({id:e.key,name:Ji(e).label,weight:s===void 0?v[e.key]?.weight??e.weight:Math.round(s[e.key]??0)})),[k,v,s]);return i(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[i(`button`,{type:`button`,onClick:()=>S(!w),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":w,children:[d(C,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${w?`rotate-90`:``}`}),d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),d(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:_?b>=2?i(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[d(Rt,{className:`h-3.5 w-3.5`}),b,` accelerators`]}):b===1?d(`span`,{className:`text-foreground-subtle`,children:`single default`}):d(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):i(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[d(I,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),w&&i(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[_?m&&g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):d(`ul`,{className:`space-y-2`,children:g.map(e=>{let t=Ji(e),n=v[e.key]??E(e),a=n.enabled&&e.available;return i(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[d(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${Yi[t.hue]}`,children:d(t.Icon,{className:`h-4.5 w-4.5`})}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),d(W,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&d(W,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`font-mono`,children:e.key}),!a&&i(o,{children:[d(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:[`default model`,` `,d(`span`,{className:`font-mono text-foreground/80`,children:e.defaultModelId})]})]})]})]}),a&&i(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),d(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);O(e,r!=null&&r>0?r:null)},disabled:h.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),a&&d(Zi,{suggested:r?.[e.key]??null,current:n.maxSessions,pending:h.isPending,onApply:t=>O(e,t)}),d(Se,{checked:a,onCheckedChange:()=>D(e),disabled:!e.available||h.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):d(Qi,{}),_&&k.length>=2&&i(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[i(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[d(fn,{className:`h-3.5 w-3.5`}),`Accelerator share`]}),d(qi,{nodes:A,pending:h.isPending,onCommitWeights:e=>{let t={...v};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}y(t),T(t)},weightLabel:`Accelerator share`,readOnly:s!==void 0,footnote:s===void 0?d(o,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`}):d(o,{children:`Automatic: each accelerator's share follows its measured throughput at its model. Switch the node shares to manual to set them yourself.`})})]}),h.isError&&i(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,h.error instanceof Error?h.error.message:`unknown error`]})]})]})}function Zi({suggested:e,current:t,pending:n,onApply:r}){return e===null||e<1||e===t?null:i(V,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`,children:[`use `,e]})}function Qi(){return i(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[d(I,{className:`h-6 w-6 text-foreground-subtle/60`}),d(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),d(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}r();var $i=3600*1e3,ea=2e4,ta=.4;function na({refreshToken:e,onOpenAutoTune:t}){let n=c(),{nodes:r}=G(),s=O(void 0),f=vt({isCamera:!0,projection:`slim`}),p=Ne({windowMs:$i},{refetchInterval:ea,placeholderData:l}).data,m=ce(void 0,{refetchInterval:ea,placeholderData:l}).data,h=()=>{Di(n),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},_=Ze({onSuccess:h}),v=Et({onSuccess:()=>{h(),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),x=Ve({onSuccess:h}),S=xt(),[C,w]=u(!1),T=m?.source,E=T===`benchmark`?`benchmark`:`hardware`,D=Nt({headroom:ta,source:E},{enabled:C,staleTime:1/0}),k=D.data,A=a(()=>{let e=new Map((s.data??[]).map(e=>[e.nodeId,e.settings]));return r.filter(t=>Sn(e.get(t.id),t.isHub).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:q(n,`detectWeight`)??1,maxCameras:q(n,`maxCameras`)}})},[r,s.data]),j=e=>r.find(t=>t.id===e)?.name??e,ee=Nn((f.data??[]).map(e=>({id:e.id,name:e.name}))),M=k?Ii(k):void 0,N=Ri(A,m),P=T!==`manual`,F=e=>{if(m===void 0||m.source===`manual`||m.autoPending)return;let t=m.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},I=m?zi(m,j):null,L=m?Hi(m,j):null,R=Bi.find(e=>e.value===T)?.hint;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(sn,{nodeId:`hub`,addonIds:[fi],level:`global`,sectionIds:[`load`],title:`Placement policy`,description:`How a new detection session picks its node and device, and what happens when a node falls behind. 'Honour shares' (default) holds the shares below for PARALLEL sessions.`}),d(Dn,{refreshToken:e}),d(Ai,{stats:p,...m!==void 0&&m.source!==`manual`&&!m.autoPending?{targetWeights:Object.fromEntries(m.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),d(H,{headingId:`load-balancing-node-shares`,title:`Node shares`,icon:fn,actions:i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{role:`radiogroup`,"aria-label":`Share source`,className:`flex items-center gap-1`,children:Bi.map(e=>d(V,{role:`radio`,"aria-checked":T===e.value,variant:T===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:v.isPending||m===void 0,onClick:()=>{T!==e.value&&v.mutate({source:e.value})},children:e.label},e.value))}),i(V,{variant:`outline`,size:`sm`,onClick:()=>{w(!0),C&&D.refetch()},disabled:D.isFetching,children:[d(de,{className:`h-3.5 w-3.5`}),D.isFetching?`Suggesting…`:E===`benchmark`?`Suggest from benchmark`:`Suggest from hardware`]}),i(V,{variant:`ghost`,size:`sm`,onClick:t,children:[d(ke,{className:`h-3.5 w-3.5`}),`Auto tune`]}),i(V,{variant:`outline`,size:`sm`,onClick:()=>S.mutate(void 0),disabled:S.isPending,title:`Move standing (always-on) cameras that are no longer on their best node. Pinned cameras never move; on-motion sessions are placed per session anyway.`,children:[d(Ot,{className:`h-3.5 w-3.5`}),S.isPending?`Rebalancing…`:`Rebalance`]})]}),children:i(`div`,{className:`${g} space-y-3`,children:[R!==void 0&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:R}),p&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Policy:`,` `,d(W,{variant:p.policy===`share`?`info`:`default`,children:p.policy===`share`?`honour shares`:`least-loaded`}),` `,`· cluster peak `,p.clusterPeakSessions,` parallel sessions in the last hour`,p.policy===`least-loaded`&&` · under least-loaded an idle node always wins, so shares only bite once nodes are busy`]}),d(qi,{nodes:N.nodes,pending:_.isPending,readOnly:N.readOnly,onCommitWeights:e=>_.mutate(Pi(e)),weightLabel:`Node share`,...N.readOnly?{footnote:m?.autoPending?d(o,{children:`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`}):i(o,{children:[T===`benchmark`?`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`:`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`,m?.computedAt==null?``:` — last at ${new Date(m.computedAt).toLocaleTimeString()}${m.trigger===null?``:` (${m.trigger})`}`,`.`]})}:{}}),I!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:I}),L!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:L}),v.isError&&d(fe,{message:`Failed to switch shares: ${v.error instanceof Error?v.error.message:`unknown error`}`}),_.isError&&d(fe,{message:`Failed to save shares: ${_.error instanceof Error?_.error.message:`unknown error`}`}),i(`details`,{className:`rounded-md border border-border`,children:[d(`summary`,{className:`${b} cursor-pointer text-xs text-foreground`,children:`Max concurrent sessions (advanced)`}),d(`ul`,{className:`divide-y divide-border border-t border-border`,children:A.map(e=>i(`li`,{className:`${b} flex items-center gap-2`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),d(Be,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":`Max concurrent sessions for ${e.name}`,className:`w-20 text-right`,disabled:x.isPending,onBlur:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==e.maxCameras&&x.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),d(`p`,{className:`${b} ${y} border-t border-border`,children:`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`})]})]})}),D.isError&&d(fe,{message:`Suggestion failed: ${D.error instanceof Error?D.error.message:`unknown error`}`}),k&&d(ra,{suggestion:k,nameOf:j,pending:_.isPending,...P?{}:{onApply:()=>_.mutate(Fi(k))}}),d(H,{headingId:`load-balancing-accelerators`,title:`Accelerators`,icon:U,children:d(`div`,{className:`${g} space-y-2`,children:A.length===0?d(ve,{title:`No detect-capable nodes`,description:`Enable detection on a node in Roles & nodes to configure its accelerators.`}):A.map(e=>d(Xi,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...M?.[e.id]===void 0?{}:{suggestedMaxSessions:M[e.id]},...F(e.id)===void 0?{}:{autoDeviceShares:F(e.id)}},e.id))})}),p!==void 0&&p.stalePins.length>0&&d(ia,{stats:p,cameraName:ee})]})}function ra({suggestion:e,nameOf:t,pending:n,onApply:r}){return i(H,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?`Suggested from benchmark`:`Suggested from hardware`,icon:de,...r===void 0?{}:{actions:d(V,{size:`sm`,onClick:r,disabled:n,children:`Apply suggested shares`})},children:[d(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>i(`li`,{className:`${b} space-y-0.5`,children:[i(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),d(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?`skipped`:`${e.share}%`})]}),i(`p`,{className:y,children:[Vi(e.capacityFallback)===null?``:`${Vi(e.capacityFallback)} · `,e.skippedReason===null?`≈ ${e.capacitySessions} parallel sessions · ${e.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}`:`not part of the suggestion — ${e.skippedReason}`]})]},e.nodeId))}),i(`p`,{className:`${b} ${y} border-t border-border`,children:[`Shares in proportion to each node's capacity in parallel sessions —`,` `,e.source===`benchmark`?`measured by node benchmarks, or from the hardware table where a node has no results`:`at the models Auto tune picks (at least ${e.minSessionsPerDevice} per accelerator), from the measured speed of each node's hardware`,`, counted in `,e.cameraFps,` fps sessions with`,` `,Math.round(e.headroom*100),`% kept free. No load is measured or estimated.`,r===void 0?`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`:`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`]})]})}function ia({stats:e,cameraName:t}){let n=c(),r=Pe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return d(H,{headingId:`load-balancing-stale-pins`,title:`Stale device pins`,icon:un,children:d(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>i(`li`,{className:`${b} flex items-center gap-2`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[d(`p`,{className:`truncate text-xs text-foreground`,title:t(e.deviceId),children:t(e.deviceId)}),d(`p`,{className:y,children:Li(e)})]}),d(V,{variant:`outline`,size:`sm`,disabled:r.isPending,onClick:()=>r.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:`Clear pin`})]},e.deviceId))})})}r();var aa=1024,oa=65536;function sa(e,t,n){let r=e.trim();if(r.length===0)return{value:null,error:null};let i=Number(r);return Number.isInteger(i)?i<t?{value:null,error:`at least ${t}`}:i>n?{value:null,error:`at most ${n}`}:{value:i,error:null}:{value:null,error:`whole number`}}function ca({nodeId:e,decodeBudgetMb:t,maxLiveDecodeWorkers:n,status:r,errorMessage:a,onCommit:o}){let[s,c]=u(t===null?``:String(t)),[l,p]=u(n===null?``:String(n));f(()=>{c(t===null?``:String(t))},[t]),f(()=>{p(n===null?``:String(n))},[n]);let m=sa(s,aa,oa),h=sa(l,1,32),g=r===`pending`,_=m.value!==t||h.value!==n,v=m.error!==null||h.error!==null,y=_&&!v&&!g,b=()=>{y&&o(e,{decodeBudgetMb:m.value,maxLiveDecodeWorkers:h.value})};return i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(Be,{"aria-label":`Decode budget MB for ${e}`,type:`number`,inputMode:`numeric`,min:aa,max:oa,placeholder:`auto`,value:s,disabled:g,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:`w-20`}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`MB`}),d(Be,{"aria-label":`Max decode workers for ${e}`,type:`number`,inputMode:`numeric`,min:1,max:32,placeholder:`auto`,value:l,disabled:g,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:`w-20`}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`workers`}),i(V,{variant:`outline`,size:`sm`,onClick:b,disabled:!y,"aria-label":`Save decode limits for ${e}`,title:`Save decode limits`,children:[g?d(j,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):d(Qe,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),m.error===null?null:i(`span`,{className:`text-[11px] text-danger`,children:[`budget: `,m.error]}),h.error===null?null:i(`span`,{className:`text-[11px] text-danger`,children:[`workers: `,h.error]}),!_&&!g&&r===`success`&&d(Qe,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":`Saved`,role:`img`}),r===`error`&&d(`span`,{title:a??`Failed to save decode limits`,children:d(dt,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":`Save failed`,role:`img`})})]})}function la({node:e,emphasis:t=!1}){let n=e.isHub?ct:U;return i(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),i(`div`,{className:`min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(W,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(W,{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})]})]})}r();function ua({nodeId:e,value:t,detectedHosts:n,status:r,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=r===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return i(`div`,{className:`flex items-center gap-1.5`,children:[d(Be,{"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-36`}),i(V,{variant:`outline`,size:`sm`,onClick:v,disabled:!_,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,children:[m?d(j,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):d(Qe,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&r===`success`&&d(Qe,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":`Saved`,role:`img`}),r===`error`&&d(`span`,{title:a??`Failed to save reachable host`,children:d(dt,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}function da({nodes:e,actions:t}){return d(me,{columns:[{key:`node`,header:`Node`,sortValue:e=>e.name,render:e=>d(la,{node:e})},...vi.map(e=>({key:e.key,header:e.label,align:`center`,notSortableReason:`A switch — sorting would move the row while it is being changed.`,render:n=>d(Se,{"aria-label":`${e.label} on ${n.name}`,title:e.hint,checked:Ti(n.effective,e.key),disabled:t.capabilityPending,onCheckedChange:r=>t.onToggleCapability(n.id,e.key,r)})})),{key:`host`,header:`Reachable host`,notSortableReason:`An editor`,render:e=>d(ua,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})},{key:`decode`,header:`Decode limits`,notSortableReason:`An editor`,render:e=>d(ca,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})}],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,mobileMode:`scroll`,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:`No cluster nodes reporting yet.`})}function fa({roleValues:e,options:t,pending:n,onRoleChange:r}){let a=t.map(e=>({value:e.id,label:e.id===`hub`?`${e.name} (default)`:e.name}));return d(`ul`,{className:`divide-y divide-border`,children:_i.map(t=>i(`li`,{className:`${b} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[i(`div`,{className:`min-w-0 flex-1 basis-56`,children:[d(`div`,{className:`text-xs font-medium text-foreground`,children:Ci(t)}),d(`p`,{className:y,children:wi(t)})]}),d(`div`,{className:`w-full sm:w-48`,children:d(z,{"aria-label":`${Ci(t)} node`,value:e[t],disabled:n,options:a,onChange:e=>r(t,e.target.value)})})]},t))})}r();function pa(){let e=c(),{nodes:t}=G(),n=O(void 0),r=Ge({addonId:fi}),o=Ge({addonId:pi}),s=Ge({addonId:hi}),l=()=>Di(e),u=Ie({onSuccess:l}),f=it({onSuccess:l}),p=ut({onSuccess:l}),m=ot({onSuccess:l}),h=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),g=a(()=>t.map(e=>{let t=h.get(e.id),n=Sn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,reachableHost:Si(t,`reachableHost`),detectedHosts:e.localIps,decodeBudgetMb:q(t,`decodeBudgetMb`),maxLiveDecodeWorkers:q(t,`maxLiveDecodeWorkers`)}}),[t,h]),_={ingestNode:xi(r.data,`ingestNode`,`hub`),recordingNode:xi(o.data,mi,`hub`),audioNode:xi(r.data,`audioNode`,`hub`),motionNode:xi(r.data,`motionNode`,`hub`),postProcessingNode:xi(s.data,gi,`hub`)},v=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id),n=e=>t.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,..._i.map(e=>_[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:n(e)}))},[t,_]),b=n.isLoading||r.isLoading||o.isLoading||s.isLoading,x=(e,t,n)=>{u.mutate({agentNodeId:e,[t]:n})},S=(e,t)=>{if(e===`recordingNode`){m.mutate({addonId:pi,patch:{[mi]:t}});return}if(e===`postProcessingNode`){m.mutate({addonId:hi,patch:{[gi]:t}});return}m.mutate({addonId:fi,patch:{[e]:t}})},C=e=>f.variables?.agentNodeId===e?f.isPending?`pending`:f.isError?`error`:f.isSuccess?`success`:`idle`:`idle`,w=e=>C(e)===`error`?Ei(f.error):null,T=e=>p.variables?.agentNodeId===e?p.isPending?`pending`:p.isError?`error`:p.isSuccess?`success`:`idle`:`idle`,E={capabilityPending:u.isPending,onToggleCapability:x,onCommitReachableHost:(e,t)=>f.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:C,reachableHostErrorMessage:w,onCommitDecodeLimits:(e,t)=>p.mutate({agentNodeId:e,...t}),decodeLimitsStatus:T,decodeLimitsErrorMessage:e=>T(e)===`error`?Ei(p.error):null};return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(H,{headingId:`roles-nodes-cluster-roles`,title:`Cluster roles`,icon:ln,actions:b?d(j,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":`Loading`}):null,children:[d(`p`,{className:`${y} border-b border-border px-3 py-1.5 sm:px-4`,children:`One node holds each role for every camera. Detection shares and caps are on Load balancing.`}),d(fa,{roleValues:_,options:v,pending:m.isPending,onRoleChange:S})]}),d(H,{headingId:`roles-nodes-node-capabilities`,title:`Node capabilities`,icon:ct,children:d(da,{nodes:g,actions:E})})]})}var ma=`pipeline-analytics`,ha=`face-gallery`,ga=`pipeline-orchestrator`,_a=`pipeline-runner`,va=`audio-analyzer`;function ya(e){return[...Kt.filter(t=>t.stepId===e).map(e=>Bt(e.stepId)),...Vt.filter(t=>t.stepId===e).map(e=>Yt(e.stepId,e.key))]}var ba=`faces`,xa=`semantic-search`,Sa=[{id:ba,title:`Faces & recognition`,hint:`The face encoder for every node, the smallest faces worth embedding, keeping and auto-assigning, and how a face is matched to a person.`,panels:[{addonId:ga,fieldKeys:ya(`face-embedding`)},{addonId:ma,capability:ha}]},{id:xa,title:`Semantic search`,hint:`The image encoder behind "search by description". One for the whole cluster: changing it hides existing results until the index is rebuilt.`,panels:[{addonId:ga,fieldKeys:ya(`clip-embedding`)}]},{id:Xt,title:`Enrichment crop`,hint:`How the crop handed to face, plate and search models is cut from the frame.`,panels:[{addonId:ga,sectionIds:[Xt]}]},{id:qt,title:`Full-resolution crops`,hint:`How long each camera keeps full-resolution pixels so a late crop (snapshot, face, plate) is sharp instead of cut from the small detection frame.`,panels:[{addonId:ga,sectionIds:[qt]}]},{id:`runner-defaults`,title:`Runner defaults`,hint:`Values every node's detection runner and audio analyzer use. A node's own decode limits (Roles & nodes) take precedence.`,panels:[{addonId:_a,fieldScope:`cluster`},{addonId:va,fieldScope:`cluster`}]},{id:`failover`,title:`Failover`,hint:`What happens to cameras when a node disconnects and comes back.`,panels:[{addonId:ga,sectionIds:[`failover`]}]}],Ca={"cluster-step-models":ba};function wa(e){return e===`clip-embedding`?xa:ba}r();var Ta=2500,Ea={faces:Le,"semantic-search":ke,"detail-crop":Lt,"native-lease":Rt,"runner-defaults":U,failover:A};function Da(e){f(()=>{if(e===null)return;let t=Ca[e]??e,n=`[data-cluster-settings-card="${CSS.escape(t)}"]`,r=()=>{let e=document.querySelector(n);return e===null?!1:(e.scrollIntoView({block:`start`,behavior:`smooth`}),e.classList.add(`ring-2`,`ring-primary/60`),setTimeout(()=>e.classList.remove(`ring-2`,`ring-primary/60`),Ta),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function Oa({section:e}){return d(`div`,{"data-cluster-settings-card":e.id,className:`rounded-lg`,children:d(H,{headingId:`cluster-settings-${e.id}`,title:e.title,...Ea[e.id]===void 0?{}:{icon:Ea[e.id]},children:i(`div`,{className:`${g} space-y-3`,children:[d(`p`,{className:y,children:e.hint}),e.panels.map(e=>d(sn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:[`cluster`,`load`],emptyMessage:`Not available — the addon that owns these settings did not answer.`,...e.capability===void 0?{}:{capability:e.capability},...e.sectionIds===void 0?{}:{sectionIds:e.sectionIds},...e.fieldKeys===void 0?{}:{fieldKeys:e.fieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function ka({refreshToken:e}){let[t]=an();return Da(t.get(Ao)),d(`div`,{className:`space-y-3 sm:space-y-4`,children:Sa.map(e=>d(Oa,{section:e},e.id))})}var Aa=`pipeline-orchestrator`,ja=200;function Ma(){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(Fe,{addonId:Aa,limit:ja,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}var Na=[{id:`assignments`,label:`Assignments`},{id:`load-balancing`,label:`Load balancing`},{id:`auto-tune`,label:`Auto tune`},{id:`roles-nodes`,label:`Roles & nodes`},{id:`settings`,label:`Settings`},{id:`logs`,label:`Logs`}];function Pa(e){return Na.some(t=>t.id===e)}function Fa({refreshToken:e}){let[t,n]=an(),r=t.get(ko),a=Pa(r)?r:`assignments`,o=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(ko,e),n.delete(Ao),n},{replace:!0})};return i(`div`,{className:`flex flex-col h-full`,children:[i(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Na.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[a===`assignments`&&d(Vr,{}),a===`load-balancing`&&d(na,{refreshToken:e,onOpenAutoTune:()=>o(`auto-tune`)}),a===`auto-tune`&&d(oi,{}),a===`roles-nodes`&&d(pa,{}),a===`settings`&&d(ka,{refreshToken:e}),a===`logs`&&d(Ma,{})]})]})}var Ia=`armed:`;function La(e){return e.assignment.reasons.detection?.startsWith(Ia)===!0}function Ra(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!La(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function za(e){let t=[],n=[],{assignment:r,detection:i,broker:a}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),r.detectionNodeId===null&&i===null&&!La(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let o=e.degraded??[];if(o.length>0){let e=[...new Set(o.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}n.push(...Ha(e.cameraSensors));for(let e of a?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Ba(e){return e.state===`unreadable`&&Ut.state===`unreadable`&&e.reason===Ut.reason}function Va(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is missing`};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) is ${e.reason}`};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) cannot drive motion: ${e.reason}`};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is unreadable: ${e.reason}`}}}function Ha(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return Ba(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:`Camera sensors unreadable: ${e.reason}`}];let t=e.sensors.flatMap(e=>{let t=Va(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[Ua(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:`Confirm / Replace cannot suppress this camera's own motion until its provider is updated`},...n]}function Ua(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?`Camera sensors are attached but never fire: add "Camera sensors" (onboard) to this camera's motion sources`:`Camera sensors are attached but never fire: this camera has no active detection`}}function Wa(e){return e===void 0?`status unavailable from this node`:e.state===`not-configured`?`none attached`:e.state===`unreadable`?`unknown — ${e.reason}`:e.sensors.map(Ka).join(`, `)}function Ga(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function Ka(e){return`${qa(e)}${Ga(e)}`}function qa(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return`${e.name} (#${e.deviceId}) — unsupported`;case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function Ja(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Ya(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Xa(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Za(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Qa={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 $a(e){if(!Ja(e)||!Array.isArray(e.sections))return Qa;let t=$t(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)Za(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Ya(n(`detectionFps`)),motionSources:Xa(n(`motionSources`)),motionFps:Ya(n(`motionFps`)),motionCooldownMs:Ya(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 eo(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(...eo(r.children,t+1));return n}function X({title:e,children:t}){return i(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return i(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(to,{})]})}function to(){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 no={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 ${no[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function ro({icon:e,label:t,nodeId:n,pinned:r,reason:a,overridden:s}){return i(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):i(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?i(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(dn,{className:`h-2.5 w-2.5`}),` manual`]}):i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function io({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return i(X,{title:`Where it runs`,children:[d(ro,{icon:U,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(ro,{icon:se,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(ro,{icon:E,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(ro,{icon:Ue,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:i(`select`,{value:o,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>i(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function ao(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function oo(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function so(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function co({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:a,cameraSensors:s}){let c=oo(t,n.detectionStreamProfile),l=oo(t,n.motionStreamProfile),u=n.motionSources.includes(`analyzer`);return i(X,{title:`Streams & motion`,children:[i(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:so(n.detectionFps)}),i(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map(en).join(` + `):`none`,r===!1&&` · inactive`]}),d(Z,{label:`Camera sensors`,children:Wa(s)}),u&&i(o,{children:[i(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),i(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[so(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>i(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,ao(e)]},e.camStreamId))})]})}function lo({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return i(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:i(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&i(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:i(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var uo={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function fo({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return i(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:r,children:n??`—`}),d($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=F(a),f=a===`active`&&o===0;return i(X,{title:`Detection runtime`,children:[i(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[i(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(_e,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:r,children:n??`—`}),i(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),i(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&i(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&i(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),i(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),i(Z,{label:`Provisioning`,children:[d(Q,{tone:uo[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&i(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function po({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):i(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return i(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),i(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),i(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps===null?`—`:e.inFps.toFixed(0),`fps`]}),i(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),i(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[i(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),i(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function mo({decoder:e}){return e===null?d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})}):d(X,{title:`Decoder`,children:d(Z,{label:`Node`,children:e.nodeId})})}r();var ho=`pipeline-orchestrator`,go={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},_o={healthy:`Healthy`,idle:`Idle`,error:`Error`};function vo({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>i(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[d(xe,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function yo({deviceId:e,name:t,online:n,status:r,live:o,onlineNodes:s}){let l=c(),{data:u}=wt({addonId:ho,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=et({deviceId:e},{staleTime:3e4}),p=a(()=>$a(u),[u]),m=a(()=>f===void 0?void 0:eo(f.steps),[f]),h=a(()=>r===void 0?[]:za(r),[r]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=ae({onSuccess:g}),v=jt({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=r===void 0?`idle`:Ra(r),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return i(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[i(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:go[b]}`,title:x?`Error`:_o[b],"aria-label":x?`Error`:_o[b],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),i(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),r?.recording!=null&&(r.recording.active?i(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&i(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),h.length>0&&d(vo,{problems:h}),r===void 0?d(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):i(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(io,{assignment:r.assignment,settings:p,onlineNodes:s,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),d(fo,{detection:r.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(lo,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:r.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(co,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:p,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null,cameraSensors:r.cameraSensors}),d(po,{broker:r.broker}),d(mo,{decoder:r.decoder})]})]})}r();var bo=5e3,xo=1e4,So=5e3;function Co(e){let t=c(),{data:n,isLoading:r}=on(),{data:i,isLoading:o}=ie({},{refetchInterval:bo}),{nodes:s}=G();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);st(Qt.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()-xo,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},So);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}r();function wo({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:o}=Co(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:za(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:i(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[i(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[i(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),i(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),i(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(yo,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}var To=e({CLUSTER_NODE_ID:()=>Eo,PipelinePage:()=>Oo});r();var Eo=`__cluster__`;function Do(e){return e===`cameras`?`cameras`:`nodes`}function Oo(){let[e,t]=an(),n=Do(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Eo},{replace:!0})},[n,e,t]),i(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[i(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[i(`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:r},{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:i(`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(Ct,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),n===`nodes`&&i(`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:[i(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(S,{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`?i(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(wn,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?d(Fa,{refreshToken:a}):d(Br,{nodeId:r,refreshToken:a})})]}):d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:d(wo,{refreshToken:a})})})]})}var ko=`ctab`,Ao=`section`;function jo(e,t){let n=new URLSearchParams({view:`nodes`,node:Eo,[ko]:e});return t!==void 0&&n.set(Ao,t),`/pipeline?${n.toString()}`}function Mo(e){return jo(`settings`,wa(e))}function No(){return jo(`load-balancing`)}var Po=`pipeline-orchestrator`;function Fo(e){return Kt.find(t=>t.stepId===e)??null}function Io({step:e,engineFormat:t,runnableModelIds:n}){let{data:r}=Ge({addonId:Po}),a=zt(r??null)[e.stepId]??e.defaultModelId,o=e.options.find(e=>e.id===a)?.label??a,s=n.length>0&&!n.includes(a);return i(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:o}),d(`span`,{title:`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`}),d(rn,{to:Mo(e.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Change in Cluster → Settings ›`})]}),i(`p`,{className:y,children:[`One model for every node and camera: `,e.indexName,` only matches vectors from the model that made them.`]}),s&&i(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:[`This accelerator's engine (`,t,`) ships no build of `,d(`b`,{children:a}),`. It refuses this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`.`]})]})}export{cr as _,Er as a,dr as c,_r as d,yr as f,lr as g,vr as h,Dr as i,Cr as l,gr as m,Fo as n,hr as o,Sr as p,To as r,br as s,Io as t,xr as u,ar as v,hn as y};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as u,ct as d,ft as f,gt as p,ht as m,st as h,vt as g}from"./player-overlays-tKtUzh3g.js";import{Ad as _,Au as v,Ba as y,Cn as b,Dn as x,En as S,Fn as C,Ga as w,Ha as T,In as E,Ja as D,Ka as O,La as k,Mu as A,Pu as j,Ra as M,Tn as N,Ua as P,Uu as F,Va as I,Wa as L,Ya as R,ad as z,bn as B,gd as V,gf as H,ld as U,mu as W,qa as G,qn as K,sa as ee,tr as te,ud as ne,vd as re,wn as q,xn as J,yu as Y,za as ie}from"./src-Y4G_LfLc.js";import{t as ae}from"./crop-9g1Z5sFT.js";import{a as oe,c as se,f as ce,i as le,l as ue,m as de,n as X,o as fe,p as Z,r as pe,s as me,t as he,u as ge}from"./debounced-invalidate-COhAlfWE.js";import{t as _e}from"./user-round-BGmDt-wq.js";import{n as ve,r as ye,t as be}from"./face-bbox-CFdWEIAo.js";import{pi as xe}from"./client-HDm3z1QL.js";import{X as Se}from"./index-d2QAhmc-.js";import{t as Ce}from"./AdminPage-BSFohA3i.js";import{n as we,r as Te}from"./authed-media-DQAkskU5.js";var Ee=g(`image-plus`,[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]);n();var De=`pipeline-analytics`,Oe=`photo.analyze`,ke=`photo.enroll`,Ae=`photo.discard`,je=18*1024*1024;function Me(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function $(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Ne(e,t){let n=e[t];return typeof n==`boolean`?n:null}function Pe(e){if(!Me(e))return null;let t=$(e,`x`),n=$(e,`y`),r=$(e,`width`),i=$(e,`height`);return t===null||n===null||r===null||i===null?null:{x:t,y:n,width:r,height:i}}function Fe(e){if(!Me(e))return null;let t=$(e,`detectionShortSidePx`),n=$(e,`score`);if(t===null||n===null)return null;let r=$(e,`magnitude`);return{detectionShortSidePx:t,score:n,...r===null?{}:{magnitude:r}}}function Ie(e){if(!Me(e))return null;let t=$(e,`faceIndex`),n=$(e,`score`),r=Ne(e,`enrollable`),i=Pe(e.bbox),a=Fe(e.quality);if(t===null||n===null||r===null||i===null||a===null)return null;let o=Q(e,`refusedReason`),s=Q(e,`alignedCropBase64`),c=Q(e,`modelId`);return{faceIndex:t,bbox:i,score:n,enrollable:r,quality:a,...o===null?{}:{refusedReason:o},...s===null?{}:{alignedCropBase64:s},...c===null?{}:{modelId:c}}}function Le(e){if(!Me(e))return null;let t=Q(e,`sessionId`),n=Q(e,`ranOnNodeId`),r=e.faces;if(t===null||n===null||!Array.isArray(r))return null;let i=[];for(let e of r){let t=Ie(e);t!==null&&i.push(t)}return{sessionId:t,ranOnNodeId:n,faces:i}}function Re(e){if(!Me(e))return null;let t=Q(e,`sampleId`),n=Q(e,`identityId`),r=Q(e,`modelId`);return t===null||n===null||r===null?null:{sampleId:t,identityId:n,modelId:r}}function ze(e,t,n){let r={...e};return n===null||n===``?delete r[t]:r[t]=n,r}function Be(e,t){return e.filter(e=>e.enrollable&&t[e.faceIndex]!==void 0).length}function Ve(e,t,n){let r=[];for(let i of t){if(!i.enrollable)continue;let t=n[i.faceIndex];t!==void 0&&r.push({sessionId:e,faceIndex:i.faceIndex,identityId:t})}return r}function He(e){switch(e){case`no-embedding`:return`Too small or too indistinct for the recognizer to measure — try a photo where this face is larger.`;case`no-model-id`:return`The recognizer did not report which model it used, so this face cannot be enrolled safely.`;case`no-aligned-crop`:return`The recognizer produced no aligned crop for this face, so there is nothing to store.`;case`magnitude`:return`Refused by the quality gate: the features look degenerate, and a sample like this matches everybody.`;default:return`This face is not usable as a sample.`}}function Ue(e,t){let n=[],r=[];for(let i of e)i.size>t.maxBytes?n.push(i.name):r.push(i);return{accepted:r.slice(0,t.maxCount),oversize:n,overflow:r.slice(t.maxCount).map(e=>e.name)}}async function We(e,t,n){let r=Array(e.length),i=e.map((e,t)=>({item:e,index:t})),a=0,o=async()=>{for(;;){let e=i[a];if(a+=1,e===void 0)return;r[e.index]=await n(e.item,e.index)}},s=Array.from({length:Math.max(1,Math.min(t,e.length))},()=>o());return await Promise.all(s),r}function Ge(e,t,n){return e.map(e=>e.photoIndex===t?{...e,...n}:e)}function Ke(e,t){return`${e}:${t}`}function qe(e,t,n,r){let i=ze(e[t]??{},n,r),a={...e};return Object.keys(i).length===0?delete a[t]:a[t]=i,a}function Je(e,t){let n=0;for(let r of e)r.analysis!==void 0&&(n+=Be(r.analysis.faces,t[r.photoIndex]??{}));return n}var Ye=`__new__`;function Xe(e,t,n){let r=[];for(let i of e){if(i.analysis===void 0)continue;let e=t[i.photoIndex]??{};for(let t of i.analysis.faces){if(!t.enrollable||e[t.faceIndex]!==`__new__`)continue;let a=(n[Ke(i.photoIndex,t.faceIndex)]??``).trim();if(a===``)return{kind:`error`,message:`${i.filename}: face ${t.faceIndex+1} is set to a new person but has no name.`};r.includes(a)||r.push(a)}}return{kind:`ok`,names:r}}function Ze(e,t,n){let r={};for(let[i,a]of Object.entries(e)){let e=Number(i),o={};for(let[r,i]of Object.entries(a)){let a=Number(r);if(i!==`__new__`){o[a]=i;continue}let s=n[(t[Ke(e,a)]??``).trim()];s!==void 0&&(o[a]=s)}r[e]=o}return r}function Qe(e,t){let n=[];for(let r of e){if(r.analysis===void 0)continue;let e=Ve(r.analysis.sessionId,r.analysis.faces,t[r.photoIndex]??{});for(let t of e)n.push({photoIndex:r.photoIndex,request:t})}return n}function $e(e){return/expired/i.test(e)}function et(e){return e instanceof Error?e.message:String(e)}async function tt(e,t,n){let r=new Map(e.map(e=>[e.photoIndex,e])),i={},a=[],o=0,s=null,c=(e,t)=>`${r.get(e)?.filename??`photo ${e+1}`}, face ${t+1}`;for(let l of Qe(e,t)){let e=i[l.photoIndex],t=e===void 0?l.request:{...l.request,sessionId:e.sessionId};try{let e=await n.enroll(t);o+=1,s=e.modelId}catch(t){let u=et(t);if(!$e(u)||e!==void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let d=r.get(l.photoIndex);if(d===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${u}`);continue}let f;try{f=await n.reanalyze(d)}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired and re-analysing failed (${et(e)})`);continue}if(i[l.photoIndex]=f,f.faces.find(e=>e.faceIndex===l.request.faceIndex&&e.enrollable)===void 0){a.push(`${c(l.photoIndex,l.request.faceIndex)}: the analysis expired, and re-analysing no longer finds this face — assign it again from the fresh result`);continue}try{let e=await n.enroll({...l.request,sessionId:f.sessionId});o+=1,s=e.modelId}catch(e){a.push(`${c(l.photoIndex,l.request.faceIndex)}: ${et(e)}`)}}}return{enrolled:o,stampedModelId:s,failures:a,refreshedAnalyses:i}}var nt=[[`faceGallery`]],rt=``;function it(e){return new Promise((t,n)=>{let r=new FileReader;r.addEventListener(`error`,()=>n(Error(`the file could not be read`)),{once:!0}),r.addEventListener(`load`,()=>{let e=r.result;if(typeof e!=`string`){n(Error(`the file could not be read`));return}let i=e.indexOf(`,`);t(i>=0?e.slice(i+1):e)},{once:!0}),r.readAsDataURL(e)})}function at(e){return e instanceof Error?e.message:String(e)}function ot({face:e,identities:t,value:n,onChange:o,disabled:s}){let l=i(()=>[{value:rt,label:`Ignore this face`},...t.map(e=>({value:e.id,label:e.name})),{value:Ye,label:`+ New person…`}],[t]);return r(`div`,{className:`rounded-md border border-border bg-surface p-2`,children:[c(`div`,{className:`mb-2 aspect-square w-full overflow-hidden rounded border border-border bg-surface-hover`,children:e.alignedCropBase64?c(`img`,{src:`data:image/jpeg;base64,${e.alignedCropBase64}`,alt:`Face ${e.faceIndex+1}`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(_e,{className:`h-8 w-8`})})}),e.enrollable?r(a,{children:[c(C,{options:l,value:n,disabled:s,onChange:e=>o(e.target.value),"aria-label":`Assign face ${e.faceIndex+1}`}),r(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:[Math.round(e.quality.detectionShortSidePx),` px`,e.modelId?` · ${e.modelId}`:``]})]}):r(`div`,{className:`space-y-1`,children:[c(te,{variant:`warning`,className:`text-[10px]`,children:`Not usable`}),c(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:He(e.refusedReason)})]})]})}function st({photo:e,identities:t,draft:n,newNames:i,disabled:a,onAssign:o,onNameChange:s,onRetry:l}){let u=e.analysis?.faces??[],d=n[e.photoIndex]??{};return r(`div`,{className:`space-y-2`,children:[r(`div`,{className:`flex items-center gap-2 border-b border-border pb-1`,children:[c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.filename}),e.status===`analyzing`||e.status===`queued`?r(`span`,{className:`flex items-center gap-1 text-xs text-foreground-subtle`,children:[c(_,{className:`h-3 w-3 animate-spin`}),` analysing…`]}):null,e.status===`analyzed`&&e.analysis!==void 0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[u.length,` face`,u.length===1?``:`s`,` · analysed on`,` `,e.analysis.ranOnNodeId]}),e.status===`failed`&&r(E,{variant:`secondary`,size:`sm`,disabled:a,onClick:l,children:[c(U,{className:`h-3 w-3`}),` Retry`]})]}),e.status===`failed`&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(j,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),r(`span`,{children:[`This photo could not be analysed: `,e.error??`unknown error`,`. The other photos are unaffected.`]})]}),e.status===`analyzed`&&u.length===0&&c(`p`,{className:`text-xs text-foreground-subtle`,children:`No faces were found in this photo. A face has to be reasonably large and facing the camera for the detector to measure it.`}),u.length>0&&c(`div`,{className:`grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5`,children:u.map(e=>c(ot,{face:e,identities:t,value:d[e.faceIndex]??rt,disabled:a,onChange:t=>o(e.faceIndex,t)},e.faceIndex))}),u.filter(e=>d[e.faceIndex]===Ye).map(t=>r(`div`,{className:`flex items-center gap-2`,children:[r(`span`,{className:`w-28 shrink-0 truncate text-xs text-foreground-subtle`,children:[`Face `,t.faceIndex+1]}),c(`input`,{className:`h-7 flex-1 rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,placeholder:`New person name… (type the same name under another face to reuse it)`,value:i[Ke(e.photoIndex,t.faceIndex)]??``,onChange:e=>s(t.faceIndex,e.target.value)})]},t.faceIndex))]})}function ct({open:n,onOpenChange:a}){let l=u(),d=o(),f=t(null),{data:p}=T(),m=M(),[h,g]=s([]),[v,y]=s(!1),[C,w]=s(null),[D,O]=s({}),[k,A]=s({}),[P,F]=s(null),I=i(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),L=h.some(e=>e.status===`queued`||e.status===`analyzing`),R=L||v,z=e(e=>{for(let t of e){let e=t.analysis?.sessionId;e!==void 0&&l.trpcClient.addons.custom.mutate({addonId:De,action:Ae,input:{sessionId:e}}).catch(()=>void 0)}},[l]),B=e(()=>{g([]),O({}),A({}),w(null),F(null),f.current&&(f.current.value=``)},[]),V=e(()=>{z(h),B(),a(!1)},[z,a,h,B]),H=e(async e=>{let t=Le(await l.trpcClient.addons.custom.mutate({addonId:De,action:Oe,input:{photoBase64:e.photoBase64,filename:e.filename}}));if(t===null)throw Error(`the server replied with something this page could not read`);return t},[l]),U=e(async e=>{g(t=>Ge(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await H(e);g(n=>Ge(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>Ge(n,e.photoIndex,{status:`failed`,error:at(t)}))}},[H]),W=e(async e=>{if(e.length===0)return;z(h),B();let t=Ue(e,{maxCount:12,maxBytes:je}),n=[];t.oversize.length>0&&n.push(`Over the ${Math.round(je/(1024*1024))} MB limit and skipped: ${t.oversize.join(`, `)}.`),t.overflow.length>0&&n.push(`A batch holds at most 12 photos — not analysed: ${t.overflow.join(`, `)}. Enrol them in a second round.`),n.length>0&&w(n.join(` `));let r;try{r=await Promise.all(t.accepted.map(async(e,t)=>({photoIndex:t,filename:e.name,photoBase64:await it(e),status:`queued`})))}catch(e){w(at(e));return}g(r),await We(r,2,e=>U(e))},[z,h,B,U]),G=Je(h,D),K=e(async()=>{y(!0),w(null),F(null);try{let e=Xe(h,D,k);if(e.kind===`error`){w(e.message);return}let t={};for(let n of e.names)t[n]=(await m.mutateAsync({name:n})).id;let n=await tt(h,Ze(D,k,t),{enroll:async e=>{let t=Re(await l.trpcClient.addons.custom.mutate({addonId:De,action:ke,input:e}));if(t===null)throw Error(`unreadable reply`);return t},reanalyze:e=>H(e)});Object.keys(n.refreshedAnalyses).length>0&&g(e=>e.map(e=>{let t=n.refreshedAnalyses[e.photoIndex];return t===void 0?e:{...e,status:`analyzed`,analysis:t}})),d.invalidateQueries({queryKey:nt}),n.failures.length>0&&w(n.failures.join(` · `)),F(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){w(at(e))}finally{y(!1)}},[H,m,D,k,h,d,l]),ee=h.filter(e=>e.status===`analyzed`).length;return c(J,{open:n,onOpenChange:e=>e?a(!0):V(),children:r(b,{className:`max-w-3xl`,children:[r(S,{children:[c(x,{children:`Enrol from photos`}),c(q,{children:`Every photo is analysed with the same face detector the cameras use, and all the faces found are reviewed below in one pass, grouped by photo. Assign each face to a person, or leave it ignored.`})]}),r(`div`,{className:`rounded-md border border-border bg-surface-hover px-3 py-2 text-xs text-foreground-subtle`,children:[`For reliable recognition use `,c(`strong`,{children:`at least 3 photos per person`}),`, taken at different times, with different poses and lighting — you can select them all at once. Several frames from the same moment count as one — they do not add information.`]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{ref:f,type:`file`,accept:`image/jpeg,image/png,image/webp`,multiple:!0,className:`hidden`,onChange:e=>void W(Array.from(e.target.files??[]))}),r(E,{variant:`secondary`,size:`sm`,disabled:R,onClick:()=>f.current?.click(),children:[L?c(_,{className:`h-3.5 w-3.5 animate-spin`}):c(Ee,{className:`h-3.5 w-3.5`}),`Choose photos`]}),h.length>0&&r(`span`,{className:`text-xs text-foreground-subtle`,children:[ee,`/`,h.length,` photo`,h.length===1?``:`s`,` analysed`]})]}),C!==null&&r(`div`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:[c(j,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),c(`span`,{children:C})]}),P!==null&&c(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:P}),h.length>0&&c(`div`,{className:`max-h-[50vh] space-y-4 overflow-y-auto pr-1`,children:h.map(e=>c(st,{photo:e,identities:I,draft:D,newNames:k,disabled:R,onAssign:(t,n)=>O(r=>qe(r,e.photoIndex,t,n===rt?null:n)),onNameChange:(t,n)=>A(r=>({...r,[Ke(e.photoIndex,t)]:n})),onRetry:()=>void U(e)},e.photoIndex))}),r(N,{children:[c(E,{variant:`secondary`,onClick:V,disabled:v,children:`Close`}),r(E,{variant:`primary`,onClick:()=>void K(),disabled:R||G===0,children:[v?c(_,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,G,` face`,G===1?``:`s`]})]})]})})}n();var lt=[[`faceGallery`]];function ut({identityId:e}){let t=o(),{data:n,isLoading:i}=P({identityId:e}),a=w();function s(n){a.mutate({identityId:e,sampleId:n.id},{onSettled:()=>{t.invalidateQueries({queryKey:lt})}})}return i?r(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,children:[c(_,{className:`h-3.5 w-3.5 animate-spin`}),`Loading samples…`]}):!n||n.length===0?c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No samples yet.`}):c(`div`,{className:`mt-2 grid grid-cols-4 gap-2 sm:grid-cols-6 md:grid-cols-8`,children:n.map(e=>r(`div`,{className:`group relative aspect-square overflow-hidden rounded-md border border-border bg-surface`,children:[e.base64?c(`img`,{src:`data:image/jpeg;base64,${e.base64}`,alt:`Sample`,className:`h-full w-full object-cover`}):c(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:c(_e,{className:`h-6 w-6`})}),e.source===`photo`&&c(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 p-0.5 text-white`,title:`Enrolled from an uploaded photo`,children:c(Ee,{className:`h-3 w-3`})}),c(`button`,{type:`button`,onClick:()=>s(e),disabled:a.isPending,className:`absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 transition-opacity group-hover:opacity-100 disabled:cursor-not-allowed`,"aria-label":`Remove sample`,children:c(Y,{className:`h-4 w-4 text-white`})})]},e.id))})}function dt({identity:e,expanded:t,onToggle:n}){let i=o(),[l,u]=s(``),[d,f]=s(!1),[g,v]=s(!1),C=O(),w=y();function T(){u(e.name),f(!0)}function D(){f(!1),u(``)}function k(){let t=l.trim();if(!t||t===e.name){D();return}C.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),D()}})}function A(){w.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),v(!1)}})}return r(`div`,{className:`rounded-md border border-border bg-surface`,children:[r(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[c(`div`,{className:`h-8 w-8 shrink-0 overflow-hidden rounded-full border border-border bg-surface-hover`,children:c(ve,{mediaId:e.coverMediaId,base64:e.coverBase64,alt:e.name,className:`h-full w-full object-cover`,placeholder:c(`div`,{className:`flex h-full w-full items-center justify-center`,children:c(_e,{className:`h-4 w-4 text-foreground-subtle`})})})}),c(`div`,{className:`flex flex-1 min-w-0 items-center gap-2`,children:d?r(a,{children:[c(B,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&k(),e.key===`Escape`&&D()},className:`h-6 text-xs`,autoFocus:!0}),c(`button`,{type:`button`,onClick:k,disabled:C.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:c(H,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:D,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:c(Y,{className:`h-3.5 w-3.5`})})]}):c(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),c(te,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!d&&r(`div`,{className:`flex items-center gap-1`,children:[c(`button`,{type:`button`,onClick:T,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:c(re,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:()=>v(!0),className:`p-1 rounded hover:bg-danger/10 text-foreground-subtle hover:text-danger`,"aria-label":`Delete`,children:c(h,{className:`h-3.5 w-3.5`})})]}),c(`button`,{type:`button`,onClick:n,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":t?`Collapse`:`Expand`,children:c(t?p:m,{className:`h-3.5 w-3.5`})})]}),t&&c(`div`,{className:`border-t border-border px-3 pb-3 pt-2`,children:c(ut,{identityId:e.id})}),c(J,{open:g,onOpenChange:e=>!e&&v(!1),children:r(b,{children:[r(S,{children:[c(x,{children:`Delete person`}),r(q,{children:[`Delete `,c(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(N,{children:[c(E,{variant:`secondary`,onClick:()=>v(!1),children:`Cancel`}),r(E,{variant:`danger`,onClick:A,disabled:w.isPending,children:[w.isPending?c(_,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ft(){let e=o(),[t,n]=s(``),i=M();function a(){let r=t.trim();r&&i.mutate({name:r},{onSettled:()=>{e.invalidateQueries({queryKey:lt}),n(``)}})}return r(`div`,{className:`flex items-center gap-2 pt-2`,children:[c(B,{placeholder:`New person name…`,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()},className:`h-7 text-xs flex-1`}),r(E,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?c(_,{className:`h-3.5 w-3.5 animate-spin`}):c(V,{className:`h-3.5 w-3.5`}),`Add`]})]})}function pt(){let{data:e,isLoading:t}=T(),[n,i]=s(null),[a,o]=s(!1);function l(e){i(t=>t===e?null:e)}return t?r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(_,{className:`h-4 w-4 animate-spin`}),`Loading people…`]}):r(`div`,{className:`space-y-2`,children:[(!e||e.length===0)&&c(`p`,{className:`py-2 text-xs text-foreground-subtle`,children:`No people enrolled yet. Add one below.`}),e?.map(e=>c(dt,{identity:e,expanded:n===e.id,onToggle:()=>l(e.id)},e.id)),c(ft,{}),c(`div`,{className:`pt-1`,children:r(E,{variant:`secondary`,size:`sm`,onClick:()=>o(!0),children:[c(Ee,{className:`h-3.5 w-3.5`}),`Enrol from a photo`]})}),c(ct,{open:a,onOpenChange:o})]})}function mt(e){let t=e.cropUrl!==void 0&&e.cropUrl.length>0,n=e.base64!==void 0&&e.base64.length>0;return!t&&!n}function ht(e){return e.filter(mt).map(e=>e.faceId)}function gt(e){let t=0;for(let n of e)mt(n)&&(t+=1);return t}function _t(e){return e==null?null:e.cropUrl!==void 0&&e.cropUrl.length>0?e.cropUrl:e.base64!==void 0&&e.base64.length>0?`data:image/jpeg;base64,${e.base64}`:null}n();var vt=[[`faceGallery`]];function yt({faceIds:e,identities:t,onDone:n}){let i=o(),a=k(),l=M(),[u,d]=s(``),[f,p]=s(!1),[m,h]=s(null),g=e!==null&&e.length>0,v=e?.length??0;function y(){p(!1),d(``),h(null)}function C(){y(),n()}function w(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:vt}),C()}})}function T(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&w(e.id)},onError:()=>{i.invalidateQueries({queryKey:vt}),C()}})}let D=a.isPending||l.isPending;return c(J,{open:g,onOpenChange:e=>!e&&C(),children:r(b,{children:[r(S,{children:[c(x,{children:v>1?`Assign ${String(v)} faces to person`:`Assign face to person`}),c(q,{children:`Select an existing person or create a new one.`})]}),c(`div`,{className:`space-y-1 max-h-56 overflow-y-auto`,children:t.map(e=>r(`button`,{type:`button`,onClick:()=>h(e.id),className:`w-full rounded-md px-3 py-2 text-left text-xs transition-colors ${m===e.id?`bg-primary/12 text-primary`:`hover:bg-surface-hover text-foreground`}`,children:[c(`span`,{className:`font-medium`,children:e.name}),r(`span`,{className:`ml-2 text-foreground-subtle`,children:[e.sampleCount,` samples`]})]},e.id))}),f?c(`div`,{className:`flex items-center gap-2 pt-2 border-t border-border`,children:c(B,{placeholder:`New person name…`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T()},autoFocus:!0,className:`flex-1`})}):c(`button`,{type:`button`,onClick:()=>{h(null),p(!0)},className:`mt-2 w-full rounded-md border border-dashed border-border px-3 py-2 text-left text-xs text-foreground-subtle hover:border-primary hover:text-primary transition-colors`,children:`+ New person…`}),r(N,{children:[c(E,{variant:`secondary`,onClick:C,disabled:D,children:`Cancel`}),f?r(E,{variant:`primary`,onClick:T,disabled:D||!u.trim(),children:[D&&c(_,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(E,{variant:`primary`,onClick:()=>m&&w(m),disabled:D||!m,children:[D&&c(_,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,v>1?` ${String(v)}`:``]})]})]})})}n();function bt(e){let[t,n]=s(null),[r,i]=s(null),[a,o]=s(!1);return l(()=>{if(n(null),i(null),o(!1),e===void 0)return;let t=!1,r=null;return(async()=>{try{let i=await we(Te(e));if(t)return;r=URL.createObjectURL(i),n(r)}catch{t||o(!0)}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),l(()=>{if(!t)return;let e=new Image;return e.onload=()=>i({width:e.naturalWidth,height:e.naturalHeight}),e.onerror=()=>o(!0),e.src=t,()=>{e.onload=null,e.onerror=null}},[t]),{frameSrc:t,naturalWidth:r?.width??null,naturalHeight:r?.height??null,failed:a}}function xt(e){let t=e.filter(e=>e.url.length>0);return t.length===0?null:t.find(e=>/crop|face/i.test(e.kind))??t[0]}function St({label:e,value:t}){return r(`div`,{className:`flex items-baseline justify-between gap-3 py-1.5 border-b border-border/60 last:border-0`,children:[c(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),c(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground`,children:t})]})}function Ct({box:e}){return c(`div`,{className:`pointer-events-none absolute rounded-[3px] border-2 border-primary shadow-[0_0_0_9999px_rgba(0,0,0,0.28)]`,style:{left:`${String(e.x*100)}%`,top:`${String(e.y*100)}%`,width:`${String(e.width*100)}%`,height:`${String(e.height*100)}%`},children:c(`span`,{className:`absolute -top-4 left-0 rounded bg-primary px-1 text-[9px] font-semibold uppercase tracking-wide text-white`,children:`Face`})})}function wt({face:e,cameraName:t,onClose:n,onAssign:a,onUnassign:o,onDelete:l,actionsPending:u}){let{data:d,isFetching:p}=I({faceId:e?.faceId??``},{enabled:e!==null}),[m,g]=s(`frame`),{frameSrc:y,naturalWidth:x,naturalHeight:S,failed:C}=bt(e?.keyFrameMediaId),w=i(()=>{let t=xt(d??[]);return t?t.url:_t(e)},[d,e]),T=i(()=>!e?.faceBbox||x===null||S===null?null:be(e.faceBbox,x,S),[e?.faceBbox,x,S]);if(e===null)return null;let D=e.keyFrameMediaId!==void 0&&!C,O=D&&m===`frame`,k=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return c(J,{open:!0,onOpenChange:e=>!e&&n(),children:r(b,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Face detail`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[r(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`min-w-0`,children:[c(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:`Face detail`}),c(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:t})]}),c(`button`,{type:`button`,onClick:n,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(Y,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[D&&r(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5 text-xs`,children:[r(`button`,{type:`button`,onClick:()=>g(`frame`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`frame`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(z,{className:`h-3.5 w-3.5`}),` Full frame`]}),r(`button`,{type:`button`,onClick:()=>g(`crop`),className:`flex flex-1 items-center justify-center gap-1 rounded px-2 py-1 transition-colors ${m===`crop`?`bg-primary/12 font-medium text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(ae,{className:`h-3.5 w-3.5`}),` Crop`]})]}),O&&y?c(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:c(X,{src:y,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:T?c(Ct,{box:T}):void 0})}):w?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[c(X,{src:w,alt:`Detected face`,className:`h-full w-full`}),p&&c(`div`,{className:`absolute right-2 top-2 rounded-full bg-black/50 p-1 text-white`,children:c(_,{className:`h-3.5 w-3.5 animate-spin`})})]}):r(`div`,{className:`flex aspect-square w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-warning/5 text-foreground-subtle`,children:[c(f,{className:`h-8 w-8 text-warning/70`}),c(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-warning/80`,children:`No image`}),c(`span`,{className:`px-6 text-center text-[10px] text-foreground-subtle`,children:`The crop media for this face could not be resolved (a pre-fix orphan). Safe to delete.`})]}),r(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[c(St,{label:`Camera`,value:t}),c(St,{label:`Captured`,value:Z(e.timestamp)}),c(St,{label:`Track`,value:e.trackId}),c(St,{label:`Identity`,value:k})]})]}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[e.assigned?r(E,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:u,children:[c(ye,{className:`h-3.5 w-3.5`}),` Detach`]}):r(E,{variant:`primary`,onClick:()=>a(e.faceId),disabled:u,children:[c(v,{className:`h-3.5 w-3.5`}),` Assign`]}),r(E,{variant:`secondary`,onClick:()=>l(e.faceId),disabled:u,children:[c(h,{className:`h-3.5 w-3.5`}),` Delete`]})]})]})})}function Tt(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function Et(e,t){return e.faceIds.filter(e=>!t.has(e))}function Dt(e,t){return e.faceIds.filter(e=>t(e))}n();var Ot=[[`faceGallery`]],kt=20,At=.3,jt=.9,Mt=.05,Nt=.5,Pt=2,Ft=10,It=2;function Lt({cluster:e,face:t,active:n,onSelect:i}){let a=_t(t);return r(`button`,{type:`button`,onClick:i,className:`flex shrink-0 flex-col items-center gap-1.5 rounded-md border p-2 text-center transition-colors md:w-full md:flex-row md:gap-2.5 md:text-left ${n?`border-primary bg-primary/8`:`border-border bg-surface hover:bg-surface-hover`}`,children:[c(`div`,{className:`h-24 w-24 shrink-0 overflow-hidden rounded bg-surface-hover`,children:a===null?c(f,{className:`h-24 w-24 p-6 text-foreground-subtle`}):c(`img`,{src:a,alt:``,loading:`lazy`,decoding:`async`,className:`h-24 w-24 object-cover`})}),r(`span`,{className:`w-24 text-[11px] leading-tight text-foreground-subtle md:w-auto`,children:[e.size,` faces · `,Math.round(e.cohesion*100),`% alike`]})]})}function Rt({face:e,cameraName:t,nowMs:n,excluded:i,onToggleExclude:a,onDelete:o,deletePending:s}){let l=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden transition-opacity ${i?`border-border opacity-40 grayscale`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[l===null?r(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,children:[c(f,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(X,{src:l,alt:`Face from ${t}`,className:`h-full w-full`}),c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),a()},className:`absolute right-1 top-1 z-10 rounded-full bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Include face`:`Exclude face`,title:i?`Include`:`Exclude`,children:c(i?A:Y,{className:`h-3.5 w-3.5`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:ce(e.timestamp,n)})]}),c(`div`,{className:`mt-1 flex items-center justify-end border-t border-border/60 px-1 py-0.5`,children:c(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:s,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:s?c(_,{className:`h-4 w-4 animate-spin`}):c(h,{className:`h-4 w-4`})})})]})}function zt({open:e,onClose:t,byId:n,cameraName:u,nowMs:d,identities:f,selectMany:p}){let m=o(),h=K(),g=ie(),[y,x]=s(Nt),[S,C]=s(It),[w,T]=s(null),[D,O]=s({}),[k,A]=s(null),{data:j,isFetching:M,refetch:N}=G({threshold:y,minClusterSize:S,limit:kt},{enabled:e}),P=j??[];l(()=>{O({})},[y,S]),l(()=>{if(P.length===0){T(null);return}P.some(e=>e.representativeFaceId===w)||T(P[0]?.representativeFaceId??null)},[P]);let I=i(()=>P.find(e=>e.representativeFaceId===w)??null,[P,w]),L=I?D[I.representativeFaceId]??new Set:new Set,R=i(()=>I?Dt(I,e=>n.has(e)):[],[I,n]),z=I?I.faceIds.length-R.length:0,B=I?Et({...I,faceIds:R},L):[];function V(e){if(!I)return;let t=I.representativeFaceId;O(n=>({...n,[t]:Tt(n[t]??new Set,e)}))}function H(){m.invalidateQueries({queryKey:Ot})}async function U(e){await h({title:`Delete face`,message:`Permanently deletes this face crop. This cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&g.mutate({faceId:e},{onSettled:H})}function W(){A(null),t()}function ee(){B.length!==0&&(p(B),W())}return r(J,{open:e,onOpenChange:e=>!e&&W(),children:[r(b,{placement:`sheet-on-mobile`,width:`lg`,"aria-label":`Look-alike groups`,className:`flex max-h-[92dvh] flex-col gap-0 overflow-hidden p-0 md:max-w-4xl`,children:[r(`header`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3`,children:[r(`div`,{className:`flex items-center justify-between gap-2`,children:[r(`div`,{className:`flex items-center gap-1.5 text-sm font-semibold text-foreground`,children:[c(F,{className:`h-4 w-4 text-primary`}),` Look-alike groups`]}),c(`button`,{type:`button`,onClick:W,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:c(Y,{className:`h-4 w-4`})})]}),r(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Threshold`,c(`input`,{type:`range`,min:At,max:jt,step:Mt,value:y,onChange:e=>x(Number(e.target.value)),className:`h-1.5 w-28 cursor-pointer accent-primary`}),c(`span`,{className:`w-8 shrink-0 text-right font-mono text-[11px] tabular-nums text-foreground`,children:y.toFixed(2)})]}),r(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Min size`,c(`input`,{type:`number`,min:Pt,max:Ft,step:1,value:S,onChange:e=>C(Math.min(Ft,Math.max(Pt,Number(e.target.value)||Pt))),className:`w-12 rounded border border-border bg-background px-1.5 py-0.5 text-xs text-foreground`})]}),r(E,{variant:`secondary`,onClick:()=>{O({}),N()},disabled:M,children:[M?c(_,{className:`h-3.5 w-3.5 animate-spin`}):c(ne,{className:`h-3.5 w-3.5`}),`Re-analyze`]})]})]}),c(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden px-4 py-3 md:flex-row`,children:M&&P.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(_,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):P.length===0?c(`div`,{className:`flex flex-1 items-center justify-center py-8 text-xs text-foreground-subtle`,children:`No look-alike groups at this threshold.`}):r(a,{children:[c(`div`,{className:`flex gap-2 overflow-x-auto pb-1 md:hidden`,children:P.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===w,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:P.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===w,onSelect:()=>T(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:I&&r(a,{children:[z>0&&r(`p`,{className:`mb-2 text-[11px] text-foreground-subtle`,children:[z,` not loaded — excluded from actions`]}),c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-2`,children:R.map(e=>{let t=n.get(e);return t?c(Rt,{face:t,cameraName:u(t.deviceId),nowMs:d,excluded:L.has(e),onToggleExclude:()=>V(e),onDelete:()=>void U(e),deletePending:g.isPending&&g.variables?.faceId===e},e):null})})]})})]})}),r(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:[c(E,{variant:`secondary`,onClick:ee,disabled:B.length===0,children:`Select in gallery`}),r(E,{variant:`primary`,onClick:()=>A(B),disabled:B.length===0,children:[c(v,{className:`h-3.5 w-3.5`}),` Adopt (`,B.length,`)`]})]})]}),c(yt,{faceIds:k,identities:f,onDone:()=>A(null)})]})}n();var Bt=[[`faceGallery`]],Vt=500,Ht=120;function Ut({face:e,cameraName:t,nowMs:n,selected:i,onToggleSelect:a,onAssign:s,onOpenDetail:l}){let u=o(),p=D(),m=ie(),g=()=>{u.invalidateQueries({queryKey:Bt})},y=()=>l(e.faceId),b=_t(e);return r(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[r(`div`,{className:`aspect-square relative overflow-hidden bg-surface-hover`,children:[b===null?r(`button`,{type:`button`,onClick:y,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-warning/5 text-foreground-subtle`,title:`No crop image — the face's crop media is missing (a pre-fix orphan). Safe to delete.`,children:[c(f,{className:`h-7 w-7 text-warning/70`}),c(`span`,{className:`text-[9px] font-medium uppercase tracking-wide text-warning/80`,children:`No crop`})]}):c(`img`,{src:b,alt:`Face from ${t}`,onClick:y,loading:`lazy`,decoding:`async`,className:`h-full w-full cursor-zoom-in object-cover`}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(e.faceId)},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?c(de,{className:`h-4 w-4 text-primary`}):c(d,{className:`h-4 w-4`})})]}),r(`div`,{className:`min-w-0 px-2 pt-1.5 space-y-0.5`,children:[c(`p`,{className:`text-[10px] font-medium text-foreground truncate`,title:t,children:t}),c(`p`,{className:`text-[10px] text-foreground-subtle truncate`,children:ce(e.timestamp,n)}),e.identityName&&c(`p`,{className:`text-[10px] font-medium text-primary truncate`,title:e.identityName,children:e.identityName})]}),r(`div`,{className:`mt-1 flex items-center gap-0.5 border-t border-border/60 px-1 py-0.5`,children:[e.assigned?c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),p.mutate({faceId:e.faceId},{onSettled:g})},disabled:p.isPending,className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-warning/10 hover:text-warning disabled:opacity-40`,"aria-label":`Detach face`,title:`Detach`,children:p.isPending?c(_,{className:`h-4 w-4 animate-spin`}):c(ye,{className:`h-4 w-4`})}):c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.faceId)},className:`rounded p-1.5 text-foreground-subtle transition-colors hover:bg-primary/10 hover:text-primary`,"aria-label":`Assign face to person`,title:`Assign to person`,children:c(v,{className:`h-4 w-4`})}),c(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),m.mutate({faceId:e.faceId},{onSettled:g})},disabled:m.isPending,className:`ml-auto rounded p-1.5 text-foreground-subtle transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40`,"aria-label":`Delete face`,title:`Delete face`,children:m.isPending?c(_,{className:`h-4 w-4 animate-spin`}):c(h,{className:`h-4 w-4`})})]})]})}var Wt=[{label:`All`,value:`all`},{label:`Unassigned`,value:`unassigned`},{label:`Recognized`,value:`recognized`}];function Gt(){let e=o(),[t,n]=s(`all`),[l,u]=s(me),[d,p]=s(new Set),[m,g]=s(new Set),[y,b]=s(null),[x,S]=s(!1),[C,w]=s(null),{data:O,isLoading:A}=L({limit:Vt,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:j=[]}=T(),{data:M}=ee({isCamera:!0,projection:`slim`}),N=k(),P=D(),I=R(),z=ie(),B=Date.now(),V=O??[],H=i(()=>{let e=new Map;for(let t of M??[])e.set(t.id,t.name);return e},[M]),U=e=>H.get(e)??`Camera #${String(e)}`,W=i(()=>se(V).map(e=>({id:e,name:U(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[V,H]),G=i(()=>ue(ge(V,l),d),[V,l,d]),K=fe(G,Ht,i(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),te=i(()=>new Map(V.map(e=>[e.faceId,e])),[V]),ne=i(()=>gt(G),[G]),re=C===null?null:te.get(C)??null,q=()=>{e.invalidateQueries({queryKey:Bt})},J=()=>g(new Set);function ae(e){g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function ce(e){g(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function de(){ce(ht(G))}let X=[...m],Z=N.isPending||I.isPending||z.isPending,he=P.isPending||z.isPending;function _e(){X.length!==0&&I.mutate({faceIds:X},{onSettled:()=>{q(),J()}})}function ve(){X.length!==0&&Promise.allSettled(X.map(e=>z.mutateAsync({faceId:e}))).then(()=>{q(),J()})}function be(e){w(null),b([e])}function xe(e){P.mutate({faceId:e},{onSettled:q}),w(null)}function Se(e){z.mutate({faceId:e},{onSettled:q}),w(null)}let Ce=G.length!==V.length;return r(`div`,{className:`relative space-y-3`,children:[r(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[c(`div`,{className:`flex items-center gap-1`,children:Wt.map(e=>c(`button`,{type:`button`,onClick:()=>n(e.value),className:`rounded-md px-2.5 py-1 text-xs transition-colors ${t===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e.label},e.value))}),c(pe,{onChange:u}),c(le,{cameras:W,selected:d,onChange:p}),r(`button`,{type:`button`,onClick:()=>S(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${x?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(F,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!A&&ne>0&&r(`button`,{type:`button`,onClick:de,className:`ml-auto flex items-center gap-1 rounded-md px-2.5 py-1 text-xs text-warning/90 transition-colors hover:bg-warning/10`,title:`Select every visible face whose crop image is missing so you can delete the orphans in one pass`,children:[c(f,{className:`h-3.5 w-3.5`}),` Select `,ne,` crop-less`]}),!A&&c(`span`,{className:`text-[10px] text-foreground-subtle ${ne>0?`ml-2`:`ml-auto`}`,children:Ce?`${String(G.length)} of ${String(V.length)} faces`:`${String(G.length)} face${G.length===1?``:`s`}`})]}),m.size>0&&r(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[r(`span`,{className:`text-xs font-medium text-foreground`,children:[m.size,` selected`]}),r(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[r(E,{variant:`primary`,onClick:()=>b(X),disabled:Z,children:[c(v,{className:`h-3.5 w-3.5`}),` Assign`]}),r(E,{variant:`secondary`,onClick:_e,disabled:Z,children:[I.isPending?c(_,{className:`h-3.5 w-3.5 animate-spin`}):c(ye,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(E,{variant:`secondary`,onClick:ve,disabled:Z,children:[c(h,{className:`h-3.5 w-3.5`}),` Delete`]}),c(E,{variant:`ghost`,onClick:J,disabled:Z,children:c(Y,{className:`h-3.5 w-3.5`})})]})]}),A&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(_,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!A&&G.length===0&&c(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:V.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!A&&G.length>0&&r(a,{children:[c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:K.pageItems.map(e=>c(Ut,{face:e,cameraName:U(e.deviceId),nowMs:B,selected:m.has(e.faceId),onToggleSelect:ae,onAssign:e=>b([e]),onOpenDetail:w},e.faceId))}),c(oe,{currentPage:K.page,totalItems:K.totalItems,pageSize:K.pageSize,onPageChange:K.setPage,itemNoun:`faces`})]}),c(wt,{face:re,cameraName:re?U(re.deviceId):``,onClose:()=>w(null),onAssign:be,onUnassign:xe,onDelete:Se,actionsPending:he}),c(yt,{faceIds:y,identities:j,onDone:()=>{b(null),J()}}),c(zt,{open:x,onClose:()=>S(!1),byId:te,cameraName:U,nowMs:B,identities:j,selectMany:ce})]})}n();var Kt=[[`faceGallery`]],qt=2e3;function Jt(){let e=o(),n=t(e);n.current=e;let r=t(void 0);r.current||=he({delayMs:qt,invalidate:()=>{n.current.invalidateQueries({queryKey:Kt})}}),l(()=>()=>r.current?.cancel(),[]),W(xe.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Yt(){return Jt(),c(Ce,{icon:Se,title:`Faces`,subtitle:`Manage enrolled identities and assign detected face crops to people.`,children:r(`section`,{className:`space-y-3`,children:[r(`div`,{children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`People`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Enrolled identities used for face recognition. Expand a row to view or remove training samples.`}),c(pt,{})]}),r(`div`,{className:`pt-4 border-t border-border`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Recent detected faces`}),c(`p`,{className:`text-xs text-foreground-subtle mb-3`,children:`Face crops captured by the detection pipeline. Assign them to a person to build recognition training data.`}),c(Gt,{})]})]})})}export{Yt as DetectionIntelligencePage};
|