@camstack/addon-admin-ui 1.2.382 → 1.2.383
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonAssetIcon-CSPa1pdd.js → AddonAssetIcon-CGHE_dHd.js} +1 -1
- package/dist/assets/AddonIntegrationBody-BY8ZJ1gK.js +1 -0
- package/dist/assets/{Addons-zKXMiTgS.js → Addons-D_NdyZ25.js} +2 -2
- package/dist/assets/{AdminPage-CKxdhLBh.js → AdminPage-CypZrzwh.js} +1 -1
- package/dist/assets/AdminSectionedPage-DIjr4rPP.js +1 -0
- package/dist/assets/{AiProfiles-20FE0uz4.js → AiProfiles-DVBA8N8z.js} +1 -1
- package/dist/assets/{BrokerForm-CC5vlB6J.js → BrokerForm-RzhDFRN_.js} +1 -1
- package/dist/assets/Build-R0nJdvAY.js +40 -0
- package/dist/assets/{Calendars-C7hVIOp2.js → Calendars-Bt-vx65e.js} +1 -1
- package/dist/assets/Cluster-D5jACE9H.js +1 -0
- package/dist/assets/ClusterStepModel-DHFmP8fZ.js +1 -0
- package/dist/assets/{CompositionEditor-NKRxjmjH.js → CompositionEditor-DhY-4ig2.js} +1 -1
- package/dist/assets/{CompositionEditorPage-WxJyh5SN.js → CompositionEditorPage-jVFg06vj.js} +1 -1
- package/dist/assets/{Data-DF90X0g2.js → Data-Cg-gwO2g.js} +1 -1
- package/dist/assets/{DeviceDetail-bTQDICGS.js → DeviceDetail-BT35tdU8.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-CUn6dldJ.js → DeviceDoActionFields-DNK6VlKf.js} +1 -1
- package/dist/assets/{Devices-Bzod2YPx.js → Devices-BH9rnVil.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Dtpaqat6.js → EmbedPlayerPage-CXJOZURH.js} +1 -1
- package/dist/assets/Identity-D-IiFqqz.js +1 -0
- package/dist/assets/IntegrationDetail-D5XcoFW_.js +1 -0
- package/dist/assets/Integrations-BzSKpt4h.js +1 -0
- package/dist/assets/{Integrations-C36coZkR.js → Integrations-Ct8MGSZx.js} +1 -1
- package/dist/assets/Library-Vhx5FjI5.js +1 -0
- package/dist/assets/Locations-CPujYQkv.js +3 -0
- package/dist/assets/{Logs-Ca_HuvcS.js → Logs-B7S5VHCy.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BbOnxwDN.js → MotionZonesSettings-ChwhaFL5.js} +1 -1
- package/dist/assets/{MyAccess-BUF_fBQs.js → MyAccess-CYrQqx-n.js} +1 -1
- package/dist/assets/{Network-DsA3IvEH.js → Network-C17cZn3W.js} +1 -1
- package/dist/assets/NodeAddonsSettingsPanel-D3Jc-y6k.js +1 -0
- package/dist/assets/Notifications-DUyur2d8.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-B8E2Jjy5.js → PrivacyMaskSettings-BM5XPIdA.js} +1 -1
- package/dist/assets/{Recordings-Bw4PcTDY.js → Recordings-D01OlVFo.js} +1 -1
- package/dist/assets/{ScanNetworkModal-B0-S-15i.js → ScanNetworkModal-D2lfc8pP.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-BFZ3oTIz.js → SceneMonitorEditor-0LjWD_pU.js} +1 -1
- package/dist/assets/{SessionsList-DZPXHEho.js → SessionsList-D0Z-bb1X.js} +2 -2
- package/dist/assets/{Showroom-HnF21NoG.js → Showroom-DRSdclUn.js} +1 -1
- package/dist/assets/System-CCjprs8V.js +1 -0
- package/dist/assets/{Terminal-Btfmq8z7.js → Terminal-D9LB32rC.js} +1 -1
- package/dist/assets/{Viewer-Bp3AMLSN.js → Viewer-2M0ylOw3.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BHqsyNfC.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BgPIzpZC.js} +1 -1
- package/dist/assets/{archive-CJfmV07C.js → archive-DkKvhgYZ.js} +1 -1
- package/dist/assets/{authed-media-krq7cFK5.js → authed-media-DmJCnyAU.js} +1 -1
- package/dist/assets/{boxes-X_rDWdou.js → boxes-N_8REhrI.js} +1 -1
- package/dist/assets/circle-slash-BzeOqvpP.js +1 -0
- package/dist/assets/{client-B2uiK_6q.js → client-tKRKHAfe.js} +1 -1
- package/dist/assets/crop-CU4-9FgF.js +1 -0
- package/dist/assets/{device-integration-icon-BzUlpgwp.js → device-integration-icon-DfmaqyiI.js} +1 -1
- package/dist/assets/device-picker-model-CdxP7UkM.js +1 -0
- package/dist/assets/{dist-tT_Ns69g.js → dist-BCmVYFXW.js} +1 -1
- package/dist/assets/{dist-DkXpG0Wn.js → dist-gYMznef8.js} +2 -2
- package/dist/assets/{format-size-B4KE3z8i.js → format-size-BuyX1HQn.js} +1 -1
- package/dist/assets/{history-BVPkDM04.js → history-BJ_1Cv2l.js} +1 -1
- package/dist/assets/{hostInit-tROHpLNF.js → hostInit-CyEtnNFN.js} +1 -1
- package/dist/assets/{index-DpCn0dLh.js → index-Bjrvl1f3.js} +3 -3
- package/dist/assets/{index-DvqtCSIh.css → index-DtcBoptX.css} +1 -1
- package/dist/assets/{layers-Bg9_2Fck.js → layers-BGzuaLQ3.js} +1 -1
- package/dist/assets/{location-owned-usage-Di30oDYo.js → location-owned-usage-tqd-wYKU.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-73d036c0.js → mf-entry-bootstrap-0-9dc3e469.js} +2 -2
- package/dist/assets/{monitor-smartphone-5lHVpcLH.js → monitor-smartphone-VXk6kWa5.js} +1 -1
- package/dist/assets/mount-CdxP7UkM.js +1 -0
- package/dist/assets/{notification-schedule-field-CvweO84u.js → notification-schedule-field-K1sNMmx4.js} +1 -1
- package/dist/assets/{octagon-alert-Bn06fTVi.js → octagon-alert-D14SAZE5.js} +1 -1
- package/dist/assets/{player-overlays-Sm-ivm_8.js → player-overlays-Gj8o_n4X.js} +1 -1
- package/dist/assets/remoteEntry-HJa-d3BT.js +1 -0
- package/dist/assets/{send-TxnVMKnC.js → send-BE-aSLQv.js} +1 -1
- package/dist/assets/{settings-2-BAm45F1t.js → settings-2-DAMMEuMJ.js} +1 -1
- package/dist/assets/{src-D-Gp-jKI.js → src-CoX6DWRw.js} +17 -17
- package/dist/assets/{use-scenes-feed-_AMV4hTX.js → use-scenes-feed-D9DWklxj.js} +1 -1
- package/dist/assets/{use-stationary-objects-DKJzY3wc.js → use-stationary-objects-CRAk6z8Y.js} +1 -1
- package/dist/assets/useEventInvalidation-CdxP7UkM.js +1 -0
- package/dist/assets/useNodeUrlSelection-DLap5xNo.js +1 -0
- package/dist/assets/user-round-CEze1eTI.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BMm3si9a.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BWZVzJfl.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/addon.js +20 -2
- package/package.json +1 -1
- package/dist/assets/AddonIntegrationBody-C9N9V3gJ.js +0 -1
- package/dist/assets/AdminSectionedPage-tI4gVEsh.js +0 -1
- package/dist/assets/Build-DB3lwg8g.js +0 -40
- package/dist/assets/Cluster-CtMNB7lJ.js +0 -1
- package/dist/assets/ClusterStepModel-Cj-HjjR9.js +0 -1
- package/dist/assets/Identity-CWCGBs24.js +0 -1
- package/dist/assets/IntegrationDetail-B96YgSIx.js +0 -1
- package/dist/assets/Integrations-MmWPpB2n.js +0 -1
- package/dist/assets/Library-J7hH6KXX.js +0 -1
- package/dist/assets/Locations-ChUUt-FK.js +0 -3
- package/dist/assets/NodeAddonsSettingsPanel-DFxGT0UJ.js +0 -1
- package/dist/assets/Notifications-D0jyJN0J.js +0 -1
- package/dist/assets/System-xGEhcmxg.js +0 -1
- package/dist/assets/circle-slash-C9dO41QA.js +0 -1
- package/dist/assets/crop-o1ZnayCW.js +0 -1
- package/dist/assets/device-picker-model-CQJ7chdb.js +0 -1
- package/dist/assets/mount-CQJ7chdb.js +0 -1
- package/dist/assets/remoteEntry-CGlo-x_4.js +0 -1
- package/dist/assets/useEventInvalidation-CQJ7chdb.js +0 -1
- package/dist/assets/useNodeUrlSelection-CSWTT3qU.js +0 -1
- package/dist/assets/user-round-BLTQwaog.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,W as a,b as o,i as s,o as c,p as l,q as u,x as d,z as f}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{A as p,D as m,N as h,O as g,T as _,V as v,_t as y,b,ct as x,dt as S,gt as C,j as w,k as T,ot as E,v as D,y as O,yt as k,z as A}from"./player-overlays-Sm-ivm_8.js";import{$l as j,$u as M,An as N,As as P,Bs as F,C as ee,Cd as I,Cn as L,Cs as te,Ds as ne,E as re,Es as ie,F as R,Fn as ae,Gn as z,Gs as oe,H as se,Hn as B,Hs as ce,Ht as le,In as ue,J as de,Js as fe,Jt as pe,Ks as me,Ls as he,Lu as ge,Mn as _e,Mt as ve,Nn as ye,Ns as be,O as xe,Od as Se,Os as Ce,Ou as we,Pf as Te,Pn as Ee,Ql as De,Qs as Oe,Rd as ke,Rs as Ae,S as je,Sn as Me,Sr as Ne,Ss as Pe,T as Fe,Td as Ie,Ts as Le,Tt as Re,Un as ze,Ut as Be,Vd as Ve,Vs as He,Vt as V,W as Ue,Wn as H,Ws as We,Xs as Ge,Xu as Ke,Y as qe,Ys as Je,Yt as Ye,Zd as U,Zl as Xe,Zs as Ze,_u as Qe,ad as $e,bn as et,cc as tt,cn as nt,cu as rt,dc as it,du as at,fd as ot,fn as st,fu as ct,gn as lt,hn as ut,id as dt,jn as ft,kn as pt,ks as mt,lc as ht,ln as gt,lu as _t,mn as vt,nr as yt,oc as bt,ou as W,pc as xt,pn as St,pu as Ct,qt as wt,qu as Tt,r as Et,sc as Dt,su as Ot,uc as kt,un as At,ur as G,uu as jt,va as Mt,vn as Nt,vr as Pt,vt as Ft,w as It,wd as Lt,ws as Rt,xu as zt,yn as Bt,yr as K}from"./src-D-Gp-jKI.js";import{t as Vt}from"./crop-o1ZnayCW.js";import{t as Ht}from"./layers-Bg9_2Fck.js";import{An as Ut,Br as Wt,Dn as Gt,En as Kt,Mn as qt,On as Jt,Tn as Yt,c as Xt,fi as Zt,jn as Qt,kn as $t,l as en,m as tn,vi as nn,wn as rn,zr as an}from"./client-B2uiK_6q.js";import{n as on}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{U as sn,X as cn,at as ln,et as un,it as dn}from"./index-DpCn0dLh.js";import"./useEventInvalidation-CQJ7chdb.js";import{t as fn}from"./NodeAddonsSettingsPanel-DFxGT0UJ.js";import{a as pn,c as mn,d as hn,g as gn,h as _n,i as vn,l as yn,n as bn,o as xn,p as Sn,r as Cn,s as wn,t as Tn}from"./board-model-Bmts6hrg.js";var En=k(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),Dn=k(`crown`,[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]),On=k(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),kn=k(`scale`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`m19 8 3 8a5 5 0 0 1-6 0zV7`,key:`zcdpyk`}],[`path`,{d:`M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1`,key:`1yorad`}],[`path`,{d:`m5 8 3 8a5 5 0 0 1-6 0zV7`,key:`eua70x`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}]]),An=k(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]),jn=`step`,Mn=[jn,`acc`];function Nn(e,t){return`${e}/${t}`}function Pn(e,t,n){let r=n.step!==null&&e.includes(n.step),i=n.acc!==null&&t.includes(n.acc);return{stepId:r?n.step:null,acceleratorId:i?n.acc:null,staleStepId:n.step!==null&&n.step!==``&&!r&&e.length>0?n.step:null}}function Fn(e){if(e==null)return null;if(typeof e==`number`)return e>0?e:null;let t=Date.parse(e);return Number.isNaN(t)?null:t}function In(e){return e}function Ln(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function Rn(e,t){return typeof e==`boolean`?e:In(t)}function zn(e,t){return{pipeline:Rn(Ln(e,`detect`),t),audio:Rn(Ln(e,`audio`),t),ingest:Rn(Ln(e,`ingest`),t)}}function Bn(e,t,n){let r=e?.find(e=>e.nodeId===t);return zn(r?.settings,n)}function Vn({selectedNodeId:e,onSelect:t,refreshToken:n}){let{nodes:r}=Ot(),{data:a}=F(void 0),{data:s}=We(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=r??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return i(`div`,{className:`flex flex-col h-full`,children:[i(`button`,{type:`button`,onClick:()=>t(ko),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[d(dn,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[d(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),d(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Assignments, load balancing, roles`})]})]}),d(`div`,{className:`flex-1 overflow-y-auto`,children:l.map(n=>{let r=e===n.id,a=c.get(n.id)??0,l=n.isHub?Ke:U,u=Bn(s,n.id,n.isHub),f=n.isOnline?null:Ft(Fn(n.lastSeen));return i(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${r?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[d(l,{className:`h-4 w-4 flex-shrink-0`}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-danger flex-shrink-0`}),n.isOnline&&d(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),i(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[i(`span`,{children:[n.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[d(zt,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{className:`text-danger`,children:[`offline`,f===null?``:` · ${f}`]})]})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[d(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`}),d(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`]}),f>0&&i(`span`,{className:`text-danger`,children:[f,` offline`]})]})]})}function Hn({nodeId:e,refreshToken:t}){let{nodes:n}=Ot(),r=n?.find(t=>t.id===e),a=rt(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?i(`div`,{className:`px-6 py-4 border-b border-border`,children:[i(`div`,{className:`flex items-center gap-2 mb-1`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):d(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-danger/10 text-danger`,children:`offline`}),r.isHub&&d(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),i(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[d(`span`,{children:r.cpuModel??`CPU`}),d(`span`,{children:`•`}),i(`span`,{children:[r.cpuCores,` cores`]}),d(`span`,{children:`•`}),i(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&i(o,{children:[d(`span`,{children:`•`}),i(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),d(`span`,{children:`•`}),i(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),d(`span`,{children:`•`}),i(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&i(o,{children:[d(`span`,{children:`•`}),d(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):d(`div`,{className:`px-6 py-4 border-b border-border`,children:i(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}var Un=[`assignments`,`tree`,`engines`,`logs`];r();function Wn({refreshToken:e,nodeId:t}){let[n,r]=u(new Map),{nodes:o}=W();jt(`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}=P(void 0),c=a(()=>{let e=new Map;for(let t of s??[])e.set(t.nodeId,t.deviceCount);return e},[s]),l=a(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),f=a(()=>{let e=new Map;for(let t of o)e.set(t.id,t.shortName);return e},[o]),p=a(()=>{let e=0,t=0,n=0,r=0,i=0;for(let a of l.values())e+=a.attachedCameras,t+=a.activeCameras,n+=a.totalFps,r+=a.totalInferenceWeighted,i+=a.queueDepth;let a=e>0?r/e:0;return{totalAgents:o.length,onlineAgents:o.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:a,queueDepth:i,totalFps:n}},[l,o]);if(t){let e=l.get(t);return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[d(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),d(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),d(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),d(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),d(q,{label:`Audio`,value:String(c.get(t)??`—`)})]})]})}let m=[...l.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return i(`div`,{className:`@container/liveload`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),i(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[d(q,{label:`Total agents`,value:`${p.onlineAgents}/${p.totalAgents}`}),d(q,{label:`Active / Attached`,value:`${p.activeCameras}/${p.attachedCameras}`}),d(q,{label:`Total FPS`,value:p.totalFps.toFixed(1)}),d(q,{label:`Avg inference ms`,value:p.avgInferenceTimeMs.toFixed(0)}),d(q,{label:`Queue depth`,value:String(p.queueDepth)})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[480px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),d(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),d(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),d(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),d(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),d(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),i(`tbody`,{children:[m.map(([e,t])=>i(`tr`,{className:`border-t border-border`,children:[d(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:f.get(e)??e}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:c.get(e)??`—`})]},e)),m.length===0&&d(`tr`,{children:d(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[d(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),d(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}var Gn={active:!1,pinned:!1,nodeId:null,reason:``};function Kn(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function qn(e,t,n){let r=new Map(t.map(e=>[e.deviceId,e])),i=new Map(n.map(e=>[e.deviceId,e]));return e.map(e=>{let t=r.get(e.id),n=i.get(e.id),a=t?{active:!0,pinned:t.pinned,nodeId:t.agentNodeId,reason:t.reason??``}:Gn,o=n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:Gn;return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:a,detection:a,decoder:Gn,audio:o}}).toSorted(Kn)}function Jn(e,t,n){return{active:e!==null,pinned:t,nodeId:e,reason:n??``}}function Yn(e,t){let n=new Map(t.map(e=>[e.deviceId,e.assignment]));return e.map(e=>{let t=n.get(e.deviceId);return t===void 0?e:{...e,detection:Jn(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:Jn(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:Jn(t.audioNodeId,t.pinned.audio,t.reasons.audio)}})}function Xn(e,t,n){let r=(t,n,r)=>({active:t!==null&&t===e,pinned:n,nodeId:t,reason:r??``});return t.map(({deviceId:e,assignment:t})=>({deviceId:e,deviceName:n(e),detection:r(t.detectionNodeId,t.pinned.detection,t.reasons.detection),decoder:r(t.decoderNodeId,t.pinned.decoder,t.reasons.decoder),audio:r(t.audioNodeId,t.pinned.audio,t.reasons.audio)})).filter(e=>e.detection.active||e.decoder.active||e.audio.active).toSorted(Kn)}function Zn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>{let n=t.get(e);return n!==void 0&&n!==``?n:e}}function Qn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??`Camera ${e}`}function $n(e,t,n){return[{value:`auto`,label:`Auto`},...[...new Set([...e.nodeId===null?[]:[e.nodeId],...t.map(e=>e.id)])].map(e=>({value:e,label:`Pin → ${n(e)}`}))]}function er({roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:i,emphasizeOnNodeId:a}){if(n.nodeId===null)return null;let o=n.nodeId,s=a===void 0?!1:n.active&&o===a;return d(wt,{roleId:e,roleLabel:t,nodeName:r(o),colorId:Ye(i,o),emphasized:s,pinned:n.pinned})}function tr({detection:e,decoder:t,audio:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o}){let s=(e,t,n)=>d(er,{roleId:e,roleLabel:t,state:n,nameOf:r,colorByNodeId:a,emphasizeOnNodeId:o},e);return i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[s(`detection`,`Detection`,e),s(`decode`,`Decode`,t),s(`audio`,`Audio`,n)]})}function nr({snap:e}){if(e===void 0)return d(`div`,{className:`flex h-8 items-center text-[11px] text-foreground-subtle`,title:`No metrics in the last 10 s — the camera has no session running`,children:`no live data`});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:a,configuredFps:o,droppedFrames:s}=e.metrics,c=ve(t);return i(`div`,{className:`flex h-8 min-w-0 flex-col justify-center font-mono text-[10px] leading-tight tabular-nums`,children:[i(`span`,{className:`inline-flex min-w-0 items-center gap-1 ${c.textColor}`,children:[d(R,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),d(`span`,{className:`truncate font-semibold uppercase tracking-wider`,children:c.label}),d(`span`,{className:`text-foreground`,children:n.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[`/`,o.toFixed(0),` fps`]})]}),i(`span`,{className:`truncate text-foreground-subtle`,children:[d(`span`,{className:`text-foreground`,children:r.toFixed(0)}),` ms`,a>0&&i(`span`,{className:`ml-1 text-warning`,children:[`q`,a]}),i(`span`,{className:s>0?`ml-1 text-warning`:`ml-1`,children:[`drops `,s]})]})]})}r();var rr=1e4,ir=5e3;function ar(e){let[t,n]=u(new Map);return jt(`pipeline.camera-metrics-snapshot`,t=>{let r=t.data;typeof r.deviceId==`number`&&(e!==void 0&&r.nodeId!==e||n(e=>new Map(e).set(r.deviceId,r)))}),f(()=>{if(t.size===0)return;let e=setInterval(()=>{n(e=>{let t=Date.now()-rr,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},ir);return()=>clearInterval(e)},[t.size]),t}var or=3e5;function sr({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:i}){return d(H,{"aria-label":`Node pin`,title:`Auto lets each session pick its node; a pin keeps the camera on one node.`,value:e.pinned&&e.nodeId!==null?e.nodeId:`auto`,disabled:r,options:[...$n(e,t,n)],onChange:e=>i(e.target.value)})}function cr({deviceId:e,nodeId:t}){let n=c(),{data:r}=He({deviceId:e},{refetchOnMount:`always`}),{data:i}=Ae({nodeId:t},{staleTime:or}),a=Dt({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});if(r===void 0||i===void 0)return d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`accelerator: …`});let o=i.devices??[],s=o.filter(e=>e.enabled),l=r?.deviceKey??`auto`,u=l!==`auto`&&!s.some(e=>e.key===l),f=o.find(e=>e.key===l),p=[{value:`auto`,label:`Any accelerator`},...u?[{value:l,label:`${f?`${Me(f)} (${l})`:l} (not enabled)`}]:[],...s.map(e=>({value:e.key,label:`${Me(e)} · ${e.format}`}))];return d(H,{"aria-label":`Inference device pin`,title:`Pin detection to one accelerator of the node, or let each session pick.`,value:l,disabled:a.isPending,options:p,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value})})}r();function lr(e){let t=n(null);return e.nodeId!==null&&(t.current=e),t.current}function ur({deviceId:e,state:t,...n}){let r=lr(t);return i(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[d(sr,{state:t,...n}),r?.nodeId==null?d(H,{"aria-label":`Inference device pin (no node yet)`,title:`An accelerator is pinned on the camera's node; this camera has not run on one yet.`,disabled:!0,defaultValue:`auto`,options:[{value:`auto`,label:`Any accelerator`}]}):d(cr,{deviceId:e,nodeId:r.nodeId})]})}function dr({state:e,nameOf:t}){let n=lr(e);if(n?.nodeId==null)return d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`— no session yet`});let r=e.active&&e.nodeId!==null,a=n.pinned?`pinned`:`auto · ${n.reason||`capacity`}`;return i(`div`,{"data-testid":`resolved-placement`,className:`flex w-40 min-w-0 flex-col leading-tight`,title:n.pinned?void 0:`An unpinned camera is placed again at every session start, so this can change between sessions.`,children:[i(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[d(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${r?`bg-success`:`bg-foreground-subtle/40`}`}),d(`span`,{"data-testid":`resolved-placement-node`,className:`truncate font-medium ${r?`text-foreground`:`text-foreground-muted`}`,children:t(n.nodeId)})]}),d(`span`,{className:`truncate pl-3 text-[10px] ${n.pinned?`text-warning`:`text-foreground-subtle`}`,children:r?a:`${a} · idle, last session`})]})}function fr({deviceId:e,deviceName:t}){let[n,r]=u(!1);return i(o,{children:[d(De,{icon:$e,variant:`ghost`,size:`sm`,"aria-label":`Stream brokers of ${t}`,title:`Stream brokers & clients`,onClick:()=>r(!0)}),d(N,{open:n,onOpenChange:r,children:i(_e,{width:`lg`,scroll:`body`,placement:`sheet-on-mobile`,children:[d(ae,{children:i(ue,{children:[t,` — stream brokers & clients`]})}),d(ft,{children:n&&d(pt,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e,instanceId:`pipeline-row/${e}`,config:{variant:`compact`}})})]})})]})}function pr(e){return e.hasFreshMetrics?`active`:e.hasPipelineAssignment?`recently-active`:`inactive`}function mr(e,t){return t.size===0?!0:t.has(e)}var hr=[{value:`active`,label:`Active`},{value:`recently-active`,label:`Recently active`},{value:`inactive`,label:`Inactive`}];r();var gr=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function _r(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function vr(){let e=c();Et([`pipelineOrchestrator`,`getPipelineAssignments`],gr),Et([`pipelineOrchestrator`,`getAudioAssignments`],gr),Et([`pipelineOrchestrator`,`getCameraStatuses`],gr);let{data:t}=Mt({isCamera:!0,projection:`slim`}),{data:n}=F(void 0),{data:r}=mt(void 0),{data:o}=be({}),{data:s}=We(void 0),{nodes:l}=W(),f=ar(),p=a(()=>Zn(l),[l]),m=a(()=>pe(s),[s]),h=a(()=>l.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[l]),g=a(()=>Yn(qn((t??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),n??[],r??[]),o??[]),[t,n,r,o]),[_,v]=u(()=>new Set),y=a(()=>g.filter(e=>mr(pr({hasPipelineAssignment:e.pipeline.active,hasFreshMetrics:f.has(e.deviceId)}),_)),[g,f,_]),x=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=()=>_r(e),C=ne({onSuccess:S}),w=it({onSuccess:S}),T=C.isPending||w.isPending,E=[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[d(cn,{to:`/devices/${String(e.deviceId)}`,className:`min-w-0 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName}),e.disabled&&d(G,{variant:`default`,children:`off`})]})},{key:`placement`,header:`Placement`,width:`w-80`,notSortableReason:`A pair of controls — editing one would move the row under the cursor.`,render:e=>d(ur,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:h,nameOf:p,pending:T,onChange:t=>t===`auto`?w.mutate({deviceId:e.deviceId}):C.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:e=>d(tr,{detection:e.detection,decoder:e.decoder,audio:e.audio,nameOf:p,colorByNodeId:m})},{key:`resolved`,header:`Running on`,width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:p(e.pipeline.nodeId),render:e=>d(dr,{state:e.pipeline,nameOf:p})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>f.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(nr,{snap:f.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>d(fr,{deviceId:e.deviceId,deviceName:e.deviceName})}],k=t===void 0?`Loading cameras…`:g.length===0?`No cameras`:`No cameras match this activity filter.`;return i(`div`,{className:`flex flex-col gap-2`,children:[d(`nav`,{"aria-label":`Filter by camera activity`,"data-testid":`assignments-activity-filter`,children:d(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:hr.map(e=>{let t=_.has(e.value);return d(`button`,{type:`button`,"aria-pressed":t,"data-testid":`assignments-activity-${e.value}`,className:j(O,t?D:b),onClick:()=>x(e.value),children:e.label},e.value)})})}),d(le,{columns:E,rows:y,rowKey:e=>e.deviceId,minWidthPx:920,mobileMode:`scroll`,maxBodyHeight:Be,emptyMessage:k})]})}r();function yr({nodeId:e}){let t=c();Et([`pipelineOrchestrator`,`getCameraStatuses`],gr);let{data:n}=be({}),{data:r}=We(void 0),{data:i}=Mt({isCamera:!0,projection:`slim`}),{nodes:o}=W(),s=ar(),l=a(()=>Zn(o),[o]),u=a(()=>pe(r),[r]),f=a(()=>Xn(e,n??[],Qn((i??[]).map(e=>({id:e.id,name:e.name})))),[e,n,i]),p=o.filter(t=>t.isOnline&&t.id!==e),m=()=>_r(t),h=ne({onSuccess:m}),g=it({onSuccess:m}),_=ie({onSuccess:m}),v=kt({onSuccess:m}),y=e=>[...e.detection.active?p.map(t=>({id:`detect-${t.id}`,label:`Move detection to ${t.name}`,onClick:()=>h.mutate({deviceId:e.deviceId,agentNodeId:t.id})})):[],...e.audio.active?p.map(t=>({id:`audio-${t.id}`,label:`Move audio to ${t.name}`,onClick:()=>_.mutate({deviceId:e.deviceId,nodeId:t.id})})):[],{id:`unpin-detect`,label:`Unpin detection`,hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>g.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:`Unpin audio`,hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>v.mutate({deviceId:e.deviceId})}];return d(le,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>d(cn,{to:`/devices/${String(e.deviceId)}`,className:`block w-44 truncate text-xs font-medium text-primary hover:underline`,title:e.deviceName,children:e.deviceName})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:t=>d(tr,{detection:t.detection,decoder:t.decoder,audio:t.audio,nameOf:l,colorByNodeId:u,emphasizeOnNodeId:e})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(nr,{snap:s.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>d(Ue,{items:y(e),title:`Move ${e.deviceName}`})}],rows:f,rowKey:e=>e.deviceId,minWidthPx:560,mobileMode:`scroll`,maxBodyHeight:Be,emptyMessage:n===void 0?`Loading cameras…`:`No camera runs on this node right now`})}function br({nodeId:e,refreshToken:t}){let{nodes:n}=W(),r=n.find(t=>t.id===e)?.name??e;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(Wn,{refreshToken:t,nodeId:e}),i(`div`,{className:`space-y-2`,children:[i(`div`,{children:[i(`h3`,{className:`text-sm font-semibold text-foreground`,children:[`Cameras on `,r]}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`The roles each camera runs here right now. Move a role or unpin it from the row menu; pins for every camera are on Cluster → Assignments.`})]}),d(yr,{nodeId:e})]})]})}r();function xr(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Sr({nodeId:e,refreshToken:t}){let n=c(),r=yt(),o=te({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:s}=Rt({nodeId:e}),l=rt(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??s??null,u=l===null;Et([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=xt({nodeId:e}),{values:p}=_t(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),m=a(()=>p.filter(e=>e.metrics.phase===`active`).length,[p]),h=t=>{let n=f??[];if(n.length===0){o.mutate({nodeId:e,engine:t,force:!1});return}(async()=>{await r({title:`Kill engine`,message:`${String(n.length)} camera(s) are dispatching through this engine. Killing it drops their in-flight work and forces a respawn on the next frame.`,confirmLabel:`Kill engine`,variant:`danger`})&&o.mutate({nodeId:e,engine:t,force:!0})})()};return i(`div`,{className:`space-y-6`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(l??[]).length,` engine(s) resident in RAM. `,(f??[]).length,` `,`camera(s) attached, `,m,` actively dispatching frames. Refreshes every 5s.`]})]}),d(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:i(`table`,{className:`w-full text-xs min-w-[640px]`,children:[d(`thead`,{className:`bg-surface`,children:i(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),d(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),d(`th`,{className:`text-left px-3 py-2`,children:`Models`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),d(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),d(`th`,{className:`w-20`})]})}),i(`tbody`,{children:[u&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!u&&(l??[]).map(e=>{let t=e.kind===`device-pool`;return i(`tr`,{className:`border-t border-border ${t?`bg-primary/[0.05]`:``}`,children:[d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[d(t?Ht:U,{className:`h-3 w-3`}),t?`pool`:`runtime`]})}),d(`td`,{className:`px-3 py-2`,children:i(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[d(ct,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),d(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?d(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>d(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),d(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),d(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?d(`span`,{className:`text-foreground-subtle`,children:xr(e.idleMs,e.idleTtlMs)}):d(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),d(`td`,{className:`px-3 py-2 text-right text-foreground`,children:(f??[]).length}),d(`td`,{className:`px-3 py-2 text-right`,children:t?d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):i(z,{variant:`ghost`,size:`sm`,disabled:o.isPending,onClick:()=>h(e.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[d(x,{className:`h-3.5 w-3.5`}),`Kill`]})})]},e.engineKey)}),!u&&(l??[]).length===0&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),o.isError&&d(B,{message:`Kill failed: ${o.error instanceof Error?o.error.message:`unknown error`}`})]})}var Cr=`pipeline-runner`,wr=200;function Tr({nodeId:e}){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),i(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(Re,{agentId:e,addonId:Cr,limit:wr,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}r();function Er({nodeId:e,title:t}){let{data:n}=sn(),{data:r}=F(void 0),o=a(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),s=a(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),c=ar(e),l=a(()=>{let e=[];for(let t of c.values())s&&!s.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[c,s]);return l.length===0?i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):i(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[i(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[d(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:l.length})]}),d(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map(e=>{let t=o.get(e.deviceId)??`#${e.deviceId}`,n=ve(e.metrics.phase);return i(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[d(R,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),d(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),d(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),d(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}function Dr(e,t,n){return e.map(e=>{if(e.key===t)return e;let r=e.steps[n];if(!r||r.settings===void 0)return e;let{settings:i,...a}=r,o={...e.steps};return Object.keys(a).length>0?o[n]=a:delete o[n],{...e,steps:o}})}function Or(e,t,n){let r=e.filter(e=>e.key!==t).toSorted((e,t)=>e.key.localeCompare(t.key)),i=[...r.filter(e=>!e.enabled),...r.filter(e=>e.enabled),...e.filter(e=>e.key===t)],a;for(let e of i){let t=e.steps?.[n]?.settings;!t||Object.keys(t).length===0||(a={...a,...t})}return a}function kr(e){let t={};for(let n of e){let e=Object.keys(n.steps).length>0;t[n.key]={enabled:n.enabled,weight:Math.max(1,n.weight),...n.maxSessions!==null&&n.maxSessions>0?{maxSessions:n.maxSessions}:{},...e?{steps:n.steps}:{}}}return t}var Ar=`pipeline-orchestrator`;function jr({addonId:e,highlightLabel:t}){let n=Jt(e),{data:r}=K({addonId:Ar});if(n.length===0)return null;let a=Qt(r??null)[e]??{};return i(`section`,{className:`space-y-1.5 border-t border-border/60 pt-3`,"aria-label":`Cluster-wide settings`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[d(`h3`,{className:v,children:`Cluster-wide settings`}),d(cn,{to:Io(e),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Edit in Cluster → Settings ›`})]}),n.map(e=>i(`div`,{className:`${p} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[d(`span`,{className:w,children:e.label}),d(`span`,{className:h,children:d(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),d(`p`,{className:A,children:`One value for every node and camera — this step writes into a shared index.`})]})}function Mr({rows:e}){return i(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>i(`li`,{className:`${_} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-foreground-muted`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:e.modelId??`—`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.sourceLabel})]},e.id))}),d(`p`,{className:A,children:`To change a model, open that accelerator's cell in the table.`})]})}r();function Nr(e,n){let[r,i]=un(),o=r.get(jn),s=r.get(`acc`),c=a(()=>Pn(e,n,{step:o,acc:s}),[e,n,o,s]),l=t(e=>{i(t=>{let n=new URLSearchParams(t);return e(n),n},{replace:!0})},[i]);return{selection:c,open:t(e=>l(t=>{t.set(jn,e.stepId),e.acceleratorId===void 0?t.delete(`acc`):t.set(`acc`,e.acceleratorId)}),[l]),close:t(()=>l(e=>{e.delete(jn),e.delete(`acc`)}),[l])}}function Pr(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function Fr(e){return e.split(`.`)[0]??e}function Ir(e,t,n){return{id:Nn(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${Fr(t)} · ${Me(n)}`,shortLabel:`${Fr(t)} · ${L(n)}`,nodeLabel:Fr(t),disabled:!n.enabled}}function Lr(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>Ir(e,t,n))}function Rr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>Ir(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>Ir(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[Ir(e.id,e.name,a)]})}function zr(e,t,n){return{modelId:Nt({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function Br(e,t,n){let r=Pr(e,`object-detection`);if(r===null)return;let i=Nt({catalog:r,device:t.device,base:t.device.steps?.[`object-detection`]?.modelId,override:n});if(i===void 0)return;let a=r.models.find(e=>e.id===i);return{modelId:i,name:a?.name??i,supplies:a?.suppliesSteps??[]}}function Vr(e,t,n){return!an(e)||n===void 0?!1:Wt(e,t,n.supplies).effective}function Hr(e,t){return e!==null&&Bt(e.models,t.device.format)}function Ur(e){return Hr(e.addon,e.acc)?e.clusterModelId===void 0?{kind:`enabled`,modelId:e.model.modelId??`Auto`,overridden:e.model.source===`camera`,...e.rootName===void 0?{}:{suppliedByRoot:e.rootName},...e.jumpTo===void 0?{}:{jumpTo:e.jumpTo}}:{kind:`enabled`,modelId:e.clusterModelId,clusterWide:!0}:e.gatedOn?e.jumpTo===void 0?{kind:`skip`}:{kind:`skip`,jumpTo:e.jumpTo}:{kind:`na`}}function Wr(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function Gr(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=Jt(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function Kr(e){return e.flatMap(e=>[{node:e,depth:0},...Kr(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function qr(e,t){return e.flatMap(e=>{let n=qr(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}r();function Jr(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:Me(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Yr({tree:e,searchRows:r,accelerators:o,cellState:s,stepBadge:c,disabledCount:l,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:y}){let b=yt(),x=nt(),{selection:S,open:C,close:w}=Nr(a(()=>Kr(e).map(e=>e.node.addonId),[e]),a(()=>o.map(e=>e.id),[o])),[T,E]=u(``),[D,O]=u(null),[k,j]=u(null),M=n(null),N=n(null),P=n(null),F=n(null),I=a(()=>ee(r,T),[r,T]),L=a(()=>T.trim()===``?e:qr(e,new Set(I.map(e=>e.addonId))),[e,I,T]),te=e=>I.find(t=>t.addonId===e)?.matchedField??null,ne=a(()=>o.map(Jr),[o]),ie=e=>o.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),R=o.find(e=>e.id===S.acceleratorId)??null,ae=S.stepId!==null,z=t(async e=>{if(m){if(!await b({title:`Discard unsaved changes?`,message:`This step has changes that are not saved yet.`,confirmLabel:`Discard`,variant:`danger`}))return;h()}e()},[b,m,h]),oe=()=>{requestAnimationFrame(()=>F.current?.focus())},se=(e,t,n=!1)=>{if(e===S.stepId&&(t?.id??null)===S.acceleratorId){n&&oe();return}let r=()=>{O(te(e)),C({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&oe()};e===S.stepId?r():z(r)},B=()=>{let e=S.stepId;z(()=>{if(w(),e!==null){let t=R===null?null:qe({agentNodeId:R.nodeId,deviceKey:R.deviceKey});requestAnimationFrame(()=>M.current?.focusCell(e,t))}})},ce=e=>{if(e.key===`Enter`){let t=I[0];if(t===void 0)return;e.preventDefault(),se(t.addonId,void 0,!0)}else e.key===`Escape`&&E(``)},le=x?d(re,{onClick:B}):d(De,{icon:Ct,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:B});return i(`div`,{ref:N,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),P.current?.focus()),e.key===`Escape`&&t&&ae&&(e.preventDefault(),B())},children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),d(`input`,{ref:P,type:`search`,value:T,onChange:e=>E(e.target.value),onKeyDown:ce,placeholder:`Filter steps or settings /`,"aria-label":`Filter steps or settings`,className:`h-9 w-56 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none focus:border-primary focus:ring-1 focus:ring-primary/30 md:h-7`}),l>0&&i(`label`,{className:`inline-flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[d(At,{checked:f,onChange:e=>p(e.target.checked)}),`Show disabled accelerators (`,l,`)`]}),_]}),S.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:[`The link names a step this pipeline does not have (`,S.staleStepId,`).`]}),L.length===0?i(`p`,{className:`${A} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:[`No step matches “`,T,`”.`]}):d(de,{ref:M,tree:L,agents:ne,label:v,getCellState:(e,t)=>{let n=ie(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>se(e,ie(t),n),onStepClick:(e,t)=>se(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:ae&&S.stepId!==null&&R!==null?{addonId:S.stepId,agentNodeId:R.nodeId,deviceKey:R.deviceKey}:null,fallbackNodeId:k,onFallbackNodeChange:j,reserveRightPx:ae&&!x?432:0}),d(xe,{open:ae,anchor:N,onClose:B,label:`Step settings`,children:S.stepId!==null&&y({stepId:S.stepId,accelerator:R,matchedField:D,closeButton:le,onEscape:B,headingRef:e=>{F.current=e}})})]})}r();function Xr(e){f(()=>{if(e===null)return;let t=document.getElementById(e);t===null||typeof t.scrollIntoView!=`function`||t.scrollIntoView({block:`center`,behavior:`smooth`})},[e])}r();function Zr(e,t){let n=e.filter(e=>e.steps?.[t]?.settings!==void 0),r=e=>e.toSorted((e,t)=>e.key.localeCompare(t.key));return r(n.filter(e=>e.enabled))[0]?.key??r(n)[0]?.key??r(e.filter(e=>e.enabled))[0]?.key??e[0]?.key}function Qr(e,t){let n=t.settings===void 0?void 0:Zr(e,t.stepId),r=e.map(e=>{let r={...e.steps},i=r[t.stepId]??{},a=t.models[e.key],o=t.jumps[e.key],s=e.key===n&&t.settings!==void 0?Object.keys(t.settings).length>0?t.settings:void 0:i.settings,c=a===void 0?i.modelId:a??void 0,l=o===void 0?i.jumpDeviceKey:o||void 0,u={...c===void 0?{}:{modelId:c},...s===void 0?{}:{settings:s},...l===void 0?{}:{jumpDeviceKey:l}};return Object.keys(u).length>0?r[t.stepId]=u:delete r[t.stepId],{key:e.key,enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:r}});return n===void 0?r:Dr(r,n,t.stepId)}function $r(e,t,n){if(t===null)return 0;let r=Object.entries(t.models).filter(([n,r])=>(r??void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.modelId).length,i=Object.entries(t.jumps).filter(([n,r])=>(r||void 0)!==e.find(e=>e.key===n)?.steps?.[t.stepId]?.jumpDeviceKey).length,a=new Set([...Object.keys(n),...Object.keys(t.settings??{})]),o=t.settings===void 0?0:[...a].filter(e=>!tn(n[e],t.settings?.[e])).length;return r+i+o}function ei({nodeId:e,nodeName:t,toolbar:n}){let r=c(),s=Ae({nodeId:e},{refetchOnMount:`always`}),l=Pe({nodeId:e},{refetchOnMount:`always`}),f=Ut(K({addonId:`pipeline-orchestrator`}).data??null),p=s.data?.devices??[],m=l.data??null,[h,g]=u(null),[_,y]=u(null),[b,x]=u(null),S=Ze({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),C=a(()=>m?je(m):[],[m]),w=a(()=>Kr(C),[C]),[T,E]=u(!1),D=a(()=>Lr(e,t,p,T),[e,t,p,T]),O=a(()=>Lr(e,t,p),[e,t,p]),k=O.length>=2,j=(e,t)=>(t===void 0?void 0:Or(p,t.deviceKey,e))??{},M=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return O.find(e=>e.deviceKey===r);if(!Hr(e,t))return O.filter(n=>n.id!==t.id&&Hr(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},N=(e,t)=>{let n=Pr(m,e),r=zo(e),i=Br(m,t),a=j(e,t),o=M(n,t);return Ur({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?zr(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},...Vr(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:f[e]??r.defaultModelId}:{},...o?{jumpTo:L(o.device)}:{}})},P=w.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:Gr(Pr(m,e.addonId))}));if(s.isLoading||l.isLoading)return d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`});if(m===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`});let F=i(`span`,{className:A,children:[`Accelerators:`,` `,d(`span`,{className:`text-foreground`,children:O.length>0?O.map(e=>L(e.device)).join(` · `):`none enabled`}),p.some(e=>!e.enabled)&&i(o,{children:[` `,`— off:`,` `,p.filter(e=>!e.enabled).map(L).join(`, `)]}),` `,`·`,` `,d(cn,{to:Lo(),className:`text-primary hover:underline`,children:`Cluster → Load balancing ›`})]});return d(Yr,{tree:C,searchRows:P,accelerators:D,cellState:N,disabledCount:p.filter(e=>!e.enabled).length,showDisabled:T,onShowDisabledChange:E,dirty:h!==null&&$r(p,h,j(h.stepId,D[0]))>0,onDiscard:()=>g(null),summary:F,...n===void 0?{}:{toolbar:n},label:`Detection steps`,renderDetail:({stepId:n,accelerator:r,matchedField:a,closeButton:s,onEscape:c,headingRef:l})=>{let u=Pr(m,n);if(u===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let f=h?.stepId===n?h:null,C=r??O[0]??D[0],w=j(n,C),T=f?.settings??w,E=$r(p,f,w),N=e=>{x(null),g(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},P=zo(n),F=vt(u),ee=C===void 0?void 0:Br(m,C),I=e=>{let t=f?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},L=C===void 0?void 0:zr(u,C,{nodePin:I(C)}).modelId,te=D.length>1&&D.some(e=>!tn(j(n,e),w)),ne=e=>{let t=I(e),r=zr(u,e,{nodePin:t}),a=Br(m,e),s=Vr(n,f?.settings??j(n,e),a),c=f?.jumps[e.deviceKey],l=M(u,e,c),p=Hr(u,e)?s&&a?d(st,{rootModel:a,stepModelId:r.modelId}):void 0:i(o,{children:[`No `,e.device.format,` build of this step.`,` `,l?`It runs on ${l.shortLabel} instead.`:`It does not run here.`]}),h=k?i(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Run on`}),d(H,{"aria-label":`Run on`,value:c??e.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:`Auto (this accelerator, or the next one that can run it)`},...O.filter(t=>t.id!==e.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:t=>N({jumps:{...f?.jumps,[e.deviceKey]:t.target.value}})}),d(`span`,{className:A,children:`Routes this step (and its child steps) to another accelerator of this node.`})]}):void 0;return{label:e.label,format:e.device.format,modelId:r.modelId,source:r.source===`node`?`node`:`default`,sourceLabel:r.source===`node`?`node pin`:`hardware default`,models:et(u.models??[],e.device.format),defaultModelId:u.defaultModelIdByFormat?.[e.device.format]??u.defaultModelId,expanded:_===e.id,onToggle:()=>y(t=>t===e.id?null:e.id),onChangeModel:t=>N({models:{...f?.models,[e.deviceKey]:t}}),...t===void 0?{}:{onReset:()=>N({models:{...f?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...p===void 0?{}:{note:p},...h===void 0?{}:{extra:h},changed:f?.models[e.deviceKey]!==void 0||c!==void 0}},re=()=>{f!==null&&S.mutate({agentNodeId:e,inferenceDevices:kr(Qr(p,f))},{onSuccess:()=>{g(null),x({kind:`saved`})},onError:e=>x({kind:`error`,error:e.message})})};return d(Fe,{ref:l,title:r===null?`${u.name} · ${t}`:`${u.name} · ${r.label}`,subtitle:r===null?`${u.slot} · every accelerator of ${t}`:`${u.slot} · ${r.device.format} · base for every camera that lands here`,leading:s,onEscape:c,saveBar:{dirtyCount:E,saving:S.isPending,status:b?.kind??null,...b?.error===void 0?{}:{error:b.error},onSave:re,onDiscard:()=>g(null)},children:i(`div`,{className:`space-y-3`,children:[i(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[d(`h3`,{className:v,children:`Model`}),P!==null&&C!==void 0?d(Bo,{step:P,engineFormat:C.device.format,runnableModelIds:et(u.models??[],C.device.format).map(e=>e.id)}):D.length===0?i(`p`,{className:A,children:[`No accelerator is enabled on this node —`,` `,d(cn,{to:Lo(),className:`text-primary hover:underline`,children:`enable one in Cluster → Load balancing`}),`.`]}):r===null?d(Mr,{rows:D.map(e=>{let t=zr(u,e,{nodePin:I(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):d(It,{...ne(r)},r.id)]}),(F.length>0||ee!==void 0)&&P===null&&i(`section`,{"aria-label":`Settings`,className:`space-y-2 border-t border-border/60 pt-2`,children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`settings-scope`,children:[`Node-wide: these settings apply on every accelerator of `,t,`.`]}),te&&d(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-2 py-1 text-[11px] text-warning`,children:`This step's settings differ between this node's accelerators. Saving makes the values shown here node-wide.`}),d(ti,{addon:u,fields:F,settings:T,modelId:St(u,L,T,ee),root:ee,highlight:a,onChange:e=>N({settings:e})})]}),d(jr,{addonId:n,highlightLabel:a})]})})}})}function ti({addon:e,fields:t,settings:n,modelId:r,root:i,highlight:a,onChange:o}){let s=t.find(e=>`label`in e&&e.label===a)?.key??null;return Xr(s===null?null:lt(s)),d(ut,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:`Node`},modelId:r,...i===void 0?{}:{rootModel:i},highlightKey:s,onChangeLayer:o})}r();function ni({nodeId:e,refreshToken:t}){let n=yt(),[r,a]=u(null),{nodes:s}=W(),c=s.find(t=>t.id===e)?.name??e,l=fe({onSuccess:e=>{a(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${c} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(a(null),l.mutate({agentNodeId:e}))};return i(`div`,{className:`space-y-2`,children:[d(Er,{nodeId:e}),d(ei,{nodeId:e,nodeName:c,toolbar:i(o,{children:[r&&d(`span`,{className:`text-[11px] text-success`,children:r}),l.isError&&d(`span`,{className:`text-[11px] text-danger`,children:l.error instanceof Error?l.error.message:`Reset failed`}),d(z,{variant:`outline`,size:`sm`,onClick:()=>{f()},disabled:l.isPending,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:l.isPending?`Resetting…`:`Reset to default`})]})})]})}var ri=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],ii=`decoder-nodeav`,ai=`ntab`,oi={decoder:`engine`},si={engine:`Engine & decoder`},ci=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function li({nodeId:e,refreshToken:t}){let[n,r]=un(),{nodes:a}=W(),o=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??ii,s=[...ri,o],c=n.get(ai),l={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:d(br,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:d(ni,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:d(Sr,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:d(Tr,{nodeId:e})}},u=Un.map(e=>l[e]);return i(`div`,{className:`flex flex-col h-full`,children:[d(Hn,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:d(fn,{nodeId:e,addonIds:s,level:`global`,fieldScope:`perNode`,emptyMessage:ci,tabAliases:oi,tabLabelOverrides:si,extraTabs:u,activeTab:c===null?null:oi[c]??c,onActiveTabChange:e=>r(t=>{let n=new URLSearchParams(t);n.set(ai,e);for(let e of Mn)n.delete(e);return n},{replace:!0})})})]})}function ui(){return i(`div`,{className:`space-y-2`,children:[i(`div`,{className:`min-w-0`,children:[d(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Camera placement`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pin a camera to a node, or to one accelerator of its node; Auto lets each session pick. Decode always runs with detection. Load, shares and caps are on Load balancing.`})]}),d(vr,{})]})}function di(e){return`${Math.round(e*100)}%`}function fi(e){return`${e} session${e===1?``:`s`}`}var pi={"intel-npu":`Intel NPU`,"intel-igpu":`Intel iGPU`,"amd-igpu":`AMD iGPU (WebGPU)`,"amd-npu":`AMD XDNA NPU`,"x86-cpu":`CPU`,"arm-cpu":`CPU`,"apple-ane":`Apple Neural Engine`,coral:`Coral Edge TPU`},mi={"intel-core-ultra":`Intel Core Ultra`,"intel-n-series":`Intel N-series`,"apple-m-base":`Apple M (base)`,"apple-m-pro":`Apple M Pro / Max / Ultra`,"amd-phoenix":`AMD Ryzen Phoenix / Hawk Point`,unknown:`Not measured`};function hi(e){return e===null?`—`:pi[e]??e}function gi(e){return e===null?`—`:mi[e]??e}function _i(e){switch(e.kind){case`capacity`:return`Capacity ${fi(e.sessions)} ≥ min ${e.minSessions}.`;case`tie-faster`:return`As accurate as ${e.over} (within ${di(e.recallDelta)} recall) and faster.`;case`stepped-down`:return`${e.from} would not fit the load on ${e.limitedBy}; ${e.to} is the most accurate that does.`;case`no-fit-lightest`:return`No model reaches ${fi(e.minSessions)} per device; the one with the most capacity (${fi(e.sessions)}) is used.`;case`derived-latency`:return`${e.modelId}: latency estimated from a similar chip, not measured on this one.`;case`cpu-device`:return`CPU fallback device: picked on its own.`;case`coral-untouched`:return`Coral: left as is (no YOLOv9 build exists for it).`;case`device-disabled`:return`Disabled: not changed.`;case`device-unavailable`:return`Not available on the node right now: not changed.`;case`node-offline`:return`Node offline: nothing on it will change.`;case`no-hardware-facts`:return`Hardware could not be read: nothing on this node will change.`;case`no-measured-data`:return`This hardware has no measured data: nothing on this node will change.`;case`no-family-build`:return`No YOLOv9 build for the ${e.format} format: not changed.`;case`kept-custom-pin`:return`Custom model ${e.modelId} is pinned on ${e.deviceKey}: Auto tune skips this device.`}}function vi(e,t){switch(e.kind){case`detector-store-cluster-wide`:return`Per-camera detector thresholds are not tied to a node, so they are cleared for every camera — including cameras that run on skipped nodes (${e.skippedNodes.map(t).join(`, `)}).`;case`detector-store-unreadable`:return`Per-camera detector thresholds could not be read (${e.error}); those will not be cleared.`;case`coral-enabled`:return`${t(e.nodeId)}: the Coral (${e.deviceKey}) is enabled and keeps running its SSD model, which finds far fewer people than YOLOv9. Consider disabling it.`;case`custom-pin-kept`:return e.deviceId===null?`${t(e.nodeId)}: custom model ${e.modelId} pinned on ${e.deviceKey??`—`} — Auto tune skips this node device.`:`Camera ${e.deviceId} pins custom model ${e.modelId} on ${t(e.nodeId)} — Auto tune keeps that override and its thresholds.`;case`custom-registry-unreadable`:return`The custom-model registry could not be read (${e.error}): every pin to a model outside the measured catalog is kept.`}}function yi(e){let t=e.nodeChanges.reduce((e,t)=>e+t.modelPins.length,0),n=e.nodeChanges.reduce((e,t)=>e+t.thresholds.length,0),r=new Set([...e.cameraClears.map(e=>e.deviceId),...e.detectorStoreClears.map(e=>e.deviceId)]);return{modelChanges:t,thresholdClears:n,cameraOverrideClears:e.cameraClears.length,detectorStoreClears:e.detectorStoreClears.length,camerasTouched:r.size}}function bi(e){let t=yi(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function xi(e,t,n){let r=e.nodeChanges.find(e=>e.nodeId===t&&e.deviceKey===n)?.modelPins.find(e=>e.stepId===`object-detection`);return r===void 0?null:{before:r.before,after:r.after}}function Si(e,t){return e?.kind===`node-benchmark`?`measured on this node, ${new Date(e.measuredAtMs).toLocaleDateString(t,{day:`numeric`,month:`short`})}`:`from the latency table — benchmark this node to measure it`}r();var Ci=[.3,.4,.5];function wi(e){return Ci.some(t=>t===e)}var Ti=[1,2,3,4,6,8];function Ei({plan:e,node:t,nodeName:n}){return i(`section`,{className:g,"data-testid":`auto-tune-node-${t.nodeId}`,children:[i(`header`,{className:`${T} flex flex-wrap items-center gap-2`,children:[d(U,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${v} min-w-0 flex-1`,children:n(t.nodeId)}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[gi(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?d(G,{variant:`warning`,children:`Not changed`}):t.acceleratorModelId!==null&&d(G,{variant:`info`,children:t.acceleratorModelId})]}),t.reasons.length>0&&d(`ul`,{className:`px-3 pt-2 text-[11px] text-foreground-muted`,children:t.reasons.map((e,t)=>d(`li`,{children:_i(e)},t))}),d(`div`,{className:`overflow-x-auto`,children:i(`table`,{className:`w-full text-xs`,children:[d(`thead`,{children:i(`tr`,{className:`text-left text-[11px] text-foreground-subtle`,children:[d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Device`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Capacity`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Detector`}),d(`th`,{className:`px-3 py-1.5 font-medium`,children:`Why`})]})}),d(`tbody`,{children:t.devices.map(n=>{let r=xi(e,t.nodeId,n.deviceKey);return i(`tr`,{className:`border-t border-border align-top`,children:[i(`td`,{className:`px-3 py-1.5`,children:[d(`div`,{className:`font-mono text-foreground`,children:n.deviceKey}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:hi(n.accelerator)})]}),i(`td`,{className:`px-3 py-1.5 text-foreground-muted`,children:[n.chosen===null?`—`:`${n.chosen.capacitySessions} session${n.chosen.capacitySessions===1?``:`s`} at ${e.cameraFps} fps`,n.chosen!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[n.chosen.fps,` fps, `,Math.round(e.headroom*100),`% kept free`,d(`div`,{children:Si(n.chosen.source)})]})]}),d(`td`,{className:`px-3 py-1.5`,children:n.chosen===null?d(`span`,{className:`text-foreground-subtle`,children:`unchanged`}):r!==null&&r.before!==r.after?i(`span`,{children:[d(`span`,{className:`text-foreground-subtle`,children:r.before??`default`}),` → `,d(`span`,{className:`font-medium text-foreground`,children:r.after})]}):d(`span`,{className:`text-foreground`,children:n.chosen.modelId})}),d(`td`,{className:`px-3 py-1.5 text-[11px] text-foreground-muted`,children:n.reasons.map((e,t)=>d(`div`,{children:_i(e)},t))})]},n.deviceKey)})})]})})]})}function Di({plan:e,nameOf:t,nodeName:n}){return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[i(`div`,{children:[d(`div`,{className:v,children:`Node settings`}),e.nodeChanges.length===0?d(`div`,{className:`text-foreground-subtle`,children:`No change.`}):d(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.nodeChanges.flatMap(e=>[...e.modelPins.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: `,t.before??`default`,` → `,t.after??`step default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/pin`)),...e.thresholds.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: reset `,t.keys.join(`, `),` to the model default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),i(`div`,{children:[d(`div`,{className:v,children:`Camera overrides cleared`}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?d(`div`,{className:`text-foreground-subtle`,children:`None.`}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,r)=>i(`li`,{children:[t(e.deviceId),` — `,n(e.nodeId),e.deviceKey===null?` (whole pipeline)`:` · ${e.deviceKey}`,` — `,e.stepId,e.modelIdBefore===null?``:`: model ${e.modelIdBefore} removed`,e.keys.length>0?`; ${e.keys.join(`, `)} reset`:``]},`c${r}`)),e.detectorStoreClears.map(e=>i(`li`,{children:[t(e.deviceId),` — detector thresholds: `,e.keys.join(`, `),` reset`]},`d${e.deviceId}`))]})]})]})}function Oi({result:e}){return e.kind===`refused`?d(`div`,{className:`text-xs text-warning`,children:`Another apply is already running.`}):e.kind===`stale`?d(`div`,{className:`text-xs text-warning`,children:`The configuration changed since the plan was shown. Review the updated plan below and apply again.`}):i(`ul`,{className:`text-xs`,"data-testid":`auto-tune-result`,children:[e.kind===`aborted`&&d(`li`,{className:`text-danger`,children:`A model could not be downloaded: nothing was changed.`}),e.phases.map(e=>i(`li`,{className:e.ok?`text-foreground-muted`:`text-danger`,children:[e.ok?`✓`:`✗`,` `,e.phase,`: `,e.detail]},e.phase))]})}function ki(){let e=c(),[t,n]=u(.4),[r,o]=u(2),[s,l]=u(!1),[f,p]=u(!1),[m,h]=u(null),{data:_}=sn(),y=a(()=>new Map((_??[]).map(e=>[e.id,e.name])),[_]),b=e=>y.get(e)??`Camera ${e}`,{nodes:x}=W(),S=a(()=>Zn(x),[x]),C=oe({headroom:t,minSessionsPerDevice:r},{enabled:s,refetchOnWindowFocus:!1}),w=Le({onSuccess:t=>{h(t),p(!1),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.kind===`applied`&&C.refetch()}}),E=m?.kind===`stale`?m.plan:C.data,D=E===void 0?null:yi(E);return i(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[i(`section`,{className:g,children:[i(`header`,{className:`${T} flex flex-wrap items-center gap-2`,children:[d(ge,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${v} min-w-0 flex-1`,children:`Auto tune`})]}),i(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[d(`p`,{children:`Picks, for every accelerator, the most accurate YOLOv9 detector that still carries at least the chosen number of cameras at once, from the node's hardware and measured speeds. Nothing is measured or estimated about your cameras' activity. Applying it sets those models and clears every model and threshold override — node level and per camera — so each model runs its own default thresholds. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`Keep free`}),d(H,{"aria-label":`Share of each accelerator kept free`,value:String(t),options:Ci.map(e=>({value:String(e),label:`${Math.round(e*100)}% of each accelerator`})),onChange:e=>{let t=Number(e.target.value);wi(t)&&n(t)}})]}),i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`At least`}),d(H,{"aria-label":`Minimum parallel sessions per device`,value:String(r),options:Ti.map(e=>({value:String(e),label:`${e} camera${e===1?``:`s`} at once per accelerator`})),onChange:e=>{let t=Number(e.target.value);Ti.some(e=>e===t)&&o(t)}})]}),d(z,{size:`sm`,variant:`secondary`,onClick:()=>{h(null),l(!0),s&&C.refetch()},children:C.isFetching?`Computing…`:E===void 0?`Compute plan`:`Recompute`}),E!==void 0&&d(z,{size:`sm`,disabled:bi(E),onClick:()=>p(!0),children:`Apply…`})]}),C.error!==null&&d(`div`,{className:`text-danger`,children:C.error.message}),m!==null&&d(Oi,{result:m}),D!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[D.modelChanges,` model change(s), `,D.thresholdClears,` node threshold reset(s), `,D.cameraOverrideClears+D.detectorStoreClears,` camera override(s) on `,D.camerasTouched,` camera(s).`]})]})]}),E?.warnings.map((e,t)=>d(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:vi(e,S)},t)),E?.nodes.map(e=>d(Ei,{plan:E,node:e,nodeName:S},e.nodeId)),E!==void 0&&d(N,{open:f,onOpenChange:p,children:i(_e,{width:`lg`,scroll:`body`,children:[i(ae,{children:[d(ue,{children:`Apply auto tune?`}),d(ye,{children:`These are all the changes. Every override listed is removed and cannot be restored.`})]}),d(ft,{children:d(Di,{plan:E,nameOf:b,nodeName:S})}),i(Ee,{children:[d(z,{variant:`ghost`,onClick:()=>p(!1),children:`Cancel`}),d(z,{variant:`danger`,disabled:w.isPending,onClick:()=>w.mutate({planHash:E.planHash,headroom:t,minSessionsPerDevice:r}),children:w.isPending?`Applying…`:`Apply`})]})]})})]})}var Ai={disabled:`switched off — not a dispatch target`,unavailable:`the node probe does not see it (unplugged or still provisioning)`,"cannot-host-camera-root":`its engine format has no object-detection root model`,"accelerator-preferred":`CPU fallback — it never competes while an accelerator is serving`};function ji(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function Mi(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function Ni(e,t,n){let r=e.filter(e=>e.exclusion===null).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.map(e=>{let i=t.get(e.key)??(n?0:null),a=e.weight>0?e.weight:1;return{key:e.key,label:Me(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?ji(a,r):null,maxSessions:e.maxSessions,atCap:e.maxSessions!==null&&i!==null&&i>=e.maxSessions,available:e.available,enabled:e.enabled,exclusion:e.exclusion}}).toSorted((e,t)=>e.exclusion===null==(t.exclusion===null)?e.key.localeCompare(t.key):e.exclusion===null?-1:1)}function Pi(e){let t=new Map(e.loads.map(e=>[e.nodeId,e])),n=e.nodes.filter(e=>e.isOnline&&e.detectEnabled).reduce((e,t)=>e+(t.weight>0?t.weight:1),0);return e.nodes.map(r=>{let i=t.get(r.id),a=Ni(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),Mi(i)),o=r.isOnline&&r.detectEnabled,s=r.weight>0?r.weight:1,c=i?.load.attachedCameras??null;return{nodeId:r.id,name:r.name,isOnline:r.isOnline,detectEnabled:r.detectEnabled,reported:i!==void 0,attachedCameras:c,activeCameras:i?.load.activeCameras??null,maxCameras:r.maxCameras,capacityPct:c!==null&&r.maxCameras!==null&&r.maxCameras>0?ji(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?ji(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}r();var Fi=2e4,Ii=3e5;function Li({stats:e,targetWeights:t}){let{nodes:n}=W(),r=E().trpcClient,o=Ce(void 0,{placeholderData:l,staleTime:Fi,refetchInterval:Fi,refetchOnWindowFocus:!0}),c=We(void 0,{staleTime:Ii}),u=a(()=>n.map(e=>e.id),[n]),f=s({queries:u.map(e=>({queryKey:on(at.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:Ii,refetchOnWindowFocus:!1,placeholderData:l}))}),p=a(()=>{let e={};return u.forEach((t,n)=>{let r=f[n]?.data;r&&(e[t]=r.devices)}),e},[u,f.map(e=>e.dataUpdatedAt).join(`|`)]),h=a(()=>{let e=new Map;for(let t of c.data??[])e.set(t.nodeId,t.settings);return e},[c.data]),g=a(()=>n.map(e=>{let n=h.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:zn(n,e.isHub).pipeline,weight:t?.[e.id]??hn(n,`detectWeight`)??1,maxCameras:hn(n,`maxCameras`)}}),[n,h,t]),_=o.data??[],v=a(()=>Pi({nodes:g,loads:_,devicesByNode:p}),[g,_,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),x=o.dataUpdatedAt>0?Date.now()-o.dataUpdatedAt:null,S=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return d(V,{headingId:`load-balancing-node-load`,title:`Node load`,icon:Te,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[b,` running · `,y,` attached ·`,` `,o.data===void 0?`reading…`:`${x===null?`—`:`${Math.round(x/1e3)}s`} old`]}),children:d(`div`,{className:m,children:v.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>d(Ri,{row:e,placed:S.get(e.nodeId)},e.nodeId))})})})}function Ri({row:e,placed:t}){let n=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[d(we,{className:`h-2.5 w-2.5`}),` no reading`]}),!e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-foreground-subtle`,children:[d(Qe,{className:`h-2.5 w-2.5`}),` offline`]})]}),i(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:n,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share (1 h)`,value:t?.observedShare===null||t===void 0?`—`:`${Math.round(t.observedShare*100)}%`,title:`Time-weighted share of the cluster's PARALLEL detection sessions this node carried over the last hour — the quantity a share holds. '—' = no session ran here in the window.`}),d(J,{label:`Peak · yields`,value:t===void 0?`—`:`${t.peakSessions} · ${t.yieldsAway}`,title:`Most sessions this node ran at once in the last hour, and how many share turns it handed to another node because it was full or drowning.`}),d(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(zi,{row:e})]})}function zi({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):i(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[i(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(ke,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(Bi,{device:e},e.key))})]})}function Bi({device:e}){let t=e.exclusion;return i(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(U,{className:`h-2.5 w-2.5 shrink-0 ${t===null?`text-foreground-subtle`:`text-foreground-subtle/50`}`}),d(`span`,{className:`shrink-0 font-medium ${t===null?`text-foreground`:`text-foreground-subtle`}`,title:`${e.key} · ${e.format}`,children:e.label}),t===null?i(o,{children:[i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,children:[e.weightSharePct,`% share`]}),i(`span`,{className:`shrink-0 tabular-nums text-foreground-subtle`,title:e.sessions===null?`Not known: the node did not report, or runs a session no device accounts for.`:void 0,children:[`· `,e.sessions??`—`,` session`,e.sessions===1?``:`s`,e.maxSessions===null?``:`/${e.maxSessions}`]}),e.atCap&&d(`span`,{className:`shrink-0 text-amber-400`,title:`At its maxSessions cap — the balancer skips it until a session ends.`,children:`· at cap`})]}):i(`span`,{className:`truncate text-foreground-subtle/80`,title:Ai[t],children:[`excluded — `,Ai[t]]})]})}function J({label:e,value:t,title:n}){return i(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Vi(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Hi(e){let t={},n={};for(let r of e.nodes){if(r.share===null||r.share<=0)continue;t[r.nodeId]=r.share;let e=Object.fromEntries(r.devices.filter(e=>e.share>0).map(e=>[e.deviceKey,e.share]));Object.keys(e).length>0&&(n[r.nodeId]=e)}return{nodes:t,devices:n}}function Ui(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Wi(e){return e.reason===`disabled`?`${e.deviceKey} is not enabled on any node — sessions ignore this pin`:`no node offers ${e.deviceKey} — sessions ignore this pin`}function Gi(e,t){if(t===void 0||t.source===`manual`||t.autoPending)return{nodes:e,readOnly:t!==void 0&&t.source!==`manual`};let n=new Map(t.nodes.map(e=>[e.nodeId,e.configuredPct]));return{nodes:e.map(e=>({...e,weight:Math.round(n.get(e.id)??e.weight)})),readOnly:!0}}function Ki(e,t){let n=e.nodes.filter(e=>!e.eligible);if(n.length===0)return null;let r=e.nodes.filter(e=>e.eligible).map(e=>`${t(e.nodeId)} ${Math.round(e.effectivePct)}%`).join(`, `);return`${n.map(e=>t(e.nodeId)).join(`, `)} cannot take sessions — ${n.length===1?`its share goes`:`their shares go`} to the others: ${r}`}var qi=[{value:`hardware`,label:`Hardware`,hint:`Each node’s share follows what its accelerators can carry at their Auto tune models, from the measured speed of its hardware. No load is measured or estimated.`},{value:`benchmark`,label:`Benchmark`,hint:`Each node’s share follows its own node-benchmark results. A node without results uses its hardware capacity instead, and says so.`},{value:`manual`,label:`Manual`,hint:`The sliders below, as you set them.`}];function Ji(e){return e===`no-benchmark-results`?`no benchmark results yet — sized from hardware`:e===`partial-benchmark-results`?`benchmark results miss some of its accelerators — sized from hardware`:null}function Yi(e,t){if(e.source!==`benchmark`)return null;let n=e.nodes.filter(e=>e.capacityFallback!==null);return n.length===0?null:n.map(e=>`${t(e.nodeId)}: ${Ji(e.capacityFallback)??``}`).join(` · `)}r();function Xi(e,t,n){return Math.min(Math.max(e,t),n)}function Zi(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function Qi(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:Xi(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function $i(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function ea({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:a,footnote:s,readOnly:c=!1}){let[l,p]=u(()=>Zi(e)),[m,h]=u(new Set);f(()=>{p(Zi(e)),h(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let g=e.map(e=>e.id),_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=(e,t)=>{p(n=>Qi(n,e,t,m,g))},y=()=>{let t=$i(l,g,m),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...m]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:a??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let b=e.length===1;return i(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=l[e.id]??0,a=m.has(e.id);return i(`div`,{className:`flex items-center gap-3`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),d(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:c||t||a||b,onChange:t=>v(e.id,Number(t.target.value)),onPointerUp:()=>y(),onKeyUp:()=>y(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),i(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),!c&&d(`button`,{type:`button`,onClick:()=>_(e.id),disabled:t||b,"aria-pressed":a,title:a?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${a?`text-amber-400`:`text-foreground-subtle`}`,children:d(a?I:Lt,{className:`h-3.5 w-3.5`})})]},e.id)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:s??d(o,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}function ta(e){let t=e.steps?.[`object-detection`]?.modelId;return typeof t==`string`&&t.length>0?t:typeof e.defaultModelId==`string`&&e.defaultModelId.length>0?e.defaultModelId:null}r();function na(e){let t=Me(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:U,hue:`slate`}:r===`npu`?{label:t,Icon:ct,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:En,hue:`violet`}:n===`edgetpu`?{label:t,Icon:An,hue:`emerald`}:{label:t,Icon:U,hue:`slate`}}var ra={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function ia({nodeId:e,nodeName:t,isOnline:n,suggestedMaxSessions:r,autoDeviceShares:s}){let l=c(),{data:p,isLoading:m}=Ae({nodeId:e},{refetchInterval:15e3}),h=Ze({onSettled:()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),g=p?.devices??[],_=p?.reachable??n,[v,y]=u({});f(()=>{y(Object.fromEntries(g.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[g.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let b=a(()=>g.filter(e=>v[e.key]?.enabled??e.enabled).length,[g,v]),[x,S]=u(null),w=x??b>0,T=t=>{let n=g.map(e=>{let n=t[e.key]??E(e);return{key:e.key,enabled:n.enabled,weight:n.weight,maxSessions:n.maxSessions,steps:n.steps}});h.mutate({agentNodeId:e,inferenceDevices:kr(n)})},E=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),D=e=>{if(!e.available)return;let t=v[e.key]??E(e),n={...v,[e.key]:{...t,enabled:!t.enabled}};y(n),T(n)},O=(e,t)=>{let n=v[e.key]??E(e),r={...v,[e.key]:{...n,maxSessions:t}};y(r),T(r)},k=a(()=>g.filter(e=>(v[e.key]?.enabled??e.enabled)&&e.available),[g,v]),A=a(()=>k.map(e=>({id:e.key,name:na(e).label,weight:s===void 0?v[e.key]?.weight??e.weight:Math.round(s[e.key]??0)})),[k,v,s]);return i(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[i(`button`,{type:`button`,onClick:()=>S(!w),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":w,children:[d(C,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${w?`rotate-90`:``}`}),d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),d(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:_?b>=2?i(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[d(Ht,{className:`h-3.5 w-3.5`}),b,` accelerators`]}):b===1?d(`span`,{className:`text-foreground-subtle`,children:`single default`}):d(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):i(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[d(Qe,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),w&&i(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[_?m&&g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):d(`ul`,{className:`space-y-2`,children:g.map(e=>{let t=na(e),n=v[e.key]??E(e),a=n.enabled&&e.available,s=ta({defaultModelId:e.defaultModelId,steps:n.steps});return i(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[d(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${ra[t.hue]}`,children:d(t.Icon,{className:`h-4.5 w-4.5`})}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),d(G,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&d(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:[d(`span`,{className:`font-mono`,children:e.key}),s!==null&&i(o,{children:[d(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:[`root model`,` `,d(`span`,{className:`font-mono text-foreground/80`,children:s})]})]})]})]}),a&&i(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),d(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);O(e,r!=null&&r>0?r:null)},disabled:h.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),a&&d(aa,{suggested:r?.[e.key]??null,current:n.maxSessions,pending:h.isPending,onApply:t=>O(e,t)}),d(gt,{checked:a,onCheckedChange:()=>D(e),disabled:!e.available||h.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):d(oa,{}),_&&k.length>=2&&i(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[i(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[d(kn,{className:`h-3.5 w-3.5`}),`Accelerator share`]}),d(ea,{nodes:A,pending:h.isPending,onCommitWeights:e=>{let t={...v};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}y(t),T(t)},weightLabel:`Accelerator share`,readOnly:s!==void 0,footnote:s===void 0?d(o,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`}):d(o,{children:`Automatic: each accelerator's share follows its measured throughput at its model. Switch the node shares to manual to set them yourself.`})})]}),h.isError&&i(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,h.error instanceof Error?h.error.message:`unknown error`]})]})]})}function aa({suggested:e,current:t,pending:n,onApply:r}){return e===null||e<1||e===t?null:i(z,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`,children:[`use `,e]})}function oa(){return i(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[d(Qe,{className:`h-6 w-6 text-foreground-subtle/60`}),d(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),d(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}r();var sa=3600*1e3,ca=2e4,la=.4;function ua({refreshToken:e,onOpenAutoTune:t}){let n=c(),{nodes:r}=W(),s=We(void 0),f=Mt({isCamera:!0,projection:`slim`}),p=ce({windowMs:sa},{refetchInterval:ca,placeholderData:l}).data,h=he(void 0,{refetchInterval:ca,placeholderData:l}).data,g=()=>{yn(n),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},v=bt({onSuccess:g}),y=tt({onSuccess:()=>{g(),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),b=Oe({onSuccess:g}),x=me(),[S,C]=u(!1),w=h?.source,T=w===`benchmark`?`benchmark`:`hardware`,E=ht({headroom:la,source:T},{enabled:S,staleTime:1/0}),D=E.data,O=a(()=>{let e=new Map((s.data??[]).map(e=>[e.nodeId,e.settings]));return r.filter(t=>zn(e.get(t.id),t.isHub).pipeline).map(t=>{let n=e.get(t.id);return{id:t.id,name:t.name,isOnline:t.isOnline,weight:hn(n,`detectWeight`)??1,maxCameras:hn(n,`maxCameras`)}})},[r,s.data]),k=e=>r.find(t=>t.id===e)?.name??e,j=Qn((f.data??[]).map(e=>({id:e.id,name:e.name}))),M=D?Ui(D):void 0,N=Gi(O,h),P=w!==`manual`,F=e=>{if(h===void 0||h.source===`manual`||h.autoPending)return;let t=h.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},ee=h?Ki(h,k):null,I=h?Yi(h,k):null,L=qi.find(e=>e.value===w)?.hint;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(fn,{nodeId:`hub`,addonIds:[Cn],level:`global`,sectionIds:[`load`],title:`Placement policy`,description:`How a new detection session picks its node and device, and what happens when a node falls behind. 'Honour shares' (default) holds the shares below for PARALLEL sessions.`}),d(Wn,{refreshToken:e}),d(Li,{stats:p,...h!==void 0&&h.source!==`manual`&&!h.autoPending?{targetWeights:Object.fromEntries(h.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),d(V,{headingId:`load-balancing-node-shares`,title:`Node shares`,icon:kn,actions:i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{role:`radiogroup`,"aria-label":`Share source`,className:`flex items-center gap-1`,children:qi.map(e=>d(z,{role:`radio`,"aria-checked":w===e.value,variant:w===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:y.isPending||h===void 0,onClick:()=>{w!==e.value&&y.mutate({source:e.value})},children:e.label},e.value))}),i(z,{variant:`outline`,size:`sm`,onClick:()=>{C(!0),S&&E.refetch()},disabled:E.isFetching,children:[d(Se,{className:`h-3.5 w-3.5`}),E.isFetching?`Suggesting…`:T===`benchmark`?`Suggest from benchmark`:`Suggest from hardware`]}),i(z,{variant:`ghost`,size:`sm`,onClick:t,children:[d(ge,{className:`h-3.5 w-3.5`}),`Auto tune`]}),i(z,{variant:`outline`,size:`sm`,onClick:()=>x.mutate(void 0),disabled:x.isPending,title:`Move standing (always-on) cameras that are no longer on their best node. Pinned cameras never move; on-motion sessions are placed per session anyway.`,children:[d(ct,{className:`h-3.5 w-3.5`}),x.isPending?`Rebalancing…`:`Rebalance`]})]}),children:i(`div`,{className:`${m} space-y-3`,children:[L!==void 0&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:L}),p&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Policy:`,` `,d(G,{variant:p.policy===`share`?`info`:`default`,children:p.policy===`share`?`honour shares`:`least-loaded`}),` `,`· cluster peak `,p.clusterPeakSessions,` parallel sessions in the last hour`,p.policy===`least-loaded`&&` · under least-loaded an idle node always wins, so shares only bite once nodes are busy`]}),d(ea,{nodes:N.nodes,pending:v.isPending,readOnly:N.readOnly,onCommitWeights:e=>v.mutate(Vi(e)),weightLabel:`Node share`,...N.readOnly?{footnote:h?.autoPending?d(o,{children:`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`}):i(o,{children:[w===`benchmark`?`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`:`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`,h?.computedAt==null?``:` — last at ${new Date(h.computedAt).toLocaleTimeString()}${h.trigger===null?``:` (${h.trigger})`}`,`.`]})}:{}}),ee!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:ee}),I!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:I}),y.isError&&d(B,{message:`Failed to switch shares: ${y.error instanceof Error?y.error.message:`unknown error`}`}),v.isError&&d(B,{message:`Failed to save shares: ${v.error instanceof Error?v.error.message:`unknown error`}`}),i(`details`,{className:`rounded-md border border-border`,children:[d(`summary`,{className:`${_} cursor-pointer text-xs text-foreground`,children:`Max concurrent sessions (advanced)`}),d(`ul`,{className:`divide-y divide-border border-t border-border`,children:O.map(e=>i(`li`,{className:`${_} flex items-center gap-2`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),d(Xe,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":`Max concurrent sessions for ${e.name}`,className:`w-20 text-right`,disabled:b.isPending,onBlur:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==e.maxCameras&&b.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),d(`p`,{className:`${_} ${A} border-t border-border`,children:`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`})]})]})}),E.isError&&d(B,{message:`Suggestion failed: ${E.error instanceof Error?E.error.message:`unknown error`}`}),D&&d(da,{suggestion:D,nameOf:k,pending:v.isPending,...P?{}:{onApply:()=>v.mutate(Hi(D))}}),d(V,{headingId:`load-balancing-accelerators`,title:`Accelerators`,icon:U,children:d(`div`,{className:`${m} space-y-2`,children:O.length===0?d(ze,{title:`No detect-capable nodes`,description:`Enable detection on a node in Roles & nodes to configure its accelerators.`}):O.map(e=>d(ia,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...M?.[e.id]===void 0?{}:{suggestedMaxSessions:M[e.id]},...F(e.id)===void 0?{}:{autoDeviceShares:F(e.id)}},e.id))})}),p!==void 0&&p.stalePins.length>0&&d(fa,{stats:p,cameraName:j})]})}function da({suggestion:e,nameOf:t,pending:n,onApply:r}){return i(V,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?`Suggested from benchmark`:`Suggested from hardware`,icon:Se,...r===void 0?{}:{actions:d(z,{size:`sm`,onClick:r,disabled:n,children:`Apply suggested shares`})},children:[d(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>i(`li`,{className:`${_} space-y-0.5`,children:[i(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),d(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?`skipped`:`${e.share}%`})]}),i(`p`,{className:A,children:[Ji(e.capacityFallback)===null?``:`${Ji(e.capacityFallback)} · `,e.skippedReason===null?`≈ ${e.capacitySessions} parallel sessions · ${e.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}`:`not part of the suggestion — ${e.skippedReason}`]})]},e.nodeId))}),i(`p`,{className:`${_} ${A} border-t border-border`,children:[`Shares in proportion to each node's capacity in parallel sessions —`,` `,e.source===`benchmark`?`measured by node benchmarks, or from the hardware table where a node has no results`:`at the models Auto tune picks (at least ${e.minSessionsPerDevice} per accelerator), from the measured speed of each node's hardware`,`, counted in `,e.cameraFps,` fps sessions with`,` `,Math.round(e.headroom*100),`% kept free. No load is measured or estimated.`,r===void 0?`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`:`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`]})]})}function fa({stats:e,cameraName:t}){let n=c(),r=Dt({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return d(V,{headingId:`load-balancing-stale-pins`,title:`Stale device pins`,icon:On,children:d(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>i(`li`,{className:`${_} flex items-center gap-2`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[d(`p`,{className:`truncate text-xs text-foreground`,title:t(e.deviceId),children:t(e.deviceId)}),d(`p`,{className:A,children:Wi(e)})]}),d(z,{variant:`outline`,size:`sm`,disabled:r.isPending,onClick:()=>r.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:`Clear pin`})]},e.deviceId))})})}function pa({node:e,emphasis:t=!1}){let n=e.isHub?Ke:U;return i(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[d(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),d(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),i(`div`,{className:`min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[d(`span`,{className:`truncate`,children:e.name}),e.isHub&&d(G,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(G,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}function ma({nodes:e,actions:t}){return d(le,{columns:[{key:`node`,header:`Node`,sortValue:e=>e.name,render:e=>d(pa,{node:e})},...bn.map(e=>({key:e.key,header:e.label,align:`center`,notSortableReason:`A switch — sorting would move the row while it is being changed.`,render:n=>d(gt,{"aria-label":`${e.label} on ${n.name}`,title:e.hint,checked:mn(n.effective,e.key),disabled:t.capabilityPending,onCheckedChange:r=>t.onToggleCapability(n.id,e.key,r)})}))],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,mobileMode:`scroll`,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:`No cluster nodes reporting yet.`})}function ha({roleValues:e,options:t,pending:n,onRoleChange:r}){let a=t.map(e=>({value:e.id,label:e.id===`hub`?`${e.name} (default)`:e.name}));return d(`ul`,{className:`divide-y divide-border`,children:wn.map(t=>i(`li`,{className:`${_} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[i(`div`,{className:`min-w-0 flex-1 basis-56`,children:[d(`div`,{className:`text-xs font-medium text-foreground`,children:gn(t)}),d(`p`,{className:A,children:_n(t)})]}),d(`div`,{className:`w-full sm:w-48`,children:d(H,{"aria-label":`${gn(t)} node`,value:e[t],disabled:n,options:a,onChange:e=>r(t,e.target.value)})})]},t))})}r();function ga(){let e=c(),{nodes:t}=W(),n=We(void 0),r=K({addonId:Cn}),o=K({addonId:pn}),s=K({addonId:Tn}),l=()=>yn(e),u=Ge({onSuccess:l}),f=Ne({onSuccess:l}),p=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),m=a(()=>t.map(e=>{let t=p.get(e.id),n=zn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n}}),[t,p]),h={ingestNode:Sn(r.data,`ingestNode`,`hub`),recordingNode:Sn(o.data,xn,`hub`),audioNode:Sn(r.data,`audioNode`,`hub`),motionNode:Sn(r.data,`motionNode`,`hub`),postProcessingNode:Sn(s.data,vn,`hub`)},g=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id),n=e=>t.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,...wn.map(e=>h[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:n(e)}))},[t,h]),_=n.isLoading||r.isLoading||o.isLoading||s.isLoading,v=(e,t,n)=>{u.mutate({agentNodeId:e,[t]:n})},y=(e,t)=>{if(e===`recordingNode`){f.mutate({addonId:pn,patch:{[xn]:t}});return}if(e===`postProcessingNode`){f.mutate({addonId:Tn,patch:{[vn]:t}});return}f.mutate({addonId:Cn,patch:{[e]:t}})},b={capabilityPending:u.isPending,onToggleCapability:v};return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(V,{headingId:`roles-nodes-cluster-roles`,title:`Cluster roles`,icon:Dn,actions:_?d(Ie,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":`Loading`}):null,children:[d(`p`,{className:`${A} border-b border-border px-3 py-1.5 sm:px-4`,children:`One node holds each role for every camera. Detection shares and caps are on Load balancing.`}),d(ha,{roleValues:h,options:g,pending:f.isPending,onRoleChange:y})]}),d(V,{headingId:`roles-nodes-node-capabilities`,title:`Node capabilities`,icon:Ke,children:d(ma,{nodes:m,actions:b})})]})}var _a=`pipeline-analytics`,va=`face-gallery`,ya=`pipeline-orchestrator`,ba=`pipeline-runner`,xa=`audio-analyzer`;function Sa(e){return[...Yt.filter(t=>t.stepId===e).map(e=>Gt(e.stepId)),...Kt.filter(t=>t.stepId===e).map(e=>$t(e.stepId,e.key))]}var Ca=`faces`,wa=`semantic-search`,Ta=[{id:Ca,title:`Faces & recognition`,hint:`The face encoder for every node, the smallest faces worth embedding, keeping and auto-assigning, and how a face is matched to a person.`,panels:[{addonId:ya,fieldKeys:Sa(`face-embedding`)},{addonId:_a,capability:va}]},{id:wa,title:`Semantic search`,hint:`The image encoder behind "search by description". One for the whole cluster: changing it hides existing results until the index is rebuilt.`,panels:[{addonId:ya,fieldKeys:Sa(`clip-embedding`)}]},{id:en,title:`Enrichment crop`,hint:`How the crop handed to face, plate and search models is cut from the frame.`,panels:[{addonId:ya,sectionIds:[en]}]},{id:Xt,title:`Full-resolution crops`,hint:`How long each camera keeps full-resolution pixels so a late crop (snapshot, face, plate) is sharp instead of cut from the small detection frame.`,panels:[{addonId:ya,sectionIds:[Xt]}]},{id:`runner-defaults`,title:`Runner defaults`,hint:`Values every node's detection runner and audio analyzer use. A node's own decode limits (Engine & decoder) take precedence.`,panels:[{addonId:ba,fieldScope:`cluster`},{addonId:xa,fieldScope:`cluster`}]},{id:`failover`,title:`Failover`,hint:`What happens to cameras when a node disconnects and comes back.`,panels:[{addonId:ya,sectionIds:[`failover`]}]}],Ea={"cluster-step-models":Ca};function Da(e){return e===`clip-embedding`?wa:Ca}r();var Oa=2500,ka={faces:M,"semantic-search":ge,"detail-crop":Vt,"native-lease":Ht,"runner-defaults":U,failover:Tt};function Aa(e){f(()=>{if(e===null)return;let t=Ea[e]??e,n=`[data-cluster-settings-card="${CSS.escape(t)}"]`,r=()=>{let e=document.querySelector(n);return e===null?!1:(e.scrollIntoView({block:`start`,behavior:`smooth`}),e.classList.add(`ring-2`,`ring-primary/60`),setTimeout(()=>e.classList.remove(`ring-2`,`ring-primary/60`),Oa),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function ja({section:e}){return d(`div`,{"data-cluster-settings-card":e.id,className:`rounded-lg`,children:d(V,{headingId:`cluster-settings-${e.id}`,title:e.title,...ka[e.id]===void 0?{}:{icon:ka[e.id]},children:i(`div`,{className:`${m} space-y-3`,children:[d(`p`,{className:A,children:e.hint}),e.panels.map(e=>d(fn,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:[`cluster`,`load`],emptyMessage:`Not available — the addon that owns these settings did not answer.`,...e.capability===void 0?{}:{capability:e.capability},...e.sectionIds===void 0?{}:{sectionIds:e.sectionIds},...e.fieldKeys===void 0?{}:{fieldKeys:e.fieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function Ma({refreshToken:e}){let[t]=un();return Aa(t.get(Po)),d(`div`,{className:`space-y-3 sm:space-y-4`,children:Ta.map(e=>d(ja,{section:e},e.id))})}var Na=`pipeline-orchestrator`,Pa=200;function Fa(){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(Re,{addonId:Na,limit:Pa,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}var Ia=[{id:`assignments`,label:`Assignments`},{id:`load-balancing`,label:`Load balancing`},{id:`auto-tune`,label:`Auto tune`},{id:`roles-nodes`,label:`Roles`},{id:`settings`,label:`Settings`},{id:`logs`,label:`Logs`}];function La(e){return Ia.some(t=>t.id===e)}function Ra({refreshToken:e}){let[t,n]=un(),r=t.get(No),a=La(r)?r:`assignments`,o=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(No,e),n.delete(Po),n},{replace:!0})};return i(`div`,{className:`flex flex-col h-full`,children:[i(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Ia.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[a===`assignments`&&d(ui,{}),a===`load-balancing`&&d(ua,{refreshToken:e,onOpenAutoTune:()=>o(`auto-tune`)}),a===`auto-tune`&&d(ki,{}),a===`roles-nodes`&&d(ga,{}),a===`settings`&&d(Ma,{refreshToken:e}),a===`logs`&&d(Fa,{})]})]})}var za=`armed:`;function Ba(e){return e.assignment.reasons.detection?.startsWith(za)===!0}function Va(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!Ba(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function Ha(e){let t=[],n=[],{assignment:r,detection:i,broker:a}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),r.detectionNodeId===null&&i===null&&!Ba(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let o=e.degraded??[];if(o.length>0){let e=[...new Set(o.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}n.push(...Ga(e.cameraSensors));for(let e of a?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Ua(e){return e.state===`unreadable`&&qt.state===`unreadable`&&e.reason===qt.reason}function Wa(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is missing`};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) is ${e.reason}`};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) cannot drive motion: ${e.reason}`};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is unreadable: ${e.reason}`}}}function Ga(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return Ua(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:`Camera sensors unreadable: ${e.reason}`}];let t=e.sensors.flatMap(e=>{let t=Wa(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[Ka(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:`Confirm / Replace cannot suppress this camera's own motion until its provider is updated`},...n]}function Ka(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?`Camera sensors are attached but never fire: add "Camera sensors" (onboard) to this camera's motion sources`:`Camera sensors are attached but never fire: this camera has no active detection`}}function qa(e){return e===void 0?`status unavailable from this node`:e.state===`not-configured`?`none attached`:e.state===`unreadable`?`unknown — ${e.reason}`:e.sensors.map(Ya).join(`, `)}function Ja(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function Ya(e){return`${Xa(e)}${Ja(e)}`}function Xa(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return`${e.name} (#${e.deviceId}) — unsupported`;case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function Za(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Qa(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function $a(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function eo(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var to={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function no(e){if(!Za(e)||!Array.isArray(e.sections))return to;let t=Zt(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)eo(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Qa(n(`detectionFps`)),motionSources:$a(n(`motionSources`)),motionFps:Qa(n(`motionFps`)),motionCooldownMs:Qa(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function ro(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...ro(r.children,t+1));return n}function X({title:e,children:t}){return i(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return i(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(io,{})]})}function io(){return d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var ao={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return d(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${ao[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function oo({icon:e,label:t,nodeId:n,pinned:r,reason:a,overridden:s}){return i(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):i(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?i(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(ot,{className:`h-2.5 w-2.5`}),` manual`]}):i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function so({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return i(X,{title:`Where it runs`,children:[d(oo,{icon:U,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(oo,{icon:Ve,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(oo,{icon:S,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(oo,{icon:$e,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:i(`select`,{value:o,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>i(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function co(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function lo(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function uo(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function fo({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:a,cameraSensors:s}){let c=lo(t,n.detectionStreamProfile),l=lo(t,n.motionStreamProfile),u=n.motionSources.includes(`analyzer`);return i(X,{title:`Streams & motion`,children:[i(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:uo(n.detectionFps)}),i(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map(rn).join(` + `):`none`,r===!1&&` · inactive`]}),d(Z,{label:`Camera sensors`,children:qa(s)}),u&&i(o,{children:[i(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),i(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[uo(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>i(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,co(e)]},e.camStreamId))})]})}function po({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return i(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:i(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&i(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:i(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var mo={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function ho({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return i(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:r,children:n??`—`}),d($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=ve(a),f=a===`active`&&o===0;return i(X,{title:`Detection runtime`,children:[i(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[i(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${u.badgeClass}`,children:[d(R,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:r,children:n??`—`}),i(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),i(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&i(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&i(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),i(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),i(Z,{label:`Provisioning`,children:[d(Q,{tone:mo[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&i(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function go({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):i(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return i(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),i(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),i(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps===null?`—`:e.inFps.toFixed(0),`fps`]}),i(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),i(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[i(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),i(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function _o({decoder:e}){return e===null?d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})}):d(X,{title:`Decoder`,children:d(Z,{label:`Node`,children:e.nodeId})})}r();var vo=`pipeline-orchestrator`,yo={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},bo={healthy:`Healthy`,idle:`Idle`,error:`Error`};function xo({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>i(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[d(we,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function So({deviceId:e,name:t,online:n,status:r,live:o,onlineNodes:s}){let l=c(),{data:u}=Pt({addonId:vo,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=Je({deviceId:e},{staleTime:3e4}),p=a(()=>no(u),[u]),m=a(()=>f===void 0?void 0:ro(f.steps),[f]),h=a(()=>r===void 0?[]:Ha(r),[r]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=ne({onSuccess:g}),v=it({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=r===void 0?`idle`:Va(r),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return i(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[i(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:yo[b]}`,title:x?`Error`:bo[b],"aria-label":x?`Error`:bo[b],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),i(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),r?.recording!=null&&(r.recording.active?i(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&i(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),h.length>0&&d(xo,{problems:h}),r===void 0?d(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):i(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(so,{assignment:r.assignment,settings:p,onlineNodes:s,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),d(ho,{detection:r.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(po,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:r.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(fo,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:p,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null,cameraSensors:r.cameraSensors}),d(go,{broker:r.broker}),d(_o,{decoder:r.decoder})]})]})}r();var Co=5e3,wo=1e4,To=5e3;function Eo(e){let t=c(),{data:n,isLoading:r}=sn(),{data:i,isLoading:o}=be({},{refetchInterval:Co}),{nodes:s}=W();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);jt(nn.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-wo,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},To);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}r();function Do({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:o}=Eo(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:Ha(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:i(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[i(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[i(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),i(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),i(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(So,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}var Oo=e({CLUSTER_NODE_ID:()=>ko,PipelinePage:()=>Mo});r();var ko=`__cluster__`;function Ao(e){return e===`cameras`?`cameras`:`nodes`}function jo({viewMode:e,onNodes:t,onCameras:n}){return i(`div`,{className:`flex items-center gap-1 rounded-lg border border-border bg-surface p-0.5`,role:`tablist`,"aria-label":`Pipeline view`,children:[d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`nodes`,onClick:t,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),d(`button`,{type:`button`,role:`tab`,"aria-selected":e===`cameras`,onClick:n,className:[`rounded-md px-3 py-1 text-[11px] font-medium transition-colors`,e===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]})}function Mo(){let[e,t]=un(),n=Ao(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:ko},{replace:!0})},[n,e,t]),i(se,{icon:ln,title:`Pipeline`,subtitle:`Detection placement, load and per-camera runtime across the cluster.`,actions:i(z,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s(e=>e+1),title:`Refresh`,children:[d(dt,{className:`h-3.5 w-3.5`}),`Refresh`]}),nav:d(jo,{viewMode:n,onNodes:()=>{t({view:`nodes`,node:r},{replace:!0})},onCameras:()=>{t({view:`cameras`},{replace:!0})}}),className:`flex h-full min-h-0 flex-col overflow-hidden`,children:[n===`nodes`&&i(z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>l(e=>!e),"aria-expanded":c,className:`flex w-full shrink-0 justify-between border-b border-border md:hidden`,children:[i(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(y,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden md:flex-row`,children:n===`nodes`?i(o,{children:[d(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b border-border md:border-b-0 md:border-r`,`max-h-[60vh] overflow-y-auto md:max-h-none`].join(` `),children:d(Vn,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:r===`__cluster__`?d(Ra,{refreshToken:a}):d(li,{nodeId:r,refreshToken:a})})]}):d(`section`,{className:`min-h-0 flex-1 overflow-hidden`,children:d(Do,{refreshToken:a})})})]})}var No=`ctab`,Po=`section`;function Fo(e,t){let n=new URLSearchParams({view:`nodes`,node:ko,[No]:e});return t!==void 0&&n.set(Po,t),`/system/pipeline?${n.toString()}`}function Io(e){return Fo(`settings`,Da(e))}function Lo(){return Fo(`load-balancing`)}var Ro=`pipeline-orchestrator`;function zo(e){return Yt.find(t=>t.stepId===e)??null}function Bo({step:e,engineFormat:t,runnableModelIds:n}){let{data:r}=K({addonId:Ro}),a=Ut(r??null)[e.stepId]??e.defaultModelId,o=e.options.find(e=>e.id===a)?.label??a,s=n.length>0&&!n.includes(a);return i(`div`,{className:`space-y-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2`,children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:o}),d(`span`,{title:`One value for the whole cluster — this step writes into a shared vector index, where two encoders make similarity scores meaningless.`,className:`rounded border border-primary/40 bg-primary/10 px-1 py-px text-[9px] font-medium uppercase tracking-wide text-primary`,children:`cluster-wide`}),d(cn,{to:Io(e.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Change in Cluster → Settings ›`})]}),i(`p`,{className:A,children:[`One model for every node and camera: `,e.indexName,` only matches vectors from the model that made them.`]}),s&&i(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:[`This accelerator's engine (`,t,`) ships no build of `,d(`b`,{children:a}),`. It refuses this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`.`]})]})}export{jr as _,Yr as a,Pr as c,Br as d,Hr as f,Mr as g,Vr as h,Xr as i,Kr as l,zr as m,zo as n,Rr as o,Gr as p,Oo as r,Ur as s,Bo as t,Wr as u,Or as v,Mn as y};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Q as e,S as t,W as n,a 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{_t as l,ct as u,gt as d,ot as f,yt as p}from"./player-overlays-Sm-ivm_8.js";import{Ad as m,Al as h,An as g,Bl as _,Bu as v,Cd as y,Cu as b,Dd as x,Dl as S,Fl as C,Fn as w,Ft as T,G as E,Gn as D,Hl as O,Hn as ee,Ht as k,Il as A,In as j,Ju as te,Ku as M,L as ne,Ll as N,Ml as P,Mn as F,Mr as I,N as re,Nl as ie,Ol as ae,P as L,Pl as oe,Pn as R,Qu as se,Rl as ce,Td as z,Un as le,Vl as ue,Wd as de,Wn as fe,X as pe,Z as me,Zl as B,dn as V,du as H,jd as U,jl as he,jn as W,jr as ge,kd as _e,kl as ve,nr as G,pd as ye,pu as be,ql as xe,qu as K,rr as Se,sf as Ce,ud as we,ur as Te,va as Ee,z as De,zl as Oe}from"./src-D-Gp-jKI.js";import{t as ke}from"./history-BVPkDM04.js";import{t as Ae}from"./monitor-smartphone-5lHVpcLH.js";import{_ as q,a as je,b as Me,c as Ne,d as Pe,f as Fe,g as Ie,h as J,i as Le,l as Re,m as ze,n as Be,o as Ve,p as He,s as Ue,t as We,u as Ge,v as Y,y as Ke}from"./SessionsList-DZPXHEho.js";import{a as qe,i as Je,o as Ye,s as Xe}from"./client-B2uiK_6q.js";import{t as Ze}from"./useTranslation-Bc5yH9V9.js";import{X as Qe,Z as $e,c as et,et as tt,it as nt,nt as rt,ot as it,p as at,s as ot,w as st,z as X}from"./index-DpCn0dLh.js";import{t as ct}from"./AdminSectionedPage-tI4gVEsh.js";import{t as lt}from"./AdminPage-CKxdhLBh.js";import{n as ut,r as dt,t as ft}from"./AddonIntegrationBody-C9N9V3gJ.js";import{n as pt,t as mt}from"./addon-display-names-BkwMrExv.js";var ht=p(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),gt=p(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]);e();function _t(){let e=G(),t=H.useUtils(),r=Ke(),{data:i,isLoading:a}=C(),c=n(()=>i??[],[i]),l=H.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=H.auth.listLoginMethods.useQuery(),[d,f]=o(null),p=ue({onSuccess:()=>void t.userManagement.listExternalIdentities.invalidate(),onError:e=>f(`Remove failed: ${e.message}`)}),m=n(()=>new Map((u.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[u.data]),h=c.flatMap((e,t)=>l[t]?.data??[]),g=h.map(e=>({...Pe(e,r),kind:m.get(e.provider)??e.provider})),_=async t=>{let n=h.find(e=>Ge(e)===t.id);n!==void 0&&await e({title:`Remove sign-in link`,message:`"${t.ownerName}" will no longer be able to sign in with this ${t.kind} account.`,confirmLabel:`Remove`,variant:`danger`})&&(f(null),p.mutate({userId:n.userId,provider:n.provider,subject:n.subject}))};return s(q,{notice:Y(d),onDismissNotice:()=>{f(null)},id:`external-identities`,title:`Sign-in links`,icon:it,description:`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`,children:s(J,{rows:g,label:`sign-in links`,isLoading:a||l.some(e=>e.isLoading),loadError:l.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:`Remove`,icon:Me,isAvailable:()=>!0,onRun:e=>void _(e),busyId:null,disabled:p.isPending}})})}e();function vt(){let e=G(),t=a(),r=Ke(),i=P(),[c,l]=o(null),d=N({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>l(`Revoke failed: ${e.message}`)}),f=n(()=>(i.data??[]).map(e=>Re(e,r)),[i.data,r]),p=async t=>{await e({title:`Revoke "${t.name}"?`,message:`Any client using this key loses access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(l(null),d.mutate({id:t.id}))};return s(q,{notice:Y(c),onDismissNotice:()=>{l(null)},id:`legacy-api-keys`,title:`Legacy API keys`,icon:ke,description:`Keys from before scoped tokens. Nothing creates them any more; revoke them and issue a scoped token instead.`,children:s(J,{rows:f,label:`legacy API keys`,isLoading:i.isLoading,loadError:i.isError?i.error?.message??`Request failed`:null,emptyText:`No legacy API keys.`,action:{label:`Revoke`,icon:u,isAvailable:()=>!0,onRun:e=>void p(e),busyId:d.isPending?d.variables?.id??null:null,disabled:d.isPending}})})}e();function yt(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function bt(){let e=G(),t=a(),r=oe(),[i,c]=o(null),l=ce({onSuccess:()=>void t.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),onError:e=>c(`Revoke failed: ${e.message}`)}),d=n(()=>(r.data??[]).map(e=>Fe(e,e.scopes.map(yt).join(`, `))),[r.data]),f=async t=>{await e({title:`Revoke the "${t.name}" link?`,message:`${t.name} loses access for ${t.ownerName} on its next call. Linking it again needs the account-link flow from the start.`,confirmLabel:`Revoke`,variant:`danger`})&&(c(null),l.mutate({id:t.id}))},p=l.isPending?l.variables?.id??null:null;return s(q,{notice:Y(i),onDismissNotice:()=>{c(null)},id:`linked-apps`,title:`Linked apps`,icon:x,description:`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call.`,children:s(J,{rows:d,label:`linked apps`,isLoading:r.isLoading,loadError:r.isError?r.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:`Revoke`,icon:u,isAvailable:e=>e.status===`active`,onRun:e=>void f(e),busyId:p,disabled:l.isPending}})})}e();var xt={one:`session`,many:`sessions`};function St(){let e=G(),t=H.useUtils(),r=Ke(),i=H.auth.listSessions.useQuery(),[a,c]=o(null),l=()=>void t.auth.listSessions.invalidate(),u=H.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),d=Ie(`login-session`,xt,l),f=n(()=>(i.data??[]).map(e=>He(e,r,{client:e=>je(e).label,method:Ve})),[i.data,r]),p=async t=>{await e({title:`Sign out this session`,message:`${t.ownerName} on ${t.name} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(c(null),u.mutate({id:t.id}))};return s(q,{notice:Y(a,d.outcome),onDismissNotice:()=>{c(null),d.dismiss()},id:`login-sessions`,title:`Login sessions`,icon:Ae,description:`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`,children:s(J,{rows:f,label:`sessions`,isLoading:i.isLoading,loadError:i.isError?i.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:`Sign out`,icon:rt,isAvailable:e=>e.status===`active`,onRun:e=>void p(e),busyId:u.isPending&&u.variables!==void 0&&`id`in u.variables?u.variables.id:null,disabled:u.isPending||d.busy},bulk:{revoke:d,noun:xt,isSelectable:e=>e.status===`active`}})})}e();function Ct({open:e,users:n,onClose:r,onSubmit:i,submitting:a}){let{user:c}=X(),l=c?.isAdmin===!0?null:c?.scopes??[],[u,d]=o(n[0]?.id??``),[f,p]=o(``),[m,h]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[g,_]=o(``),v=L(m);return s(De,{open:e,onClose:r,title:`Create scoped token`,icon:M,width:`md`,testId:`create-scoped-token-dialog`,footer:t(D,{type:`button`,variant:`primary`,size:`sm`,onClick:()=>{let e=parseInt(g,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;i({userId:u,name:f.trim(),scopes:m,expiresAt:t})},disabled:!(u!==``&&f.trim().length>0&&m.length>0&&v===null&&!a),children:[a?s(z,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):s(M,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Issue token`]}),children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[s(V,{htmlFor:`scoped-token-user`,children:`On behalf of user`}),s(fe,{id:`scoped-token-user`,value:u,onChange:e=>d(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})]}),s(E,{label:`Name`,required:!0,children:s(B,{id:`scoped-token-name`,value:f,onChange:e=>p(e.target.value),placeholder:`cloudflare-tunnel-route`,autoFocus:!0})}),t(`div`,{className:`space-y-1`,children:[s(V,{children:`Scopes`}),s(re,{value:m,onChange:h,clampToParent:l}),v&&s(`p`,{className:`text-[10px] text-danger`,children:v}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`})]}),t(`div`,{className:`space-y-1`,children:[s(V,{htmlFor:`scoped-token-days`,children:`Expires in (days)`}),s(B,{id:`scoped-token-days`,type:`number`,min:1,value:g,onChange:e=>_(e.target.value),placeholder:`30`}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Leave blank for non-expiring.`})]})]})})}var wt={scoped:`newScoped`,admin:`newAdmin`};function Tt({token:e,label:n,onClose:r}){return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(F,{width:`md`,scroll:`body`,children:[s(w,{children:s(j,{children:`Token: ${n}`})}),t(W,{className:`space-y-3`,children:[s(`div`,{className:`rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),s(`div`,{className:`select-all break-all rounded-md border border-border bg-background p-2 font-mono text-[11px] text-foreground`,children:e})]}),t(R,{children:[s(T,{value:e,label:`Copy`,srLabel:`token`}),s(D,{type:`button`,variant:`primary`,size:`sm`,onClick:r,children:`Done`})]})]})})}e();function Et(e){return e.type===`device`?`device:[${me(e.selector)}]`:`${e.type}:${e.target??``}`}function Dt(){let e=G(),r=a(),i=Ke(),{data:c,isLoading:l}=C(),d=n(()=>c??[],[c]),f=H.useQueries(e=>d.map(t=>e.userManagement.listScopedTokens({userId:t.id}))),[p,h]=o(null),[g,_]=o(null),{state:v,openNew:y,close:b}=ne({newKey:wt.scoped}),x=()=>void r.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),w=S({onSuccess:({token:e,record:t})=>{x(),b(),_({token:e,label:t.name})},onError:e=>h(`Create failed: ${e.message}`)}),T=Oe({onSuccess:x,onError:e=>h(`Revoke failed: ${e.message}`)}),E=Date.now(),O=d.flatMap((e,t)=>(f[t]?.data??[]).map(t=>ze(t,e.id,i,t.scopes.map(Et).join(`, `),E))),ee=f.find(e=>e.isError)?.error?.message??null,k=async t=>{await e({title:`Revoke "${t.name}"?`,message:`${t.ownerName}'s scoped token stops working on its next use. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(h(null),T.mutate({id:t.id}))};return t(q,{notice:Y(p),onDismissNotice:()=>{h(null)},id:`scoped-tokens`,title:`Scoped tokens`,icon:m,description:`Tokens issued on behalf of a user for one narrow surface — an addon, an integration, a capability or some devices. Every token must be scoped, so revoking one has a predictable blast radius.`,actions:t(D,{type:`button`,variant:`primary`,size:`sm`,onClick:y,disabled:d.length===0,title:d.length===0?`Create a user first`:`Issue a scoped token`,children:[s(M,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`New token`]}),children:[s(J,{rows:O,label:`scoped tokens`,isLoading:l||f.some(e=>e.isLoading),loadError:ee,emptyText:`No scoped tokens.`,action:{label:`Revoke`,icon:u,isAvailable:()=>!0,onRun:e=>void k(e),busyId:T.isPending?T.variables?.id??null:null,disabled:T.isPending}}),s(Ct,{open:v.mode===`new`,users:d.map(e=>({id:e.id,username:e.username})),onClose:b,onSubmit:e=>w.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:w.isPending}),g!==null&&s(Tt,{token:g.token,label:g.label,onClose:()=>_(null)})]})}e();var Ot={one:`admin token`,many:`admin tokens`},kt=7,At=90,jt=80;function Mt(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=At?t:null}function Nt(){let{user:e}=X();return e?.isAdmin?s(Pt,{}):null}function Pt(){let e=G(),r=H.useUtils(),i=H.auth.listAdminTokens.useQuery(),a=Ke(),{requestProof:l,dialog:d}=Le(`Creating an admin token`),{state:f,openNew:p,close:m}=ne({newKey:wt.admin}),[h,g]=o(``),[_,v]=o(String(kt)),[y,b]=o(null),[x,S]=o(null),[C,w]=o(!1),[T,E]=o(null),O=()=>{r.auth.listAdminTokens.invalidate(),r.auth.listAuthAudit.invalidate()},ee=H.auth.createAdminToken.useMutation({onSuccess:({token:e,record:t})=>{O(),g(``),v(String(kt)),S(null),m(),E({token:e,label:t.name})},onError:e=>{b(`Create failed: ${e.message}`),S(`Create failed: ${e.message}`)}}),k=H.auth.revokeAdminToken.useMutation({onSuccess:O,onError:e=>b(`Revoke failed: ${e.message}`)}),A=Ie(`admin-token`,Ot,O);c(()=>{f.mode===`closed`&&(g(``),v(String(kt)),S(null),w(!1))},[f.mode]);let j=Date.now(),te=n(()=>(i.data??[]).map(e=>Ne(e,a,j)),[i.data,a]),M=h.trim(),N=Mt(_),P=M.length>0&&M.length<=jt&&N!==null&&!ee.isPending&&!C,F=async()=>{if(!P||N===null)return;b(null),S(null),w(!0);let e=await l();w(!1),e!==null&&ee.mutate({name:M,expiresInDays:N,reauthToken:e})},I=async t=>{await e({title:`Revoke admin token "${t.name}"?`,message:`Every script using it loses access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&(b(null),k.mutate({id:t.id}))};return t(`div`,{"data-testid":`admin-tokens`,children:[d,s(q,{id:`admin-tokens`,title:`Admin tokens`,icon:K,tone:`danger`,notice:Y(y,A.outcome),onDismissNotice:()=>{b(null),A.dismiss()},description:t(`div`,{className:`space-y-1`,children:[t(`p`,{children:[`An admin token acts as a `,s(`strong`,{children:`full administrator`}),` for scripts, e.g.`,` `,s(`code`,{className:`font-mono`,children:`node scripts/hub/hub.mjs --token-file <file> …`}),`. Anyone holding it can do anything an admin can.`]}),s(`p`,{children:`It expires in at most 90 days and every use is audited. Creating one asks you to confirm it is you.`})]}),actions:t(D,{type:`button`,variant:`danger`,size:`sm`,onClick:p,children:[s(K,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`New admin token`]}),children:s(J,{rows:te,label:`admin tokens`,isLoading:i.isLoading,loadError:i.isError?i.error?.message??`Request failed`:null,emptyText:`No admin tokens.`,action:{label:`Revoke`,icon:u,isAvailable:e=>e.status===`active`,onRun:e=>void I(e),busyId:k.isPending?k.variables?.id??null:null,disabled:k.isPending||A.busy},bulk:{revoke:A,noun:Ot,isSelectable:e=>e.status===`active`}})}),s(De,{open:f.mode===`new`,onClose:m,title:`Create admin token`,icon:K,error:x,width:`md`,testId:`admin-token-form-dialog`,footer:t(D,{type:`button`,variant:`danger`,size:`sm`,disabled:!P,onClick:()=>void F(),children:[ee.isPending||C?s(z,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):s(K,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),`Create admin token`]}),children:t(`div`,{className:`space-y-3`,children:[t(`div`,{className:`space-y-1`,children:[s(V,{htmlFor:`admin-token-name`,children:`Token name`}),s(B,{id:`admin-token-name`,value:h,maxLength:jt,onChange:e=>g(e.target.value),placeholder:`nightly-backup`,autoFocus:!0})]}),t(`div`,{className:`space-y-1`,children:[s(V,{htmlFor:`admin-token-days`,children:`Expires in (days)`}),s(B,{id:`admin-token-days`,type:`number`,min:1,max:At,value:_,onChange:e=>v(e.target.value),state:N===null?`error`:`default`}),N===null?t(`p`,{className:`text-[11px] text-danger`,children:[`Expiry must be a whole number of days, 1 to `,At,`.`]}):t(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Whole number of days, 1 to `,At,`.`]})]})]})}),T&&s(Tt,{token:T.token,label:T.label,onClose:()=>E(null)})]})}var Ft={"share-link":`share links`,"admin-token":`admin tokens`,"login-session":`login sessions`};function Z(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function It(e,t){let n=Z(e,`tokenId`);return Z(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Lt(e){return e.filter(e=>e!==null)}function Rt(e){let t=Z(e,`prefix`);return t===null?null:`Prefix ${t}…`}function zt(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:`Admin token "${It(n,t)}" created`,details:Lt([Rt(n),typeof e==`number`?`Expires ${Ue(e)}`:null])}}case`admin-token-used`:{let e=Z(n,`path`);return{title:`Admin token "${It(n,t)}" used`,details:Lt([Rt(n),e===null?null:`Call ${e}`])}}case`admin-token-revoked`:return{title:`Admin token "${It(n,t)}" revoked`,details:Lt([Rt(n)])};case`credentials-revoked`:{let e=Z(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Ft[e]??`${e}s`;return{title:`${typeof t==`number`?String(t):`?`} ${i} revoked in bulk`,details:Lt([typeof r==`number`&&r>0?`${String(r)} skipped`:null,Z(n,`ids`)===null?null:`Ids ${Z(n,`ids`)??``}`])}}case`second-factor-skipped`:{let e=Z(n,`method`),t=Z(n,`factors`);return{title:`Second factor skipped on a trusted network`,details:Lt([e===null?null:`Signed in with ${Ve(e)}`,t===null?null:`Skipped: ${t.split(`,`).join(`, `)}`])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}e();var Bt=100;function Vt(){let{user:e}=X();return e?.isAdmin?s(Ut,{}):null}function Ht(){let{data:e}=C(),{data:t}=H.auth.listAdminTokens.useQuery();return n(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.name);return{userNameById:n,tokenNameById:r}},[e,t])}function Ut(){let e=H.auth.listAuthAudit.useQuery({limit:Bt}),{userNameById:n,tokenNameById:r}=Ht(),i=e.data??[];return t(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[t(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[s(se,{className:`h-3.5 w-3.5 text-foreground-subtle`}),s(`div`,{className:`text-xs font-semibold text-foreground`,children:`Authentication audit`}),t(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[`Latest `,Bt,`, newest first`]})]}),s(`div`,{className:`p-4`,children:e.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading audit trail…`]}):e.isError?t(`div`,{className:`text-[11px] text-danger`,children:[`Could not load the audit trail: `,e.error?.message??`Request failed`]}):i.length===0?s(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center`,children:`No authentication events recorded yet.`}):s(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>s(Wt,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function Wt({record:e,userName:n,tokenNameById:r}){let i=zt(e,r);return t(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[t(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[s(`span`,{className:`font-medium text-foreground`,children:i.title}),s(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ue(e.at)})]}),t(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[n!==null&&s(`span`,{className:`text-foreground`,children:n}),e.ip!==void 0&&s(`span`,{className:`font-mono`,children:e.ip}),i.details.map(e=>s(`span`,{className:`font-mono`,children:e},e))]})]})}var Q={loginSessions:`login-sessions`,linkedApps:`linked-apps`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,legacyApiKeys:`legacy-api-keys`,externalIdentities:`external-identities`,audit:`auth-audit`},Gt={state:`ok`,stateLabel:`available`,showState:!1};function $(e,t,n,r){return{id:e,name:t,fallbackIcon:n,...Gt,render:r}}function Kt(){let e=P(),t=(e.data??[]).length>0;return s(dt,{embedded:!0,icon:gt,title:`Tokens & sessions`,subtitle:`Every credential this hub honours — who holds it, what it can reach, when it was last used and when it expires. Pick a kind; revoke one, or select several and revoke them after typing the count.`,groups:[{id:`sessions`,label:`Sessions`,entries:[$(Q.loginSessions,`Login sessions`,Ae,()=>s(St,{})),$(Q.linkedApps,`Linked apps`,x,()=>s(bt,{}))]},{id:`tokens`,label:`Tokens`,entries:[$(Q.scopedTokens,`Scoped tokens`,m,()=>s(Dt,{})),$(Q.adminTokens,`Admin tokens`,K,()=>s(Nt,{})),$(Q.shareLinks,`Share links`,te,()=>s(Be,{})),...t?[$(Q.legacyApiKeys,`Legacy API keys`,ke,()=>s(vt,{}))]:[]]},{id:`identity`,label:`Identity`,entries:[$(Q.externalIdentities,`Sign-in links`,it,()=>s(_t,{})),$(Q.audit,`Audit`,se,()=>s(Vt,{}))]}],isLoading:e.isLoading,emptyTitle:`No credential kinds`,emptyDescription:`This hub offers no credential kinds.`})}e();var qt=3e4,Jt=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],Yt={title:`Authentication`,subtitle:`Login providers (local password, OIDC, SAML) and second-factor providers (passkeys / WebAuthn). They run in parallel — enable or disable each independently; disabling one only removes that method, local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Xt(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:gt,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],setupSteps:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:nt,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:nt,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:v,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:v,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:M,bullets:[`Generic authentication provider. No additional hints registered.`]}}function Zt(){let e=I({capName:Jt[0].capName},{refetchInterval:qt}),t=I({capName:Jt[1].capName},{refetchInterval:qt}),r=ge(void 0,{refetchInterval:qt}),i=n(()=>mt(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Jt.entries())for(let a of r[e]??[])n.push({addonId:a.addonId,displayName:i.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,i]),o=[{id:`authentication`,label:`Authentication providers`,install:{capability:Jt[0].capName,label:Yt.installLabel},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:M,...pt(e.isActive),render:()=>s(ft,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:s(Te,{variant:`info`,className:ut,children:e.stageBadge}),panels:[{id:`about`,title:`About`,icon:Xt(e.addonId).icon,content:s(Qt,{addonId:e.addonId})}]})}))}];return s(dt,{embedded:!0,icon:M,title:Yt.title,subtitle:Yt.subtitle,groups:o,isLoading:e.isLoading||t.isLoading,emptyTitle:Yt.emptyTitle,emptyDescription:Yt.emptyDescription})}function Qt({addonId:e}){let n=Xt(e),r=n.icon;return t(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[t(`div`,{className:`flex items-start gap-2.5`,children:[s(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),s(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),s(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>s(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[t(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[s(ht,{className:`h-3 w-3`}),`Setup steps`]}),s(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>s(`li`,{children:e},t))})]}),e===`local-auth`&&t(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[s(U,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(Qe,{to:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,s(Qe,{to:`/system/identity?tab=users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function $t({userId:e,username:n,onClose:r}){let i=G(),a=H.useUtils(),o=ie({userId:e}),c=H.auth.listLoginMethods.useQuery(),l=ue({onSuccess:()=>void a.userManagement.listExternalIdentities.invalidate()}),u=new Map((c.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),d=o.data??[],f=async(t,r)=>{await i({title:`Remove sign-in link`,message:`"${n}" will no longer be able to sign in with this ${r} account.`,confirmLabel:`Remove`,variant:`danger`})&&l.mutate({userId:e,provider:t.provider,subject:t.subject})};return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(F,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[s(w,{children:t(j,{className:`flex items-center gap-2`,children:[s(x,{className:`h-4 w-4 text-primary`}),t(`span`,{children:[`Linked sign-in accounts`,t(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]})}),s(W,{className:`space-y-3`,children:o.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}):d.length===0?s(`p`,{className:`text-xs text-foreground-subtle`,children:`No linked accounts. Only the user can link one, from their own profile page.`}):s(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:d.map(e=>{let n=u.get(e.provider),r=n??e.provider;return t(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[t(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`font-medium text-foreground truncate`,children:[r,n===void 0&&s(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:`provider unavailable`})]}),t(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),t(`button`,{onClick:()=>void f(e,r),disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[s(Me,{className:`h-3 w-3`}),`Remove`]})]},`${e.provider}|${e.subject}`)})})}),s(R,{children:s(D,{onClick:r,variant:`secondary`,children:`Close`})})]})})}function en({userId:e,username:n,onClose:r}){let o=a(),c=G(),l=he({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=h({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(F,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(w,{children:t(j,{className:`flex items-center gap-2`,children:[s(v,{className:`h-4 w-4 text-primary`}),t(`span`,{children:[`Two-factor authentication`,t(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]})}),t(W,{className:`space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),p===`not_enrolled`&&t(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[s(U,{className:`h-4 w-4 mt-0.5 shrink-0`}),t(`div`,{children:[s(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),s(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),p===`enrolled`&&u&&t(i,{children:[t(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[s(Ce,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),t(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[s(`div`,{className:`font-medium`,children:`2FA is active`}),t(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`]})]})]}),s(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),t(`div`,{className:`flex justify-end gap-2`,children:[s(D,{onClick:r,variant:`secondary`,children:`Close`}),t(`button`,{onClick:async()=>{await c({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&f.mutate({userId:e})},disabled:f.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[f.isPending?s(z,{className:`h-3 w-3 animate-spin`}):s(be,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}e();function tn({userId:e,username:n,onClose:r}){let{user:i,logout:a}=X(),c=i?.id===e,l=G(),u=H.useUtils(),d=H.auth.listSessions.useQuery({userId:e}),[f,p]=o(null),m=H.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(c&&`userId`in t){a();return}u.auth.listSessions.invalidate()},onError:e=>p(`Sign out failed: ${e.message}`)}),h=async e=>{await l({title:`Sign out this session`,message:`"${n}" on ${je(e.client).label} will have to sign in again.`,confirmLabel:`Sign out`,variant:`danger`})&&(p(null),m.mutate({id:e.id}))},_=async()=>{await l({title:`Sign out everywhere`,message:c?`Every session of your own account ends, this browser included: you will be signed out here too.`:`Every session of "${n}" ends at once; each device has to sign in again.`,confirmLabel:`Sign out everywhere`,variant:`danger`})&&(p(null),m.mutate({userId:e}))},v=m.isPending&&m.variables!==void 0&&`id`in m.variables?m.variables.id:null;return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(F,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[s(w,{children:t(j,{className:`flex items-center gap-2`,children:[s(Ae,{className:`h-4 w-4 text-primary`}),t(`span`,{children:[`Active sessions`,t(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]})}),t(W,{className:`space-y-3`,children:[f!==null&&s(`div`,{className:`text-[11px] text-danger`,children:f}),s(We,{sessions:d.data??[],isLoading:d.isLoading,loadError:d.isError?d.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void h(e),revokingId:v})]}),t(R,{className:`justify-between`,children:[t(`button`,{onClick:()=>void _(),disabled:m.isPending||(d.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[m.isPending&&v===null?s(z,{className:`h-3 w-3 animate-spin`}):s(rt,{className:`h-3 w-3`}),`Sign out everywhere`]}),s(D,{onClick:r,variant:`secondary`,children:`Close`})]})]})})}function nn({icon:e,label:n,count:r,all:i,total:a}){return t(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[s(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:n}),s(`span`,{className:r===0?`text-foreground-subtle`:`font-medium text-foreground`,children:r===0?`none`:i?`all ${a}`:`${r} of ${a}`})]})}function rn({scopes:e,isAdmin:n,invalidReason:a}){let o=f(),c=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:l}=Ee({projection:`slim`}),d=l?.length??0;if(a!==null)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:t(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[s(K,{className:`h-3 w-3 shrink-0`}),a]})});if(c.isLoading)return t(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[s(z,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(c.isError||!c.data)return s(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:s(`p`,{className:`text-[11px] text-danger`,children:`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`})});let p=c.data;return s(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:p.isAdmin?t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`Administrator`}),` — unrestricted. Grants are ignored for an admin.`]}):t(i,{children:[s(nn,{icon:de,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:d}),s(nn,{icon:ye,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:d}),s(nn,{icon:u,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:d}),t(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[`System access: `,p.system.length===0?`none`:p.system.join(`, `),p.capabilities.length>0&&t(i,{children:[` · Extra capabilities: `,p.capabilities.map(e=>e.name).join(`, `)]}),p.addons.length>0&&t(i,{children:[` · Addons: `,p.addons.map(e=>e.name).join(`, `)]})]}),p.device.view.deviceCount===0&&s(`p`,{className:`text-[10px] text-warning`,children:`This user will not be able to see any device.`})]})})}e();function an(e){let t=Ye(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function on(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:qe({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function sn({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:u}){let f=n(()=>an(e.scopes??[]),[e.scopes]),[p,m]=o(f),[h,_]=o(f.mode===`advanced`),v=n(()=>on(p),[p]),y=!e.isAdmin&&p.mode===`role`&&p.roleId===null,b=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?`Pick what this user can do to see the result.`:L(v),[e.isAdmin,p.mode,p.roleId,v]),x=e=>m({...p,...e});return s(g,{open:!0,onOpenChange:e=>!e&&r(),children:t(F,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[t(w,{children:[t(j,{children:[`Access — `,e.username]}),s(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`This user is an administrator — they can do everything, and the settings below are ignored.`:`Choose what they can do, then which devices it applies to.`})]}),t(W,{className:`space-y-4`,children:[y&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(K,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),t(`p`,{className:`text-[11px] text-foreground`,children:[s(`span`,{className:`font-medium`,children:`No access.`}),` `,t(`span`,{className:`text-foreground-subtle`,children:[e.username,` cannot see or do anything yet. Configure it below.`]})]})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`1 · What can they do`}),s(`div`,{className:`space-y-1.5`,children:Je.map(e=>{let n=p.mode===`role`&&p.roleId===e.id;return t(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${n?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[s(`input`,{type:`radio`,name:`access-role`,checked:n,onChange:()=>x({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),t(`span`,{className:`min-w-0`,children:[s(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),s(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),t(`button`,{type:`button`,onClick:()=>{if(!h){m({...p,mode:`advanced`,advancedScopes:v}),_(!0);return}_(!1),m(an(p.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[s(h?l:d,{className:`h-3 w-3`}),`Advanced — edit raw grants`]}),h&&t(`div`,{className:`rounded-lg border border-border p-2`,children:[s(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`}),s(re,{value:p.advancedScopes,onChange:e=>x({mode:`advanced`,advancedScopes:e}),clampToParent:u,emptyHint:t(i,{children:[`No grants.`,` `,s(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until one is added.`]})})]})]}),p.mode===`role`&&t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:`2 · On which devices`}),s(pe,{value:p.selector,onChange:e=>x({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>x({includeLinked:e}),clampToDeviceIds:null})]}),t(`section`,{className:`space-y-2`,children:[s(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p.mode===`role`?`3 · Result`:`2 · Result`}),s(rn,{scopes:v,isAdmin:e.isAdmin,invalidReason:b})]})]}),t(R,{children:[s(D,{variant:`outline`,size:`sm`,onClick:r,children:`Cancel`}),s(D,{size:`sm`,onClick:()=>a([...v]),disabled:c||b!==null,children:c?s(z,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var cn=8;function ln(){return{username:``,password:``,isAdmin:!1}}function un(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function dn(e){return e instanceof Error?e.message:`Something went wrong`}function fn(){let e=a(),{user:n}=X(),{state:r,openNew:l,openEdit:d,close:f}=ne(),[p,m]=o(null),[h,g]=o(null),[y,S]=o(!1),{data:w,isLoading:T,isError:j,error:te,refetch:N}=C(),P=G(),F=Se(),I=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),re=ae(),ie=ve({onSuccess:I}),L=O({onSuccess:I}),oe=A({onSuccess:I}),R=_({onSuccess:()=>{I(),ce(null)}}),[se,ce]=o(null),[ue,de]=o(null),[fe,pe]=o(null),[me,V]=o(null),H=w??[],U=r.mode===`edit`?H.find(e=>e.id===r.id)??null:null,he=()=>{m(null),g(null),S(!1),re.reset(),L.reset(),f()};c(()=>{if(r.mode===`closed`){m(null),g(null),S(!1);return}if(r.mode===`new`){m(e=>e!==null&&e.id===void 0?e:ln());return}if(U===null){T||f();return}m(e=>e?.id===U.id?e:un(U))},[r,U,T,f]);let W=r.mode===`new`&&p!==null&&p.id===void 0||r.mode===`edit`&&p!==null&&U!==null;async function ge(e){await P({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&(ie.mutate({id:e.id}),r.mode===`edit`&&r.id===e.id&&he())}async function be(e){let t=await F({title:`Reset password`,message:`Set a new password for "${e.username}".`,label:`New password`,inputType:`password`,placeholder:`At least 8 characters`,confirmLabel:`Continue`,validate:e=>e.length<cn?`Password must be at least ${String(cn)} characters.`:null});t===null||t.length===0||await P({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&oe.mutate({id:e.id,newPassword:t})}function K(e,t){t!==e.isAdmin&&L.mutate({id:e.id,isAdmin:t})}async function Ce(){if(p!==null){g(null);try{if(p.id===void 0){let e=p.username.trim();if(e===``||p.password.length<cn)return;await re.mutateAsync({username:e,password:p.password,isAdmin:p.isAdmin})}else await L.mutateAsync({id:p.id,isAdmin:p.isAdmin});I(),he()}catch(e){g(dn(e))}}}function Te(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let Ee=re.isPending||L.isPending,Oe=p!==null&&p.id===void 0&&p.username.trim()!==``&&p.password.length>=cn,ke=p!==null&&p.id!==void 0,q=Ee||(p?.id===void 0?!Oe:!ke),je=e=>ie.isPending&&ie.variables?.id===e.id||L.isPending&&L.variables?.id===e.id||oe.isPending&&oe.variables?.id===e.id;return t(lt,{embedded:!0,icon:b,title:`Users`,subtitle:`Hub accounts, admin flag, access scopes, sessions and sign-in links.`,actions:t(D,{size:`sm`,type:`button`,onClick:()=>{g(null),l()},children:[s(we,{className:`h-3.5 w-3.5`}),`Create User`]}),children:[j&&s(ee,{title:`Could not load users`,message:dn(te),onRetry:()=>void N()}),T&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(z,{className:`h-3.5 w-3.5 animate-spin`}),`Loading…`]}),!T&&!j&&H.length===0&&s(le,{icon:b,title:`No users yet`,description:`Create a user to grant hub access.`}),!T&&!j&&H.length>0&&s(k,{columns:[{key:`username`,header:`Username`,sortValue:e=>e.username,render:e=>s(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`isAdmin`,header:`Admin`,nowrap:!0,sortValue:e=>+!!e.isAdmin,render:e=>s(`span`,{onClick:e=>e.stopPropagation(),children:t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:e.isAdmin,onChange:t=>K(e,t.target.checked),disabled:je(e),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:e.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:e.isAdmin?`Admin`:`Regular`})]})})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):s(`span`,{onClick:e=>e.stopPropagation(),children:t(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ce(e),title:`Configure access`,children:[s(M,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(pn,{scopes:e.scopes??[]})]})})},{key:`createdAt`,header:`Created`,nowrap:!0,sortValue:e=>e.createdAt,render:e=>s(`span`,{className:`text-foreground-subtle`,children:Te(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:e=>{let r=je(e),i=e.id!==n?.id&&e.totpEnabled;return t(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[t(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>d(e.id),disabled:r,title:`Edit user`,children:[s(ye,{className:`h-3 w-3`}),`Edit`]}),i&&t(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>de(e),disabled:r,title:`Remove two-factor authentication`,children:[s(v,{className:`h-3 w-3`}),`Remove 2FA`]}),t(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>pe(e),disabled:r,title:`Linked sign-in accounts`,children:[s(x,{className:`h-3 w-3`}),`Sign-in links`]}),t(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>V(e),disabled:r,title:`Active sessions`,children:[s(Ae,{className:`h-3 w-3`}),`Sessions`]}),t(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void be(e),disabled:r,title:`Reset password`,children:[s(_e,{className:`h-3 w-3`}),`Reset password`]}),t(D,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void ge(e),disabled:r,title:`Delete user`,className:`text-danger hover:bg-danger/10`,children:[r?s(z,{className:`h-3 w-3 animate-spin`}):s(u,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:H,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,mobileMode:`scroll`,onRowClick:e=>d(e.id)}),s(De,{open:W,onClose:he,title:p?.id===void 0?`Create User`:`Edit ${p.username||`user`}`,icon:b,error:h,testId:`user-form-dialog`,footer:s(D,{size:`sm`,type:`button`,disabled:q,onClick:()=>void Ce(),children:Ee?t(i,{children:[s(z,{className:`h-3.5 w-3.5 animate-spin`}),`Saving…`]}):p?.id===void 0?`Create`:`Save`}),children:p!==null&&t(`div`,{className:`space-y-3`,children:[s(E,{label:`Username`,required:p.id===void 0,children:s(B,{value:p.username,onChange:e=>m({...p,username:e.target.value}),placeholder:`john`,autoFocus:p.id===void 0,disabled:p.id!==void 0,"data-testid":`user-form-username`})}),p.id===void 0&&s(E,{label:`Password`,required:!0,description:`At least ${String(cn)} characters.`,children:s(xe,{value:p.password,onValueChange:e=>m({...p,password:e}),shown:y,onToggleShown:()=>S(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),s(E,{label:`Admin`,description:`Unrestricted access to every capability and device.`,children:t(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:p.isAdmin,onChange:e=>m({...p,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),s(`span`,{children:`Admin`})]})}),p.id!==void 0&&s(`p`,{className:`text-[11px] text-foreground-subtle`,children:`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`})]})}),ue&&s(en,{userId:ue.id,username:ue.username,onClose:()=>de(null)}),fe&&s($t,{userId:fe.id,username:fe.username,onClose:()=>pe(null)}),me&&s(tn,{userId:me.id,username:me.username,onClose:()=>V(null)}),se&&s(mn,{user:se,onClose:()=>ce(null),onSubmit:e=>R.mutate({userId:se.id,scopes:e}),submitting:R.isPending})]})}function pn({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=Ye(e);return n===null?t(`span`,{className:`text-foreground-subtle`,children:[`Custom · `,e.length,` grant`,e.length===1?``:`s`]}):t(`span`,{className:`text-foreground-subtle`,children:[s(`span`,{className:`font-medium text-foreground`,children:Xe(n.roleId).label}),` ·`,` `,me(n.selector)]})}function mn(e){let{user:t}=X(),n=t?.isAdmin===!0;return s(sn,{...e,callerScopes:n?null:t?.scopes??[]})}var hn={"api-keys":Q.scopedTokens,"linked-sessions":Q.linkedApps};function gn(){let{t:e}=Ze(),[t]=tt(),n=hn[t.get(`tab`)??``];if(n!==void 0)return s($e,{to:at(`access`,{integration:n}),replace:!0});let r=st(`/system/identity`,{t:e,isAdmin:!0})??{icon:y,title:e(`system.identity`,`Identity & Access`)};return s(ct,{icon:r.icon,title:r.title,defaultSection:`users`,sectionsLabel:`${r.title} sections`,sections:[{id:`users`,label:`Users`,content:s(fn,{})},{id:et.access.tab,label:`Tokens & sessions`,content:s(Kt,{}),ownedParams:ot.concat([wt.scoped,wt.admin])},{id:et.authentication.tab,label:`Authentication`,content:s(Zt,{}),ownedParams:ot}]})}export{gn as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W 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{_t as l,ct as u,gt as d,ht as f,ot as p,yt as m}from"./player-overlays-Sm-ivm_8.js";import{$i as h,An as g,Da as _,Fn as v,In as y,It as b,Kt as x,Lr as S,Mn as C,Ou as w,Qi as T,Qu as E,Ta as D,Td as O,Tt as k,Wa as A,Wd as j,Yu as M,Zi as N,aa as P,br as F,co as I,df as ee,do as L,ea as R,et as te,fo as z,gu as B,ho as V,ia as H,id as U,iu as W,jn as G,kf as K,la as ne,ln as re,lo as ie,nf as q,od as ae,of as J,pa as Y,po as oe,pu as X,ra as se,rd as ce,rt as le,ta as ue,tt as de,tu as fe,ua as pe,ud as me,uo as he,va as ge,wn as Z,yr as _e}from"./src-D-Gp-jKI.js";import{Er as ve}from"./client-B2uiK_6q.js";import{t as ye}from"./useTranslation-Bc5yH9V9.js";import{$ as be,J as xe,L as Se,Q as Ce,et as we}from"./index-DpCn0dLh.js";import{t as Te}from"./NodeAddonsSettingsPanel-DFxGT0UJ.js";import{t as Ee}from"./device-integration-icon-BzUlpgwp.js";import{n as De,r as Oe,t as ke}from"./ScanNetworkModal-B0-S-15i.js";var Ae=m(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);n();function Q(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Q(n.fields));return t}function je(t,n,r){let[a,s]=o(`idle`),[c,l]=o({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...Q(n.fields));return e},[t]),d=u.length>0&&r!==void 0,f=e(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:a,hasProbeFields:d,probeResults:c,handleTestAll:e(async()=>{if(!r)return;let e=u.filter(e=>{let t=n[e];return t!=null&&String(t).trim()!==``});if(e.length===0)return;s(`testing`);let t={};for(let n of e)t[n]={status:`probing`};l(t);let i=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await r(e,n[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),a={};for(let e of i)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;a[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(a),s(`idle`)},[r,u,n]),clearProbeResult:f}}n();function Me(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Me(n.fields));return t}function Ne(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Pe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Pe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Fe(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Ie({open:t,integrationId:n,addonId:u,onClose:d}){let{t:f}=ye(),p=a(),[m,h]=o({}),[g,_]=o(!1),[v,y]=o(null),[b,x]=o(Fe),S=D({addonId:u},{enabled:t}),C=S.data?.deviceType??null,T=Y({addonId:u,type:C??ve.Camera},{enabled:t&&S.isSuccess&&C!==null}),j=T.data??null;c(()=>{t&&(h(j?Pe(j.sections.flatMap(e=>e.fields)):{}),x(Fe()),_(!1),y(null))},[t,n,j]);let M=i(()=>({...m,_probeRequestId:b}),[m,b]),N=H({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),P=A(),F=e(async(e,t)=>{_(!0);let n=await P.mutateAsync({addonId:u,type:C??ve.Camera,key:e,value:t,formValues:M});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ne(e[i])&&!Ne(a)&&(r[i]=a,t=!0);return t?r:e}),n},[P,u,M,C]),{testAllStatus:I,hasProbeFields:ee,probeResults:L,handleTestAll:R,clearProbeResult:te}=je(j??{sections:[]},m,F);async function z(e){y(null);try{await N.mutateAsync({addonId:u,type:C??ve.Camera,config:m,integrationId:n}),e?h(j?Pe(j.sections.flatMap(e=>e.fields)):{}):d()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let V=Me((j?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ne(m[e])),U=V.length===0,W=S.isLoading||C!==null&&T.isLoading,G=S.isError||S.isSuccess&&C===null||T.isError||T.isSuccess&&j===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:d}),r(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),s(`button`,{onClick:d,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:s(X,{className:`h-4 w-4`})})]}),s(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:W?s(`div`,{className:`flex items-center justify-center py-8`,children:s(O,{className:`h-5 w-5 animate-spin text-primary`})}):G?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[s(w,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,s(`span`,{className:`font-mono`,children:u}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):s(Se,{schema:j,values:m,onChange:h,onTestField:F,probeResults:L,onClearProbe:te})}),!G&&!W&&r(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[r(`button`,{type:`button`,onClick:()=>_(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[r(`span`,{className:`flex items-center gap-2`,children:[s(E,{className:`h-3.5 w-3.5`}),`Test logs`,s(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),s(l,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&s(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:s(k,{addonId:u,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!G&&!W&&(v||V.length>0)&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(w,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${V.join(`, `)}`})]})}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:d,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!G&&ee&&r(`button`,{type:`button`,onClick:R,disabled:I===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[I===`testing`?s(O,{className:`h-3.5 w-3.5 animate-spin`}):s(B,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:()=>z(!0),disabled:G||!U||N.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),s(`button`,{onClick:()=>z(!1),disabled:G||!U||N.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:N.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Le=1500;function $({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=ye(),o=N(),c=(R({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Le:!1}).data??[]).find(e=>e.jobId===n);if(!c)return null;let l=c.state===`running`,u=c.processed,d=c.total>0?Math.round(u/c.total*100):0;!l&&c.finishedAt!==null&&i();let f=[`${u}/${c.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];c.adopted>0&&f.push(`${c.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),c.alreadyAdopted>0&&f.push(`${c.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),c.failed>0&&f.push(`${c.failed} ${a(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let p=f.join(` · `);return r(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[r(`div`,{className:`flex items-center gap-2`,children:[l?s(O,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):c.failed>0?s(w,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):c.state===`cancelled`?s(q,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):s(J,{className:`h-3.5 w-3.5 text-primary shrink-0`}),s(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&s(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:a(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),s(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:s(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),c.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>r(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Re(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}n();var ze=`devices`,Be={id:ze,label:`Devices`,isDefault:!0},Ve=2e4,He=100;function Ue({addonId:n,integrationId:i,onClose:l}){let{t:u}=ye(),d=a(),[f,p]=o(new Set),[m,g]=o(new Set),[_,v]=o(new Map),[y,b]=o(null),{data:x}=he(),S=(x??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[C,E]=o(!0),D=T({addonId:n,integrationId:i}).data?.filters,k=D&&D.length>0?D:[Be],[A,j]=o(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===ze)?ze:k[0].id)),M=A!==ze,N=ue(),P=h({addonId:n,integrationId:i,page:1,pageSize:Ve,filter:A}),F=P.refetch,I=N.mutate,L=e(()=>{I({addonId:n,integrationId:i},{onSettled:()=>{F()}})},[I,n,i,F]),R=t(null);c(()=>{let e=`${n}::${i}`;R.current===e||P.isLoading||(R.current=e,(P.data?.candidates.length??0)===0&&L())},[n,i,P.isLoading,P.data,L]);let z=N.isPending,B=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=typeof N.data?.lastError==`string`&&N.data.lastError.length>0?N.data.lastError:null,H=P.data?.candidates??[],U=P.isError?P.error instanceof Error?P.error.message:String(P.error):null,G=se(),[K,ne]=o(null),re=e(e=>{e.alreadyAdopted||p(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),ie=e(e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),q=e((e,t)=>{v(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),ae=e(e=>{let t={};for(let n of e){let e=_.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[_]),J=e(async()=>{b(null);let e=[...f];if(e.length!==0)try{let t=ae(e),{jobId:r}=await G.mutateAsync({addonId:n,integrationId:i,filter:A,childNativeIds:e,...t?{perCandidate:t}:{},...S?{importLocations:C}:{}});ne(r),p(new Set),v(new Map)}catch(e){b(e instanceof Error?e.message:String(e))}},[f,ae,G,n,i,A,S,C]),Y=t(null),oe=e(()=>{K===null||Y.current===K||(Y.current=K,F(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[K,F,d]),le=e(e=>{j(e),p(new Set),g(new Set),v(new Map),b(null)},[]),de=f.size,pe=K!==null&&de===0&&!G.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),r(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[r(`div`,{className:`min-w-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),s(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:u(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),r(`div`,{className:`flex items-center gap-3 shrink-0`,children:[S&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[s(`input`,{type:`checkbox`,checked:C,onChange:e=>E(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),s(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:s(X,{className:`h-4 w-4`})})]})]}),r(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(B??U??V)&&H.length===0&&s(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(w,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[s(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),s(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:B??U??V})]})]})}),k.length>1&&s(We,{filters:k,activeFilter:A,onSelect:le}),s(`div`,{className:`flex-1 min-h-0`,children:s(te,{mode:`generic`,items:H,pageSize:He,getKey:e=>e.childNativeId,getSearchText:Re,getFilterType:e=>e.type,filterOptions:fe(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:P.isLoading||z&&H.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(B??U??V)&&H.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:L,disabled:z,title:u(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[s(ce,{className:`h-3.5 w-3.5 ${z?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>s(Ge,{candidate:e,expandable:!M,expanded:m.has(e.childNativeId),onToggleExpand:()=>ie(e.childNativeId),adoptedLabel:u(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:u(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=W(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[s(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>s(`div`,{className:`flex items-center justify-end`,children:s(`button`,{onClick:()=>re(e),disabled:e.alreadyAdopted,"aria-label":f.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${f.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:f.has(e.childNativeId)&&s(ee,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!M&&m.has(e.childNativeId),renderExpanded:M?void 0:e=>s(Ke,{candidate:e,hiddenChildIds:_.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>q(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),y&&s(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:r(`div`,{className:`flex items-start gap-2`,children:[s(w,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),s(`p`,{className:`text-[11px] text-destructive`,children:y})]})}),K!==null&&s($,{addonId:n,integrationId:i,jobId:K,onFinished:oe}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[s(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:u(`integrations.cancel`,{defaultValue:`Cancel`})}),r(`button`,{onClick:pe?l:J,disabled:!pe&&(de===0||G.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[G.isPending&&s(O,{className:`h-3.5 w-3.5 animate-spin`}),pe?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!pe&&de>0?` (${de})`:``]})]})]})]})]})}function We({filters:e,activeFilter:t,onSelect:n}){return s(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return s(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ge({candidate:e,expandable:t,expanded:n,onToggleExpand:i,adoptedLabel:a}){let o=(e.children??[]).length;return r(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&o>0?r(`button`,{type:`button`,onClick:i,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[s(n?l:d,{className:`h-3.5 w-3.5`}),o]}):s(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),s(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&s(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Ke({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:s(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),a=e.capabilities??[];return r(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[s(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&s(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),s(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?`Show child`:`Hide child`,title:i?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:s(i?f:j,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function qe(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...qe(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Je(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>qe(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ye(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Xe({integrationId:e,addonId:t,name:n,kind:o,mode:c,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=ye(),m=a(),{data:h,isLoading:_}=L({id:e},{enabled:c===`account`||c===`broker`}),b=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:x,isLoading:S}=_e({addonId:t,nodeId:`hub`},{enabled:c===`account`}),w=i(()=>x?Ye(x):null,[x]),T=oe(),E=(t,n)=>{T.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return s(g,{open:!0,onOpenChange:e=>!e&&f(),children:r(C,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[s(v,{children:r(y,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]})}),s(G,{children:c===`broker`?l?r(`div`,{className:`space-y-3`,children:[s(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),b&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,s(`span`,{className:`font-mono text-foreground-subtle`,children:b})]}),T.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(O,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):s(Oe,{kind:l,onResolved:e=>{E({brokerId:e})},onBack:f}),T.isError&&s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):s(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):c===`account`?_||S?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[s(O,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):s(De,{addonId:t,configSchema:w,canTest:u,initialName:n,initialConfig:Je(w,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>E(e,t),onBack:f}):s(Z,{trpc:d,addonId:t,nodeId:`hub`,title:n})})]})})}function Ze(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Qe(){let{t}=ye(),{integrationId:n}=be(),l=a(),d=Ce(),[f,m]=we(),h=p(),[w,T]=o(!1),[D,A]=o(!1),[j,N]=o(!1),[ee,L]=o(!1),{data:R,isLoading:B}=ie({id:n??``},{enabled:!!n}),{data:H}=_e({addonId:R?.addonId??``,nodeId:`hub`},{enabled:!!R?.addonId}),{data:W,isSuccess:q}=he(),J=i(()=>{let e=R?.addonId;return!e||!q?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,R?.addonId,q]),{data:Y}=ne({}),oe=i(()=>(Y?.providers??[]).some(e=>e.addonId===R?.addonId),[Y,R?.addonId]),X=J!==null,se=R?.info?.fixed===!0,ce=X?J===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ue=i(()=>{let e=R?.addonId;return!e||!q?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,R?.addonId,q]),fe=i(()=>{let e=R?.addonId;return!e||!q?!1:(W??[]).find(t=>t.addonId===e)?.canTest===!0},[W,R?.addonId,q]),Z=i(()=>{let e=R?.addonId;return!e||!q?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,R?.addonId,q]);c(()=>{f.get(`add`)===`1`&&X&&(T(!0),m(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[f,X,m]);let ve=H!=null&&Array.isArray(H.sections)&&H.sections.some(e=>e.fields.length>0),{data:xe}=F({addonId:R?.addonId??``,nodeId:`hub`},{enabled:!!R?.addonId&&Z!==`account`}),Se=Z!==null&&Z!==`account`&&Ze(xe),De=i(()=>R?.addonId?[R.addonId]:[],[R?.addonId]),{data:Oe}=ge({projection:`slim`},{refetchInterval:3e4}),Q=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],je=V({onMutate:async e=>{await l.cancelQueries({queryKey:Q});let t=l.getQueryData(Q);return t!=null&&l.setQueryData(Q,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&l.setQueryData(Q,r.previous)},onSettled:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=I({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]}),d(`/integrations`)}}),Ne=S({onSuccess:()=>{l.invalidateQueries({queryKey:[[`integrations`]]}),l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Pe=_({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=P({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=pe({onSuccess:()=>{l.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=i(()=>Oe??[],[Oe]),Re=i(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),ze=e(e=>Re.get(e)??null,[Re]),{data:Be}=z(void 0),Ve=i(()=>de(Be),[Be]),He=e(e=>d(`/devices/${String(e)}`),[d]),We=i(()=>{let e=R?.id;return e?$.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[$,R?.id,Ve]),Ge=i(()=>Be===void 0?null:le(We).length,[Be,We])??`…`;return B?r(`div`,{className:`p-4`,children:[s(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),s(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):R?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[s(x,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:R.name}]}),r(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[r(`div`,{className:`flex items-center gap-3 min-w-0`,children:[s($e,{addonId:R.addonId}),r(`div`,{className:`min-w-0`,children:[s(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:R.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[R.addonId,` · `,Ge,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[oe&&r(`button`,{onClick:()=>A(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[s(ae,{className:`h-3.5 w-3.5`}),`Scan network`]}),!se&&r(`button`,{onClick:()=>T(!0),disabled:!X,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:ce,children:[s(me,{className:`h-3.5 w-3.5`}),ce]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${je.isPending?`opacity-60`:``} ${R.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[s(re,{checked:R.enabled,onCheckedChange:e=>je.mutate({id:n,enabled:e}),disabled:je.isPending,"aria-label":R.enabled?`Disable integration`:`Enable integration`}),s(`span`,{className:`text-[11px] font-medium ${R.enabled?`text-success`:`text-foreground-subtle`}`,children:R.enabled?`Enabled`:`Disabled`}),je.isPending&&s(O,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Z!==`standalone`&&(ve||J===`device-adoption`)&&r(`button`,{onClick:()=>N(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[s(M,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>L(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:t(`integrations.logs`,{defaultValue:`View logs`}),children:[s(E,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),s(b,{label:`Restart`,icon:U,title:`Restart "${R.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ge} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({addonId:R.addonId})}),!se&&n&&s(b,{label:t(`integrations.delete`,{defaultValue:`Delete`}),icon:u,title:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:R.name,count:Ge}),confirmLabel:t(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Me.isPending,action:()=>Me.mutateAsync({id:n})})]})]}),Se&&s(Te,{nodeId:null,addonIds:De,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),s(te,{context:`integration-detail`,devices:$,trpc:h.trpcClient,integrationOf:Ve,forceIntegrationId:R.id,urlScope:`root`,lsKey:`integration-detail:${R.addonId}`,resolveIntegrationIcon:Ee,resolveParent:ze,onNavigate:He,batchActions:{remove:Pe.mutate,disable:Fe.mutate,enable:Le.mutate},...se?{}:{onDeleteDevice:e=>Pe.mutate({deviceId:e.id})}}),w&&n&&J===`device-adoption`&&s(Ue,{addonId:R.addonId,integrationId:n,onClose:()=>T(!1)}),w&&n&&J===`device-provider`&&s(Ie,{open:w,integrationId:n,addonId:R.addonId,onClose:()=>T(!1)}),D&&R&&s(ke,{open:D,scope:{addonId:R.addonId,label:R.name},onClose:()=>A(!1)}),j&&n&&J!==null&&Z!==null&&s(Xe,{integrationId:n,addonId:R.addonId,name:R.name,kind:J,mode:Z,brokerKind:ue,canTest:fe,trpc:h.trpcClient,onClose:()=>N(!1)}),ee&&s(g,{open:!0,onOpenChange:e=>!e&&L(!1),children:r(C,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[s(v,{className:`mb-0`,children:r(y,{className:`flex items-center gap-2 min-w-0`,children:[s(E,{className:`h-4 w-4 text-primary shrink-0`}),s(`span`,{className:`truncate`,children:R.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[R.addonId,n?` · ${n}`:``]})]})}),s(G,{className:`min-h-0 overflow-hidden p-0`,children:s(k,{addonId:R.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[s(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:s(Ae,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),s(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),r(`button`,{onClick:()=>d(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[s(K,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function $e({addonId:e}){let t=xe(e),[n,r]=o(!1);return!t||n?null:s(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>r(!0)})}export{Qe as IntegrationDetailPage};
|
|
@@ -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{_t as l,gt as u,ot as d,vt as f}from"./player-overlays-Sm-ivm_8.js";import{$l as p,M as m,Td as h,Xi as ee,Yu as g,df as _,et as v,fo as y,id as b,ld as x,od as S,pu as te,r as C,rt as ne,sa as w,so as re,tt as T,ud as E,uo as D,va as O,yr as k}from"./src-D-Gp-jKI.js";import{t as A}from"./useTranslation-Bc5yH9V9.js";import{Q as j,et as ie,q as M}from"./index-DpCn0dLh.js";import{t as N}from"./AdminPage-CKxdhLBh.js";import"./useEventInvalidation-CQJ7chdb.js";import{t as ae}from"./device-integration-icon-BzUlpgwp.js";import{n as oe,r as P,t as F}from"./ScanNetworkModal-B0-S-15i.js";t();function I(e=!0){c(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}t();function L(e,t){let[n,r]=o(!1);return c(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}t();function R({providerId:e,onImport:t,onSkip:r}){let{t:i}=A(),[a,l]=o(new Set),u=w(),d=u.data,p=u.isPending||!u.data&&!u.isError;c(()=>{e&&(u.isPending||u.data||u.mutate({addonId:e}))},[e,u]);function m(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(p)return n(`div`,{className:`flex flex-col items-center py-12`,children:[s(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),s(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:i(`integrations.searchingDevices`)})]});let h=d??[];return n(`div`,{className:`space-y-4`,children:[s(`p`,{className:`text-xs text-foreground-subtle`,children:h.length>0?i(`integrations.foundDevices`,{count:h.length}):i(`integrations.noDevicesFound`)}),h.length>0&&s(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:h.map(e=>{let t=e.stableId,r=e.suggestedName??t,o=a.has(t),c=e.alreadyOnboarded===!0;return n(`button`,{onClick:()=>{c||m(t)},disabled:c,title:c?i(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:e.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${c?`border-border bg-surface opacity-60 cursor-not-allowed`:o?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[s(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${o&&!c?`border-primary bg-primary`:`border-border`}`,children:o&&!c&&s(_,{className:`h-3 w-3 text-primary-foreground`})}),s(f,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),s(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),c&&s(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:i(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},t)})}),n(`div`,{className:`flex items-center justify-between pt-2`,children:[s(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.skip`)}),h.length>0&&n(`button`,{onClick:()=>t(Array.from(a)),disabled:a.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[i(`integrations.importSelected`),` (`,a.size,`)`]})]})]})}function z({onSelect:e,onClose:t,pendingAddonId:r=null}){let{t:i}=A(),a=j(),{data:o,isLoading:c}=D();if(c)return s(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-14 rounded-lg bg-surface animate-pulse`},e))});let l=r!==null;return n(`div`,{className:`space-y-2`,children:[(o??[]).map(o=>{let c=o.instanceMode===`unique`&&o.existingInstances.length>0,d=r===o.addonId,f=l;return n(`button`,{disabled:f,onClick:()=>{if(!f)if(c){let e=o.existingInstances[0].id;t(),a(`/integrations/${e}`)}else e(o.addonId,o.instanceMode,o.discoveryMode,o.name,o.kind,o.brokerKind,o.mode,o.canTest)},className:`flex w-full items-center gap-3 rounded-lg border border-border bg-surface p-3 text-left hover:border-foreground-subtle/30 transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[o.iconUrl?s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`img`,{src:o.iconUrl,alt:``,className:`h-5 w-5`})}):s(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${o.color}15`},children:s(`span`,{className:`text-sm`,style:{color:o.color},children:`◉`})}),n(`div`,{className:`flex-1 min-w-0`,children:[s(`p`,{className:`text-xs font-semibold text-foreground`,children:o.name}),o.description&&s(`p`,{className:`text-[10px] text-foreground-subtle mt-0.5 truncate`,children:o.description})]}),d?s(h,{className:`h-4 w-4 animate-spin text-primary flex-shrink-0`}):c?n(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[s(g,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(u,{className:`h-4 w-4 text-foreground-subtle flex-shrink-0`})]},o.addonId)}),(o??[]).length===0&&s(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:i(`integrations.noProviders`)})]})}t();function se(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var B=2e4;function V({open:e,onClose:t}){let{t:l}=A(),u=j(),d=a(),[f,p]=o(`picker`),[m,g]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[x,S]=o(null),[C,ne]=o(``),[T,E]=o(null),[D,O]=o(null),[ie,M]=o(!1),{data:N}=k({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),ae=r(()=>N?se(N):null,[N]),F=re({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=w(),H=V.data;c(()=>{f!==`discovery`||!_||!m||V.isPending||V.data||V.mutate({addonId:m})},[f,_,m,V]);let ce=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(g(e),M(s),b(n),ne(r),O(null),o===`broker`){if(!a){O(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}S(a),p(`broker`);return}if(o===`account`){p(`config`);return}U(e,r)}}async function U(e,n){try{let r=await F.mutateAsync({addonId:e,name:n,settings:{}});t(),J(),u(`/integrations/${r.id}?add=1`)}catch{}}async function W(e){if(m)try{let t=await F.mutateAsync({addonId:m,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),y===`auto`||y===`both`?p(`discovery`):q(t.id)}catch{}}async function G(e){if(m)try{let t=await F.mutateAsync({addonId:m,name:C,settings:{brokerId:e}});E(t.id),v(t.id),q(t.id)}catch{}}async function K(e){if(m){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:m,candidate:e,...T===null?{}:{integrationId:T}})}q()}}function q(e){let n=e??_??m;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),g(null),v(null),b(`manual`),S(null),ne(``),E(null),O(null),M(!1)}function Y(){t(),J()}I(e);let X=F.isPending,Z=L(X,B);if(!e)return null;let ue={picker:l(`integrations.newIntegration`),config:l(`integrations.configureIntegration`),discovery:l(`integrations.importDevices`),broker:l(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},Q=X?m:null,$=F.error,de=X&&!Z;return n(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[s(`div`,{className:`absolute inset-0 bg-black/60`,onClick:de?void 0:Y}),n(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[n(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:ue[f]}),s(`button`,{onClick:Y,disabled:de,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:s(te,{className:`h-4 w-4`})})]}),n(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[$&&!X&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:$ instanceof Error?$.message:String($)}),f===`picker`&&n(i,{children:[D&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:D}),s(z,{onSelect:le,onClose:Y,pendingAddonId:Q})]}),f===`config`&&m&&s(oe,{addonId:m,configSchema:ae??null,canTest:ie,onSave:W,onBack:()=>p(`picker`)}),f===`broker`&&x&&s(P,{kind:x,onResolved:e=>{G(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&s(R,{providerId:_,onImport:K,onSkip:q})]}),X&&n(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[s(h,{className:`h-6 w-6 animate-spin text-primary`}),s(`p`,{className:`text-xs font-medium text-foreground`,children:l(`integrations.creating`,{defaultValue:`Creating integration…`})}),!Z&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:l(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),Z&&n(i,{children:[s(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:l(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),s(`button`,{onClick:Y,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:l(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function H({integration:e,expanded:t,onToggleExpand:r}){return n(`div`,{className:`flex items-center gap-2.5`,children:[s(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e.addonId)},"aria-label":t?`Collapse`:`Expand`,"aria-expanded":t,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:s(t?l:u,{className:`h-3.5 w-3.5`})}),s(M,{type:e.addonId,size:`sm`}),n(`div`,{className:`flex min-w-0 flex-col`,children:[s(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:e.name}),s(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:e.addonId})]})]})}function ce(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:`Integration`,headerClassName:`w-[55%]`,cell:e=>s(H,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:`Devices`,headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>`${e.deviceCount} device${e.deviceCount===1?``:`s`}`},{key:`status`,header:`Status`,headerClassName:`w-[15%]`,cell:e=>s(m,{status:e.status})}]}t();function le(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var U=`expand`;function W(){let{t}=A(),a=j(),c=d(),[l]=ie(),[u,f]=o(!1),m=e(()=>f(!0),[]),h=e(()=>f(!1),[]),[ee,g]=o(!1),_=e(()=>g(!0),[]),te=e(()=>g(!1),[]);C([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),C([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:w,isLoading:re,refetch:D}=y(void 0),{data:k,isLoading:M,refetch:oe}=O({projection:`slim`}),P=r(()=>k??[],[k]),I=r(()=>w??[],[w]),L=r(()=>{let e=new Map;for(let t of P)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[P]),R=r(()=>T(w),[w]),z=r(()=>{let e=new Map;for(let t of ne(P)){let n=R(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[P,R]),se=r(()=>I.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:le(e),deviceCount:z.get(e.id)??0})),[I,z]),B=l.get(U),H=e(e=>{let t=new URLSearchParams(window.location.search);t.get(U)===e?t.delete(U):t.set(U,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),W=e(e=>a(`/integrations/${e.id}`),[a]),G=e(e=>L.get(e)??null,[L]),K=e(e=>a(`/devices/${String(e)}`),[a]),q=e(e=>s(v,{context:`integration-detail`,devices:P,trpc:c.trpcClient,integrationOf:R,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:ae,resolveParent:G,onNavigate:K}),[P,c.trpcClient,R,G,K]),J=e(e=>B===e.addonId,[B]),Y=r(()=>ce({isExpanded:J,onToggleExpand:H}),[J,H]),X=e(e=>`${e.name} ${e.addonId}`,[]),Z=e(e=>e.addonId,[]),ue=e(()=>{D(),oe()},[D,oe]),Q=re||M,$=I.length>0;return n(N,{icon:x,title:t(`nav.integrations`,`Integrations`),actions:n(i,{children:[s(`button`,{onClick:ue,disabled:Q,className:`flex items-center gap-1 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,title:`Refresh`,children:s(b,{className:p(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:_,className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the local network for devices`,children:[s(S,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:m,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm`,children:[s(E,{className:`h-3.5 w-3.5`}),`New Integration`]})]}),children:[Q&&s(`div`,{className:`space-y-2`,children:[1,2,3].map(e=>s(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Q&&!$&&n(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[s(`p`,{className:`text-sm`,children:`No integrations configured.`}),s(`p`,{className:`text-xs mt-1`,children:`Click "New Integration" to connect cameras and devices.`})]}),!Q&&$&&s(v,{mode:`generic`,items:se,getKey:Z,getSearchText:X,columns:Y,onRowClick:W,isExpanded:J,renderExpanded:q,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),s(V,{open:u,onClose:h}),s(F,{open:ee,onClose:te})]})}export{W as IntegrationsPage};
|