@camstack/addon-admin-ui 1.2.349 → 1.2.350
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonCollectionPage-jXCbcMZu.js → AddonCollectionPage-D9Q3skZA.js} +1 -1
- package/dist/assets/Addons-Bxd8giTY.js +1 -0
- package/dist/assets/{AdminTabs-DcYKYXzK.js → AdminTabs-DbxtEjk6.js} +1 -1
- package/dist/assets/AiProfiles-D4ktKl5a.js +3 -0
- package/dist/assets/{BrokerForm-rRXdhvBg.js → BrokerForm-b2HG3A_I.js} +1 -1
- package/dist/assets/Build-D9tNwFp7.js +40 -0
- package/dist/assets/{Calendars-BhTVLKHz.js → Calendars-DPpRjVVr.js} +1 -1
- package/dist/assets/{Capabilities-CvhnCl7c.js → Capabilities-0tfKqmQA.js} +1 -1
- package/dist/assets/Cluster-BQanBpWv.js +11 -0
- package/dist/assets/ClusterStepModel-Di3RCHbu.js +1 -0
- package/dist/assets/{CompositionEditor-gkHb7ZT2.js → CompositionEditor-8xtSUeri.js} +1 -1
- package/dist/assets/{CompositionEditorPage-UrJerX9A.js → CompositionEditorPage-boKGo8GQ.js} +1 -1
- package/dist/assets/Data-DMpZGfrn.js +1 -0
- package/dist/assets/DetectionIntelligence-DAgaEMGO.js +1 -0
- package/dist/assets/DeviceDetail-BSb1-TNN.js +2 -0
- package/dist/assets/{DeviceDoActionFields-Qp-mdQoy.js → DeviceDoActionFields-BfmISfgz.js} +1 -1
- package/dist/assets/{Devices-D0X5ZMil.js → Devices-Hx32f7xo.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-BCohm6GU.js → EmbedPlayerPage-CocO1BTn.js} +1 -1
- package/dist/assets/Events-BkTP2omD.js +1 -0
- package/dist/assets/Identity-CWRUDt5i.js +1 -0
- package/dist/assets/IntegrationDetail-BKzLD-QT.js +1 -0
- package/dist/assets/Integrations-BeENEzwD.js +1 -0
- package/dist/assets/Integrations-CDvy6QgO.js +1 -0
- package/dist/assets/Locations-DRody3E5.js +3 -0
- package/dist/assets/{Logs-4q8jFD5i.js → Logs-CBhyoglF.js} +1 -1
- package/dist/assets/{MotionZonesSettings-M2UAaOLw.js → MotionZonesSettings-TfnZ4ZPN.js} +1 -1
- package/dist/assets/{MyAccess-Brzl2xif.js → MyAccess-BGXlB9No.js} +1 -1
- package/dist/assets/Network-DCoLk82s.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-DzIjWuOo.js +1 -0
- package/dist/assets/Notifications-BmXW8_iS.js +1 -0
- package/dist/assets/Plates-DTq6QrGW.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-8lVg2P1M.js → PrivacyMaskSettings-Ha-Zqjj7.js} +1 -1
- package/dist/assets/Recordings-BtqzNlHC.js +1 -0
- package/dist/assets/{ScanNetworkModal-B59h5xvq.js → ScanNetworkModal-Bu7C4PSL.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-B1E8n6ou.js → SceneMonitorEditor-breuTs7j.js} +1 -1
- package/dist/assets/{Scenes-CR29v0gZ.js → Scenes-DkIfQKai.js} +1 -1
- package/dist/assets/{Settings-BvzufFl5.js → Settings-DPHIIOeT.js} +1 -1
- package/dist/assets/{Showroom-BnjdRdKN.js → Showroom-CvSria_z.js} +1 -1
- package/dist/assets/{Terminal-aUzk1uKX.js → Terminal-DvihlsfY.js} +5 -5
- package/dist/assets/{Viewer-M6qlWxs9.js → Viewer-DAm-N3A9.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BsOXjLIp.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B1L1rmsf.js} +1 -1
- package/dist/assets/{archive-D-Y4i_R_.js → archive-QWpDQvmy.js} +1 -1
- package/dist/assets/{authed-media-_X4FXSBp.js → authed-media-CvliDudL.js} +1 -1
- package/dist/assets/{boxes-DXM8dtQJ.js → boxes-ghM9MyNI.js} +1 -1
- package/dist/assets/circle-slash-BY9azzp9.js +1 -0
- package/dist/assets/client-D2T6hnwJ.js +357 -0
- package/dist/assets/crop-eTEKuG4V.js +1 -0
- package/dist/assets/debounced-invalidate-Brd-xEUl.js +1 -0
- package/dist/assets/{device-integration-icon-BXFJAjbm.js → device-integration-icon-BxxUQkzA.js} +1 -1
- package/dist/assets/device-picker-model-Er0KXZFo.js +1 -0
- package/dist/assets/{dist-BoA-02Ta.js → dist-BkWWqFzL.js} +1 -1
- package/dist/assets/dist-CWyZkxmr.js +357 -0
- package/dist/assets/face-bbox-BtWjVAUr.js +1 -0
- package/dist/assets/{hard-drive-download-DI78Qxnu.js → hard-drive-download-BNwv1QZy.js} +1 -1
- package/dist/assets/{hostInit-CjZNBAf2.js → hostInit-DeFZcRbl.js} +1 -1
- package/dist/assets/index-CFu9bpWo.css +2 -0
- package/dist/assets/index-CTLsm4or.js +4 -0
- package/dist/assets/{layers-BYuVbzVs.js → layers-Cqi6DnJp.js} +1 -1
- package/dist/assets/{location-owned-usage-Bj5-khSs.js → location-owned-usage-nUG-wNCP.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-ea91eb80.js → mf-entry-bootstrap-0-f3da6c45.js} +2 -2
- package/dist/assets/mount-Er0KXZFo.js +1 -0
- package/dist/assets/notification-schedule-field-OWvLlCoa.js +1 -0
- package/dist/assets/{player-overlays-BddRivLE.js → player-overlays-BHccEyE0.js} +1 -1
- package/dist/assets/remoteEntry-BFQE9dZb.js +1 -0
- package/dist/assets/{send-CyJGX9-U.js → send-JCuF4gJW.js} +1 -1
- package/dist/assets/{settings-2-BOGh_wO6.js → settings-2-x7GDFxSP.js} +1 -1
- package/dist/assets/src-DgWGoEDF.js +67 -0
- package/dist/assets/{use-scenes-feed-B4UtvXrE.js → use-scenes-feed-B7UdAzGO.js} +1 -1
- package/dist/assets/{use-stationary-objects-QRm4Gn4u.js → use-stationary-objects-BnA_XGaA.js} +1 -1
- package/dist/assets/useEventInvalidation-Er0KXZFo.js +1 -0
- package/dist/assets/{useNodeUrlSelection-BDv33pGy.js → useNodeUrlSelection-uZUf1p_p.js} +1 -1
- package/dist/assets/user-round-Ck3MDNjX.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C2YrzRgM.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DWDVV7Rx.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/addon.js +35 -327
- package/package.json +1 -1
- package/dist/assets/Addons-rr7aue1z.js +0 -1
- package/dist/assets/AiProfiles-CxBtibtD.js +0 -3
- package/dist/assets/Build-Tu52RNi0.js +0 -40
- package/dist/assets/Cluster-Bq5YAagB.js +0 -11
- package/dist/assets/ClusterStepModel-BXuKvfKQ.js +0 -1
- package/dist/assets/Data-CRMaoAvA.js +0 -1
- package/dist/assets/DetectionIntelligence-hpln0NzF.js +0 -1
- package/dist/assets/DeviceDetail-DA9kIkj-.js +0 -2
- package/dist/assets/Events-DJqXUhGE.js +0 -1
- package/dist/assets/Identity-CMHAJE1i.js +0 -1
- package/dist/assets/IntegrationDetail-D6CPV8I0.js +0 -1
- package/dist/assets/Integrations-C3v7m_pV.js +0 -1
- package/dist/assets/Integrations-CrSI1y99.js +0 -1
- package/dist/assets/Locations-BXxpBY8V.js +0 -3
- package/dist/assets/Network-UpHA2zPn.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-D7Ope1My.js +0 -1
- package/dist/assets/Notifications-3jCEMiJT.js +0 -1
- package/dist/assets/Plates-DnKm0uO5.js +0 -1
- package/dist/assets/Recordings-C8Dz8QdA.js +0 -1
- package/dist/assets/circle-slash-Bh6ndID4.js +0 -1
- package/dist/assets/client-BVesZTvN.js +0 -357
- package/dist/assets/debounced-invalidate-On21l1Xj.js +0 -1
- package/dist/assets/device-picker-model-Br0xkUVQ.js +0 -1
- package/dist/assets/dist-CXTK9bJc.js +0 -357
- package/dist/assets/face-bbox-3mjLW0O1.js +0 -1
- package/dist/assets/index-DP2qgRL_.css +0 -2
- package/dist/assets/index-NHwA6Zmb.js +0 -4
- package/dist/assets/mount-Br0xkUVQ.js +0 -1
- package/dist/assets/notification-schedule-field-Bho2AfCu.js +0 -1
- package/dist/assets/remoteEntry-CJLM9B1W.js +0 -1
- package/dist/assets/square-check-big-CpCHNAfP.js +0 -1
- package/dist/assets/src-DnQxdAYg.js +0 -67
- package/dist/assets/useEventInvalidation-Br0xkUVQ.js +0 -1
- package/dist/assets/user-round-1jRRPQok.js +0 -1
|
@@ -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,T as a,W as o,b as s,i as c,o as l,p as u,q as d,x as f,z as p}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 m,B as h,D as g,E as _,M as v,O as y,R as b,T as x,at as S,ct as C,gt as w,ht as T,k as E,st as D,ut as O,vt as k}from"./player-overlays-BddRivLE.js";import{Bd as A,Bl as j,Bn as M,Bs as N,C as P,Cd as F,Cn as I,Cs as L,Ct as R,Ds as ee,E as te,En as z,F as ne,Fs as re,Gl as B,Gs as ie,H as ae,Hl as oe,Hs as se,Is as ce,Js as V,Kl as le,Ks as ue,Lu as de,M as fe,Mn as pe,Ms as me,O as he,Ps as ge,Qn as _e,Rn as ve,Rs as ye,Rt as be,Ru as xe,S as Se,Sn as Ce,Ss as we,T as Te,Tn as Ee,Ud as De,Ul as Oe,Us as ke,V as Ae,Vl as je,Vn as H,Wl as Me,Ws as Ne,Xl as Pe,Zu as Fe,_n as Ie,_s as Le,ac as Re,an as ze,bs as Be,cc as Ve,cn as He,dn as Ue,en as We,eu as Ge,ff as Ke,fn as qe,gn as Je,gr as U,gs as Ye,gt as Xe,gu as Ze,hd as Qe,hn as $e,hr as et,ic as tt,in as nt,js as rt,kd as W,kt as it,ku as at,ln as ot,mn as st,nc as ct,nd as lt,oc as ut,od as dt,on as ft,or as G,pn as pt,qs as mt,r as ht,rc as gt,rd as _t,sn as vt,su as yt,tc as bt,td as xt,un as St,vd as Ct,vn as wt,vs as Tt,w as Et,ws as Dt,xn as Ot,xs as kt,yn as At,yr as jt,ys as Mt,zl as K,zn as Nt,zs as Pt}from"./src-DnQxdAYg.js";import{t as Ft}from"./layers-BYuVbzVs.js";import{t as It}from"./square-check-big-CpCHNAfP.js";import{n as Lt}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{Cn as Rt,Dn as zt,En as Bt,Mr as Vt,Sn as Ht,Tn as Ut,f as Wt,jr as Gt,ni as Kt,ti as qt,wn as Jt,xn as Yt}from"./client-BVesZTvN.js";import{B as Xt,E as Zt,F as Qt,M as $t}from"./index-NHwA6Zmb.js";import"./useEventInvalidation-Br0xkUVQ.js";import{t as en}from"./NodeAddonsSettingsPanel-D7Ope1My.js";var tn=k(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),nn=k(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),rn=k(`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`}]]),an=k(`scale`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`m19 8 3 8a5 5 0 0 1-6 0zV7`,key:`zcdpyk`}],[`path`,{d:`M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1`,key:`1yorad`}],[`path`,{d:`m5 8 3 8a5 5 0 0 1-6 0zV7`,key:`eua70x`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}]]),on=k(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]),sn=`step`,cn=[sn,`acc`];function ln(e,t){return`${e}/${t}`}function un(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:t[0]??null,staleStepId:n.step!==null&&n.step!==``&&!r&&e.length>0?n.step:null}}function dn(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 fn(e){return e}function pn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function mn(e,t){return typeof e==`boolean`?e:fn(t)}function hn(e,t){return{pipeline:mn(pn(e,`detect`),t),audio:mn(pn(e,`audio`),t),ingest:mn(pn(e,`ingest`),t)}}function gn(e,t,n){let r=e?.find(e=>e.nodeId===t);return hn(r?.settings,n)}function _n({selectedNodeId:e,onSelect:t,refreshToken:n}){let{nodes:r}=j(),{data:a}=ge(void 0),{data:o}=ye(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,d=l.filter(e=>!e.isOnline).length;return i(`div`,{className:`flex flex-col h-full`,children:[i(`button`,{type:`button`,onClick:()=>t(no),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:[f(Xt,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[f(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),f(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Assignments, load balancing, roles`})]})]}),f(`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?at:W,u=gn(o,n.id,n.isHub),d=n.isOnline?null:Xe(dn(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:[f(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:[f(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&f(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&f(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&f(`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`]}),f(`span`,{children:`•`}),i(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&i(s,{children:[f(`span`,{children:`•`}),i(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[f(Ge,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&i(s,{children:[f(`span`,{children:`•`}),i(`span`,{className:`text-destructive`,children:[`offline`,d===null?``:` · ${d}`]})]})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[f(G,{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`}),f(G,{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`]}),d>0&&i(`span`,{className:`text-destructive`,children:[d,` offline`]})]})]})}function vn({nodeId:e,refreshToken:t}){let{nodes:n}=j(),r=n?.find(t=>t.id===e),a=je(`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:[f(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?f(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):f(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&f(`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:[f(`span`,{children:r.cpuModel??`CPU`}),f(`span`,{children:`•`}),i(`span`,{children:[r.cpuCores,` cores`]}),f(`span`,{children:`•`}),i(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&i(s,{children:[f(`span`,{children:`•`}),i(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),f(`span`,{children:`•`}),i(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),f(`span`,{children:`•`}),i(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&i(s,{children:[f(`span`,{children:`•`}),f(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):f(`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 yn=[`assignments`,`tree`,`engines`,`logs`];r();function bn({refreshToken:e,nodeId:t}){let[n,r]=d(new Map),{nodes:a}=K();Oe(`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}=Dt(void 0),c=o(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=o(()=>{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]),u=o(()=>{let e=new Map;for(let t of a)e.set(t.id,t.shortName);return e},[a]),p=o(()=>{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 o=e>0?r/e:0;return{totalAgents:a.length,onlineAgents:a.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:i,totalFps:n}},[l,a]);if(t){let e=l.get(t);return i(`div`,{className:`@container/liveload`,children:[f(`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:[f(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),f(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),f(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),f(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),f(q,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return i(`div`,{className:`@container/liveload`,children:[f(`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:[f(q,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),f(q,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),f(q,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),f(q,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),f(q,{label:`Queue depth`,value:String(p.queueDepth)})]}),f(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[480px]`,children:[f(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[f(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),f(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),f(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),f(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),f(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),f(`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:[f(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:u.get(e)??e}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&f(`tr`,{children:f(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[f(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),f(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}function xn(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 Sn(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 Cn(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}r();function wn(e,t,n){return Math.min(Math.max(e,t),n)}function Tn(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 En(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:wn(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 Dn(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 On({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:a,footnote:o,readOnly:c=!1}){let[l,u]=d(()=>Tn(e)),[m,h]=d(new Set);p(()=>{u(Tn(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)=>{u(n=>En(n,e,t,m,g))},y=()=>{let t=Dn(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 f(`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:[f(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),f(`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&&f(`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:f(a?xt:lt,{className:`h-3.5 w-3.5`})})]},e.id)}),f(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:o??f(s,{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 kn(e){let t=Ee(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:W,hue:`slate`}:r===`npu`?{label:t,Icon:B,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:tn,hue:`violet`}:n===`edgetpu`?{label:t,Icon:on,hue:`emerald`}:{label:t,Icon:W,hue:`slate`}}var An={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 jn({nodeId:e,nodeName:t,isOnline:n,suggestedMaxSessions:r,autoDeviceShares:a}){let c=l(),{data:u,isLoading:m}=me({nodeId:e},{refetchInterval:15e3}),h=ue({onSettled:()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),g=u?.devices??[],_=u?.reachable??n,[v,y]=d({});p(()=>{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=o(()=>g.filter(e=>v[e.key]?.enabled??e.enabled).length,[g,v]),[x,S]=d(null),C=x??b>0,w=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:Cn(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),w(n)},O=(e,t)=>{let n=v[e.key]??E(e),r={...v,[e.key]:{...n,maxSessions:t}};y(r),w(r)},k=o(()=>g.filter(e=>(v[e.key]?.enabled??e.enabled)&&e.available),[g,v]),A=o(()=>k.map(e=>({id:e.key,name:kn(e).label,weight:a===void 0?v[e.key]?.weight??e.weight:Math.round(a[e.key]??0)})),[k,v,a]);return i(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[i(`button`,{type:`button`,onClick:()=>S(!C),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":C,children:[f(T,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${C?`rotate-90`:``}`}),f(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),f(`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:[f(Ft,{className:`h-3.5 w-3.5`}),b,` accelerators`]}):b===1?f(`span`,{className:`text-foreground-subtle`,children:`single default`}):f(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):i(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[f(Pe,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),C&&i(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[_?m&&g.length===0?f(`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?f(`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.`}):f(`ul`,{className:`space-y-2`,children:g.map(e=>{let t=kn(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:[f(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${An[t.hue]}`,children:f(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:[f(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),f(G,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&f(G,{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:[f(`span`,{className:`font-mono`,children:e.key}),!a&&i(s,{children:[f(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:[`default model`,` `,f(`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:[f(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),f(`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&&f(Mn,{suggested:r?.[e.key]??null,current:n.maxSessions,pending:h.isPending,onApply:t=>O(e,t)}),f(Ue,{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)})}):f(Nn,{}),_&&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:[f(an,{className:`h-3.5 w-3.5`}),`Accelerator share`]}),f(On,{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),w(t)},weightLabel:`Accelerator share`,readOnly:a!==void 0,footnote:a===void 0?f(s,{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%.`}):f(s,{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 Mn({suggested:e,current:t,pending:n,onApply:r}){return e===null||e<1||e===t?null:i(H,{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 Nn(){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:[f(Pe,{className:`h-6 w-6 text-foreground-subtle/60`}),f(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),f(`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 Pn={active:!1,pinned:!1,nodeId:null,reason:``},Fn=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],In=3e5,Ln={pipeline:W,decoder:Ct,audio:O},Rn={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function zn({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=l(),[c,u]=d(null),[m,h]=d(null),[g,_]=d(new Map);ht([`pipelineOrchestrator`,`getPipelineAssignments`],Fn),ht([`pipelineOrchestrator`,`getAudioAssignments`],Fn),ht([`pipelineOrchestrator`,`getCameraStatuses`],Fn);let{data:v}=ge(void 0),{data:y}=L(void 0),{data:b}=ee({},{enabled:e===`agent`}),{nodes:x}=K(),{data:S}=Zt();Oe(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&_(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),p(()=>{if(g.size===0)return;let e=setInterval(()=>{_(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[g.size]);let C=o(()=>{let e=new Map;for(let t of S??[])e.set(t.id,t.name);return e},[S]),E=o(()=>{if(e===`agent`){let e=[];for(let n of b??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:C.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:C.get(e)??`Device ${e}`,pipeline:Pn,decoder:Pn,audio:Pn};return n.set(e,r),r};for(let i of v??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of y??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[v,y,b,C,e,t]),D=o(()=>(x??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[x]),O=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},k=kt({onSuccess:O}),A=ut({onSuccess:O}),j=Be({onSuccess:O}),M=Re({onSuccess:O}),N=(e,t,n)=>{t===`pipeline`?k.mutate({deviceId:e,agentNodeId:n}):j.mutate({deviceId:e,nodeId:n}),u(null)},P=(e,t)=>{t===`pipeline`?A.mutate({deviceId:e}):M.mutate({deviceId:e}),u(null)};return f(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[f(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&f(`th`,{className:`w-10`}),f(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?i(s,{children:[f(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),f(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):i(s,{children:[f(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),f(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),f(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),f(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),i(`tbody`,{children:[E.map(t=>{let r=g.get(t.deviceId),o=m===t.deviceId;return i(a.Fragment,{children:[i(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&f(`td`,{className:`px-2 py-2 align-middle`,children:f(`button`,{type:`button`,onClick:()=>h(o?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":o?`Collapse broker details`:`Expand broker details`,children:f(o?w:T,{className:`h-3.5 w-3.5`})})}),i(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[f(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?i(s,{children:[f(`td`,{className:`px-3 py-2 align-middle`,children:f(Vn,{state:t.pipeline,onlineNodes:D,pending:k.isPending||A.isPending,onChange:e=>{e===`auto`?P(t.deviceId,`pipeline`):N(t.deviceId,`pipeline`,e)}})}),f(`td`,{className:`px-3 py-2 align-middle`,children:f(Un,{state:t.pipeline,deviceId:t.deviceId})})]}):i(s,{children:[f(Gn,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:c?.deviceId===t.deviceId&&c.role===`pipeline`,onToggleMenu:()=>u(c?.deviceId===t.deviceId&&c.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>u(null),onMove:e=>N(t.deviceId,`pipeline`,e),onUnpin:()=>P(t.deviceId,`pipeline`)}),f(Gn,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:D,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),f(Gn,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:D,isMenuOpen:c?.deviceId===t.deviceId&&c.role===`audio`,onToggleMenu:()=>u(c?.deviceId===t.deviceId&&c.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>u(null),onMove:e=>N(t.deviceId,`audio`,e),onUnpin:()=>P(t.deviceId,`audio`)})]}),f(`td`,{className:`px-3 py-2 align-middle`,children:f(Yn,{snap:r})})]}),o&&!n&&i(`tr`,{className:`bg-surface/50`,children:[f(`td`,{}),i(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&f(Bn,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),f(pe,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),E.length===0&&f(`tr`,{children:f(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function Bn({deviceId:e,nodeId:t}){let n=l(),{data:r}=me({nodeId:t}),{data:a}=re({deviceId:e}),o=ct({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),s=r?.devices??[],c=a?.deviceKey??`auto`,u=c!==`auto`&&!s.some(e=>e.key===c);return i(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[f(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),i(`select`,{value:c,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[f(`option`,{value:`auto`,children:`Auto (balanced)`}),u&&i(`option`,{value:c,children:[`Pin → `,c,` (not on this node)`]}),s.map(e=>i(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),o.isPending&&f(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function Vn({state:e,onlineNodes:t,pending:n,onChange:r}){let a=e.pinned&&e.nodeId?e.nodeId:`auto`,o=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return i(`select`,{value:a,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[f(`option`,{value:`auto`,children:`Auto`}),o.map(e=>i(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function Hn(e){let t=n(null);return e.nodeId!==null&&(t.current=e),t.current}function Un({state:e,deviceId:t}){let n=Hn(e),r=e.active&&e.nodeId!==null;if(n===null||n.nodeId===null)return f(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`— · no session yet`});let a=n.pinned?`pinned · manual`:`auto · ${n.reason||`capacity`}`;return i(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[f(`span`,{className:`font-mono text-[11px] truncate ${r?`text-foreground`:`text-foreground-subtle`}`,title:n.pinned?n.nodeId:`${n.nodeId} — an unpinned camera is re-elected per on-motion session, so this can change between sessions`,children:n.nodeId}),f(`span`,{className:`truncate ${n.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:a,children:a}),f(`span`,{className:`truncate text-[10px] ${r?`text-emerald-400`:`text-foreground-subtle/70`}`,children:r?`● running here`:`○ idle · last session here`}),f(Wn,{deviceId:t,nodeId:n.nodeId})]})}function Wn({deviceId:e,nodeId:t}){let n=l(),{data:r}=re({deviceId:e},{refetchOnMount:`always`}),{data:a}=me({nodeId:t},{staleTime:In}),o=ct({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||a===void 0)return f(`span`,{className:`mt-0.5 text-[10px] text-foreground-subtle italic`,children:`device: …`});let s=a.devices??[],c=s.filter(e=>e.enabled),u=r.deviceKey??`auto`,d=u!==`auto`&&!c.some(e=>e.key===u),p=s.find(e=>e.key===u);return i(`select`,{value:u,disabled:o.isPending,"aria-label":`Inference device pin`,onChange:t=>o.mutate({deviceId:e,deviceKey:t.target.value}),className:`mt-0.5 w-full min-w-0 rounded border border-border bg-background px-1 py-0.5 text-[10px] text-foreground disabled:opacity-50`,children:[f(`option`,{value:`auto`,children:`Auto (balanced)`}),d&&i(`option`,{value:u,children:[p?`${kn(p).label} (${u})`:u,` (not enabled)`]}),c.map(e=>i(`option`,{value:e.key,children:[kn(e).label,` · `,e.format]},e.key))]})}function Gn({role:e,state:t,mode:n,onlineNodes:r,readOnly:a=!1,isMenuOpen:o,onToggleMenu:s,onCloseMenu:c,onMove:l,onUnpin:u}){let d=Ln[e],p=r.filter(e=>e.id!==(t.nodeId??``)),m=!a&&(t.active||n===`cluster`)&&(p.length>0||t.pinned);return i(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[i(`div`,{className:`flex items-center gap-2 min-w-0`,children:[f(n===`agent`?Kn:qn,{state:t,Icon:d}),f(`div`,{className:`ml-auto shrink-0`,children:m&&f(`button`,{type:`button`,onClick:s,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${Rn[e]} actions`,children:f(F,{className:`h-3 w-3 text-foreground-subtle`})})})]}),o&&m&&f(Xn,{title:Rn[e],targets:p,pinned:t.pinned,onMove:l,onUnpin:u,onClose:c})]})}function Kn({state:e,Icon:t}){return i(`div`,{className:`flex items-center gap-1.5`,children:[f(e.active?It:C,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),f(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&f(rn,{className:`h-2.5 w-2.5 text-amber-400`})]})}function qn({state:e,Icon:t}){return!e.active||!e.nodeId?i(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[f(t,{className:`h-3 w-3`}),f(`span`,{className:`text-[10px] italic`,children:`—`})]}):i(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[f(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),i(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[f(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),f(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?i(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[f(rn,{className:`h-2.5 w-2.5`}),` manual`]}):i(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Jn=`min-h-[3.25rem]`;function Yn({snap:e}){if(!e)return f(`div`,{className:`flex items-center ${Jn}`,children:f(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=it(t);return i(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Jn}`,children:[i(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${c.textColor}`,children:[f(ne,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),f(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:c.label})]}),i(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[f(`span`,{className:`text-foreground`,children:n.toFixed(1)}),i(`span`,{children:[`/`,o.toFixed(0),` fps`]})]}),i(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[f(`span`,{className:`text-foreground`,children:r.toFixed(0)}),f(`span`,{children:` ms`}),a>0&&i(`span`,{className:`text-warning ml-1`,children:[`q`,a]})]}),i(`span`,{className:`whitespace-nowrap truncate ${s>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,f(`span`,{className:`text-foreground`,children:s})]})]})}function Xn({title:e,targets:t,pinned:r,onMove:a,onUnpin:o,onClose:s}){let c=n(null);return p(()=>{let e=e=>{c.current?.contains(e.target)||s()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[s]),i(`div`,{ref:c,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[f(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&f(`div`,{className:`py-1`,children:t.map(e=>i(`button`,{type:`button`,onClick:()=>a(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),r&&i(`button`,{type:`button`,onClick:o,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!r&&f(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Zn({nodeId:e,refreshToken:t}){return i(`div`,{className:`space-y-6`,children:[f(bn,{refreshToken:t,nodeId:e}),i(`div`,{children:[f(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),f(zn,{mode:`agent`,nodeId:e,compact:!0})]})}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=l(),r=_e(),a=Le({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:s}=Tt({nodeId:e}),c=je(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??s??null,u=c===null;ht([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:d}=Ve({nodeId:e}),{values:p}=oe(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=o(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),h=t=>{let n=d??[];if(n.length===0){a.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`})&&a.mutate({nodeId:e,engine:t,force:!0})})()};return i(`div`,{className:`space-y-6`,children:[i(`div`,{children:[f(`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:[(c??[]).length,` engine(s) resident in RAM. `,(d??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),f(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[640px]`,children:[f(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[f(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),f(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),f(`th`,{className:`text-left px-3 py-2`,children:`Models`}),f(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),f(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),f(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),f(`th`,{className:`w-20`})]})}),i(`tbody`,{children:[u&&f(`tr`,{children:f(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!u&&(c??[]).map(e=>{let t=e.kind===`device-pool`;return i(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[f(`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:[f(t?Ft:W,{className:`h-3 w-3`}),t?`pool`:`runtime`]})}),f(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[f(B,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),f(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?f(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):f(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>f(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),f(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),f(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?f(`span`,{className:`text-foreground-subtle`,children:Qn(e.idleMs,e.idleTtlMs)}):f(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),f(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(d??[]).length}),f(`td`,{className:`px-3 py-2 text-right`,children:t?f(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):i(`button`,{type:`button`,disabled:a.isPending,onClick:()=>h(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[f(D,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!u&&(c??[]).length===0&&f(`tr`,{children:f(`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:[f(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,f(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,f(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),a.isError&&i(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,a.error instanceof Error?a.error.message:`unknown`]})]})}var er=`pipeline-runner`,tr=200;function nr({nodeId:e}){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[f(`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.`]})]}),f(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:f(R,{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}=Zt(),{data:r}=ge(void 0),a=o(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=o(()=>{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,l]=d(new Map);Oe(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||l(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),p(()=>{if(c.size===0)return;let e=setInterval(()=>{l(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[c.size]);let u=o(()=>{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 u.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:[f(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),f(`span`,{className:`text-[10px] text-foreground-subtle`,children:u.length})]}),f(`div`,{className:`flex flex-wrap gap-1.5`,children:u.map(e=>{let t=a.get(e.deviceId)??`#${e.deviceId}`,n=it(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:[f(ne,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),f(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),f(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),f(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}var ir=`pipeline-orchestrator`;function ar({addonId:e,highlightLabel:t}){let n=Jt(e),{data:r}=U({addonId:ir});if(n.length===0)return null;let a=Bt(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:[f(`h3`,{className:h,children:`Cluster-wide settings`}),f($t,{to:co(),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Edit in Cluster → Settings → Enrichment models ›`})]}),n.map(e=>i(`div`,{className:`${E} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[f(`span`,{className:m,children:e.label}),f(`span`,{className:v,children:f(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),f(`p`,{className:b,children:`One value for every node and camera — this step writes into a shared index.`})]})}r();function or(e,n){let[r,i]=Qt(),a=r.get(sn),s=r.get(`acc`),c=o(()=>un(e,n,{step:a,acc:s}),[e,n,a,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(sn,e.stepId),e.acceleratorId!==void 0&&t.set(`acc`,e.acceleratorId)}),[l]),selectAccelerator:t(e=>l(t=>t.set(`acc`,e)),[l]),close:t(()=>l(e=>e.delete(sn)),[l])}}function sr(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function cr(e){return e.split(`.`)[0]??e}function lr(e,t,n){return{id:ln(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${cr(t)} · ${Ee(n)}`,shortLabel:`${cr(t)} · ${z(n)}`,nodeLabel:cr(t),disabled:!n.enabled}}function ur(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>lr(e,t,n))}function dr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>lr(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>lr(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[lr(e.id,e.name,a)]})}function fr(e,t,n){return{modelId:Ot({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function pr(e,t,n){let r=sr(e,`object-detection`);if(r===null)return;let i=Ot({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 mr(e,t,n){return!Gt(e)||n===void 0?!1:Vt(e,t,n.supplies).effective}function hr(e,t){return e!==null&&Ce(e.models,t.device.format)}function gr(e){return hr(e.addon,e.acc)?e.clusterModelId===void 0?{kind:`enabled`,modelId:e.model.modelId??`Auto`,overridden:e.model.source===`camera`,...e.rootName===void 0?{}:{suppliedByRoot:e.rootName},...e.jumpTo===void 0?{}:{jumpTo:e.jumpTo}}:{kind:`enabled`,modelId:e.clusterModelId,clusterWide:!0}:e.gatedOn?e.jumpTo===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:e.jumpTo}:{kind:`na`}}function _r(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function vr(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=Jt(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function yr(e){return e.flatMap(e=>[{node:e,depth:0},...yr(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function br(e,t){return e.flatMap(e=>{let n=br(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}r();function xr(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:Ee(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Sr({tree:e,searchRows:r,accelerators:a,cellState:s,stepBadge:c,disabledCount:l,showDisabled:u,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:y}){let x=_e(),S=We(),{selection:C,open:w,selectAccelerator:T,close:E}=or(o(()=>yr(e).map(e=>e.node.addonId),[e]),o(()=>a.map(e=>e.id),[a])),[D,O]=d(``),[k,A]=d(null),[j,M]=d(null),N=n(null),F=n(null),I=n(null),L=n(null),R=o(()=>P(r,D),[r,D]),ee=o(()=>D.trim()===``?e:br(e,new Set(R.map(e=>e.addonId))),[e,R,D]),z=e=>R.find(t=>t.addonId===e)?.matchedField??null,ne=o(()=>a.map(xr),[a]),re=e=>a.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),B=a.find(e=>e.id===C.acceleratorId)??a[0],ie=C.stepId!==null,oe=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===void 0||t.id===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():oe(r)},V=()=>{let e=C.stepId;oe(()=>{if(E(),e!==null){let t=B?ae({agentNodeId:B.nodeId,deviceKey:B.deviceKey}):null;requestAnimationFrame(()=>N.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`&&O(``)},de=S?f(te,{onClick:V}):f(st,{icon:le,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:V});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&&ie&&(e.preventDefault(),V())},children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[f(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),f(`input`,{ref:I,type:`search`,value:D,onChange:e=>O(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:[f(qe,{checked:u,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,`).`]}),ee.length===0?i(`p`,{className:`${b} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:[`No step matches “`,D,`”.`]}):f(Ae,{ref:N,tree:ee,agents:ne,label:v,getCellState:(e,t)=>{let n=re(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>ce(e,re(t),n),onStepClick:(e,t)=>ce(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:ie&&C.stepId!==null&&B!==void 0?{addonId:C.stepId,agentNodeId:B.nodeId,deviceKey:B.deviceKey}:null,fallbackNodeId:j,onFallbackNodeChange:M,reserveRightPx:ie&&!S?432:0}),f(he,{open:ie,anchor:F,onClose:V,label:`Step settings`,children:C.stepId!==null&&y({stepId:C.stepId,acceleratorId:C.acceleratorId,matchedField:k,selectAccelerator:T,closeButton:de,onEscape:V,headingRef:e=>{L.current=e}})})]})}r();function Cr(e){p(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}r();function wr(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 Tr(e,t){let n=t.settings===void 0?void 0:wr(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:xn(r,n,t.stepId)}function Er(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=>!Wt(n[e],t.settings?.[e])).length;return r+i+o}function Dr({nodeId:e,nodeName:t,toolbar:n}){let r=l(),a=me({nodeId:e},{refetchOnMount:`always`}),c=Ye({nodeId:e},{refetchOnMount:`always`}),u=Ut(U({addonId:`pipeline-orchestrator`}).data??null),p=a.data?.devices??[],m=c.data??null,[g,_]=d(null),[v,y]=d(null),[x,S]=d(null),C=ue({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),w=o(()=>m?Se(m):[],[m]),T=o(()=>yr(w),[w]),[E,D]=d(!1),O=o(()=>ur(e,t,p,E),[e,t,p,E]),k=o(()=>ur(e,t,p),[e,t,p]),A=k.length>=2,j=(e,t)=>(t===void 0?void 0:Sn(p,t.deviceKey,e))??{},M=(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(!hr(e,t))return k.filter(n=>n.id!==t.id&&hr(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},N=(e,t)=>{let n=sr(m,e),r=fo(e),i=pr(m,t),a=j(e,t),o=M(n,t);return gr({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?fr(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...mr(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:u[e]??r.defaultModelId}:{},...o?{jumpTo:z(o.device)}:{}})},P=T.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:vr(sr(m,e.addonId))}));if(a.isLoading||c.isLoading)return f(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`});if(m===null)return f(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`});let F=i(`span`,{className:b,children:[`Accelerators:`,` `,f(`span`,{className:`text-foreground`,children:k.length>0?k.map(e=>z(e.device)).join(` · `):`none enabled`}),p.some(e=>!e.enabled)&&i(s,{children:[` `,`— off:`,` `,p.filter(e=>!e.enabled).map(z).join(`, `)]}),` `,`·`,` `,f($t,{to:lo(),className:`text-primary hover:underline`,children:`Cluster → Load balancing ›`})]});return f(Sr,{tree:w,searchRows:P,accelerators:O,cellState:N,disabledCount:p.filter(e=>!e.enabled).length,showDisabled:E,onShowDisabledChange:D,dirty:g!==null&&Er(p,g,j(g.stepId,O[0]))>0,onDiscard:()=>_(null),summary:F,...n===void 0?{}:{toolbar:n},label:`Detection steps`,renderDetail:({stepId:n,acceleratorId:r,matchedField:a,selectAccelerator:o,closeButton:c,onEscape:l,headingRef:u})=>{let d=sr(m,n);if(d===null)return f(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let w=g?.stepId===n?g:null,T=O.find(e=>e.id===r)??O[0],E=j(n,T),D=w?.settings??E,k=Er(p,w,E),N=e=>{S(null),_(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},P=fo(n),F=Ie(d),L=T===void 0?void 0:pr(m,T),R=e=>{let t=w?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},ee=T===void 0?void 0:fr(d,T,{nodePin:R(T)}).modelId,te=O.length>1&&O.some(e=>!Wt(j(n,e),E)),z=()=>{w!==null&&C.mutate({agentNodeId:e,inferenceDevices:Cn(Tr(p,w))},{onSuccess:()=>{_(null),S({kind:`saved`})},onError:e=>S({kind:`error`,error:e.message})})};return f(Te,{ref:u,title:d.name,subtitle:`${d.slot} · base for every camera that lands on ${t}`,leading:c,onEscape:l,headerExtra:A&&F.length>0&&P===null?i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[f(`span`,{className:b,children:`Values as they run on`}),f(fe,{items:O.map(e=>({id:e.id,label:e.shortLabel})),selectedId:T?.id??null,onSelect:o})]}):void 0,saveBar:{dirtyCount:k,saving:C.isPending,status:x?.kind??null,...x?.error===void 0?{}:{error:x.error},onSave:z,onDiscard:()=>_(null)},children:i(`div`,{className:`space-y-3`,children:[i(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[f(`h3`,{className:h,children:`Model`}),P!==null&&T!==void 0?f(po,{step:P,engineFormat:T.device.format,runnableModelIds:I(d.models??[],T.device.format).map(e=>e.id)}):O.length===0?i(`p`,{className:b,children:[`No accelerator is enabled on this node —`,` `,f($t,{to:lo(),className:`text-primary hover:underline`,children:`enable one in Cluster → Load balancing`}),`.`]}):f(Et,{rows:O.map(e=>{let t=w?.models[e.deviceKey],r=R(e),a=fr(d,e,{nodePin:r}),o=pr(m,e),c=mr(n,w?.settings??j(n,e),o),l=w?.jumps[e.deviceKey],u=M(d,e,l),p=hr(d,e)?c&&o?f($e,{rootModel:o,stepModelId:a.modelId}):void 0:i(s,{children:[`No `,e.device.format,` build of this step.`,` `,u?`It runs on ${u.shortLabel} instead.`:`It does not run here.`]}),h=A?i(`label`,{className:`block space-y-1`,children:[f(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Run on`}),i(`select`,{className:`h-9 w-full rounded-md border border-border bg-surface px-2 text-xs md:h-8`,value:l??e.device.steps?.[n]?.jumpDeviceKey??``,onChange:t=>N({jumps:{...w?.jumps,[e.deviceKey]:t.target.value}}),children:[f(`option`,{value:``,children:`Auto (this accelerator, or the next one that can run it)`}),O.filter(t=>t.id!==e.id).map(e=>i(`option`,{value:e.deviceKey,children:[e.label,` · `,e.device.format]},e.id))]}),f(`span`,{className:b,children:`Routes this step (and its child steps) to another accelerator of this node.`})]}):void 0;return{id:e.id,label:e.label,format:e.device.format,modelId:a.modelId,source:a.source===`node`?`node`:`default`,sourceLabel:a.source===`node`?`node pin`:`hardware default`,models:I(d.models??[],e.device.format),defaultModelId:d.defaultModelIdByFormat?.[e.device.format]??d.defaultModelId,expanded:v===e.id,onToggle:()=>y(t=>t===e.id?null:e.id),onChangeModel:t=>N({models:{...w?.models,[e.deviceKey]:t}}),...r===void 0?{}:{onReset:()=>N({models:{...w?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...p===void 0?{}:{note:p},...h===void 0?{}:{extra:h},changed:t!==void 0||l!==void 0}})},n)]}),(F.length>0||L!==void 0)&&P===null&&i(`section`,{"aria-label":`Settings`,className:`border-t border-border/60 pt-2`,children:[te&&f(`p`,{className:`mb-2 rounded-md border border-amber-500/40 bg-amber-500/10 px-2 py-1 text-[11px] text-amber-500`,children:`This step's settings differ between this node's accelerators. Saving makes the values shown here node-wide.`}),f(Or,{addon:d,fields:F,settings:D,modelId:Je(d,ee,D,L),root:L,highlight:a,onChange:e=>N({settings:e})})]}),f(ar,{addonId:n,highlightLabel:a})]})})}})}function Or({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 Cr(s===null?null:At(s)),f(wt,{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 kr({nodeId:e,refreshToken:t}){let n=_e(),[r,a]=d(null),{nodes:o}=K(),c=o.find(t=>t.id===e)?.name??e,l=se({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)`)}}),u=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:[f(rr,{nodeId:e}),f(Dr,{nodeId:e,nodeName:c,toolbar:i(s,{children:[r&&f(`span`,{className:`text-[11px] text-success`,children:r}),l.isError&&f(`span`,{className:`text-[11px] text-danger`,children:l.error instanceof Error?l.error.message:`Reset failed`}),f(H,{variant:`outline`,size:`sm`,onClick:()=>{u()},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 Ar=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],jr=`decoder-nodeav`,Mr=`ntab`;function Nr({nodeId:e,refreshToken:t}){let[n,r]=Qt(),{nodes:a}=K(),o=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??jr,s=[...Ar,o],c={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:f(Zn,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:f(kr,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:f($n,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:f(nr,{nodeId:e})}},l=yn.map(e=>c[e]);return i(`div`,{className:`flex flex-col h-full`,children:[f(vn,{nodeId:e,refreshToken:t}),f(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:f(en,{nodeId:e,addonIds:s,level:`global`,extraTabs:l,activeTab:n.get(Mr),onActiveTabChange:e=>r(t=>{let n=new URLSearchParams(t);n.set(Mr,e);for(let e of cn)n.delete(e);return n},{replace:!0})})})]})}function Pr(){return i(`div`,{className:`space-y-6`,children:[f(rr,{title:`Cluster cameras`}),i(`div`,{className:`min-w-0`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),f(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Use the Auto | Pin control to pin a camera to a node, the inference-device select to pin it to an accelerator, or the kebab to move a role; expand the chevron for the per-camera broker drill-down. Load, shares, caps and Rebalance live on the Load balancing tab.`})]}),f(zn,{mode:`cluster`})]})}function Fr(e){return`${Math.round(e*100)}%`}function Ir(e){return`${e} session${e===1?``:`s`}`}var Lr={"intel-npu":`Intel NPU`,"intel-igpu":`Intel iGPU`,"x86-cpu":`CPU`,"arm-cpu":`CPU`,"apple-ane":`Apple Neural Engine`,coral:`Coral Edge TPU`},Rr={"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 zr(e){return e===null?`—`:Lr[e]??e}function Br(e){return e===null?`—`:Rr[e]??e}function Vr(e){switch(e.kind){case`capacity`:return`Capacity ${Ir(e.sessions)} ≥ min ${e.minSessions}.`;case`tie-faster`:return`As accurate as ${e.over} (within ${Fr(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 ${Ir(e.minSessions)} per device; the one with the most capacity (${Ir(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.`}}function Hr(e){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.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`${e.nodeId}: the Coral (${e.deviceKey}) is enabled and keeps running its SSD model, which finds far fewer people than YOLOv9. Consider disabling it.`}}function Ur(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 Wr(e){let t=Ur(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function Gr(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}}r();var Kr=[.3,.4,.5];function qr(e){return Kr.some(t=>t===e)}var Jr=[1,2,3,4,6,8];function Yr({plan:e,node:t}){return i(`section`,{className:g,"data-testid":`auto-tune-node-${t.nodeId}`,children:[i(`header`,{className:`${y} flex flex-wrap items-center gap-2`,children:[f(W,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),f(`h3`,{className:`${h} min-w-0 flex-1`,children:t.nodeId}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[Br(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?f(G,{variant:`warning`,children:`Not changed`}):t.acceleratorModelId!==null&&f(G,{variant:`info`,children:t.acceleratorModelId})]}),t.reasons.length>0&&f(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:t.reasons.map((e,t)=>f(`li`,{children:Vr(e)},t))}),f(`div`,{className:`overflow-x-auto`,children:i(`table`,{className:`w-full text-xs`,children:[f(`thead`,{children:i(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[f(`th`,{className:`px-3 py-1.5 font-medium`,children:`Device`}),f(`th`,{className:`px-3 py-1.5 font-medium`,children:`Capacity`}),f(`th`,{className:`px-3 py-1.5 font-medium`,children:`Detector`}),f(`th`,{className:`px-3 py-1.5 font-medium`,children:`Why`})]})}),f(`tbody`,{children:t.devices.map(n=>{let r=Gr(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:[f(`div`,{className:`font-mono text-foreground`,children:n.deviceKey}),f(`div`,{className:`text-[11px] text-foreground-subtle`,children:zr(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`]})]}),f(`td`,{className:`px-3 py-1.5`,children:n.chosen===null?f(`span`,{className:`text-foreground-subtle`,children:`unchanged`}):r!==null&&r.before!==r.after?i(`span`,{children:[f(`span`,{className:`text-foreground-subtle`,children:r.before??`default`}),` → `,f(`span`,{className:`font-medium text-foreground`,children:r.after})]}):f(`span`,{className:`text-foreground`,children:n.chosen.modelId})}),f(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>f(`div`,{children:Vr(e)},t))})]},n.deviceKey)})})]})})]})}function Xr({plan:e,nameOf:t}){return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[i(`div`,{children:[f(`div`,{className:h,children:`Node settings`}),e.nodeChanges.length===0?f(`div`,{className:`text-foreground-subtle`,children:`No change.`}):f(`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:[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:[e.nodeId,` · `,e.deviceKey]}),` `,`— `,t.stepId,`: reset `,t.keys.join(`, `),` to the model default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),i(`div`,{children:[f(`div`,{className:h,children:`Camera overrides cleared`}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?f(`div`,{className:`text-foreground-subtle`,children:`None.`}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,n)=>i(`li`,{children:[t(e.deviceId),` — `,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${n}`)),e.detectorStoreClears.map(e=>i(`li`,{children:[t(e.deviceId),` — detector thresholds: `,e.keys.join(`, `),` reset`]},`d${e.deviceId}`))]})]})]})}function Zr({result:e}){return e.kind===`refused`?f(`div`,{className:`text-xs text-warning`,children:`Another apply is already running.`}):e.kind===`stale`?f(`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`&&f(`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 Qr(){let e=l(),[t,n]=d(.4),[r,a]=d(2),[s,c]=d(!1),[u,p]=d(!1),[m,_]=d(null),{data:v}=Zt(),b=o(()=>new Map((v??[]).map(e=>[e.id,e.name])),[v]),x=e=>b.get(e)??`Device ${e}`,S=Pt({headroom:t,minSessionsPerDevice:r},{enabled:s,refetchOnWindowFocus:!1}),C=Mt({onSuccess:t=>{_(t),p(!1),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.kind===`applied`&&S.refetch()}}),w=m?.kind===`stale`?m.plan:S.data,T=w===void 0?null:Ur(w);return i(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[i(`section`,{className:g,children:[i(`header`,{className:`${y} flex flex-wrap items-center gap-2`,children:[f(Ze,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),f(`h3`,{className:`${h} 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:[f(`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:[f(`span`,{className:`whitespace-nowrap`,children:`Keep free`}),f(M,{"aria-label":`Share of each accelerator kept free`,value:String(t),options:Kr.map(e=>({value:String(e),label:`${Math.round(e*100)}% of each accelerator`})),onChange:e=>{let t=Number(e.target.value);qr(t)&&n(t)}})]}),i(`label`,{className:`flex items-center gap-1.5`,children:[f(`span`,{className:`whitespace-nowrap`,children:`At least`}),f(M,{"aria-label":`Minimum parallel sessions per device`,value:String(r),options:Jr.map(e=>({value:String(e),label:`${e} camera${e===1?``:`s`} at once per accelerator`})),onChange:e=>{let t=Number(e.target.value);Jr.some(e=>e===t)&&a(t)}})]}),f(H,{size:`sm`,variant:`secondary`,onClick:()=>{_(null),c(!0),s&&S.refetch()},children:S.isFetching?`Computing…`:w===void 0?`Compute plan`:`Recompute`}),w!==void 0&&f(H,{size:`sm`,disabled:Wr(w),onClick:()=>p(!0),children:`Apply…`})]}),S.error!==null&&f(`div`,{className:`text-danger`,children:S.error.message}),m!==null&&f(Zr,{result:m}),T!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[T.modelChanges,` model change(s), `,T.thresholdClears,` node threshold reset(s), `,T.cameraOverrideClears+T.detectorStoreClears,` camera override(s) on `,T.camerasTouched,` camera(s).`]})]})]}),w?.warnings.map((e,t)=>f(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:Hr(e)},t)),w?.nodes.map(e=>f(Yr,{plan:w,node:e},e.nodeId)),w!==void 0&&f(nt,{open:u,onOpenChange:p,children:i(ft,{width:`lg`,scroll:`body`,children:[i(ot,{children:[f(St,{children:`Apply auto tune?`}),f(vt,{children:`These are all the changes. Every override listed is removed and cannot be restored.`})]}),f(ze,{children:f(Xr,{plan:w,nameOf:x})}),i(He,{children:[f(H,{variant:`ghost`,onClick:()=>p(!1),children:`Cancel`}),f(H,{variant:`danger`,disabled:C.isPending,onClick:()=>C.mutate({planHash:w.planHash,headroom:t,minSessionsPerDevice:r}),children:C.isPending?`Applying…`:`Apply`})]})]})})]})}var $r={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 ei(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function ti(e,t){let n=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let r=t.get(e.key),i=r?.sessions??0,a=e.weight>0?e.weight:1;return{key:e.key,label:Ee(e),format:e.format,sessions:i,queueDepth:r?.queueDepth??0,weight:a,weightSharePct:e.exclusion===null?ei(a,n):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function ni(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=ti(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,{sessions:e.attachedCameras,queueDepth:e.queueDepthTotal}]))),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?ei(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?ei(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}var ri=`pipeline-orchestrator`,ii=`recorder`,ai=`recordingNodeId`,oi=`pipeline-analytics`,si=`postProcessingNodeId`,ci=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`,`postProcessingNode`],li=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function ui(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function di(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function fi(e,t,n){let r=ui(e,t);return typeof r==`string`&&r.length>0?r:n}function pi(e,t){let n=di(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function mi(e,t){let n=di(e,t);return typeof n==`string`&&n.length>0?n:null}function hi(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:e===`postProcessingNode`?`Post-processing`:`Motion Node`}function gi(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:e===`postProcessingNode`?`Runs detection post-processing (events, media, audio & motion)`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function _i(e,t){switch(t){case`detect`:return e.pipeline}}function vi(e){return e instanceof Error?e.message:`Failed to save`}function yi(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}r();var bi=2e4,xi=3e5;function Si({stats:e,targetWeights:t}){let{nodes:n}=K(),r=S().trpcClient,a=we(void 0,{placeholderData:u,staleTime:bi,refetchInterval:bi,refetchOnWindowFocus:!0}),s=ye(void 0,{staleTime:xi}),l=o(()=>n.map(e=>e.id),[n]),d=c({queries:l.map(e=>({queryKey:Lt(Me.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:xi,refetchOnWindowFocus:!1,placeholderData:u}))}),p=o(()=>{let e={};return l.forEach((t,n)=>{let r=d[n]?.data;r&&(e[t]=r.devices)}),e},[l,d.map(e=>e.dataUpdatedAt).join(`|`)]),m=o(()=>{let e=new Map;for(let t of s.data??[])e.set(t.nodeId,t.settings);return e},[s.data]),h=o(()=>n.map(e=>{let n=m.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:hn(n,e.isHub).pipeline,weight:t?.[e.id]??pi(n,`detectWeight`)??1,maxCameras:pi(n,`maxCameras`)}}),[n,m,t]),g=a.data??[],v=o(()=>ni({nodes:h,loads:g,devicesByNode:p}),[h,g,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),x=a.dataUpdatedAt>0?Date.now()-a.dataUpdatedAt:null,C=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return f(be,{headingId:`load-balancing-node-load`,title:`Node load`,icon:Ke,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[b,` running · `,y,` attached ·`,` `,a.data===void 0?`reading…`:`${x===null?`—`:`${Math.round(x/1e3)}s`} old`]}),children:f(`div`,{className:_,children:v.length===0?f(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):f(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>f(Ci,{row:e,placed:C.get(e.nodeId)},e.nodeId))})})})}function Ci({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:[f(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),f(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&f(`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:[f(yt,{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:[f(Pe,{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:[f(J,{label:`Running / attached`,value:n,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),f(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).`}),f(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.`}),f(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.`}),f(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&&f(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&f(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&f(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),f(wi,{row:e})]})}function wi({row:e}){return e.devices.length===0?f(`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:[f(Qe,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&f(`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`})]}),f(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>f(Ti,{device:e},e.key))})]})}function Ti({device:e}){let t=e.exclusion;return i(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[f(W,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),f(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?i(s,{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`,children:[`· `,e.sessions,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.queueDepth>0&&i(`span`,{className:`shrink-0 tabular-nums text-amber-400`,children:[`· q`,e.queueDepth]}),e.atCap&&f(`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:$r[t],children:[`excluded — `,$r[t]]})]})}function J({label:e,value:t,title:n}){return i(`div`,{className:`min-w-0`,title:n,children:[f(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),f(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Ei(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Di(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 Oi(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function ki(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 Ai(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 ji(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 Mi=[{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 Ni(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 Pi(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)}: ${Ni(e.capacityFallback)??``}`).join(` · `)}r();var Fi=3600*1e3,Ii=2e4,Li=.4;function Ri({refreshToken:e,onOpenAutoTune:t}){let n=l(),{nodes:r}=K(),a=ye(void 0),c=ce({windowMs:Fi},{refetchInterval:Ii,placeholderData:u}).data,p=rt(void 0,{refetchInterval:Ii,placeholderData:u}).data,m=()=>{yi(n),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},h=bt({onSuccess:m}),g=gt({onSuccess:()=>{m(),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),v=mt({onSuccess:m}),y=N(),[S,C]=d(!1),w=p?.source,T=w===`benchmark`?`benchmark`:`hardware`,E=tt({headroom:Li,source:T},{enabled:S,staleTime:1/0}),D=E.data,O=o(()=>{let e=new Map((a.data??[]).map(e=>[e.nodeId,e.settings]));return r.filter(t=>hn(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:pi(n,`detectWeight`)??1,maxCameras:pi(n,`maxCameras`)}})},[r,a.data]),k=e=>r.find(t=>t.id===e)?.name??e,A=D?Oi(D):void 0,j=Ai(O,p),M=w!==`manual`,P=e=>{if(p===void 0||p.source===`manual`||p.autoPending)return;let t=p.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},F=p?ji(p,k):null,I=p?Pi(p,k):null,L=Mi.find(e=>e.value===w)?.hint;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[f(en,{nodeId:`hub`,addonIds:[ri],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.`}),f(bn,{refreshToken:e}),f(Si,{stats:c,...p!==void 0&&p.source!==`manual`&&!p.autoPending?{targetWeights:Object.fromEntries(p.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),f(be,{headingId:`load-balancing-node-shares`,title:`Node shares`,icon:an,actions:i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[f(`div`,{role:`radiogroup`,"aria-label":`Share source`,className:`flex items-center gap-1`,children:Mi.map(e=>f(H,{role:`radio`,"aria-checked":w===e.value,variant:w===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:g.isPending||p===void 0,onClick:()=>{w!==e.value&&g.mutate({source:e.value})},children:e.label},e.value))}),i(H,{variant:`outline`,size:`sm`,onClick:()=>{C(!0),S&&E.refetch()},disabled:E.isFetching,children:[f(dt,{className:`h-3.5 w-3.5`}),E.isFetching?`Suggesting…`:T===`benchmark`?`Suggest from benchmark`:`Suggest from hardware`]}),i(H,{variant:`ghost`,size:`sm`,onClick:t,children:[f(Ze,{className:`h-3.5 w-3.5`}),`Auto tune`]}),i(H,{variant:`outline`,size:`sm`,onClick:()=>y.mutate(void 0),disabled:y.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:[f(B,{className:`h-3.5 w-3.5`}),y.isPending?`Rebalancing…`:`Rebalance`]})]}),children:i(`div`,{className:`${_} space-y-3`,children:[L!==void 0&&f(`p`,{className:`text-[10px] text-foreground-subtle`,children:L}),c&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Policy:`,` `,f(G,{variant:c.policy===`share`?`info`:`default`,children:c.policy===`share`?`honour shares`:`least-loaded`}),` `,`· cluster peak `,c.clusterPeakSessions,` parallel sessions in the last hour`,c.policy===`least-loaded`&&` · under least-loaded an idle node always wins, so shares only bite once nodes are busy`]}),f(On,{nodes:j.nodes,pending:h.isPending,readOnly:j.readOnly,onCommitWeights:e=>h.mutate(Ei(e)),weightLabel:`Node share`,...j.readOnly?{footnote:p?.autoPending?f(s,{children:`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`}):i(s,{children:[w===`benchmark`?`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`:`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`,p?.computedAt==null?``:` — last at ${new Date(p.computedAt).toLocaleTimeString()}${p.trigger===null?``:` (${p.trigger})`}`,`.`]})}:{}}),F!==null&&f(`p`,{className:`text-[10px] text-foreground-subtle`,children:F}),I!==null&&f(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:I}),g.isError&&f(ve,{message:`Failed to switch shares: ${g.error instanceof Error?g.error.message:`unknown error`}`}),h.isError&&f(ve,{message:`Failed to save shares: ${h.error instanceof Error?h.error.message:`unknown error`}`}),i(`details`,{className:`rounded-md border border-border`,children:[f(`summary`,{className:`${x} cursor-pointer text-xs text-foreground`,children:`Max concurrent sessions (advanced)`}),f(`ul`,{className:`divide-y divide-border border-t border-border`,children:O.map(e=>i(`li`,{className:`${x} flex items-center gap-2`,children:[f(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),f(pt,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":`Max concurrent sessions for ${e.name}`,className:`w-20 text-right`,disabled:v.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&&v.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),f(`p`,{className:`${x} ${b} border-t border-border`,children:`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`})]})]})}),E.isError&&f(ve,{message:`Suggestion failed: ${E.error instanceof Error?E.error.message:`unknown error`}`}),D&&f(zi,{suggestion:D,nameOf:k,pending:h.isPending,...M?{}:{onApply:()=>h.mutate(Di(D))}}),f(be,{headingId:`load-balancing-accelerators`,title:`Accelerators`,icon:W,children:f(`div`,{className:`${_} space-y-2`,children:O.length===0?f(Nt,{title:`No detect-capable nodes`,description:`Enable detection on a node in Roles & nodes to configure its accelerators.`}):O.map(e=>f(jn,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...A?.[e.id]===void 0?{}:{suggestedMaxSessions:A[e.id]},...P(e.id)===void 0?{}:{autoDeviceShares:P(e.id)}},e.id))})}),c!==void 0&&c.stalePins.length>0&&f(Bi,{stats:c})]})}function zi({suggestion:e,nameOf:t,pending:n,onApply:r}){return i(be,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?`Suggested from benchmark`:`Suggested from hardware`,icon:dt,...r===void 0?{}:{actions:f(H,{size:`sm`,onClick:r,disabled:n,children:`Apply suggested shares`})},children:[f(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>i(`li`,{className:`${x} space-y-0.5`,children:[i(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[f(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),f(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?`skipped`:`${e.share}%`})]}),i(`p`,{className:b,children:[Ni(e.capacityFallback)===null?``:`${Ni(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:`${x} ${b} 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 Bi({stats:e}){let t=l(),n=ct({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return f(be,{headingId:`load-balancing-stale-pins`,title:`Stale device pins`,icon:nn,children:f(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>i(`li`,{className:`${x} flex items-center gap-2`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`text-xs text-foreground`,children:[`Camera `,e.deviceId]}),f(`p`,{className:b,children:ki(e)})]}),f(H,{variant:`outline`,size:`sm`,disabled:n.isPending,onClick:()=>n.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:`Clear pin`})]},e.deviceId))})})}function Vi({capability:e,label:t,hint:n,nodeId:r,active:a,pending:o,layout:s,onToggle:c}){let l=a?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,u=s===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,d=a?De:Fe;return i(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:o,onClick:()=>c(e,!a),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${l} ${u}`,children:[f(d,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),f(`span`,{children:t})]})}function Hi({node:e,emphasis:t=!1}){let n=e.isHub?at:W;return i(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[f(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),f(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:[f(`span`,{className:`truncate`,children:e.name}),e.isHub&&f(G,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&f(G,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),f(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}r();function Ui({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:a,onCommit:o}){let[s,c]=d(t??``);p(()=>{c(t??``)},[t]);let l=n[0],u=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:[f(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:u,value:s,disabled:m,onChange:e=>c(e.target.value),onBlur:v,onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&c(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),i(`button`,{type:`button`,onClick:v,disabled:!_,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[m?f(_t,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):f(De,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&r===`success`&&f(De,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&f(`span`,{title:a??`Failed to save reachable host`,children:f(A,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}r();var Wi=1024,Gi=65536;function Ki(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 qi({nodeId:e,decodeBudgetMb:t,maxLiveDecodeWorkers:n,status:r,errorMessage:a,onCommit:o}){let[s,c]=d(t===null?``:String(t)),[l,u]=d(n===null?``:String(n));p(()=>{c(t===null?``:String(t))},[t]),p(()=>{u(n===null?``:String(n))},[n]);let m=Ki(s,Wi,Gi),h=Ki(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})},x=`w-24 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`;return i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[f(`input`,{"aria-label":`Decode budget MB for ${e}`,type:`number`,inputMode:`numeric`,min:Wi,max:Gi,placeholder:`auto`,value:s,disabled:g,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:x}),f(`span`,{className:`text-[11px] text-foreground-subtle`,children:`MB`}),f(`input`,{"aria-label":`Max decode workers for ${e}`,type:`number`,inputMode:`numeric`,min:1,max:32,placeholder:`auto`,value:l,disabled:g,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:x}),f(`span`,{className:`text-[11px] text-foreground-subtle`,children:`workers`}),i(`button`,{type:`button`,onClick:b,disabled:!y,"aria-label":`Save decode limits for ${e}`,title:`Save decode limits`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[g?f(_t,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):f(De,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),m.error===null?null:i(`span`,{className:`text-[11px] text-red-400`,children:[`budget: `,m.error]}),h.error===null?null:i(`span`,{className:`text-[11px] text-red-400`,children:[`workers: `,h.error]}),!_&&!g&&r===`success`&&f(De,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&f(`span`,{title:a??`Failed to save decode limits`,children:f(A,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":`Save failed`,role:`img`})})]})}function Ji({label:e,children:t}){return i(`div`,{className:`flex items-center justify-between gap-3`,children:[f(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Yi({node:e,actions:t}){return i(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[f(Hi,{node:e,emphasis:!0}),f(`div`,{className:`grid grid-cols-2 gap-2`,children:li.map(n=>f(Vi,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:_i(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),i(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[f(Ji,{label:`Reachable host`,children:f(Ui,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),f(Ji,{label:`Decode limits`,children:f(qi,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]})]})}function Xi(){return i(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[i(`span`,{className:`inline-flex items-center gap-1.5`,children:[f(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),i(`span`,{className:`inline-flex items-center gap-1.5`,children:[f(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),i(`span`,{className:`inline-flex items-center gap-1.5`,children:[f(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),i(`span`,{className:`inline-flex items-center gap-1.5`,children:[f(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function Zi({nodes:e,actions:t}){return f(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:i(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[f(`thead`,{children:i(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[f(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),li.map(e=>f(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),f(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`}),f(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Decode limits`})]})}),f(`tbody`,{children:e.map(e=>i(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[f(`td`,{className:`px-4 py-3 align-middle`,children:f(Hi,{node:e})}),li.map(n=>f(`td`,{className:`px-3 py-3 text-center align-middle`,children:f(Vi,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:_i(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),f(`td`,{className:`px-4 py-3 align-middle`,children:f(Ui,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})}),f(`td`,{className:`px-4 py-3 align-middle`,children:f(qi,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})})]},e.id))})]})})}function Qi({role:e,value:t,options:n,pending:r,onChange:a}){return i(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[f(`span`,{className:`text-xs font-semibold text-foreground`,children:hi(e)}),f(`select`,{value:t,disabled:r,onChange:t=>a(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>f(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),f(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:gi(e)})]})}function $i({roleValues:e,options:t,pending:n,onRoleChange:r}){return f(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-3`,children:ci.map(i=>f(Qi,{role:i,value:e[i],options:t,pending:n,onChange:r},i))})}r();function ea(){let e=l(),{nodes:t}=K(),n=ye(void 0),r=U({addonId:ri}),a=U({addonId:ii}),c=U({addonId:oi}),u=()=>yi(e),d=Ne({onSuccess:u}),p=V({onSuccess:u}),m=ie({onSuccess:u}),h=jt({onSuccess:u}),g=o(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),_=o(()=>t.map(e=>{let t=g.get(e.id),n=hn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,reachableHost:mi(t,`reachableHost`),detectedHosts:e.localIps,decodeBudgetMb:pi(t,`decodeBudgetMb`),maxLiveDecodeWorkers:pi(t,`maxLiveDecodeWorkers`)}}),[t,g]),v={ingestNode:fi(r.data,`ingestNode`,`hub`),recordingNode:fi(a.data,ai,`hub`),audioNode:fi(r.data,`audioNode`,`hub`),motionNode:fi(r.data,`motionNode`,`hub`),postProcessingNode:fi(c.data,si,`hub`)},y=o(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...ci.map(e=>v[e]),...e])].filter(e=>e.length>0)},[t,v]),b=n.isLoading||r.isLoading||a.isLoading||c.isLoading,x=(e,t,n)=>{d.mutate({agentNodeId:e,[t]:n})},S=(e,t)=>{if(e===`recordingNode`){h.mutate({addonId:ii,patch:{[ai]:t}});return}if(e===`postProcessingNode`){h.mutate({addonId:oi,patch:{[si]:t}});return}h.mutate({addonId:ri,patch:{[e]:t}})},C=e=>p.variables?.agentNodeId===e?p.isPending?`pending`:p.isError?`error`:p.isSuccess?`success`:`idle`:`idle`,w=e=>C(e)===`error`?vi(p.error):null,T=e=>m.variables?.agentNodeId===e?m.isPending?`pending`:m.isError?`error`:m.isSuccess?`success`:`idle`:`idle`,E={capabilityPending:d.isPending,onToggleCapability:x,onCommitReachableHost:(e,t)=>p.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:C,reachableHostErrorMessage:w,onCommitDecodeLimits:(e,t)=>m.mutate({agentNodeId:e,...t}),decodeLimitsStatus:T,decodeLimitsErrorMessage:e=>T(e)===`error`?vi(m.error):null};return i(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[i(`header`,{className:`flex items-start justify-between gap-4`,children:[i(`div`,{className:`space-y-1`,children:[f(`h3`,{className:`text-base font-semibold text-foreground`,children:`Roles & nodes`}),f(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Choose the singleton cluster roles and which node runs each pipeline capability. Detection shares and caps live on the Load balancing tab.`})]}),b&&f(_t,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),i(`div`,{className:`space-y-3`,children:[f(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),f($i,{roleValues:v,options:y,pending:h.isPending,onRoleChange:S})]}),i(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[f(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),f(Xi,{})]}),_.length===0?f(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):i(s,{children:[f(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:_.map(e=>f(Yi,{node:e,actions:E},e.id))}),f(`div`,{className:`hidden @3xl/clustertab:block`,children:f(Zi,{nodes:_,actions:E})})]})]})]})}var ta=[`pipeline-orchestrator`],na=`pipeline-analytics`,ra=`face-gallery`;r();var ia=2500;function aa(e){p(()=>{if(e===null)return;let t=`[data-settings-section="${CSS.escape(e)}"]`,n=()=>{let e=document.querySelector(t);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`),ia),!0)};if(n())return;let r=new MutationObserver(()=>{n()&&r.disconnect()});return r.observe(document.body,{childList:!0,subtree:!0}),()=>r.disconnect()},[e])}function oa({refreshToken:e}){let[t]=Qt();return aa(t.get(oo)),i(`div`,{className:`space-y-4 max-w-3xl`,children:[f(en,{nodeId:`hub`,addonIds:ta,level:`global`,omitSectionIds:[`cluster`,`load`],title:`Cluster settings`,description:`Cluster-wide orchestration knobs: failover, enrichment models, and the admission settings those models share. Placement and load policies live on Load balancing; node roles on Roles & nodes. Per-camera pipelines live in Device Overrides.`}),f(en,{nodeId:`hub`,addonIds:[na],level:`global`,capability:ra,title:`Face recognition`,description:`Match threshold, ambiguity margin, and auto-assign floors. Same settings as System → Settings → pipeline-analytics — this page asks the face-gallery cap, it does not store a second copy.`})]})}var sa=`pipeline-orchestrator`,ca=200;function la(){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[f(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),f(`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.`})]}),f(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:f(R,{addonId:sa,limit:ca,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}var ua=[{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 da(e){return ua.some(t=>t.id===e)}function fa({refreshToken:e}){let[t,n]=Qt(),r=t.get(ao),a=da(r)?r:`assignments`,o=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(ao,e),n.delete(oo),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:[f(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),f(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`})]}),f(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:ua.map(e=>f(`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`&&f(Pr,{}),a===`load-balancing`&&f(Ri,{refreshToken:e,onOpenAutoTune:()=>o(`auto-tune`)}),a===`auto-tune`&&f(Qr,{}),a===`roles-nodes`&&f(ea,{}),a===`settings`&&f(oa,{refreshToken:e}),a===`logs`&&f(la,{})]})]})}var pa=`armed:`;function ma(e){return e.assignment.reasons.detection?.startsWith(pa)===!0}function ha(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!ma(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function ga(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&&!ma(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(...ya(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 _a(e){return e.state===`unreadable`&&zt.state===`unreadable`&&e.reason===zt.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 ya(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return _a(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:[ba(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 ba(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 xa(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(Ca).join(`, `)}function Sa(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function Ca(e){return`${wa(e)}${Sa(e)}`}function wa(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 Ta(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Ea(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Da(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Oa(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var ka={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 Aa(e){if(!Ta(e)||!Array.isArray(e.sections))return ka;let t=qt(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)Oa(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Ea(n(`detectionFps`)),motionSources:Da(n(`motionSources`)),motionFps:Ea(n(`motionFps`)),motionCooldownMs:Ea(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 ja(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(...ja(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:[f(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),f(`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:[f(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),f(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&f(Ma,{})]})}function Ma(){return f(`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 Na={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 f(`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 ${Na[e]}`,children:t})}function $({children:e}){return f(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Pa({icon:e,label:t,nodeId:n,pinned:r,reason:a,overridden:o}){return i(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[f(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),f(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?f(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):i(s,{children:[f(`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:[f(rn,{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`]}),o&&f(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function Fa({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:[f(Pa,{icon:W,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),f(Pa,{icon:Ct,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),f(Pa,{icon:O,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),f(Pa,{icon:xe,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),f(`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:[f(`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 Ia(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function La(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function Ra(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function za({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:a,cameraSensors:o}){let c=La(t,n.detectionStreamProfile),l=La(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}`]}),f(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:Ra(n.detectionFps)}),i(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map(Yt).join(` + `):`none`,r===!1&&` · inactive`]}),f(Z,{label:`Camera sensors`,children:xa(o)}),u&&i(s,{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:[Ra(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),f(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),f(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?f($,{children:`No streams registered`}):e.map(e=>i(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[f(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,Ia(e)]},e.camStreamId))})]})}function Ba({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return i(X,{title:`Pipeline steps`,children:[e===void 0?f($,{children:`Resolving…`}):e.length===0?f($,{children:`No steps configured`}):f(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>f(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&&f(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&i(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),f(`div`,{className:`mt-1`,children:i(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var Va={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function Ha({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return i(X,{title:`Detection runtime`,children:[f(Z,{label:`Mode`,overridden:r,children:n??`—`}),f($,{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=it(a),d=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:[f(ne,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&f(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),f(Z,{label:`Mode`,overridden:r,children:n??`—`}),i(Z,{label:`FPS`,children:[f(`span`,{className:d?`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:[f(Q,{tone:Va[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 Ua({broker:e}){return e===null?f(X,{title:`Stream broker`,children:f($,{children:`Broker stage inactive or unreachable`})}):i(X,{title:`Stream broker`,children:[e.profiles.length===0?f($,{children:`No broker profiles`}):f(`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:[f(`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}),f(`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.toFixed(0),`→`,e.outFps.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 Wa({decoder:e}){return e===null?f(X,{title:`Decoder`,children:f($,{children:`Decoder stage inactive or unreachable`})}):f(X,{title:`Decoder`,children:f(Z,{label:`Node`,children:e.nodeId})})}r();var Ga=`pipeline-orchestrator`,Ka={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},qa={healthy:`Healthy`,idle:`Idle`,error:`Error`};function Ja({problems:e}){return f(`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:[f(yt,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),f(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function Ya({deviceId:e,name:t,online:n,status:r,live:a,onlineNodes:s}){let c=l(),{data:u}=et({addonId:Ga,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:d}=ke({deviceId:e},{staleTime:3e4}),p=o(()=>Aa(u),[u]),m=o(()=>d===void 0?void 0:ja(d.steps),[d]),h=o(()=>r===void 0?[]:ga(r),[r]),g=()=>{c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),c.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=kt({onSuccess:g}),v=ut({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=r===void 0?`idle`:ha(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:[f(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:Ka[b]}`,title:x?`Error`:qa[b],"aria-label":x?`Error`:qa[b],role:`img`}),f(`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&&f(Q,{tone:`danger`,children:`offline`}),i(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&f(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:[f(`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&&f(Ja,{problems:h}),r===void 0?f(`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:[f(Fa,{assignment:r.assignment,settings:p,onlineNodes:s,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),f(Ha,{detection:r.detection,live:a,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),f(Ba,{steps:m,audioModelId:d?.audio?.modelId??null,audioEnabled:r.audio?.enabled??d?.audio?.enabled??null,audioMode:p.audioMode}),f(za,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:p,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null,cameraSensors:r.cameraSensors}),f(Ua,{broker:r.broker}),f(Wa,{decoder:r.decoder})]})]})}r();var Xa=5e3,Za=1e4,Qa=5e3;function $a(e){let t=l(),{data:n,isLoading:r}=Zt(),{data:i,isLoading:a}=ee({},{refetchInterval:Xa}),{nodes:s}=K();p(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[c,u]=d(new Map);Oe(Kt.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&u(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})}),p(()=>{if(c.size===0)return;let e=setInterval(()=>{u(e=>{let t=Date.now()-Za,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},Qa);return()=>clearInterval(e)},[c.size]);let f=o(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:o(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:f.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,f]),liveMetrics:c,onlineNodes:o(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||a}}r();function eo({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:a}=$a(e),s=o(()=>[...t.map(e=>{let t=e.status===void 0?[]:ga(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=o(()=>{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 a&&t.length===0?f(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?f(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):f(`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:[f(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),i(`span`,{children:[f(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),i(`span`,{children:[f(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),f(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>f(Ya,{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:()=>no,PipelinePage:()=>io});r();var no=`__cluster__`;function ro(e){return e===`cameras`?`cameras`:`nodes`}function io(){let[e,t]=Qt(),n=ro(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[a,o]=d(0),[c,l]=d(!1);return p(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:no},{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:[f(`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`}),f(`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`})]}),f(`div`,{className:`flex items-center gap-2`,children:i(`button`,{type:`button`,onClick:()=>o(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:[f(de,{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`]}),f(w,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),f(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?i(s,{children:[f(`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:f(_n,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),f(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?f(fa,{refreshToken:a}):f(Nr,{nodeId:r,refreshToken:a})})]}):f(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:f(eo,{refreshToken:a})})})]})}var ao=`ctab`,oo=`section`;function so(e,t){let n=new URLSearchParams({view:`nodes`,node:no,[ao]:e});return t!==void 0&&n.set(oo,t),`/pipeline?${n.toString()}`}function co(){return so(`settings`,Rt)}function lo(){return so(`load-balancing`)}var uo=`pipeline-orchestrator`;function fo(e){return Ht.find(t=>t.stepId===e)??null}function po({step:e,engineFormat:t,runnableModelIds:n}){let{data:r}=U({addonId:uo}),a=Ut(r??null)[e.stepId]??e.defaultModelId,o=e.options.find(e=>e.id===a)?.label??a,s=n.length>0&&!n.includes(a);return i(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[f(`span`,{className:`font-medium text-foreground`,children:e.label}),f(`span`,{className:`font-mono text-foreground`,children:o}),f(`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`}),f($t,{to:co(),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Change in Cluster → Settings → Enrichment models ›`})]}),i(`p`,{className:b,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 `,f(`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{Sn as _,Sr as a,sr as c,pr as d,hr as f,ar as g,mr as h,Cr as i,yr as l,fr as m,fo as n,dr as o,vr as p,to as r,gr as s,po as t,_r as u,cn as v};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,Q as t,S as n,W as r,b as i,o as a,q as o,x as s,z as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as l,gt as u,ht as d,st as f,vt as p}from"./player-overlays-BddRivLE.js";import{$r as m,Ed as h,Fc as g,Gu as _,Ic as v,Iu as y,Kl as b,Lc as x,Nd as S,Pd as C,Pr as w,Qn as T,Qr as E,Rc as D,Rd as O,Uu as k,Wu as A,Xr as j,Zc as M,Zr as N,ai as P,ei as F,fd as I,if as ee,ii as te,ni as ne,of as re,oi as ie,rd as L,ri as ae,sf as oe,si as R,ti as z,wc as se}from"./src-DnQxdAYg.js";import{t as ce}from"./archive-D-Y4i_R_.js";import{t as B}from"./circle-slash-Bh6ndID4.js";import{a as V,c as H,l as U,n as W,o as G,s as le,t as ue,u as de}from"./location-owned-usage-Bj5-khSs.js";import{t as fe}from"./hard-drive-download-DI78Qxnu.js";import"./mount-Br0xkUVQ.js";import{t as K}from"./AdminPage-CiKtOLQm.js";import{n as pe}from"./authed-media-_X4FXSBp.js";import{t as me}from"./AdminTabs-DcYKYXzK.js";import{t as q}from"./format-size-DIxKXxtj.js";var he=p(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),ge=p(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]);t();function _e(){let e=a(),t=T(),{data:i,isLoading:c,isError:l}=D({}),u=x(),d=r(()=>u.data??[],[u.data]),{data:f}=se({},{refetchOnWindowFocus:!1}),p=r(()=>ue(i??[],f?.locations),[i,f?.locations]),{data:m}=v({},{refetchOnWindowFocus:!1}),h=r(()=>V(m),[m]),[_,y]=o(null),[b,S]=o(null),C=g({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),w=M({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),E=async(e,n)=>{U(n)&&!await t({title:`Disable "${e.displayName}"?`,message:`${H(n).consequence}\n\nNothing is deleted — set the location back to Read-only or Active to bring its footage back.`,confirmLabel:`Disable`,variant:`danger`})||w.mutate(le(e,{mode:n}))},O=async e=>{if(await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`}))try{await C.mutateAsync({id:e.id})}catch(n){await t({title:`Delete anyway?`,message:`${n instanceof Error?n.message:String(n)}\n\nForcing the delete removes the record only. Anything still on that location becomes unreachable — index rows naming it stop resolving, and playback of those segments goes silently black rather than erroring.`,confirmLabel:`Force delete`,variant:`danger`})&&C.mutate({id:e.id,force:!0})}},k=r(()=>{let e=new Map;for(let t of i??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[i]),A=c||u.isLoading,j=l||u.isError;return n(K,{children:[A&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),j&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!A&&!j&&n(`div`,{className:`space-y-3`,children:[d.length===0&&s(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),d.map(e=>s(W,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:k.get(e.id)??[],onAdd:e=>y(e),onEdit:e=>S(e),onDelete:e=>{O(e)},ownedBytesById:p,drainById:h,onSetMode:(e,t)=>{E(e,t)}},e.id))]}),_!==null&&s(de,{initialType:_,onClose:()=>y(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),y(null)}}),b!==null&&s(G,{location:b,onClose:()=>S(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),S(null)}})]})}t();var ve=[[`backup`,`listDestinations`]],ye=[`backup`,`listArchives`];function be({destinationId:t,restoreSupported:i,onOpenRestoreWizard:c}){let l=a(),u=T(),{data:d,isLoading:p,isError:m}=F({destinationId:t}),g=d??[],_=N({onSuccess:()=>{l.invalidateQueries({queryKey:[[...ye]]}),l.invalidateQueries({queryKey:ve})}}),v=e(async e=>{await u({title:`Delete this archive?`,message:`Permanently deletes "${e.label??e.id}" and frees ${q(e.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&_.mutate({destinationId:t,backupId:e.id})},[u,t,_]),[b,x]=o(null),S=e(async e=>{x(e.id);try{let n=await pe(xe(t,e.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.label??e.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{x(null)}},[t]),C=r(()=>[...g].toSorted((e,t)=>t.createdAt-e.createdAt),[g]);return p?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):m?s(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):C.length===0?s(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):s(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:C.map(e=>n(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:Se(e.createdAt)}),s(`td`,{className:`px-3 py-1.5 text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),s(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:e.locations.join(`, `)}),s(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:q(e.sizeBytes)}),s(`td`,{className:`px-3 py-1.5`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[n(`button`,{onClick:()=>{S(e)},disabled:b===e.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[b===e.id?s(L,{className:`h-3 w-3 animate-spin`}):s(h,{className:`h-3 w-3`}),`Download`]}),i&&c&&n(`button`,{onClick:()=>c({destinationId:t,archiveId:e.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[s(y,{className:`h-3 w-3`}),`Restore`]}),s(`button`,{onClick:()=>{v(e)},disabled:_.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:_.isPending?s(L,{className:`h-3 w-3 animate-spin`}):s(f,{className:`h-3 w-3`})})]})})]},e.id))})]})})}function xe(e,t){return l(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function Se(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}t();var J=[[`backup`,`listSchedules`]];function Ce({onEdit:e,onOpenRestoreWizard:t}){let{data:i,isLoading:a,isError:c}=ae(),l=i??[],u=z().data??[],d=r(()=>{let e=new Map;for(let t of u)e.set(t.id,t);return e},[u]),[f,p]=o(null),m=e=>{p(t=>t===e?null:e)};return a?s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):c?s(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):l.length===0?s(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:s(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[820px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[s(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),s(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),s(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),s(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),s(`tbody`,{children:l.map(n=>s(we,{row:n,destById:d,isOpen:f===n.id,onToggle:()=>m(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function we({row:t,destById:l,isOpen:p,onToggle:m,onEdit:h,onOpenRestoreWizard:g}){let v=a(),y=T(),b=R({onSuccess:()=>{v.invalidateQueries({queryKey:J})}}),x=E({onSuccess:()=>{v.invalidateQueries({queryKey:J})}}),S=ie({onMutate:()=>{v.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{v.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),v.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),v.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),[C,w]=o(String(t.retentionCount));c(()=>{w(String(t.retentionCount))},[t.retentionCount]);let D=r(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),O=e(e=>{b.mutate({...D,enabled:e})},[b,D]),k=e(()=>{let e=Number.parseInt(C,10);if(Number.isNaN(e)||e<1){w(String(t.retentionCount));return}e!==t.retentionCount&&b.mutate({...D,enabled:t.enabled,retentionCount:e})},[b,D,C,t.retentionCount,t.enabled]),j=e(()=>{t.locationIds.length!==0&&S.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[S,t]),M=e(async()=>{await y({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&x.mutate({id:t.id})},[y,x,t.id,t.label]),N=t.cron.trim().length>0,P=b.isPending||x.isPending;return n(i,{children:[n(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[s(`td`,{className:`px-2 py-2`,children:s(`button`,{onClick:m,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:p?`Hide archives`:`Show archives`,children:s(p?u:d,{className:`h-3.5 w-3.5`})})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:h,className:`text-left hover:underline focus:outline-none`,children:[s(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&n(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:s(`label`,{className:`inline-flex items-center cursor-pointer`,children:s(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:P,onChange:e=>O(e.target.checked)})})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&s(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>s(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:l.get(e)?.displayName??e},e))]})}),s(`td`,{className:`px-3 py-2`,children:s(`input`,{type:`number`,min:1,max:1e3,value:C,disabled:P,onChange:e=>w(e.target.value),onBlur:k,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&w(String(t.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),s(`td`,{className:`px-3 py-2`,children:n(`button`,{onClick:h,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[n(`span`,{className:`inline-flex items-center gap-1`,children:[s(he,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),s(`span`,{className:`font-mono text-[11px] text-foreground`,children:N?t.cron:`Manual`})]}),N&&t.nextRunAt!==void 0&&n(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),s(`td`,{className:`px-3 py-2`,children:n(`div`,{className:`flex items-center justify-end gap-1.5`,children:[n(`button`,{onClick:j,disabled:S.isPending||t.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[S.isPending?s(L,{className:`h-3 w-3 animate-spin`}):s(A,{className:`h-3 w-3`}),`Run now`]}),s(`button`,{onClick:h,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:s(_,{className:`h-3 w-3`})}),s(`button`,{onClick:()=>{M()},disabled:P,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:s(f,{className:`h-3 w-3`})})]})})]}),p&&s(`tr`,{className:`border-t border-border bg-background/30`,children:n(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&s(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>n(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:l.get(e)?.displayName??e}),s(be,{destinationId:e,restoreSupported:l.get(e)?.restoreSupported??!0,...g?{onOpenRestoreWizard:g}:{}})]},e))]})})]})}t();var Y=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function Te(e){let t=e.trim();for(let e of Y)if(e.cron===t)return e.id;return`custom`}function Ee({value:e,onChange:t,previewCount:r=5,disabled:i=!1}){let a=Te(e),[l,u]=o(a===`custom`);c(()=>{a!==`custom`&&u(!1)},[a]);let d=ke(e,250),f=te({cron:d,count:r},{enabled:d.trim().length>0}),p=f.data??null,m=e=>{u(!1),t(e.cron)},h=l||a===`custom`;return n(`div`,{className:`space-y-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),n(`div`,{className:`flex flex-wrap gap-1.5`,children:[Y.map(e=>s(`button`,{type:`button`,onClick:()=>m(e),disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!l&&a===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),s(`button`,{type:`button`,onClick:()=>{u(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:i,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(h?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),h&&n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),s(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:i,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),n(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,s(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),s(De,{cron:d,preview:p,loading:f.isFetching})]})}function De({cron:e,preview:t,loading:r}){return r&&t===null?n(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[s(L,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?s(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):n(`div`,{className:`space-y-1`,children:[s(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),s(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>n(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[s(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),s(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:Oe(e)})]},`${e}-${t}`))})]}):s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function Oe(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function ke(e,t){let[n,i]=o(e),a=r(()=>e,[e]);return c(()=>{let e=setTimeout(()=>i(a),t);return()=>clearTimeout(e)},[a,t]),n}t();var Ae=[[`backup`,`listSchedules`]];function je({entry:e,onClose:t,onSaved:i}){let c=a(),l=z(),u=l.data??[],[d,f]=o(e?.label??``),[p,m]=o(e?.cron??`0 3 * * *`),[h,g]=o(e?.enabled??!0),[_,v]=o(String(e?.retentionCount??7)),[y,x]=o(new Set(e?.locationIds??[])),S=R({onSuccess:()=>{c.invalidateQueries({queryKey:Ae}),i()}}),C=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},w=Number.parseInt(_,10),T=r(()=>d.trim().length>0&&y.size>0&&!Number.isNaN(w)&&w>=1&&w<=1e3,[d,y,w]),E=()=>{T&&S.mutate({...e?{id:e.id}:{},label:d.trim(),cron:p.trim(),enabled:h,locationIds:Array.from(y),retentionCount:w})},D=S.error instanceof Error?S.error.message:null;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:n(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),s(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:s(b,{className:`h-4 w-4`})})]}),n(`div`,{className:`p-4 space-y-4`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),s(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Nightly offsite`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1.5`,children:[n(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,y.size,` selected)`]}),l.isLoading&&n(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[s(L,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!l.isLoading&&u.length===0&&s(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),u.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:u.map(e=>n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`checkbox`,checked:y.has(e.id),onChange:()=>C(e.id),className:`accent-primary`}),s(`span`,{className:`text-foreground`,children:e.displayName})]}),n(`div`,{className:`flex items-center gap-1.5`,children:[s(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),s(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),n(`div`,{className:`grid grid-cols-2 gap-3`,children:[n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),s(`input`,{type:`number`,min:1,max:1e3,value:_,onChange:e=>v(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),n(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),n(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`accent-primary`}),s(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),n(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),s(Ee,{value:p,onChange:m,disabled:S.isPending})]}),D&&s(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:D})]}),n(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[s(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),n(`button`,{onClick:E,disabled:!T||S.isPending,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[S.isPending&&s(L,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}t();var Me=2e3,Ne=5e3;function X(e){return e.state===`queued`||e.state===`running`}function Pe(e){if(e.state===`queued`)return{title:`Cancel queued backup run?`,message:`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`,confirmLabel:`Cancel run`,variant:`warning`};let t=e.completedDestinationIds.length;return{title:`Stop this backup run?`,message:`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. ${t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`}`,confirmLabel:`Stop run`,variant:`danger`}}function Fe(){let t=T(),[n,r]=o(null),i=ne(void 0,{refetchInterval:e=>(e.state.data??[]).some(X)?Me:Ne}),a=j({onSettled:()=>{r(null),i.refetch()}}),c=e(async e=>{await t(Pe(e))&&(r(e.id),a.mutate({runId:e.id}))},[t,a]);return s(Ie,{queryState:i.isError?`error`:i.data===void 0?`pending`:`ready`,runs:i.data??[],cancelingId:n,onCancelRequest:e=>{c(e)},now:Date.now()})}function Ie({queryState:e,runs:t,cancelingId:r,onCancelRequest:i,now:a}){let o=e===`ready`&&t.some(X),c=t.filter(e=>e.state===`running`),l=t.filter(e=>e.state===`queued`),u=t.filter(e=>!X(e)),d=[...c,...l,...u];return n(`section`,{className:`rounded-lg border border-border bg-surface`,children:[n(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[s(`h2`,{className:`text-xs font-semibold text-foreground`,children:`Runs`}),o&&n(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:`A backup run is in progress`,children:[s(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),`live`]}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:`One run executes at a time — queued runs wait in line.`})]}),e===`pending`&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:`Checking for backup runs…`}),e===`error`&&s(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:`Could not read backup runs — the orchestrator did not answer.`}),e===`ready`&&t.length===0&&s(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`}),e===`ready`&&t.length>0&&s(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs min-w-[720px]`,children:[s(`thead`,{children:n(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Run`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`State`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Progress`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Destinations`}),s(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Timing`}),s(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:`Actions`})]})}),s(`tbody`,{children:d.map(e=>s(Le,{run:e,canceling:r===e.id,onCancelRequest:i,now:a},e.id))})]})})]})}function Le({run:e,canceling:t,onCancelRequest:r,now:i}){let a=X(e);return n(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[n(`td`,{className:`px-3 py-2`,children:[s(`div`,{className:`text-foreground`,children:e.label??s(`span`,{className:`text-foreground-subtle italic`,children:`manual`})}),s(`div`,{className:`text-[10px] text-foreground-subtle font-mono`,title:e.id,children:e.id.slice(0,8)})]}),n(`td`,{className:`px-3 py-2`,children:[s(Re,{run:e}),e.state===`failed`&&e.error!==void 0&&s(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),s(`td`,{className:`px-3 py-2`,children:s(ze,{run:e})}),s(`td`,{className:`px-3 py-2`,children:s(Be,{run:e})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:s(Ve,{run:e,now:i})}),s(`td`,{className:`px-3 py-2`,children:s(`div`,{className:`flex justify-end`,children:a&&n(`button`,{onClick:()=>r(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?`Remove this run from the queue before it starts`:`Stop this run — the half-written archive is discarded`,children:[t?s(L,{className:`h-3 w-3 animate-spin`}):s(ee,{className:`h-3 w-3`}),e.state===`queued`?`Cancel`:`Stop`]})})})]})}function Re({run:e}){switch(e.state){case`queued`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[s(S,{className:`h-3 w-3`}),`Queued`]});case`running`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[s(L,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?`Uploading`:`Building archive`]});case`succeeded`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[s(O,{className:`h-3 w-3`}),`Succeeded`]});case`failed`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[s(C,{className:`h-3 w-3`}),`Failed`]});case`cancelled`:return n(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:`Stopped before completing every destination — not a success`,children:[s(B,{className:`h-3 w-3`}),`Stopped`]})}}function ze({run:e}){if(e.state===`queued`)return s(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?s(`span`,{className:`italic`,children:`waiting its turn`}):n(`span`,{className:`inline-flex items-center gap-1`,children:[s(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:He(e.queuePosition)}),`in line`]})});if(e.state===`running`&&e.phase===`building`)return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(fe,{className:`h-3 w-3 text-primary`}),s(`span`,{className:`tabular-nums font-medium animate-pulse`,children:q(e.stagedBytes)}),s(`span`,{className:`text-foreground-subtle`,children:`staged so far`})]});if(e.state===`running`){let t=e.archiveSizeBytes;return n(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[s(ge,{className:`h-3 w-3 text-primary`}),n(`span`,{className:`tabular-nums font-medium`,children:[q(e.uploadedBytes),t===void 0?``:` / ${q(t)}`]}),s(`span`,{className:`text-foreground-subtle`,children:`to current destination`})]})}let t=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return t===void 0?s(`span`,{className:`text-foreground-subtle italic`,children:`—`}):n(`span`,{className:`tabular-nums text-foreground`,children:[q(t),` archive`]})}function Be({run:e}){let t=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return t===0?s(`span`,{className:`text-foreground-subtle italic`,children:`not resolved yet`}):n(`div`,{className:`flex flex-col gap-0.5`,children:[n(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:[t,` target`,t===1?``:`s`]}),n(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&n(`span`,{className:`text-success`,title:`Kept their archive: ${e.completedDestinationIds.join(`, `)}`,children:[`✓ `,r,` completed`]}),i>0&&n(`span`,{className:`text-danger`,title:`Failed: ${e.failedDestinationIds.join(`, `)}`,children:[`✗ `,i,` failed`]})]})]})}function Ve({run:e,now:t}){return e.state===`queued`?n(`span`,{children:[`queued `,Z(t-e.requestedAt),` ago`]}):e.startedAt===void 0?s(`span`,{children:`—`}):e.finishedAt===void 0?n(`span`,{children:[`running for `,Z(t-e.startedAt)]}):n(`div`,{className:`flex flex-col gap-0.5`,children:[s(`span`,{children:Q(e.finishedAt)}),n(`span`,{className:`text-[10px]`,children:[`took `,Z(e.finishedAt-e.startedAt)]})]})}function He(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function Z(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function Q(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}t();var Ue=[[`backup`,`list`]];function We({initialDestinationId:e,initialArchiveId:t,onClose:i,onScheduled:l}){let u=a(),[d,f]=o(e&&t?2:1),[p,h]=o(e),[g,_]=o(t),[v,x]=o(new Set),{data:S}=z(),C=S??[],{data:w,isLoading:T}=F({destinationId:p??``},{enabled:!!p}),E=w??[];c(()=>{if(p!==void 0)return;let e=C.filter(e=>e.restoreSupported);e.length===1&&h(e[0].id)},[p,C]);let{data:D}=m({destinationId:p??``,backupId:g??``},{enabled:!!p&&!!g}),O=r(()=>D?.locations??[],[D]);c(()=>{O.length!==0&&x(e=>e.size===0?new Set(O):e)},[O]);let k=P({onSuccess:()=>{u.invalidateQueries({queryKey:Ue}),l(),i()}}),A=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},j=!!p&&!!g,M=v.size>0,N=j&&M&&!k.isPending,I=()=>{!p||!g||k.mutate({destinationId:p,backupId:g,locations:[...v]})};return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:i,children:n(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[n(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[n(`div`,{className:`space-y-0.5`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),n(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,d,` of 3 —`,` `,d===1?`pick source`:d===2?`pick locations`:`confirm`]})]}),s(`button`,{onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:s(b,{className:`h-4 w-4`})})]}),d===1&&s(Ge,{destinations:C,destinationId:p,onPickDestination:e=>{h(e),_(void 0),x(new Set)},archives:E,archivesLoading:T,archiveId:g,onPickArchive:_}),d===2&&s(Ke,{locations:O,picked:v,onToggle:A}),d===3&&s(qe,{destinationName:C.find(e=>e.id===p)?.displayName??p??``,archive:E.find(e=>e.id===g),picked:[...v]}),n(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[s(`div`,{children:d>1&&n(`button`,{onClick:()=>f(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[s(oe,{className:`h-3 w-3`}),`Back`]})}),n(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:i,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),d<3?n(`button`,{disabled:d===1&&!j||d===2&&!M,onClick:()=>f(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,s(re,{className:`h-3 w-3`})]}):n(`button`,{onClick:I,disabled:!N,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[k.isPending?s(L,{className:`h-3.5 w-3.5 animate-spin`}):s(y,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Ge({destinations:e,destinationId:t,onPickDestination:r,archives:i,archivesLoading:a,archiveId:o,onPickArchive:c}){let l=e.filter(e=>e.restoreSupported);return n(`div`,{className:`p-4 space-y-3`,children:[n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),n(`select`,{value:t??``,onChange:e=>r(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[s(`option`,{value:``,disabled:!0,children:`Select destination…`}),l.map(e=>n(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&a&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!a&&i.length===0&&s(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&i.length>0&&s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:i.map(e=>{let t=o===e.id;return n(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>c(e.id),className:`accent-primary`}),n(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),s(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),s(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:q(e.sizeBytes)})]},e.id)})})]})]})}function Ke({locations:e,picked:t,onToggle:r}){return e.length===0?s(`div`,{className:`p-4`,children:s(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):n(`div`,{className:`p-4 space-y-3`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),n(`div`,{className:`space-y-1.5`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),s(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>n(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>r(e),className:`accent-primary`}),s(`span`,{className:`font-mono text-foreground`,children:e}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ye(e)})]},e))})]})]})}function qe({destinationName:e,archive:t,picked:r}){return n(`div`,{className:`p-4 space-y-3 text-xs`,children:[s(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),n(`dl`,{className:`space-y-1.5`,children:[s($,{term:`Destination`,value:e}),s($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&s($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${q(t.sizeBytes)}`}),s($,{term:`Locations`,value:r.length>0?r.join(`, `):`— (full archive)`})]})]})}function $({term:e,value:t}){return n(`div`,{className:`flex justify-between gap-3`,children:[s(`dt`,{className:`text-foreground-subtle`,children:e}),s(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Je={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ye(e){return Je[e]??``}t();function Xe(){let e=T(),t=w(),[r,i]=o(null),[a,c]=o(!1),[l,u]=o(!1),[d,f]=o(void 0),p=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&t.mutate({confirm:!0})};return n(K,{children:[n(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[n(`button`,{onClick:()=>c(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[s(y,{className:`h-3.5 w-3.5`}),`Restore…`]}),n(`button`,{onClick:()=>f(null),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[s(k,{className:`h-3.5 w-3.5`}),`New entry`]})]}),l&&s(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2`,children:[s(y,{className:`h-3.5 w-3.5`}),s(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),n(`button`,{onClick:()=>{p()},disabled:t.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[t.isPending?s(L,{className:`h-3.5 w-3.5 animate-spin`}):s(y,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),s(Fe,{}),s(Ce,{onEdit:e=>f(e),onOpenRestoreWizard:e=>i(e)}),d!==void 0&&s(je,{entry:d,onClose:()=>f(void 0),onSaved:()=>f(void 0)}),(r||a)&&s(We,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),c(!1)},onScheduled:()=>u(!0)})]})}function Ze(){return s(`div`,{className:`flex flex-col p-4`,children:s(me,{tabs:[{id:`storage`,label:`Storage`,icon:I,content:s(_e,{})},{id:`backup`,label:`Backup`,icon:ce,content:s(Xe,{})}]})})}export{Ze as DataPage};
|
|
@@ -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-BddRivLE.js";import{$a as _,Bn as v,Ga as y,Gu as b,Ha as x,Iu as S,Ja as C,Ka as w,Kl as T,Lu as E,Mu as ee,Qa as D,Qn as O,Ua as k,Ud as A,Ul as j,Uu as M,Va as N,Vn as P,Wa as F,Xa as I,Ya as L,Za as R,au as z,cn as B,da as te,gu as ne,in as V,ln as re,on as H,or as U,pn as W,qa as G,rd as K,ru as ie,sn as q,su as J,un as Y}from"./src-DnQxdAYg.js";import{i as ae,n as oe,r as se,t as ce}from"./face-bbox-3mjLW0O1.js";import{t as X}from"./square-check-big-CpCHNAfP.js";import{t as Z}from"./user-round-1jRRPQok.js";import{ni as le}from"./client-BVesZTvN.js";import{L as ue}from"./index-NHwA6Zmb.js";import{t as de}from"./AdminPage-CiKtOLQm.js";import{n as fe,r as pe}from"./authed-media-_X4FXSBp.js";import{a as me,c as he,f as ge,i as _e,l as ve,n as ye,o as be,p as xe,r as Se,s as Ce,t as we,u as Te}from"./debounced-invalidate-On21l1Xj.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(Z,{className:`h-8 w-8`})})}),e.enrollable?r(a,{children:[c(v,{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(U,{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(K,{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(P,{variant:`secondary`,size:`sm`,disabled:a,onClick:l,children:[c(S,{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}=w(),m=x(),[h,g]=s([]),[_,v]=s(!1),[y,b]=s(null),[S,C]=s({}),[T,E]=s({}),[ee,D]=s(null),O=i(()=>(p??[]).map(e=>({id:e.id,name:e.name})),[p]),k=h.some(e=>e.status===`queued`||e.status===`analyzing`),A=k||_,j=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]),M=e(()=>{g([]),C({}),E({}),b(null),D(null),f.current&&(f.current.value=``)},[]),N=e(()=>{j(h),M(),a(!1)},[j,a,h,M]),F=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]),I=e(async e=>{g(t=>Ge(t,e.photoIndex,{status:`analyzing`,error:void 0}));try{let t=await F(e);g(n=>Ge(n,e.photoIndex,{status:`analyzed`,analysis:t}))}catch(t){g(n=>Ge(n,e.photoIndex,{status:`failed`,error:at(t)}))}},[F]),L=e(async e=>{if(e.length===0)return;j(h),M();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&&b(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){b(at(e));return}g(r),await We(r,2,e=>I(e))},[j,h,M,I]),R=Je(h,S),z=e(async()=>{v(!0),b(null),D(null);try{let e=Xe(h,S,T);if(e.kind===`error`){b(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(S,T,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=>F(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&&b(n.failures.join(` · `)),D(n.enrolled===0?`Nothing was enrolled.`:`Enrolled ${n.enrolled} sample${n.enrolled===1?``:`s`}${n.stampedModelId===null?``:` with ${n.stampedModelId}`}.`)}catch(e){b(at(e))}finally{v(!1)}},[F,m,S,T,h,d,l]),te=h.filter(e=>e.status===`analyzed`).length;return c(V,{open:n,onOpenChange:e=>e?a(!0):N(),children:r(H,{className:`max-w-3xl`,children:[r(re,{children:[c(Y,{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 L(Array.from(e.target.files??[]))}),r(P,{variant:`secondary`,size:`sm`,disabled:A,onClick:()=>f.current?.click(),children:[k?c(K,{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:[te,`/`,h.length,` photo`,h.length===1?``:`s`,` analysed`]})]}),y!==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:y})]}),ee!==null&&c(`div`,{className:`rounded-md border border-success/40 bg-success/10 px-3 py-2 text-xs text-success`,children:ee}),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:O,draft:S,newNames:T,disabled:A,onAssign:(t,n)=>C(r=>qe(r,e.photoIndex,t,n===rt?null:n)),onNameChange:(t,n)=>E(r=>({...r,[Ke(e.photoIndex,t)]:n})),onRetry:()=>void I(e)},e.photoIndex))}),r(B,{children:[c(P,{variant:`secondary`,onClick:N,disabled:_,children:`Close`}),r(P,{variant:`primary`,onClick:()=>void z(),disabled:A||R===0,children:[_?c(K,{className:`h-3.5 w-3.5 animate-spin`}):null,`Enrol `,R,` face`,R===1?``:`s`]})]})]})})}n();var lt=[[`faceGallery`]];function ut({identityId:e}){let t=o(),{data:n,isLoading:i}=G({identityId:e}),a=L();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(K,{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(Z,{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(T,{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,_]=s(!1),v=I(),y=F();function x(){u(e.name),f(!0)}function S(){f(!1),u(``)}function C(){let t=l.trim();if(!t||t===e.name){S();return}v.mutate({id:e.id,name:t},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),S()}})}function w(){y.mutate({id:e.id},{onSettled:()=>{i.invalidateQueries({queryKey:lt}),_(!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(oe,{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(Z,{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(W,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C(),e.key===`Escape`&&S()},className:`h-6 text-xs`,autoFocus:!0}),c(`button`,{type:`button`,onClick:C,disabled:v.isPending,className:`text-success hover:text-success/80 disabled:opacity-50`,"aria-label":`Confirm rename`,children:c(A,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:S,className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Cancel rename`,children:c(T,{className:`h-3.5 w-3.5`})})]}):c(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.name})}),c(U,{variant:`default`,className:`text-[10px]`,children:e.sampleCount}),!d&&r(`div`,{className:`flex items-center gap-1`,children:[c(`button`,{type:`button`,onClick:x,className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle hover:text-foreground`,"aria-label":`Rename`,children:c(b,{className:`h-3.5 w-3.5`})}),c(`button`,{type:`button`,onClick:()=>_(!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(V,{open:g,onOpenChange:e=>!e&&_(!1),children:r(H,{children:[r(re,{children:[c(Y,{children:`Delete person`}),r(q,{children:[`Delete `,c(`strong`,{children:e.name}),` and all their samples? This cannot be undone.`]})]}),r(B,{children:[c(P,{variant:`secondary`,onClick:()=>_(!1),children:`Cancel`}),r(P,{variant:`danger`,onClick:w,disabled:y.isPending,children:[y.isPending?c(K,{className:`h-3.5 w-3.5 animate-spin`}):null,`Delete`]})]})]})})]})}function ft(){let e=o(),[t,n]=s(``),i=x();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(W,{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(P,{variant:`primary`,size:`sm`,onClick:a,disabled:i.isPending||!t.trim(),children:[i.isPending?c(K,{className:`h-3.5 w-3.5 animate-spin`}):c(M,{className:`h-3.5 w-3.5`}),`Add`]})]})}function pt(){let{data:e,isLoading:t}=w(),[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(K,{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(P,{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=N(),l=x(),[u,d]=s(``),[f,p]=s(!1),[m,h]=s(null),g=e!==null&&e.length>0,_=e?.length??0;function v(){p(!1),d(``),h(null)}function y(){v(),n()}function b(t){!e||e.length===0||a.mutate({faceIds:[...e],identityId:t},{onSettled:()=>{i.invalidateQueries({queryKey:vt}),y()}})}function S(){!e||!u.trim()||l.mutate({name:u.trim()},{onSuccess:e=>{e?.id&&b(e.id)},onError:()=>{i.invalidateQueries({queryKey:vt}),y()}})}let C=a.isPending||l.isPending;return c(V,{open:g,onOpenChange:e=>!e&&y(),children:r(H,{children:[r(re,{children:[c(Y,{children:_>1?`Assign ${String(_)} 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(W,{placeholder:`New person name…`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&S()},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(B,{children:[c(P,{variant:`secondary`,onClick:y,disabled:C,children:`Cancel`}),f?r(P,{variant:`primary`,onClick:S,disabled:C||!u.trim(),children:[C&&c(K,{className:`h-3.5 w-3.5 animate-spin`}),`Create & assign`]}):r(P,{variant:`primary`,onClick:()=>m&&b(m),disabled:C||!m,children:[C&&c(K,{className:`h-3.5 w-3.5 animate-spin`}),`Assign`,_>1?` ${String(_)}`:``]})]})]})})}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 fe(pe(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}=y({faceId:e?.faceId??``},{enabled:e!==null}),[m,g]=s(`frame`),{frameSrc:_,naturalWidth:v,naturalHeight:b,failed:x}=bt(e?.keyFrameMediaId),S=i(()=>{let t=xt(d??[]);return t?t.url:_t(e)},[d,e]),C=i(()=>!e?.faceBbox||v===null||b===null?null:ce(e.faceBbox,v,b),[e?.faceBbox,v,b]);if(e===null)return null;let w=e.keyFrameMediaId!==void 0&&!x,E=w&&m===`frame`,D=e.assigned?e.identityName??`Assigned`:e.recognizedIdentityId?`${e.identityName??`Recognized`} (suggested)`:`Unassigned`;return c(V,{open:!0,onOpenChange:e=>!e&&n(),children:r(H,{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(T,{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:[w&&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(ee,{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`]})]}),E&&_?c(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:c(ye,{src:_,alt:`Full frame with detected face`,fit:`natural`,className:`w-full`,overlay:C?c(Ct,{box:C}):void 0})}):S?r(`div`,{className:`relative aspect-square w-full overflow-hidden rounded-lg border border-border`,children:[c(ye,{src:S,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(K,{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:xe(e.timestamp)}),c(St,{label:`Track`,value:e.trackId}),c(St,{label:`Identity`,value:D})]})]}),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(P,{variant:`secondary`,onClick:()=>o(e.faceId),disabled:u,children:[c(se,{className:`h-3.5 w-3.5`}),` Detach`]}):r(P,{variant:`primary`,onClick:()=>a(e.faceId),disabled:u,children:[c(ie,{className:`h-3.5 w-3.5`}),` Assign`]}),r(P,{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(ye,{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?z:T,{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:ge(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(K,{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=O(),g=k(),[_,v]=s(Nt),[y,b]=s(It),[x,S]=s(null),[C,w]=s({}),[ee,D]=s(null),{data:A,isFetching:j,refetch:M}=R({threshold:_,minClusterSize:y,limit:kt},{enabled:e}),N=A??[];l(()=>{w({})},[_,y]),l(()=>{if(N.length===0){S(null);return}N.some(e=>e.representativeFaceId===x)||S(N[0]?.representativeFaceId??null)},[N]);let F=i(()=>N.find(e=>e.representativeFaceId===x)??null,[N,x]),I=F?C[F.representativeFaceId]??new Set:new Set,L=i(()=>F?Dt(F,e=>n.has(e)):[],[F,n]),z=F?F.faceIds.length-L.length:0,B=F?Et({...F,faceIds:L},I):[];function te(e){if(!F)return;let t=F.representativeFaceId;w(n=>({...n,[t]:Tt(n[t]??new Set,e)}))}function re(){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:re})}function W(){D(null),t()}function G(){B.length!==0&&(p(B),W())}return r(V,{open:e,onOpenChange:e=>!e&&W(),children:[r(H,{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(ne,{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(T,{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:_,onChange:e=>v(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:_.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:y,onChange:e=>b(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(P,{variant:`secondary`,onClick:()=>{w({}),M()},disabled:j,children:[j?c(K,{className:`h-3.5 w-3.5 animate-spin`}):c(E,{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:j&&N.length===0?r(`div`,{className:`flex flex-1 items-center justify-center gap-2 py-8 text-xs text-foreground-subtle`,children:[c(K,{className:`h-4 w-4 animate-spin`}),` Finding similar faces…`]}):N.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:N.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===x,onSelect:()=>S(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`hidden shrink-0 flex-col gap-2 overflow-y-auto md:flex md:w-56`,children:N.map(e=>c(Lt,{cluster:e,face:n.get(e.representativeFaceId),active:e.representativeFaceId===x,onSelect:()=>S(e.representativeFaceId)},e.representativeFaceId))}),c(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:F&&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:L.map(e=>{let t=n.get(e);return t?c(Rt,{face:t,cameraName:u(t.deviceId),nowMs:d,excluded:I.has(e),onToggleExclude:()=>te(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(P,{variant:`secondary`,onClick:G,disabled:B.length===0,children:`Select in gallery`}),r(P,{variant:`primary`,onClick:()=>D(B),disabled:B.length===0,children:[c(ie,{className:`h-3.5 w-3.5`}),` Adopt (`,B.length,`)`]})]})]}),c(yt,{faceIds:ee,identities:f,onDone:()=>D(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=k(),g=()=>{u.invalidateQueries({queryKey:Bt})},_=()=>l(e.faceId),v=_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:[v===null?r(`button`,{type:`button`,onClick:_,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:v,alt:`Face from ${t}`,onClick:_,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(X,{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:ge(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(K,{className:`h-4 w-4 animate-spin`}):c(se,{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(ie,{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(K,{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(Ce),[d,p]=s(new Set),[m,g]=s(new Set),[v,y]=s(null),[b,x]=s(!1),[S,E]=s(null),{data:ee,isLoading:O}=C({limit:Vt,filter:t,includeCrops:!1},{refetchInterval:3e4}),{data:A=[]}=w(),{data:j}=te({isCamera:!0,projection:`slim`}),M=N(),F=D(),I=_(),L=k(),R=Date.now(),z=ee??[],B=i(()=>{let e=new Map;for(let t of j??[])e.set(t.id,t.name);return e},[j]),V=e=>B.get(e)??`Camera #${String(e)}`,re=i(()=>he(z).map(e=>({id:e,name:V(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[z,B]),H=i(()=>ve(Te(z,l),d),[z,l,d]),U=be(H,Ht,i(()=>JSON.stringify([t,l.fromMs,l.toMs,[...d].sort((e,t)=>e-t)]),[t,l.fromMs,l.toMs,d])),W=i(()=>new Map(z.map(e=>[e.faceId,e])),[z]),G=i(()=>gt(H),[H]),q=S===null?null:W.get(S)??null,J=()=>{e.invalidateQueries({queryKey:Bt})},Y=()=>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 oe(e){g(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})}function ce(){oe(ht(H))}let X=[...m],Z=M.isPending||I.isPending||L.isPending,le=F.isPending||L.isPending;function ue(){X.length!==0&&I.mutate({faceIds:X},{onSettled:()=>{J(),Y()}})}function de(){X.length!==0&&Promise.allSettled(X.map(e=>L.mutateAsync({faceId:e}))).then(()=>{J(),Y()})}function fe(e){E(null),y([e])}function pe(e){F.mutate({faceId:e},{onSettled:J}),E(null)}function ge(e){L.mutate({faceId:e},{onSettled:J}),E(null)}let ye=H.length!==z.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(Se,{onChange:u}),c(_e,{cameras:re,selected:d,onChange:p}),r(`button`,{type:`button`,onClick:()=>x(!0),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${b?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[c(ne,{className:`h-3.5 w-3.5`}),` Similar groups`]}),!O&&G>0&&r(`button`,{type:`button`,onClick:ce,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 `,G,` crop-less`]}),!O&&c(`span`,{className:`text-[10px] text-foreground-subtle ${G>0?`ml-2`:`ml-auto`}`,children:ye?`${String(H.length)} of ${String(z.length)} faces`:`${String(H.length)} face${H.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(P,{variant:`primary`,onClick:()=>y(X),disabled:Z,children:[c(ie,{className:`h-3.5 w-3.5`}),` Assign`]}),r(P,{variant:`secondary`,onClick:ue,disabled:Z,children:[I.isPending?c(K,{className:`h-3.5 w-3.5 animate-spin`}):c(se,{className:`h-3.5 w-3.5`}),` `,`Detach`]}),r(P,{variant:`secondary`,onClick:de,disabled:Z,children:[c(h,{className:`h-3.5 w-3.5`}),` Delete`]}),c(P,{variant:`ghost`,onClick:Y,disabled:Z,children:c(T,{className:`h-3.5 w-3.5`})})]})]}),O&&r(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[c(K,{className:`h-4 w-4 animate-spin`}),` Loading faces…`]}),!O&&H.length===0&&c(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:z.length>0?`No faces match the current date / camera filters.`:`No faces found for this filter.`}),!O&&H.length>0&&r(a,{children:[c(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(6.5rem,1fr))] gap-2`,children:U.pageItems.map(e=>c(Ut,{face:e,cameraName:V(e.deviceId),nowMs:R,selected:m.has(e.faceId),onToggleSelect:ae,onAssign:e=>y([e]),onOpenDetail:E},e.faceId))}),c(me,{currentPage:U.page,totalItems:U.totalItems,pageSize:U.pageSize,onPageChange:U.setPage,itemNoun:`faces`})]}),c(wt,{face:q,cameraName:q?V(q.deviceId):``,onClose:()=>E(null),onAssign:fe,onUnassign:pe,onDelete:ge,actionsPending:le}),c(yt,{faceIds:v,identities:A,onDone:()=>{y(null),Y()}}),c(zt,{open:b,onClose:()=>x(!1),byId:W,cameraName:V,nowMs:R,identities:A,selectMany:oe})]})}n();var Kt=[[`faceGallery`]],qt=2e3;function Jt(){let e=o(),n=t(e);n.current=e;let r=t(void 0);r.current||=we({delayMs:qt,invalidate:()=>{n.current.invalidateQueries({queryKey:Kt})}}),l(()=>()=>r.current?.cancel(),[]),j(le.PipelineAnalyticsFaceGalleryChanged,()=>{r.current?.trigger()})}function Yt(){return Jt(),c(de,{icon:ue,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};
|