@camstack/addon-admin-ui 1.2.356 → 1.2.358
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/assets/icon.svg +5 -0
- package/dist/assets/Addons-BpNMAC8g.js +4 -0
- package/dist/assets/{AdminTabs-BOhyA0v_.js → AdminTabs-CjafoxvK.js} +1 -1
- package/dist/assets/{AiProfiles-gc9Na6rv.js → AiProfiles-BeZSyNFd.js} +1 -1
- package/dist/assets/{BrokerForm-Bxjn8Xkb.js → BrokerForm-vK7o_-sd.js} +1 -1
- package/dist/assets/Build-CHPyiOzb.js +40 -0
- package/dist/assets/{Calendars-9eEuusHn.js → Calendars-py7REb8I.js} +1 -1
- package/dist/assets/{Capabilities-BuQgXiX1.js → Capabilities-CTyuV2mU.js} +1 -1
- package/dist/assets/Cluster-Dvmv3-5C.js +11 -0
- package/dist/assets/ClusterStepModel-BCXM90oM.js +1 -0
- package/dist/assets/{CompositionEditor-DsZomdtR.js → CompositionEditor-Bktdwhnn.js} +1 -1
- package/dist/assets/{CompositionEditorPage-CEYhfRyr.js → CompositionEditorPage-DXiq4mMC.js} +1 -1
- package/dist/assets/{Data-CxzcaPPX.js → Data-DtUlsreq.js} +1 -1
- package/dist/assets/{DetectionIntelligence-esy4sm8-.js → DetectionIntelligence-BHcjDiGb.js} +1 -1
- package/dist/assets/{DeviceDetail-BUFpgkeN.js → DeviceDetail-TJQ3r5Wf.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-C_OPAByq.js → DeviceDoActionFields-4wfCnUDo.js} +1 -1
- package/dist/assets/{Devices-D5wKCK9_.js → Devices-Zuh3Gb1y.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-xTUcKS8t.js → EmbedPlayerPage-Cfayr0_2.js} +1 -1
- package/dist/assets/{Events-BD2v1o2Z.js → Events-C8rtJF0X.js} +1 -1
- package/dist/assets/Identity-BHqbF-VQ.js +1 -0
- package/dist/assets/IntegrationDetail-DDZBkRYs.js +1 -0
- package/dist/assets/IntegrationHub-C_kwGzUm.js +1 -0
- package/dist/assets/Integrations-B3NL6Bhn.js +1 -0
- package/dist/assets/{Integrations-ErVYCOG1.js → Integrations-D3H9rujI.js} +1 -1
- package/dist/assets/{Locations-BBu_JUg1.js → Locations-BIetkfhV.js} +1 -1
- package/dist/assets/{Logs-hVhOlpsU.js → Logs-BYKgLvH-.js} +1 -1
- package/dist/assets/{MotionZonesSettings-B8426WyB.js → MotionZonesSettings-40HbSg1J.js} +1 -1
- package/dist/assets/{MyAccess-D0PqfqUg.js → MyAccess-B8HF1nGo.js} +1 -1
- package/dist/assets/Network-m6TRq9hZ.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-Bin020YC.js → NodeAddonsSettingsPanel-DhbzB3yG.js} +1 -1
- package/dist/assets/{Notifications-DBedpZv-.js → Notifications-DWpao1R2.js} +1 -1
- package/dist/assets/{Plates-D1_YX1bj.js → Plates-BW_rdxX6.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-C-lyYBaQ.js → PrivacyMaskSettings-9mlw-Sg2.js} +1 -1
- package/dist/assets/{Recordings-9M71-km4.js → Recordings-DJmbAZFE.js} +1 -1
- package/dist/assets/{ScanNetworkModal-DjrnLqkB.js → ScanNetworkModal-mYvbo8Uo.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CnTzBKHk.js → SceneMonitorEditor-DNVt27Re.js} +1 -1
- package/dist/assets/{Scenes-9o38vvfG.js → Scenes-CyjlxaOP.js} +1 -1
- package/dist/assets/{Secrets-Di_XuHEM.js → Secrets-DgQr5Kxc.js} +1 -1
- package/dist/assets/{Settings-CdsQXImT.js → Settings-cSyoiNRe.js} +1 -1
- package/dist/assets/{Showroom-CueI9Hof.js → Showroom-CVxQH10K.js} +1 -1
- package/dist/assets/{Terminal-CgkhEdVL.js → Terminal-5aXU64zN.js} +1 -1
- package/dist/assets/{Viewer-CXSln4qp.js → Viewer-CSSu8htq.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D23uSeCV.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DxPQ0X7S.js} +1 -1
- package/dist/assets/{archive-HjFKqcYJ.js → archive-DeR3e4g-.js} +1 -1
- package/dist/assets/{authed-media-DTi-1YAt.js → authed-media-DKCCsaRv.js} +1 -1
- package/dist/assets/{boxes-Bhz-2O4q.js → boxes-DxeTkSiW.js} +1 -1
- package/dist/assets/circle-slash-CttzF2br.js +1 -0
- package/dist/assets/client-BqN2lVYf.js +357 -0
- package/dist/assets/crop-BEmkkd3b.js +1 -0
- package/dist/assets/{debounced-invalidate-BmvWt3Mf.js → debounced-invalidate-7E55pOhB.js} +1 -1
- package/dist/assets/{device-integration-icon-vpQeGGPt.js → device-integration-icon-CPFH1cD5.js} +1 -1
- package/dist/assets/device-picker-model-DDC4ATOt.js +1 -0
- package/dist/assets/{dist-BVQ0qNkk.js → dist-9DPeVlno.js} +1 -1
- package/dist/assets/dist-CxwXQGCF.js +357 -0
- package/dist/assets/{face-bbox-DIMw9bdN.js → face-bbox-BLwRunnv.js} +1 -1
- package/dist/assets/{hard-drive-download-DGUpD-NK.js → hard-drive-download-BT7-6QED.js} +1 -1
- package/dist/assets/{hostInit-jbr3yepU.js → hostInit-DAWBqgef.js} +1 -1
- package/dist/assets/index-CpGfiJoj.js +4 -0
- package/dist/assets/{layers-TAdyTRRS.js → layers-D1ITEDh9.js} +1 -1
- package/dist/assets/{location-owned-usage-D5P9h6fD.js → location-owned-usage-CFYIPCzN.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-c002b961.js → mf-entry-bootstrap-0-127f685c.js} +2 -2
- package/dist/assets/mount-DDC4ATOt.js +1 -0
- package/dist/assets/{notification-schedule-field-DdO5UXE-.js → notification-schedule-field-CrLB-wdt.js} +1 -1
- package/dist/assets/{player-overlays-PPtffSZH.js → player-overlays-D4lg_avJ.js} +1 -1
- package/dist/assets/remoteEntry-Cpe5-iTU.js +1 -0
- package/dist/assets/{send-qYTKAtys.js → send-CYTiWXyC.js} +1 -1
- package/dist/assets/{settings-2-BfvfZMIZ.js → settings-2-DVqttbaa.js} +1 -1
- package/dist/assets/{src-EnVigh-D.js → src-DzkLcOyh.js} +17 -17
- package/dist/assets/{unlink-CvsfIFka.js → unlink-ZWAv-UAl.js} +1 -1
- package/dist/assets/{use-scenes-feed-DupdXK3r.js → use-scenes-feed-BUMM_vS8.js} +1 -1
- package/dist/assets/{use-stationary-objects-Blrh3fb3.js → use-stationary-objects-F6FJkq-t.js} +1 -1
- package/dist/assets/useEventInvalidation-DDC4ATOt.js +1 -0
- package/dist/assets/{useNodeUrlSelection-DemYJ0D7.js → useNodeUrlSelection-CWDgf9EZ.js} +1 -1
- package/dist/assets/user-round-D1OVtUFE.js +1 -0
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CFcHLszk.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D0bzMnfx.js} +2 -2
- package/dist/index.html +7 -7
- package/dist/server/addon.js +26 -2
- package/package.json +4 -2
- package/dist/assets/Addons-vaVt3N8c.js +0 -4
- package/dist/assets/Build-DNhwnx2k.js +0 -40
- package/dist/assets/Cluster-BGpeqgpD.js +0 -11
- package/dist/assets/ClusterStepModel-Cg0YqJM-.js +0 -1
- package/dist/assets/Identity-hydVfEcG.js +0 -1
- package/dist/assets/IntegrationDetail-IjNeTPn2.js +0 -1
- package/dist/assets/IntegrationHub-Czg3bSVM.js +0 -1
- package/dist/assets/Integrations-xrJzBxAs.js +0 -1
- package/dist/assets/Network-1FUHkoPH.js +0 -1
- package/dist/assets/circle-slash-RDy1aZkR.js +0 -1
- package/dist/assets/client-DuQQ55XQ.js +0 -357
- package/dist/assets/crop-BWtvQsYY.js +0 -1
- package/dist/assets/device-picker-model-C1VaG3XC.js +0 -1
- package/dist/assets/dist-B46vwY9Q.js +0 -357
- package/dist/assets/index-I9Gc2ACc.js +0 -4
- package/dist/assets/mount-C1VaG3XC.js +0 -1
- package/dist/assets/remoteEntry-CdbrIBDO.js +0 -1
- package/dist/assets/useEventInvalidation-C1VaG3XC.js +0 -1
- package/dist/assets/user-round-BCwcukON.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,B as m,D as h,E as g,M as _,O as v,R as y,T as b,at as x,gt as S,ht as C,k as w,st as T,ut as E,vt as D}from"./player-overlays-PPtffSZH.js";import{$t as O,B as k,Bs as A,C as j,Cc as ee,Cn as M,Ct as N,Cu as P,Dn as F,E as te,Ec as I,En as L,Fd as R,Fn as z,Hs as ne,I as re,In as B,Is as V,Jd as ie,Jt as ae,Ju as oe,Ls as se,Mt as H,Mu as ce,Nd as le,Nn as ue,Nt as de,O as fe,Oc as pe,Ou as me,P as he,Pd as ge,Pn as _e,Pt as ve,Qs as ye,Qt as be,Rd as xe,Rs as Se,S as Ce,Sc as we,Sn as Te,T as Ee,Tc as De,Tn as Oe,Us as ke,V as Ae,Vs as je,Wf as Me,Ws as Ne,Zd as Pe,Zs as Fe,_t as Ie,_u as Le,ac as Re,an as ze,bn as Be,bu as Ve,cc as He,cn as Ue,dc as We,dn as U,dr as Ge,ec as Ke,en as qe,fc as Je,fn as Ye,gd as Xe,gu as Ze,hd as Qe,hu as W,ic as $e,id as et,in as tt,lc as nt,ln as rt,mc as it,mr as at,nc as ot,nn as st,oc as ct,pc as lt,qn as ut,qs as dt,r as ft,rn as pt,sa as mt,sd as ht,sf as G,sn as gt,tc as _t,tn as vt,tr as K,uc as yt,ud as bt,ur as xt,ut as St,vf as Ct,vn as wt,vu as Tt,w as Et,wc as Dt,wn as Ot,wu as kt,xc as At,xf as jt,xn as Mt,yu as Nt,zs as Pt,zu as Ft}from"./src-EnVigh-D.js";import{t as It}from"./crop-BWtvQsYY.js";import{t as Lt}from"./layers-TAdyTRRS.js";import{An as Rt,Dn as zt,En as Bt,Lr as Vt,Mn as Ht,On as Ut,Rr as Wt,Tn as Gt,c as Kt,jn as qt,kn as Jt,l as Yt,m as Xt,pi as Zt,si as Qt,wn as $t}from"./client-DuQQ55XQ.js";import{n as en}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DX7sYWrs.js";import{$ as tn,G as nn,J as rn,z as an}from"./index-I9Gc2ACc.js";import"./useEventInvalidation-C1VaG3XC.js";import{t as on}from"./NodeAddonsSettingsPanel-Bin020YC.js";var sn=D(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),cn=D(`crown`,[[`path`,{d:`M11.562 3.266a.5.5 0 0 1 .876 0L15.39 8.87a1 1 0 0 0 1.516.294L21.183 5.5a.5.5 0 0 1 .798.519l-2.834 10.246a1 1 0 0 1-.956.734H5.81a1 1 0 0 1-.957-.734L2.02 6.02a.5.5 0 0 1 .798-.519l4.276 3.664a1 1 0 0 0 1.516-.294z`,key:`1vdc57`}],[`path`,{d:`M5 21h14`,key:`11awu3`}]]),ln=D(`pin-off`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]),un=D(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),dn=D(`scale`,[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`m19 8 3 8a5 5 0 0 1-6 0zV7`,key:`zcdpyk`}],[`path`,{d:`M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1`,key:`1yorad`}],[`path`,{d:`m5 8 3 8a5 5 0 0 1-6 0zV7`,key:`eua70x`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}]]),fn=D(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]),pn=`step`,mn=[pn,`acc`];function hn(e,t){return`${e}/${t}`}function gn(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 _n(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 vn(e){return e}function yn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function bn(e,t){return typeof e==`boolean`?e:vn(t)}function xn(e,t){return{pipeline:bn(yn(e,`detect`),t),audio:bn(yn(e,`audio`),t),ingest:bn(yn(e,`ingest`),t)}}function Sn(e,t,n){let r=e?.find(e=>e.nodeId===t);return xn(r?.settings,n)}function Cn({selectedNodeId:e,onSelect:t,refreshToken:n}){let{nodes:r}=Ze(),{data:a}=Ke(void 0),{data:s}=$e(void 0),c=new Map;for(let e of a??[])c.set(e.agentNodeId,(c.get(e.agentNodeId)??0)+1);let l=r??[],u=l.filter(e=>e.isOnline).length,f=l.filter(e=>!e.isOnline).length;return i(`div`,{className:`flex flex-col h-full`,children:[i(`button`,{type:`button`,onClick:()=>t(Eo),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[d(tn,{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?ht:G,u=Sn(s,n.id,n.isHub),f=n.isOnline?null:St(_n(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(ce,{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(K,{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(K,{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 wn({nodeId:e,refreshToken:t}){let{nodes:n}=Ze(),r=n?.find(t=>t.id===e),a=Le(`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 Tn=[`assignments`,`tree`,`engines`,`logs`];r();function En({refreshToken:e,nodeId:t}){let[n,r]=u(new Map),{nodes:o}=W();Nt(`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}=Ne(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 Dn={active:!1,pinned:!1,nodeId:null,reason:``};function On(e,t){return e.deviceName.localeCompare(t.deviceName)||e.deviceId-t.deviceId}function kn(e,t,n){let r=new Map(t.map(e=>[e.deviceId,e])),i=new Map(n.map(e=>[e.deviceId,e]));return e.map(e=>{let t=r.get(e.id),n=i.get(e.id);return{deviceId:e.id,deviceName:e.name,disabled:e.disabled===!0,pipeline:t?{active:!0,pinned:t.pinned,nodeId:t.agentNodeId,reason:t.reason??``}:Dn,audio:n?{active:!0,pinned:n.pinned,nodeId:n.nodeId,reason:``}:Dn}}).toSorted(On)}function An(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(On)}function jn(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 Mn(e){let t=new Map(e.map(e=>[e.id,e.name]));return e=>t.get(e)??`Camera ${e}`}function Nn(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 Pn({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=N(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(he,{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 Fn=1e4,In=5e3;function Ln(e){let[t,n]=u(new Map);return Nt(`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()-Fn,n=[...e].filter(([,e])=>e.timestamp>=t);return n.length===e.size?e:new Map(n)})},In);return()=>clearInterval(e)},[t.size]),t}var Rn=3e5;function zn({state:e,onlineNodes:t,nameOf:n,pending:r,onChange:i}){return d(z,{"aria-label":`Node pin`,title:`Auto lets each session pick its node; a pin keeps the camera on one node.`,value:e.pinned&&e.nodeId!==null?e.nodeId:`auto`,disabled:r,options:[...Nn(e,t,n)],onChange:e=>i(e.target.value)})}function Bn({deviceId:e,nodeId:t}){let n=c(),{data:r}=_t({deviceId:e},{refetchOnMount:`always`}),{data:i}=ye({nodeId:t},{staleTime:Rn}),a=we({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?`${U(f)} (${l})`:l} (not enabled)`}]:[],...s.map(e=>({value:e.key,label:`${U(e)} · ${e.format}`}))];return d(z,{"aria-label":`Inference device pin`,title:`Pin detection to one accelerator of the node, or let each session pick.`,value:l,disabled:a.isPending,options:p,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value})})}r();function Vn(e){let t=n(null);return e.nodeId!==null&&(t.current=e),t.current}function Hn({deviceId:e,state:t,...n}){let r=Vn(t);return i(`div`,{className:`grid w-80 grid-cols-2 gap-1.5`,children:[d(zn,{state:t,...n}),r?.nodeId==null?d(z,{"aria-label":`Inference device pin (no node yet)`,title:`An accelerator is pinned on the camera's node; this camera has not run on one yet.`,disabled:!0,defaultValue:`auto`,options:[{value:`auto`,label:`Any accelerator`}]}):d(Bn,{deviceId:e,nodeId:r.nodeId})]})}function Un({state:e,nameOf:t}){let n=Vn(e);if(n?.nodeId==null)return d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`— no session yet`});let r=e.active&&e.nodeId!==null,a=n.pinned?`pinned`:`auto · ${n.reason||`capacity`}`;return i(`div`,{className:`flex w-40 min-w-0 flex-col leading-tight`,title:n.pinned?void 0:`An unpinned camera is placed again at every session start, so this can change between sessions.`,children:[i(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs`,children:[d(`span`,{"aria-hidden":!0,className:`h-1.5 w-1.5 shrink-0 rounded-full ${r?`bg-success`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate font-medium ${r?`text-foreground`:`text-foreground-muted`}`,children:t(n.nodeId)})]}),d(`span`,{className:`truncate pl-3 text-[10px] ${n.pinned?`text-warning`:`text-foreground-subtle`}`,children:r?a:`${a} · idle, last session`})]})}function Wn({deviceId:e,deviceName:t}){let[n,r]=u(!1);return i(o,{children:[d(qe,{icon:Xe,variant:`ghost`,size:`sm`,"aria-label":`Stream brokers of ${t}`,title:`Stream brokers & clients`,onClick:()=>r(!0)}),d(Mt,{open:n,onOpenChange:r,children:i(M,{width:`lg`,scroll:`body`,children:[d(L,{children:i(F,{children:[t,` — stream brokers & clients`]})}),d(Te,{children:n&&d(wt,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:e,instanceId:`pipeline-row/${e}`,config:{variant:`compact`,title:`Stream brokers & clients`}})})]})})]})}r();var Gn=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`];function Kn(e){for(let t of[`getPipelineAssignments`,`getAudioAssignments`,`getCameraStatuses`])e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,t]]})}function qn(){let e=c();ft([`pipelineOrchestrator`,`getPipelineAssignments`],Gn),ft([`pipelineOrchestrator`,`getAudioAssignments`],Gn);let{data:t}=mt({isCamera:!0,projection:`slim`}),{data:n}=Ke(void 0),{data:r}=ke(void 0),{nodes:o}=W(),s=Ln(),l=a(()=>jn(o),[o]),u=a(()=>o.filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),f=a(()=>kn((t??[]).map(e=>({id:e.id,name:e.name,disabled:e.disabled})),n??[],r??[]),[t,n,r]),p=()=>Kn(e),m=je({onSuccess:p}),h=I({onSuccess:p}),g=m.isPending||h.isPending;return d(de,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>i(`div`,{className:`flex w-44 min-w-0 items-center gap-1.5`,children:[d(`span`,{className:`min-w-0 truncate text-xs font-medium text-foreground`,title:e.deviceName,children:e.deviceName}),e.disabled&&d(K,{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(Hn,{deviceId:e.deviceId,state:e.pipeline,onlineNodes:u,nameOf:l,pending:g,onChange:t=>t===`auto`?h.mutate({deviceId:e.deviceId}):m.mutate({deviceId:e.deviceId,agentNodeId:t})})},{key:`resolved`,header:`Running on`,width:`w-40`,sortValue:e=>e.pipeline.nodeId===null?null:l(e.pipeline.nodeId),render:e=>d(Un,{state:e.pipeline,nameOf:l})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(Pn,{snap:s.get(e.deviceId)})},{key:`brokers`,header:``,align:`right`,width:`w-10`,notSortableReason:`An action`,render:e=>d(Wn,{deviceId:e.deviceId,deviceName:e.deviceName})}],rows:f,rowKey:e=>e.deviceId,minWidthPx:760,mobileMode:`scroll`,maxBodyHeight:ve,emptyMessage:t===void 0?`Loading cameras…`:`No cameras`})}r();function Jn({label:e,state:t,nameOf:n}){return t.active?i(K,{variant:`info`,className:`gap-1`,title:t.pinned?`Pinned here`:void 0,children:[t.pinned&&d(un,{className:`h-2.5 w-2.5`,"aria-label":`pinned`}),e]}):t.nodeId===null?null:i(`span`,{className:`text-[10px] text-foreground-subtle`,children:[e,` on `,n(t.nodeId)]})}function Yn({nodeId:e}){let t=c();ft([`pipelineOrchestrator`,`getCameraStatuses`],Gn);let{data:n}=dt({}),{data:r}=mt({isCamera:!0,projection:`slim`}),{nodes:o}=W(),s=Ln(),l=a(()=>jn(o),[o]),u=a(()=>An(e,n??[],Mn((r??[]).map(e=>({id:e.id,name:e.name})))),[e,n,r]),f=o.filter(t=>t.isOnline&&t.id!==e),p=()=>Kn(t),m=je({onSuccess:p}),h=I({onSuccess:p}),g=A({onSuccess:p}),_=De({onSuccess:p}),v=e=>[...e.detection.active?f.map(t=>({id:`detect-${t.id}`,label:`Move detection to ${t.name}`,onClick:()=>m.mutate({deviceId:e.deviceId,agentNodeId:t.id})})):[],...e.audio.active?f.map(t=>({id:`audio-${t.id}`,label:`Move audio to ${t.name}`,onClick:()=>g.mutate({deviceId:e.deviceId,nodeId:t.id})})):[],{id:`unpin-detect`,label:`Unpin detection`,hidden:!(e.detection.active&&e.detection.pinned),separatorBefore:!0,onClick:()=>h.mutate({deviceId:e.deviceId})},{id:`unpin-audio`,label:`Unpin audio`,hidden:!(e.audio.active&&e.audio.pinned),onClick:()=>_.mutate({deviceId:e.deviceId})}];return d(de,{columns:[{key:`camera`,header:`Camera`,width:`w-44`,sortValue:e=>e.deviceName,render:e=>d(`span`,{className:`block w-44 truncate text-xs font-medium text-foreground`,title:e.deviceName,children:e.deviceName})},{key:`roles`,header:`Roles here`,notSortableReason:`A set of roles has no single order.`,render:e=>i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(Jn,{label:`Detection`,state:e.detection,nameOf:l}),d(Jn,{label:`Decode`,state:e.decoder,nameOf:l}),d(Jn,{label:`Audio`,state:e.audio,nameOf:l})]})},{key:`status`,header:`Status`,width:`w-40`,sortValue:e=>s.get(e.deviceId)?.metrics.actualFps??null,render:e=>d(Pn,{snap:s.get(e.deviceId)})},{key:`actions`,header:``,align:`right`,width:`w-10`,notSortableReason:`Actions`,render:e=>d(re,{items:v(e),title:`Move ${e.deviceName}`})}],rows:u,rowKey:e=>e.deviceId,minWidthPx:560,mobileMode:`scroll`,maxBodyHeight:ve,emptyMessage:n===void 0?`Loading cameras…`:`No camera runs on this node right now`})}function Xn({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(En,{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(Yn,{nodeId:e})]})]})}r();function Zn(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function Qn({nodeId:e,refreshToken:t}){let n=c(),r=ut(),o=se({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:s}=Se({nodeId:e}),l=Le(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??s??null,u=l===null;ft([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:f}=pe({nodeId:e}),{values:p}=Tt(`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?Lt:G,{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(P,{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:Zn(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(B,{variant:`ghost`,size:`sm`,disabled:o.isPending,onClick:()=>h(e.engine),className:`text-danger hover:bg-danger/10 hover:text-danger`,children:[d(T,{className:`h-3.5 w-3.5`}),`Kill`]})})]},e.engineKey)}),!u&&(l??[]).length===0&&d(`tr`,{children:d(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),i(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[d(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,d(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,d(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),o.isError&&d(ue,{message:`Kill failed: ${o.error instanceof Error?o.error.message:`unknown error`}`})]})}var $n=`pipeline-runner`,er=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(Ie,{agentId:e,addonId:$n,limit:er,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}r();function nr({nodeId:e,title:t}){let{data:n}=an(),{data:r}=Ke(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=Ln(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=N(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(he,{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 rr(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 ir(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 ar(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 or=`pipeline-orchestrator`;function sr({addonId:e,highlightLabel:t}){let n=Ut(e),{data:r}=Ge({addonId:or});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:m,children:`Cluster-wide settings`}),d(nn,{to:Mo(e),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Edit in Cluster → Settings ›`})]}),n.map(e=>i(`div`,{className:`${w} rounded px-2 ${t===e.label?`bg-primary/5 ring-1 ring-primary/40`:``}`,children:[d(`span`,{className:p,children:e.label}),d(`span`,{className:_,children:d(`span`,{className:`font-mono text-xs text-foreground`,children:String(a[e.key]??e.default)})})]},e.key)),d(`p`,{className:y,children:`One value for every node and camera — this step writes into a shared index.`})]})}function cr({rows:e}){return i(`div`,{className:`space-y-1.5`,"data-testid":`effective-models`,children:[d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map(e=>i(`li`,{className:`${b} flex flex-wrap items-baseline gap-x-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-foreground-muted`,children:e.label}),d(`span`,{className:`font-mono text-foreground`,children:e.modelId??`—`}),d(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.sourceLabel})]},e.id))}),d(`p`,{className:y,children:`To change a model, open that accelerator's cell in the table.`})]})}r();function lr(e,n){let[r,i]=rn(),o=r.get(pn),s=r.get(`acc`),c=a(()=>gn(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(pn,e.stepId),e.acceleratorId===void 0?t.delete(`acc`):t.set(`acc`,e.acceleratorId)}),[l]),close:t(()=>l(e=>{e.delete(pn),e.delete(`acc`)}),[l])}}function ur(e,t){for(let n of e?.slots??[])for(let e of n.addons)if(e.id===t)return e;return null}function dr(e){return e.split(`.`)[0]??e}function fr(e,t,n){return{id:hn(e,n.key),nodeId:e,deviceKey:n.key,device:n,label:`${dr(t)} · ${U(n)}`,shortLabel:`${dr(t)} · ${Ye(n)}`,nodeLabel:dr(t),disabled:!n.enabled}}function pr(e,t,n,r=!1){return n.filter(e=>r||e.enabled).map(n=>fr(e,t,n))}function mr(e,t,n=!1){return e.flatMap(e=>{let r=t[e.id]??[];if(n)return r.map(t=>fr(e.id,e.name,t));let i=r.filter(e=>e.enabled&&e.available);if(i.length>0)return i.map(t=>fr(e.id,e.name,t));let a=r.find(e=>e.available)??r[0];return a===void 0?[]:[fr(e.id,e.name,a)]})}function hr(e,t,n){return{modelId:gt({catalog:e,device:t.device,base:n.nodePin,override:n.cameraPin}),source:n.cameraPin===void 0?n.nodePin===void 0?`default`:`node`:`camera`}}function gr(e,t,n){let r=ur(e,`object-detection`);if(r===null)return;let i=gt({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 _r(e,t,n){return!Vt(e)||n===void 0?!1:Wt(e,t,n.supplies).effective}function vr(e,t){return e!==null&&Ue(e.models,t.device.format)}function yr(e){return vr(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 br(e){return Object.values(e).reduce((e,t)=>e+t.filter(e=>!e.enabled).length,0)}function xr(e){if(e===null)return[];let t=(e.configSchema??[]).flatMap(e=>`label`in e&&typeof e.label==`string`?[e.label]:[]),n=Ut(e.id).map(e=>e.label);return[...new Set([...t,...n])]}function Sr(e){return e.flatMap(e=>[{node:e,depth:0},...Sr(e.children).map(e=>({node:e.node,depth:e.depth+1}))])}function Cr(e,t){return e.flatMap(e=>{let n=Cr(e.children,t);return t.has(e.addonId)||n.length>0?[{...e,children:n}]:[]})}r();function wr(e){return{agentNodeId:e.nodeId,nodeLabel:e.nodeLabel,engineLabel:e.device.format,deviceKey:e.deviceKey,deviceLabel:U(e.device),detail:e.device.defaultModelId,disabled:e.disabled}}function Tr({tree:e,searchRows:r,accelerators:o,cellState:s,stepBadge:c,disabledCount:l,showDisabled:f,onShowDisabledChange:p,dirty:m,onDiscard:h,summary:g,toolbar:_,label:v,renderDetail:b}){let x=ut(),S=ae(),{selection:C,open:w,close:T}=lr(a(()=>Sr(e).map(e=>e.node.addonId),[e]),a(()=>o.map(e=>e.id),[o])),[E,D]=u(``),[A,ee]=u(null),[M,N]=u(null),P=n(null),F=n(null),I=n(null),L=n(null),R=a(()=>j(r,E),[r,E]),z=a(()=>E.trim()===``?e:Cr(e,new Set(R.map(e=>e.addonId))),[e,R,E]),ne=e=>R.find(t=>t.addonId===e)?.matchedField??null,re=a(()=>o.map(wr),[o]),B=e=>o.find(t=>t.nodeId===e.agentNodeId&&t.deviceKey===e.deviceKey),V=o.find(e=>e.id===C.acceleratorId)??null,ie=C.stepId!==null,oe=t(async e=>{if(m){if(!await x({title:`Discard unsaved changes?`,message:`This step has changes that are not saved yet.`,confirmLabel:`Discard`,variant:`danger`}))return;h()}e()},[x,m,h]),se=()=>{requestAnimationFrame(()=>L.current?.focus())},H=(e,t,n=!1)=>{if(e===C.stepId&&(t?.id??null)===C.acceleratorId){n&&se();return}let r=()=>{ee(ne(e)),w({stepId:e,...t===void 0?{}:{acceleratorId:t.id}}),n&&se()};e===C.stepId?r():oe(r)},ce=()=>{let e=C.stepId;oe(()=>{if(T(),e!==null){let t=V===null?null:Ae({agentNodeId:V.nodeId,deviceKey:V.deviceKey});requestAnimationFrame(()=>P.current?.focusCell(e,t))}})},le=e=>{if(e.key===`Enter`){let t=R[0];if(t===void 0)return;e.preventDefault(),H(t.addonId,void 0,!0)}else e.key===`Escape`&&D(``)},ue=S?d(te,{onClick:ce}):d(qe,{icon:kt,variant:`ghost`,size:`sm`,"aria-label":`Close`,onClick:ce});return i(`div`,{ref:F,className:`space-y-2`,onKeyDown:e=>{let t=e.target instanceof HTMLElement&&e.target.dataset.r!==void 0;e.key===`/`&&t&&(e.preventDefault(),I.current?.focus()),e.key===`Escape`&&t&&ie&&(e.preventDefault(),ce())},children:[i(`div`,{className:`flex flex-wrap items-center gap-2 text-xs`,children:[d(`div`,{className:`min-w-0 basis-full sm:basis-auto`,children:g}),d(`input`,{ref:I,type:`search`,value:E,onChange:e=>D(e.target.value),onKeyDown:le,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(O,{checked:f,onChange:e=>p(e.target.checked)}),`Show disabled accelerators (`,l,`)`]}),_]}),C.staleStepId!==null&&i(`p`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-1.5 text-[11px] text-warning`,children:[`The link names a step this pipeline does not have (`,C.staleStepId,`).`]}),z.length===0?i(`p`,{className:`${y} rounded-md border border-dashed border-border px-3 py-4 text-center`,children:[`No step matches “`,E,`”.`]}):d(k,{ref:P,tree:z,agents:re,label:v,getCellState:(e,t)=>{let n=B(t);return n===void 0?{kind:`na`}:s(e,n)},onCellClick:(e,t,n)=>H(e,B(t),n),onStepClick:(e,t)=>H(e,void 0,t),...c===void 0?{}:{stepBadge:c},selectedCell:ie&&C.stepId!==null&&V!==null?{addonId:C.stepId,agentNodeId:V.nodeId,deviceKey:V.deviceKey}:null,fallbackNodeId:M,onFallbackNodeChange:N,reserveRightPx:ie&&!S?432:0}),d(fe,{open:ie,anchor:F,onClose:ce,label:`Step settings`,children:C.stepId!==null&&b({stepId:C.stepId,accelerator:V,matchedField:A,closeButton:ue,onEscape:ce,headingRef:e=>{L.current=e}})})]})}r();function Er(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 Dr(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 Or(e,t){let n=t.settings===void 0?void 0:Dr(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:rr(r,n,t.stepId)}function kr(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=>!Xt(n[e],t.settings?.[e])).length;return r+i+o}function Ar({nodeId:e,nodeName:t,toolbar:n}){let r=c(),s=ye({nodeId:e},{refetchOnMount:`always`}),l=V({nodeId:e},{refetchOnMount:`always`}),f=Rt(Ge({addonId:`pipeline-orchestrator`}).data??null),p=s.data?.devices??[],h=l.data??null,[g,_]=u(null),[v,b]=u(null),[x,S]=u(null),C=Je({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})}}),w=a(()=>h?Ce(h):[],[h]),T=a(()=>Sr(w),[w]),[E,D]=u(!1),O=a(()=>pr(e,t,p,E),[e,t,p,E]),k=a(()=>pr(e,t,p),[e,t,p]),A=k.length>=2,j=(e,t)=>(t===void 0?void 0:ir(p,t.deviceKey,e))??{},ee=(e,t,n)=>{let r=n??t.device.steps?.[e?.id??``]?.jumpDeviceKey;if(r!==void 0&&r!==``)return k.find(e=>e.deviceKey===r);if(!vr(e,t))return k.filter(n=>n.id!==t.id&&vr(e,n)).toSorted((e,t)=>e.deviceKey.localeCompare(t.deviceKey))[0]},M=(e,t)=>{let n=ur(h,e),r=Fo(e),i=gr(h,t),a=j(e,t),o=ee(n,t);return yr({addon:n,acc:t,gatedOn:n?.enabledByDefault??!0,model:n?hr(n,t,{nodePin:t.device.steps?.[e]?.modelId}):{modelId:void 0,source:`default`},..._r(e,a,i)&&i?{rootName:i.name}:{},...r?{clusterModelId:f[e]??r.defaultModelId}:{},...o?{jumpTo:Ye(o.device)}:{}})},N=T.map(({node:e})=>({addonId:e.addonId,name:e.addonName,fieldLabels:xr(ur(h,e.addonId))}));if(s.isLoading||l.isLoading)return d(`div`,{className:`animate-pulse p-4 text-xs text-foreground-subtle`,children:`Loading pipeline…`});if(h===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`Catalog unavailable.`});let P=i(`span`,{className:y,children:[`Accelerators:`,` `,d(`span`,{className:`text-foreground`,children:k.length>0?k.map(e=>Ye(e.device)).join(` · `):`none enabled`}),p.some(e=>!e.enabled)&&i(o,{children:[` `,`— off:`,` `,p.filter(e=>!e.enabled).map(Ye).join(`, `)]}),` `,`·`,` `,d(nn,{to:No(),className:`text-primary hover:underline`,children:`Cluster → Load balancing ›`})]});return d(Tr,{tree:w,searchRows:N,accelerators:O,cellState:M,disabledCount:p.filter(e=>!e.enabled).length,showDisabled:E,onShowDisabledChange:D,dirty:g!==null&&kr(p,g,j(g.stepId,O[0]))>0,onDiscard:()=>_(null),summary:P,...n===void 0?{}:{toolbar:n},label:`Detection steps`,renderDetail:({stepId:n,accelerator:r,matchedField:a,closeButton:s,onEscape:c,headingRef:l})=>{let u=ur(h,n);if(u===null)return d(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No step selected.`});let f=g?.stepId===n?g:null,w=r??k[0]??O[0],T=j(n,w),E=f?.settings??T,D=kr(p,f,T),M=e=>{S(null),_(t=>({...t?.stepId===n?t:{stepId:n,models:{},jumps:{}},...e}))},N=Fo(n),P=pt(u),F=w===void 0?void 0:gr(h,w),te=e=>{let t=f?.models[e.deviceKey];return t===void 0?e.device.steps?.[n]?.modelId:t??void 0},I=w===void 0?void 0:hr(u,w,{nodePin:te(w)}).modelId,L=O.length>1&&O.some(e=>!Xt(j(n,e),T)),R=e=>{let t=te(e),r=hr(u,e,{nodePin:t}),a=gr(h,e),s=_r(n,f?.settings??j(n,e),a),c=f?.jumps[e.deviceKey],l=ee(u,e,c),p=vr(u,e)?s&&a?d(vt,{rootModel:a,stepModelId:r.modelId}):void 0:i(o,{children:[`No `,e.device.format,` build of this step.`,` `,l?`It runs on ${l.shortLabel} instead.`:`It does not run here.`]}),m=A?i(`label`,{className:`block space-y-1`,children:[d(`span`,{className:`text-[11px] font-medium text-foreground`,children:`Run on`}),d(z,{"aria-label":`Run on`,value:c??e.device.steps?.[n]?.jumpDeviceKey??``,options:[{value:``,label:`Auto (this accelerator, or the next one that can run it)`},...k.filter(t=>t.id!==e.id).map(e=>({value:e.deviceKey,label:`${e.label} · ${e.device.format}`}))],onChange:t=>M({jumps:{...f?.jumps,[e.deviceKey]:t.target.value}})}),d(`span`,{className:y,children:`Routes this step (and its child steps) to another accelerator of this node.`})]}):void 0;return{label:e.label,format:e.device.format,modelId:r.modelId,source:r.source===`node`?`node`:`default`,sourceLabel:r.source===`node`?`node pin`:`hardware default`,models:rt(u.models??[],e.device.format),defaultModelId:u.defaultModelIdByFormat?.[e.device.format]??u.defaultModelId,expanded:v===e.id,onToggle:()=>b(t=>t===e.id?null:e.id),onChangeModel:t=>M({models:{...f?.models,[e.deviceKey]:t}}),...t===void 0?{}:{onReset:()=>M({models:{...f?.models,[e.deviceKey]:null}}),resetLabel:`Reset to hardware default`},...p===void 0?{}:{note:p},...m===void 0?{}:{extra:m},changed:f?.models[e.deviceKey]!==void 0||c!==void 0}},ne=()=>{f!==null&&C.mutate({agentNodeId:e,inferenceDevices:ar(Or(p,f))},{onSuccess:()=>{_(null),S({kind:`saved`})},onError:e=>S({kind:`error`,error:e.message})})};return d(Ee,{ref:l,title:r===null?`${u.name} · ${t}`:`${u.name} · ${r.label}`,subtitle:r===null?`${u.slot} · every accelerator of ${t}`:`${u.slot} · ${r.device.format} · base for every camera that lands here`,leading:s,onEscape:c,saveBar:{dirtyCount:D,saving:C.isPending,status:x?.kind??null,...x?.error===void 0?{}:{error:x.error},onSave:ne,onDiscard:()=>_(null)},children:i(`div`,{className:`space-y-3`,children:[i(`section`,{className:`space-y-2`,"aria-label":`Model`,children:[d(`h3`,{className:m,children:`Model`}),N!==null&&w!==void 0?d(Io,{step:N,engineFormat:w.device.format,runnableModelIds:rt(u.models??[],w.device.format).map(e=>e.id)}):O.length===0?i(`p`,{className:y,children:[`No accelerator is enabled on this node —`,` `,d(nn,{to:No(),className:`text-primary hover:underline`,children:`enable one in Cluster → Load balancing`}),`.`]}):r===null?d(cr,{rows:O.map(e=>{let t=hr(u,e,{nodePin:te(e)});return{id:e.id,label:e.label,modelId:t.modelId,sourceLabel:t.source===`node`?`node pin`:`hardware default`}})}):d(Et,{...R(r)},r.id)]}),(P.length>0||F!==void 0)&&N===null&&i(`section`,{"aria-label":`Settings`,className:`space-y-2 border-t border-border/60 pt-2`,children:[i(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`settings-scope`,children:[`Node-wide: these settings apply on every accelerator of `,t,`.`]}),L&&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(jr,{addon:u,fields:P,settings:E,modelId:st(u,I,E,F),root:F,highlight:a,onChange:e=>M({settings:e})})]}),d(sr,{addonId:n,highlightLabel:a})]})})}})}function jr({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 Er(s===null?null:ze(s)),d(tt,{addon:e,fields:t,layers:{node:n},target:`node`,labels:{node:`Node`},modelId:r,...i===void 0?{}:{rootModel:i},highlightKey:s,onChangeLayer:o})}r();function Mr({nodeId:e,refreshToken:t}){let n=ut(),[r,a]=u(null),{nodes:s}=W(),c=s.find(t=>t.id===e)?.name??e,l=He({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(nr,{nodeId:e}),d(Ar,{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(B,{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 Nr=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],Pr=`decoder-nodeav`,Fr=`ntab`,Ir={decoder:`engine`},Lr={engine:`Engine & decoder`},Rr=`Nothing here is set per node. Cluster-wide values are on Cluster → Settings.`;function zr({nodeId:e,refreshToken:t}){let[n,r]=rn(),{nodes:a}=W(),o=a.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.addonId??Pr,s=[...Nr,o],c=n.get(Fr),l={assignments:{id:`assignments`,label:`Assignments`,order:-10,content:d(Xn,{nodeId:e,refreshToken:t})},tree:{id:`tree`,label:`Pipeline`,order:39,content:d(Mr,{nodeId:e,refreshToken:t})},engines:{id:`engines`,label:`Warm instances`,order:180,content:d(Qn,{nodeId:e,refreshToken:t})},logs:{id:`logs`,label:`Logs`,order:300,content:d(tr,{nodeId:e})}},u=Tn.map(e=>l[e]);return i(`div`,{className:`flex flex-col h-full`,children:[d(wn,{nodeId:e,refreshToken:t}),d(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6`,children:d(on,{nodeId:e,addonIds:s,level:`global`,fieldScope:`perNode`,emptyMessage:Rr,tabAliases:Ir,tabLabelOverrides:Lr,extraTabs:u,activeTab:c===null?null:Ir[c]??c,onActiveTabChange:e=>r(t=>{let n=new URLSearchParams(t);n.set(Fr,e);for(let e of mn)n.delete(e);return n},{replace:!0})})})]})}function Br(){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(qn,{})]})}function Vr(e){return`${Math.round(e*100)}%`}function Hr(e){return`${e} session${e===1?``:`s`}`}var Ur={"intel-npu":`Intel NPU`,"intel-igpu":`Intel iGPU`,"x86-cpu":`CPU`,"arm-cpu":`CPU`,"apple-ane":`Apple Neural Engine`,coral:`Coral Edge TPU`},Wr={"intel-core-ultra":`Intel Core Ultra`,"intel-n-series":`Intel N-series`,"apple-m-base":`Apple M (base)`,"apple-m-pro":`Apple M Pro / Max / Ultra`,unknown:`Not measured`};function Gr(e){return e===null?`—`:Ur[e]??e}function Kr(e){return e===null?`—`:Wr[e]??e}function qr(e){switch(e.kind){case`capacity`:return`Capacity ${Hr(e.sessions)} ≥ min ${e.minSessions}.`;case`tie-faster`:return`As accurate as ${e.over} (within ${Vr(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 ${Hr(e.minSessions)} per device; the one with the most capacity (${Hr(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 Jr(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 Yr(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 Xr(e){let t=Yr(e);return t.modelChanges+t.thresholdClears+t.cameraOverrideClears+t.detectorStoreClears===0}function Zr(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 Qr(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 $r=[.3,.4,.5];function ei(e){return $r.some(t=>t===e)}var ti=[1,2,3,4,6,8];function ni({plan:e,node:t,nodeName:n}){return i(`section`,{className:h,"data-testid":`auto-tune-node-${t.nodeId}`,children:[i(`header`,{className:`${v} flex flex-wrap items-center gap-2`,children:[d(G,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${m} min-w-0 flex-1`,children:n(t.nodeId)}),i(`span`,{className:`text-[11px] text-foreground-subtle`,children:[Kr(t.hardwareClass),t.cpuModel===null?``:` · ${t.cpuModel}`]}),t.skipped?d(K,{variant:`warning`,children:`Not changed`}):t.acceleratorModelId!==null&&d(K,{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:qr(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=Zr(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:Gr(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:Qr(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:qr(e)},t))})]},n.deviceKey)})})]})})]})}function ri({plan:e,nameOf:t,nodeName:n}){return i(`div`,{className:`flex flex-col gap-3 text-xs`,"data-testid":`auto-tune-change-list`,children:[i(`div`,{children:[d(`div`,{className:m,children:`Node settings`}),e.nodeChanges.length===0?d(`div`,{className:`text-foreground-subtle`,children:`No change.`}):d(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.nodeChanges.flatMap(e=>[...e.modelPins.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: `,t.before??`default`,` → `,t.after??`step default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/pin`)),...e.thresholds.map(t=>i(`li`,{children:[i(`span`,{className:`font-mono`,children:[n(e.nodeId),` · `,e.deviceKey]}),` `,`— `,t.stepId,`: reset `,t.keys.join(`, `),` to the model default`]},`${e.nodeId}/${e.deviceKey}/${t.stepId}/thr`))])})]}),i(`div`,{children:[d(`div`,{className:m,children:`Camera overrides cleared`}),e.cameraClears.length===0&&e.detectorStoreClears.length===0?d(`div`,{className:`text-foreground-subtle`,children:`None.`}):i(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:[e.cameraClears.map((e,r)=>i(`li`,{children:[t(e.deviceId),` — `,n(e.nodeId),e.deviceKey===null?` (whole pipeline)`:` · ${e.deviceKey}`,` — `,e.stepId,e.modelIdBefore===null?``:`: model ${e.modelIdBefore} removed`,e.keys.length>0?`; ${e.keys.join(`, `)} reset`:``]},`c${r}`)),e.detectorStoreClears.map(e=>i(`li`,{children:[t(e.deviceId),` — detector thresholds: `,e.keys.join(`, `),` reset`]},`d${e.deviceId}`))]})]})]})}function ii({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 ai(){let e=c(),[t,n]=u(.4),[r,o]=u(2),[s,l]=u(!1),[f,p]=u(!1),[g,_]=u(null),{data:y}=an(),b=a(()=>new Map((y??[]).map(e=>[e.id,e.name])),[y]),x=e=>b.get(e)??`Camera ${e}`,{nodes:S}=W(),C=a(()=>jn(S),[S]),w=Re({headroom:t,minSessionsPerDevice:r},{enabled:s,refetchOnWindowFocus:!1}),T=Pt({onSuccess:t=>{_(t),p(!1),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),t.kind===`applied`&&w.refetch()}}),E=g?.kind===`stale`?g.plan:w.data,D=E===void 0?null:Yr(E);return i(`div`,{className:`flex flex-col gap-3`,"data-testid":`cluster-auto-tune`,children:[i(`section`,{className:h,children:[i(`header`,{className:`${v} flex flex-wrap items-center gap-2`,children:[d(oe,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),d(`h3`,{className:`${m} min-w-0 flex-1`,children:`Auto tune`})]}),i(`div`,{className:`flex flex-col gap-2 px-3 py-2 text-xs text-foreground-muted`,children:[d(`p`,{children:`Picks, for every accelerator, the most accurate YOLOv9 detector that still carries at least the chosen number of cameras at once, from the node's hardware and measured speeds. Nothing is measured or estimated about your cameras' activity. Applying it sets those models and clears every model and threshold override — node level and per camera — so each model runs its own default thresholds. Enabled steps, devices, pins, recording, notifications, zones and rules are not touched. There is no undo.`}),i(`div`,{className:`flex flex-wrap items-center gap-2`,children:[i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`Keep free`}),d(z,{"aria-label":`Share of each accelerator kept free`,value:String(t),options:$r.map(e=>({value:String(e),label:`${Math.round(e*100)}% of each accelerator`})),onChange:e=>{let t=Number(e.target.value);ei(t)&&n(t)}})]}),i(`label`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`whitespace-nowrap`,children:`At least`}),d(z,{"aria-label":`Minimum parallel sessions per device`,value:String(r),options: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(B,{size:`sm`,variant:`secondary`,onClick:()=>{_(null),l(!0),s&&w.refetch()},children:w.isFetching?`Computing…`:E===void 0?`Compute plan`:`Recompute`}),E!==void 0&&d(B,{size:`sm`,disabled:Xr(E),onClick:()=>p(!0),children:`Apply…`})]}),w.error!==null&&d(`div`,{className:`text-danger`,children:w.error.message}),g!==null&&d(ii,{result:g}),D!==null&&i(`div`,{className:`text-[11px] text-foreground-subtle`,children:[D.modelChanges,` model change(s), `,D.thresholdClears,` node threshold reset(s), `,D.cameraOverrideClears+D.detectorStoreClears,` camera override(s) on `,D.camerasTouched,` camera(s).`]})]})]}),E?.warnings.map((e,t)=>d(`div`,{className:`rounded-md border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:Jr(e,C)},t)),E?.nodes.map(e=>d(ni,{plan:E,node:e,nodeName:C},e.nodeId)),E!==void 0&&d(Mt,{open:f,onOpenChange:p,children:i(M,{width:`lg`,scroll:`body`,children:[i(L,{children:[d(F,{children:`Apply auto tune?`}),d(Ot,{children:`These are all the changes. Every override listed is removed and cannot be restored.`})]}),d(Te,{children:d(ri,{plan:E,nameOf:x,nodeName:C})}),i(Oe,{children:[d(B,{variant:`ghost`,onClick:()=>p(!1),children:`Cancel`}),d(B,{variant:`danger`,disabled:T.isPending,onClick:()=>T.mutate({planHash:E.planHash,headroom:t,minSessionsPerDevice:r}),children:T.isPending?`Applying…`:`Apply`})]})]})})]})}var oi={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 si(e,t){return t<=0?0:Math.round(e/t*1e3)/10}function ci(e){return e===void 0?!1:e.load.devices.reduce((e,t)=>e+t.attachedCameras,0)>=e.load.attachedCameras}function li(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:U(e),format:e.format,sessions:i,weight:a,weightSharePct:e.exclusion===null?si(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 ui(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=li(e.devicesByNode[r.id]??[],new Map((i?.load.devices??[]).map(e=>[e.deviceKey,e.attachedCameras])),ci(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?si(c,r.maxCameras):null,queueDepthTotal:i?.load.queueDepthTotal??null,avgInferenceTimeMs:i?.load.avgInferenceTimeMs??null,score:i?.score??null,weight:s,weightSharePct:o?si(s,n):null,decodeHwaccel:i?.decodeHwaccel??null,devices:a,eligibleDeviceCount:a.filter(e=>e.exclusion===null).length}})}var di=`pipeline-orchestrator`,fi=`recorder`,pi=`recordingNodeId`,mi=`pipeline-analytics`,hi=`postProcessingNodeId`,gi=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`,`postProcessingNode`],_i=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function vi(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function yi(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function bi(e,t,n){let r=vi(e,t);return typeof r==`string`&&r.length>0?r:n}function xi(e,t){let n=yi(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function Si(e,t){let n=yi(e,t);return typeof n==`string`&&n.length>0?n:null}function Ci(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:e===`postProcessingNode`?`Post-processing`:`Motion`}function wi(e){return e===`ingestNode`?`Connects to every camera and serves its stream to the others`:e===`recordingNode`?`Writes the recordings`:e===`audioNode`?`Runs audio analysis for every camera`:e===`postProcessingNode`?`Builds events and their media from detections, audio and motion`:`Runs software motion detection; cameras with onboard motion are unaffected`}function Ti(e,t){switch(t){case`detect`:return e.pipeline}}function Ei(e){return e instanceof Error?e.message:`Failed to save`}function Di(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}r();var Oi=2e4,ki=3e5;function Ai({stats:e,targetWeights:t}){let{nodes:n}=W(),r=x().trpcClient,o=ne(void 0,{placeholderData:l,staleTime:Oi,refetchInterval:Oi,refetchOnWindowFocus:!0}),c=$e(void 0,{staleTime:ki}),u=a(()=>n.map(e=>e.id),[n]),f=s({queries:u.map(e=>({queryKey:en(Ve.pipelineOrchestrator.getNodeInferenceDevices,{nodeId:e},`query`),queryFn:()=>r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:e}),staleTime:ki,refetchOnWindowFocus:!1,placeholderData:l}))}),p=a(()=>{let e={};return u.forEach((t,n)=>{let r=f[n]?.data;r&&(e[t]=r.devices)}),e},[u,f.map(e=>e.dataUpdatedAt).join(`|`)]),m=a(()=>{let e=new Map;for(let t of c.data??[])e.set(t.nodeId,t.settings);return e},[c.data]),h=a(()=>n.map(e=>{let n=m.get(e.id);return{id:e.id,name:e.name,isOnline:e.isOnline,detectEnabled:xn(n,e.isHub).pipeline,weight:t?.[e.id]??xi(n,`detectWeight`)??1,maxCameras:xi(n,`maxCameras`)}}),[n,m,t]),_=o.data??[],v=a(()=>ui({nodes:h,loads:_,devicesByNode:p}),[h,_,p]),y=v.reduce((e,t)=>e+(t.attachedCameras??0),0),b=v.reduce((e,t)=>e+(t.activeCameras??0),0),S=o.dataUpdatedAt>0?Date.now()-o.dataUpdatedAt:null,C=new Map((e?.nodes??[]).map(e=>[e.nodeId,e]));return d(H,{headingId:`load-balancing-node-load`,title:`Node load`,icon:Me,actions:i(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[b,` running · `,y,` attached ·`,` `,o.data===void 0?`reading…`:`${S===null?`—`:`${Math.round(S/1e3)}s`} old`]}),children:d(`div`,{className:g,children:v.length===0?d(`p`,{className:`text-[11px] italic text-foreground-subtle`,children:`No cluster nodes reported yet.`}):d(`div`,{className:`grid gap-2 @2xl/clustertab:grid-cols-2 @5xl/clustertab:grid-cols-3`,children:v.map(e=>d(ji,{row:e,placed:C.get(e.nodeId)},e.nodeId))})})})}function ji({row:e,placed:t}){let n=e.attachedCameras===null?`—`:`${e.activeCameras??0} / ${e.attachedCameras}${e.maxCameras===null?``:` of ${e.maxCameras}`}`;return i(`div`,{className:`rounded-lg border border-border bg-surface/60 p-2.5 min-w-0`,children:[i(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[d(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${e.isOnline?`bg-emerald-400`:`bg-foreground-subtle/40`}`}),d(`span`,{className:`truncate text-xs font-medium text-foreground`,title:e.nodeId,children:e.name}),!e.detectEnabled&&d(`span`,{className:`shrink-0 rounded bg-surface-hover px-1 text-[9px] uppercase tracking-wide text-foreground-subtle`,children:`no detect`}),!e.reported&&e.isOnline&&i(`span`,{className:`ml-auto inline-flex shrink-0 items-center gap-1 text-[9px] text-amber-400`,title:`Online, but it did not answer the last load read — its numbers below are unknown, not zero.`,children:[d(Ft,{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(me,{className:`h-2.5 w-2.5`}),` offline`]})]}),i(`dl`,{className:`mt-1.5 grid grid-cols-2 gap-x-2 gap-y-0.5 text-[10px]`,children:[d(J,{label:`Running / attached`,value:n,title:`Sessions in inference now / cameras attached to this runner (the balancer's committed load) / operator cap.`}),d(J,{label:`Target share`,value:e.weightSharePct===null?`out of play`:`${e.weightSharePct}%`,title:`The node share (automatic or manual) normalised over the nodes the balancer actually ranks (online AND detect-enabled).`}),d(J,{label:`Actual share (1 h)`,value:t?.observedShare===null||t===void 0?`—`:`${Math.round(t.observedShare*100)}%`,title:`Time-weighted share of the cluster's PARALLEL detection sessions this node carried over the last hour — the quantity a share holds. '—' = no session ran here in the window.`}),d(J,{label:`Peak · yields`,value:t===void 0?`—`:`${t.peakSessions} · ${t.yieldsAway}`,title:`Most sessions this node ran at once in the last hour, and how many share turns it handed to another node because it was full or drowning.`}),d(J,{label:`Score · queue`,value:e.score===null?`—`:`${e.score} · ${e.queueDepthTotal??0}`,title:`The capacity score balance() minimises (attached + queue depth), and the raw queue depth.`}),e.capacityPct!==null&&d(J,{label:`Cap fill`,value:`${e.capacityPct}%`,title:`attached / maxCameras.`}),e.avgInferenceTimeMs!==null&&d(J,{label:`Avg infer`,value:`${Math.round(e.avgInferenceTimeMs)} ms`,title:`Mean inference time across this node's attached cameras.`}),e.decodeHwaccel!==null&&d(J,{label:`Decode`,value:e.decodeHwaccel,title:`This node's probed decode hwaccel.`})]}),d(Mi,{row:e})]})}function Mi({row:e}){return e.devices.length===0?d(`p`,{className:`mt-2 text-[10px] italic text-foreground-subtle`,children:`Accelerators not read yet.`}):i(`div`,{className:`mt-2 border-t border-border pt-1.5`,children:[i(`div`,{className:`flex items-center gap-1 text-[9px] uppercase tracking-wider text-foreground-subtle`,children:[d(ie,{className:`h-2.5 w-2.5`}),`Accelerators`,e.eligibleDeviceCount===0&&d(`span`,{className:`ml-1 normal-case tracking-normal text-amber-400`,title:`No device is a camera-root candidate on this node — sessions run on the runner's default (CPU) pool.`,children:`none in play · runner default pool`})]}),d(`ul`,{className:`mt-1 space-y-0.5`,children:e.devices.map(e=>d(Ni,{device:e},e.key))})]})}function Ni({device:e}){let t=e.exclusion;return i(`li`,{className:`flex items-baseline gap-1.5 text-[10px] min-w-0`,children:[d(G,{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:oi[t],children:[`excluded — `,oi[t]]})]})}function J({label:e,value:t,title:n}){return i(`div`,{className:`min-w-0`,title:n,children:[d(`dt`,{className:`text-[9px] uppercase tracking-wide text-foreground-subtle`,children:e}),d(`dd`,{className:`truncate font-medium tabular-nums text-foreground`,children:t})]})}function Pi(e){return{nodes:Object.fromEntries(e.map(e=>[e.nodeId,Math.max(1,e.weight)])),devices:{}}}function Fi(e){let t={},n={};for(let r of e.nodes){if(r.share===null||r.share<=0)continue;t[r.nodeId]=r.share;let e=Object.fromEntries(r.devices.filter(e=>e.share>0).map(e=>[e.deviceKey,e.share]));Object.keys(e).length>0&&(n[r.nodeId]=e)}return{nodes:t,devices:n}}function Ii(e){return Object.fromEntries(e.nodes.map(e=>[e.nodeId,Object.fromEntries(e.devices.map(e=>[e.deviceKey,e.suggestedMaxSessions]))]))}function Li(e){return e.reason===`disabled`?`${e.deviceKey} is not enabled on any node — sessions ignore this pin`:`no node offers ${e.deviceKey} — sessions ignore this pin`}function Ri(e,t){if(t===void 0||t.source===`manual`||t.autoPending)return{nodes:e,readOnly:t!==void 0&&t.source!==`manual`};let n=new Map(t.nodes.map(e=>[e.nodeId,e.configuredPct]));return{nodes:e.map(e=>({...e,weight:Math.round(n.get(e.id)??e.weight)})),readOnly:!0}}function zi(e,t){let n=e.nodes.filter(e=>!e.eligible);if(n.length===0)return null;let r=e.nodes.filter(e=>e.eligible).map(e=>`${t(e.nodeId)} ${Math.round(e.effectivePct)}%`).join(`, `);return`${n.map(e=>t(e.nodeId)).join(`, `)} cannot take sessions — ${n.length===1?`its share goes`:`their shares go`} to the others: ${r}`}var Bi=[{value:`hardware`,label:`Hardware`,hint:`Each node’s share follows what its accelerators can carry at their Auto tune models, from the measured speed of its hardware. No load is measured or estimated.`},{value:`benchmark`,label:`Benchmark`,hint:`Each node’s share follows its own node-benchmark results. A node without results uses its hardware capacity instead, and says so.`},{value:`manual`,label:`Manual`,hint:`The sliders below, as you set them.`}];function Vi(e){return e===`no-benchmark-results`?`no benchmark results yet — sized from hardware`:e===`partial-benchmark-results`?`benchmark results miss some of its accelerators — sized from hardware`:null}function Hi(e,t){if(e.source!==`benchmark`)return null;let n=e.nodes.filter(e=>e.capacityFallback!==null);return n.length===0?null:n.map(e=>`${t(e.nodeId)}: ${Vi(e.capacityFallback)??``}`).join(` · `)}r();function Ui(e,t,n){return Math.min(Math.max(e,t),n)}function Wi(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function Gi(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:Ui(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function Ki(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function qi({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:a,footnote:s,readOnly:c=!1}){let[l,p]=u(()=>Wi(e)),[m,h]=u(new Set);f(()=>{p(Wi(e)),h(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let g=e.map(e=>e.id),_=e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},v=(e,t)=>{p(n=>Gi(n,e,t,m,g))},y=()=>{let t=Ki(l,g,m),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...m]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:a??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let b=e.length===1;return i(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=l[e.id]??0,a=m.has(e.id);return i(`div`,{className:`flex items-center gap-3`,children:[d(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),d(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:c||t||a||b,onChange:t=>v(e.id,Number(t.target.value)),onPointerUp:()=>y(),onKeyUp:()=>y(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),i(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),!c&&d(`button`,{type:`button`,onClick:()=>_(e.id),disabled:t||b,"aria-pressed":a,title:a?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${a?`text-amber-400`:`text-foreground-subtle`}`,children:d(a?le:ge,{className:`h-3.5 w-3.5`})})]},e.id)}),d(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:s??d(o,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}r();function Ji(e){let t=U(e),n=e.backend.toLowerCase(),r=e.device.toLowerCase();return e.key===`cpu`||r===`cpu`?{label:t,Icon:G,hue:`slate`}:r===`npu`?{label:t,Icon:P,hue:`sky`}:r===`gpu`||r===`igpu`?{label:t,Icon:sn,hue:`violet`}:n===`edgetpu`?{label:t,Icon:fn,hue:`emerald`}:{label:t,Icon:G,hue:`slate`}}var Yi={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function Xi({nodeId:e,nodeName:t,isOnline:n,suggestedMaxSessions:r,autoDeviceShares:s}){let l=c(),{data:p,isLoading:m}=ye({nodeId:e},{refetchInterval:15e3}),h=Je({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:ar(n)})},E=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),D=e=>{if(!e.available)return;let t=v[e.key]??E(e),n={...v,[e.key]:{...t,enabled:!t.enabled}};y(n),T(n)},O=(e,t)=>{let n=v[e.key]??E(e),r={...v,[e.key]:{...n,maxSessions:t}};y(r),T(r)},k=a(()=>g.filter(e=>(v[e.key]?.enabled??e.enabled)&&e.available),[g,v]),A=a(()=>k.map(e=>({id:e.key,name:Ji(e).label,weight:s===void 0?v[e.key]?.weight??e.weight:Math.round(s[e.key]??0)})),[k,v,s]);return i(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[i(`button`,{type:`button`,onClick:()=>S(!w),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":w,children:[d(C,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${w?`rotate-90`:``}`}),d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t}),d(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:_?b>=2?i(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[d(Lt,{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(me,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),w&&i(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[_?m&&g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):g.length===0?d(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):d(`ul`,{className:`space-y-2`,children:g.map(e=>{let t=Ji(e),n=v[e.key]??E(e),a=n.enabled&&e.available;return i(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?a?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[d(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${Yi[t.hue]}`,children:d(t.Icon,{className:`h-4.5 w-4.5`})}),i(`div`,{className:`min-w-0 flex-1`,children:[i(`div`,{className:`flex items-center gap-2`,children:[d(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),d(K,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&d(K,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),i(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`font-mono`,children:e.key}),!a&&i(o,{children:[d(`span`,{"aria-hidden":!0,children:`·`}),i(`span`,{children:[`default model`,` `,d(`span`,{className:`font-mono text-foreground/80`,children:e.defaultModelId})]})]})]})]}),a&&i(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[d(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),d(`input`,{type:`number`,min:1,placeholder:`∞`,value:n.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);O(e,r!=null&&r>0?r:null)},disabled:h.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),a&&d(Zi,{suggested:r?.[e.key]??null,current:n.maxSessions,pending:h.isPending,onApply:t=>O(e,t)}),d(be,{checked:a,onCheckedChange:()=>D(e),disabled:!e.available||h.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):d(Qi,{}),_&&k.length>=2&&i(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[i(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[d(dn,{className:`h-3.5 w-3.5`}),`Accelerator share`]}),d(qi,{nodes:A,pending:h.isPending,onCommitWeights:e=>{let t={...v};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}y(t),T(t)},weightLabel:`Accelerator share`,readOnly:s!==void 0,footnote:s===void 0?d(o,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`}):d(o,{children:`Automatic: each accelerator's share follows its measured throughput at its model. Switch the node shares to manual to set them yourself.`})})]}),h.isError&&i(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,h.error instanceof Error?h.error.message:`unknown error`]})]})]})}function Zi({suggested:e,current:t,pending:n,onApply:r}){return e===null||e<1||e===t?null:i(B,{variant:`ghost`,size:`sm`,onClick:()=>r(e),disabled:n,title:`Advisory cap from the measured throughput at the suggested model, with the headroom kept free. Applying it writes this device's cap.`,children:[`use `,e]})}function Qi(){return i(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[d(me,{className:`h-6 w-6 text-foreground-subtle/60`}),d(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),d(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}r();var $i=3600*1e3,ea=2e4,ta=.4;function na({refreshToken:e,onOpenAutoTune:t}){let n=c(),{nodes:r}=W(),s=$e(void 0),f=mt({isCamera:!0,projection:`slim`}),p=ot({windowMs:$i},{refetchInterval:ea,placeholderData:l}).data,m=Fe(void 0,{refetchInterval:ea,placeholderData:l}).data,h=()=>{Di(n),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`]]})},_=At({onSuccess:h}),v=ee({onSuccess:()=>{h(),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getEffectiveShares`]]})}}),x=lt({onSuccess:h}),S=ct(),[C,w]=u(!1),T=m?.source,E=T===`benchmark`?`benchmark`:`hardware`,D=Dt({headroom:ta,source:E},{enabled:C,staleTime:1/0}),O=D.data,k=a(()=>{let e=new Map((s.data??[]).map(e=>[e.nodeId,e.settings]));return r.filter(t=>xn(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:xi(n,`detectWeight`)??1,maxCameras:xi(n,`maxCameras`)}})},[r,s.data]),A=e=>r.find(t=>t.id===e)?.name??e,j=Mn((f.data??[]).map(e=>({id:e.id,name:e.name}))),M=O?Ii(O):void 0,N=Ri(k,m),F=T!==`manual`,te=e=>{if(m===void 0||m.source===`manual`||m.autoPending)return;let t=m.nodes.find(t=>t.nodeId===e);return t===void 0?void 0:Object.fromEntries(t.devices.map(e=>[e.deviceKey,e.configuredPct]))},I=m?zi(m,A):null,L=m?Hi(m,A):null,R=Bi.find(e=>e.value===T)?.hint;return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[d(on,{nodeId:`hub`,addonIds:[di],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(En,{refreshToken:e}),d(Ai,{stats:p,...m!==void 0&&m.source!==`manual`&&!m.autoPending?{targetWeights:Object.fromEntries(m.nodes.map(e=>[e.nodeId,e.configuredPct]))}:{}}),d(H,{headingId:`load-balancing-node-shares`,title:`Node shares`,icon:dn,actions:i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(`div`,{role:`radiogroup`,"aria-label":`Share source`,className:`flex items-center gap-1`,children:Bi.map(e=>d(B,{role:`radio`,"aria-checked":T===e.value,variant:T===e.value?`primary`:`outline`,size:`sm`,title:e.hint,disabled:v.isPending||m===void 0,onClick:()=>{T!==e.value&&v.mutate({source:e.value})},children:e.label},e.value))}),i(B,{variant:`outline`,size:`sm`,onClick:()=>{w(!0),C&&D.refetch()},disabled:D.isFetching,children:[d(xe,{className:`h-3.5 w-3.5`}),D.isFetching?`Suggesting…`:E===`benchmark`?`Suggest from benchmark`:`Suggest from hardware`]}),i(B,{variant:`ghost`,size:`sm`,onClick:t,children:[d(oe,{className:`h-3.5 w-3.5`}),`Auto tune`]}),i(B,{variant:`outline`,size:`sm`,onClick:()=>S.mutate(void 0),disabled:S.isPending,title:`Move standing (always-on) cameras that are no longer on their best node. Pinned cameras never move; on-motion sessions are placed per session anyway.`,children:[d(P,{className:`h-3.5 w-3.5`}),S.isPending?`Rebalancing…`:`Rebalance`]})]}),children:i(`div`,{className:`${g} space-y-3`,children:[R!==void 0&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:R}),p&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Policy:`,` `,d(K,{variant:p.policy===`share`?`info`:`default`,children:p.policy===`share`?`honour shares`:`least-loaded`}),` `,`· cluster peak `,p.clusterPeakSessions,` parallel sessions in the last hour`,p.policy===`least-loaded`&&` · under least-loaded an idle node always wins, so shares only bite once nodes are busy`]}),d(qi,{nodes:N.nodes,pending:_.isPending,readOnly:N.readOnly,onCommitWeights:e=>_.mutate(Pi(e)),weightLabel:`Node share`,...N.readOnly?{footnote:m?.autoPending?d(o,{children:`Automatic shares are being computed from the cluster's measured capacity; the stored values are used meanwhile.`}):i(o,{children:[T===`benchmark`?`Benchmark: each node's share follows its measured capacity from node benchmark results (hardware capacity where it has none)`:`Hardware: each node's share follows its capacity at its Auto tune model, from the measured speed of its hardware`,`, recomputed whenever a node or accelerator is added, removed, switched on or off, or changes model`,m?.computedAt==null?``:` — last at ${new Date(m.computedAt).toLocaleTimeString()}${m.trigger===null?``:` (${m.trigger})`}`,`.`]})}:{}}),I!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,children:I}),L!==null&&d(`p`,{className:`text-[10px] text-foreground-subtle`,"data-testid":`benchmark-fallback-note`,children:L}),v.isError&&d(ue,{message:`Failed to switch shares: ${v.error instanceof Error?v.error.message:`unknown error`}`}),_.isError&&d(ue,{message:`Failed to save shares: ${_.error instanceof Error?_.error.message:`unknown error`}`}),i(`details`,{className:`rounded-md border border-border`,children:[d(`summary`,{className:`${b} cursor-pointer text-xs text-foreground`,children:`Max concurrent sessions (advanced)`}),d(`ul`,{className:`divide-y divide-border border-t border-border`,children:k.map(e=>i(`li`,{className:`${b} flex items-center gap-2`,children:[d(`span`,{className:`min-w-0 flex-1 truncate text-xs text-foreground`,children:e.name}),d(Be,{type:`number`,min:1,placeholder:`∞`,defaultValue:e.maxCameras??``,"aria-label":`Max concurrent sessions for ${e.name}`,className:`w-20 text-right`,disabled:x.isPending,onBlur:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10),i=r!==null&&r>0?r:null;i!==e.maxCameras&&x.mutate({agentNodeId:e.id,maxCameras:i})}})]},e.id))}),d(`p`,{className:`${b} ${y} border-t border-border`,children:`A hard cap on the sessions a node runs at once (always-on cameras count too). A node at its cap is never chosen; under shares its turn goes to a free node. Empty = unlimited.`})]})]})}),D.isError&&d(ue,{message:`Suggestion failed: ${D.error instanceof Error?D.error.message:`unknown error`}`}),O&&d(ra,{suggestion:O,nameOf:A,pending:_.isPending,...F?{}:{onApply:()=>_.mutate(Fi(O))}}),d(H,{headingId:`load-balancing-accelerators`,title:`Accelerators`,icon:G,children:d(`div`,{className:`${g} space-y-2`,children:k.length===0?d(_e,{title:`No detect-capable nodes`,description:`Enable detection on a node in Roles & nodes to configure its accelerators.`}):k.map(e=>d(Xi,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline,...M?.[e.id]===void 0?{}:{suggestedMaxSessions:M[e.id]},...te(e.id)===void 0?{}:{autoDeviceShares:te(e.id)}},e.id))})}),p!==void 0&&p.stalePins.length>0&&d(ia,{stats:p,cameraName:j})]})}function ra({suggestion:e,nameOf:t,pending:n,onApply:r}){return i(H,{headingId:`load-balancing-suggestion`,title:e.source===`benchmark`?`Suggested from benchmark`:`Suggested from hardware`,icon:xe,...r===void 0?{}:{actions:d(B,{size:`sm`,onClick:r,disabled:n,children:`Apply suggested shares`})},children:[d(`ul`,{className:`divide-y divide-border`,children:e.nodes.map(e=>i(`li`,{className:`${b} space-y-0.5`,children:[i(`div`,{className:`flex items-baseline gap-2 text-xs`,children:[d(`span`,{className:`min-w-0 flex-1 truncate font-medium text-foreground`,children:t(e.nodeId)}),d(`span`,{className:`tabular-nums text-foreground`,children:e.share===null?`skipped`:`${e.share}%`})]}),i(`p`,{className:y,children:[Vi(e.capacityFallback)===null?``:`${Vi(e.capacityFallback)} · `,e.skippedReason===null?`≈ ${e.capacitySessions} parallel sessions · ${e.devices.map(e=>`${e.deviceKey} ${e.share}% (${e.modelId??`—`}${e.measured?``:`, estimated`}, cap ${e.suggestedMaxSessions??`—`})`).join(` · `)}`:`not part of the suggestion — ${e.skippedReason}`]})]},e.nodeId))}),i(`p`,{className:`${b} ${y} border-t border-border`,children:[`Shares in proportion to each node's capacity in parallel sessions —`,` `,e.source===`benchmark`?`measured by node benchmarks, or from the hardware table where a node has no results`:`at the models Auto tune picks (at least ${e.minSessionsPerDevice} per accelerator), from the measured speed of each node's hardware`,`, counted in `,e.cameraFps,` fps sessions with`,` `,Math.round(e.headroom*100),`% kept free. No load is measured or estimated.`,r===void 0?`Automatic shares already follow this; the caps are advisory — apply each from its accelerator row.`:`Applying writes the node and accelerator shares; the caps are advisory — apply each from its accelerator row.`]})]})}function ia({stats:e,cameraName:t}){let n=c(),r=we({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPlacementStats`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}});return d(H,{headingId:`load-balancing-stale-pins`,title:`Stale device pins`,icon:ln,children:d(`ul`,{className:`divide-y divide-border`,children:e.stalePins.map(e=>i(`li`,{className:`${b} flex items-center gap-2`,children:[i(`div`,{className:`min-w-0 flex-1`,children:[d(`p`,{className:`truncate text-xs text-foreground`,title:t(e.deviceId),children:t(e.deviceId)}),d(`p`,{className:y,children:Li(e)})]}),d(B,{variant:`outline`,size:`sm`,disabled:r.isPending,onClick:()=>r.mutate({deviceId:e.deviceId,deviceKey:`auto`}),children:`Clear pin`})]},e.deviceId))})})}r();var aa=1024,oa=65536;function sa(e,t,n){let r=e.trim();if(r.length===0)return{value:null,error:null};let i=Number(r);return Number.isInteger(i)?i<t?{value:null,error:`at least ${t}`}:i>n?{value:null,error:`at most ${n}`}:{value:i,error:null}:{value:null,error:`whole number`}}function ca({nodeId:e,decodeBudgetMb:t,maxLiveDecodeWorkers:n,status:r,errorMessage:a,onCommit:o}){let[s,c]=u(t===null?``:String(t)),[l,p]=u(n===null?``:String(n));f(()=>{c(t===null?``:String(t))},[t]),f(()=>{p(n===null?``:String(n))},[n]);let m=sa(s,aa,oa),h=sa(l,1,32),g=r===`pending`,_=m.value!==t||h.value!==n,v=m.error!==null||h.error!==null,y=_&&!v&&!g,b=()=>{y&&o(e,{decodeBudgetMb:m.value,maxLiveDecodeWorkers:h.value})};return i(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d(Be,{"aria-label":`Decode budget MB for ${e}`,type:`number`,inputMode:`numeric`,min:aa,max:oa,placeholder:`auto`,value:s,disabled:g,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:`w-20`}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`MB`}),d(Be,{"aria-label":`Max decode workers for ${e}`,type:`number`,inputMode:`numeric`,min:1,max:32,placeholder:`auto`,value:l,disabled:g,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()},className:`w-20`}),d(`span`,{className:`text-[11px] text-foreground-subtle`,children:`workers`}),i(B,{variant:`outline`,size:`sm`,onClick:b,disabled:!y,"aria-label":`Save decode limits for ${e}`,title:`Save decode limits`,children:[g?d(R,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):d(jt,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),m.error===null?null:i(`span`,{className:`text-[11px] text-danger`,children:[`budget: `,m.error]}),h.error===null?null:i(`span`,{className:`text-[11px] text-danger`,children:[`workers: `,h.error]}),!_&&!g&&r===`success`&&d(jt,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":`Saved`,role:`img`}),r===`error`&&d(`span`,{title:a??`Failed to save decode limits`,children:d(Ct,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":`Save failed`,role:`img`})})]})}function la({node:e,emphasis:t=!1}){let n=e.isHub?ht:G;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(K,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&d(K,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}r();function ua({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:a,onCommit:o}){let[s,c]=u(t??``);f(()=>{c(t??``)},[t]);let l=n[0],p=l===void 0?`auto-detect`:`auto: ${l}`,m=r===`pending`,h=s.trim(),g=h!==(t??``),_=g&&!m,v=()=>{_&&o(e,h.length>0?h:null)};return i(`div`,{className:`flex items-center gap-1.5`,children:[d(Be,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:p,value:s,disabled:m,onChange:e=>c(e.target.value),onBlur:v,onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&c(t??``)},className:`w-36`}),i(B,{variant:`outline`,size:`sm`,onClick:v,disabled:!_,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,children:[m?d(R,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):d(jt,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!g&&!m&&r===`success`&&d(jt,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":`Saved`,role:`img`}),r===`error`&&d(`span`,{title:a??`Failed to save reachable host`,children:d(Ct,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":a??`Failed to save reachable host`,role:`img`})})]})}function da({nodes:e,actions:t}){return d(de,{columns:[{key:`node`,header:`Node`,sortValue:e=>e.name,render:e=>d(la,{node:e})},..._i.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(be,{"aria-label":`${e.label} on ${n.name}`,title:e.hint,checked:Ti(n.effective,e.key),disabled:t.capabilityPending,onCheckedChange:r=>t.onToggleCapability(n.id,e.key,r)})})),{key:`host`,header:`Reachable host`,notSortableReason:`An editor`,render:e=>d(ua,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})},{key:`decode`,header:`Decode limits`,notSortableReason:`An editor`,render:e=>d(ca,{nodeId:e.id,decodeBudgetMb:e.decodeBudgetMb,maxLiveDecodeWorkers:e.maxLiveDecodeWorkers,status:t.decodeLimitsStatus(e.id),errorMessage:t.decodeLimitsErrorMessage(e.id),onCommit:t.onCommitDecodeLimits})}],rows:e,rowKey:e=>e.id,bordered:!1,minWidthPx:720,mobileMode:`scroll`,rowClassName:e=>e.isOnline?void 0:`opacity-60`,emptyMessage:`No cluster nodes reporting yet.`})}function fa({roleValues:e,options:t,pending:n,onRoleChange:r}){let a=t.map(e=>({value:e.id,label:e.id===`hub`?`${e.name} (default)`:e.name}));return d(`ul`,{className:`divide-y divide-border`,children:gi.map(t=>i(`li`,{className:`${b} flex flex-wrap items-center gap-x-3 gap-y-1.5`,children:[i(`div`,{className:`min-w-0 flex-1 basis-56`,children:[d(`div`,{className:`text-xs font-medium text-foreground`,children:Ci(t)}),d(`p`,{className:y,children:wi(t)})]}),d(`div`,{className:`w-full sm:w-48`,children:d(z,{"aria-label":`${Ci(t)} node`,value:e[t],disabled:n,options:a,onChange:e=>r(t,e.target.value)})})]},t))})}r();function pa(){let e=c(),{nodes:t}=W(),n=$e(void 0),r=Ge({addonId:di}),o=Ge({addonId:fi}),s=Ge({addonId:mi}),l=()=>Di(e),u=yt({onSuccess:l}),f=it({onSuccess:l}),p=We({onSuccess:l}),m=at({onSuccess:l}),h=a(()=>{let e=new Map;for(let t of n.data??[])e.set(t.nodeId,t.settings);return e},[n.data]),g=a(()=>t.map(e=>{let t=h.get(e.id),n=xn(t,e.isHub);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,reachableHost:Si(t,`reachableHost`),detectedHosts:e.localIps,decodeBudgetMb:xi(t,`decodeBudgetMb`),maxLiveDecodeWorkers:xi(t,`maxLiveDecodeWorkers`)}}),[t,h]),_={ingestNode:bi(r.data,`ingestNode`,`hub`),recordingNode:bi(o.data,pi,`hub`),audioNode:bi(r.data,`audioNode`,`hub`),motionNode:bi(r.data,`motionNode`,`hub`),postProcessingNode:bi(s.data,hi,`hub`)},v=a(()=>{let e=t.filter(e=>e.isOnline).map(e=>e.id),n=e=>t.find(t=>t.id===e)?.name||e;return[...new Set([`hub`,...gi.map(e=>_[e]),...e])].filter(e=>e.length>0).map(e=>({id:e,name:n(e)}))},[t,_]),b=n.isLoading||r.isLoading||o.isLoading||s.isLoading,x=(e,t,n)=>{u.mutate({agentNodeId:e,[t]:n})},S=(e,t)=>{if(e===`recordingNode`){m.mutate({addonId:fi,patch:{[pi]:t}});return}if(e===`postProcessingNode`){m.mutate({addonId:mi,patch:{[hi]:t}});return}m.mutate({addonId:di,patch:{[e]:t}})},C=e=>f.variables?.agentNodeId===e?f.isPending?`pending`:f.isError?`error`:f.isSuccess?`success`:`idle`:`idle`,w=e=>C(e)===`error`?Ei(f.error):null,T=e=>p.variables?.agentNodeId===e?p.isPending?`pending`:p.isError?`error`:p.isSuccess?`success`:`idle`:`idle`,E={capabilityPending:u.isPending,onToggleCapability:x,onCommitReachableHost:(e,t)=>f.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:C,reachableHostErrorMessage:w,onCommitDecodeLimits:(e,t)=>p.mutate({agentNodeId:e,...t}),decodeLimitsStatus:T,decodeLimitsErrorMessage:e=>T(e)===`error`?Ei(p.error):null};return i(`div`,{className:`space-y-3 sm:space-y-4`,children:[i(H,{headingId:`roles-nodes-cluster-roles`,title:`Cluster roles`,icon:cn,actions:b?d(R,{className:`h-3.5 w-3.5 animate-spin text-foreground-subtle`,"aria-label":`Loading`}):null,children:[d(`p`,{className:`${y} border-b border-border px-3 py-1.5 sm:px-4`,children:`One node holds each role for every camera. Detection shares and caps are on Load balancing.`}),d(fa,{roleValues:_,options:v,pending:m.isPending,onRoleChange:S})]}),d(H,{headingId:`roles-nodes-node-capabilities`,title:`Node capabilities`,icon:ht,children:d(da,{nodes:g,actions:E})})]})}var ma=`pipeline-analytics`,ha=`face-gallery`,ga=`pipeline-orchestrator`,_a=`pipeline-runner`,va=`audio-analyzer`;function ya(e){return[...Gt.filter(t=>t.stepId===e).map(e=>zt(e.stepId)),...Bt.filter(t=>t.stepId===e).map(e=>Jt(e.stepId,e.key))]}var ba=`faces`,xa=`semantic-search`,Sa=[{id:ba,title:`Faces & recognition`,hint:`The face encoder for every node, the smallest faces worth embedding, keeping and auto-assigning, and how a face is matched to a person.`,panels:[{addonId:ga,fieldKeys:ya(`face-embedding`)},{addonId:ma,capability:ha}]},{id:xa,title:`Semantic search`,hint:`The image encoder behind "search by description". One for the whole cluster: changing it hides existing results until the index is rebuilt.`,panels:[{addonId:ga,fieldKeys:ya(`clip-embedding`)}]},{id:Yt,title:`Enrichment crop`,hint:`How the crop handed to face, plate and search models is cut from the frame.`,panels:[{addonId:ga,sectionIds:[Yt]}]},{id:Kt,title:`Full-resolution crops`,hint:`How long each camera keeps full-resolution pixels so a late crop (snapshot, face, plate) is sharp instead of cut from the small detection frame.`,panels:[{addonId:ga,sectionIds:[Kt]}]},{id:`runner-defaults`,title:`Runner defaults`,hint:`Values every node's detection runner and audio analyzer use. A node's own decode limits (Roles & nodes) take precedence.`,panels:[{addonId:_a,fieldScope:`cluster`},{addonId:va,fieldScope:`cluster`}]},{id:`failover`,title:`Failover`,hint:`What happens to cameras when a node disconnects and comes back.`,panels:[{addonId:ga,sectionIds:[`failover`]}]}],Ca={"cluster-step-models":ba};function wa(e){return e===`clip-embedding`?xa:ba}r();var Ta=2500,Ea={faces:bt,"semantic-search":oe,"detail-crop":It,"native-lease":Lt,"runner-defaults":G,failover:et};function Da(e){f(()=>{if(e===null)return;let t=Ca[e]??e,n=`[data-cluster-settings-card="${CSS.escape(t)}"]`,r=()=>{let e=document.querySelector(n);return e===null?!1:(e.scrollIntoView({block:`start`,behavior:`smooth`}),e.classList.add(`ring-2`,`ring-primary/60`),setTimeout(()=>e.classList.remove(`ring-2`,`ring-primary/60`),Ta),!0)};if(r())return;let i=new MutationObserver(()=>{r()&&i.disconnect()});return i.observe(document.body,{childList:!0,subtree:!0}),()=>i.disconnect()},[e])}function Oa({section:e}){return d(`div`,{"data-cluster-settings-card":e.id,className:`rounded-lg`,children:d(H,{headingId:`cluster-settings-${e.id}`,title:e.title,...Ea[e.id]===void 0?{}:{icon:Ea[e.id]},children:i(`div`,{className:`${g} space-y-3`,children:[d(`p`,{className:y,children:e.hint}),e.panels.map(e=>d(on,{nodeId:`hub`,addonIds:[e.addonId],level:`global`,hideSectionChrome:!0,omitSectionIds:[`cluster`,`load`],emptyMessage:`Not available — the addon that owns these settings did not answer.`,...e.capability===void 0?{}:{capability:e.capability},...e.sectionIds===void 0?{}:{sectionIds:e.sectionIds},...e.fieldKeys===void 0?{}:{fieldKeys:e.fieldKeys},...e.fieldScope===void 0?{}:{fieldScope:e.fieldScope}},`${e.addonId}:${e.capability??``}`))]})})})}function ka({refreshToken:e}){let[t]=rn();return Da(t.get(Ao)),d(`div`,{className:`space-y-3 sm:space-y-4`,children:Sa.map(e=>d(Oa,{section:e},e.id))})}var Aa=`pipeline-orchestrator`,ja=200;function Ma(){return i(`div`,{className:`flex flex-col gap-3`,children:[i(`div`,{children:[d(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),d(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),d(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:d(Ie,{addonId:Aa,limit:ja,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}var Na=[{id:`assignments`,label:`Assignments`},{id:`load-balancing`,label:`Load balancing`},{id:`auto-tune`,label:`Auto tune`},{id:`roles-nodes`,label:`Roles & nodes`},{id:`settings`,label:`Settings`},{id:`logs`,label:`Logs`}];function Pa(e){return Na.some(t=>t.id===e)}function Fa({refreshToken:e}){let[t,n]=rn(),r=t.get(ko),a=Pa(r)?r:`assignments`,o=e=>{n(t=>{let n=new URLSearchParams(t);return n.set(ko,e),n.delete(Ao),n},{replace:!0})};return i(`div`,{className:`flex flex-col h-full`,children:[i(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[d(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),d(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Camera assignments, load balancing, the detector recommendation, cluster roles and settings.`})]}),d(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:Na.map(e=>d(`button`,{type:`button`,onClick:()=>o(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${a===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),i(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[a===`assignments`&&d(Br,{}),a===`load-balancing`&&d(na,{refreshToken:e,onOpenAutoTune:()=>o(`auto-tune`)}),a===`auto-tune`&&d(ai,{}),a===`roles-nodes`&&d(pa,{}),a===`settings`&&d(ka,{refreshToken:e}),a===`logs`&&d(Ma,{})]})]})}var Ia=`armed:`;function La(e){return e.assignment.reasons.detection?.startsWith(Ia)===!0}function Ra(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null&&!La(e)?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function za(e){let t=[],n=[],{assignment:r,detection:i,broker:a}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),r.detectionNodeId===null&&i===null&&!La(e)&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});let o=e.degraded??[];if(o.length>0){let e=[...new Set(o.map(e=>e.stage))].join(`, `);n.push({code:`status-unreadable`,severity:`warning`,message:`Could not read ${e} for this camera — those blocks are unknown, not empty (a switch read that failed does NOT mean nothing is switched off)`})}n.push(...Ha(e.cameraSensors));for(let e of a?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Ba(e){return e.state===`unreadable`&&Ht.state===`unreadable`&&e.reason===Ht.reason}function Va(e){switch(e.state){case`ready`:return null;case`missing`:return{code:`camera-sensor-missing`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is missing`};case`offline`:return{code:`camera-sensor-offline`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) is ${e.reason}`};case`unsupported`:return{code:`camera-sensor-unsupported`,severity:`warning`,message:`Camera sensor ${e.name} (#${e.deviceId}) cannot drive motion: ${e.reason}`};case`unreadable`:return{code:`camera-sensor-unreadable`,severity:`warning`,message:`Camera sensor ${e.addonId}/${e.stableId} is unreadable: ${e.reason}`}}}function Ha(e){if(e===void 0||e.state===`not-configured`)return[];if(e.state===`unreadable`)return Ba(e)?[]:[{code:`camera-sensors-unreadable`,severity:`warning`,message:`Camera sensors unreadable: ${e.reason}`}];let t=e.sensors.flatMap(e=>{let t=Va(e);return t===null?[]:[t]}),n=e.notForwarded===void 0?t:[Ua(e.notForwarded),...t];return e.notEnforced===void 0?n:[{code:`camera-sensors-not-enforced`,severity:`warning`,message:`Confirm / Replace cannot suppress this camera's own motion until its provider is updated`},...n]}function Ua(e){return{code:`camera-sensors-not-forwarded`,severity:`warning`,message:e===`onboard-not-listed`?`Camera sensors are attached but never fire: add "Camera sensors" (onboard) to this camera's motion sources`:`Camera sensors are attached but never fire: this camera has no active detection`}}function Wa(e){return e===void 0?`status unavailable from this node`:e.state===`not-configured`?`none attached`:e.state===`unreadable`?`unknown — ${e.reason}`:e.sensors.map(Ka).join(`, `)}function Ga(e){return e.mode===`in-addition`?``:` · ${e.mode}`}function Ka(e){return`${qa(e)}${Ga(e)}`}function qa(e){switch(e.state){case`ready`:return`${e.name} (#${e.deviceId})`;case`offline`:return`${e.name} (#${e.deviceId}) — ${e.reason}`;case`unsupported`:return`${e.name} (#${e.deviceId}) — unsupported`;case`missing`:case`unreadable`:return`${e.addonId}/${e.stableId} — ${e.state}`}}function Ja(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Ya(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Xa(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Za(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Qa={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function $a(e){if(!Ja(e)||!Array.isArray(e.sections))return Qa;let t=Qt(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)Za(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Ya(n(`detectionFps`)),motionSources:Xa(n(`motionSources`)),motionFps:Ya(n(`motionFps`)),motionCooldownMs:Ya(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function eo(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...eo(r.children,t+1));return n}function X({title:e,children:t}){return i(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[d(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),d(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return i(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[d(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),d(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&d(to,{})]})}function to(){return d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var no={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return d(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${no[e]}`,children:t})}function $({children:e}){return d(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function ro({icon:e,label:t,nodeId:n,pinned:r,reason:a,overridden:s}){return i(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[d(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),d(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?d(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):i(o,{children:[d(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?i(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[d(un,{className:`h-2.5 w-2.5`}),` manual`]}):i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,a!==void 0&&a.length>0?a:`capacity`]}),s&&d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function io({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:a}){let o=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,s=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return i(X,{title:`Where it runs`,children:[d(ro,{icon:G,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),d(ro,{icon:Pe,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),d(ro,{icon:E,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),d(ro,{icon:Xe,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),d(`div`,{className:`mt-1.5`,children:i(`select`,{value:o,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>a(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[d(`option`,{value:`auto`,children:`Auto (load balanced)`}),s.map(e=>i(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function ao(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function oo(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function so(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function co({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:a,cameraSensors:s}){let c=oo(t,n.detectionStreamProfile),l=oo(t,n.motionStreamProfile),u=n.motionSources.includes(`analyzer`);return i(X,{title:`Streams & motion`,children:[i(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,c!==void 0&&` · ${c.width}×${c.height} ${c.codec}`]}),d(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:so(n.detectionFps)}),i(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.map($t).join(` + `):`none`,r===!1&&` · inactive`]}),d(Z,{label:`Camera sensors`,children:Wa(s)}),u&&i(o,{children:[i(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,l!==void 0&&` · ${l.width}×${l.height} ${l.codec}`]}),i(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[so(n.motionFps),a!==null&&` · live ${a.toFixed(1)}`]})]}),d(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),d(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?d($,{children:`No streams registered`}):e.map(e=>i(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[d(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,ao(e)]},e.camStreamId))})]})}function lo({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return i(X,{title:`Pipeline steps`,children:[e===void 0?d($,{children:`Resolving…`}):e.length===0?d($,{children:`No steps configured`}):d(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>d(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:i(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&d(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&i(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),d(`div`,{className:`mt-1`,children:i(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var uo={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function fo({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return i(X,{title:`Detection runtime`,children:[d(Z,{label:`Mode`,overridden:r,children:n??`—`}),d($,{children:`Detection stage inactive or unreachable`})]});let a=t?.phase??e.phase,o=t?.actualFps??e.actualFps,s=t?.configuredFps??e.configuredFps,c=t?.avgInferenceTimeMs??e.avgInferenceMs,l=t?.queueDepth??e.queueDepth,u=N(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(he,{phase:a,className:`h-2.5 w-2.5`}),u.label]}),t!==void 0&&d(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),d(Z,{label:`Mode`,overridden:r,children:n??`—`}),i(Z,{label:`FPS`,children:[d(`span`,{className:f?`text-danger font-semibold`:``,children:o.toFixed(1)}),i(`span`,{className:`text-foreground-subtle`,children:[` / `,s.toFixed(0),` configured`]})]}),i(Z,{label:`Inference`,children:[c.toFixed(0),` ms`,l>0&&i(`span`,{className:`text-warning`,children:[` · queue `,l]}),t!==void 0&&t.droppedFrames>0&&i(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),i(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),i(Z,{label:`Provisioning`,children:[d(Q,{tone:uo[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&i(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function po({broker:e}){return e===null?d(X,{title:`Stream broker`,children:d($,{children:`Broker stage inactive or unreachable`})}):i(X,{title:`Stream broker`,children:[e.profiles.length===0?d($,{children:`No broker profiles`}):d(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return i(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),d(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),i(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),i(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps===null?`—`:e.inFps.toFixed(0),`fps`]}),i(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),i(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[i(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),i(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function mo({decoder:e}){return e===null?d(X,{title:`Decoder`,children:d($,{children:`Decoder stage inactive or unreachable`})}):d(X,{title:`Decoder`,children:d(Z,{label:`Node`,children:e.nodeId})})}r();var ho=`pipeline-orchestrator`,go={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},_o={healthy:`Healthy`,idle:`Idle`,error:`Error`};function vo({problems:e}){return d(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>i(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[d(Ft,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),d(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function yo({deviceId:e,name:t,online:n,status:r,live:o,onlineNodes:s}){let l=c(),{data:u}=xt({addonId:ho,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:f}=nt({deviceId:e},{staleTime:3e4}),p=a(()=>$a(u),[u]),m=a(()=>f===void 0?void 0:eo(f.steps),[f]),h=a(()=>r===void 0?[]:za(r),[r]),g=()=>{l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),l.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},_=je({onSuccess:g}),v=I({onSuccess:g}),y=t=>{t===`auto`?v.mutate({deviceId:e}):_.mutate({deviceId:e,agentNodeId:t})},b=r===void 0?`idle`:Ra(r),x=h.some(e=>e.severity===`error`),S=h.length>0,C=x?`border-danger/50`:S?`border-warning/40`:`border-border`;return i(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${C} bg-background overflow-hidden`,children:[i(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[d(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${x?`bg-danger`:go[b]}`,title:x?`Error`:_o[b],"aria-label":x?`Error`:_o[b],role:`img`}),d(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),i(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&d(Q,{tone:`danger`,children:`offline`}),i(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[p.detectionMode!==null&&d(Q,{tone:p.detectionMode===`disabled`?`warning`:p.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:p.detectionMode===`disabled`?`detection off`:p.detectionMode}),r?.recording!=null&&(r.recording.active?i(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[d(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&i(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),h.length>0&&d(vo,{problems:h}),r===void 0?d(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):i(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[d(io,{assignment:r.assignment,settings:p,onlineNodes:s,pinPending:_.isPending||v.isPending,onDetectionPinChange:y}),d(fo,{detection:r.detection,live:o,detectionMode:p.detectionMode,modeOverridden:p.overriddenKeys.has(`detectionMode`)}),d(lo,{steps:m,audioModelId:f?.audio?.modelId??null,audioEnabled:r.audio?.enabled??f?.audio?.enabled??null,audioMode:p.audioMode}),d(co,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:p,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null,cameraSensors:r.cameraSensors}),d(po,{broker:r.broker}),d(mo,{decoder:r.decoder})]})]})}r();var bo=5e3,xo=1e4,So=5e3;function Co(e){let t=c(),{data:n,isLoading:r}=an(),{data:i,isLoading:o}=dt({},{refetchInterval:bo}),{nodes:s}=W();f(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[l,d]=u(new Map);Nt(Zt.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),f(()=>{if(l.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-xo,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},So);return()=>clearInterval(e)},[l.size]);let p=a(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:a(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:p.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,p]),liveMetrics:l,onlineNodes:a(()=>(s??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[s]),isLoading:r||o}}r();function wo({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:o}=Co(e),s=a(()=>[...t.map(e=>{let t=e.status===void 0?[]:za(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),c=a(()=>{let e=0,t=0;for(let r of s)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:s.length,active:e,issues:t}},[s,n]);return o&&t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?d(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):d(`div`,{className:`h-full overflow-y-auto`,children:i(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[i(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[i(`span`,{children:[d(`span`,{className:`font-semibold text-foreground`,children:c.total}),` cameras`]}),i(`span`,{children:[d(`span`,{className:`font-semibold text-success`,children:c.active}),` actively inferring`]}),i(`span`,{children:[d(`span`,{className:`font-semibold ${c.issues>0?`text-danger`:`text-foreground`}`,children:c.issues}),` `,`with issues`]}),d(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),s.map(({row:e})=>d(yo,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}var To=e({CLUSTER_NODE_ID:()=>Eo,PipelinePage:()=>Oo});r();var Eo=`__cluster__`;function Do(e){return e===`cameras`?`cameras`:`nodes`}function Oo(){let[e,t]=rn(),n=Do(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[a,s]=u(0),[c,l]=u(!1);return f(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:Eo},{replace:!0})},[n,e,t]),i(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[i(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[i(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[d(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),d(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),d(`div`,{className:`flex items-center gap-2`,children:i(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[d(Qe,{className:`h-3.5 w-3.5`}),`Refresh`]})})]}),n===`nodes`&&i(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-expanded":c,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[i(`span`,{children:[c?`Hide`:`Show`,` node list`]}),d(S,{className:[`h-4 w-4 transition-transform`,c?`rotate-180`:``].join(` `)})]}),d(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?i(o,{children:[d(`aside`,{className:[c?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:d(Cn,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),l(!1)},refreshToken:a})}),d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?d(Fa,{refreshToken:a}):d(zr,{nodeId:r,refreshToken:a})})]}):d(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:d(wo,{refreshToken:a})})})]})}var ko=`ctab`,Ao=`section`;function jo(e,t){let n=new URLSearchParams({view:`nodes`,node:Eo,[ko]:e});return t!==void 0&&n.set(Ao,t),`/pipeline?${n.toString()}`}function Mo(e){return jo(`settings`,wa(e))}function No(){return jo(`load-balancing`)}var Po=`pipeline-orchestrator`;function Fo(e){return Gt.find(t=>t.stepId===e)??null}function Io({step:e,engineFormat:t,runnableModelIds:n}){let{data:r}=Ge({addonId:Po}),a=Rt(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(nn,{to:Mo(e.stepId),className:`ml-auto text-[11px] text-primary hover:underline`,children:`Change in Cluster → Settings ›`})]}),i(`p`,{className:y,children:[`One model for every node and camera: `,e.indexName,` only matches vectors from the model that made them.`]}),s&&i(`p`,{className:`rounded border border-warning/40 bg-warning/10 px-2 py-1 text-[10px] leading-snug text-warning`,children:[`This accelerator's engine (`,t,`) ships no build of `,d(`b`,{children:a}),`. It refuses this step rather than run a different encoder — a substitute would put a second feature space into `,e.indexName,`.`]})]})}export{sr as _,Tr as a,ur as c,gr as d,vr as f,cr as g,_r as h,Er as i,Sr as l,hr as m,Fo as n,mr as o,xr as p,To as r,yr as s,Io as t,br as u,ir 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}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{at as c,gt as l,ht as u,st as d,vt as f}from"./player-overlays-PPtffSZH.js";import{$l as p,Bd as m,Cd as h,Cr as g,Fd as _,Gl as v,H as y,Hl as b,In as x,Jl as S,Jn as C,Kl as w,Ld as T,M as E,N as D,Nt as ee,Pu as O,Ql as te,U as k,Ul as ne,Vd as A,Wl as re,Xl as j,Yl as M,Zl as ie,Zu as N,_f as P,bu as F,cf as I,ef as L,eu as R,id as z,iu as ae,nu as oe,ql as se,qn as B,rd as V,ru as ce,sa as le,tr as ue,tu as de,wr as H,wu as U,xd as fe,xf as pe,zd as me}from"./src-EnVigh-D.js";import{t as he}from"./unlink-CvsfIFka.js";import{a as ge,i as _e,o as ve,s as ye}from"./client-DuQQ55XQ.js";import{$ as be,F as W,G as xe,o as Se,s as Ce}from"./index-I9Gc2ACc.js";import{t as G}from"./AdminPage-BSFohA3i.js";import{t as we}from"./AdminTabs-BOhyA0v_.js";import{n as Te,r as Ee,t as De}from"./IntegrationHub-Czg3bSVM.js";import{n as Oe,t as ke}from"./addon-display-names-BkwMrExv.js";var Ae=f(`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`}]]),je=f(`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`}]]),Me=f(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]);e();function Ne({userId:e,username:n,onClose:r}){let i=B(),a=F.useUtils(),o=S({userId:e}),c=F.auth.listLoginMethods.useQuery(),l=ce({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(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{"data-testid":`external-identities-modal`,className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(T,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Linked sign-in accounts`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,"aria-label":`Close`,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(U,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-3`,children:[o.isLoading?t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(_,{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(he,{className:`h-3 w-3`}),`Remove`]})]},`${e.provider}|${e.subject}`)})}),s(`div`,{className:`flex justify-end`,children:s(x,{onClick:r,variant:`secondary`,children:`Close`})})]})]})})}function Pe({userId:e,username:n,onClose:r}){let o=a(),c=B(),l=w({userId:e}),u=l.data,d=()=>o.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),f=v({onSuccess:()=>{d(),r()}}),p=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[t(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[t(`div`,{className:`flex items-center gap-2`,children:[s(N,{className:`h-4 w-4 text-primary`}),t(`div`,{children:[s(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),t(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,s(`span`,{className:`font-mono`,children:n})]})]})]}),s(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:s(U,{className:`h-4 w-4`})})]}),t(`div`,{className:`p-4 space-y-4`,children:[p===`loading`&&t(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(_,{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(A,{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(P,{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(x,{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(_,{className:`h-3 w-3 animate-spin`}):s(U,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function K({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 Fe({scopes:e,isAdmin:n,invalidReason:a}){let o=c(),l=r({queryKey:[`auth`,`previewScope`,e,n],enabled:a===null,queryFn:()=>o.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:n})}),{data:u}=le({projection:`slim`}),f=u?.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(z,{className:`h-3 w-3 shrink-0`}),a]})});if(l.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(_,{className:`h-3 w-3 animate-spin`}),`Resolving…`]});if(l.isError||!l.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=l.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(K,{icon:L,label:`Devices they can see`,count:p.device.view.deviceCount,all:p.device.view.all,total:f}),s(K,{icon:h,label:`Devices they can operate`,count:p.device.create.deviceCount,all:p.device.create.all,total:f}),s(K,{icon:d,label:`Devices they can delete`,count:p.device.delete.deviceCount,all:p.device.delete.all,total:f}),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.`})]})})}function Ie(e){let t=ve(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 Le(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:ge({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function Re({user:e,onClose:r,onSubmit:a,submitting:c,callerScopes:d}){let f=n(()=>Ie(e.scopes??[]),[e.scopes]),[p,m]=o(f),[h,g]=o(f.mode===`advanced`),v=n(()=>Le(p),[p]),b=!e.isAdmin&&p.mode===`role`&&p.roleId===null,x=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?`Pick what this user can do to see the result.`:D(v),[e.isAdmin,p.mode,p.roleId,v]),S=e=>m({...p,...e});return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 pt-[calc(1rem+env(safe-area-inset-top))] pb-[calc(1rem+env(safe-area-inset-bottom))]`,children:t(`div`,{className:`flex max-h-full w-full max-w-2xl flex-col rounded-lg border border-border bg-surface shadow-xl`,children:[t(`div`,{className:`flex shrink-0 items-start justify-between border-b border-border px-4 py-3`,children:[t(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Access — `,e.username]}),s(`div`,{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.`})]}),s(`button`,{onClick:r,className:`shrink-0 text-foreground-subtle hover:text-foreground`,title:`Close`,children:s(U,{className:`h-4 w-4`})})]}),t(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto px-4 py-4`,children:[b&&t(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[s(z,{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:_e.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:()=>S({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}),g(!0);return}g(!1),m(Ie(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:u,{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(E,{value:p.advancedScopes,onChange:e=>S({mode:`advanced`,advancedScopes:e}),clampToParent:d,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(y,{value:p.selector,onChange:e=>S({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>S({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(Fe,{scopes:v,isAdmin:e.isAdmin,invalidReason:x})]})]}),t(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[s(`button`,{onClick:r,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>a([...v]),disabled:c||x!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:c?s(_,{className:`h-3 w-3 animate-spin`}):`Save access`})]})]})})}e();var ze=8;function Be(){let e=a(),{user:n}=W(),[r,i]=o(!1),[c,l]=o(``),[u,f]=o(``),[p,m]=o(!1),[h,g]=o(null),{data:v,isLoading:y,isError:b}=ie(),x=B(),S=C(),w=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),E=ne({onSuccess:()=>{w(),i(!1),l(``),f(``),m(!1),g(null)},onError:e=>{g(e instanceof Error?e.message:`Failed to create user`)}}),D=re({onSuccess:w}),O=ae({onSuccess:w}),k=te({onSuccess:w}),A=oe({onSuccess:()=>{w(),M(null)}}),[j,M]=o(null),[P,F]=o(null),[I,L]=o(null),R=v??[];async function z(e){await x({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`})&&D.mutate({id:e.id})}async function se(e){let t=await S({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<ze?`Password must be at least ${String(ze)} characters.`:null});t===null||t.length===0||await x({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&k.mutate({id:e.id,newPassword:t})}function ce(e,t){t!==e.isAdmin&&O.mutate({id:e.id,isAdmin:t})}function le(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return t(G,{children:[s(`div`,{className:`flex items-center justify-end`,children:t(`button`,{onClick:()=>i(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[s(fe,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&t(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:[s(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),s(`button`,{onClick:()=>i(!1),className:`text-foreground-subtle hover:text-foreground`,children:s(U,{className:`h-4 w-4`})})]}),t(`div`,{className:`grid grid-cols-3 gap-3`,children:[t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),s(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),s(`input`,{type:`password`,value:u,onChange:e=>f(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),t(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`rounded border-border focus:ring-primary`}),s(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),h&&s(`p`,{className:`text-[10px] text-danger`,children:h}),t(`div`,{className:`flex justify-end gap-2`,children:[s(`button`,{onClick:()=>i(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),s(`button`,{onClick:()=>E.mutate({username:c,password:u,isAdmin:p}),disabled:E.isPending||!c||!u,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:E.isPending?`Creating...`:`Create`})]})]}),y&&s(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),b&&s(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!y&&!b&&R.length===0&&s(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>D.isPending&&D.variables?.id===e.id||O.isPending&&O.variables?.id===e.id||k.isPending&&k.variables?.id===e.id;return s(ee,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:n=>t(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[s(`input`,{type:`checkbox`,checked:n.isAdmin,onChange:e=>ce(n,e.target.checked),disabled:e(n),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),s(`span`,{className:n.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:n.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Access`,render:e=>e.isAdmin?s(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:`everything (admin)`}):t(`button`,{onClick:()=>M(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] hover:bg-foreground-subtle/10`,title:`Configure access`,children:[s(V,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),s(Ve,{scopes:e.scopes??[]})]})},{key:`createdAt`,header:`Created`,render:e=>s(`span`,{className:`text-foreground-subtle`,children:le(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:r=>{let i=e(r);return t(`div`,{className:`flex items-center justify-end gap-1`,children:[r.id!==n?.id&&r.totpEnabled&&t(`button`,{onClick:()=>F(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[s(N,{className:`h-3 w-3`}),`Remove 2FA`]}),t(`button`,{onClick:()=>L(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Linked sign-in accounts`,children:[s(T,{className:`h-3 w-3`}),`Sign-in links`]}),t(`button`,{onClick:()=>se(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[s(me,{className:`h-3 w-3`}),`Reset password`]}),t(`button`,{onClick:()=>z(r),disabled:i,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[i?s(_,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:R,rowKey:e=>e.id,minWidthPx:560})})(),P&&s(Pe,{userId:P.id,username:P.username,onClose:()=>F(null)}),I&&s(Ne,{userId:I.id,username:I.username,onClose:()=>L(null)}),j&&s(He,{user:j,onClose:()=>M(null),onSubmit:e=>A.mutate({userId:j.id,scopes:e}),submitting:A.isPending})]})}function Ve({scopes:e}){if(e.length===0)return s(`span`,{className:`font-medium text-warning`,children:`No access`});let n=ve(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:ye(n.roleId).label}),` ·`,` `,k(n.selector)]})}function He(e){let{user:t}=W(),n=t?.isAdmin===!0;return s(Re,{...e,callerScopes:n?null:t?.scopes??[]})}e();var Ue=`bg-primary/10 text-primary`,We=`bg-foreground-subtle/10 text-foreground-subtle`;function q(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function Ge(e){return e?e===`*`?`*`:e.join(`, `):``}function Ke(){let e=a(),r=B(),{data:i,isLoading:c}=se(),{data:l}=ie(),u=n(()=>i??[],[i]),f=n(()=>l??[],[l]),m=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),h=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[g,v]=o(!1),[y,x]=o(null),S=p({onSuccess:m}),C=b({onSuccess:({token:e,record:t})=>{h(),v(!1),x({token:e,label:t.name})}}),w=de({onSuccess:h}),T=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&S.mutate({id:e})},E=async(e,t)=>{await r({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&w.mutate({id:e})};return t(G,{children:[t(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[s(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),t(`button`,{onClick:()=>v(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:f.length===0,title:f.length===0?`Create a user first`:`Issue a scoped token`,children:[s(V,{className:`h-3.5 w-3.5`}),`New token`]})]}),t(qe,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[f.length===0&&s(Ye,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),f.map(e=>s(Ze,{userId:e.id,username:e.username,onRevoke:(e,t)=>{E(e,t)},revokePending:w.isPending,revokeId:w.variables?.id},e.id))]}),u.length>0&&s(qe,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:s(Xe,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let n=!!e.isAdmin,r=S.isPending&&S.variables?.id===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${n?Ue:We}`,children:n?`admin`:`regular`})}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:Ge(e.allowedProviders)||`all`}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>{T(e.id,e.label)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(_,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&s(Je,{}),g&&s(Qe,{users:f.map(e=>({id:e.id,username:e.username})),onClose:()=>v(!1),onSubmit:e=>C.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:C.isPending}),y&&s($e,{token:y.token,label:y.label,onClose:()=>x(null)})]})}function qe({title:e,subtitle:n,children:r}){return t(`div`,{className:`space-y-2`,children:[t(`div`,{className:`flex items-baseline justify-between`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),n&&s(`span`,{className:`text-[10px] text-foreground-subtle`,children:n})]}),r]})}function Je(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ye({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function Xe({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function Ze({userId:e,username:n,onRevoke:r,revokePending:i,revokeId:a}){let{data:o,isLoading:c}=j({userId:e}),l=o??[];return c||l.length===0?null:t(`div`,{className:`space-y-1.5`,children:[s(`div`,{className:`text-[11px] font-medium text-foreground`,children:n}),s(Xe,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:l.map(e=>{let n=i&&a===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),t(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,n)=>t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${k(e.selector)}]`:e.target]},n))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.expiresAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.createdAt)}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:t(`button`,{onClick:()=>r(e.id,e.name),disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[n?s(_,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function Qe({users:e,onClose:n,onSubmit:r,submitting:i}){let{user:a}=W(),c=a?.isAdmin===!0?null:a?.scopes??[],[l,u]=o(e[0]?.id??``),[d,f]=o(``),[p,m]=o([{type:`capability`,target:``,access:[`view`,`create`]}]),[h,g]=o(``),v=D(p),y=l!==``&&d.trim().length>0&&p.length>0&&v===null&&!i;return t(J,{title:`Create scoped token`,onClose:n,children:[t(`div`,{className:`space-y-3`,children:[s(Y,{label:`On behalf of user`,children:s(`select`,{value:l,onChange:e=>u(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>s(`option`,{value:e.id,children:e.username},e.id))})}),s(Y,{label:`Name`,children:s(`input`,{value:d,onChange:e=>f(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),t(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[s(E,{value:p,onChange:m,clampToParent:c}),v&&s(`p`,{className:`mt-1 text-[10px] text-danger`,children:v})]}),s(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:s(`input`,{type:`number`,min:1,value:h,onChange:e=>g(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),t(et,{children:[s(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),t(`button`,{onClick:()=>{let e=parseInt(h,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:l,name:d.trim(),scopes:p,expiresAt:t})},disabled:!y,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?s(_,{className:`h-3.5 w-3.5 animate-spin`}):s(V,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function $e({token:e,label:n,onClose:r}){let[i,a]=o(!1),c=async()=>{try{await navigator.clipboard.writeText(e),a(!0)}catch{}};return t(J,{title:`Token: ${n}`,onClose:r,children:[t(`div`,{className:`space-y-3`,children:[s(`div`,{className:`rounded 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:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),t(et,{children:[t(`button`,{onClick:()=>{c()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[i?s(pe,{className:`h-3.5 w-3.5 text-primary`}):s(I,{className:`h-3.5 w-3.5`}),i?`Copied`:`Copy`]}),s(`button`,{onClick:r,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function J({title:e,onClose:n,children:r}){return s(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:t(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[t(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[s(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),s(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:s(U,{className:`h-4 w-4`})})]}),s(`div`,{className:`p-4`,children:r})]})})}function et({children:e}){return s(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:n,children:r}){return t(`div`,{className:`space-y-1`,children:[s(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),r,n&&s(`p`,{className:`text-[10px] text-foreground-subtle`,children:n})]})}e();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function tt(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 nt(){return s(`div`,{className:`space-y-2`,children:[1,2].map(e=>s(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function rt({text:e}){return s(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function it({headers:e,rows:n}){return s(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:t(`table`,{className:`w-full text-xs min-w-[640px]`,children:[s(`thead`,{children:s(`tr`,{children:e.map((t,n)=>s(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),s(`tbody`,{children:n})]})})}function at(){let e=a(),r=B(),{data:i,isLoading:o}=M(),c=n(()=>i??[],[i]),l=R({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),u=async(e,t)=>{await r({title:`Revoke "${t}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&l.mutate({id:e})};return t(G,{icon:Me,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[o&&s(nt,{}),!o&&c.length===0&&s(rt,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!o&&c.length>0&&s(it,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:c.map(e=>{let n=e.revokedAt!==null,r=(l.isPending?l.variables?.id:void 0)===e.id;return t(`tr`,{className:`hover:bg-primary/5`,children:[s(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),s(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:s(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>s(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:tt(e)},t))})}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),s(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),s(`td`,{className:`px-3 py-2 border-b border-border`,children:n?t(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):s(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),s(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!n&&t(`button`,{onClick:()=>{u(e.id,e.integrationId)},disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[r?s(_,{className:`h-3 w-3 animate-spin`}):s(d,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}e();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication`,subtitle:`Login providers (local password, OIDC, SAML, magic-link) 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 ot(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:je,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).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:be,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:be,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:N,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`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:N,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:V,bullets:[`Generic authentication provider. No additional hints registered.`]}}function st(){let e=H({capName:Q[0].capName},{refetchInterval:Z}),t=H({capName:Q[1].capName},{refetchInterval:Z}),r=g(void 0,{refetchInterval:Z}),i=n(()=>ke(r.data??[]),[r.data]),a=n(()=>{let n=[],r=[e.data??[],t.data??[]];for(let[e,t]of Q.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:Q[0].capName,label:$.installLabel},entries:a.map(e=>({id:e.addonId,name:e.displayName,fallbackIcon:V,...Oe(e.isActive),render:()=>s(Te,{addonId:e.addonId,displayName:e.displayName,capName:e.capName,isActive:e.isActive,badges:e.stageBadge===null?null:s(ue,{variant:`info`,className:Ee,children:e.stageBadge}),panels:[{id:`about`,title:`About`,icon:ot(e.addonId).icon,content:s(ct,{addonId:e.addonId})}]})}))}];return s(De,{icon:V,title:$.title,subtitle:$.subtitle,groups:o,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription})}function ct({addonId:e}){let n=ot(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(Ae,{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-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[s(A,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),t(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,s(xe,{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(xe,{to:`/system/identity?tab=users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function lt(){return s(`div`,{className:`flex flex-col p-4`,children:s(we,{tabs:[{id:`users`,label:`Users`,icon:O,content:s(Be,{})},{id:`api-keys`,label:`Tokens`,icon:m,content:s(Ke,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:Me,content:s(at,{})},{id:Ce.authentication.tab,label:`Authentication`,icon:V,content:s(st,{}),ownedParams:Se}]})})}export{lt as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{I as e,K as t,Q as n,S as r,W as i,b as a,o,q as s,x as c,z as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{Z as u,at as d,gt as f,ht as p,mt as m,st as h,vt as g}from"./player-overlays-PPtffSZH.js";import{$a as _,$i as v,Bi as y,Dt as b,Du as x,Fd as S,Hi as C,It as w,Ji as T,K as E,Ki as D,Na as ee,Qa as O,Qi as k,Qt as A,Ui as j,Vi as te,Wi as ne,Y as re,Za as M,_d as N,_t as P,dr as F,ef as I,eo as L,ff as R,fr as z,ga as ie,gf as B,hd as ae,io as V,kr as H,ld as oe,ma as se,md as ce,na as U,no as W,od as le,pn as G,pu as ue,q as de,qi as fe,sa as pe,to as me,uu as he,wu as ge,xd as _e,xf as ve,zf as ye,zu as K}from"./src-EnVigh-D.js";import{Tr as be}from"./client-DuQQ55XQ.js";import{t as xe}from"./useTranslation-Bc5yH9V9.js";import"./mount-C1VaG3XC.js";import{J as Se,K as Ce,N as we,q as Te}from"./index-I9Gc2ACc.js";import{t as Ee}from"./NodeAddonsSettingsPanel-Bin020YC.js";import{t as De}from"./device-integration-icon-vpQeGGPt.js";import{n as Oe,r as q,t as ke}from"./ScanNetworkModal-DjrnLqkB.js";var Ae=g(`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 je(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...je(n.fields));return t}function Me(t,n,r){let[a,o]=s(`idle`),[c,l]=s({}),u=i(()=>{let e=[];for(let n of t.sections)e.push(...je(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;o(`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),o(`idle`)},[r,u,n]),clearProbeResult:f}}n();function Ne(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(...Ne(n.fields));return t}function Pe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Fe(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Fe(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function J(){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:a,onClose:u}){let{t:d}=xe(),p=o(),[m,h]=s({}),[g,_]=s(!1),[v,y]=s(null),[b,C]=s(J),w=se({addonId:a},{enabled:t}),T=w.data?.deviceType??null,E=U({addonId:a,type:T??be.Camera},{enabled:t&&w.isSuccess&&T!==null}),D=E.data??null;l(()=>{t&&(h(D?Fe(D.sections.flatMap(e=>e.fields)):{}),C(J()),_(!1),y(null))},[t,n,D]);let O=i(()=>({...m,_probeRequestId:b}),[m,b]),k=fe({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),A=ee(),j=e(async(e,t)=>{_(!0);let n=await A.mutateAsync({addonId:a,type:T??be.Camera,key:e,value:t,formValues:O});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Pe(e[i])&&!Pe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[A,a,O,T]),{testAllStatus:te,hasProbeFields:ne,probeResults:re,handleTestAll:M,clearProbeResult:N}=Me(D??{sections:[]},m,j);async function F(e){y(null);try{await k.mutateAsync({addonId:a,type:T??be.Camera,config:m,integrationId:n}),e?h(D?Fe(D.sections.flatMap(e=>e.fields)):{}):u()}catch(e){y(e instanceof Error?e.message:String(e))}}if(!t)return null;let I=Ne((D?.sections??[]).flatMap(e=>e.fields)).filter(e=>Pe(m[e])),L=I.length===0,R=w.isLoading||T!==null&&E.isLoading,z=w.isError||w.isSuccess&&T===null||E.isError||E.isSuccess&&D===null;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),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:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:d(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?c(`div`,{className:`flex items-center justify-center py-8`,children:c(S,{className:`h-5 w-5 animate-spin text-primary`})}):z?r(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(K,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),r(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,c(`span`,{className:`font-mono`,children:a}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):c(we,{schema:D,values:m,onChange:h,onTestField:j,probeResults:re,onClearProbe:N})}),!z&&!R&&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:[c(oe,{className:`h-3.5 w-3.5`}),`Test logs`,c(`span`,{className:`font-mono text-[9px] opacity-60`,children:b.slice(0,14)})]}),c(f,{className:`h-3.5 w-3.5 transition-transform ${g?`rotate-180`:``}`})]}),g&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(P,{addonId:a,requestId:b,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(v||I.length>0)&&c(`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:[c(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:v||`Required: ${I.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:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:d(`integrations.cancel`)}),!z&&ne&&r(`button`,{type:`button`,onClick:M,disabled:te===`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:[te===`testing`?c(S,{className:`h-3.5 w-3.5 animate-spin`}):c(x,{className:`h-3.5 w-3.5`}),`Test All`]})]}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>F(!0),disabled:z||!L||k.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:d(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>F(!1),disabled:z||!L||k.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:k.isPending?d(`integrations.saving`):d(`integrations.save`)})]})]})]})]})}var Le=1500;function Y({addonId:e,integrationId:t,jobId:n,onFinished:i}){let{t:a}=xe(),o=y(),s=(j({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Le:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,d=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&i();let f=[`${u}/${s.total} ${a(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&f.push(`${s.adopted} ${a(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&f.push(`${s.alreadyAdopted} ${a(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&f.push(`${s.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?c(S,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(K,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(R,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(B,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:p}),l&&c(`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`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${d}%`},role:`progressbar`,"aria-valuenow":d,"aria-valuemin":0,"aria-valuemax":100})}),s.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 X=`devices`,ze={id:X,label:`Devices`,isDefault:!0},Be=2e4,Z=100;function Ve({addonId:n,integrationId:i,onClose:a}){let{t:u}=xe(),d=o(),[f,p]=s(new Set),[m,h]=s(new Set),[g,v]=s(new Map),[y,b]=s(null),{data:x}=_(),w=(x??[]).find(e=>e.addonId===n)?.supportsLocationImport??!1,[T,ee]=s(!0),O=te({addonId:n,integrationId:i}).data?.filters,k=O&&O.length>0?O:[ze],[A,j]=s(k.find(e=>e.isDefault)?.id??(k.some(e=>e.id===X)?X:k[0].id)),re=A!==X,M=ne(),N=C({addonId:n,integrationId:i,page:1,pageSize:Be,filter:A}),P=N.refetch,F=M.mutate,I=e(()=>{F({addonId:n,integrationId:i},{onSettled:()=>{P()}})},[F,n,i,P]),L=t(null);l(()=>{let e=`${n}::${i}`;L.current===e||N.isLoading||(L.current=e,(N.data?.candidates.length??0)===0&&I())},[n,i,N.isLoading,N.data,I]);let R=M.isPending,z=M.isError?M.error instanceof Error?M.error.message:String(M.error):null,ie=typeof M.data?.lastError==`string`&&M.data.lastError.length>0?M.data.lastError:null,B=N.data?.candidates??[],ae=N.isError?N.error instanceof Error?N.error.message:String(N.error):null,V=D(),[H,oe]=s(null),se=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})},[]),U=e(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),W=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})},[]),le=e(e=>{let t={};for(let n of e){let e=g.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[g]),G=e(async()=>{b(null);let e=[...f];if(e.length!==0)try{let t=le(e),{jobId:r}=await V.mutateAsync({addonId:n,integrationId:i,filter:A,childNativeIds:e,...t?{perCandidate:t}:{},...w?{importLocations:T}:{}});oe(r),p(new Set),v(new Map)}catch(e){b(e instanceof Error?e.message:String(e))}},[f,le,V,n,i,A,w,T]),de=t(null),fe=e(()=>{H===null||de.current===H||(de.current=H,P(),d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}))},[H,P,d]),pe=e(e=>{j(e),p(new Set),h(new Set),v(new Map),b(null)},[]),me=f.size,_e=H!==null&&me===0&&!V.isPending;return r(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),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:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:u(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`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:[w&&r(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:T,onChange:e=>ee(e.target.checked),className:`accent-primary`}),u(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:c(ge,{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:[(z??ae??ie)&&B.length===0&&c(`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:[c(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),r(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:u(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:z??ae??ie})]})]})}),k.length>1&&c(He,{filters:k,activeFilter:A,onSelect:pe}),c(`div`,{className:`flex-1 min-h-0`,children:c(E,{mode:`generic`,items:B,pageSize:Z,getKey:e=>e.childNativeId,getSearchText:Re,getFilterType:e=>e.type,filterOptions:he(),filterLabel:u(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:N.isLoading||R&&B.length===0,searchPlaceholder:u(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(z??ae??ie)&&B.length===0?``:u(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:r(`button`,{type:`button`,onClick:I,disabled:R,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:[c(ce,{className:`h-3.5 w-3.5 ${R?`animate-spin`:``}`}),u(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:u(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ue,{candidate:e,expandable:!re,expanded:m.has(e.childNativeId),onToggleExpand:()=>U(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=ue(e.type),n=t.icon;return r(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(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=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>se(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)&&c(ve,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!re&&m.has(e.childNativeId),renderExpanded:re?void 0:e=>c(Q,{candidate:e,hiddenChildIds:g.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>W(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:f.has(e.childNativeId)?`bg-primary/5`:``})})]}),y&&c(`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:[c(K,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:y})]})}),H!==null&&c(Y,{addonId:n,integrationId:i,jobId:H,onFinished:fe}),r(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),r(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:a,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:_e?a:G,disabled:!_e&&(me===0||V.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:[V.isPending&&c(S,{className:`h-3.5 w-3.5 animate-spin`}),_e?u(`integrations.close`,{defaultValue:`Close`}):u(`integrations.addSelected`,{defaultValue:`Add selected`}),!_e&&me>0?` (${me})`:``]})]})]})]})]})}function He({filters:e,activeFilter:t,onSelect:n}){return c(`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 c(`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 Ue({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:[c(n?f:p,{className:`h-3.5 w-3.5`}),o]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:a})]})}function Q({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let i=e.children??[];return i.length===0?null:c(`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:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),a.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:a.join(`, `)}),c(`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:c(i?m:I,{className:`h-3 w-3`})})]},e.childNativeId)})})}n();function $(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...$(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function We(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>$(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Ge(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 Ke({integrationId:e,addonId:t,name:n,kind:a,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=xe(),m=o(),{data:h,isLoading:g}=L({id:e},{enabled:s===`account`||s===`broker`}),_=i(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=F({addonId:t,nodeId:`hub`},{enabled:s===`account`}),b=i(()=>v?Ge(v):null,[v]),x=W(),C=(t,n)=>{x.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:f,children:r(`div`,{className:`max-h-[85vh] w-full max-w-lg overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`mb-3 flex items-center justify-between`,children:[r(`h2`,{className:`text-sm font-semibold text-foreground`,children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),c(`button`,{onClick:f,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":p(`common.close`,{defaultValue:`Close`}),children:c(ge,{className:`h-4 w-4`})})]}),s===`broker`?l?r(`div`,{className:`space-y-3`,children:[c(`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.`})}),_&&r(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),x.isPending?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(S,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(q,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),x.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?r(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(S,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(Oe,{addonId:t,configSchema:b,canTest:u,initialName:n,initialConfig:We(b,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):c(G,{trpc:d,addonId:t,nodeId:`hub`,title:n})]})})}function qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}n();function Je(){let{t}=xe(),{integrationId:n}=Te(),f=o(),p=Ce(),[m,g]=Se(),y=d(),[x,C]=s(!1),[D,ee]=s(!1),[j,te]=s(!1),[ne,I]=s(!1),[L,R]=s(!1),{data:B,isLoading:se}=O({id:n??``},{enabled:!!n}),{data:ce}=F({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId}),{data:U,isSuccess:W}=_(),G=i(()=>{let e=B?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[U,B?.addonId,W]),{data:ue}=k({}),fe=i(()=>(ue?.providers??[]).some(e=>e.addonId===B?.addonId),[ue,B?.addonId]),he=G!==null,ve=B?.info?.fixed===!0,be=he?G===`device-adoption`?t(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):t(`integrations.addDevice`):t(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),we=i(()=>{let e=B?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.brokerKind??null},[U,B?.addonId,W]),Oe=i(()=>{let e=B?.addonId;return!e||!W?!1:(U??[]).find(t=>t.addonId===e)?.canTest===!0},[U,B?.addonId,W]),q=i(()=>{let e=B?.addonId;return!e||!W?null:(U??[]).find(t=>t.addonId===e)?.mode??null},[U,B?.addonId,W]);l(()=>{m.get(`add`)===`1`&&he&&(C(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[m,he,g]);let je=ce!=null&&Array.isArray(ce.sections)&&ce.sections.some(e=>e.fields.length>0),{data:Me}=z({addonId:B?.addonId??``,nodeId:`hub`},{enabled:!!B?.addonId&&q!==`account`}),Ne=q!==null&&q!==`account`&&qe(Me),Pe=i(()=>B?.addonId?[B.addonId]:[],[B?.addonId]),{data:Fe}=pe({projection:`slim`},{refetchInterval:3e4}),J=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Le=V({onMutate:async e=>{await f.cancelQueries({queryKey:J});let t=f.getQueryData(J);return t!=null&&f.setQueryData(J,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&f.setQueryData(J,r.previous)},onSettled:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Y=M({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]}),I(!1),p(`/integrations`)}}),Re=H({onSuccess:()=>{f.invalidateQueries({queryKey:[[`integrations`]]}),f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),X=ie({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ze=T({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Be=v({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Z=i(()=>Fe??[],[Fe]),He=i(()=>{let e=new Map;for(let t of Z)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Z]),Ue=e(e=>He.get(e)??null,[He]),{data:Q}=me(void 0),$=i(()=>de(Q),[Q]),We=e(e=>p(`/devices/${String(e)}`),[p]),Ge=i(()=>{let e=B?.id;return e?Z.filter(t=>{let n=$(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Z,B?.id,$]),Je=i(()=>Q===void 0?null:re(Ge).length,[Q,Ge])??`…`;return se?r(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):B?r(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(w,{items:[{label:`Integrations`,onClick:()=>p(`/integrations`)},{label:B.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:[c(`img`,{src:u(`/api/addon-assets/${B.addonId}/assets/icon.svg`),alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),r(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:B.name}),r(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[B.addonId,` · `,Je,` `,t(`integrations.devices`)]})]})]}),r(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[fe&&r(`button`,{onClick:()=>ee(!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:[c(N,{className:`h-3.5 w-3.5`}),`Scan network`]}),!ve&&r(`button`,{onClick:()=>C(!0),disabled:!he,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:be,children:[c(_e,{className:`h-3.5 w-3.5`}),be]}),r(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Le.isPending?`opacity-60`:``} ${B.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:t(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(A,{checked:B.enabled,onCheckedChange:e=>Le.mutate({id:n,enabled:e}),disabled:Le.isPending,"aria-label":B.enabled?`Disable integration`:`Enable integration`}),c(`span`,{className:`text-[11px] font-medium ${B.enabled?`text-success`:`text-foreground-subtle`}`,children:B.enabled?`Enabled`:`Disabled`}),Le.isPending&&c(S,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),q!==`standalone`&&(je||G===`device-adoption`)&&r(`button`,{onClick:()=>te(!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:[c(le,{className:`h-3 w-3`}),t(`integrations.config`)]}),r(`button`,{onClick:()=>R(!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:[c(oe,{className:`h-3 w-3`}),t(`integrations.logs`,{defaultValue:`Logs`})]}),c(b,{label:`Restart`,icon:ae,title:`Restart "${B.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Je} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Re.isPending,action:()=>Re.mutateAsync({addonId:B.addonId})}),!ve&&r(`button`,{onClick:()=>I(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:t(`integrations.delete`,{defaultValue:`Delete integration`}),children:[c(h,{className:`h-3 w-3`}),t(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),Ne&&c(Ee,{nodeId:null,addonIds:Pe,level:`global`,surface:`integration`,title:t(`integrations.settings`,{defaultValue:`Settings`})}),c(E,{context:`integration-detail`,devices:Z,trpc:y.trpcClient,integrationOf:$,forceIntegrationId:B.id,urlScope:`root`,lsKey:`integration-detail:${B.addonId}`,resolveIntegrationIcon:De,resolveParent:Ue,onNavigate:We,batchActions:{remove:X.mutate,disable:ze.mutate,enable:Be.mutate},...ve?{}:{onDeleteDevice:e=>X.mutate({deviceId:e.id})}}),x&&n&&G===`device-adoption`&&c(Ve,{addonId:B.addonId,integrationId:n,onClose:()=>C(!1)}),x&&n&&G===`device-provider`&&c(Ie,{open:x,integrationId:n,addonId:B.addonId,onClose:()=>C(!1)}),D&&B&&c(ke,{open:D,scope:{addonId:B.addonId,label:B.name},onClose:()=>ee(!1)}),j&&n&&G!==null&&q!==null&&c(Ke,{integrationId:n,addonId:B.addonId,name:B.name,kind:G,mode:q,brokerKind:we,canTest:Oe,trpc:y.trpcClient,onClose:()=>te(!1)}),L&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>R(!1),children:r(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[r(`div`,{className:`flex items-center gap-2 min-w-0`,children:[c(oe,{className:`h-4 w-4 text-primary shrink-0`}),c(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:B.name}),r(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[B.addonId,n?` · ${n}`:``]})]}),c(`button`,{onClick:()=>R(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:c(ge,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:c(P,{addonId:B.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),ne&&c(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Y.isPending&&I(!1),children:r(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[r(`div`,{className:`flex items-start gap-3`,children:[c(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:c(K,{className:`h-4 w-4 text-danger`})}),r(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),c(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:t(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:B.name,count:Je})})]})]}),Y.error&&c(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Y.error instanceof Error?Y.error.message:String(Y.error)}),r(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[c(`button`,{onClick:()=>I(!1),disabled:Y.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:t(`integrations.cancel`,{defaultValue:`Cancel`})}),c(`button`,{onClick:()=>Y.mutate({id:n}),disabled:Y.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Y.isPending?r(a,{children:[c(S,{className:`h-3 w-3 animate-spin`}),t(`integrations.deleting`,{defaultValue:`Deleting…`})]}):r(a,{children:[c(h,{className:`h-3 w-3`}),t(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):r(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(Ae,{className:`h-6 w-6 text-foreground-subtle`})}),r(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:t(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`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:()=>p(`/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:[c(ye,{className:`h-3 w-3`}),t(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Je as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{D as e,K as t,L as n,Q as r,S as i,W as a,b as o,o as s,q as c,x as l,z as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js";import{B as d,Z as f,ct as p}from"./player-overlays-PPtffSZH.js";import{An as m,Dt as h,Fd as g,Fr as _,In as v,Ld as y,Mt as b,Nn as x,Pn as S,Sd as C,_t as w,gt as ee,hd as T,kf as E,kr as te,ld as ne,tr as re,xd as D,zu as O}from"./src-EnVigh-D.js";import{t as k}from"./settings-2-BfvfZMIZ.js";import"./mount-C1VaG3XC.js";import{G as A,J as j,a as M,c as N,d as P,f as F,l as I,p as L,u as R}from"./index-I9Gc2ACc.js";import{t as z}from"./AdminPage-BSFohA3i.js";import{t as B}from"./NodeAddonsSettingsPanel-Bin020YC.js";r();var V=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],H=`text-[10px]`;function U({isActive:e}){return l(re,{variant:e?`success`:`default`,className:H,children:e?`Enabled`:`Disabled`})}function W({capName:e,addonId:t,isActive:n}){let r=s(),a=_({onSuccess:()=>{for(let e of V)r.invalidateQueries({queryKey:e})}}),o=a.isPending;return i(v,{size:`sm`,variant:n?`secondary`:`primary`,disabled:o,onClick:()=>a.mutate({capName:e,addonId:t,enabled:!n}),children:[o?l(g,{className:`h-3 w-3 animate-spin`}):l(n?p:C,{className:`h-3 w-3`}),n?`Disable`:`Enable`]})}function G({addonId:e,displayName:t}){let n=s(),r=te({onSuccess:()=>{for(let e of V)n.invalidateQueries({queryKey:e})}});return l(h,{label:`Restart`,icon:T,size:`sm`,title:`Restart "${t}"?`,description:`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`ghost`,confirmVariant:`danger`,disabled:r.isPending,action:()=>r.mutateAsync({addonId:e})})}var K=600,q=e(null);function J({id:e,title:r,icon:a,actions:s,framed:c=!1,children:u}){let f=n(q),p=t(null),m=`integration-section-${e}`;Y(p,f,e);let h=i(o,{children:[f===null?null:l(A,{to:f.sectionHref(e),"aria-label":`Link to ${r}`,title:`Link to ${r}`,className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:l(y,{className:`h-3 w-3`,"aria-hidden":!0})}),s]});return c?l(`div`,{ref:p,className:`scroll-mt-4`,children:l(b,{headingId:m,title:r,icon:a,actions:h,children:u})}):i(`section`,{ref:p,"aria-labelledby":m,className:`scroll-mt-4 space-y-2`,children:[i(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[a!==void 0&&l(a,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),l(`h2`,{id:m,className:`${d} min-w-0 flex-1`,children:r}),h]}),u]})}function Y(e,t,n){let r=t?.requestedSection===n,i=t?.integrationId;u(()=>{if(!r)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,i=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,i,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},K);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,i)}},[r,i,e])}r();var X=`max-h-72`;function ie({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o,error:s=null,lead:c,panels:u=[]}){let d=u.filter(e=>e.placement!==`end`),f=u.filter(e=>e.placement===`end`);return i(`div`,{className:`flex flex-col gap-4`,children:[l(ae,{addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}),s!==null&&l(x,{message:s}),c,l(Z,{panels:d}),l(J,{id:R,title:`Settings`,icon:k,children:l(B,{nodeId:`hub`,addonIds:[e],level:`global`,capability:n})}),l(se,{addonId:e}),l(Z,{panels:f})]})}function Z({panels:e}){return l(o,{children:e.map(e=>l(J,{id:e.id,title:e.title,icon:e.icon,children:e.content},e.id))})}function ae({addonId:e,displayName:t,capName:n,isActive:r,badges:a,primaryAction:o}){return i(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-surface px-2 py-1.5 sm:px-3`,"data-testid":`integration-status-strip`,children:[i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[l(U,{isActive:r}),a,l(`span`,{className:`break-all font-mono text-[11px] text-foreground-subtle`,children:e})]}),i(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[o,l(W,{capName:n,addonId:e,isActive:r}),l(G,{addonId:e,displayName:t})]})]})}var oe=[{kind:`logs`,label:`Logs`,icon:ne},{kind:`events`,label:`Events`,icon:E}];function se({addonId:e}){let[t,n]=c(`logs`);return l(J,{id:M,title:`Activity`,framed:!0,actions:l(`div`,{role:`group`,"aria-label":`Activity stream`,className:`flex items-center gap-1`,children:oe.map(({kind:e,label:r,icon:a})=>i(`button`,{type:`button`,"aria-pressed":t===e,onClick:()=>n(e),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${t===e?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[l(a,{className:`h-3 w-3`,"aria-hidden":!0}),r]},e))}),children:t===`logs`?l(w,{addonId:e,maxHeight:X,showFilters:!1}):l(ee,{addonId:e,category:`addon.*`,maxHeight:X})})}r();function ce(e){let{ids:t,answered:n,legacyGroupParam:r=null,groupFirst:i}=e,[o]=j(),s=o.get(N),c=r===null?null:o.get(r),l=o.get(I),u=a(()=>F({ids:t,requested:s,answered:n,legacyGroup:c,...i===void 0?{}:{groupFirst:i}}),[t,s,n,c,i]),d=a(()=>(e,t)=>`?${L(o,e,r,t??null).toString()}`,[o,r]);return{...u,requestedSection:l,hrefFor:d}}r();var le={md:{tile:`h-10 w-10 rounded-lg`,img:`h-7 w-7 rounded-md p-1`,fallback:`h-5 w-5`},sm:{tile:`h-5 w-5 rounded`,img:`h-5 w-5 rounded p-0.5`,fallback:`h-3.5 w-3.5`}};function ue({addonId:e,fallback:t,tileClassName:n,iconPath:r=`assets/icon.svg`,size:i=`md`}){let[a,o]=c(!1),s=f(`/api/addon-assets/${e}/${r}`),u=le[i];return l(`div`,{className:`${u.tile} flex items-center justify-center shrink-0 ${n}`,children:a?l(t,{className:u.fallback,"aria-hidden":!0}):l(`img`,{src:s,alt:``,className:`${u.img} bg-white ring-1 ring-black/5`,onError:()=>o(!0)})})}var Q=`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,de=`border-primary bg-primary/10 text-primary font-medium`,fe=`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,pe={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function me({label:e,groups:t,selectedId:n,hrefFor:r}){let a=t.length>1;return l(`nav`,{"aria-label":e,className:a?`flex flex-col gap-2 sm:grid sm:grid-cols-[max-content_minmax(0,1fr)] sm:items-start sm:gap-x-3`:`flex flex-col`,children:t.map(e=>i(`div`,{role:`group`,"aria-label":e.label,className:a?`flex min-w-0 flex-col gap-1 sm:col-span-2 sm:grid sm:grid-cols-subgrid sm:items-start`:`min-w-0`,children:[a&&l(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle sm:pt-2`,children:e.label}),i(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[e.entries.map(e=>l(he,{entry:e,current:e.id===n,href:r(e.id)},e.id)),e.install&&i(A,{to:P(e.install.capability),className:`${Q} border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[l(D,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),l(`span`,{className:`truncate`,children:e.install.label})]})]})]},e.id))})}function he({entry:e,current:t,href:n}){let r=e.state===`ok`;return i(A,{to:n,"aria-current":t?`true`:void 0,className:`${Q} ${t?de:fe}`,"data-testid":`integration-pill-${e.id}`,children:[l(ue,{addonId:e.id,fallback:e.fallbackIcon,tileClassName:``,size:`sm`}),l(`span`,{className:`truncate`,children:e.name}),l(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${pe[e.state]}`,"aria-hidden":!0}),l(`span`,{className:r?`sr-only`:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:e.stateLabel})]})}r();function ge({icon:e,title:t,subtitle:n,groups:r,isLoading:s,emptyTitle:c,emptyDescription:u,legacyGroupParam:d,trailing:f}){let p=a(()=>r.flatMap(e=>e.entries),[r]),h=a(()=>p.map(e=>e.id),[p]),g=a(()=>{let e={};for(let t of r){let n=t.entries[0];n!==void 0&&(e[t.id]=n.id)}return e},[r]),_=ce({ids:h,answered:!s,legacyGroupParam:d??null,groupFirst:g}),v=p.find(e=>e.id===_.selectedId)??null,y=a(()=>v===null?null:{integrationId:v.id,requestedSection:_.requestedSection,sectionHref:e=>_.hrefFor(v.id,e)},[v,_]);return l(z,{icon:e,title:t,subtitle:n,nav:s?null:l(me,{label:`${t} integrations`,groups:r,selectedId:_.selectedId,hrefFor:e=>_.hrefFor(e)}),children:s?l(m,{children:l(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:`Loading…`})}):i(o,{children:[_.staleId!==null&&l(_e,{staleId:_.staleId,shownName:v?.name??null}),v!==null&&y!==null?l(q.Provider,{value:y,children:l(`div`,{role:`region`,"aria-label":v.name,"data-testid":`integration-body`,children:v.render()},v.id)}):l($,{groups:r,title:c,description:u}),f]})})}function $({groups:e,title:t,description:n}){let r=e.find(e=>e.install!==void 0)?.install;return l(m,{children:l(S,{title:t,description:n,action:r?l(A,{to:P(r.capability),children:i(v,{variant:`primary`,size:`sm`,children:[l(D,{className:`mr-1 h-3.5 w-3.5`}),r.label]})}):void 0})})}function _e({staleId:e,shownName:t}){return i(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[l(O,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),i(`span`,{children:[`This link named `,l(`span`,{className:`font-mono text-foreground`,children:e}),`, which is not installed here.`,t!==null&&i(o,{children:[` `,`Showing `,l(`span`,{className:`font-medium text-foreground`,children:t}),` instead.`]})]})]})}export{ie as n,H as r,ge as t};
|
|
@@ -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,at as u,gt as d,ht as f}from"./player-overlays-PPtffSZH.js";import{$a as p,Fd as m,K as h,Xa as ee,Xi as g,Y as _,_d as v,bd as y,cr as b,dr as te,hd as x,od as S,q as C,r as w,sa as ne,to as re,wu as T,xd as ie,xf as E,zi as D}from"./src-EnVigh-D.js";import{t as O}from"./useTranslation-Bc5yH9V9.js";import{J as k,K as A,U as j}from"./index-I9Gc2ACc.js";import{t as M}from"./AdminPage-BSFohA3i.js";import"./useEventInvalidation-C1VaG3XC.js";import{t as N}from"./StatusBadge-CeptlsPG.js";import{t as ae}from"./device-integration-icon-vpQeGGPt.js";import{n as oe,r as P,t as F}from"./ScanNetworkModal-DjrnLqkB.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}=O(),[a,u]=o(new Set),d=g(),f=d.data,p=d.isPending||!d.data&&!d.isError;c(()=>{e&&(d.isPending||d.data||d.mutate({addonId:e}))},[e,d]);function m(e){u(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=f??[];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(E,{className:`h-3 w-3 text-primary-foreground`})}),s(l,{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}=O(),a=A(),{data:o,isLoading:c}=p();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,u=r===o.addonId,d=l;return n(`button`,{disabled:d,onClick:()=>{if(!d)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})]}),u?s(m,{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(S,{className:`h-3 w-3`}),i(`integrations.manage`)]}):s(f,{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}=O(),u=A(),d=a(),[f,p]=o(`picker`),[h,_]=o(null),[v,y]=o(null),[b,x]=o(`manual`),[S,C]=o(null),[w,ne]=o(``),[re,ie]=o(null),[E,k]=o(null),[j,M]=o(!1),{data:N}=te({addonId:h??``,nodeId:`hub`},{enabled:h!=null}),ae=r(()=>N?se(N):null,[N]),F=ee({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),V=g(),H=V.data;c(()=>{f!==`discovery`||!v||!h||V.isPending||V.data||V.mutate({addonId:h})},[f,v,h,V]);let ce=D({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function le(e,t,n,r,i,a,o,s){if(!F.isPending){if(_(e),M(s),x(n),ne(r),k(null),o===`broker`){if(!a){k(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}C(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(h)try{let t=await F.mutateAsync({addonId:h,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});y(t.id),b===`auto`||b===`both`?p(`discovery`):q(t.id)}catch{}}async function G(e){if(h)try{let t=await F.mutateAsync({addonId:h,name:w,settings:{brokerId:e}});ie(t.id),y(t.id),q(t.id)}catch{}}async function K(e){if(h){for(let t of e){let e=H?.find(e=>e.stableId===t);e&&await ce.mutateAsync({addonId:h,candidate:e,...re===null?{}:{integrationId:re}})}q()}}function q(e){let n=e??v??h;t(),J(),n&&u(`/integrations/${n}`)}function J(){p(`picker`),_(null),y(null),x(`manual`),C(null),ne(``),ie(null),k(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?h: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(T,{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:[E&&s(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:E}),s(z,{onSelect:le,onClose:Y,pendingAddonId:Q})]}),f===`config`&&h&&s(oe,{addonId:h,configSchema:ae??null,canTest:j,onSave:W,onBack:()=>p(`picker`)}),f===`broker`&&S&&s(P,{kind:S,onResolved:e=>{G(e)},onBack:()=>p(`picker`)}),f===`discovery`&&v&&s(R,{providerId:v,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(m,{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?d:f,{className:`h-3.5 w-3.5`})}),s(j,{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(N,{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}=O(),a=A(),c=u(),[l]=k(),[d,f]=o(!1),p=e(()=>f(!0),[]),m=e(()=>f(!1),[]),[ee,g]=o(!1),te=e(()=>g(!0),[]),S=e(()=>g(!1),[]);w([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),w([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:T,isLoading:E,refetch:D}=re(void 0),{data:j,isLoading:N,refetch:oe}=ne({projection:`slim`}),P=r(()=>j??[],[j]),I=r(()=>T??[],[T]),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(()=>C(T),[T]),z=r(()=>{let e=new Map;for(let t of _(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(h,{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=E||N,$=I.length>0;return n(M,{icon:y,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(x,{className:b(`h-3.5 w-3.5`,Q&&`animate-spin`)})}),n(`button`,{onClick:te,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(v,{className:`h-3.5 w-3.5`}),`Scan network`]}),n(`button`,{onClick:p,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(ie,{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(h,{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:d,onClose:m}),s(F,{open:ee,onClose:S})]})}export{W as IntegrationsPage};
|